input.rs 827 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. mod button;
  2. pub use button::ButtonSet;
  3. use tiny_skia::Point;
  4. #[derive(Clone, Copy, Debug)]
  5. #[repr(u8)]
  6. pub enum MouseButton {
  7. Left,
  8. Right,
  9. Middle,
  10. ScrollUp,
  11. ScrollDown,
  12. ExtraButton1,
  13. ExtraButton2,
  14. ExtraButton3,
  15. ExtraButton4,
  16. }
  17. impl Into<u8> for MouseButton {
  18. fn into(self) -> u8 {
  19. self as u8
  20. }
  21. }
  22. #[derive(Default)]
  23. pub struct MouseState {
  24. pub pos: Point,
  25. pub last_pos: Point,
  26. pub buttons: ButtonSet<MouseButton>,
  27. pub last_buttons: ButtonSet<MouseButton>,
  28. }
  29. impl MouseState {
  30. pub fn pressed(&self) -> ButtonSet<MouseButton> {
  31. self.buttons & !self.last_buttons
  32. }
  33. pub fn released(&self) -> ButtonSet<MouseButton> {
  34. !self.buttons & self.last_buttons
  35. }
  36. }
  37. #[derive(Default)]
  38. pub struct InputState {
  39. pub mouse: MouseState,
  40. }