Hiding the cursor while dragging the screen

master
Wynd 2024-11-10 11:11:16 +02:00
parent 5e8716acf0
commit 2bc6898b15
2 changed files with 11 additions and 3 deletions

View File

@ -1,3 +1,5 @@
use std::sync::Arc;
use winit::{
event::{ElementState, MouseButton, MouseScrollDelta, WindowEvent},
keyboard::{Key, NamedKey},
@ -8,13 +10,15 @@ use crate::camera::Camera;
const MAX_ZOOM_LEVEL: f32 = 15.0;
pub struct CameraController {
window: Arc<winit::window::Window>,
zoom_speed: f32,
movement_speed: f32,
zoom: f32,
cursor_start: (f32, f32),
movement: (f32, f32),
is_moving: bool,
pub is_moving: bool,
is_ctrl_pressed: bool,
movement_total: (f32, f32),
@ -22,8 +26,10 @@ pub struct CameraController {
}
impl CameraController {
pub fn new(zoom_speed: f32, movement_speed: f32) -> Self {
pub fn new(zoom_speed: f32, movement_speed: f32, window: Arc<winit::window::Window>) -> Self {
Self {
window,
zoom_speed,
movement_speed,
@ -43,10 +49,12 @@ impl CameraController {
WindowEvent::MouseInput { state, button, .. } => {
if state.is_pressed() && *button == MouseButton::Left {
self.is_moving = true;
self.window.set_cursor_visible(false);
return true;
}
else {
self.is_moving = false;
self.window.set_cursor_visible(true);
self.movement = (0.0, 0.0);
}
false

View File

@ -118,7 +118,7 @@ impl<'a> State<'a> {
};
let (camera, camera_info) = Camera::new(&device);
let camera_controller = CameraController::new(ZOOM_SPEED, MOVE_SPEED);
let camera_controller = CameraController::new(ZOOM_SPEED, MOVE_SPEED, window.clone());
let (spotlight, spotlight_info) = Spotlight::new(&device, window.clone());