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
use glium::glutin;
use std::time::Duration;
pub use glium::glutin::{ElementState, KeyboardInput, WindowEvent, VirtualKeyCode};
pub trait LoopEvent: From<Update> + From<glutin::Event> {}
impl<E> LoopEvent for E where E: From<Update> + From<glutin::Event> {}
#[derive(Clone, Debug)]
pub struct Update {
pub since_last: Duration,
pub since_start: Duration,
}
#[derive(Clone, Debug)]
pub enum Event {
WindowEvent(glutin::WindowId, glutin::WindowEvent),
DeviceEvent(glutin::DeviceId, glutin::DeviceEvent),
Update(Update),
Awakened,
Suspended(bool),
}
impl From<Update> for Event {
fn from(update: Update) -> Self {
Event::Update(update)
}
}
impl From<glutin::Event> for Event {
fn from(event: glutin::Event) -> Self {
match event {
glutin::Event::WindowEvent { window_id, event } =>
Event::WindowEvent(window_id, event),
glutin::Event::DeviceEvent { device_id, event } =>
Event::DeviceEvent(device_id, event),
glutin::Event::Awakened =>
Event::Awakened,
}
}
}