Galactica/src/inputstatus.rs

61 lines
1.4 KiB
Rust

use winit::event::{ElementState, MouseButton, MouseScrollDelta, TouchPhase, VirtualKeyCode};
pub struct InputStatus {
scroll_speed: f32,
pub key_left: bool,
pub key_right: bool,
pub key_thrust: bool,
pub key_guns: bool,
pub v_scroll: f32,
}
impl InputStatus {
pub fn new() -> Self {
InputStatus {
key_left: false,
key_right: false,
key_thrust: false,
key_guns: false,
v_scroll: 0.0,
scroll_speed: 10.0,
}
}
pub fn release_all(&mut self) {
self.key_left = false;
self.key_right = false;
self.key_thrust = false;
self.key_guns = false;
}
pub fn process_key(&mut self, state: &ElementState, key: &VirtualKeyCode) {
let down = state == &ElementState::Pressed;
match key {
VirtualKeyCode::Left => self.key_left = down,
VirtualKeyCode::Right => self.key_right = down,
VirtualKeyCode::Up => self.key_thrust = down,
VirtualKeyCode::Space => self.key_guns = down,
_ => {}
}
}
pub fn process_click(&mut self, state: &ElementState, key: &MouseButton) {
let _down = state == &ElementState::Pressed;
match key {
_ => {}
}
}
pub fn process_scroll(&mut self, delta: &MouseScrollDelta, _phase: &TouchPhase) {
match delta {
MouseScrollDelta::LineDelta(_h, v) => {
self.v_scroll -= self.scroll_speed * v;
}
// TODO: handle this better
MouseScrollDelta::PixelDelta(v) => {
self.v_scroll -= v.x as f32;
}
}
}
}