summaryrefslogtreecommitdiff
path: root/client/paintui
diff options
context:
space:
mode:
Diffstat (limited to 'client/paintui')
-rw-r--r--client/paintui/paintui.ha38
1 files changed, 38 insertions, 0 deletions
diff --git a/client/paintui/paintui.ha b/client/paintui/paintui.ha
new file mode 100644
index 0000000..ce55bb7
--- /dev/null
+++ b/client/paintui/paintui.ha
@@ -0,0 +1,38 @@
+// paintui handles turning sdl input things
+// into drawing instructions
+// it might have some kind of state machine
+// for doing smooth lines between discrete mouse positions
+
+// all mouse pos stuff in this module is in world coordinates
+// someone else is responsible for doing the transform from
+// screen to world coords.
+
+use drawing;
+use drawing::{pos};
+
+export type state = struct {
+ // last known mouse position, in world coordinates
+ last_mouse_pos: pos,
+ // last known mouse pressed-ness
+ last_mouse_pressed: bool
+
+};
+
+export fn tick(
+ pstate: *state,
+ mouse_pos: pos, mouse_pressed: bool
+) (void | drawing::op) = {
+ defer {
+ pstate.last_mouse_pos = mouse_pos;
+ pstate.last_mouse_pressed = mouse_pressed;
+ };
+
+ // if mouse down and (position moved OR newly pressed)
+ return if (mouse_pressed
+ && (mouse_pos.0 != pstate.last_mouse_pos.0
+ || mouse_pos.1 != pstate.last_mouse_pos.1
+ || (!pstate.last_mouse_pressed)))
+ mouse_pos: drawing::op_circle
+ else void;
+};
+