pub struct MouseState { /* private fields */ }

Implementations

Returns true if the left mouse button is pressed.

Example
use sdl2::mouse::MouseButton;

fn is_a_pressed(e: &sdl2::EventPump) -> bool {
    e.mouse_state().left()
}

Tests if the middle mouse button was pressed.

Tests if the right mouse button was pressed.

Tests if the X1 mouse button was pressed.

Tests if the X2 mouse button was pressed.

Returns the x coordinate of the state

Returns the y coordinate of the state

Returns true if the mouse button is pressed.

Example
use sdl2::mouse::MouseButton;

fn is_left_pressed(e: &sdl2::EventPump) -> bool {
    e.mouse_state().is_mouse_button_pressed(MouseButton::Left)
}

Returns an iterator all mouse buttons with a boolean indicating if the scancode is pressed.

Example
use sdl2::mouse::MouseButton;
use std::collections::HashMap;

fn mouse_button_set(e: &sdl2::EventPump) -> HashMap<MouseButton, bool> {
    e.mouse_state().mouse_buttons().collect()
}

fn find_first_pressed(e: &sdl2::EventPump) -> bool {
    for (key,value) in mouse_button_set(e) {
        return value != false
    }
    false
}

Returns an iterator of pressed mouse buttons.

Example
use sdl2::mouse::MouseButton;
use std::collections::HashSet;

fn pressed_mouse_button_set(e: &sdl2::EventPump) -> HashSet<MouseButton> {
    e.mouse_state().pressed_mouse_buttons().collect()
}

fn newly_pressed(old: &HashSet<MouseButton>, new: &HashSet<MouseButton>) -> HashSet<MouseButton> {
    new - old
    // sugar for: new.difference(old).collect()
}

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.