Add set_cursor_position method to Window (#917)
This commit is contained in:
parent
86d724e04e
commit
b2c82955ff
@ -76,6 +76,10 @@ pub enum WindowCommand {
|
||||
SetCursorVisibility {
|
||||
visible: bool,
|
||||
},
|
||||
SetCursorPosition {
|
||||
x: i32,
|
||||
y: i32,
|
||||
},
|
||||
}
|
||||
|
||||
/// Defines the way a window is displayed
|
||||
@ -203,6 +207,11 @@ impl Window {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn set_cursor_position(&mut self, x: i32, y: i32) {
|
||||
self.command_queue
|
||||
.push(WindowCommand::SetCursorPosition { x, y });
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn mode(&self) -> WindowMode {
|
||||
self.mode
|
||||
|
@ -12,7 +12,7 @@ pub use winit_windows::*;
|
||||
use bevy_app::{prelude::*, AppExit};
|
||||
use bevy_ecs::{Resources, World};
|
||||
use bevy_math::Vec2;
|
||||
use bevy_utils::tracing::trace;
|
||||
use bevy_utils::tracing::{error, trace};
|
||||
use bevy_window::{
|
||||
CreateWindow, CursorMoved, ReceivedCharacter, Window, WindowCloseRequested, WindowCreated,
|
||||
WindowResized, Windows,
|
||||
@ -86,12 +86,20 @@ fn change_window(_: &mut World, resources: &mut Resources) {
|
||||
}
|
||||
bevy_window::WindowCommand::SetCursorLockMode { locked } => {
|
||||
let window = winit_windows.get_window(id).unwrap();
|
||||
window.set_cursor_grab(locked).unwrap();
|
||||
window
|
||||
.set_cursor_grab(locked)
|
||||
.unwrap_or_else(|e| error!("Unable to un/grab cursor: {}", e));
|
||||
}
|
||||
bevy_window::WindowCommand::SetCursorVisibility { visible } => {
|
||||
let window = winit_windows.get_window(id).unwrap();
|
||||
window.set_cursor_visible(visible);
|
||||
}
|
||||
bevy_window::WindowCommand::SetCursorPosition { x, y } => {
|
||||
let window = winit_windows.get_window(id).unwrap();
|
||||
window
|
||||
.set_cursor_position(winit::dpi::PhysicalPosition::new(x, y))
|
||||
.unwrap_or_else(|e| error!("Unable to set cursor position: {}", e));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user