home *** CD-ROM | disk | FTP | other *** search
- package com.livebrush.styles
- {
- import com.livebrush.data.Exchangeable;
- import com.livebrush.data.Settings;
- import com.livebrush.data.Storable;
- import com.livebrush.utils.ColorObj;
-
- public class StrokeStyle implements Exchangeable, Storable
- {
- public static const SOLID_STROKE:String = "solid";
-
- public static const RAKE_STROKE:String = "rake";
-
- public static const PATH_STROKE:String = "path";
-
- public static const WIDTH:String = "width";
-
- public static const DIR:String = "direction";
-
- public static const ROTATE:String = "rotate";
-
- public static const FIXED:String = "fixed";
-
- public static const NONE:String = "none";
-
- public static const OSC:String = "osc";
-
- public static const RANDOM:String = "random";
-
- public static const SPEED:String = "speed";
-
- public static const LIST:String = "list";
-
- public static const SAMPLE:String = "sample";
-
- public static const SAMPLE_BRUSH:String = "sampleBrush";
-
- public static const SMOOTH:String = "smooth";
-
- public static const STRAIGHT:String = "straight";
-
- public var defaultSettings:Settings;
-
- public var weight:Number = 1;
-
- public var alphaSpeed:Number = 10;
-
- public var strokeType:String = "solid";
-
- public var colorSteps:int = 50;
-
- public var minWidth:Number = 2;
-
- public var widthType:String = "speed";
-
- public var minAngle:Number = 0;
-
- private var _colorList:Array;
-
- public var minAlpha:Number = 1;
-
- public var angleType:String = "direction";
-
- public var widthSpeed:Number = 50;
-
- public var _colorObjList:Array;
-
- public var angleSpeed:Number = 50;
-
- public var alphaType:String = "fixed";
-
- public var styleManager:StyleManager;
-
- private var _colorType:String = "list";
-
- private var _colorHold:int = 1;
-
- public var maxWidth:Number = 75;
-
- public var maxAngle:Number = 180;
-
- public var style:Style;
-
- public var maxAlpha:Number = 1;
-
- public var thresholds:Object;
-
- private var _decorate:Boolean = true;
-
- public var lines:int = 2;
-
- public function StrokeStyle(style:Style)
- {
- super();
- this.style = style;
- this.colorObjList = [new ColorObj(0),new ColorObj(16777215)];
- this.styleManager = style.styleManager;
- this.thresholds = {
- "speed":{
- "min":50,
- "max":100,
- "enabled":false
- },
- "width":{
- "min":50,
- "max":100,
- "enabled":false
- },
- "angle":{
- "min":0,
- "max":180,
- "enabled":false
- },
- "distance":{
- "min":100,
- "max":500,
- "enabled":false
- },
- "random":{
- "min":10,
- "max":10,
- "enabled":false
- },
- "interval":{
- "min":1000,
- "max":1000,
- "enabled":false
- }
- };
- this.defaultSettings = this.settings;
- }
-
- public function die() : void
- {
- delete global[this];
- }
-
- public function get decorate() : Boolean
- {
- return this.style.decoStyle.decoSet.activeLength > 0 ? this._decorate : false;
- }
-
- private function setDecorate() : void
- {
- var propT:String = null;
- this.decorate = false;
- for(propT in this.thresholds)
- {
- this.decorate = this.decorate ? true : Boolean(this.thresholds[propT].enabled);
- }
- this.decorate = this.decorate ? this.style.decoStyle.decoSet.activeLength > 0 : false;
- }
-
- public function get selectedColor() : Number
- {
- return this.colorList[0];
- }
-
- public function set decorate(b:Boolean) : void
- {
- this._decorate = b;
- }
-
- public function set colorHold(n:Number) : void
- {
- this._colorHold = Math.max(1,n);
- }
-
- public function get settings() : Settings
- {
- var settings:Settings = new Settings();
- settings.strokeType = this.strokeType;
- settings.lines = this.lines;
- settings.weight = this.weight;
- settings.angleType = this.angleType;
- settings.minAngle = this.minAngle;
- settings.maxAngle = this.maxAngle;
- settings.angleSpeed = this.angleSpeed;
- settings.widthType = this.widthType;
- settings.minWidth = this.minWidth;
- settings.maxWidth = this.maxWidth;
- settings.widthSpeed = this.widthSpeed;
- settings.colorType = this.colorType;
- settings.colorSteps = this.colorSteps;
- settings.colorObjList = Settings.copyArrayOfObjects(this.colorObjList);
- settings.colorHold = this.colorHold;
- settings.alphaType = this.alphaType;
- settings.minAlpha = this.minAlpha;
- settings.maxAlpha = this.maxAlpha;
- settings.alphaSpeed = this.alphaSpeed;
- settings.thresholds = Settings.copyObject(this.thresholds);
- return settings;
- }
-
- public function set colorObjList(list:Array) : void
- {
- this._colorObjList = list;
- this._colorList = [];
- var i:int = 0;
- while(i < list.length)
- {
- if(list[i].enabled)
- {
- this._colorList.push(list[i].color);
- }
- i++;
- }
- }
-
- public function get colorList() : Array
- {
- return this._colorList;
- }
-
- public function get colorType() : String
- {
- return this._colorType;
- }
-
- public function get colorStringObjList() : Array
- {
- for(var stringObjList:Array = [],var i:int = 0; i < this.colorObjList.length; stringObjList.push({
- "value":this.colorObjList[i].colorString,
- "enabled":this.colorObjList[i].enabled
- }),i++)
- {
- }
- return stringObjList;
- }
-
- public function set settings(settings:Settings) : void
- {
- var propT:String = null;
- var prop:String = null;
- for(propT in settings.thresholds)
- {
- this.thresholds[propT] = settings.thresholds[propT];
- }
- this.setDecorate();
- for(prop in settings)
- {
- if(prop != "thresholds")
- {
- try
- {
- this[prop] = settings[prop];
- }
- catch(e:Error)
- {
- }
- }
- }
- this.lines = this.strokeType == SOLID_STROKE ? int(Math.max(2,this.lines)) : int(Math.max(1,this.lines));
- }
-
- public function get colorObjList() : Array
- {
- return this._colorObjList;
- }
-
- public function setXML(xml:String) : void
- {
- var element:XML = null;
- var values:Array = null;
- var strokeXML:XML = new XML(xml);
- try
- {
- this.strokeType = strokeXML.strokeType;
- this.lines = strokeXML.lines;
- this.weight = strokeXML.weight;
- this.angleType = strokeXML.angleType;
- this.minAngle = strokeXML.minAngle;
- this.maxAngle = strokeXML.maxAngle;
- this.angleSpeed = strokeXML.angleSpeed;
- this.widthType = strokeXML.widthType;
- this.minWidth = strokeXML.minWidth;
- this.maxWidth = strokeXML.maxWidth;
- this.widthSpeed = strokeXML.widthSpeed;
- this.colorType = strokeXML.colorType;
- this.colorSteps = strokeXML.colorSteps;
- this.colorObjList = Style.objListToColorObjList(Style.propEnabledXMLToList(strokeXML.colorList.color));
- this.colorHold = strokeXML.colorHold;
- this.alphaType = strokeXML.alphaType;
- this.minAlpha = strokeXML.minAlpha;
- this.maxAlpha = strokeXML.maxAlpha;
- this.alphaSpeed = strokeXML.alphaSpeed;
- }
- catch(e:Error)
- {
- }
- if(this.colorObjList == null || this.colorObjList.length == 0)
- {
- this.colorObjList = [new ColorObj(16711680,true)];
- }
- for each(element in strokeXML.thresholds.*)
- {
- try
- {
- values = element.text().split(",");
- this.thresholds[element.name()] = {
- "enabled":(element.enabled == "true" ? true : false),
- "min":values[0],
- "max":values[1]
- };
- }
- catch(e:Error)
- {
- }
- }
- this.setDecorate();
- }
-
- public function clone(style:Style) : StrokeStyle
- {
- var strokeStyle:StrokeStyle = new StrokeStyle(style);
- strokeStyle.settings = this.settings;
- return strokeStyle;
- }
-
- public function get colorHold() : Number
- {
- return this._colorHold;
- }
-
- internal function varStringToXML(str:String, value:String = null) : XML
- {
- var xml:XML = null;
- if(value == null)
- {
- xml = new XML(<{str}>{this[str]}</{str}>);
- }
- else
- {
- xml = new XML(<{str}>{value}</{str}>);
- }
- return xml;
- }
-
- public function getXML() : XML
- {
- var strokeXML:XML = new XML(<stroke/>);
- strokeXML.appendChild(this.varStringToXML("strokeType"));
- strokeXML.appendChild(<minWidth>{this.minWidth}</minWidth>);
- strokeXML.appendChild(<minAlpha>{this.minAlpha}</minAlpha>);
- strokeXML.appendChild(<angleType>{this.angleType}</angleType>);
- strokeXML.appendChild(<minAngle>{this.minAngle}</minAngle>);
- strokeXML.appendChild(<maxAngle>{this.maxAngle}</maxAngle>);
- strokeXML.appendChild(<angleSpeed>{this.angleSpeed}</angleSpeed>);
- strokeXML.appendChild(<widthSpeed>{this.widthSpeed}</widthSpeed>);
- strokeXML.appendChild(<maxWidth>{this.maxWidth}</maxWidth>);
- strokeXML.appendChild(<lines>{this.lines}</lines>);
- strokeXML.appendChild(<weight>{this.weight}</weight>);
- strokeXML.appendChild(<alphaType>{this.alphaType}</alphaType>);
- strokeXML.appendChild(<colorType>{this.colorType}</colorType>);
- strokeXML.appendChild(<colorSteps>{this.colorSteps}</colorSteps>);
- strokeXML.appendChild(Style.propEnabledListToXML(this.colorStringObjList,"value","enabled","color"));
- strokeXML.appendChild(<colorHold>{this.colorHold}</colorHold>);
- strokeXML.appendChild(<maxAlpha>{this.maxAlpha}</maxAlpha>);
- strokeXML.appendChild(<widthType>{this.widthType}</widthType>);
- strokeXML.appendChild(<alphaSpeed>{this.alphaSpeed}</alphaSpeed>);
- strokeXML.appendChild(<thresholds/>);
- strokeXML.thresholds.appendChild(<speed enabled={this.thresholds.speed.enabled}>{this.thresholds.speed.min + "," + this.thresholds.speed.max}</speed>);
- strokeXML.thresholds.appendChild(<width enabled={this.thresholds.width.enabled}>{this.thresholds.width.min + "," + this.thresholds.width.max}</width>);
- strokeXML.thresholds.appendChild(<angle enabled={this.thresholds.angle.enabled}>{this.thresholds.angle.min + "," + this.thresholds.angle.max}</angle>);
- strokeXML.thresholds.appendChild(<distance enabled={this.thresholds.distance.enabled}>{this.thresholds.distance.min + "," + this.thresholds.distance.max}</distance>);
- strokeXML.thresholds.appendChild(<random enabled={this.thresholds.random.enabled}>{"null," + this.thresholds.random.max}</random>);
- strokeXML.thresholds.appendChild(<interval enabled={this.thresholds.interval.enabled}>{this.thresholds.interval.min}</interval>);
- return strokeXML;
- }
-
- public function set colorType(s:String) : void
- {
- this._colorType = s;
- }
- }
- }
-
-