kiss3d 0.41.0

Keep it simple, stupid, 2D and 3D graphics engine for Rust.
Documentation
/// Events generated by the window.
///
/// These events are produced during each frame and can be accessed via
/// [`Window::events()`](crate::window::Window::events).
#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum WindowEvent {
    /// The window position changed (x, y in screen coordinates).
    Pos(i32, i32),
    /// The window size changed (width, height in pixels).
    Size(u32, u32),
    /// The window close button was clicked.
    Close,
    /// The window needs to be refreshed.
    Refresh,
    /// The window gained or lost focus.
    Focus(bool),
    /// The window was iconified (minimized) or restored.
    Iconify(bool),
    /// The framebuffer size changed (width, height in pixels).
    FramebufferSize(u32, u32),
    /// A mouse button was pressed or released (button, action, modifiers).
    MouseButton(MouseButton, Action, Modifiers),
    /// The cursor position changed (x, y in pixels, modifiers).
    CursorPos(f64, f64, Modifiers),
    /// The cursor entered or left the window.
    CursorEnter(bool),
    /// The mouse wheel was scrolled (x_offset, y_offset, modifiers).
    Scroll(f64, f64, Modifiers),
    /// A keyboard key was pressed, released, or repeated (key, action, modifiers).
    Key(Key, Action, Modifiers),
    /// A character was typed.
    Char(char),
    /// A character was typed with modifiers.
    CharModifiers(char, Modifiers),
    /// A touch event occurred (id, x, y, action, modifiers).
    Touch(u64, f64, f64, TouchAction, Modifiers),
}

use WindowEvent::*;
impl WindowEvent {
    /// Checks if this event is keyboard-related.
    ///
    /// # Returns
    /// `true` for `Key`, `Char`, or `CharModifiers` events
    pub fn is_keyboard_event(&self) -> bool {
        matches!(self, Key(..) | Char(..) | CharModifiers(..))
    }

    /// Checks if this event is mouse-related.
    ///
    /// # Returns
    /// `true` for `MouseButton`, `CursorPos`, `CursorEnter`, or `Scroll` events
    pub fn is_mouse_event(&self) -> bool {
        matches!(
            self,
            MouseButton(..) | CursorPos(..) | CursorEnter(..) | Scroll(..)
        )
    }

    /// Checks if this event is touch-related.
    ///
    /// # Returns
    /// `true` for `Touch` events
    pub fn is_touch_event(&self) -> bool {
        matches!(self, Touch(..))
    }
}

// NOTE: list of keys inspired from glutin.
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Key {
    Key1,
    Key2,
    Key3,
    Key4,
    Key5,
    Key6,
    Key7,
    Key8,
    Key9,
    Key0,
    A,
    B,
    C,
    D,
    E,
    F,
    G,
    H,
    I,
    J,
    K,
    L,
    M,
    N,
    O,
    P,
    Q,
    R,
    S,
    T,
    U,
    V,
    W,
    X,
    Y,
    Z,
    Escape,
    F1,
    F2,
    F3,
    F4,
    F5,
    F6,
    F7,
    F8,
    F9,
    F10,
    F11,
    F12,
    F13,
    F14,
    F15,
    F16,
    F17,
    F18,
    F19,
    F20,
    F21,
    F22,
    F23,
    F24,
    Snapshot,
    Scroll,
    Pause,
    Insert,
    Home,
    Delete,
    End,
    PageDown,
    PageUp,
    Left,
    Up,
    Right,
    Down,
    Back,
    Return,
    Space,
    Compose,
    Caret,
    Numlock,
    Numpad0,
    Numpad1,
    Numpad2,
    Numpad3,
    Numpad4,
    Numpad5,
    Numpad6,
    Numpad7,
    Numpad8,
    Numpad9,
    AbntC1,
    AbntC2,
    Add,
    Apostrophe,
    Apps,
    At,
    Ax,
    Backslash,
    Calculator,
    Capital,
    Colon,
    Comma,
    Convert,
    Decimal,
    Divide,
    Equals,
    Grave,
    Kana,
    Kanji,
    LAlt,
    LBracket,
    LControl,
    LShift,
    LWin,
    Mail,
    MediaSelect,
    MediaStop,
    Minus,
    Multiply,
    Mute,
    MyComputer,
    NavigateForward,
    NavigateBackward,
    NextTrack,
    NoConvert,
    NumpadComma,
    NumpadEnter,
    NumpadEquals,
    OEM102,
    Period,
    PlayPause,
    Power,
    PrevTrack,
    RAlt,
    RBracket,
    RControl,
    RShift,
    RWin,
    Semicolon,
    Slash,
    Sleep,
    Stop,
    Subtract,
    Sysrq,
    Tab,
    Underline,
    Unlabeled,
    VolumeDown,
    VolumeUp,
    Wake,
    WebBack,
    WebFavorites,
    WebForward,
    WebHome,
    WebRefresh,
    WebSearch,
    WebStop,
    Yen,
    Copy,
    Paste,
    Cut,
    Unknown,
}
/// Mouse button identifiers.
///
/// These represent physical mouse buttons that can be clicked.
/// Button1 is typically the left button, Button2 is typically the right button.
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum MouseButton {
    /// Left mouse button (primary button).
    Button1,
    /// Right mouse button (secondary button).
    Button2,
    /// Middle mouse button (wheel button).
    Button3,
    /// Additional mouse button 4.
    Button4,
    /// Additional mouse button 5.
    Button5,
    /// Additional mouse button 6.
    Button6,
    /// Additional mouse button 7.
    Button7,
    /// Additional mouse button 8.
    Button8,
}

/// The state of a button or key.
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Action {
    /// The button/key was released.
    Release,
    /// The button/key was pressed.
    Press,
}

/// Touch event actions for touch-screen devices.
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum TouchAction {
    /// A new touch point started (finger pressed down).
    Start,
    /// A touch point ended (finger lifted).
    End,
    /// A touch point moved (finger dragged).
    Move,
    /// A touch point was cancelled.
    Cancel,
}

bitflags! {
    /// Keyboard modifier keys.
    ///
    /// These can be combined using bitwise operations to represent
    /// multiple modifiers pressed simultaneously.
    ///
    /// # Example
    /// ```
    /// # use kiss3d::event::Modifiers;
    /// // Ctrl+Shift combination
    /// let mods = Modifiers::Control | Modifiers::Shift;
    /// ```
    #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
    pub struct Modifiers: i32 {
        /// The Shift key modifier.
        const Shift       = 0b0001;
        /// The Control (Ctrl/Cmd) key modifier.
        const Control     = 0b0010;
        /// The Alt (Option) key modifier.
        const Alt         = 0b0100;
        /// The Super (Windows/Command) key modifier.
        const Super       = 0b1000;
    }
}