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 / StrokeStyle.as < prev    next >
Encoding:
Text File  |  2009-10-26  |  12.5 KB  |  378 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 StrokeStyle implements Exchangeable, Storable
  9.    {
  10.       public static const SOLID_STROKE:String = "solid";
  11.       
  12.       public static const RAKE_STROKE:String = "rake";
  13.       
  14.       public static const PATH_STROKE:String = "path";
  15.       
  16.       public static const WIDTH:String = "width";
  17.       
  18.       public static const DIR:String = "direction";
  19.       
  20.       public static const ROTATE:String = "rotate";
  21.       
  22.       public static const FIXED:String = "fixed";
  23.       
  24.       public static const NONE:String = "none";
  25.       
  26.       public static const OSC:String = "osc";
  27.       
  28.       public static const RANDOM:String = "random";
  29.       
  30.       public static const SPEED:String = "speed";
  31.       
  32.       public static const LIST:String = "list";
  33.       
  34.       public static const SAMPLE:String = "sample";
  35.       
  36.       public static const SAMPLE_BRUSH:String = "sampleBrush";
  37.       
  38.       public static const SMOOTH:String = "smooth";
  39.       
  40.       public static const STRAIGHT:String = "straight";
  41.       
  42.       public var defaultSettings:Settings;
  43.       
  44.       public var weight:Number = 1;
  45.       
  46.       public var alphaSpeed:Number = 10;
  47.       
  48.       public var strokeType:String = "solid";
  49.       
  50.       public var colorSteps:int = 50;
  51.       
  52.       public var minWidth:Number = 2;
  53.       
  54.       public var widthType:String = "speed";
  55.       
  56.       public var minAngle:Number = 0;
  57.       
  58.       private var _colorList:Array;
  59.       
  60.       public var minAlpha:Number = 1;
  61.       
  62.       public var angleType:String = "direction";
  63.       
  64.       public var widthSpeed:Number = 50;
  65.       
  66.       public var _colorObjList:Array;
  67.       
  68.       public var angleSpeed:Number = 50;
  69.       
  70.       public var alphaType:String = "fixed";
  71.       
  72.       public var styleManager:StyleManager;
  73.       
  74.       private var _colorType:String = "list";
  75.       
  76.       private var _colorHold:int = 1;
  77.       
  78.       public var maxWidth:Number = 75;
  79.       
  80.       public var maxAngle:Number = 180;
  81.       
  82.       public var style:Style;
  83.       
  84.       public var maxAlpha:Number = 1;
  85.       
  86.       public var thresholds:Object;
  87.       
  88.       private var _decorate:Boolean = true;
  89.       
  90.       public var lines:int = 2;
  91.       
  92.       public function StrokeStyle(style:Style)
  93.       {
  94.          super();
  95.          this.style = style;
  96.          this.colorObjList = [new ColorObj(0),new ColorObj(16777215)];
  97.          this.styleManager = style.styleManager;
  98.          this.thresholds = {
  99.             "speed":{
  100.                "min":50,
  101.                "max":100,
  102.                "enabled":false
  103.             },
  104.             "width":{
  105.                "min":50,
  106.                "max":100,
  107.                "enabled":false
  108.             },
  109.             "angle":{
  110.                "min":0,
  111.                "max":180,
  112.                "enabled":false
  113.             },
  114.             "distance":{
  115.                "min":100,
  116.                "max":500,
  117.                "enabled":false
  118.             },
  119.             "random":{
  120.                "min":10,
  121.                "max":10,
  122.                "enabled":false
  123.             },
  124.             "interval":{
  125.                "min":1000,
  126.                "max":1000,
  127.                "enabled":false
  128.             }
  129.          };
  130.          this.defaultSettings = this.settings;
  131.       }
  132.       
  133.       public function die() : void
  134.       {
  135.          delete global[this];
  136.       }
  137.       
  138.       public function get decorate() : Boolean
  139.       {
  140.          return this.style.decoStyle.decoSet.activeLength > 0 ? this._decorate : false;
  141.       }
  142.       
  143.       private function setDecorate() : void
  144.       {
  145.          var propT:String = null;
  146.          this.decorate = false;
  147.          for(propT in this.thresholds)
  148.          {
  149.             this.decorate = this.decorate ? true : Boolean(this.thresholds[propT].enabled);
  150.          }
  151.          this.decorate = this.decorate ? this.style.decoStyle.decoSet.activeLength > 0 : false;
  152.       }
  153.       
  154.       public function get selectedColor() : Number
  155.       {
  156.          return this.colorList[0];
  157.       }
  158.       
  159.       public function set decorate(b:Boolean) : void
  160.       {
  161.          this._decorate = b;
  162.       }
  163.       
  164.       public function set colorHold(n:Number) : void
  165.       {
  166.          this._colorHold = Math.max(1,n);
  167.       }
  168.       
  169.       public function get settings() : Settings
  170.       {
  171.          var settings:Settings = new Settings();
  172.          settings.strokeType = this.strokeType;
  173.          settings.lines = this.lines;
  174.          settings.weight = this.weight;
  175.          settings.angleType = this.angleType;
  176.          settings.minAngle = this.minAngle;
  177.          settings.maxAngle = this.maxAngle;
  178.          settings.angleSpeed = this.angleSpeed;
  179.          settings.widthType = this.widthType;
  180.          settings.minWidth = this.minWidth;
  181.          settings.maxWidth = this.maxWidth;
  182.          settings.widthSpeed = this.widthSpeed;
  183.          settings.colorType = this.colorType;
  184.          settings.colorSteps = this.colorSteps;
  185.          settings.colorObjList = Settings.copyArrayOfObjects(this.colorObjList);
  186.          settings.colorHold = this.colorHold;
  187.          settings.alphaType = this.alphaType;
  188.          settings.minAlpha = this.minAlpha;
  189.          settings.maxAlpha = this.maxAlpha;
  190.          settings.alphaSpeed = this.alphaSpeed;
  191.          settings.thresholds = Settings.copyObject(this.thresholds);
  192.          return settings;
  193.       }
  194.       
  195.       public function set colorObjList(list:Array) : void
  196.       {
  197.          this._colorObjList = list;
  198.          this._colorList = [];
  199.          var i:int = 0;
  200.          while(i < list.length)
  201.          {
  202.             if(list[i].enabled)
  203.             {
  204.                this._colorList.push(list[i].color);
  205.             }
  206.             i++;
  207.          }
  208.       }
  209.       
  210.       public function get colorList() : Array
  211.       {
  212.          return this._colorList;
  213.       }
  214.       
  215.       public function get colorType() : String
  216.       {
  217.          return this._colorType;
  218.       }
  219.       
  220.       public function get colorStringObjList() : Array
  221.       {
  222.          for(var stringObjList:Array = [],var i:int = 0; i < this.colorObjList.length; stringObjList.push({
  223.             "value":this.colorObjList[i].colorString,
  224.             "enabled":this.colorObjList[i].enabled
  225.          }),i++)
  226.          {
  227.          }
  228.          return stringObjList;
  229.       }
  230.       
  231.       public function set settings(settings:Settings) : void
  232.       {
  233.          var propT:String = null;
  234.          var prop:String = null;
  235.          for(propT in settings.thresholds)
  236.          {
  237.             this.thresholds[propT] = settings.thresholds[propT];
  238.          }
  239.          this.setDecorate();
  240.          for(prop in settings)
  241.          {
  242.             if(prop != "thresholds")
  243.             {
  244.                try
  245.                {
  246.                   this[prop] = settings[prop];
  247.                }
  248.                catch(e:Error)
  249.                {
  250.                }
  251.             }
  252.          }
  253.          this.lines = this.strokeType == SOLID_STROKE ? int(Math.max(2,this.lines)) : int(Math.max(1,this.lines));
  254.       }
  255.       
  256.       public function get colorObjList() : Array
  257.       {
  258.          return this._colorObjList;
  259.       }
  260.       
  261.       public function setXML(xml:String) : void
  262.       {
  263.          var element:XML = null;
  264.          var values:Array = null;
  265.          var strokeXML:XML = new XML(xml);
  266.          try
  267.          {
  268.             this.strokeType = strokeXML.strokeType;
  269.             this.lines = strokeXML.lines;
  270.             this.weight = strokeXML.weight;
  271.             this.angleType = strokeXML.angleType;
  272.             this.minAngle = strokeXML.minAngle;
  273.             this.maxAngle = strokeXML.maxAngle;
  274.             this.angleSpeed = strokeXML.angleSpeed;
  275.             this.widthType = strokeXML.widthType;
  276.             this.minWidth = strokeXML.minWidth;
  277.             this.maxWidth = strokeXML.maxWidth;
  278.             this.widthSpeed = strokeXML.widthSpeed;
  279.             this.colorType = strokeXML.colorType;
  280.             this.colorSteps = strokeXML.colorSteps;
  281.             this.colorObjList = Style.objListToColorObjList(Style.propEnabledXMLToList(strokeXML.colorList.color));
  282.             this.colorHold = strokeXML.colorHold;
  283.             this.alphaType = strokeXML.alphaType;
  284.             this.minAlpha = strokeXML.minAlpha;
  285.             this.maxAlpha = strokeXML.maxAlpha;
  286.             this.alphaSpeed = strokeXML.alphaSpeed;
  287.          }
  288.          catch(e:Error)
  289.          {
  290.          }
  291.          if(this.colorObjList == null || this.colorObjList.length == 0)
  292.          {
  293.             this.colorObjList = [new ColorObj(16711680,true)];
  294.          }
  295.          for each(element in strokeXML.thresholds.*)
  296.          {
  297.             try
  298.             {
  299.                values = element.text().split(",");
  300.                this.thresholds[element.name()] = {
  301.                   "enabled":(element.enabled == "true" ? true : false),
  302.                   "min":values[0],
  303.                   "max":values[1]
  304.                };
  305.             }
  306.             catch(e:Error)
  307.             {
  308.             }
  309.          }
  310.          this.setDecorate();
  311.       }
  312.       
  313.       public function clone(style:Style) : StrokeStyle
  314.       {
  315.          var strokeStyle:StrokeStyle = new StrokeStyle(style);
  316.          strokeStyle.settings = this.settings;
  317.          return strokeStyle;
  318.       }
  319.       
  320.       public function get colorHold() : Number
  321.       {
  322.          return this._colorHold;
  323.       }
  324.       
  325.       internal function varStringToXML(str:String, value:String = null) : XML
  326.       {
  327.          var xml:XML = null;
  328.          if(value == null)
  329.          {
  330.             xml = new XML(<{str}>{this[str]}</{str}>);
  331.          }
  332.          else
  333.          {
  334.             xml = new XML(<{str}>{value}</{str}>);
  335.          }
  336.          return xml;
  337.       }
  338.       
  339.       public function getXML() : XML
  340.       {
  341.          var strokeXML:XML = new XML(<stroke/>);
  342.          strokeXML.appendChild(this.varStringToXML("strokeType"));
  343.          strokeXML.appendChild(<minWidth>{this.minWidth}</minWidth>);
  344.          strokeXML.appendChild(<minAlpha>{this.minAlpha}</minAlpha>);
  345.          strokeXML.appendChild(<angleType>{this.angleType}</angleType>);
  346.          strokeXML.appendChild(<minAngle>{this.minAngle}</minAngle>);
  347.          strokeXML.appendChild(<maxAngle>{this.maxAngle}</maxAngle>);
  348.          strokeXML.appendChild(<angleSpeed>{this.angleSpeed}</angleSpeed>);
  349.          strokeXML.appendChild(<widthSpeed>{this.widthSpeed}</widthSpeed>);
  350.          strokeXML.appendChild(<maxWidth>{this.maxWidth}</maxWidth>);
  351.          strokeXML.appendChild(<lines>{this.lines}</lines>);
  352.          strokeXML.appendChild(<weight>{this.weight}</weight>);
  353.          strokeXML.appendChild(<alphaType>{this.alphaType}</alphaType>);
  354.          strokeXML.appendChild(<colorType>{this.colorType}</colorType>);
  355.          strokeXML.appendChild(<colorSteps>{this.colorSteps}</colorSteps>);
  356.          strokeXML.appendChild(Style.propEnabledListToXML(this.colorStringObjList,"value","enabled","color"));
  357.          strokeXML.appendChild(<colorHold>{this.colorHold}</colorHold>);
  358.          strokeXML.appendChild(<maxAlpha>{this.maxAlpha}</maxAlpha>);
  359.          strokeXML.appendChild(<widthType>{this.widthType}</widthType>);
  360.          strokeXML.appendChild(<alphaSpeed>{this.alphaSpeed}</alphaSpeed>);
  361.          strokeXML.appendChild(<thresholds/>);
  362.          strokeXML.thresholds.appendChild(<speed enabled={this.thresholds.speed.enabled}>{this.thresholds.speed.min + "," + this.thresholds.speed.max}</speed>);
  363.          strokeXML.thresholds.appendChild(<width enabled={this.thresholds.width.enabled}>{this.thresholds.width.min + "," + this.thresholds.width.max}</width>);
  364.          strokeXML.thresholds.appendChild(<angle enabled={this.thresholds.angle.enabled}>{this.thresholds.angle.min + "," + this.thresholds.angle.max}</angle>);
  365.          strokeXML.thresholds.appendChild(<distance enabled={this.thresholds.distance.enabled}>{this.thresholds.distance.min + "," + this.thresholds.distance.max}</distance>);
  366.          strokeXML.thresholds.appendChild(<random enabled={this.thresholds.random.enabled}>{"null," + this.thresholds.random.max}</random>);
  367.          strokeXML.thresholds.appendChild(<interval enabled={this.thresholds.interval.enabled}>{this.thresholds.interval.min}</interval>);
  368.          return strokeXML;
  369.       }
  370.       
  371.       public function set colorType(s:String) : void
  372.       {
  373.          this._colorType = s;
  374.       }
  375.    }
  376. }
  377.  
  378.