2019-04-26 04:29:35 +00:00
|
|
|
use conrod_core::{event::Input, input::Button};
|
|
|
|
use vek::*;
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct Event(pub Input);
|
|
|
|
impl Event {
|
2019-07-28 15:47:14 +00:00
|
|
|
pub fn try_from(
|
2019-10-26 14:50:01 +00:00
|
|
|
event: glutin::event::Event<()>,
|
|
|
|
window: &glutin::ContextWrapper<glutin::PossiblyCurrent, winit::window::Window>,
|
2019-07-28 15:47:14 +00:00
|
|
|
) -> Option<Self> {
|
2019-04-26 04:29:35 +00:00
|
|
|
use conrod_winit::*;
|
2020-02-01 20:39:39 +00:00
|
|
|
// A wrapper around the winit window that allows us to implement the trait
|
|
|
|
// necessary for enabling the winit <-> conrod conversion functions.
|
2019-10-26 14:50:01 +00:00
|
|
|
struct WindowRef<'a>(&'a winit::window::Window);
|
2019-04-26 04:29:35 +00:00
|
|
|
|
2020-02-01 20:39:39 +00:00
|
|
|
// Implement the `WinitWindow` trait for `WindowRef` to allow for generating
|
|
|
|
// compatible conversion functions.
|
2019-04-26 04:29:35 +00:00
|
|
|
impl<'a> conrod_winit::WinitWindow for WindowRef<'a> {
|
|
|
|
fn get_inner_size(&self) -> Option<(u32, u32)> {
|
2019-10-26 14:50:01 +00:00
|
|
|
Some(winit::window::Window::inner_size(&self.0).into())
|
2019-04-26 04:29:35 +00:00
|
|
|
}
|
2020-02-01 20:39:39 +00:00
|
|
|
|
2019-10-27 07:11:18 +00:00
|
|
|
fn hidpi_factor(&self) -> f32 { winit::window::Window::hidpi_factor(&self.0) as _ }
|
2019-04-26 04:29:35 +00:00
|
|
|
}
|
2019-10-26 14:50:01 +00:00
|
|
|
convert_event!(event, &WindowRef(window.window())).map(|input| Self(input))
|
2019-04-26 04:29:35 +00:00
|
|
|
}
|
2020-02-01 20:39:39 +00:00
|
|
|
|
2019-04-26 04:29:35 +00:00
|
|
|
pub fn is_keyboard_or_mouse(&self) -> bool {
|
|
|
|
match self.0 {
|
|
|
|
Input::Press(_)
|
|
|
|
| Input::Release(_)
|
|
|
|
| Input::Motion(_)
|
|
|
|
| Input::Touch(_)
|
|
|
|
| Input::Text(_) => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
2020-02-01 20:39:39 +00:00
|
|
|
|
2019-04-26 04:29:35 +00:00
|
|
|
pub fn is_keyboard(&self) -> bool {
|
|
|
|
match self.0 {
|
|
|
|
Input::Press(Button::Keyboard(_))
|
|
|
|
| Input::Release(Button::Keyboard(_))
|
|
|
|
| Input::Text(_) => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
2020-02-01 20:39:39 +00:00
|
|
|
|
|
|
|
pub fn new_resize(dims: Vec2<f64>) -> Self { Self(Input::Resize(dims.x, dims.y)) }
|
2019-04-26 04:29:35 +00:00
|
|
|
}
|