-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathevents.rs
More file actions
53 lines (51 loc) · 2.11 KB
/
events.rs
File metadata and controls
53 lines (51 loc) · 2.11 KB
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
use winit::{ Event, VirtualKeyCode, ElementState, MouseButton, WindowEvent };
// @TODO - We need a better way of abstracting this.
pub fn string_to_wevent(s: &String, event: &Event) -> Option<f32> {
match s.as_ref() {
"arrow_left" => {
match event {
&Event::WindowEvent { event: WindowEvent::KeyboardInput(ElementState::Pressed, _, Some(VirtualKeyCode::Left), _), ..} => {
Some(-1.0)
}
&Event::WindowEvent { event: WindowEvent::KeyboardInput(ElementState::Released, _, Some(VirtualKeyCode::Left), _), ..} => {
Some(0.0)
}
_ => None,
}
}
"arrow_right" => {
match event {
&Event::WindowEvent { event: WindowEvent::KeyboardInput(ElementState::Pressed, _, Some(VirtualKeyCode::Right), _), ..} => {
Some(1.0)
}
&Event::WindowEvent { event: WindowEvent::KeyboardInput(ElementState::Released, _, Some(VirtualKeyCode::Right), _), ..} => {
Some(0.0)
}
_ => None,
}
}
"arrow_up" => {
match event {
&Event::WindowEvent { event: WindowEvent::KeyboardInput(ElementState::Pressed, _, Some(VirtualKeyCode::Up), _), ..} => {
Some(1.0)
}
&Event::WindowEvent { event: WindowEvent::KeyboardInput(ElementState::Released, _, Some(VirtualKeyCode::Up), _), ..} => {
Some(0.0)
}
_ => None,
}
}
"arrow_down" => {
match event {
&Event::WindowEvent { event: WindowEvent::KeyboardInput(ElementState::Pressed, _, Some(VirtualKeyCode::Down), _), ..} => {
Some(-1.0)
}
&Event::WindowEvent { event: WindowEvent::KeyboardInput(ElementState::Released, _, Some(VirtualKeyCode::Down), _), ..} => {
Some(0.0)
}
_ => None,
}
}
_ => None,
}
}