home *** CD-ROM | disk | FTP | other *** search
- package com.livebrush.ui
- {
- import com.livebrush.events.CanvasEvent;
- import com.livebrush.graphics.canvas.Canvas;
- import com.livebrush.graphics.canvas.CanvasManager;
- import com.livebrush.graphics.canvas.Layer;
- import com.livebrush.styles.StrokeStyle;
- import com.livebrush.utils.Controller;
- import fl.controls.ComboBox;
- import fl.controls.TextInput;
- import fl.data.DataProvider;
- import flash.events.Event;
- import flash.events.MouseEvent;
- import org.casalib.util.NumberUtil;
-
- public class UIController extends Controller
- {
- public function UIController(uiView:UIView)
- {
- super(uiView);
- }
-
- public static function registerTypeControl(comboBox:ComboBox, dataSet:Array, changeHandler:Function, notifyPanel:Boolean = true, rowCount:int = 10) : void
- {
- comboBox.dataProvider = new DataProvider(dataSet);
- comboBox.rowCount = rowCount;
- comboBox.addEventListener(Event.CHANGE,changeHandler);
- }
-
- public static function typeInputIsAutomatic(s:String) : Boolean
- {
- return s == StrokeStyle.ROTATE || s == StrokeStyle.OSC;
- }
-
- public static function toDataList(l:Array) : Array
- {
- var dL:Array = [];
- for(var i:int = 0; i < l.length; i++)
- {
- dL.push(l[i].data);
- }
- return dL;
- }
-
- public static function toNumber(value:Object) : Number
- {
- return Number(value);
- }
-
- public static function speed(value:Object) : Number
- {
- return toFraction(minMax(toNumber(value)));
- }
-
- public static function minMax(value:Object, min:Number = 1, max:Number = 1000) : Number
- {
- value = toNumber(value);
- return NumberUtil.constrain(Number(value),min,max);
- }
-
- public static function toObjList(l:Array) : Array
- {
- var dL:Array = [];
- for(var i:int = 0; i < l.length; i++)
- {
- dL.push({"data":l[i]});
- }
- return dL;
- }
-
- public static function time(value:Object) : Number
- {
- return toNumber(value) * 1000;
- }
-
- public static function toFraction(value:Object, div:Number = 100) : Number
- {
- return toNumber(value) / div;
- }
-
- override public function die() : void
- {
- this.canvasManager.removeEventListener(CanvasEvent.MOUSE_EVENT,this.canvasMouseEvent);
- }
-
- public function toObjList(l:Array) : Array
- {
- return UIController.toObjList(l);
- }
-
- public function registerTypeControl(comboBox:ComboBox, dataSet:Array, changeHandler:Function, notifyPanel:Boolean = true, rowCount:int = 10) : void
- {
- UIController.registerTypeControl(comboBox,dataSet,changeHandler);
- }
-
- public function toDataList(l:Array) : Array
- {
- return UIController.toDataList(l);
- }
-
- protected function contentRightMouseDown(e:MouseEvent) : void
- {
- }
-
- protected function openCanvasMouseDown(e:MouseEvent) : void
- {
- }
-
- protected function _loadHelp() : void
- {
- this.ui.loadHelp(UIView(view).helpID);
- }
-
- public function speed(value:Object) : Number
- {
- return UIController.speed(value);
- }
-
- protected function canvasMouseUp(e:MouseEvent) : void
- {
- }
-
- protected function registerTextInput(textInput:TextInput, changeHandler:Function, restrict:String = "0123456789", maxChars:int = 3) : void
- {
- textInput.restrict = restrict;
- textInput.addEventListener(Event.CHANGE,changeHandler);
- textInput.maxChars = maxChars;
- }
-
- public function get activeLayer() : Layer
- {
- return this.canvasManager.activeLayer;
- }
-
- protected function canvasMouseEvent(e:CanvasEvent) : void
- {
- var mouseEvent:MouseEvent = null;
- var clickedContent:Boolean = false;
- if(!Layer.isBackgroundLayer(this.activeLayer))
- {
- mouseEvent = e.triggerEvent as MouseEvent;
- clickedContent = this.activeLayer.mouseHitTest();
- if(mouseEvent.type == MouseEvent.MOUSE_DOWN)
- {
- if(clickedContent)
- {
- this.contentMouseDown(mouseEvent);
- }
- else
- {
- this.openCanvasMouseDown(mouseEvent);
- }
- }
- else if(mouseEvent.type == MouseEvent.MOUSE_UP)
- {
- this.canvasMouseUp(mouseEvent);
- }
- else if(mouseEvent.type == MouseEvent.RIGHT_MOUSE_DOWN)
- {
- if(clickedContent)
- {
- this.contentRightMouseDown(mouseEvent);
- }
- }
- }
- }
-
- protected function contentMouseDown(e:MouseEvent) : void
- {
- }
-
- public function get activeLayers() : Array
- {
- return this.canvasManager.activeLayers;
- }
-
- override protected function init() : void
- {
- this.canvasManager.addEventListener(CanvasEvent.MOUSE_EVENT,this.canvasMouseEvent);
- }
-
- public function minMax(value:Object, min:Number = 1, max:Number = NaN) : Number
- {
- return UIController.minMax(value,min,max);
- }
-
- protected function get ui() : UI
- {
- return UIView(view).ui;
- }
-
- public function get canvasManager() : CanvasManager
- {
- return this.ui.canvasManager;
- }
-
- protected function registerMinMaxInput(name:String, changeHandler:Function, notifyPanel:Boolean = true, restrict:String = "0123456789", maxChars:int = 3) : void
- {
- }
-
- public function get canvas() : Canvas
- {
- return this.canvasManager.canvas;
- }
-
- protected function registerSliderControl(slider:SliderInput, changeHandler:Function, label:String = "Slider Control", min:Number = 0.01, max:Number = 100, mid:Number = 50) : void
- {
- slider.label = label;
- slider.max = max;
- slider.min = min;
- slider.value = mid;
- slider.addEventListener(Event.CHANGE,changeHandler);
- }
-
- public function time(value:Object) : Number
- {
- return UIController.time(value);
- }
-
- public function toNumber(value:Object) : Number
- {
- return UIController.toNumber(value);
- }
-
- public function toFraction(value:Object, div:Number = 100) : Number
- {
- return UIController.toFraction(value,div);
- }
- }
- }
-
-