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 / LineStyleView.as < prev    next >
Encoding:
Text File  |  2009-10-26  |  9.4 KB  |  249 lines

  1. package com.livebrush.ui
  2. {
  3.    import com.livebrush.data.Settings;
  4.    import com.livebrush.events.UpdateEvent;
  5.    import com.livebrush.styles.StrokeStyle;
  6.    import com.livebrush.utils.Update;
  7.    import fl.controls.List;
  8.    
  9.    public class LineStyleView extends UIView
  10.    {
  11.       public static const EDGE_ANGLE_TYPES:Array = [{
  12.          "label":"Fixed",
  13.          "data":StrokeStyle.FIXED
  14.       },{
  15.          "label":"Draw Speed",
  16.          "data":StrokeStyle.SPEED
  17.       },{
  18.          "label":"Stroke Width",
  19.          "data":StrokeStyle.WIDTH
  20.       },{
  21.          "label":"Stroke Direction",
  22.          "data":StrokeStyle.DIR
  23.       },{
  24.          "label":"Oscillate",
  25.          "data":StrokeStyle.OSC
  26.       },{
  27.          "label":"Rotate",
  28.          "data":StrokeStyle.ROTATE
  29.       },{
  30.          "label":"Random",
  31.          "data":StrokeStyle.RANDOM
  32.       }];
  33.       
  34.       public static const STROKE_TYPES:Array = [{
  35.          "label":"Solid",
  36.          "data":StrokeStyle.SOLID_STROKE
  37.       },{
  38.          "label":"Rake",
  39.          "data":StrokeStyle.RAKE_STROKE
  40.       },{
  41.          "label":"Path",
  42.          "data":StrokeStyle.PATH_STROKE
  43.       },{
  44.          "label":"None",
  45.          "data":StrokeStyle.NONE
  46.       }];
  47.       
  48.       public static const WIDTH_TYPES:Array = [{
  49.          "label":"Fixed",
  50.          "data":StrokeStyle.FIXED
  51.       },{
  52.          "label":"Draw Speed",
  53.          "data":StrokeStyle.SPEED
  54.       },{
  55.          "label":"Oscillate",
  56.          "data":StrokeStyle.OSC
  57.       },{
  58.          "label":"Random",
  59.          "data":StrokeStyle.RANDOM
  60.       }];
  61.       
  62.       public static const COLOR_TYPES:Array = [{
  63.          "label":"Fixed",
  64.          "data":StrokeStyle.FIXED
  65.       },{
  66.          "label":"Multiple",
  67.          "data":StrokeStyle.LIST
  68.       },{
  69.          "label":"Brush Position",
  70.          "data":StrokeStyle.SAMPLE_BRUSH
  71.       },{
  72.          "label":"Mouse Position",
  73.          "data":StrokeStyle.SAMPLE
  74.       },{
  75.          "label":"Random",
  76.          "data":StrokeStyle.RANDOM
  77.       },{
  78.          "label":"None",
  79.          "data":StrokeStyle.NONE
  80.       }];
  81.       
  82.       public static const ALPHA_TYPES:Array = [{
  83.          "label":"Fixed",
  84.          "data":StrokeStyle.FIXED
  85.       },{
  86.          "label":"Draw Speed",
  87.          "data":StrokeStyle.SPEED
  88.       },{
  89.          "label":"Stroke Width",
  90.          "data":StrokeStyle.WIDTH
  91.       },{
  92.          "label":"Oscillate",
  93.          "data":StrokeStyle.OSC
  94.       },{
  95.          "label":"Random",
  96.          "data":StrokeStyle.RANDOM
  97.       }];
  98.       
  99.       public static const LINE_TYPES:Array = [{
  100.          "label":"Smooth",
  101.          "data":StrokeStyle.SMOOTH
  102.       },{
  103.          "label":"Straight",
  104.          "data":StrokeStyle.STRAIGHT
  105.       }];
  106.       
  107.       private var _colorInputs:SequenceList;
  108.       
  109.       public var brushPropsModel:BrushPropsModel;
  110.       
  111.       public var uiAsset:LineStyleUI;
  112.       
  113.       public function LineStyleView(brushPropsModel:BrushPropsModel)
  114.       {
  115.          super(brushPropsModel.ui);
  116.          this.brushPropsModel = brushPropsModel;
  117.          init();
  118.       }
  119.       
  120.       override protected function createView() : void
  121.       {
  122.          this.uiAsset = new LineStyleUI();
  123.          this.uiAsset.lineTypeHead.label.text = "Line Type".toUpperCase();
  124.          this.uiAsset.lineType.dataProvider = Settings.arrayToDataProvider(LINE_TYPES);
  125.          this.uiAsset.strokeTypeHead.label.text = "Edge Type".toUpperCase();
  126.          this.uiAsset.strokeInputs.label1 = "Lines";
  127.          this.uiAsset.strokeInputs.label2 = "Weight";
  128.          this.uiAsset.strokeInputs.list = STROKE_TYPES;
  129.          this.uiAsset.strokeInputs.toggleInput(2,false);
  130.          this.uiAsset.lineWidthHead.label.text = "Width".toUpperCase();
  131.          this.uiAsset.widthInputs.list = WIDTH_TYPES;
  132.          this.uiAsset.lineAngleHead.label.text = "Angle".toUpperCase();
  133.          this.uiAsset.angleInputs.list = EDGE_ANGLE_TYPES;
  134.          this._colorInputs = new SequenceList(this.uiAsset.colorInputs,ColorListItem);
  135.          this.uiAsset.lineColorHead.label.text = "Color".toUpperCase();
  136.          this._colorInputs.speedLabel = "Tween";
  137.          this._colorInputs.typeList = COLOR_TYPES;
  138.          this._colorInputs.holdInput.label = "Hold";
  139.          this._colorInputs.holdInput.min = 0;
  140.          this.uiAsset.lineAlphaHead.label.text = "Opacity".toUpperCase();
  141.          this.uiAsset.alphaInputs.list = ALPHA_TYPES;
  142.          this.uiAsset.strokeInputs.setMinMax(1,500);
  143.          this.uiAsset.strokeInputs._input1.min = 0.25;
  144.          this.uiAsset.strokeInputs._input1.max = 16;
  145.          this.uiAsset.widthInputs.setMinMax(0,1000,1,1000);
  146.          this.uiAsset.angleInputs.setMinMax(0,360,1,360);
  147.          this.uiAsset.alphaInputs.setMinMax(0,100,1,100);
  148.          Tooltip.addTip(this.uiAsset.colorInputs._listEditor.addBtn,"Duplicate selected color");
  149.          Tooltip.addTip(this.uiAsset.colorInputs._listEditor.removeBtn,"Remove selected color");
  150.          Tooltip.addTip(this.uiAsset.colorInputs._listEditor.upBtn,"Move color up");
  151.          Tooltip.addTip(this.uiAsset.colorInputs._listEditor.downBtn,"Move color down");
  152.       }
  153.       
  154.       public function applyProps() : void
  155.       {
  156.          try
  157.          {
  158.             this.uiAsset.strokeInputs._input0._input.enabled = this.uiAsset.strokeInputs.type == StrokeStyle.RAKE_STROKE || this.uiAsset.strokeInputs.type == StrokeStyle.PATH_STROKE;
  159.             this.uiAsset.strokeInputs._input1._input.enabled = this.uiAsset.strokeInputs._input0._input.enabled;
  160.             this.uiAsset.widthInputs.speedEnabled = typeInputIsAutomatic(this.uiAsset.widthInputs.type);
  161.             this.uiAsset.angleInputs.speedEnabled = typeInputIsAutomatic(this.uiAsset.angleInputs.type);
  162.             this.uiAsset.alphaInputs.speedEnabled = typeInputIsAutomatic(this.uiAsset.alphaInputs.type);
  163.             this._colorInputs.speedEnabled = StrokeStyle.LIST == String(this._colorInputs.type);
  164.          }
  165.          catch(e:Error)
  166.          {
  167.          }
  168.       }
  169.       
  170.       override public function get settings() : Settings
  171.       {
  172.          var settings:Settings = new Settings();
  173.          settings.smoothing = this.uiAsset.lineType.selectedIndex == 0;
  174.          settings.strokeType = this.uiAsset.strokeInputs.type;
  175.          settings.lines = this.uiAsset.strokeInputs.input0;
  176.          settings.weight = this.uiAsset.strokeInputs.input1;
  177.          settings.angleType = this.uiAsset.angleInputs.type;
  178.          settings.minAngle = this.uiAsset.angleInputs.min;
  179.          settings.maxAngle = this.uiAsset.angleInputs.max;
  180.          settings.angleSpeed = this.uiAsset.angleInputs.speed;
  181.          settings.widthType = this.uiAsset.widthInputs.type;
  182.          settings.minWidth = this.uiAsset.widthInputs.min;
  183.          settings.maxWidth = this.uiAsset.widthInputs.max;
  184.          settings.widthSpeed = this.uiAsset.widthInputs.speed / 100;
  185.          settings.colorType = this._colorInputs.type;
  186.          settings.colorObjList = this._colorInputs.list;
  187.          settings.colorSteps = this._colorInputs.speed;
  188.          settings.colorHold = this._colorInputs.holdInput.value;
  189.          settings.alphaType = this.uiAsset.alphaInputs.type;
  190.          settings.minAlpha = this.uiAsset.alphaInputs.min / 100;
  191.          settings.maxAlpha = this.uiAsset.alphaInputs.max / 100;
  192.          settings.alphaSpeed = this.uiAsset.alphaInputs.speed / 100;
  193.          return settings;
  194.       }
  195.       
  196.       public function get colorInputs() : SequenceList
  197.       {
  198.          return this._colorInputs;
  199.       }
  200.       
  201.       override public function update(update:Update = null) : void
  202.       {
  203.          if(!(update.type == UpdateEvent.WINDOW || update.type == UpdateEvent.UI))
  204.          {
  205.             if(update.type == UpdateEvent.BRUSH_STYLE)
  206.             {
  207.                this.settings = update.data.line as Settings;
  208.             }
  209.          }
  210.       }
  211.       
  212.       override public function set settings(settings:Settings) : void
  213.       {
  214.          this.uiAsset.lineType.selectedIndex = !!settings.smoothing ? 0 : 1;
  215.          this.uiAsset.strokeInputs.type = settings.strokeType;
  216.          this.uiAsset.strokeInputs.input0 = settings.lines;
  217.          this.uiAsset.strokeInputs.input1 = settings.weight;
  218.          this.uiAsset.angleInputs.type = settings.angleType;
  219.          this.uiAsset.angleInputs.min = settings.minAngle;
  220.          this.uiAsset.angleInputs.max = settings.maxAngle;
  221.          this.uiAsset.angleInputs.speed = settings.angleSpeed;
  222.          this.uiAsset.widthInputs.type = settings.widthType;
  223.          this.uiAsset.widthInputs.min = settings.minWidth;
  224.          this.uiAsset.widthInputs.max = settings.maxWidth;
  225.          this.uiAsset.widthInputs.speed = settings.widthSpeed * 100;
  226.          this._colorInputs.type = settings.colorType;
  227.          this._colorInputs.dataProvider = settings.colorObjList;
  228.          this._colorInputs.speed = settings.colorSteps;
  229.          this._colorInputs.holdInput.value = settings.colorHold;
  230.          this.uiAsset.alphaInputs.type = settings.alphaType;
  231.          this.uiAsset.alphaInputs.min = settings.minAlpha * 100;
  232.          this.uiAsset.alphaInputs.max = settings.maxAlpha * 100;
  233.          this.uiAsset.alphaInputs.speed = settings.alphaSpeed * 100;
  234.          this.applyProps();
  235.       }
  236.       
  237.       public function get list() : List
  238.       {
  239.          return this.uiAsset.styleList;
  240.       }
  241.       
  242.       override protected function createController() : void
  243.       {
  244.          controller = new LineStyleController(this);
  245.       }
  246.    }
  247. }
  248.  
  249.