use kurbo::Point;
use kurbo::Vec2;
use serde_json::Value as Json;
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub enum PointerKind {
#[default]
Mouse,
Pen {
pressure: f32,
tilt: Vec2,
},
Touch,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Phase {
Down,
Move,
Up,
Cancel,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct Modifiers {
pub shift: bool,
pub alt: bool,
pub primary: bool,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct PointerEvent {
pub id: u64,
pub kind: PointerKind,
pub phase: Phase,
pub position: Point,
pub buttons: u8,
pub modifiers: Modifiers,
pub time: f64,
}
impl PointerEvent {
#[must_use]
pub fn mouse(phase: Phase, position: Point, time: f64) -> Self {
Self {
id: 0,
kind: PointerKind::Mouse,
phase,
position,
buttons: u8::from(phase != Phase::Up),
modifiers: Modifiers::default(),
time,
}
}
#[must_use]
pub fn with_modifiers(mut self, modifiers: Modifiers) -> Self {
self.modifiers = modifiers;
self
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct WheelEvent {
pub delta: Vec2,
pub position: Point,
pub modifiers: Modifiers,
pub pinch: bool,
}
#[derive(Clone, Debug, PartialEq)]
pub struct KeyEvent {
pub key: String,
pub modifiers: Modifiers,
pub down: bool,
}
#[derive(Clone, Debug, PartialEq)]
pub enum Input {
Pointer(PointerEvent),
Wheel(WheelEvent),
Key(KeyEvent),
Custom {
kind: String,
value: Json,
},
}