Own-Programming-Language-Tu.../examples/canvas/fx_event_handlers.own

17 lines
525 B
Scala
Raw Normal View History

2023-09-09 15:52:32 +03:00
use canvasfx, std
2016-02-21 17:32:58 +02:00
w = 800 h = 600
2016-05-24 14:40:11 +03:00
g = window("JavaFX Event handler example", w, h)
2016-02-21 17:32:58 +02:00
addEventHandler(Events.MOUSE_MOVED, ::onMouseMoved)
addEventHandler(Events.MOUSE_DRAGGED, ::onMouseMoved)
addEventHandler(Events.KEY_PRESSED, def(e) {
if (e.code == KeyCode.C) clearRect(0, 0, w, h)
})
def onMouseMoved(e) {
2016-05-24 14:40:11 +03:00
g.setFill(Color.rgb(rand(255), rand(255), rand(255), rand()))
2016-02-21 17:32:58 +02:00
m = 1 + e.isPrimaryButtonDown + e.isSecondaryButtonDown
radius = m * rand(30, 50)
2016-05-24 14:40:11 +03:00
g.fillOval(e.x - radius/2, e.y - radius/2, radius, radius)
2016-02-21 17:32:58 +02:00
}