Set cursor updates (#993)

* update `Window::set_cursor_position` to take a `Vec2` instead of `i32`s

this allows fractional coordinates to work correctly
This commit is contained in:
Nathan Jeffords 2020-12-03 12:39:03 -08:00 committed by GitHub
parent 1f2e4171cf
commit 1aff709d27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View file

@ -80,8 +80,7 @@ pub enum WindowCommand {
visible: bool,
},
SetCursorPosition {
x: i32,
y: i32,
position: Vec2,
},
}
@ -237,9 +236,9 @@ impl Window {
self.cursor_position
}
pub fn set_cursor_position(&mut self, x: i32, y: i32) {
pub fn set_cursor_position(&mut self, position: Vec2) {
self.command_queue
.push(WindowCommand::SetCursorPosition { x, y });
.push(WindowCommand::SetCursorPosition { position });
}
#[allow(missing_docs)]

View file

@ -94,10 +94,14 @@ fn change_window(_: &mut World, resources: &mut Resources) {
let window = winit_windows.get_window(id).unwrap();
window.set_cursor_visible(visible);
}
bevy_window::WindowCommand::SetCursorPosition { x, y } => {
bevy_window::WindowCommand::SetCursorPosition { position } => {
let window = winit_windows.get_window(id).unwrap();
let inner_size = window.inner_size().to_logical::<f32>(window.scale_factor());
window
.set_cursor_position(winit::dpi::LogicalPosition::new(x, y))
.set_cursor_position(winit::dpi::LogicalPosition::new(
position.x,
inner_size.height - position.y,
))
.unwrap_or_else(|e| error!("Unable to set cursor position: {}", e));
}
}