[][src]Struct sdl2::mouse::MouseState

pub struct MouseState { /* fields omitted */ }

Methods

impl MouseState[src]

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

pub fn from_sdl_state(state: u32) -> MouseState[src]

pub fn to_sdl_state(&self) -> u32[src]

pub fn left(&self) -> bool[src]

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

pub fn middle(&self) -> bool[src]

Tests if the middle mouse button was pressed.

pub fn right(&self) -> bool[src]

Tests if the right mouse button was pressed.

pub fn x1(&self) -> bool[src]

Tests if the X1 mouse button was pressed.

pub fn x2(&self) -> bool[src]

Tests if the X2 mouse button was pressed.

pub fn x(&self) -> i32[src]

Returns the x coordinate of the state

pub fn y(&self) -> i32[src]

Returns the y coordinate of the state

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

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

pub fn mouse_buttons(&self) -> MouseButtonIterator[src]

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
}

pub fn pressed_mouse_buttons(&self) -> PressedMouseButtonIterator[src]

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

impl Clone for MouseState[src]

impl Copy for MouseState[src]

impl Debug for MouseState[src]

impl Eq for MouseState[src]

impl Hash for MouseState[src]

impl PartialEq<MouseState> for MouseState[src]

impl StructuralEq for MouseState[src]

impl StructuralPartialEq for MouseState[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.