1
use kludgine_core::figures::{Pixels, Points};
2
use kludgine_core::math::{Point, Scale, Scaled, Size};
3
pub use kludgine_core::winit::event::{
4
    DeviceId, ElementState, MouseButton, MouseScrollDelta, ScanCode, TouchPhase, VirtualKeyCode,
5
};
6
use kludgine_core::winit::window::Theme;
7

            
8
/// Whether an event has been processed or ignored.
9
#[derive(Eq, PartialEq, Copy, Clone, Debug)]
10
pub enum EventStatus {
11
    /// The event was not handled.
12
    Ignored,
13
    /// The event was handled and should not be processed any further.
14
    Processed,
15
}
16

            
17
impl Default for EventStatus {
18
    fn default() -> Self {
19
        Self::Ignored
20
    }
21
}
22

            
23
impl EventStatus {
24
    /// Updates `self` such that if either `self` or `other` are `Processed`,
25
    /// `self` will be proecssed.
26
    pub fn update_with(&mut self, other: Self) {
27
        if self != &other {
28
            *self = if self == &Self::Processed || other == Self::Processed {
29
                Self::Processed
30
            } else {
31
                Self::Ignored
32
            };
33
        }
34
    }
35
}
36

            
37
/// An Event from a device
38
#[derive(Copy, Clone, Debug)]
39
pub struct InputEvent {
40
    /// The device that triggered this event
41
    pub device_id: DeviceId,
42
    /// The event that was triggered
43
    pub event: Event,
44
}
45

            
46
/// An input Event
47
#[derive(Copy, Clone, Debug)]
48
pub enum Event {
49
    /// A keyboard event
50
    Keyboard {
51
        /// The hardware-dependent scan code.
52
        scancode: ScanCode,
53
        /// Contains a [`VirtualKeyCode`] if `scancode` was interpetted as a
54
        /// known key.
55
        key: Option<VirtualKeyCode>,
56
        /// Indicates pressed or released/
57
        state: ElementState,
58
    },
59
    /// A mouse button event
60
    MouseButton {
61
        /// The button tha triggered this event.
62
        button: MouseButton,
63
        /// Indicates pressed or released/
64
        state: ElementState,
65
    },
66
    /// Mouse cursor event
67
    MouseMoved {
68
        /// The location within the window of the cursor. Will be invoked with
69
        /// `None` when the cursor leaves the window.
70
        position: Option<Point<f32, Scaled>>,
71
    },
72
    /// Mouse wheel event
73
    MouseWheel {
74
        /// The scroll amount.
75
        delta: MouseScrollDelta,
76
        /// If this event was caused by touch events, the phase of the touch.
77
        touch_phase: TouchPhase,
78
    },
79
}
80

            
81
#[derive(Debug)]
82
pub(crate) enum WindowEvent {
83
    WakeUp,
84
    CloseRequested,
85
    Resize {
86
        size: Size<u32, Pixels>,
87
        scale_factor: Scale<f32, Points, Pixels>,
88
    },
89
    Input(InputEvent),
90
    ReceiveCharacter(char),
91
    RedrawRequested,
92
    SystemThemeChanged(Theme),
93
}