summaryrefslogtreecommitdiff
path: root/src/systems/input.rs
blob: 96ac3b8d126549326998d52429510b6600196d0d (plain) (blame)
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
use sdl2::event::{Event, WindowEvent};
use sdl2::{EventPump, Sdl};
use specs::prelude::*;

pub struct SysInput
{
    event_pump: EventPump,
}

impl SysInput
{
    pub fn new(sdl: &Sdl) -> Self
    {
        Self {
            event_pump: sdl.event_pump().unwrap(),
        }
    }
}

impl<'a> System<'a> for SysInput
{
    type SystemData = ();

    fn run(&mut self, (): Self::SystemData)
    {
        for event in self.event_pump.poll_iter() {
            match event {
                Event::Quit { .. } => {
                    panic!("Quitting due to exit signal");
                },
                Event::Window {
                    win_event: WindowEvent::Resized(x, y),
                    ..
                } => {
                    println!("Window resized to {}x{}", x, y);
                },
                _ => {},
            }
        }
    }
}