home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 2010 Software/Programs / PCGuia_programas.iso / Software / Utils / Livebrush / Install-LivebrushLite.air / livebrush.swf / scripts / com / livebrush / styles / DecoStyle.as < prev    next >
Encoding:
Text File  |  2009-10-26  |  13.9 KB  |  410 lines

  1. package com.livebrush.styles
  2. {
  3.    import com.livebrush.data.Exchangeable;
  4.    import com.livebrush.data.Settings;
  5.    import com.livebrush.data.Storable;
  6.    import com.livebrush.utils.ColorObj;
  7.    
  8.    public class DecoStyle implements Exchangeable, Storable
  9.    {
  10.       public static const SEQUENCE_DECO:String = "sequence";
  11.       
  12.       public static const FIXED_DECO:String = "fixed";
  13.       
  14.       public static const RANDOM_DECO:String = "random";
  15.       
  16.       public static const A:String = "a";
  17.       
  18.       public static const B:String = "b";
  19.       
  20.       public static const CENTER:String = "center";
  21.       
  22.       public static const ALT:String = "alt";
  23.       
  24.       public static const WIDTH:String = "strokeWidth";
  25.       
  26.       public static const DIR:String = "strokeDirection";
  27.       
  28.       public static const SCATTER:String = "scatter";
  29.       
  30.       public static const ORBIT:String = "orbit";
  31.       
  32.       public static const POS_DIR:String = "posDir";
  33.       
  34.       public static const ROTATE:String = "rotate";
  35.       
  36.       public static const FIXED:String = "fixed";
  37.       
  38.       public static const NONE:String = "none";
  39.       
  40.       public static const OSC:String = "osc";
  41.       
  42.       public static const RANDOM:String = "random";
  43.       
  44.       public static const SPEED:String = "speed";
  45.       
  46.       public static const LIST:String = "list";
  47.       
  48.       public static const STROKE:String = "stroke";
  49.       
  50.       public static const SAMPLE:String = "sample";
  51.       
  52.       public static const ALIGN_CENTER:String = "center";
  53.       
  54.       public static const ALIGN_CORNER:String = "corner";
  55.       
  56.       public static const ALIGN_TL:String = "TL";
  57.       
  58.       public static const ALIGN_TR:String = "TR";
  59.       
  60.       public static const ALIGN_BL:String = "BL";
  61.       
  62.       public static const ALIGN_BR:String = "BR";
  63.       
  64.       public var defaultSettings:Settings;
  65.       
  66.       public var xFlip:Boolean = false;
  67.       
  68.       public var yFlip:Boolean = false;
  69.       
  70.       public var alphaSpeed:Number = 10;
  71.       
  72.       public var colorSteps:int = 50;
  73.       
  74.       public var decoHold:int = 1;
  75.       
  76.       public var maxTint:Number = 0;
  77.       
  78.       public var decoset:XML;
  79.       
  80.       public var decoNum:int = 1;
  81.       
  82.       public var tintSpeed:Number = 1;
  83.       
  84.       public var maxSize:Number = 1;
  85.       
  86.       public var minAngle:Number = 90;
  87.       
  88.       public var minPos:Number = 0;
  89.       
  90.       public var orderType:String = "sequence";
  91.       
  92.       private var _colorList:Array;
  93.       
  94.       public var minAlpha:Number = 0;
  95.       
  96.       public var angleType:String = "strokeDirection";
  97.       
  98.       public var posType:String = "alt";
  99.       
  100.       public var _colorObjList:Array;
  101.       
  102.       public var angleSpeed:Number = 25;
  103.       
  104.       public var style:Style;
  105.       
  106.       public var autoFlip:Boolean = true;
  107.       
  108.       private var _colorType:String = "list";
  109.       
  110.       public var alphaType:String = "stroke";
  111.       
  112.       public var styleManager:StyleManager;
  113.       
  114.       public var sizeSpeed:Number = 10;
  115.       
  116.       public var colorHold:int = 1;
  117.       
  118.       public var selectedDecoIndex:int = 0;
  119.       
  120.       public var maxAngle:Number = 360;
  121.       
  122.       public var posSpeed:Number = 25;
  123.       
  124.       public var persist:Boolean = true;
  125.       
  126.       public var tintType:String = "fixed";
  127.       
  128.       public var maxPos:Number = 1;
  129.       
  130.       public var sizeType:String = "speed";
  131.       
  132.       public var alignType:String = "corner";
  133.       
  134.       public var minTint:Number = 0;
  135.       
  136.       public var maxAlpha:Number = 1;
  137.       
  138.       public var minSize:Number = 0.1;
  139.       
  140.       public var decoSet:DecoSet;
  141.       
  142.       public function DecoStyle(style:Style)
  143.       {
  144.          super();
  145.          this.style = style;
  146.          this.styleManager = style.styleManager;
  147.          this.decoSet = new DecoSet();
  148.          this.decoSet.addDeco("Default");
  149.          this.colorObjList = [new ColorObj(0),new ColorObj(16777215)];
  150.          this.defaultSettings = this.settings;
  151.       }
  152.       
  153.       public function die() : void
  154.       {
  155.          this.decoSet.die();
  156.          delete global[this];
  157.       }
  158.       
  159.       public function get selectedColor() : Number
  160.       {
  161.          return this.colorList[0];
  162.       }
  163.       
  164.       public function get settings() : Settings
  165.       {
  166.          var settings:Settings = new Settings();
  167.          settings.decos = this.decoSet.decos.slice();
  168.          settings.selectedDecoIndex = this.decoSet.selectedDecoIndex;
  169.          settings.orderType = this.orderType;
  170.          settings.posType = this.posType;
  171.          settings.minPos = this.minPos;
  172.          settings.maxPos = this.maxPos;
  173.          settings.posSpeed = this.posSpeed;
  174.          settings.angleType = this.angleType;
  175.          settings.autoFlip = this.autoFlip;
  176.          settings.minAngle = this.minAngle;
  177.          settings.maxAngle = this.maxAngle;
  178.          settings.angleSpeed = this.angleSpeed;
  179.          settings.colorType = this.colorType;
  180.          settings.colorSteps = this.colorSteps;
  181.          settings.colorObjList = Settings.copyArrayOfObjects(this.colorObjList);
  182.          settings.colorHold = this.colorHold;
  183.          settings.alphaType = this.alphaType;
  184.          settings.minAlpha = this.minAlpha;
  185.          settings.maxAlpha = this.maxAlpha;
  186.          settings.alphaSpeed = this.alphaSpeed;
  187.          settings.tintType = this.tintType;
  188.          settings.minTint = this.minTint;
  189.          settings.maxTint = this.maxTint;
  190.          settings.tintSpeed = this.tintSpeed;
  191.          settings.sizeType = this.sizeType;
  192.          settings.minSize = this.minSize;
  193.          settings.maxSize = this.maxSize;
  194.          settings.sizeSpeed = this.sizeSpeed;
  195.          settings.decoNum = this.decoNum;
  196.          settings.decoHold = this.decoHold;
  197.          settings.persist = this.persist;
  198.          settings.alignType = this.alignType;
  199.          return settings;
  200.       }
  201.       
  202.       public function set colorObjList(list:Array) : void
  203.       {
  204.          this._colorObjList = list;
  205.          this._colorList = [];
  206.          var i:int = 0;
  207.          while(i < list.length)
  208.          {
  209.             if(list[i].enabled)
  210.             {
  211.                this._colorList.push(list[i].color);
  212.             }
  213.             i++;
  214.          }
  215.       }
  216.       
  217.       public function get colorList() : Array
  218.       {
  219.          return this._colorList;
  220.       }
  221.       
  222.       public function get colorType() : String
  223.       {
  224.          return this._colorType;
  225.       }
  226.       
  227.       public function get colorStringObjList() : Array
  228.       {
  229.          for(var stringObjList:Array = [],var i:int = 0; i < this.colorObjList.length; stringObjList.push({
  230.             "value":this.colorObjList[i].colorString,
  231.             "enabled":this.colorObjList[i].enabled
  232.          }),i++)
  233.          {
  234.          }
  235.          return stringObjList;
  236.       }
  237.       
  238.       public function set settings(settings:Settings) : void
  239.       {
  240.          this.decoSet.decos = settings.decos;
  241.          this.selectedDecoIndex = settings.selectedDecoIndex;
  242.          this.decoSet.selectedDecoIndex = this.selectedDecoIndex;
  243.          this.orderType = settings.orderType;
  244.          this.posType = settings.posType;
  245.          this.minPos = settings.minPos;
  246.          this.maxPos = settings.maxPos;
  247.          this.posSpeed = settings.posSpeed;
  248.          this.angleType = settings.angleType;
  249.          this.autoFlip = settings.autoFlip;
  250.          this.minAngle = settings.minAngle;
  251.          this.maxAngle = settings.maxAngle;
  252.          this.angleSpeed = settings.angleSpeed;
  253.          this.sizeType = settings.sizeType;
  254.          this.minSize = settings.minSize;
  255.          this.maxSize = settings.maxSize;
  256.          this.sizeSpeed = settings.sizeSpeed;
  257.          this.colorType = settings.colorType;
  258.          this.colorObjList = settings.colorObjList.slice();
  259.          this.colorSteps = settings.colorSteps;
  260.          this.colorHold = settings.colorHold;
  261.          this.tintType = settings.tintType;
  262.          this.minTint = settings.minTint;
  263.          this.maxTint = settings.maxTint;
  264.          this.tintSpeed = settings.tintSpeed;
  265.          this.alphaType = settings.alphaType;
  266.          this.minAlpha = settings.minAlpha;
  267.          this.maxAlpha = settings.maxAlpha;
  268.          this.alphaSpeed = settings.alphaSpeed;
  269.          this.decoNum = settings.decoNum;
  270.          this.decoHold = settings.decoHold;
  271.          this.persist = settings.persist;
  272.          this.alignType = settings.alignType;
  273.       }
  274.       
  275.       public function get colorObjList() : Array
  276.       {
  277.          return this._colorObjList;
  278.       }
  279.       
  280.       public function clone(style:Style) : DecoStyle
  281.       {
  282.          var decoStyle:DecoStyle = new DecoStyle(style);
  283.          decoStyle.settings = this.settings;
  284.          decoStyle.decoSet = this.decoSet.clone();
  285.          return decoStyle;
  286.       }
  287.       
  288.       public function setXML(xml:String) : void
  289.       {
  290.          var i:int;
  291.          var element:XML = null;
  292.          var decoList:Array = null;
  293.          var decoXML:XML = new XML(xml);
  294.          for each(element in decoXML.*)
  295.          {
  296.             try
  297.             {
  298.                if(element.name() != "colorList" && element.name() != "decoList")
  299.                {
  300.                   if(element == "true" || element == "false")
  301.                   {
  302.                      this[element.name()] = element == "true" ? true : false;
  303.                   }
  304.                   else
  305.                   {
  306.                      this[element.name()] = element;
  307.                   }
  308.                }
  309.                else if(element.name() == "colorList")
  310.                {
  311.                   this.colorObjList = Style.objListToColorObjList(Style.propEnabledXMLToList(decoXML.colorList.color));
  312.                }
  313.             }
  314.             catch(e:Error)
  315.             {
  316.             }
  317.          }
  318.          if(this.colorObjList == null || this.colorObjList.length == 0)
  319.          {
  320.             this.colorObjList = [new ColorObj(16711680,true)];
  321.          }
  322.          this.decoSet.die();
  323.          this.decoSet = new DecoSet();
  324.          this.decoSet.selectedDecoIndex = this.selectedDecoIndex;
  325.          try
  326.          {
  327.             decoList = Style.propEnabledXMLToList(decoXML.decoList.deco);
  328.          }
  329.          catch(e:Error)
  330.          {
  331.          }
  332.          for(i = 0; i < decoList.length; i++)
  333.          {
  334.             try
  335.             {
  336.                this.addDeco(decoList[i].value,decoList[i].enabled);
  337.             }
  338.             catch(e:Error)
  339.             {
  340.             }
  341.          }
  342.          try
  343.          {
  344.             this.decoSet.decos = this.decoSet.decos;
  345.          }
  346.          catch(e:Error)
  347.          {
  348.          }
  349.       }
  350.       
  351.       public function addDeco(assetPath:String, enabled:Boolean = true) : void
  352.       {
  353.          this.decoSet.addDeco(assetPath,enabled,false,this.selectedDecoIndex);
  354.       }
  355.       
  356.       public function get selectedDecoAsset() : DecoAsset
  357.       {
  358.          return this.decoSet.getDecoByIndex(this.selectedDecoIndex);
  359.       }
  360.       
  361.       public function getXML() : XML
  362.       {
  363.          var decoXML:XML = new XML(<deco/>);
  364.          decoXML.appendChild(Style.propEnabledListToXML(this.decoSet.decos,"value","enabled","deco"));
  365.          decoXML.appendChild(Settings.varStringToXML("orderType",this));
  366.          decoXML.appendChild(Settings.varStringToXML("selectedDecoIndex",this));
  367.          decoXML.appendChild(Settings.varStringToXML("decoNum",this));
  368.          decoXML.appendChild(Settings.varStringToXML("decoHold",this));
  369.          decoXML.appendChild(Settings.varStringToXML("alignType",this));
  370.          decoXML.appendChild(Settings.varStringToXML("persist",this));
  371.          decoXML.appendChild(Settings.varStringToXML("posType",this));
  372.          decoXML.appendChild(Settings.varStringToXML("minPos",this));
  373.          decoXML.appendChild(Settings.varStringToXML("maxPos",this));
  374.          decoXML.appendChild(Settings.varStringToXML("posSpeed",this));
  375.          decoXML.appendChild(Settings.varStringToXML("angleType",this));
  376.          decoXML.appendChild(Settings.varStringToXML("autoFlip",this));
  377.          decoXML.appendChild(Settings.varStringToXML("minAngle",this));
  378.          decoXML.appendChild(Settings.varStringToXML("maxAngle",this));
  379.          decoXML.appendChild(Settings.varStringToXML("angleSpeed",this));
  380.          decoXML.appendChild(Settings.varStringToXML("sizeType",this));
  381.          decoXML.appendChild(Settings.varStringToXML("minSize",this));
  382.          decoXML.appendChild(Settings.varStringToXML("maxSize",this));
  383.          decoXML.appendChild(Settings.varStringToXML("sizeSpeed",this));
  384.          decoXML.appendChild(Settings.varStringToXML("sizeType",this));
  385.          decoXML.appendChild(Settings.varStringToXML("minSize",this));
  386.          decoXML.appendChild(Settings.varStringToXML("maxSize",this));
  387.          decoXML.appendChild(Settings.varStringToXML("sizeSpeed",this));
  388.          decoXML.appendChild(Settings.varStringToXML("colorType",this));
  389.          decoXML.appendChild(Settings.varStringToXML("colorSteps",this));
  390.          decoXML.appendChild(Style.propEnabledListToXML(this.colorStringObjList,"value","enabled","color"));
  391.          decoXML.appendChild(Settings.varStringToXML("colorHold",this));
  392.          decoXML.appendChild(Settings.varStringToXML("tintType",this));
  393.          decoXML.appendChild(Settings.varStringToXML("minTint",this));
  394.          decoXML.appendChild(Settings.varStringToXML("maxTint",this));
  395.          decoXML.appendChild(Settings.varStringToXML("tintSpeed",this));
  396.          decoXML.appendChild(Settings.varStringToXML("alphaType",this));
  397.          decoXML.appendChild(Settings.varStringToXML("minAlpha",this));
  398.          decoXML.appendChild(Settings.varStringToXML("maxAlpha",this));
  399.          decoXML.appendChild(Settings.varStringToXML("alphaSpeed",this));
  400.          return decoXML;
  401.       }
  402.       
  403.       public function set colorType(s:String) : void
  404.       {
  405.          this._colorType = s;
  406.       }
  407.    }
  408. }
  409.  
  410.