aboutsummaryrefslogtreecommitdiff
path: root/client/src/window.rs
blob: d0296e707445b80c2d0dd3398ca3cff343ca3cec (plain)
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
use crate::renderer::Renderer;
use winit::{
    application::ApplicationHandler,
    event::WindowEvent,
    event_loop::ActiveEventLoop,
    window::{Window, WindowAttributes, WindowId},
};

pub struct WindowState {
    window: Option<(Window, Renderer<'static>)>,
}

impl WindowState {
    pub fn new() -> Self {
        Self { window: None }
    }
}
impl ApplicationHandler for WindowState {
    fn resumed(&mut self, event_loop: &ActiveEventLoop) {
        let window = event_loop
            .create_window(WindowAttributes::default().with_maximized(true))
            .unwrap();
        let renderer = Renderer::new(unsafe { std::mem::transmute(&window) });
        self.window = Some((window, renderer))
    }

    fn window_event(
        &mut self,
        event_loop: &ActiveEventLoop,
        window_id: WindowId,
        event: WindowEvent,
    ) {
        if let Some((win, ren)) = &self.window {
            match event {
                WindowEvent::RedrawRequested => {}
                _ => (),
            }
        }
    }
}

impl Drop for WindowState {
    fn drop(&mut self) {
        if let Some((win, ren)) = self.window.take() {
            drop(ren);
            drop(win);
        }
    }
}