Advertisement
Guest User

Untitled

a guest
Apr 29th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haxe 3.02 KB | None | 0 0
  1. import haxe.ui.containers.Box;
  2. import haxe.ui.events.MouseEvent;
  3. import haxe.ui.events.UIEvent;
  4. import openfl.geom.ColorTransform;
  5.  
  6. @:xml("
  7.    <vbox style='padding: 10px; border: 2px solid black; background-color: white; border-radius: 5px;'>
  8.        <hbox>
  9.            <label text='Current bunny count:' />
  10.            <label id='currentBunnyCountLabel' />
  11.        </hbox>
  12.        <hbox>
  13.            <textfield id='bunniesToAddField' text='100' />
  14.            <button id='addButton' text='Add Bunnies!' repeater='true' />
  15.        </hbox>
  16.        <grid columns='3'>
  17.            <label text='Rotation' />
  18.            <slider id='rotationSlider' max='360' precision='0' />
  19.            <label text='${rotationSlider.pos}' />
  20.            
  21.            <label text='Red' />
  22.            <slider id='redSlider' max='1' pos='1' precision='1' />
  23.            <label text='${redSlider.pos}' />
  24.            
  25.            <label text='Green' />
  26.            <slider id='greenSlider' max='1' pos='1' precision='1' />
  27.            <label text='${greenSlider.pos}' />
  28.            
  29.            <label text='Blue' />
  30.            <slider id='blueSlider' max='1' pos='1' precision='1' />
  31.            <label text='${blueSlider.pos}' />
  32.        </grid>
  33.    </vbox>
  34. ")
  35. class Panel extends Box {
  36.     @:bind(currentBunnyCountLabel)      public var currentBunnyCount:String = "0";
  37.     @:bind(bunniesToAddField)           public var bunniesToAdd:String;
  38.    
  39.     public function new() {
  40.         super();
  41.         currentBunnyCount = Std.string(Main.instance.bunnies.length);
  42.     }
  43.  
  44.     @:bind(addButton, MouseEvent.MOUSE_DOWN)
  45.     function onAddMouseDown(e) {
  46.         Main.instance.addingBunnies = true;
  47.         currentBunnyCount = Std.string(Main.instance.bunnies.length);
  48.     }
  49.    
  50.     @:bind(addButton, MouseEvent.MOUSE_UP)
  51.     function onAddMouseUp(e) {
  52.         Main.instance.addingBunnies = false;
  53.         currentBunnyCount = Std.string(Main.instance.bunnies.length);
  54.     }
  55.    
  56.    
  57.     @:bind(rotationSlider, UIEvent.CHANGE)
  58.     function onRotationChange(e) {
  59.         for (bunny in Main.instance.bunnies) {
  60.             bunny.rotation = rotationSlider.pos;
  61.         }
  62.     }
  63.    
  64.     @:bind(redSlider, UIEvent.CHANGE, updateColor)
  65.     function onRedChange(e) {
  66.         updateColor();
  67.     }
  68.    
  69.     @:bind(greenSlider, UIEvent.CHANGE, updateColor)
  70.     function onGreenChange(e) {
  71.         updateColor();
  72.     }
  73.    
  74.     @:bind(blueSlider, UIEvent.CHANGE, updateColor)
  75.     function onBlueChange(e) {
  76.         updateColor();
  77.     }
  78.    
  79.     function updateColor() {
  80.         for (bunny in Main.instance.bunnies) {
  81.             if (bunny.colorTransform == null) {
  82.                 bunny.colorTransform = new ColorTransform(redSlider.pos, greenSlider.pos, blueSlider.pos);
  83.             } else {
  84.                 bunny.colorTransform.redMultiplier = redSlider.pos;
  85.                 bunny.colorTransform.greenMultiplier = greenSlider.pos;
  86.                 bunny.colorTransform.blueMultiplier = blueSlider.pos;
  87.             }
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement