Update to glutin 0.26.0 + winit 0.24.0 (#334)

* Update for ModifiersChanged event

* Consistently use logical position and size

CursorMoved gives us a PhysicalPosition, which needs to be converted
to LogicalPosition to properly track the mouse movement. Change the
width/height passed to be a LogicalSize instead of a PhysicalPosition,
matching the LogicalPosition.
This commit is contained in:
iceiix 2020-12-20 08:18:39 -08:00 committed by GitHub
parent 5d0fb7fa64
commit 9bc10c1100
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 411 additions and 224 deletions

585
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -20,7 +20,7 @@ opt-level = 1
[dependencies] [dependencies]
cfg-if = "1.0.0" cfg-if = "1.0.0"
wasm-bindgen = "0.2.69" wasm-bindgen = "0.2.69"
glutin = "0.22.0" glutin = "0.26.0"
byteorder = "1.3.4" byteorder = "1.3.4"
serde = "1.0.118" serde = "1.0.118"
serde_json = "1.0.60" serde_json = "1.0.60"
@ -44,7 +44,7 @@ reqwest = { version = "0.10.10", features = [ "blocking" ]}
[target.'cfg(target_arch = "wasm32")'.dependencies] [target.'cfg(target_arch = "wasm32")'.dependencies]
stdweb = "0.4.20" stdweb = "0.4.20"
winit = { version = "0.20.0", features = [ "stdweb" ]} winit = { version = "0.24.0", features = [ "stdweb" ]}
[dependencies.steven_gl] [dependencies.steven_gl]
path = "./gl" path = "./gl"

View File

@ -399,13 +399,13 @@ fn main2() {
game.console game.console
.lock() .lock()
.unwrap() .unwrap()
.tick(&mut ui_container, &game.renderer, delta, width as f64); .tick(&mut ui_container, &game.renderer, delta, width);
ui_container.tick(&mut game.renderer, delta, width as f64, height as f64); ui_container.tick(&mut game.renderer, delta, width, height);
game.renderer.tick( game.renderer.tick(
&mut game.server.world, &mut game.server.world,
delta, delta,
width, width as u32,
height, height as u32,
physical_width, physical_width,
physical_height, physical_height,
); );
@ -434,15 +434,11 @@ fn handle_window_event<T>(
use glutin::event::*; use glutin::event::*;
match event { match event {
Event::MainEventsCleared => return true, Event::MainEventsCleared => return true,
Event::DeviceEvent { event, .. } => match event { Event::DeviceEvent { event, .. } => {
DeviceEvent::ModifiersChanged(modifiers_state) => { if let DeviceEvent::MouseMotion {
game.is_ctrl_pressed = modifiers_state.ctrl();
game.is_logo_pressed = modifiers_state.logo();
}
DeviceEvent::MouseMotion {
delta: (xrel, yrel), delta: (xrel, yrel),
} => { } = event
{
let (rx, ry) = if xrel > 1000.0 || yrel > 1000.0 { let (rx, ry) = if xrel > 1000.0 || yrel > 1000.0 {
// Heuristic for if we were passed an absolute value instead of relative // Heuristic for if we were passed an absolute value instead of relative
// Workaround https://github.com/tomaka/glutin/issues/1084 MouseMotion event returns absolute instead of relative values, when running Linux in a VM // Workaround https://github.com/tomaka/glutin/issues/1084 MouseMotion event returns absolute instead of relative values, when running Linux in a VM
@ -486,12 +482,14 @@ fn handle_window_event<T>(
window.window().set_cursor_visible(true); window.window().set_cursor_visible(true);
} }
} }
}
_ => (),
},
Event::WindowEvent { event, .. } => { Event::WindowEvent { event, .. } => {
match event { match event {
WindowEvent::ModifiersChanged(modifiers_state) => {
game.is_ctrl_pressed = modifiers_state.ctrl();
game.is_logo_pressed = modifiers_state.logo();
}
WindowEvent::CloseRequested => game.should_close = true, WindowEvent::CloseRequested => game.should_close = true,
WindowEvent::Resized(physical_size) => { WindowEvent::Resized(physical_size) => {
window.resize(physical_size); window.resize(physical_size);
@ -508,11 +506,9 @@ fn handle_window_event<T>(
WindowEvent::MouseInput { state, button, .. } => match (state, button) { WindowEvent::MouseInput { state, button, .. } => match (state, button) {
(ElementState::Released, MouseButton::Left) => { (ElementState::Released, MouseButton::Left) => {
let (width, height) = window let physical_size = window.window().inner_size();
.window() let (width, height) =
.inner_size() physical_size.to_logical::<f64>(game.dpi_factor).into();
.to_logical::<f64>(game.dpi_factor)
.into();
if game.server.is_connected() if game.server.is_connected()
&& !game.focused && !game.focused
@ -541,16 +537,14 @@ fn handle_window_event<T>(
(_, _) => (), (_, _) => (),
}, },
WindowEvent::CursorMoved { position, .. } => { WindowEvent::CursorMoved { position, .. } => {
let (x, y) = position.into(); let (x, y) = position.to_logical::<f64>(game.dpi_factor).into();
game.last_mouse_x = x; game.last_mouse_x = x;
game.last_mouse_y = y; game.last_mouse_y = y;
if !game.focused { if !game.focused {
let (width, height) = window let physical_size = window.window().inner_size();
.window() let (width, height) =
.inner_size() physical_size.to_logical::<f64>(game.dpi_factor).into();
.to_logical::<f64>(game.dpi_factor)
.into();
ui_container.hover_at(game, x, y, width, height); ui_container.hover_at(game, x, y, width, height);
} }
} }