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 / UIController.as < prev    next >
Encoding:
Text File  |  2009-10-26  |  6.9 KB  |  232 lines

  1. package com.livebrush.ui
  2. {
  3.    import com.livebrush.events.CanvasEvent;
  4.    import com.livebrush.graphics.canvas.Canvas;
  5.    import com.livebrush.graphics.canvas.CanvasManager;
  6.    import com.livebrush.graphics.canvas.Layer;
  7.    import com.livebrush.styles.StrokeStyle;
  8.    import com.livebrush.utils.Controller;
  9.    import fl.controls.ComboBox;
  10.    import fl.controls.TextInput;
  11.    import fl.data.DataProvider;
  12.    import flash.events.Event;
  13.    import flash.events.MouseEvent;
  14.    import org.casalib.util.NumberUtil;
  15.    
  16.    public class UIController extends Controller
  17.    {
  18.       public function UIController(uiView:UIView)
  19.       {
  20.          super(uiView);
  21.       }
  22.       
  23.       public static function registerTypeControl(comboBox:ComboBox, dataSet:Array, changeHandler:Function, notifyPanel:Boolean = true, rowCount:int = 10) : void
  24.       {
  25.          comboBox.dataProvider = new DataProvider(dataSet);
  26.          comboBox.rowCount = rowCount;
  27.          comboBox.addEventListener(Event.CHANGE,changeHandler);
  28.       }
  29.       
  30.       public static function typeInputIsAutomatic(s:String) : Boolean
  31.       {
  32.          return s == StrokeStyle.ROTATE || s == StrokeStyle.OSC;
  33.       }
  34.       
  35.       public static function toDataList(l:Array) : Array
  36.       {
  37.          var dL:Array = [];
  38.          for(var i:int = 0; i < l.length; i++)
  39.          {
  40.             dL.push(l[i].data);
  41.          }
  42.          return dL;
  43.       }
  44.       
  45.       public static function toNumber(value:Object) : Number
  46.       {
  47.          return Number(value);
  48.       }
  49.       
  50.       public static function speed(value:Object) : Number
  51.       {
  52.          return toFraction(minMax(toNumber(value)));
  53.       }
  54.       
  55.       public static function minMax(value:Object, min:Number = 1, max:Number = 1000) : Number
  56.       {
  57.          value = toNumber(value);
  58.          return NumberUtil.constrain(Number(value),min,max);
  59.       }
  60.       
  61.       public static function toObjList(l:Array) : Array
  62.       {
  63.          var dL:Array = [];
  64.          for(var i:int = 0; i < l.length; i++)
  65.          {
  66.             dL.push({"data":l[i]});
  67.          }
  68.          return dL;
  69.       }
  70.       
  71.       public static function time(value:Object) : Number
  72.       {
  73.          return toNumber(value) * 1000;
  74.       }
  75.       
  76.       public static function toFraction(value:Object, div:Number = 100) : Number
  77.       {
  78.          return toNumber(value) / div;
  79.       }
  80.       
  81.       override public function die() : void
  82.       {
  83.          this.canvasManager.removeEventListener(CanvasEvent.MOUSE_EVENT,this.canvasMouseEvent);
  84.       }
  85.       
  86.       public function toObjList(l:Array) : Array
  87.       {
  88.          return UIController.toObjList(l);
  89.       }
  90.       
  91.       public function registerTypeControl(comboBox:ComboBox, dataSet:Array, changeHandler:Function, notifyPanel:Boolean = true, rowCount:int = 10) : void
  92.       {
  93.          UIController.registerTypeControl(comboBox,dataSet,changeHandler);
  94.       }
  95.       
  96.       public function toDataList(l:Array) : Array
  97.       {
  98.          return UIController.toDataList(l);
  99.       }
  100.       
  101.       protected function contentRightMouseDown(e:MouseEvent) : void
  102.       {
  103.       }
  104.       
  105.       protected function openCanvasMouseDown(e:MouseEvent) : void
  106.       {
  107.       }
  108.       
  109.       protected function _loadHelp() : void
  110.       {
  111.          this.ui.loadHelp(UIView(view).helpID);
  112.       }
  113.       
  114.       public function speed(value:Object) : Number
  115.       {
  116.          return UIController.speed(value);
  117.       }
  118.       
  119.       protected function canvasMouseUp(e:MouseEvent) : void
  120.       {
  121.       }
  122.       
  123.       protected function registerTextInput(textInput:TextInput, changeHandler:Function, restrict:String = "0123456789", maxChars:int = 3) : void
  124.       {
  125.          textInput.restrict = restrict;
  126.          textInput.addEventListener(Event.CHANGE,changeHandler);
  127.          textInput.maxChars = maxChars;
  128.       }
  129.       
  130.       public function get activeLayer() : Layer
  131.       {
  132.          return this.canvasManager.activeLayer;
  133.       }
  134.       
  135.       protected function canvasMouseEvent(e:CanvasEvent) : void
  136.       {
  137.          var mouseEvent:MouseEvent = null;
  138.          var clickedContent:Boolean = false;
  139.          if(!Layer.isBackgroundLayer(this.activeLayer))
  140.          {
  141.             mouseEvent = e.triggerEvent as MouseEvent;
  142.             clickedContent = this.activeLayer.mouseHitTest();
  143.             if(mouseEvent.type == MouseEvent.MOUSE_DOWN)
  144.             {
  145.                if(clickedContent)
  146.                {
  147.                   this.contentMouseDown(mouseEvent);
  148.                }
  149.                else
  150.                {
  151.                   this.openCanvasMouseDown(mouseEvent);
  152.                }
  153.             }
  154.             else if(mouseEvent.type == MouseEvent.MOUSE_UP)
  155.             {
  156.                this.canvasMouseUp(mouseEvent);
  157.             }
  158.             else if(mouseEvent.type == MouseEvent.RIGHT_MOUSE_DOWN)
  159.             {
  160.                if(clickedContent)
  161.                {
  162.                   this.contentRightMouseDown(mouseEvent);
  163.                }
  164.             }
  165.          }
  166.       }
  167.       
  168.       protected function contentMouseDown(e:MouseEvent) : void
  169.       {
  170.       }
  171.       
  172.       public function get activeLayers() : Array
  173.       {
  174.          return this.canvasManager.activeLayers;
  175.       }
  176.       
  177.       override protected function init() : void
  178.       {
  179.          this.canvasManager.addEventListener(CanvasEvent.MOUSE_EVENT,this.canvasMouseEvent);
  180.       }
  181.       
  182.       public function minMax(value:Object, min:Number = 1, max:Number = NaN) : Number
  183.       {
  184.          return UIController.minMax(value,min,max);
  185.       }
  186.       
  187.       protected function get ui() : UI
  188.       {
  189.          return UIView(view).ui;
  190.       }
  191.       
  192.       public function get canvasManager() : CanvasManager
  193.       {
  194.          return this.ui.canvasManager;
  195.       }
  196.       
  197.       protected function registerMinMaxInput(name:String, changeHandler:Function, notifyPanel:Boolean = true, restrict:String = "0123456789", maxChars:int = 3) : void
  198.       {
  199.       }
  200.       
  201.       public function get canvas() : Canvas
  202.       {
  203.          return this.canvasManager.canvas;
  204.       }
  205.       
  206.       protected function registerSliderControl(slider:SliderInput, changeHandler:Function, label:String = "Slider Control", min:Number = 0.01, max:Number = 100, mid:Number = 50) : void
  207.       {
  208.          slider.label = label;
  209.          slider.max = max;
  210.          slider.min = min;
  211.          slider.value = mid;
  212.          slider.addEventListener(Event.CHANGE,changeHandler);
  213.       }
  214.       
  215.       public function time(value:Object) : Number
  216.       {
  217.          return UIController.time(value);
  218.       }
  219.       
  220.       public function toNumber(value:Object) : Number
  221.       {
  222.          return UIController.toNumber(value);
  223.       }
  224.       
  225.       public function toFraction(value:Object, div:Number = 100) : Number
  226.       {
  227.          return UIController.toFraction(value,div);
  228.       }
  229.    }
  230. }
  231.  
  232.