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 / ui / LayersView.as < prev    next >
Encoding:
Text File  |  2009-10-26  |  10.0 KB  |  291 lines

  1. package com.livebrush.ui
  2. {
  3.    import com.livebrush.data.Settings;
  4.    import com.livebrush.events.UpdateEvent;
  5.    import com.livebrush.graphics.canvas.Layer;
  6.    import com.livebrush.tools.Tool;
  7.    import com.livebrush.tools.TransformTool;
  8.    import com.livebrush.utils.Update;
  9.    import fl.controls.ColorPicker;
  10.    import fl.controls.ScrollPolicy;
  11.    import flash.display.BlendMode;
  12.    import flash.display.NativeMenu;
  13.    import flash.display.NativeMenuItem;
  14.    import flash.display.Sprite;
  15.    
  16.    public class LayersView extends UIView
  17.    {
  18.       public static var IDEAL_HEIGHT:int = 345;
  19.       
  20.       public var layersList:RichList;
  21.       
  22.       public var panel:Sprite;
  23.       
  24.       private var _decoAttachInstructMenu:NativeMenu;
  25.       
  26.       public var panelAsset:PanelAsset;
  27.       
  28.       public var otherLayerContextMenu:NativeMenu;
  29.       
  30.       public var tintInput:PropInputVertical;
  31.       
  32.       private var _lineLayerContextMenu:NativeMenu;
  33.       
  34.       public var state:int;
  35.       
  36.       public var alphaInput:PropInputVertical;
  37.       
  38.       private var titlebarMask:PanelTitlebarMask;
  39.       
  40.       public var color:ColorPicker;
  41.       
  42.       public var colorInput:ColorInput;
  43.       
  44.       public var blendInput:TypeInputVertical;
  45.       
  46.       public var uiAsset:LayerPropsUI;
  47.       
  48.       public function LayersView(ui:UI)
  49.       {
  50.          this.state = UI.OPEN;
  51.          super(ui);
  52.          helpID = "layerProps";
  53.          init();
  54.       }
  55.       
  56.       override protected function createView() : void
  57.       {
  58.          this._createLayerContextMenus();
  59.          this.panel = new Sprite();
  60.          this.uiAsset = new LayerPropsUI();
  61.          this.titlebarMask = new PanelTitlebarMask();
  62.          this.titlebarMask.visible = false;
  63.          this.panelAsset = new PanelAsset();
  64.          this.panelAsset.cacheAsBitmap = true;
  65.          this.panel.addChild(this.panelAsset);
  66.          this.panel.addChild(this.uiAsset);
  67.          this.panel.addChild(this.titlebarMask);
  68.          UI.UI_HOLDER.addChild(this.panel);
  69.          this.layersList = new RichList(this.uiAsset["_layersList"],LayerListItem,40);
  70.          this.layersList.uiAsset["_scrollPane"].height = 240;
  71.          this.layersList.uiAsset["_scrollPane"].width = 283;
  72.          this.layersList.uiAsset["_scrollPane"].verticalScrollPolicy = ScrollPolicy.ON;
  73.          this.blendInput = this.uiAsset["_blendInput"];
  74.          this.blendInput.label = "Blend Mode";
  75.          this.blendInput.list = [{
  76.             "label":"Normal",
  77.             "data":BlendMode.LAYER
  78.          },{
  79.             "label":"Multiply",
  80.             "data":BlendMode.MULTIPLY
  81.          },{
  82.             "label":"Darken",
  83.             "data":BlendMode.DARKEN
  84.          },{
  85.             "label":"Lighten",
  86.             "data":BlendMode.LIGHTEN
  87.          },{
  88.             "label":"Screen",
  89.             "data":BlendMode.SCREEN
  90.          },{
  91.             "label":"Add",
  92.             "data":BlendMode.ADD
  93.          },{
  94.             "label":"Subtract",
  95.             "data":BlendMode.SUBTRACT
  96.          },{
  97.             "label":"Difference",
  98.             "data":BlendMode.DIFFERENCE
  99.          },{
  100.             "label":"Invert",
  101.             "data":BlendMode.INVERT
  102.          }];
  103.          this.alphaInput = this.uiAsset["_alphaInput"];
  104.          this.alphaInput.label = "Opacity";
  105.          this.tintInput = this.uiAsset["_tintInput"];
  106.          this.tintInput.label = "Color";
  107.          this.colorInput = this.uiAsset["_colorInput"];
  108.          this.panelAsset.title.htmlText = "<b>Layers</b>";
  109.          this.panel.y = 665;
  110.          this.panelAsset.bg.height = IDEAL_HEIGHT;
  111.          this.uiAsset.y = 30;
  112.          Tooltip.addTip(this.uiAsset.upBtn,"Move layer up");
  113.          Tooltip.addTip(this.uiAsset.downBtn,"Move layer down");
  114.          Tooltip.addTip(this.uiAsset.copyBtn,"Duplicate layer");
  115.          Tooltip.addTip(this.uiAsset.flatBtn,"Flatten selected layers");
  116.          Tooltip.addTip(this.uiAsset.removeBtn,"Remove layer");
  117.          Tooltip.addTip(this.uiAsset.addBtn.addBtn,"Add new bitmap layer");
  118.       }
  119.       
  120.       override public function update(update:Update = null) : void
  121.       {
  122.          if(update.type == UpdateEvent.WINDOW || update.type == UpdateEvent.UI)
  123.          {
  124.             this.panel.x = UI.WIDTH - this.panelAsset.width - 42 - 6;
  125.             this.panel.y = ui.toolPropsView.maxY;
  126.             if(this.state != UI.CLOSED)
  127.             {
  128.                this.panelAsset.bg.height = LayersView.IDEAL_HEIGHT;
  129.             }
  130.          }
  131.          else if(update.type == UpdateEvent.LAYER)
  132.          {
  133.             this.settings = Settings(update.data);
  134.          }
  135.          else if(update.type != UpdateEvent.COLOR)
  136.          {
  137.             if(update.type == UpdateEvent.DRAW_MODE)
  138.             {
  139.                if(update.data.mode == 0)
  140.                {
  141.                   this.uiAsset.addBtn.alpha = 0.35;
  142.                   this.uiAsset.addBtn.enabled = this.uiAsset.addBtn.mouseChildren = false;
  143.                }
  144.                else
  145.                {
  146.                   this.uiAsset.addBtn.alpha = 1;
  147.                   this.uiAsset.addBtn.enabled = this.uiAsset.addBtn.mouseChildren = true;
  148.                }
  149.             }
  150.          }
  151.       }
  152.       
  153.       private function _createLayerContextMenus() : void
  154.       {
  155.          this._lineLayerContextMenu = new NativeMenu();
  156.          this._lineLayerContextMenu.addItem(new NativeMenuItem("Copy Edge Deco(s) to Layer(s)",false));
  157.          this._lineLayerContextMenu.addItem(new NativeMenuItem("Remove All Edge Decorations",false));
  158.          this.otherLayerContextMenu = new NativeMenu();
  159.          this.otherLayerContextMenu.addItem(this.createNativeMenuItem("Copy Layer To Line","copyLayerToDeco"));
  160.          this.otherLayerContextMenu.addItem(this.createNativeMenuItem("Copy Layer To Line In-Place","iCopyLayerToDeco"));
  161.          this._decoAttachInstructMenu = new NativeMenu();
  162.          var item:NativeMenuItem = this.createNativeMenuItem("Use the Transform Tool to Select Line Edges");
  163.          item.enabled = false;
  164.          this._decoAttachInstructMenu.addItem(item);
  165.       }
  166.       
  167.       public function get layerContextMenu() : NativeMenu
  168.       {
  169.          return this._getLayerContextMenu();
  170.       }
  171.       
  172.       public function set visible(b:Boolean) : void
  173.       {
  174.          this.panel.visible = b;
  175.       }
  176.       
  177.       private function createNativeMenuItem(label:String, name:String = "", primKey:String = "", isSeparator:Boolean = false) : NativeMenuItem
  178.       {
  179.          var item:NativeMenuItem = new NativeMenuItem(label,isSeparator);
  180.          item.name = name;
  181.          return item;
  182.       }
  183.       
  184.       override public function set settings(settings:Settings) : void
  185.       {
  186.          var i:int = 0;
  187.          this.layersList.dataProvider = settings.layers.slice().sortOn("depth",Array.NUMERIC | Array.DESCENDING);
  188.          var selectedIndices:Array = [];
  189.          for(i = 0; i < settings.activeLayerDepths.length; i++)
  190.          {
  191.             selectedIndices.push(Settings.idToIndex(settings.activeLayerDepths[i].toString(),this.layersList.list,"depth"));
  192.          }
  193.          this.layersList.selectedIndices = selectedIndices;
  194.          this.applyProps();
  195.       }
  196.       
  197.       public function applyProps() : void
  198.       {
  199.          try
  200.          {
  201.             this.blendInput.value = this.layersList.selectedItem.blendMode;
  202.             this.alphaInput.value = int(this.layersList.selectedItem.alpha * 100);
  203.             this.tintInput.value = int(this.layersList.selectedItem.colorPercent * 100);
  204.             this.colorInput.color = this.layersList.selectedItem.color;
  205.             this.layersList.bottomRichItem.lockUI();
  206.             if(Layer.isBackgroundLayer(this.layersList.selectedItem as Layer))
  207.             {
  208.                this.blendInput.enabled = false;
  209.                this.alphaInput.enabled = false;
  210.                this.tintInput.enabled = false;
  211.             }
  212.             else
  213.             {
  214.                this.blendInput.enabled = true;
  215.                this.alphaInput.enabled = true;
  216.                this.tintInput.enabled = true;
  217.             }
  218.          }
  219.          catch(e:Error)
  220.          {
  221.          }
  222.       }
  223.       
  224.       override public function get settings() : Settings
  225.       {
  226.          var settings:Settings = new Settings();
  227.          settings.layers = this.layersList.list;
  228.          settings.selectedLayerDepths = this.getSelectedLayerDepths();
  229.          return settings;
  230.       }
  231.       
  232.       public function toggle(force:Boolean = false) : void
  233.       {
  234.          this.state = this.state == UI.CLOSED || force ? UI.OPEN : UI.CLOSED;
  235.          if(this.state == UI.CLOSED)
  236.          {
  237.             this.panelAsset.bg.height = 22;
  238.             this.uiAsset.mask = this.titlebarMask;
  239.          }
  240.          else
  241.          {
  242.             this.panelAsset.bg.height = IDEAL_HEIGHT;
  243.             this.uiAsset.mask = null;
  244.          }
  245.       }
  246.       
  247.       public function get height() : Number
  248.       {
  249.          return this.panelAsset.height;
  250.       }
  251.       
  252.       public function getSelectedLayerDepths() : Array
  253.       {
  254.          var selectedLayerDepths:Array = [];
  255.          var selectedItems:Array = this.layersList.selectedItems;
  256.          for(var i:int = 0; i < this.layersList.selectedIndices.length; i++)
  257.          {
  258.             selectedLayerDepths.push(selectedItems[i].depth);
  259.          }
  260.          return selectedLayerDepths;
  261.       }
  262.       
  263.       private function _getLayerContextMenu() : NativeMenu
  264.       {
  265.          var menu:NativeMenu = null;
  266.          if(Layer.isLineLayer(activeLayer) && Tool.isTransformTool(activeTool))
  267.          {
  268.             if(TransformTool(activeTool).selectedEdges.length > 0)
  269.             {
  270.                menu = this.otherLayerContextMenu;
  271.             }
  272.             else
  273.             {
  274.                menu = this._decoAttachInstructMenu;
  275.             }
  276.          }
  277.          else
  278.          {
  279.             menu = this._decoAttachInstructMenu;
  280.          }
  281.          return menu;
  282.       }
  283.       
  284.       override protected function createController() : void
  285.       {
  286.          controller = new LayersController(this);
  287.       }
  288.    }
  289. }
  290.  
  291.