Struct sdl2::mouse::MouseState
source · [−]pub struct MouseState { /* private fields */ }
Implementations
sourceimpl MouseState
impl MouseState
pub fn new(_e: &EventPump) -> MouseState
pub fn from_sdl_state(state: u32) -> MouseState
pub fn to_sdl_state(&self) -> u32
sourcepub fn left(&self) -> bool
pub fn left(&self) -> bool
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()
}
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
sourceimpl Clone for MouseState
impl Clone for MouseState
sourcefn clone(&self) -> MouseState
fn clone(&self) -> MouseState
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for MouseState
impl Debug for MouseState
sourceimpl Hash for MouseState
impl Hash for MouseState
sourceimpl PartialEq<MouseState> for MouseState
impl PartialEq<MouseState> for MouseState
sourcefn eq(&self, other: &MouseState) -> bool
fn eq(&self, other: &MouseState) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &MouseState) -> bool
fn ne(&self, other: &MouseState) -> bool
This method tests for !=
.
impl Copy for MouseState
impl Eq for MouseState
impl StructuralEq for MouseState
impl StructuralPartialEq for MouseState
Auto Trait Implementations
impl RefUnwindSafe for MouseState
impl Send for MouseState
impl Sync for MouseState
impl Unpin for MouseState
impl UnwindSafe for MouseState
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more