mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
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:
parent
1f2e4171cf
commit
1aff709d27
2 changed files with 9 additions and 6 deletions
|
@ -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)]
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue