glory_render/
plot_pointer.rs1use crate::{Error, Rect};
3
4pub const MAX_PLOT_POINTER_COORDINATE: f64 = 10_000_000.;
6
7#[derive(Clone, Copy, Debug, PartialEq, Eq)]
8pub enum PlotPointerDevice {
9 Mouse,
10 Pen,
11 Touch,
12}
13
14#[derive(Clone, Copy, Debug, PartialEq, Eq)]
15pub enum PlotPointerPhase {
16 Move,
17 Down,
18 Up,
19 Leave,
20 Cancel,
21}
22
23#[derive(Clone, Copy, Debug, PartialEq)]
24pub struct PlotPointer {
25 pub pointer_id: i32,
26 pub device: PlotPointerDevice,
27 pub phase: PlotPointerPhase,
28 pub x: f64,
31 pub y: f64,
32 pub viewport: Rect,
35}
36
37impl PlotPointer {
38 pub fn validate(self) -> Result<(), Error> {
39 let terminal = matches!(
40 self.phase,
41 PlotPointerPhase::Leave | PlotPointerPhase::Cancel
42 );
43 let bounded = |value: f64| value.is_finite() && value.abs() <= MAX_PLOT_POINTER_COORDINATE;
44 if !bounded(self.x)
45 || !bounded(self.y)
46 || self.viewport.x != 0.
47 || self.viewport.y != 0.
48 || !bounded(self.viewport.width)
49 || !bounded(self.viewport.height)
50 || self.viewport.width < 0.
51 || self.viewport.height < 0.
52 || (!terminal && (self.viewport.width == 0. || self.viewport.height == 0.))
53 {
54 return Err(Error::InvalidEvent("invalid local plot pointer geometry"));
55 }
56 Ok(())
57 }
58}