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
@ -80,8 +80,7 @@ pub enum WindowCommand {
|
|||||||
visible: bool,
|
visible: bool,
|
||||||
},
|
},
|
||||||
SetCursorPosition {
|
SetCursorPosition {
|
||||||
x: i32,
|
position: Vec2,
|
||||||
y: i32,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,9 +236,9 @@ impl Window {
|
|||||||
self.cursor_position
|
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
|
self.command_queue
|
||||||
.push(WindowCommand::SetCursorPosition { x, y });
|
.push(WindowCommand::SetCursorPosition { position });
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(missing_docs)]
|
#[allow(missing_docs)]
|
||||||
|
@ -94,10 +94,14 @@ fn change_window(_: &mut World, resources: &mut Resources) {
|
|||||||
let window = winit_windows.get_window(id).unwrap();
|
let window = winit_windows.get_window(id).unwrap();
|
||||||
window.set_cursor_visible(visible);
|
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 window = winit_windows.get_window(id).unwrap();
|
||||||
|
let inner_size = window.inner_size().to_logical::<f32>(window.scale_factor());
|
||||||
window
|
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));
|
.unwrap_or_else(|e| error!("Unable to set cursor position: {}", e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user