aboutsummaryrefslogtreecommitdiff
path: root/client/paintui
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-04-08 02:28:59 +0100
committerubq323 <ubq323@ubq323.website>2024-04-08 02:28:59 +0100
commit40231bd839dbe5b8aa65e8f3bde31bd33b9a9190 (patch)
tree35b81246f7b741aa1bbb75f697f426b777f98974 /client/paintui
parentd097561c1ee24f20d5dd48fbe35301e8d9cc7cac (diff)
giant refactor, start to use drawing ops for drawing
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;
+};
+