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 {
|
SetCursorVisibility {
|
||||||
visible: bool,
|
visible: bool,
|
||||||
},
|
},
|
||||||
|
SetCursorPosition {
|
||||||
|
x: i32,
|
||||||
|
y: i32,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Defines the way a window is displayed
|
/// 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]
|
#[inline]
|
||||||
pub fn mode(&self) -> WindowMode {
|
pub fn mode(&self) -> WindowMode {
|
||||||
self.mode
|
self.mode
|
||||||
|
@ -12,7 +12,7 @@ pub use winit_windows::*;
|
|||||||
use bevy_app::{prelude::*, AppExit};
|
use bevy_app::{prelude::*, AppExit};
|
||||||
use bevy_ecs::{Resources, World};
|
use bevy_ecs::{Resources, World};
|
||||||
use bevy_math::Vec2;
|
use bevy_math::Vec2;
|
||||||
use bevy_utils::tracing::trace;
|
use bevy_utils::tracing::{error, trace};
|
||||||
use bevy_window::{
|
use bevy_window::{
|
||||||
CreateWindow, CursorMoved, ReceivedCharacter, Window, WindowCloseRequested, WindowCreated,
|
CreateWindow, CursorMoved, ReceivedCharacter, Window, WindowCloseRequested, WindowCreated,
|
||||||
WindowResized, Windows,
|
WindowResized, Windows,
|
||||||
@ -86,12 +86,20 @@ fn change_window(_: &mut World, resources: &mut Resources) {
|
|||||||
}
|
}
|
||||||
bevy_window::WindowCommand::SetCursorLockMode { locked } => {
|
bevy_window::WindowCommand::SetCursorLockMode { locked } => {
|
||||||
let window = winit_windows.get_window(id).unwrap();
|
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 } => {
|
bevy_window::WindowCommand::SetCursorVisibility { visible } => {
|
||||||
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 } => {
|
||||||
|
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