home *** CD-ROM | disk | FTP | other *** search
- package com.livebrush.styles
- {
- import com.livebrush.data.Exchangeable;
- import com.livebrush.data.FileManager;
- import com.livebrush.data.Settings;
- import com.livebrush.graphics.canvas.StylePreviewLayer;
- import com.livebrush.ui.UI;
- import com.livebrush.utils.Update;
-
- public class StyleManager implements Exchangeable
- {
- public var alphaLocked:Boolean = false;
-
- private var _copiedStyle:Style = null;
-
- public var ui:UI;
-
- public var stylePreviewAutoRefresh:Boolean = true;
-
- public var stylePreview:StylePreviewLayer;
-
- public var colorsLocked:Boolean = false;
-
- public var styleGroup:Array;
-
- public var styles:Array;
-
- private var _locked:Boolean = false;
-
- public var showStylePreview:Boolean = false;
-
- public var lockedColorSettings:Settings;
-
- public function StyleManager(ui:UI)
- {
- super();
- this.styleGroup = [];
- this.styles = [];
- this.ui = ui;
- this.lockColors(false);
- }
-
- public function updateStylePreview(style:Style) : void
- {
- if(this.showStylePreview)
- {
- this.stylePreviewLayer.drawStyle();
- }
- }
-
- public function lockColors(b:Boolean) : void
- {
- this.colorsLocked = b;
- if(b)
- {
- this.lockedColorSettings = this.ui.globalColorView.settings;
- }
- try
- {
- this.alphaLocked = this.lockedColorSettings.alphaLocked;
- }
- catch(e:Error)
- {
- alphaLocked = false;
- }
- }
-
- public function copyStyle(i:int) : void
- {
- if(this._copiedStyle != null)
- {
- this._copiedStyle.die();
- }
- this._copiedStyle = this.styles[i].clone();
- }
-
- public function set settings(settings:Settings) : void
- {
- this.styles = settings.styles;
- this.setStyleGroup(settings.styleGroup);
- }
-
- private function getStyle(id:int) : Style
- {
- var style:Style = null;
- for(var i:int = 0; i < this.styles.length; i++)
- {
- if(this.styles[i].id == id)
- {
- style = this.styles[i];
- }
- }
- return style;
- }
-
- public function get activeStyle() : Style
- {
- return this.styleGroup[0];
- }
-
- public function reset() : void
- {
- for(var i:int = 0; i < this.styles.length; i++)
- {
- this.styles[i].die();
- delete this.styles[i];
- }
- for(var j:int = 0; j < this.styleGroup.length; j++)
- {
- delete this.styleGroup[j];
- }
- this.styles = [];
- this.styleGroup = [];
- }
-
- public function removeDeco(index:int) : void
- {
- this.activeStyle.decoStyle.decoSet.removeDeco(index);
- this.pushStyle();
- }
-
- public function removeStyle(id:int) : void
- {
- var index:int = 0;
- for(var i:int = 0; i < this.styles.length; i++)
- {
- if(this.styles[i].id == id)
- {
- index = i;
- this.styles[i].die();
- this.styles.splice(i,1);
- }
- }
- this.activeStyle = this.styles[Math.min(this.styles.length - 1,index)];
- this.pushStyle();
- }
-
- public function set activeStyle(s:Style) : void
- {
- this.setStyleGroup([s]);
- }
-
- public function selectStyle(i:int) : void
- {
- this.activeStyle = this.styles[i];
- }
-
- public function get activeStyleId() : int
- {
- return this.activeStyle.id;
- }
-
- private function setStyleGroup(bGroup:Array) : void
- {
- var style:Style = null;
- var i:int = 0;
- try
- {
- for(i = 0; i < this.styleGroup.length; i++)
- {
- style = this.getStyle(this.styleGroup[i].id);
- if(style.lineStyle.type == LineStyle.DYNAMIC)
- {
- style.lineStyle.unloadInputSWF();
- }
- }
- }
- catch(error:Error)
- {
- }
- finally
- {
- this.styleGroup = [];
- for(i = 0; i < bGroup.length; i++)
- {
- style = this.getStyle(bGroup[i].id);
- if(style.lineStyle.type == LineStyle.DYNAMIC)
- {
- style.lineStyle.loadInputSWF();
- }
- this.styleGroup.push(style);
- }
- this.pushStyle();
- }
- if(this.stylePreviewAutoRefresh)
- {
- this.updateStylePreview(this.activeStyle);
- }
- }
-
- public function setDynamicInput(fileName:String) : void
- {
- this.activeStyle.lineStyle.setDynamicInput(fileName);
- this.setStyleGroup([this.activeStyle]);
- }
-
- public function createStyle(name:String) : void
- {
- var style:Style = this.activeStyle.clone();
- style.name = FileManager.createNameDup(this.styles,name,"name");
- this.styles.splice(this.styles.indexOf(this.activeStyle) + 1,0,style);
- this.activeStyle = style;
- this.pushStyle();
- }
-
- public function pasteStyle(i:int, all:Boolean, b:Boolean = false, l:Boolean = false, d:Boolean = false, lc:Boolean = false, dc:Boolean = false, dl:Boolean = false, t:Boolean = false) : void
- {
- var settingsMix:Settings = null;
- var style:Style = this.styles[i];
- if(this._copiedStyle != null)
- {
- if(all)
- {
- style.settings = this._copiedStyle.settings;
- }
- else if(b)
- {
- style.strokeStyle.thresholds = this._copiedStyle.strokeStyle.settings.thresholds;
- style.lineStyle.settings = this._copiedStyle.lineStyle.settings;
- }
- else if(l)
- {
- style.lineStyle.smoothing = this._copiedStyle.lineStyle.settings.smoothing;
- style.strokeStyle.settings = this._copiedStyle.strokeStyle.settings;
- }
- else if(d)
- {
- style.decoStyle.settings = this._copiedStyle.decoStyle.settings;
- }
- else if(lc)
- {
- settingsMix = style.strokeStyle.settings;
- settingsMix.colorObjList = this._copiedStyle.strokeStyle.settings.colorObjList;
- style.strokeStyle.settings = settingsMix;
- }
- else if(dc)
- {
- settingsMix = style.decoStyle.settings;
- settingsMix.colorObjList = this._copiedStyle.decoStyle.settings.colorObjList;
- style.decoStyle.settings = settingsMix;
- }
- else if(dl)
- {
- settingsMix = style.decoStyle.settings;
- settingsMix.decos = this._copiedStyle.decoStyle.settings.decos;
- style.decoStyle.settings = settingsMix;
- }
- else if(t)
- {
- style.strokeStyle.thresholds = this._copiedStyle.strokeStyle.settings.thresholds;
- }
- if(style == this.activeStyle)
- {
- this.pushStyle();
- }
- }
- }
-
- public function getStyleXML() : XML
- {
- var stylesXML:XML = new XML(<styles></styles>);
- for(var i:int = 0; i < this.styles.length; i++)
- {
- stylesXML.appendChild(this.styles[i].getXML());
- }
- return stylesXML;
- }
-
- public function pullStyle(settings:Settings) : void
- {
- var settingsMix:Settings = null;
- if(!this._locked)
- {
- this.activeStyle.decoStyle.settings = settings.deco;
- settingsMix = settings.behavior;
- settingsMix.smoothing = settings.line.smoothing;
- this.activeStyle.lineStyle.settings = settingsMix;
- settingsMix = settings.line;
- settingsMix.thresholds = settings.behavior.thresholds;
- this.activeStyle.strokeStyle.settings = settingsMix;
- this.settings = settings.list;
- }
- }
-
- public function moveDeco(index:int, dir:int) : void
- {
- this.activeStyle.decoStyle.decoSet.moveDeco(index,dir);
- this.pushStyle();
- }
-
- public function get settings() : Settings
- {
- var settings:Settings = new Settings();
- settings.styles = this.styles;
- settings.styleGroup = this.styleGroup;
- return settings;
- }
-
- public function setStyleXML(xml:XML, importBool:Boolean = false) : Style
- {
- this._locked = true;
- var styleXML:XML = xml.copy();
- var style:Style = new Style(this);
- style.setXML(Settings.attrToElement(styleXML));
- style.name = FileManager.createNameDup(this.styles,style.name,"name");
- this.styles.push(style);
- this.setStyleGroup([this.styleGroup.length == 0 ? this.styles[0] : (importBool ? this.styles[this.styles.length - 1] : this.activeStyle)]);
- this._locked = false;
- return style;
- }
-
- public function get stylePreviewLayer() : StylePreviewLayer
- {
- return this.ui.canvasManager.stylePreviewLayer;
- }
-
- public function pushStyle() : void
- {
- this._locked = true;
- var settings:Settings = this.settings;
- settings.behavior = this.activeStyle.lineStyle.settings;
- settings.behavior.thresholds = this.activeStyle.strokeStyle.thresholds;
- settings.line = this.activeStyle.strokeStyle.settings;
- settings.line.smoothing = settings.behavior.smoothing;
- settings.deco = this.activeStyle.decoStyle.settings;
- this.ui.update(Update.brushStyleUpdate(settings));
- this._locked = false;
- }
- }
- }
-
-