Created
June 11, 2020 04:14
-
-
Save uvtc/143ceabdf0a7737282c2a0e0de02d3d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package; | |
import haxe.ui.HaxeUIApp; | |
import haxe.ui.core.Component; | |
import haxe.ui.macros.ComponentMacros; | |
import haxe.ui.components.Button; | |
import haxe.ui.components.Slider; | |
import haxe.ui.components.Label; | |
import haxe.ui.containers.Box; | |
import hx.widgets.Panel; | |
import hx.widgets.GraphicsContext; | |
import hx.widgets.PaintDC; | |
import hx.widgets.Pen; | |
import hx.widgets.Brush; | |
import hx.widgets.StockBrushes; | |
import hx.widgets.AntialiasMode; | |
import hx.widgets.EventType; | |
import hx.widgets.Rect; | |
class Main { | |
static var mainView:Component; | |
static var button1:Button; | |
static var slider1:Slider; | |
static var panel1:Panel; | |
static var rect_size:Float = 0; | |
public static function main() { | |
var app = new HaxeUIApp(); | |
app.ready(function() { | |
mainView = ComponentMacros.buildComponent("assets/main.xml"); | |
app.addComponent(mainView); | |
// Set the static variables to their components. | |
button1 = mainView.findComponent("button1", Button); | |
slider1 = mainView.findComponent("slider1", Slider); | |
var box1 = mainView.findComponent("box1", Box); | |
panel1 = cast(box1.window, Panel); | |
// Connect up events to handlers. | |
panel1.bind(EventType.PAINT, drawPanel1); | |
button1.onClick = handleButton1; | |
slider1.onChange = handleSlider1; | |
app.start(); | |
}); | |
} | |
public static function drawPanel1(e) { | |
var dc = new PaintDC(panel1); | |
dc.background = StockBrushes.BRUSH_BLACK; | |
dc.clear(); | |
dc.textForeground = 0xFF00FF; | |
dc.drawText("Hello, drawing!", 10, 10); | |
dc.pen = new Pen(0xff0000, 3); | |
dc.brush = new Brush(0x880000); | |
dc.drawRoundedRectangle( | |
10, 30, | |
100 + Std.int(rect_size * 2), | |
100 + Std.int(rect_size), | |
10); | |
dc.pen = new Pen(0xffffff, 3); | |
dc.drawLine(10, 120, Std.int(10 + rect_size), Std.int(120 + rect_size)); | |
dc.gradientFillLinear(new Rect(10, 200, 100, 50), 0xFF8888, 0x88FFFF); | |
} | |
public static function handleButton1(e) { | |
trace("button clicked!"); | |
} | |
public static function handleSlider1(e) { | |
rect_size = slider1.pos; | |
panel1.refresh(); | |
panel1.update(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment