diff options
author | metamuffin <metamuffin@disroot.org> | 2025-01-26 16:43:36 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-01-26 16:43:36 +0100 |
commit | 912987377c60a4ec18442a5c6edcbed1aba0b59a (patch) | |
tree | b80d69833c54ca21b02f43675a429f7dc247dcd7 | |
parent | 66930534a0647e2613360658a6a99eed945e2f0f (diff) | |
download | weareserver-912987377c60a4ec18442a5c6edcbed1aba0b59a.tar weareserver-912987377c60a4ec18442a5c6edcbed1aba0b59a.tar.bz2 weareserver-912987377c60a4ec18442a5c6edcbed1aba0b59a.tar.zst |
change cursor to crosshair on center
-rw-r--r-- | client/src/window.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/client/src/window.rs b/client/src/window.rs index 05035c4..dcfb1e8 100644 --- a/client/src/window.rs +++ b/client/src/window.rs @@ -24,13 +24,14 @@ use winit::{ event::{DeviceEvent, ElementState, WindowEvent}, event_loop::ActiveEventLoop, keyboard::{KeyCode, PhysicalKey}, - window::{CursorGrabMode, Window, WindowAttributes, WindowId}, + window::{CursorGrabMode, CursorIcon, Window, WindowAttributes, WindowId}, }; pub struct WindowState { init: Option<TcpStream>, window: Option<(Window, State<'static>)>, lock: bool, + center: bool, } impl WindowState { pub fn new(init: TcpStream) -> Self { @@ -38,6 +39,7 @@ impl WindowState { window: None, init: Some(init), lock: false, + center: false, } } } @@ -74,7 +76,15 @@ impl ApplicationHandler for WindowState { let dt = 0.008_f32; let h = center + (sta.input_state.cursor_pos - center) * (-dt).exp(); sta.input_state.cursor_pos = h; - win.set_cursor_visible(center.distance(sta.input_state.cursor_pos) > 5.); + let center = center.distance(sta.input_state.cursor_pos) < 5.; + if self.center != center { + self.center = center; + win.set_cursor(if center { + CursorIcon::Crosshair + } else { + CursorIcon::Default + }); + } win.set_cursor_position(LogicalPosition::new(h.x, h.y)) .unwrap(); } @@ -95,7 +105,7 @@ impl ApplicationHandler for WindowState { }) .unwrap(); self.lock = !self.lock; - win.set_cursor_visible(!self.lock); + win.set_cursor(CursorIcon::Default); } _ => (), } |