home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2012 April / ME_04_2012.iso / Video-Tutorial / iPhoto / media / player.swf / scripts / mx / graphics / RectangularDropShadow.as
Encoding:
Text File  |  2011-11-11  |  12.3 KB  |  380 lines

  1. package mx.graphics
  2. {
  3.    import flash.display.BitmapData;
  4.    import flash.display.Graphics;
  5.    import flash.display.Shape;
  6.    import flash.filters.DropShadowFilter;
  7.    import flash.geom.Matrix;
  8.    import flash.geom.Point;
  9.    import flash.geom.Rectangle;
  10.    import mx.core.FlexShape;
  11.    import mx.core.mx_internal;
  12.    import mx.utils.GraphicsUtil;
  13.    
  14.    use namespace mx_internal;
  15.    
  16.    public class RectangularDropShadow
  17.    {
  18.       mx_internal static const VERSION:String = "4.5.0.20967";
  19.       
  20.       private var shadow:BitmapData;
  21.       
  22.       private var leftShadow:BitmapData;
  23.       
  24.       private var rightShadow:BitmapData;
  25.       
  26.       private var topShadow:BitmapData;
  27.       
  28.       private var bottomShadow:BitmapData;
  29.       
  30.       private var changed:Boolean = true;
  31.       
  32.       private var _alpha:Number = 0.4;
  33.       
  34.       private var _angle:Number = 45;
  35.       
  36.       private var _color:int = 0;
  37.       
  38.       private var _distance:Number = 4;
  39.       
  40.       private var _tlRadius:Number = 0;
  41.       
  42.       private var _trRadius:Number = 0;
  43.       
  44.       private var _blRadius:Number = 0;
  45.       
  46.       private var _brRadius:Number = 0;
  47.       
  48.       private var _blurX:Number = 4;
  49.       
  50.       private var _blurY:Number = 4;
  51.       
  52.       public function RectangularDropShadow()
  53.       {
  54.          super();
  55.       }
  56.       
  57.       public function get alpha() : Number
  58.       {
  59.          return this._alpha;
  60.       }
  61.       
  62.       public function set alpha(param1:Number) : void
  63.       {
  64.          if(this._alpha != param1)
  65.          {
  66.             this._alpha = param1;
  67.             this.changed = true;
  68.          }
  69.       }
  70.       
  71.       public function get angle() : Number
  72.       {
  73.          return this._angle;
  74.       }
  75.       
  76.       public function set angle(param1:Number) : void
  77.       {
  78.          if(this._angle != param1)
  79.          {
  80.             this._angle = param1;
  81.             this.changed = true;
  82.          }
  83.       }
  84.       
  85.       public function get color() : int
  86.       {
  87.          return this._color;
  88.       }
  89.       
  90.       public function set color(param1:int) : void
  91.       {
  92.          if(this._color != param1)
  93.          {
  94.             this._color = param1;
  95.             this.changed = true;
  96.          }
  97.       }
  98.       
  99.       public function get distance() : Number
  100.       {
  101.          return this._distance;
  102.       }
  103.       
  104.       public function set distance(param1:Number) : void
  105.       {
  106.          if(this._distance != param1)
  107.          {
  108.             this._distance = param1;
  109.             this.changed = true;
  110.          }
  111.       }
  112.       
  113.       public function get tlRadius() : Number
  114.       {
  115.          return this._tlRadius;
  116.       }
  117.       
  118.       public function set tlRadius(param1:Number) : void
  119.       {
  120.          if(this._tlRadius != param1)
  121.          {
  122.             this._tlRadius = param1;
  123.             this.changed = true;
  124.          }
  125.       }
  126.       
  127.       public function get trRadius() : Number
  128.       {
  129.          return this._trRadius;
  130.       }
  131.       
  132.       public function set trRadius(param1:Number) : void
  133.       {
  134.          if(this._trRadius != param1)
  135.          {
  136.             this._trRadius = param1;
  137.             this.changed = true;
  138.          }
  139.       }
  140.       
  141.       public function get blRadius() : Number
  142.       {
  143.          return this._blRadius;
  144.       }
  145.       
  146.       public function set blRadius(param1:Number) : void
  147.       {
  148.          if(this._blRadius != param1)
  149.          {
  150.             this._blRadius = param1;
  151.             this.changed = true;
  152.          }
  153.       }
  154.       
  155.       public function get brRadius() : Number
  156.       {
  157.          return this._brRadius;
  158.       }
  159.       
  160.       public function set brRadius(param1:Number) : void
  161.       {
  162.          if(this._brRadius != param1)
  163.          {
  164.             this._brRadius = param1;
  165.             this.changed = true;
  166.          }
  167.       }
  168.       
  169.       public function get blurX() : Number
  170.       {
  171.          return this._blurX;
  172.       }
  173.       
  174.       public function set blurX(param1:Number) : void
  175.       {
  176.          if(this._blurX != param1)
  177.          {
  178.             this._blurX = param1;
  179.             this.changed = true;
  180.          }
  181.       }
  182.       
  183.       public function get blurY() : Number
  184.       {
  185.          return this._blurY;
  186.       }
  187.       
  188.       public function set blurY(param1:Number) : void
  189.       {
  190.          if(this._blurY != param1)
  191.          {
  192.             this._blurY = param1;
  193.             this.changed = true;
  194.          }
  195.       }
  196.       
  197.       public function drawShadow(param1:Graphics, param2:Number, param3:Number, param4:Number, param5:Number) : void
  198.       {
  199.          var _loc15_:Number = NaN;
  200.          var _loc16_:Number = NaN;
  201.          var _loc17_:Number = NaN;
  202.          var _loc18_:Number = NaN;
  203.          var _loc19_:Number = NaN;
  204.          var _loc20_:Number = NaN;
  205.          var _loc21_:Number = NaN;
  206.          var _loc22_:Number = NaN;
  207.          if(this.changed)
  208.          {
  209.             this.createShadowBitmaps();
  210.             this.changed = false;
  211.          }
  212.          param4 = Math.ceil(param4);
  213.          param5 = Math.ceil(param5);
  214.          var _loc6_:int = !!this.leftShadow ? this.leftShadow.width : 0;
  215.          var _loc7_:int = !!this.rightShadow ? this.rightShadow.width : 0;
  216.          var _loc8_:int = !!this.topShadow ? this.topShadow.height : 0;
  217.          var _loc9_:int = !!this.bottomShadow ? this.bottomShadow.height : 0;
  218.          var _loc10_:int = _loc6_ + _loc7_;
  219.          var _loc11_:int = _loc8_ + _loc9_;
  220.          var _loc12_:Number = (param5 + _loc11_) / 2;
  221.          var _loc13_:Number = (param4 + _loc10_) / 2;
  222.          var _loc14_:Matrix = new Matrix();
  223.          if(Boolean(this.leftShadow) || Boolean(this.topShadow))
  224.          {
  225.             _loc15_ = Math.min(this.tlRadius + _loc10_,_loc13_);
  226.             _loc16_ = Math.min(this.tlRadius + _loc11_,_loc12_);
  227.             _loc14_.tx = param2 - _loc6_;
  228.             _loc14_.ty = param3 - _loc8_;
  229.             param1.beginBitmapFill(this.shadow,_loc14_);
  230.             param1.drawRect(param2 - _loc6_,param3 - _loc8_,_loc15_,_loc16_);
  231.             param1.endFill();
  232.          }
  233.          if(Boolean(this.rightShadow) || Boolean(this.topShadow))
  234.          {
  235.             _loc17_ = Math.min(this.trRadius + _loc10_,_loc13_);
  236.             _loc18_ = Math.min(this.trRadius + _loc11_,_loc12_);
  237.             _loc14_.tx = param2 + param4 + _loc7_ - this.shadow.width;
  238.             _loc14_.ty = param3 - _loc8_;
  239.             param1.beginBitmapFill(this.shadow,_loc14_);
  240.             param1.drawRect(param2 + param4 + _loc7_ - _loc17_,param3 - _loc8_,_loc17_,_loc18_);
  241.             param1.endFill();
  242.          }
  243.          if(Boolean(this.leftShadow) || Boolean(this.bottomShadow))
  244.          {
  245.             _loc19_ = Math.min(this.blRadius + _loc10_,_loc13_);
  246.             _loc20_ = Math.min(this.blRadius + _loc11_,_loc12_);
  247.             _loc14_.tx = param2 - _loc6_;
  248.             _loc14_.ty = param3 + param5 + _loc9_ - this.shadow.height;
  249.             param1.beginBitmapFill(this.shadow,_loc14_);
  250.             param1.drawRect(param2 - _loc6_,param3 + param5 + _loc9_ - _loc20_,_loc19_,_loc20_);
  251.             param1.endFill();
  252.          }
  253.          if(Boolean(this.rightShadow) || Boolean(this.bottomShadow))
  254.          {
  255.             _loc21_ = Math.min(this.brRadius + _loc10_,_loc13_);
  256.             _loc22_ = Math.min(this.brRadius + _loc11_,_loc12_);
  257.             _loc14_.tx = param2 + param4 + _loc7_ - this.shadow.width;
  258.             _loc14_.ty = param3 + param5 + _loc9_ - this.shadow.height;
  259.             param1.beginBitmapFill(this.shadow,_loc14_);
  260.             param1.drawRect(param2 + param4 + _loc7_ - _loc21_,param3 + param5 + _loc9_ - _loc22_,_loc21_,_loc22_);
  261.             param1.endFill();
  262.          }
  263.          if(this.leftShadow)
  264.          {
  265.             _loc14_.tx = param2 - _loc6_;
  266.             _loc14_.ty = 0;
  267.             param1.beginBitmapFill(this.leftShadow,_loc14_);
  268.             param1.drawRect(param2 - _loc6_,param3 - _loc8_ + _loc16_,_loc6_,param5 + _loc8_ + _loc9_ - _loc16_ - _loc20_);
  269.             param1.endFill();
  270.          }
  271.          if(this.rightShadow)
  272.          {
  273.             _loc14_.tx = param2 + param4;
  274.             _loc14_.ty = 0;
  275.             param1.beginBitmapFill(this.rightShadow,_loc14_);
  276.             param1.drawRect(param2 + param4,param3 - _loc8_ + _loc18_,_loc7_,param5 + _loc8_ + _loc9_ - _loc18_ - _loc22_);
  277.             param1.endFill();
  278.          }
  279.          if(this.topShadow)
  280.          {
  281.             _loc14_.tx = 0;
  282.             _loc14_.ty = param3 - _loc8_;
  283.             param1.beginBitmapFill(this.topShadow,_loc14_);
  284.             param1.drawRect(param2 - _loc6_ + _loc15_,param3 - _loc8_,param4 + _loc6_ + _loc7_ - _loc15_ - _loc17_,_loc8_);
  285.             param1.endFill();
  286.          }
  287.          if(this.bottomShadow)
  288.          {
  289.             _loc14_.tx = 0;
  290.             _loc14_.ty = param3 + param5;
  291.             param1.beginBitmapFill(this.bottomShadow,_loc14_);
  292.             param1.drawRect(param2 - _loc6_ + _loc19_,param3 + param5,param4 + _loc6_ + _loc7_ - _loc19_ - _loc21_,_loc9_);
  293.             param1.endFill();
  294.          }
  295.       }
  296.       
  297.       private function createShadowBitmaps() : void
  298.       {
  299.          var _loc1_:Number = Math.max(this.tlRadius,this.blRadius) + 3 * Math.max(Math.abs(this.distance),2) + Math.max(this.trRadius,this.brRadius);
  300.          var _loc2_:Number = Math.max(this.tlRadius,this.trRadius) + 3 * Math.max(Math.abs(this.distance),2) + Math.max(this.blRadius,this.brRadius);
  301.          if(_loc1_ < 0 || _loc2_ < 0)
  302.          {
  303.             return;
  304.          }
  305.          var _loc3_:Shape = new FlexShape();
  306.          var _loc4_:Graphics = _loc3_.graphics;
  307.          _loc4_.beginFill(16777215);
  308.          GraphicsUtil.drawRoundRectComplex(_loc4_,0,0,_loc1_,_loc2_,this.tlRadius,this.trRadius,this.blRadius,this.brRadius);
  309.          _loc4_.endFill();
  310.          var _loc5_:BitmapData = new BitmapData(_loc1_,_loc2_,true,0);
  311.          _loc5_.draw(_loc3_,new Matrix());
  312.          var _loc6_:DropShadowFilter = new DropShadowFilter(this.distance,this.angle,this.color,this.alpha,this.blurX,this.blurY);
  313.          _loc6_.knockout = true;
  314.          var _loc7_:Rectangle = new Rectangle(0,0,_loc1_,_loc2_);
  315.          var _loc8_:Rectangle = _loc5_.generateFilterRect(_loc7_,_loc6_);
  316.          var _loc9_:Number = _loc7_.left - _loc8_.left;
  317.          var _loc10_:Number = _loc8_.right - _loc7_.right;
  318.          var _loc11_:Number = _loc7_.top - _loc8_.top;
  319.          var _loc12_:Number = _loc8_.bottom - _loc7_.bottom;
  320.          this.shadow = new BitmapData(_loc8_.width,_loc8_.height);
  321.          this.shadow.applyFilter(_loc5_,_loc7_,new Point(_loc9_,_loc11_),_loc6_);
  322.          var _loc13_:Point = new Point(0,0);
  323.          var _loc14_:Rectangle = new Rectangle();
  324.          if(_loc9_ > 0)
  325.          {
  326.             _loc14_.x = 0;
  327.             _loc14_.y = this.tlRadius + _loc11_ + _loc12_;
  328.             _loc14_.width = _loc9_;
  329.             _loc14_.height = 1;
  330.             this.leftShadow = new BitmapData(_loc9_,1);
  331.             this.leftShadow.copyPixels(this.shadow,_loc14_,_loc13_);
  332.          }
  333.          else
  334.          {
  335.             this.leftShadow = null;
  336.          }
  337.          if(_loc10_ > 0)
  338.          {
  339.             _loc14_.x = this.shadow.width - _loc10_;
  340.             _loc14_.y = this.trRadius + _loc11_ + _loc12_;
  341.             _loc14_.width = _loc10_;
  342.             _loc14_.height = 1;
  343.             this.rightShadow = new BitmapData(_loc10_,1);
  344.             this.rightShadow.copyPixels(this.shadow,_loc14_,_loc13_);
  345.          }
  346.          else
  347.          {
  348.             this.rightShadow = null;
  349.          }
  350.          if(_loc11_ > 0)
  351.          {
  352.             _loc14_.x = this.tlRadius + _loc9_ + _loc10_;
  353.             _loc14_.y = 0;
  354.             _loc14_.width = 1;
  355.             _loc14_.height = _loc11_;
  356.             this.topShadow = new BitmapData(1,_loc11_);
  357.             this.topShadow.copyPixels(this.shadow,_loc14_,_loc13_);
  358.          }
  359.          else
  360.          {
  361.             this.topShadow = null;
  362.          }
  363.          if(_loc12_ > 0)
  364.          {
  365.             _loc14_.x = this.blRadius + _loc9_ + _loc10_;
  366.             _loc14_.y = this.shadow.height - _loc12_;
  367.             _loc14_.width = 1;
  368.             _loc14_.height = _loc12_;
  369.             this.bottomShadow = new BitmapData(1,_loc12_);
  370.             this.bottomShadow.copyPixels(this.shadow,_loc14_,_loc13_);
  371.          }
  372.          else
  373.          {
  374.             this.bottomShadow = null;
  375.          }
  376.       }
  377.    }
  378. }
  379.  
  380.