Cursor hiding functionality

master
Wynd 2024-11-07 01:16:12 +02:00
parent 9ea1ab3b5b
commit d8451c1053
1 changed files with 9 additions and 1 deletions

View File

@ -1,7 +1,7 @@
use std::sync::Arc; use std::sync::Arc;
use pollster::FutureExt; use pollster::FutureExt;
use wgpu::{util::DeviceExt, DynamicOffset}; use wgpu::util::DeviceExt;
use winit::{ use winit::{
event::{ElementState, WindowEvent}, event::{ElementState, WindowEvent},
keyboard::Key, keyboard::Key,
@ -62,6 +62,7 @@ pub struct State<'a> {
pub spotlight_info: SpotlightInfo, pub spotlight_info: SpotlightInfo,
pub zoom: f32, pub zoom: f32,
pub camera_controller: CameraController, pub camera_controller: CameraController,
hide_cursor: bool,
} }
impl<'a> State<'a> { impl<'a> State<'a> {
@ -204,6 +205,7 @@ impl<'a> State<'a> {
spotlight_info, spotlight_info,
camera_controller, camera_controller,
zoom: 1.0, zoom: 1.0,
hide_cursor: false,
} }
} }
@ -220,6 +222,7 @@ impl<'a> State<'a> {
pub fn input(&mut self, event: &winit::event::WindowEvent) -> bool { pub fn input(&mut self, event: &winit::event::WindowEvent) -> bool {
self.camera_controller.process_events(self.wsize, event); self.camera_controller.process_events(self.wsize, event);
self.spotlight.process_events(event); self.spotlight.process_events(event);
match event { match event {
WindowEvent::KeyboardInput { WindowEvent::KeyboardInput {
event: key_event, .. event: key_event, ..
@ -230,6 +233,9 @@ impl<'a> State<'a> {
if char == "r" { if char == "r" {
self.camera_controller.reset_camera(&mut self.camera); self.camera_controller.reset_camera(&mut self.camera);
} }
else if char == "h" {
self.hide_cursor = !self.hide_cursor;
}
} }
return true; return true;
} }
@ -261,6 +267,8 @@ impl<'a> State<'a> {
} }
pub fn render(&mut self) -> Result<(), wgpu::SurfaceError> { pub fn render(&mut self) -> Result<(), wgpu::SurfaceError> {
self.window.set_cursor_visible(!self.hide_cursor);
let output = self.surface.get_current_texture()?; let output = self.surface.get_current_texture()?;
let view = output let view = output
.texture .texture