Caching for resources is now used instead of ignored

This commit is contained in:
Keavon Chambers
2020-05-04 03:01:56 -07:00
parent 38b36ed4c6
commit 59cb448872
7 changed files with 84 additions and 94 deletions
+49
View File
@@ -0,0 +1,49 @@
use super::application::Application;
use winit::event::*;
use winit::event_loop::ControlFlow;
pub fn window_event(application: &mut Application, control_flow: &mut ControlFlow, event: &WindowEvent) {
match event {
WindowEvent::Resized(physical_size) => resize(application, *physical_size),
WindowEvent::Moved(_) => (),
WindowEvent::CloseRequested => quit(control_flow),
WindowEvent::Destroyed => (),
WindowEvent::DroppedFile(_) => (),
WindowEvent::HoveredFile(_) => (),
WindowEvent::HoveredFileCancelled => (),
WindowEvent::ReceivedCharacter(_) => (),
WindowEvent::Focused(_) => (),
WindowEvent::KeyboardInput { input, .. } => keyboard_event(application, control_flow, input),
WindowEvent::CursorMoved { .. } => (),
WindowEvent::CursorEntered { .. } => (),
WindowEvent::CursorLeft { .. } => (),
WindowEvent::MouseWheel { .. } => (),
WindowEvent::MouseInput { .. } => (),
WindowEvent::TouchpadPressure { .. } => (),
WindowEvent::AxisMotion { .. } => (),
WindowEvent::Touch(_) => (),
WindowEvent::ScaleFactorChanged { new_inner_size, .. } => resize(application, **new_inner_size),
WindowEvent::ThemeChanged(_) => (),
}
}
fn keyboard_event(application: &mut Application, control_flow: &mut ControlFlow, input: &KeyboardInput) {
match input {
KeyboardInput { state: ElementState::Pressed, virtual_keycode: Some(VirtualKeyCode::Escape), .. } => quit(control_flow),
KeyboardInput { state: ElementState::Pressed, virtual_keycode: Some(VirtualKeyCode::Space), .. } => application.example(),
_ => *control_flow = ControlFlow::Wait,
}
}
fn quit(control_flow: &mut ControlFlow) {
*control_flow = ControlFlow::Exit;
}
fn resize(application: &mut Application, new_size: winit::dpi::PhysicalSize<u32>) {
application.swap_chain_descriptor.width = new_size.width;
application.swap_chain_descriptor.height = new_size.height;
application.swap_chain = application.device.create_swap_chain(&application.surface, &application.swap_chain_descriptor);
// TODO: Mark root of GUI as dirty to force redraw of everything
}