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
use crate::{ElementState, Input};
use bevy_ecs::{event::EventReader, system::ResMut};
use bevy_math::Vec2;
#[derive(Debug, Clone)]
pub struct MouseButtonInput {
pub button: MouseButton,
pub state: ElementState,
}
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
pub enum MouseButton {
Left,
Right,
Middle,
Other(u16),
}
#[derive(Debug, Clone)]
pub struct MouseMotion {
pub delta: Vec2,
}
#[derive(Debug, Clone, Copy)]
pub enum MouseScrollUnit {
Line,
Pixel,
}
#[derive(Debug, Clone)]
pub struct MouseWheel {
pub unit: MouseScrollUnit,
pub x: f32,
pub y: f32,
}
pub fn mouse_button_input_system(
mut mouse_button_input: ResMut<Input<MouseButton>>,
mut mouse_button_input_events: EventReader<MouseButtonInput>,
) {
mouse_button_input.clear();
for event in mouse_button_input_events.iter() {
match event.state {
ElementState::Pressed => mouse_button_input.press(event.button),
ElementState::Released => mouse_button_input.release(event.button),
}
}
}