Hiding the cursor while dragging the screen
parent
5e8716acf0
commit
2bc6898b15
|
@ -1,3 +1,5 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use winit::{
|
use winit::{
|
||||||
event::{ElementState, MouseButton, MouseScrollDelta, WindowEvent},
|
event::{ElementState, MouseButton, MouseScrollDelta, WindowEvent},
|
||||||
keyboard::{Key, NamedKey},
|
keyboard::{Key, NamedKey},
|
||||||
|
@ -8,13 +10,15 @@ use crate::camera::Camera;
|
||||||
const MAX_ZOOM_LEVEL: f32 = 15.0;
|
const MAX_ZOOM_LEVEL: f32 = 15.0;
|
||||||
|
|
||||||
pub struct CameraController {
|
pub struct CameraController {
|
||||||
|
window: Arc<winit::window::Window>,
|
||||||
|
|
||||||
zoom_speed: f32,
|
zoom_speed: f32,
|
||||||
movement_speed: f32,
|
movement_speed: f32,
|
||||||
|
|
||||||
zoom: f32,
|
zoom: f32,
|
||||||
cursor_start: (f32, f32),
|
cursor_start: (f32, f32),
|
||||||
movement: (f32, f32),
|
movement: (f32, f32),
|
||||||
is_moving: bool,
|
pub is_moving: bool,
|
||||||
is_ctrl_pressed: bool,
|
is_ctrl_pressed: bool,
|
||||||
|
|
||||||
movement_total: (f32, f32),
|
movement_total: (f32, f32),
|
||||||
|
@ -22,8 +26,10 @@ pub struct CameraController {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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 {
|
Self {
|
||||||
|
window,
|
||||||
|
|
||||||
zoom_speed,
|
zoom_speed,
|
||||||
movement_speed,
|
movement_speed,
|
||||||
|
|
||||||
|
@ -43,10 +49,12 @@ impl CameraController {
|
||||||
WindowEvent::MouseInput { state, button, .. } => {
|
WindowEvent::MouseInput { state, button, .. } => {
|
||||||
if state.is_pressed() && *button == MouseButton::Left {
|
if state.is_pressed() && *button == MouseButton::Left {
|
||||||
self.is_moving = true;
|
self.is_moving = true;
|
||||||
|
self.window.set_cursor_visible(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
self.is_moving = false;
|
self.is_moving = false;
|
||||||
|
self.window.set_cursor_visible(true);
|
||||||
self.movement = (0.0, 0.0);
|
self.movement = (0.0, 0.0);
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
|
|
|
@ -118,7 +118,7 @@ impl<'a> State<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let (camera, camera_info) = Camera::new(&device);
|
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());
|
let (spotlight, spotlight_info) = Spotlight::new(&device, window.clone());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue