From 912987377c60a4ec18442a5c6edcbed1aba0b59a Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 26 Jan 2025 16:43:36 +0100 Subject: change cursor to crosshair on center --- client/src/window.rs | 16 +++++++++++++--- 1 file 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, 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); } _ => (), } -- cgit v1.2.3-70-g09d2