diff options
-rw-r--r-- | examples/render-bsp/src/main.rs | 4 | ||||
-rw-r--r-- | stockton-render/src/lib.rs | 4 | ||||
-rw-r--r-- | stockton-render/src/window.rs | 32 |
3 files changed, 34 insertions, 6 deletions
diff --git a/examples/render-bsp/src/main.rs b/examples/render-bsp/src/main.rs index 4c7ef03..b18d7f2 100644 --- a/examples/render-bsp/src/main.rs +++ b/examples/render-bsp/src/main.rs @@ -76,7 +76,9 @@ fn main() { } Event::RedrawRequested(_) => session.do_update(), _ => { - tx.send(WindowEvent::from(&event)).unwrap(); + if let Some(we) = WindowEvent::from(&event) { + tx.send(we).unwrap(); + } } } diff --git a/stockton-render/src/lib.rs b/stockton-render/src/lib.rs index 7cea5e7..4d10ff8 100644 --- a/stockton-render/src/lib.rs +++ b/stockton-render/src/lib.rs @@ -87,6 +87,10 @@ impl<'a> Renderer<'a> { self.context.draw_vertices(map, &faces).unwrap(); } } + + fn resize(&mut self) { + unsafe { self.context.handle_surface_change().unwrap() }; + } } /// A system that just renders the world. diff --git a/stockton-render/src/window.rs b/stockton-render/src/window.rs index ab19a6a..6c4cecd 100644 --- a/stockton-render/src/window.rs +++ b/stockton-render/src/window.rs @@ -18,18 +18,40 @@ use crate::Renderer; use winit::event::Event as WinitEvent; +use winit::event::WindowEvent as WinitWindowEvent; +use winit::event_loop::ControlFlow; -pub struct WindowEvent {} +#[derive(Debug, Clone, Copy)] +pub enum WindowEvent { + SizeChanged, + CloseRequested, +} impl WindowEvent { - pub fn from(_winit_event: &WinitEvent<()>) -> WindowEvent { + pub fn from(winit_event: &WinitEvent<()>) -> Option<WindowEvent> { // TODO - WindowEvent {} + match winit_event { + WinitEvent::WindowEvent { event, .. } => match event { + WinitWindowEvent::CloseRequested => Some(WindowEvent::CloseRequested), + WinitWindowEvent::Resized(_) => Some(WindowEvent::SizeChanged), + _ => None, + }, + _ => None, + } } } #[system] /// A system to process the window events sent to renderer by the winit event loop. -pub fn process_window_events(#[resource] _renderer: &mut Renderer<'static>) { - println!("processing window events..."); +pub fn process_window_events(#[resource] renderer: &mut Renderer<'static>) { + while let Ok(event) = renderer.window_events.try_recv() { + match event { + WindowEvent::SizeChanged => renderer.resize(), + WindowEvent::CloseRequested => { + let mut flow = renderer.update_control_flow.write().unwrap(); + // TODO: Let everything know this is our last frame + *flow = ControlFlow::Exit; + } + }; + } } |