bones_framework/input/
mouse.rs

1//! Mouse input resource.
2
3use crate::prelude::*;
4
5/// Resource containing the mouse input events made this frame.
6#[derive(HasSchema, Clone, Debug, Default)]
7pub struct MouseInputs {
8    /// The movement of the mouse this frame.
9    pub movement: Vec2,
10    /// The mouse wheel event sent this frame.
11    pub wheel_events: Vec<MouseScrollEvent>,
12    /// The mouse button events sent this frame.
13    pub button_events: Vec<MouseButtonEvent>,
14}
15
16/// Mouse scroll-wheel input event.
17#[derive(Debug, Clone, Copy)]
18pub struct MouseScrollEvent {
19    /// The unit the mouse scroll is in.
20    pub unit: MouseScrollUnit,
21    /// the scroll movement.
22    pub movement: Vec2,
23}
24
25/// The unit that a [`MouseScrollEvent`] is in.
26#[derive(Debug, Clone, Copy)]
27#[repr(u8)]
28pub enum MouseScrollUnit {
29    /// The number of lines scrolled.
30    Lines,
31    /// The number of pixels scrolled.
32    Pixels,
33}
34
35/// A mouse button input event.
36#[derive(Debug, Clone, Copy)]
37pub struct MouseButtonEvent {
38    /// The button that the event refers to.
39    pub button: MouseButton,
40    /// Whether the button was pressed or released.
41    pub state: ButtonState,
42}
43
44/// A button on the mouse.
45#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
46#[repr(u8)]
47pub enum MouseButton {
48    #[default]
49    /// The left mouse button.
50    Left,
51    /// The right mouse button.
52    Right,
53    /// The middle mouse button.
54    Middle,
55    /// Another mouse button with the associated number.
56    Other(u16),
57}
58
59/// The position of the mouse in screen-space.
60///
61/// `None` if there is no cursor within the window.
62#[derive(HasSchema, Clone, Copy, Debug, Default, PartialEq)]
63pub struct MouseScreenPosition(pub Option<Vec2>);
64
65/// The position of the mouse in world-space.
66///
67/// `None` if there is no cursor within the window.
68#[derive(HasSchema, Clone, Copy, Debug, Default, PartialEq)]
69pub struct MouseWorldPosition(pub Option<Vec2>);