Struct sdl2::mouse::RelativeMouseState
source · pub struct RelativeMouseState { /* private fields */ }
Implementations§
source§impl RelativeMouseState
impl RelativeMouseState
pub fn new(_e: &EventPump) -> RelativeMouseState
pub fn from_sdl_state(state: u32) -> RelativeMouseState
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§
source§impl Clone for RelativeMouseState
impl Clone for RelativeMouseState
source§fn clone(&self) -> RelativeMouseState
fn clone(&self) -> RelativeMouseState
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Hash for RelativeMouseState
impl Hash for RelativeMouseState
source§impl PartialEq for RelativeMouseState
impl PartialEq for RelativeMouseState
impl Copy for RelativeMouseState
impl Eq for RelativeMouseState
impl StructuralPartialEq for RelativeMouseState
Auto Trait Implementations§
impl Freeze for RelativeMouseState
impl RefUnwindSafe for RelativeMouseState
impl Send for RelativeMouseState
impl Sync for RelativeMouseState
impl Unpin for RelativeMouseState
impl UnwindSafe for RelativeMouseState
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)