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
use crate::KeyboardEvent;

/// Enum describing any of the possible events.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Event {
	/// A keyboard event.
	KeyboardEvent(KeyboardEvent),

	/// A mouse move event.
	MouseMoveEvent(MouseMoveEvent),

	/// A mouse button event.
	MouseButtonEvent(MouseButtonEvent),
}

/// Information describing a mouse state.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MouseButtonState {
	/// The state of the left mouse button.
	pub left: bool,

	/// The state of the middle mouse button.
	pub middle: bool,

	/// The state of the right mouse button.
	pub right: bool,
}

/// Information describing a mouse move event.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MouseMoveEvent {
	/// The mouse ID identifying which mouse triggered the event.
	pub mouse_id: u32,

	/// State of the mouse buttons at the time of the event triggering.
	pub mouse_state: MouseButtonState,

	/// The X coordinate of the mouse relative to the window.
	pub position_x: i32,

	/// The Y coordinate of the mouse relative to the window.
	pub position_y: i32,

	/// The relative X coordinate w.r.t. the previous event of the mouse relative to the window.
	pub relative_x: i32,

	/// The relative Y coordinate w.r.t. the previous event of the mouse relative to the window.
	pub relative_y: i32,
}

/// Enum describing the mouse buttons.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum MouseButton {
	/// Some unknown button.
	Unknown,

	/// The left mouse button.
	Left,

	/// The middle mouse button.
	Middle,

	/// The right mouse button.
	Right,
}

/// Enum describing the mouse buttons.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum MouseState {
	/// State when a button is pressed.
	Down,

	/// State when a button is released.
	Up,
}

/// Information describing a mouse button event.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MouseButtonEvent {
	/// The mouse ID identifying which mouse triggered the event.
	pub mouse_id: u32,

	/// The button that triggered the event.
	pub button: MouseButton,

	/// State after triggering the event.
	pub state: MouseState,

	/// Number of clicks that happened.
	pub clicks: u8,

	/// The X coordinate of the mouse relative to the window.
	pub position_x: i32,

	/// The Y coordinate of the mouse relative to the window.
	pub position_y: i32,
}