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
|
- Render LoD terrain on the character selection screen
|
||||||
- Camera no longer jumps on first mouse event after cursor grab is released on macos
|
- Camera no longer jumps on first mouse event after cursor grab is released on macos
|
||||||
- Updated wgpu. Now supports OpenGL. Dx11 no longer supported.
|
- Updated wgpu. Now supports OpenGL. Dx11 no longer supported.
|
||||||
|
- Changes center_cursor to be reset_cursor_position so the cursor is effectively grabbed
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
- Medium and large potions from all loot tables
|
- Medium and large potions from all loot tables
|
||||||
|
@ -78,8 +78,7 @@ use crate::{
|
|||||||
},
|
},
|
||||||
settings::chat::ChatFilter,
|
settings::chat::ChatFilter,
|
||||||
ui::{
|
ui::{
|
||||||
self, fonts::Fonts, img_ids::Rotations, slot, slot::SlotKey, Graphic, Ingameable,
|
fonts::Fonts, img_ids::Rotations, slot, slot::SlotKey, Graphic, Ingameable, ScaleMode, Ui,
|
||||||
ScaleMode, Ui,
|
|
||||||
},
|
},
|
||||||
window::Event as WinEvent,
|
window::Event as WinEvent,
|
||||||
GlobalState,
|
GlobalState,
|
||||||
@ -1144,32 +1143,6 @@ impl Show {
|
|||||||
self.social_search_key = search_key;
|
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) {
|
pub fn update_map_markers(&mut self, event: comp::MapMarkerUpdate) {
|
||||||
match event {
|
match event {
|
||||||
comp::MapMarkerUpdate::Owned(event) => match event {
|
comp::MapMarkerUpdate::Owned(event) => match event {
|
||||||
@ -4713,7 +4686,7 @@ impl Hud {
|
|||||||
true
|
true
|
||||||
};
|
};
|
||||||
|
|
||||||
let matching_key = match key {
|
match key {
|
||||||
GameInput::Command if state => {
|
GameInput::Command if state => {
|
||||||
self.force_chat_input = Some("/".to_owned());
|
self.force_chat_input = Some("/".to_owned());
|
||||||
self.force_chat_cursor = Some(Index { line: 0, char: 1 });
|
self.force_chat_cursor = Some(Index { line: 0, char: 1 });
|
||||||
@ -4809,13 +4782,7 @@ impl Hud {
|
|||||||
false
|
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
|
// Else the player is typing in chat
|
||||||
WinEvent::InputUpdate(_key, _) => self.typing(),
|
WinEvent::InputUpdate(_key, _) => self.typing(),
|
||||||
|
@ -988,10 +988,7 @@ impl Window {
|
|||||||
},
|
},
|
||||||
WindowEvent::CursorMoved { position, .. } => {
|
WindowEvent::CursorMoved { position, .. } => {
|
||||||
if self.cursor_grabbed {
|
if self.cursor_grabbed {
|
||||||
//TODO: An underlying OS call in winit is causing the camera to jump upon the
|
self.reset_cursor_position();
|
||||||
// next mouse movement event in macos https://github.com/rust-windowing/winit/issues/999
|
|
||||||
#[cfg(not(target_os = "macos"))]
|
|
||||||
self.center_cursor();
|
|
||||||
} else {
|
} else {
|
||||||
self.cursor_position = position;
|
self.cursor_position = position;
|
||||||
}
|
}
|
||||||
@ -1056,22 +1053,15 @@ impl Window {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Moves mouse cursor to center of screen
|
/// Reset the cursor position to the last position
|
||||||
/// based on the window dimensions
|
/// This is used when handling the CursorMoved event to maintain the cursor
|
||||||
pub fn center_cursor(&self) {
|
/// position when it is grabbed
|
||||||
let dimensions: Vec2<f64> = self.logical_size();
|
fn reset_cursor_position(&self) {
|
||||||
|
if let Err(err) = self.window.set_cursor_position(self.cursor_position) {
|
||||||
if let Err(err) = self
|
|
||||||
.window
|
|
||||||
.set_cursor_position(winit::dpi::PhysicalPosition::new(
|
|
||||||
dimensions[0] / (2_f64),
|
|
||||||
dimensions[1] / (2_f64),
|
|
||||||
))
|
|
||||||
{
|
|
||||||
// Log this error once rather than every frame
|
// Log this error once rather than every frame
|
||||||
static SPAM_GUARD: std::sync::Once = std::sync::Once::new();
|
static SPAM_GUARD: std::sync::Once = std::sync::Once::new();
|
||||||
SPAM_GUARD.call_once(|| {
|
SPAM_GUARD.call_once(|| {
|
||||||
error!("Error centering cursor position: {:?}", err);
|
error!("Error resetting cursor position: {:?}", err);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user