summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2024-04-15 22:12:38 +0100
committerubq323 <ubq323@ubq323.website>2024-04-15 22:12:38 +0100
commit9bb892b35308919ff93d22e12387e6bdc0a64223 (patch)
tree4c3dd5c1fbb81b2e4b25f0202a102fb62b6f9ceb /client
parent5333dc18382ecb0a2286712718ac3b4225fedf64 (diff)
get smooth brush strokes working to my present satisfaction
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 = {