123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- mod button;
- pub use button::ButtonSet;
- use tiny_skia::Point;
- #[derive(Clone, Copy, Debug)]
- #[repr(u8)]
- pub enum MouseButton {
- Left,
- Right,
- Middle,
- ScrollUp,
- ScrollDown,
- ExtraButton1,
- ExtraButton2,
- ExtraButton3,
- ExtraButton4,
- }
- impl Into<u8> for MouseButton {
- fn into(self) -> u8 {
- self as u8
- }
- }
- #[derive(Default)]
- pub struct MouseState {
- pub pos: Point,
- pub last_pos: Point,
- pub buttons: ButtonSet<MouseButton>,
- pub last_buttons: ButtonSet<MouseButton>,
- }
- impl MouseState {
- pub fn pressed(&self) -> ButtonSet<MouseButton> {
- self.buttons & !self.last_buttons
- }
- pub fn released(&self) -> ButtonSet<MouseButton> {
- !self.buttons & self.last_buttons
- }
- }
- #[derive(Default)]
- pub struct InputState {
- pub mouse: MouseState,
- }
|