summaryrefslogtreecommitdiff
path: root/client/src/window.rs
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/window.rs')
-rw-r--r--client/src/window.rs35
1 files changed, 34 insertions, 1 deletions
diff --git a/client/src/window.rs b/client/src/window.rs
index 6ee7fa4..ac90f71 100644
--- a/client/src/window.rs
+++ b/client/src/window.rs
@@ -1,10 +1,12 @@
use crate::state::State;
+use glam::Vec3;
use log::{info, warn};
use std::net::TcpStream;
use winit::{
application::ApplicationHandler,
- event::WindowEvent,
+ event::{DeviceEvent, ElementState, WindowEvent},
event_loop::ActiveEventLoop,
+ keyboard::{KeyCode, PhysicalKey},
window::{Window, WindowAttributes, WindowId},
};
@@ -47,6 +49,21 @@ impl ApplicationHandler for WindowState {
sta.draw();
win.request_redraw();
}
+ WindowEvent::KeyboardInput { event, .. } => {
+ if event.repeat {
+ return;
+ }
+ sta.delta.move_dir += match event.physical_key {
+ PhysicalKey::Code(KeyCode::KeyW) => Vec3::X,
+ PhysicalKey::Code(KeyCode::KeyS) => Vec3::NEG_X,
+ PhysicalKey::Code(KeyCode::KeyA) => Vec3::NEG_Z,
+ PhysicalKey::Code(KeyCode::KeyD) => Vec3::Z,
+ _ => Vec3::ZERO,
+ } * match event.state {
+ ElementState::Pressed => 1.,
+ ElementState::Released => -1.,
+ };
+ }
WindowEvent::CloseRequested => {
event_loop.exit();
}
@@ -54,6 +71,22 @@ impl ApplicationHandler for WindowState {
}
}
}
+ fn device_event(
+ &mut self,
+ _event_loop: &ActiveEventLoop,
+ _device_id: winit::event::DeviceId,
+ event: winit::event::DeviceEvent,
+ ) {
+ if let Some((_win, sta)) = &mut self.window {
+ match event {
+ DeviceEvent::MouseMotion { delta } => {
+ sta.delta.mouse_acc.x += delta.0 as f32;
+ sta.delta.mouse_acc.y += delta.1 as f32;
+ }
+ _ => (),
+ }
+ }
+ }
fn about_to_wait(&mut self, _event_loop: &ActiveEventLoop) {
if let Some((_win, sta)) = &mut self.window {
if let Err(e) = sta.update() {