//! Mouse input state.

bitflags::bitflags! {
    /// Bitflags for mouse button states and events.
    #[derive(Default, Debug, Clone, Copy)]
    pub struct MouseState: u16 {
        /// Left button is currently held.
        const LEFT_CLICKED = 0b0000_0000_0001;
        /// Middle button is currently held.
        const MIDDLE_CLICKED = 0b0000_0000_0010;
        /// Right button is currently held.
        const RIGHT_CLICKED = 0b0000_0000_0100;
        /// Mouse moved this frame.
        const MOVED = 0b0000_0000_1000;
        /// Scroll wheel moved this frame.
        const SCROLLED = 0b0000_0001_0000;
        /// Left button was pressed this frame.
        const LEFT_JUST_PRESSED = 0b0000_0010_0000;
        /// Middle button was pressed this frame.
        const MIDDLE_JUST_PRESSED = 0b0000_0100_0000;
        /// Right button was pressed this frame.
        const RIGHT_JUST_PRESSED = 0b0000_1000_0000;
        /// Left button was released this frame.
        const LEFT_JUST_RELEASED = 0b0001_0000_0000;
        /// Middle button was released this frame.
        const MIDDLE_JUST_RELEASED = 0b0010_0000_0000;
        /// Right button was released this frame.
        const RIGHT_JUST_RELEASED = 0b0100_0000_0000;
    }
}

/// Mouse input state.
#[derive(Default, Debug, Clone, Copy)]
pub struct Mouse {
    /// Current button states and frame events.
    pub state: MouseState,
    /// Cursor position in window coordinates.
    pub position: nalgebra_glm::Vec2,
    /// Cursor movement since last frame (window coordinates).
    pub position_delta: nalgebra_glm::Vec2,
    /// Raw mouse delta (unaffected by cursor acceleration).
    pub raw_mouse_delta: nalgebra_glm::Vec2,
    /// Scroll wheel delta (x = horizontal, y = vertical).
    pub wheel_delta: nalgebra_glm::Vec2,
    /// Whether `position` has been set by a `CursorMoved` event since the
    /// cursor last entered the window or the window gained focus. When false,
    /// the first `CursorMoved` updates `position` but produces zero delta to
    /// avoid a camera snap from a stale position.
    pub position_initialized: bool,
}
