From 40231bd839dbe5b8aa65e8f3bde31bd33b9a9190 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 8 Apr 2024 02:28:59 +0100 Subject: giant refactor, start to use drawing ops for drawing --- client/paintui/paintui.ha | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 client/paintui/paintui.ha (limited to 'client/paintui') 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; +}; + -- cgit v1.2.3