home *** CD-ROM | disk | FTP | other *** search
- package com.livebrush.ui
- {
- import com.livebrush.events.UpdateEvent;
- import com.livebrush.tools.BrushTool;
- import com.livebrush.tools.ColorLayerTool;
- import com.livebrush.tools.HandTool;
- import com.livebrush.tools.PenTool;
- import com.livebrush.tools.SampleTool;
- import com.livebrush.tools.TransformTool;
- import com.livebrush.utils.Update;
- import flash.display.MovieClip;
- import flash.display.Sprite;
- import flash.geom.ColorTransform;
- import org.casalib.util.ColorUtil;
-
- public class ToolbarView extends UIView
- {
- private var _cf:ColorTransform;
-
- private var _color:uint;
-
- public var toolBtns:Array;
-
- public var toolbarAsset:ToolbarAsset;
-
- private var _colorHexValue:String;
-
- public function ToolbarView(ui:UI)
- {
- super(ui);
- helpID = "tools";
- init();
- }
-
- private function _setColor(u:uint) : void
- {
- var c:Object = ColorUtil.getRGB(u);
- this._colorHexValue = ColorUtil.getHexStringFromRGB(c.r,c.g,c.b);
- this._cf.color = u;
- this.toolbarAsset._colorBg.transform.colorTransform = this._cf;
- this._color = u;
- }
-
- override protected function createView() : void
- {
- this.toolbarAsset = new ToolbarAsset();
- this.toolbarAsset.cacheAsBitmap = true;
- UI.UI_HOLDER.addChild(this.toolbarAsset);
- this.toolbarAsset.y = 32;
- this.toolBtns = [this.toolbarAsset.brushBtn,this.toolbarAsset.penBtn,this.toolbarAsset.transformBtn,this.toolbarAsset.fillBtn,this.toolbarAsset.sampleBtn,this.toolbarAsset.handBtn];
- this.toolBtns[0].toolName = BrushTool.NAME;
- this.toolBtns[1].toolName = PenTool.NAME;
- this.toolBtns[2].toolName = TransformTool.NAME;
- this.toolBtns[3].toolName = ColorLayerTool.NAME;
- this.toolBtns[4].toolName = SampleTool.NAME;
- this.toolBtns[5].toolName = HandTool.NAME;
- this.toolbarAsset._colorBg.useHandCursor = true;
- this._cf = new ColorTransform();
- }
-
- public function resetToolBtns() : void
- {
- for(var i:int = 0; i < this.toolBtns.length; i++)
- {
- this.toolBtns[i].gotoAndStop(1);
- }
- }
-
- public function getBtnByToolName(toolName:String) : MovieClip
- {
- var toolBtn:MovieClip = null;
- for(var i:int = 0; i < this.toolBtns.length; i++)
- {
- if(this.toolBtns[i].toolName == toolName)
- {
- toolBtn = this.toolBtns[i];
- }
- }
- return toolBtn;
- }
-
- override public function update(update:Update = null) : void
- {
- if(update.type == UpdateEvent.WINDOW)
- {
- this.toolbarAsset.x = UI.WIDTH - this.toolbarAsset.width - 0.7;
- this.toolbarAsset.bg.height = UI.HEIGHT - 32 - 0.7;
- }
- else if(update.type == UpdateEvent.COLOR)
- {
- this._setColor(update.data.color);
- }
- }
-
- public function get panelAsset() : Sprite
- {
- return this.toolbarAsset;
- }
-
- public function toggleToolName(name:String) : void
- {
- this.toggleTool(this.getBtnByToolName(name).name);
- }
-
- override protected function createController() : void
- {
- controller = new ToolbarController(this);
- }
-
- public function toggleTool(name:String) : void
- {
- var toolBtn:MovieClip = this.toolbarAsset[name];
- this.resetToolBtns();
- toolBtn.gotoAndStop(2);
- }
- }
- }
-
-