From: Brendan Hansen Date: Mon, 18 Apr 2022 18:09:04 +0000 (+0000) Subject: added mouse interactions X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=c1335c99d1b1b49bd14960d12f90fbd3406744ae;p=onyx-live.git added mouse interactions --- diff --git a/canvas.onyx b/canvas.onyx index dbde269..3bd8768 100644 --- a/canvas.onyx +++ b/canvas.onyx @@ -50,3 +50,22 @@ stroke_rect :: (x: f32, y: f32, w: f32, h: f32) -> void #foreign "canvas" stroke_text :: (text: str, x: f32, y: f32, max_width := -1.0f) -> void #foreign "canvas" "stroke_text" --- transform :: (a: f32, b: f32, c: f32, d: f32, e: f32, f: f32) -> void #foreign "canvas" "transform" --- translate :: (x: f32, y: f32) -> void #foreign "canvas" "translate" --- + +// Mouse interaction +// This one does not wait for a click, and live updates. +// Use '.sync' +mouse_position_internal :: (out_x: ^f32, out_y: ^f32) -> void #foreign "canvas" "mouse_position" --- +mouse_position :: () -> (f32, f32) { + mx, my: f32; + mouse_position_internal(^mx, ^my); + return mx, my; +} + +// This one waits for a click event to happen, and returns the position +// on the canvas where the click occurs. +mouse_click_internal :: (out_x, out_y: ^f32) -> void #foreign "canvas" "mouse_get_click" --- +mouse_click :: () -> (f32, f32) { + mx, my: f32; + mouse_click_internal(^mx, ^my); + return mx, my; +} diff --git a/serve.py b/serve.py index 30c13ed..d62a27b 100644 --- a/serve.py +++ b/serve.py @@ -19,7 +19,7 @@ def get_homepage(): use package core -main :: (args: [] cstr) { +main :: () { println("Hello, Onyx!"); }"""