use crate::canvas::CanvasInfo;
pub use glium::glutin;
pub use glium::glutin::event::{Event, WindowEvent};
pub struct MouseState {
pub x: i32,
pub y: i32,
pub virtual_x: i32,
pub virtual_y: i32,
}
impl MouseState {
pub fn new() -> Self {
Self {
x: 0,
y: 0,
virtual_x: 0,
virtual_y: 0,
}
}
pub fn handle_input(info: &CanvasInfo, mouse: &mut MouseState, event: &Event<()>) -> bool {
match event {
Event::WindowEvent {
event: WindowEvent::CursorMoved { position, .. },
..
} => {
let (x, y): (i32, i32) = (*position).into();
mouse.virtual_x = x;
mouse.virtual_y = y;
mouse.x = (x as f64 * info.dpi) as i32;
mouse.y = ((info.height as i32 - y) as f64 * info.dpi) as i32;
true
}
_ => false,
}
}
}