diff options
Diffstat (limited to 'client/src/window.rs')
-rw-r--r-- | client/src/window.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/client/src/window.rs b/client/src/window.rs index 68ca25b..05035c4 100644 --- a/client/src/window.rs +++ b/client/src/window.rs @@ -20,6 +20,7 @@ use log::{info, warn}; use std::net::TcpStream; use winit::{ application::ApplicationHandler, + dpi::LogicalPosition, event::{DeviceEvent, ElementState, WindowEvent}, event_loop::ActiveEventLoop, keyboard::{KeyCode, PhysicalKey}, @@ -64,6 +65,19 @@ impl ApplicationHandler for WindowState { sta.resize(size.width, size.height); } WindowEvent::RedrawRequested => { + if self.lock { + let size = vec2( + sta.renderer.surface_configuration.width as f32, + sta.renderer.surface_configuration.height as f32, + ); + let center = size / 2.; + 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.); + win.set_cursor_position(LogicalPosition::new(h.x, h.y)) + .unwrap(); + } sta.draw(); win.request_redraw(); } @@ -81,6 +95,7 @@ impl ApplicationHandler for WindowState { }) .unwrap(); self.lock = !self.lock; + win.set_cursor_visible(!self.lock); } _ => (), } |