blob: ce55bb7fc7b71f9c702e4f94d7c2d969e7020783 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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;
};
|