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 / ToolbarView.as < prev    next >
Encoding:
Text File  |  2009-10-26  |  3.7 KB  |  119 lines

  1. package com.livebrush.ui
  2. {
  3.    import com.livebrush.events.UpdateEvent;
  4.    import com.livebrush.tools.BrushTool;
  5.    import com.livebrush.tools.ColorLayerTool;
  6.    import com.livebrush.tools.HandTool;
  7.    import com.livebrush.tools.PenTool;
  8.    import com.livebrush.tools.SampleTool;
  9.    import com.livebrush.tools.TransformTool;
  10.    import com.livebrush.utils.Update;
  11.    import flash.display.MovieClip;
  12.    import flash.display.Sprite;
  13.    import flash.geom.ColorTransform;
  14.    import org.casalib.util.ColorUtil;
  15.    
  16.    public class ToolbarView extends UIView
  17.    {
  18.       private var _cf:ColorTransform;
  19.       
  20.       private var _color:uint;
  21.       
  22.       public var toolBtns:Array;
  23.       
  24.       public var toolbarAsset:ToolbarAsset;
  25.       
  26.       private var _colorHexValue:String;
  27.       
  28.       public function ToolbarView(ui:UI)
  29.       {
  30.          super(ui);
  31.          helpID = "tools";
  32.          init();
  33.       }
  34.       
  35.       private function _setColor(u:uint) : void
  36.       {
  37.          var c:Object = ColorUtil.getRGB(u);
  38.          this._colorHexValue = ColorUtil.getHexStringFromRGB(c.r,c.g,c.b);
  39.          this._cf.color = u;
  40.          this.toolbarAsset._colorBg.transform.colorTransform = this._cf;
  41.          this._color = u;
  42.       }
  43.       
  44.       override protected function createView() : void
  45.       {
  46.          this.toolbarAsset = new ToolbarAsset();
  47.          this.toolbarAsset.cacheAsBitmap = true;
  48.          UI.UI_HOLDER.addChild(this.toolbarAsset);
  49.          this.toolbarAsset.y = 32;
  50.          this.toolBtns = [this.toolbarAsset.brushBtn,this.toolbarAsset.penBtn,this.toolbarAsset.transformBtn,this.toolbarAsset.fillBtn,this.toolbarAsset.sampleBtn,this.toolbarAsset.handBtn];
  51.          this.toolBtns[0].toolName = BrushTool.NAME;
  52.          this.toolBtns[1].toolName = PenTool.NAME;
  53.          this.toolBtns[2].toolName = TransformTool.NAME;
  54.          this.toolBtns[3].toolName = ColorLayerTool.NAME;
  55.          this.toolBtns[4].toolName = SampleTool.NAME;
  56.          this.toolBtns[5].toolName = HandTool.NAME;
  57.          this.toolbarAsset._colorBg.useHandCursor = true;
  58.          this._cf = new ColorTransform();
  59.       }
  60.       
  61.       public function resetToolBtns() : void
  62.       {
  63.          for(var i:int = 0; i < this.toolBtns.length; i++)
  64.          {
  65.             this.toolBtns[i].gotoAndStop(1);
  66.          }
  67.       }
  68.       
  69.       public function getBtnByToolName(toolName:String) : MovieClip
  70.       {
  71.          var toolBtn:MovieClip = null;
  72.          for(var i:int = 0; i < this.toolBtns.length; i++)
  73.          {
  74.             if(this.toolBtns[i].toolName == toolName)
  75.             {
  76.                toolBtn = this.toolBtns[i];
  77.             }
  78.          }
  79.          return toolBtn;
  80.       }
  81.       
  82.       override public function update(update:Update = null) : void
  83.       {
  84.          if(update.type == UpdateEvent.WINDOW)
  85.          {
  86.             this.toolbarAsset.x = UI.WIDTH - this.toolbarAsset.width - 0.7;
  87.             this.toolbarAsset.bg.height = UI.HEIGHT - 32 - 0.7;
  88.          }
  89.          else if(update.type == UpdateEvent.COLOR)
  90.          {
  91.             this._setColor(update.data.color);
  92.          }
  93.       }
  94.       
  95.       public function get panelAsset() : Sprite
  96.       {
  97.          return this.toolbarAsset;
  98.       }
  99.       
  100.       public function toggleToolName(name:String) : void
  101.       {
  102.          this.toggleTool(this.getBtnByToolName(name).name);
  103.       }
  104.       
  105.       override protected function createController() : void
  106.       {
  107.          controller = new ToolbarController(this);
  108.       }
  109.       
  110.       public function toggleTool(name:String) : void
  111.       {
  112.          var toolBtn:MovieClip = this.toolbarAsset[name];
  113.          this.resetToolBtns();
  114.          toolBtn.gotoAndStop(2);
  115.       }
  116.    }
  117. }
  118.  
  119.