about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--graphics.mu20
-rw-r--r--mu.arc17
2 files changed, 37 insertions, 0 deletions
diff --git a/graphics.mu b/graphics.mu
new file mode 100644
index 00000000..c4520c8f
--- /dev/null
+++ b/graphics.mu
@@ -0,0 +1,20 @@
+; open a viewport, print coordinates of mouse clicks
+; currently need to ctrl-c to exit after closing the viewport
+(function main [
+  (graphics-on)
+  { begin
+    (pos:integer-integer-pair click?:boolean <- mouse-position)
+    { begin
+      (break-if click?:boolean)
+      (loop 2:blocks)
+    }
+    (x:integer <- get pos:integer-integer-pair 0:offset)
+    (y:integer <- get pos:integer-integer-pair 1:offset)
+    (print-primitive x:integer)
+    (print-primitive ((", " literal)))
+    (print-primitive y:integer)
+    (print-primitive (("\n" literal)))
+    (loop)
+  }
+  (graphics-off)
+])
diff --git a/mu.arc b/mu.arc
index c3527369..79f5586b 100644
--- a/mu.arc
+++ b/mu.arc
@@ -323,6 +323,8 @@
       typeinfo.operand!address))
 
 ($:require "charterm/main.rkt")
+($:require graphics/graphics)
+(= Viewport nil)
 
 ; run instructions from 'routine*' for 'time-slice'
 (def run-for-time-slice (time-slice)
@@ -518,6 +520,21 @@
                 console-off
                   (do1 nil (if ($.current-charterm) ($.close-charterm)))
 
+                ; graphics
+                graphics-on
+                  (do1 nil
+                    ($.open-graphics)
+                    (= Viewport ($.open-viewport "practice" 300 300)))
+                graphics-off
+                  (do1 nil
+                    ($.close-graphics)
+                    (= Viewport nil))
+                mouse-position
+                  (aif ($.ready-mouse-click Viewport)
+                    (let posn ($.mouse-click-posn it)
+                      (list (annotate 'record (list ($.posn-x posn) ($.posn-y posn))) t))
+                    (list nil nil))
+
                 ; user-defined functions
                 next-input
                   (let idx caller-arg-idx.routine*