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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
use crate::math::Vec2;
use crate::Context;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(
feature = "serde_support",
derive(serde::Serialize, serde::Deserialize)
)]
#[allow(missing_docs)]
pub enum MouseButton {
Left,
Middle,
Right,
X1,
X2,
}
pub fn is_mouse_button_down(ctx: &Context, button: MouseButton) -> bool {
ctx.input.mouse_buttons_down.contains(&button)
}
pub fn is_mouse_button_up(ctx: &Context, button: MouseButton) -> bool {
!ctx.input.mouse_buttons_down.contains(&button)
}
pub fn is_mouse_button_pressed(ctx: &Context, button: MouseButton) -> bool {
ctx.input.mouse_buttons_pressed.contains(&button)
}
pub fn is_mouse_button_released(ctx: &Context, button: MouseButton) -> bool {
ctx.input.mouse_buttons_released.contains(&button)
}
pub fn is_mouse_scrolled_up(ctx: &Context) -> bool {
get_mouse_wheel_movement(ctx).y > 0
}
pub fn is_mouse_scrolled_down(ctx: &Context) -> bool {
get_mouse_wheel_movement(ctx).y < 0
}
pub fn get_mouse_x(ctx: &Context) -> f32 {
ctx.input.mouse_position.x
}
pub fn get_mouse_y(ctx: &Context) -> f32 {
ctx.input.mouse_position.y
}
pub fn get_mouse_position(ctx: &Context) -> Vec2<f32> {
ctx.input.mouse_position
}
pub fn get_mouse_wheel_movement(ctx: &Context) -> Vec2<i32> {
ctx.input.mouse_wheel_movement
}
pub(crate) fn set_mouse_button_down(ctx: &mut Context, btn: MouseButton) -> bool {
let was_up = ctx.input.mouse_buttons_down.insert(btn);
if was_up {
ctx.input.mouse_buttons_pressed.insert(btn);
}
was_up
}
pub(crate) fn set_mouse_button_up(ctx: &mut Context, btn: MouseButton) -> bool {
let was_down = ctx.input.mouse_buttons_down.remove(&btn);
if was_down {
ctx.input.mouse_buttons_released.insert(btn);
}
was_down
}
pub(crate) fn set_mouse_position(ctx: &mut Context, position: Vec2<f32>) {
ctx.input.mouse_position = position;
}
pub(crate) fn apply_mouse_wheel_movement(ctx: &mut Context, wheel_movement: Vec2<i32>) {
ctx.input.mouse_wheel_movement += wheel_movement;
}