Struct sdl2::mouse::MouseState

source ·
pub struct MouseState { /* private fields */ }

Implementations§

source§

impl MouseState

source

pub fn new(_e: &EventPump) -> MouseState

source

pub fn from_sdl_state(state: u32) -> MouseState

source

pub fn to_sdl_state(&self) -> u32

source

pub fn left(&self) -> bool

Returns true if the left mouse button is pressed.

§Example
use sdl2::mouse::MouseButton;

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

pub fn middle(&self) -> bool

Tests if the middle mouse button was pressed.

source

pub fn right(&self) -> bool

Tests if the right mouse button was pressed.

source

pub fn x1(&self) -> bool

Tests if the X1 mouse button was pressed.

source

pub fn x2(&self) -> bool

Tests if the X2 mouse button was pressed.

source

pub fn x(&self) -> i32

Returns the x coordinate of the state

source

pub fn y(&self) -> i32

Returns the y coordinate of the state

source

pub fn is_mouse_button_pressed(&self, mouse_button: MouseButton) -> bool

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)
}
source

pub fn mouse_buttons(&self) -> MouseButtonIterator<'_>

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
}
source

pub fn pressed_mouse_buttons(&self) -> PressedMouseButtonIterator<'_>

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§

source§

impl Clone for MouseState

source§

fn clone(&self) -> MouseState

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for MouseState

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Hash for MouseState

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl PartialEq for MouseState

source§

fn eq(&self, other: &MouseState) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for MouseState

source§

impl Eq for MouseState

source§

impl StructuralPartialEq for MouseState

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.