added mouse interactions
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 18 Apr 2022 18:09:04 +0000 (18:09 +0000)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 18 Apr 2022 18:09:04 +0000 (18:09 +0000)
canvas.onyx
serve.py

index dbde2690f76aa74e40823e02c60c49db5718f800..3bd87680d560c18914a0f1dd4d69766ca2115a68 100644 (file)
@@ -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;
+}
index 30c13ed92f26cadd7f40b6d4b15395d6c93778e6..d62a27bc8f53e9b305e934b9586a08f6a54633b1 100644 (file)
--- a/serve.py
+++ b/serve.py
@@ -19,7 +19,7 @@ def get_homepage():
 
 use package core
 
-main :: (args: [] cstr) {
+main :: () {
     println("Hello, Onyx!");
 }"""