aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/paintui/paintui.ha29
1 files changed, 19 insertions, 10 deletions
diff --git a/client/paintui/paintui.ha b/client/paintui/paintui.ha
index 81fa7ca..4f656c4 100644
--- a/client/paintui/paintui.ha
+++ b/client/paintui/paintui.ha
@@ -37,27 +37,36 @@ export type state = struct {
color: u32
};
+fn abs(x: i32) i32 = if(x < 0) -x else x;
+
export fn tick(
pstate: *state,
mouse_pos: pos, mouse_pressed: bool
) (void | drawing::op) = {
+
+ // always update last_mouse_pos and last_mouse_pressed
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)))
- drawing::op_stroke {
+ const radius = sizes[pstate.size_idx];
+
+ const newly_pressed = mouse_pressed && !pstate.last_mouse_pressed;
+ const position_moved = (mouse_pos.0 != pstate.last_mouse_pos.0
+ || mouse_pos.1 != pstate.last_mouse_pos.1);
+
+ if (!mouse_pressed) return void;
+ return if (newly_pressed) drawing::op_circle {
+ pos = mouse_pos,
+ radius = radius,
+ color = pstate.color,
+ } else if (position_moved) drawing::op_stroke {
+ pos0 = pstate.last_mouse_pos,
pos1 = mouse_pos,
- pos0 = (0,0),
- radius = sizes[pstate.size_idx],
+ radius = radius,
color = pstate.color,
- }
- else void;
+ } else void;
};
export fn mousewheel(pstate: *state, amt: i32) void = {