45 lines
1.1 KiB
Rust
45 lines
1.1 KiB
Rust
use ui::layout::{CursorState, Vec2};
|
|
use winit::event::WindowEvent;
|
|
|
|
use crate::testing::Client;
|
|
|
|
#[derive(Default)]
|
|
pub struct Input {
|
|
mouse_pos: Vec2,
|
|
mouse_pressed: bool,
|
|
mouse_exists: bool,
|
|
}
|
|
|
|
impl Input {
|
|
pub fn event(&mut self, event: &WindowEvent) {
|
|
match event {
|
|
WindowEvent::CursorMoved { position, .. } => {
|
|
self.mouse_pos = Vec2::new(position.x as f32, position.y as f32);
|
|
self.mouse_exists = true;
|
|
}
|
|
WindowEvent::MouseInput { state, button, .. } => match button {
|
|
winit::event::MouseButton::Left => {
|
|
self.mouse_pressed = state.is_pressed();
|
|
}
|
|
_ => (),
|
|
},
|
|
_ => (),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Client {
|
|
pub fn window_size(&self) -> Vec2 {
|
|
let size = self.renderer.window().inner_size();
|
|
(size.width, size.height).into()
|
|
}
|
|
|
|
pub fn cursor_state(&self) -> CursorState {
|
|
CursorState {
|
|
pos: self.input.mouse_pos,
|
|
exists: self.input.mouse_exists,
|
|
pressed: self.input.mouse_pressed,
|
|
}
|
|
}
|
|
}
|