Skip to content

Commit

Permalink
Set cursor updates (#993)
Browse files Browse the repository at this point in the history
* update `Window::set_cursor_position` to take a `Vec2` instead of `i32`s

this allows fractional coordinates to work correctly
  • Loading branch information
blunted2night authored Dec 3, 2020
1 parent 1f2e417 commit 1aff709
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 3 additions & 4 deletions crates/bevy_window/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ pub enum WindowCommand {
visible: bool,
},
SetCursorPosition {
x: i32,
y: i32,
position: Vec2,
},
}

Expand Down Expand Up @@ -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)]
Expand Down
8 changes: 6 additions & 2 deletions crates/bevy_winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down

0 comments on commit 1aff709

Please sign in to comment.