home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Multimedija / shufflr.air / ShufflrClient.swf / scripts / com / gradientcomponents / GradientHBox.as < prev    next >
Encoding:
Text File  |  2010-06-23  |  19.4 KB  |  572 lines

  1. package com.gradientcomponents
  2. {
  3.    import flash.display.Graphics;
  4.    import flash.geom.Matrix;
  5.    import mx.containers.HBox;
  6.    import mx.utils.ArrayUtil;
  7.    
  8.    public class GradientHBox extends HBox
  9.    {
  10.       public static const DEFAULT_GRADIENTTYPE:String = "linear";
  11.       
  12.       public static const DEFAULT_FILLCOLORS:String = "0xFFFFFF";
  13.       
  14.       public static const DEFAULT_COLORSCONFIGURATION:Number = 1;
  15.       
  16.       public static const DEFAULT_FILLALPHAS:Number = 1;
  17.       
  18.       public static const DEFAULT_GRADIENTRATIO:Number = 255;
  19.       
  20.       public static const DEFAULT_BORDERTHICKNESS:Number = 0;
  21.       
  22.       public static const DEFAULT_ANGLE:Number = 0;
  23.       
  24.       public static const DEFAULT_POSITIONING:String = "absolute";
  25.       
  26.       public static const POSITIONING_ABSOLUTE:String = "absolute";
  27.       
  28.       public static const POSITIONING_PERCENT:String = "percentage";
  29.       
  30.       public static const DEFAULT_OFFSETX:Number = 0;
  31.       
  32.       public static const DEFAULT_OFFSETY:Number = 0;
  33.       
  34.       public static const DEFAULT_SPREADMETHOD:String = "pad";
  35.       
  36.       public static const DEFAULT_INTERPOLATIONMETHOD:String = "rgb";
  37.       
  38.       public static const DEFAULT_FOCALPOINTRATIO:Number = 0;
  39.       
  40.       public static const DEFAULT_CORNERRADIUS:Number = 0;
  41.       
  42.       public static const DEFAULT_TOPLEFTRADIUS:Number = 0;
  43.       
  44.       public static const DEFAULT_TOPRIGHTRADIUS:Number = 0;
  45.       
  46.       public static const DEFAULT_BOTTOMLEFTRADIUS:Number = 0;
  47.       
  48.       public static const DEFAULT_BOTTOMRIGHTRADIUS:Number = 0;
  49.       
  50.       private var _boffsetx:Number;
  51.       
  52.       private var _boffsety:Number;
  53.       
  54.       private var _offsetx:Array;
  55.       
  56.       private var _offsety:Array;
  57.       
  58.       private var _colorsconfig:Array = new Array(1);
  59.       
  60.       private var _spreadMethod:String;
  61.       
  62.       private var _bspreadMethod:String;
  63.       
  64.       private var _bottomRightRadius:Number;
  65.       
  66.       private var _topLeftRadius:Number;
  67.       
  68.       private var _bgradientRatio:Array;
  69.       
  70.       private var _ngradients:Number = this._colorsconfig.length;
  71.       
  72.       private var _gradientRatio:Array;
  73.       
  74.       private var _bangle:Number;
  75.       
  76.       private var _angle:Array;
  77.       
  78.       private var _fillAlphas:Array;
  79.       
  80.       private var _topRightRadius:Number;
  81.       
  82.       private var _bfillAlphas:Array;
  83.       
  84.       private var _bfocalPointRatio:Number;
  85.       
  86.       private var _focalPointRatio:Array;
  87.       
  88.       private var _binterpolationMethod:String;
  89.       
  90.       private var _bottomLeftRadius:Number;
  91.       
  92.       private var _interpolationMethod:String;
  93.       
  94.       private var _gradientType:String;
  95.       
  96.       private var _bgradientType:String;
  97.       
  98.       private var _borderThickness:Number;
  99.       
  100.       private var bStylePropChanged:Boolean = true;
  101.       
  102.       private var _fillColors:Array;
  103.       
  104.       private var _bfillColors:Array;
  105.       
  106.       private var _positioning:String;
  107.       
  108.       public function GradientHBox()
  109.       {
  110.          super();
  111.       }
  112.       
  113.       private function getAllStyles() : void
  114.       {
  115.          var _loc1_:Array = null;
  116.          var _loc2_:Number = NaN;
  117.          var _loc3_:Number = NaN;
  118.          var _loc4_:Array = null;
  119.          if(getStyle("gradientType") != undefined)
  120.          {
  121.             this._gradientType = getStyle("gradientType");
  122.          }
  123.          else
  124.          {
  125.             this._gradientType = DEFAULT_GRADIENTTYPE;
  126.          }
  127.          if(getStyle("bordergradientType") != undefined)
  128.          {
  129.             this._bgradientType = getStyle("bordergradientType");
  130.          }
  131.          else
  132.          {
  133.             this._bgradientType = DEFAULT_GRADIENTTYPE;
  134.          }
  135.          if(getStyle("colorsConfiguration") != undefined)
  136.          {
  137.             this._colorsconfig = ArrayUtil.toArray(getStyle("colorsConfiguration"));
  138.          }
  139.          else
  140.          {
  141.             this._ngradients = this._colorsconfig.length;
  142.          }
  143.          if(getStyle("fillColors") != undefined)
  144.          {
  145.             this._fillColors = [];
  146.             _loc1_ = [];
  147.             _loc1_ = getStyle("fillColors").toString().split(",");
  148.             _loc2_ = 0;
  149.             while(_loc2_ < this._colorsconfig.length)
  150.             {
  151.                this._fillColors.push(_loc1_.slice(0,this._colorsconfig[_loc2_]));
  152.                _loc1_ = _loc1_.slice(this._colorsconfig[_loc2_]);
  153.                _loc2_++;
  154.             }
  155.          }
  156.          else
  157.          {
  158.             this._fillColors = new Array(DEFAULT_FILLCOLORS);
  159.          }
  160.          if(getStyle("borderColors") != undefined)
  161.          {
  162.             this._bfillColors = [];
  163.             _loc1_ = [];
  164.             _loc1_ = getStyle("borderColors").toString().split(",");
  165.             _loc3_ = 0;
  166.             while(_loc3_ < _loc1_.length)
  167.             {
  168.                this._bfillColors.push(_loc1_[_loc3_]);
  169.                _loc3_++;
  170.             }
  171.          }
  172.          else
  173.          {
  174.             this._bfillColors = new Array(DEFAULT_FILLCOLORS);
  175.          }
  176.          if(getStyle("borderThickness") != undefined)
  177.          {
  178.             this._borderThickness = getStyle("borderThickness");
  179.          }
  180.          else
  181.          {
  182.             this._borderThickness = DEFAULT_BORDERTHICKNESS;
  183.          }
  184.          if(getStyle("fillAlphas") != undefined)
  185.          {
  186.             this._fillAlphas = [];
  187.             _loc1_ = [];
  188.             _loc1_ = getStyle("fillAlphas").toString().split(",");
  189.             _loc2_ = 0;
  190.             while(_loc2_ < this._colorsconfig.length)
  191.             {
  192.                this._fillAlphas.push(_loc1_.slice(0,this._colorsconfig[_loc2_]));
  193.                _loc1_ = _loc1_.slice(this._colorsconfig[_loc2_]);
  194.                _loc2_++;
  195.             }
  196.          }
  197.          else
  198.          {
  199.             this._fillAlphas = [];
  200.             _loc2_ = 0;
  201.             while(_loc2_ < this._colorsconfig.length)
  202.             {
  203.                _loc1_ = new Array();
  204.                _loc3_ = 0;
  205.                while(_loc3_ < this._colorsconfig[_loc2_])
  206.                {
  207.                   _loc1_.push(DEFAULT_FILLALPHAS);
  208.                   _loc3_++;
  209.                }
  210.                this._fillAlphas.push(_loc1_);
  211.                _loc2_++;
  212.             }
  213.          }
  214.          if(getStyle("borderAlphas") != undefined)
  215.          {
  216.             this._bfillAlphas = [];
  217.             _loc1_ = [];
  218.             _loc1_ = getStyle("borderAlphas").toString().split(",");
  219.             _loc3_ = 0;
  220.             while(_loc3_ < _loc1_.length)
  221.             {
  222.                this._bfillAlphas.push(_loc1_[_loc3_]);
  223.                _loc3_++;
  224.             }
  225.          }
  226.          else
  227.          {
  228.             this._bfillAlphas = [];
  229.             _loc2_ = 0;
  230.             while(_loc2_ < this._bfillColors.length)
  231.             {
  232.                this._bfillAlphas.push(DEFAULT_FILLALPHAS);
  233.                _loc2_++;
  234.             }
  235.          }
  236.          if(getStyle("gradientRatio") != undefined)
  237.          {
  238.             this._gradientRatio = getStyle("gradientRatio");
  239.             _loc1_ = [];
  240.             _loc1_ = getStyle("gradientRatio").toString().split(",");
  241.             _loc4_ = [];
  242.             _loc2_ = 0;
  243.             while(_loc2_ < this._colorsconfig.length)
  244.             {
  245.                _loc4_.push(_loc1_.slice(0,this._colorsconfig[_loc2_]));
  246.                _loc1_ = _loc1_.slice(this._colorsconfig[_loc2_]);
  247.                _loc2_++;
  248.             }
  249.             this._gradientRatio = _loc4_;
  250.          }
  251.          else
  252.          {
  253.             this._gradientRatio = [];
  254.             _loc2_ = 0;
  255.             while(_loc2_ < this._colorsconfig.length)
  256.             {
  257.                this._gradientRatio.push(this.generateDefaultRatio(this._colorsconfig[_loc2_]));
  258.                _loc2_++;
  259.             }
  260.          }
  261.          if(getStyle("bordergradientRatio") != undefined)
  262.          {
  263.             this._bgradientRatio = getStyle("bordergradientRatio");
  264.          }
  265.          else
  266.          {
  267.             this._bgradientRatio = [];
  268.             _loc2_ = 0;
  269.             while(_loc2_ < this._bfillColors.length)
  270.             {
  271.                this._bgradientRatio = this.generateDefaultRatio(this._bfillColors.length);
  272.                _loc2_++;
  273.             }
  274.          }
  275.          if(getStyle("angle") != undefined)
  276.          {
  277.             _loc1_ = [];
  278.             _loc1_.push(getStyle("angle"));
  279.             this._angle = _loc1_[0].toString().split(",");
  280.          }
  281.          else
  282.          {
  283.             this._angle = [];
  284.             _loc2_ = 0;
  285.             while(_loc2_ < this._colorsconfig.length)
  286.             {
  287.                this._angle.push(DEFAULT_ANGLE);
  288.                _loc2_++;
  289.             }
  290.          }
  291.          if(getStyle("borderAngle") != undefined)
  292.          {
  293.             this._bangle = getStyle("borderAngle");
  294.          }
  295.          else
  296.          {
  297.             this._bangle = DEFAULT_ANGLE;
  298.          }
  299.          if(getStyle("spreadMethod") != undefined)
  300.          {
  301.             this._spreadMethod = getStyle("spreadMethod");
  302.          }
  303.          else
  304.          {
  305.             this._spreadMethod = DEFAULT_SPREADMETHOD;
  306.          }
  307.          if(getStyle("borderSpreadMethod") != undefined)
  308.          {
  309.             this._bspreadMethod = getStyle("borderSpreadMethod");
  310.          }
  311.          else
  312.          {
  313.             this._bspreadMethod = DEFAULT_SPREADMETHOD;
  314.          }
  315.          if(getStyle("interpolationMethod") != undefined)
  316.          {
  317.             this._interpolationMethod = getStyle("interpolationMethod");
  318.          }
  319.          else
  320.          {
  321.             this._interpolationMethod = DEFAULT_INTERPOLATIONMETHOD;
  322.          }
  323.          if(getStyle("borderInterpolationMethod") != undefined)
  324.          {
  325.             this._binterpolationMethod = getStyle("borderInterpolationMethod");
  326.          }
  327.          else
  328.          {
  329.             this._binterpolationMethod = DEFAULT_INTERPOLATIONMETHOD;
  330.          }
  331.          if(getStyle("focalPointRatio") != undefined)
  332.          {
  333.             this._focalPointRatio = [];
  334.             _loc1_ = [];
  335.             _loc1_.push(getStyle("focalPointRatio"));
  336.             this._focalPointRatio = _loc1_[0].toString().split(",");
  337.          }
  338.          else
  339.          {
  340.             this._focalPointRatio = [];
  341.             _loc2_ = 0;
  342.             while(_loc2_ < this._colorsconfig.length)
  343.             {
  344.                this._focalPointRatio.push(DEFAULT_FOCALPOINTRATIO);
  345.                _loc2_++;
  346.             }
  347.          }
  348.          if(getStyle("borderfocalPointRatio") != undefined)
  349.          {
  350.             this._bfocalPointRatio = getStyle("borderfocalPointRatio");
  351.          }
  352.          else
  353.          {
  354.             this._bfocalPointRatio = DEFAULT_FOCALPOINTRATIO;
  355.          }
  356.          if(getStyle("positioning") != undefined)
  357.          {
  358.             this._positioning = getStyle("positioning");
  359.          }
  360.          else
  361.          {
  362.             this._positioning = DEFAULT_POSITIONING;
  363.          }
  364.          if(getStyle("offsetX") != undefined)
  365.          {
  366.             _loc1_ = [];
  367.             _loc1_.push(getStyle("offsetX"));
  368.             this._offsetx = _loc1_[0].toString().split(",");
  369.          }
  370.          else
  371.          {
  372.             this._offsetx = [];
  373.             _loc2_ = 0;
  374.             while(_loc2_ < this._colorsconfig.length)
  375.             {
  376.                this._offsetx.push(DEFAULT_OFFSETX);
  377.                _loc2_++;
  378.             }
  379.          }
  380.          if(getStyle("borderOffsetX") != undefined)
  381.          {
  382.             this._boffsetx = getStyle("borderOffsetX");
  383.          }
  384.          else
  385.          {
  386.             this._boffsetx = DEFAULT_OFFSETX;
  387.          }
  388.          if(getStyle("offsetY") != undefined)
  389.          {
  390.             _loc1_ = [];
  391.             _loc1_.push(getStyle("offsetY"));
  392.             this._offsety = _loc1_[0].toString().split(",");
  393.          }
  394.          else
  395.          {
  396.             this._offsety = [];
  397.             _loc2_ = 0;
  398.             while(_loc2_ < this._colorsconfig.length)
  399.             {
  400.                this._offsety.push(DEFAULT_OFFSETY);
  401.                _loc2_++;
  402.             }
  403.          }
  404.          if(getStyle("borderOffsetY") != undefined)
  405.          {
  406.             this._boffsety = getStyle("borderOffsetY");
  407.          }
  408.          else
  409.          {
  410.             this._boffsety = DEFAULT_OFFSETY;
  411.          }
  412.          if(getStyle("topLeftRadius") != 0 && getStyle("topLeftRadius") != undefined || getStyle("topRightRadius") != 0 && getStyle("topRightRadius") != undefined || getStyle("bottomLeftRadius") != 0 && getStyle("bottomLeftRadius") != undefined || getStyle("bottomRightRadius") != 0 && getStyle("bottomRightRadius") != undefined)
  413.          {
  414.             if(getStyle("topLeftRadius") != undefined)
  415.             {
  416.                this._topLeftRadius = getStyle("topLeftRadius");
  417.             }
  418.             else
  419.             {
  420.                this._topLeftRadius = DEFAULT_TOPLEFTRADIUS;
  421.             }
  422.             if(getStyle("topRightRadius") != undefined)
  423.             {
  424.                this._topRightRadius = getStyle("topRightRadius");
  425.             }
  426.             else
  427.             {
  428.                this._topRightRadius = DEFAULT_TOPRIGHTRADIUS;
  429.             }
  430.             if(getStyle("bottomLeftRadius") != undefined)
  431.             {
  432.                this._bottomLeftRadius = getStyle("bottomLeftRadius");
  433.             }
  434.             else
  435.             {
  436.                this._bottomLeftRadius = DEFAULT_BOTTOMLEFTRADIUS;
  437.             }
  438.             if(getStyle("bottomRightRadius") != undefined)
  439.             {
  440.                this._bottomRightRadius = getStyle("bottomRightRadius");
  441.             }
  442.             else
  443.             {
  444.                this._bottomRightRadius = DEFAULT_BOTTOMRIGHTRADIUS;
  445.             }
  446.          }
  447.          else
  448.          {
  449.             this._topLeftRadius = getStyle("cornerRadius");
  450.             this._topRightRadius = getStyle("cornerRadius");
  451.             this._bottomLeftRadius = getStyle("cornerRadius");
  452.             this._bottomRightRadius = getStyle("cornerRadius");
  453.          }
  454.       }
  455.       
  456.       override public function styleChanged(param1:String) : void
  457.       {
  458.          super.styleChanged(param1);
  459.          if(param1 == "fillColors" || param1 == "fillAlphas" || param1 == "cornerRadius" || param1 == "angle" || param1 == "spreadMethod" || param1 == "gradientType" || param1 == "gradientRatio" || param1 == "offsetX" || param1 == "offsetY" || param1 == "positioning" || param1 == "interpolationMethod" || param1 == "topLeftRadius" || param1 == "topRightRadius" || param1 == "bottomLeftRadius" || param1 == "bottomRightRadius" || param1 == "focalPointRatio" || param1 == "gradientType" || param1 == "borderColors" || param1 == "borderAlphas" || param1 == "bordergradientRatio" || param1 == "borderThickness" || param1 == "borderOffsetX" || param1 == "borderOffsetY" || param1 == "borderfocalPointRatio" || param1 == "borderSpreadMethod" || param1 == "borderInterpolationMethod" || param1 == "borderAngle" || param1 == "colorsConfiguration")
  460.          {
  461.             this.bStylePropChanged = true;
  462.             invalidateDisplayList();
  463.             return;
  464.          }
  465.       }
  466.       
  467.       private function drawRect(param1:Number, param2:Number, param3:Number, param4:Number, param5:Object = null, param6:Object = null, param7:Object = null, param8:Object = null, param9:String = null, param10:Array = null, param11:String = null, param12:String = null, param13:Number = 0, param14:Object = null) : void
  468.       {
  469.          if(!param3 || !param4)
  470.          {
  471.             return;
  472.          }
  473.          var _loc15_:Graphics = graphics;
  474.          _loc15_.beginGradientFill(param9,param6 as Array,param7 as Array,param10,param8 as Matrix,param11,param12,param13);
  475.          _loc15_.drawRoundRectComplex(param1,param2,param3,param4,param5.tl,param5.tr,param5.bl,param5.br);
  476.          if(param14)
  477.          {
  478.             _loc15_.drawRoundRectComplex(param14.x,param14.y,param14.w,param14.h,param5.tl,param5.tr,param5.bl,param5.br);
  479.          }
  480.          _loc15_.endFill();
  481.       }
  482.       
  483.       public function set colorsConfiguration(param1:Array) : void
  484.       {
  485.          this._colorsconfig = param1;
  486.          invalidateDisplayList();
  487.       }
  488.       
  489.       private function generateDefaultRatio(param1:Number) : Array
  490.       {
  491.          var _loc5_:Number = NaN;
  492.          var _loc2_:Number = 255 / (param1 - 1);
  493.          var _loc3_:Array = [];
  494.          var _loc4_:int = 0;
  495.          while(_loc4_ < param1)
  496.          {
  497.             _loc5_ = 255 - _loc2_ * _loc4_;
  498.             _loc3_.push(_loc5_);
  499.             _loc3_.sort(Array.NUMERIC);
  500.             _loc4_++;
  501.          }
  502.          return _loc3_;
  503.       }
  504.       
  505.       public function get colorsConfiguration() : Array
  506.       {
  507.          return this._colorsconfig;
  508.       }
  509.       
  510.       public function get numberGradients() : Number
  511.       {
  512.          return this._colorsconfig.length;
  513.       }
  514.       
  515.       override protected function updateDisplayList(param1:Number, param2:Number) : void
  516.       {
  517.          var _loc3_:Graphics = null;
  518.          var _loc4_:Object = null;
  519.          var _loc5_:int = 0;
  520.          var _loc6_:int = 0;
  521.          var _loc7_:Matrix = null;
  522.          var _loc8_:Number = NaN;
  523.          var _loc9_:Number = NaN;
  524.          var _loc10_:Matrix = null;
  525.          var _loc11_:Object = null;
  526.          super.updateDisplayList(param1,param2);
  527.          if(this.bStylePropChanged == true)
  528.          {
  529.             this.getAllStyles();
  530.             _loc3_ = graphics;
  531.             _loc3_.clear();
  532.             _loc4_ = {
  533.                "tl":this._topLeftRadius,
  534.                "tr":this._topRightRadius,
  535.                "bl":this._bottomLeftRadius,
  536.                "br":this._bottomRightRadius
  537.             };
  538.             _loc5_ = int(this._colorsconfig.length);
  539.             _loc6_ = 0;
  540.             while(_loc6_ < _loc5_)
  541.             {
  542.                _loc7_ = new Matrix();
  543.                if(this._positioning == POSITIONING_ABSOLUTE)
  544.                {
  545.                   _loc7_.createGradientBox(param1,param2,Math.PI * this._angle[_loc6_] / 180,this._offsetx[_loc6_],this._offsety[_loc6_]);
  546.                }
  547.                else if(this._positioning == POSITIONING_PERCENT)
  548.                {
  549.                   _loc8_ = this._offsetx[_loc6_] * param1 / 100;
  550.                   _loc9_ = this._offsety[_loc6_] * param2 / 100;
  551.                   _loc7_.createGradientBox(param1,param2,Math.PI * this._angle[_loc6_] / 180,_loc8_,_loc9_);
  552.                }
  553.                this.drawRect(0,0,param1,param2,_loc4_,this._fillColors[_loc6_],this._fillAlphas[_loc6_],_loc7_,this._gradientType.split(",")[_loc6_],this._gradientRatio[_loc6_],this._spreadMethod.split(",")[_loc6_],this._interpolationMethod.split(",")[_loc6_],this._focalPointRatio[_loc6_]);
  554.                _loc6_++;
  555.             }
  556.             if(this._borderThickness > 0)
  557.             {
  558.                _loc10_ = new Matrix();
  559.                _loc10_.createGradientBox(param1 + 2 * this._borderThickness,param2 + 2 * this._borderThickness,Math.PI * this._bangle / 180,this._boffsetx,this._boffsety);
  560.                _loc11_ = new Object();
  561.                _loc11_.x = 0;
  562.                _loc11_.y = 0;
  563.                _loc11_.w = param1;
  564.                _loc11_.h = param2;
  565.                this.drawRect(-this._borderThickness,-this._borderThickness,param1 + 2 * this._borderThickness,param2 + 2 * this._borderThickness,_loc4_,this._bfillColors,this._bfillAlphas,_loc10_,this._bgradientType,this._bgradientRatio,this._bspreadMethod,this._binterpolationMethod,this._bfocalPointRatio,_loc11_);
  566.             }
  567.          }
  568.       }
  569.    }
  570. }
  571.  
  572.