fix mouse button event mapping
this was preventing applications from picking up basically all non-left button states
This commit is contained in:
parent
4069a92843
commit
db60579db4
|
@ -1,13 +1,20 @@
|
|||
use bitflags::bitflags;
|
||||
|
||||
// equivalent to SDL's "SDL_BUTTON" macro
|
||||
#[inline]
|
||||
const fn button_mask_to_value(mask: u32) -> u32 {
|
||||
1 << (mask - 1)
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
#[repr(transparent)]
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub struct MouseButtons: u32 {
|
||||
const LEFT_BUTTON = sdl2::mouse::MouseButton::Left as u32;
|
||||
const MIDDLE_BUTTON = sdl2::mouse::MouseButton::Middle as u32;
|
||||
const RIGHT_BUTTON = sdl2::mouse::MouseButton::Right as u32;
|
||||
const X1 = sdl2::mouse::MouseButton::X1 as u32;
|
||||
const X2 = sdl2::mouse::MouseButton::X2 as u32;
|
||||
const LEFT_BUTTON = button_mask_to_value(sdl2::mouse::MouseButton::Left as u32);
|
||||
const MIDDLE_BUTTON = button_mask_to_value(sdl2::mouse::MouseButton::Middle as u32);
|
||||
const RIGHT_BUTTON = button_mask_to_value(sdl2::mouse::MouseButton::Right as u32);
|
||||
const X1 = button_mask_to_value(sdl2::mouse::MouseButton::X1 as u32);
|
||||
const X2 = button_mask_to_value(sdl2::mouse::MouseButton::X2 as u32);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,26 +62,26 @@ impl Mouse {
|
|||
|
||||
/// Returns true if the given button was just pressed or is being held down.
|
||||
#[inline]
|
||||
pub fn is_button_down(&self, button: usize) -> bool {
|
||||
matches!(self.buttons[button], ButtonState::Pressed | ButtonState::Held)
|
||||
pub fn is_button_down(&self, button: MouseButton) -> bool {
|
||||
matches!(self.buttons[button as usize], ButtonState::Pressed | ButtonState::Held)
|
||||
}
|
||||
|
||||
/// Returns true if the given button was not just pressed and is not being held down.
|
||||
#[inline]
|
||||
pub fn is_button_up(&self, button: usize) -> bool {
|
||||
matches!(self.buttons[button], ButtonState::Released | ButtonState::Idle)
|
||||
pub fn is_button_up(&self, button: MouseButton) -> bool {
|
||||
matches!(self.buttons[button as usize], ButtonState::Released | ButtonState::Idle)
|
||||
}
|
||||
|
||||
/// Returns true if the given button was just pressed (not being held down, yet).
|
||||
#[inline]
|
||||
pub fn is_button_pressed(&self, button: usize) -> bool {
|
||||
self.buttons[button] == ButtonState::Pressed
|
||||
pub fn is_button_pressed(&self, button: MouseButton) -> bool {
|
||||
self.buttons[button as usize] == ButtonState::Pressed
|
||||
}
|
||||
|
||||
/// Returns true if the given button was just released.
|
||||
#[inline]
|
||||
pub fn is_button_released(&self, button: usize) -> bool {
|
||||
self.buttons[button] == ButtonState::Released
|
||||
pub fn is_button_released(&self, button: MouseButton) -> bool {
|
||||
self.buttons[button as usize] == ButtonState::Released
|
||||
}
|
||||
|
||||
fn update_button_state(&mut self, button: u32, is_pressed: bool) {
|
||||
|
|
Loading…
Reference in a new issue