winit v0.25.0

This commit is contained in:
neurotok 2021-11-08 23:25:13 +01:00 committed by Benjamin Saunders
parent 87b00568a6
commit 9baeb9c19f
2 changed files with 41 additions and 24 deletions

View file

@ -5,7 +5,7 @@ authors = ["maik klein <maikklein@googlemail.com>"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
winit = "0.19.5" winit = "0.25.0"
image = "0.10.4" image = "0.10.4"
ash = { path = "../ash" } ash = { path = "../ash" }
ash-window = { path = "../ash-window" } ash-window = { path = "../ash-window" }

View file

@ -14,6 +14,13 @@ use std::default::Default;
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
use std::ops::Drop; use std::ops::Drop;
use winit::{
event::{DeviceEvent, ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
event_loop::{ControlFlow, EventLoop},
platform::run_return::EventLoopExtRunReturn,
window::WindowBuilder,
};
// Simple offset_of macro akin to C++ offsetof // Simple offset_of macro akin to C++ offsetof
#[macro_export] #[macro_export]
macro_rules! offset_of { macro_rules! offset_of {
@ -139,8 +146,8 @@ pub struct ExampleBase {
pub surface_loader: Surface, pub surface_loader: Surface,
pub swapchain_loader: Swapchain, pub swapchain_loader: Swapchain,
pub debug_utils_loader: DebugUtils, pub debug_utils_loader: DebugUtils,
pub window: winit::Window, pub window: winit::window::Window,
pub events_loop: RefCell<winit::EventsLoop>, pub events_loop: RefCell<EventLoop<()>>,
pub debug_call_back: vk::DebugUtilsMessengerEXT, pub debug_call_back: vk::DebugUtilsMessengerEXT,
pub pdevice: vk::PhysicalDevice, pub pdevice: vk::PhysicalDevice,
@ -173,32 +180,42 @@ pub struct ExampleBase {
impl ExampleBase { impl ExampleBase {
pub fn render_loop<F: Fn()>(&self, f: F) { pub fn render_loop<F: Fn()>(&self, f: F) {
use winit::*; self.events_loop
self.events_loop.borrow_mut().run_forever(|event| { .borrow_mut()
.run_return(|event, _, control_flow| {
*control_flow = ControlFlow::Wait;
f(); f();
match event { match event {
Event::WindowEvent { event, .. } => match event { Event::WindowEvent {
WindowEvent::KeyboardInput { input, .. } => { event: WindowEvent::CloseRequested,
if let Some(VirtualKeyCode::Escape) = input.virtual_keycode { window_id,
ControlFlow::Break } if window_id == self.window.id() => *control_flow = ControlFlow::Exit,
} else {
ControlFlow::Continue Event::DeviceEvent { event, .. } => match event {
DeviceEvent::Key(KeyboardInput {
virtual_keycode: Some(keycode),
state,
..
}) => match (keycode, state) {
(VirtualKeyCode::Escape, ElementState::Released) => {
*control_flow = ControlFlow::Exit
} }
} _ => (),
WindowEvent::CloseRequested => winit::ControlFlow::Break,
_ => ControlFlow::Continue,
}, },
_ => ControlFlow::Continue, _ => (),
},
_ => (),
} }
}); });
} }
pub fn new(window_width: u32, window_height: u32) -> Self { pub fn new(window_width: u32, window_height: u32) -> Self {
unsafe { unsafe {
let events_loop = winit::EventsLoop::new(); let events_loop = EventLoop::new();
let window = winit::WindowBuilder::new() let window = WindowBuilder::new()
.with_title("Ash - Example") .with_title("Ash - Example")
.with_dimensions(winit::dpi::LogicalSize::new( .with_inner_size(winit::dpi::LogicalSize::new(
f64::from(window_width), f64::from(window_width),
f64::from(window_height), f64::from(window_height),
)) ))