winit v0.25.0
This commit is contained in:
parent
87b00568a6
commit
9baeb9c19f
|
@ -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" }
|
||||||
|
|
|
@ -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()
|
||||||
f();
|
.run_return(|event, _, control_flow| {
|
||||||
match event {
|
*control_flow = ControlFlow::Wait;
|
||||||
Event::WindowEvent { event, .. } => match event {
|
f();
|
||||||
WindowEvent::KeyboardInput { input, .. } => {
|
match event {
|
||||||
if let Some(VirtualKeyCode::Escape) = input.virtual_keycode {
|
Event::WindowEvent {
|
||||||
ControlFlow::Break
|
event: WindowEvent::CloseRequested,
|
||||||
} else {
|
window_id,
|
||||||
ControlFlow::Continue
|
} if window_id == self.window.id() => *control_flow = ControlFlow::Exit,
|
||||||
}
|
|
||||||
}
|
Event::DeviceEvent { event, .. } => match event {
|
||||||
WindowEvent::CloseRequested => winit::ControlFlow::Break,
|
DeviceEvent::Key(KeyboardInput {
|
||||||
_ => ControlFlow::Continue,
|
virtual_keycode: Some(keycode),
|
||||||
},
|
state,
|
||||||
_ => ControlFlow::Continue,
|
..
|
||||||
}
|
}) => match (keycode, state) {
|
||||||
});
|
(VirtualKeyCode::Escape, ElementState::Released) => {
|
||||||
|
*control_flow = ControlFlow::Exit
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
},
|
||||||
|
_ => (),
|
||||||
|
},
|
||||||
|
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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),
|
||||||
))
|
))
|
||||||
|
|
Loading…
Reference in a new issue