mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
resets the cursor position instead of centering it when grabbed
This commit is contained in:
parent
aef9d27f64
commit
87ff55e938
@ -83,6 +83,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Render LoD terrain on the character selection screen
|
||||
- Camera no longer jumps on first mouse event after cursor grab is released on macos
|
||||
- Updated wgpu. Now supports OpenGL. Dx11 no longer supported.
|
||||
- Changes center_cursor to be reset_cursor_position so the cursor is effectively grabbed
|
||||
|
||||
### Removed
|
||||
- Medium and large potions from all loot tables
|
||||
|
@ -78,8 +78,7 @@ use crate::{
|
||||
},
|
||||
settings::chat::ChatFilter,
|
||||
ui::{
|
||||
self, fonts::Fonts, img_ids::Rotations, slot, slot::SlotKey, Graphic, Ingameable,
|
||||
ScaleMode, Ui,
|
||||
fonts::Fonts, img_ids::Rotations, slot, slot::SlotKey, Graphic, Ingameable, ScaleMode, Ui,
|
||||
},
|
||||
window::Event as WinEvent,
|
||||
GlobalState,
|
||||
@ -1144,32 +1143,6 @@ impl Show {
|
||||
self.social_search_key = search_key;
|
||||
}
|
||||
|
||||
/// If all of the menus are closed, adjusts coordinates of cursor to center
|
||||
/// of screen
|
||||
fn toggle_cursor_on_menu_close(&self, global_state: &mut GlobalState, ui: &mut Ui) {
|
||||
if !self.bag
|
||||
&& !self.trade
|
||||
&& !self.esc_menu
|
||||
&& !self.map
|
||||
&& !self.social
|
||||
&& !self.quest
|
||||
&& !self.crafting
|
||||
&& !self.diary
|
||||
&& !self.help
|
||||
&& !self.intro
|
||||
&& global_state.window.is_cursor_grabbed()
|
||||
{
|
||||
ui.handle_event(ui::Event(
|
||||
conrod_core::input::Motion::MouseCursor { x: 0.0, y: 0.0 }.into(),
|
||||
));
|
||||
|
||||
//TODO: An underlying OS call in winit is causing the camera to jump upon the
|
||||
// next mouse movement event in macos https://github.com/rust-windowing/winit/issues/999
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
global_state.window.center_cursor();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_map_markers(&mut self, event: comp::MapMarkerUpdate) {
|
||||
match event {
|
||||
comp::MapMarkerUpdate::Owned(event) => match event {
|
||||
@ -4713,7 +4686,7 @@ impl Hud {
|
||||
true
|
||||
};
|
||||
|
||||
let matching_key = match key {
|
||||
match key {
|
||||
GameInput::Command if state => {
|
||||
self.force_chat_input = Some("/".to_owned());
|
||||
self.force_chat_cursor = Some(Index { line: 0, char: 1 });
|
||||
@ -4809,13 +4782,7 @@ impl Hud {
|
||||
false
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// When a player closes all menus, resets the cursor
|
||||
// to the center of the screen
|
||||
self.show
|
||||
.toggle_cursor_on_menu_close(global_state, &mut self.ui);
|
||||
matching_key
|
||||
}
|
||||
},
|
||||
// Else the player is typing in chat
|
||||
WinEvent::InputUpdate(_key, _) => self.typing(),
|
||||
|
@ -988,10 +988,7 @@ impl Window {
|
||||
},
|
||||
WindowEvent::CursorMoved { position, .. } => {
|
||||
if self.cursor_grabbed {
|
||||
//TODO: An underlying OS call in winit is causing the camera to jump upon the
|
||||
// next mouse movement event in macos https://github.com/rust-windowing/winit/issues/999
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
self.center_cursor();
|
||||
self.reset_cursor_position();
|
||||
} else {
|
||||
self.cursor_position = position;
|
||||
}
|
||||
@ -1056,22 +1053,15 @@ impl Window {
|
||||
}
|
||||
}
|
||||
|
||||
/// Moves mouse cursor to center of screen
|
||||
/// based on the window dimensions
|
||||
pub fn center_cursor(&self) {
|
||||
let dimensions: Vec2<f64> = self.logical_size();
|
||||
|
||||
if let Err(err) = self
|
||||
.window
|
||||
.set_cursor_position(winit::dpi::PhysicalPosition::new(
|
||||
dimensions[0] / (2_f64),
|
||||
dimensions[1] / (2_f64),
|
||||
))
|
||||
{
|
||||
/// Reset the cursor position to the last position
|
||||
/// This is used when handling the CursorMoved event to maintain the cursor
|
||||
/// position when it is grabbed
|
||||
fn reset_cursor_position(&self) {
|
||||
if let Err(err) = self.window.set_cursor_position(self.cursor_position) {
|
||||
// Log this error once rather than every frame
|
||||
static SPAM_GUARD: std::sync::Once = std::sync::Once::new();
|
||||
SPAM_GUARD.call_once(|| {
|
||||
error!("Error centering cursor position: {:?}", err);
|
||||
error!("Error resetting cursor position: {:?}", err);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user