home *** CD-ROM | disk | FTP | other *** search
- package com.livebrush.ui
- {
- import com.livebrush.data.Settings;
- import com.livebrush.events.UpdateEvent;
- import com.livebrush.graphics.canvas.Layer;
- import com.livebrush.tools.Tool;
- import com.livebrush.tools.TransformTool;
- import com.livebrush.utils.Update;
- import fl.controls.ColorPicker;
- import fl.controls.ScrollPolicy;
- import flash.display.BlendMode;
- import flash.display.NativeMenu;
- import flash.display.NativeMenuItem;
- import flash.display.Sprite;
-
- public class LayersView extends UIView
- {
- public static var IDEAL_HEIGHT:int = 345;
-
- public var layersList:RichList;
-
- public var panel:Sprite;
-
- private var _decoAttachInstructMenu:NativeMenu;
-
- public var panelAsset:PanelAsset;
-
- public var otherLayerContextMenu:NativeMenu;
-
- public var tintInput:PropInputVertical;
-
- private var _lineLayerContextMenu:NativeMenu;
-
- public var state:int;
-
- public var alphaInput:PropInputVertical;
-
- private var titlebarMask:PanelTitlebarMask;
-
- public var color:ColorPicker;
-
- public var colorInput:ColorInput;
-
- public var blendInput:TypeInputVertical;
-
- public var uiAsset:LayerPropsUI;
-
- public function LayersView(ui:UI)
- {
- this.state = UI.OPEN;
- super(ui);
- helpID = "layerProps";
- init();
- }
-
- override protected function createView() : void
- {
- this._createLayerContextMenus();
- this.panel = new Sprite();
- this.uiAsset = new LayerPropsUI();
- this.titlebarMask = new PanelTitlebarMask();
- this.titlebarMask.visible = false;
- this.panelAsset = new PanelAsset();
- this.panelAsset.cacheAsBitmap = true;
- this.panel.addChild(this.panelAsset);
- this.panel.addChild(this.uiAsset);
- this.panel.addChild(this.titlebarMask);
- UI.UI_HOLDER.addChild(this.panel);
- this.layersList = new RichList(this.uiAsset["_layersList"],LayerListItem,40);
- this.layersList.uiAsset["_scrollPane"].height = 240;
- this.layersList.uiAsset["_scrollPane"].width = 283;
- this.layersList.uiAsset["_scrollPane"].verticalScrollPolicy = ScrollPolicy.ON;
- this.blendInput = this.uiAsset["_blendInput"];
- this.blendInput.label = "Blend Mode";
- this.blendInput.list = [{
- "label":"Normal",
- "data":BlendMode.LAYER
- },{
- "label":"Multiply",
- "data":BlendMode.MULTIPLY
- },{
- "label":"Darken",
- "data":BlendMode.DARKEN
- },{
- "label":"Lighten",
- "data":BlendMode.LIGHTEN
- },{
- "label":"Screen",
- "data":BlendMode.SCREEN
- },{
- "label":"Add",
- "data":BlendMode.ADD
- },{
- "label":"Subtract",
- "data":BlendMode.SUBTRACT
- },{
- "label":"Difference",
- "data":BlendMode.DIFFERENCE
- },{
- "label":"Invert",
- "data":BlendMode.INVERT
- }];
- this.alphaInput = this.uiAsset["_alphaInput"];
- this.alphaInput.label = "Opacity";
- this.tintInput = this.uiAsset["_tintInput"];
- this.tintInput.label = "Color";
- this.colorInput = this.uiAsset["_colorInput"];
- this.panelAsset.title.htmlText = "<b>Layers</b>";
- this.panel.y = 665;
- this.panelAsset.bg.height = IDEAL_HEIGHT;
- this.uiAsset.y = 30;
- Tooltip.addTip(this.uiAsset.upBtn,"Move layer up");
- Tooltip.addTip(this.uiAsset.downBtn,"Move layer down");
- Tooltip.addTip(this.uiAsset.copyBtn,"Duplicate layer");
- Tooltip.addTip(this.uiAsset.flatBtn,"Flatten selected layers");
- Tooltip.addTip(this.uiAsset.removeBtn,"Remove layer");
- Tooltip.addTip(this.uiAsset.addBtn.addBtn,"Add new bitmap layer");
- }
-
- override public function update(update:Update = null) : void
- {
- if(update.type == UpdateEvent.WINDOW || update.type == UpdateEvent.UI)
- {
- this.panel.x = UI.WIDTH - this.panelAsset.width - 42 - 6;
- this.panel.y = ui.toolPropsView.maxY;
- if(this.state != UI.CLOSED)
- {
- this.panelAsset.bg.height = LayersView.IDEAL_HEIGHT;
- }
- }
- else if(update.type == UpdateEvent.LAYER)
- {
- this.settings = Settings(update.data);
- }
- else if(update.type != UpdateEvent.COLOR)
- {
- if(update.type == UpdateEvent.DRAW_MODE)
- {
- if(update.data.mode == 0)
- {
- this.uiAsset.addBtn.alpha = 0.35;
- this.uiAsset.addBtn.enabled = this.uiAsset.addBtn.mouseChildren = false;
- }
- else
- {
- this.uiAsset.addBtn.alpha = 1;
- this.uiAsset.addBtn.enabled = this.uiAsset.addBtn.mouseChildren = true;
- }
- }
- }
- }
-
- private function _createLayerContextMenus() : void
- {
- this._lineLayerContextMenu = new NativeMenu();
- this._lineLayerContextMenu.addItem(new NativeMenuItem("Copy Edge Deco(s) to Layer(s)",false));
- this._lineLayerContextMenu.addItem(new NativeMenuItem("Remove All Edge Decorations",false));
- this.otherLayerContextMenu = new NativeMenu();
- this.otherLayerContextMenu.addItem(this.createNativeMenuItem("Copy Layer To Line","copyLayerToDeco"));
- this.otherLayerContextMenu.addItem(this.createNativeMenuItem("Copy Layer To Line In-Place","iCopyLayerToDeco"));
- this._decoAttachInstructMenu = new NativeMenu();
- var item:NativeMenuItem = this.createNativeMenuItem("Use the Transform Tool to Select Line Edges");
- item.enabled = false;
- this._decoAttachInstructMenu.addItem(item);
- }
-
- public function get layerContextMenu() : NativeMenu
- {
- return this._getLayerContextMenu();
- }
-
- public function set visible(b:Boolean) : void
- {
- this.panel.visible = b;
- }
-
- private function createNativeMenuItem(label:String, name:String = "", primKey:String = "", isSeparator:Boolean = false) : NativeMenuItem
- {
- var item:NativeMenuItem = new NativeMenuItem(label,isSeparator);
- item.name = name;
- return item;
- }
-
- override public function set settings(settings:Settings) : void
- {
- var i:int = 0;
- this.layersList.dataProvider = settings.layers.slice().sortOn("depth",Array.NUMERIC | Array.DESCENDING);
- var selectedIndices:Array = [];
- for(i = 0; i < settings.activeLayerDepths.length; i++)
- {
- selectedIndices.push(Settings.idToIndex(settings.activeLayerDepths[i].toString(),this.layersList.list,"depth"));
- }
- this.layersList.selectedIndices = selectedIndices;
- this.applyProps();
- }
-
- public function applyProps() : void
- {
- try
- {
- this.blendInput.value = this.layersList.selectedItem.blendMode;
- this.alphaInput.value = int(this.layersList.selectedItem.alpha * 100);
- this.tintInput.value = int(this.layersList.selectedItem.colorPercent * 100);
- this.colorInput.color = this.layersList.selectedItem.color;
- this.layersList.bottomRichItem.lockUI();
- if(Layer.isBackgroundLayer(this.layersList.selectedItem as Layer))
- {
- this.blendInput.enabled = false;
- this.alphaInput.enabled = false;
- this.tintInput.enabled = false;
- }
- else
- {
- this.blendInput.enabled = true;
- this.alphaInput.enabled = true;
- this.tintInput.enabled = true;
- }
- }
- catch(e:Error)
- {
- }
- }
-
- override public function get settings() : Settings
- {
- var settings:Settings = new Settings();
- settings.layers = this.layersList.list;
- settings.selectedLayerDepths = this.getSelectedLayerDepths();
- return settings;
- }
-
- public function toggle(force:Boolean = false) : void
- {
- this.state = this.state == UI.CLOSED || force ? UI.OPEN : UI.CLOSED;
- if(this.state == UI.CLOSED)
- {
- this.panelAsset.bg.height = 22;
- this.uiAsset.mask = this.titlebarMask;
- }
- else
- {
- this.panelAsset.bg.height = IDEAL_HEIGHT;
- this.uiAsset.mask = null;
- }
- }
-
- public function get height() : Number
- {
- return this.panelAsset.height;
- }
-
- public function getSelectedLayerDepths() : Array
- {
- var selectedLayerDepths:Array = [];
- var selectedItems:Array = this.layersList.selectedItems;
- for(var i:int = 0; i < this.layersList.selectedIndices.length; i++)
- {
- selectedLayerDepths.push(selectedItems[i].depth);
- }
- return selectedLayerDepths;
- }
-
- private function _getLayerContextMenu() : NativeMenu
- {
- var menu:NativeMenu = null;
- if(Layer.isLineLayer(activeLayer) && Tool.isTransformTool(activeTool))
- {
- if(TransformTool(activeTool).selectedEdges.length > 0)
- {
- menu = this.otherLayerContextMenu;
- }
- else
- {
- menu = this._decoAttachInstructMenu;
- }
- }
- else
- {
- menu = this._decoAttachInstructMenu;
- }
- return menu;
- }
-
- override protected function createController() : void
- {
- controller = new LayersController(this);
- }
- }
- }
-
-