Skip to main content

RelativeMouseState

Struct RelativeMouseState 

Source
pub struct RelativeMouseState { /* private fields */ }

Implementations§

Source§

impl RelativeMouseState

Source

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

Source

pub fn from_sdl_state(state: u32) -> RelativeMouseState

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 sdl3::mouse::MouseButton;

fn is_a_pressed(e: &sdl3::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) -> f32

Returns the x coordinate of the state

Source

pub fn y(&self) -> f32

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 sdl3::mouse::MouseButton;

fn is_left_pressed(e: &sdl3::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 sdl3::mouse::MouseButton;
use std::collections::HashMap;

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

fn find_first_pressed(e: &sdl3::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 sdl3::mouse::MouseButton;
use std::collections::HashSet;

fn pressed_mouse_button_set(e: &sdl3::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 RelativeMouseState

Source§

fn clone(&self) -> RelativeMouseState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for RelativeMouseState

Source§

impl PartialEq for RelativeMouseState

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RelativeMouseState

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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>,

Source§

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>,

Source§

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.