Added support for additional mouse buttons (#1753)

* Added support for additional mouse buttons

* Renamed mouse button enum

Co-authored-by: Lambert Wang <lambert.ww@gmail.com>
This commit is contained in:
Lambert Wang 2021-05-08 09:26:24 -07:00 committed by GitHub
parent 2565c01158
commit 2545f62565
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 81 additions and 65 deletions

View file

@ -222,7 +222,7 @@ static CameraData CAMERA = { // Global CAMERA state context
.moveControl = { 'W', 'S', 'D', 'A', 'E', 'Q' },
.smoothZoomControl = 341, // raylib: KEY_LEFT_CONTROL
.altControl = 342, // raylib: KEY_LEFT_ALT
.panControl = 2 // raylib: MOUSE_MIDDLE_BUTTON
.panControl = 2 // raylib: MOUSE_BUTTON_MIDDLE
};
//----------------------------------------------------------------------------------

View file

@ -438,12 +438,12 @@ typedef struct CoreData {
bool cursorHidden; // Track if cursor is hidden
bool cursorOnScreen; // Tracks if cursor is inside client area
char currentButtonState[3]; // Registers current mouse button state
char previousButtonState[3]; // Registers previous mouse button state
char currentButtonState[MOUSE_BUTTON_MAX]; // Registers current mouse button state
char previousButtonState[MOUSE_BUTTON_MAX]; // Registers previous mouse button state
float currentWheelMove; // Registers current mouse wheel variation
float previousWheelMove; // Registers previous mouse wheel variation
#if defined(PLATFORM_RPI) || defined(PLATFORM_DRM)
char currentButtonStateEvdev[3]; // Holds the new mouse state for the next polling event to grab (Can't be written directly due to multithreading, app could miss the update)
char currentButtonStateEvdev[MOUSE_BUTTON_MAX]; // Holds the new mouse state for the next polling event to grab (Can't be written directly due to multithreading, app could miss the update)
#endif
} Mouse;
struct {
@ -5351,11 +5351,11 @@ static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
if (flags == AMOTION_EVENT_ACTION_DOWN || flags == AMOTION_EVENT_ACTION_MOVE)
{
CORE.Input.Touch.currentTouchState[MOUSE_LEFT_BUTTON] = 1;
CORE.Input.Touch.currentTouchState[MOUSE_BUTTON_LEFT] = 1;
}
else if (flags == AMOTION_EVENT_ACTION_UP)
{
CORE.Input.Touch.currentTouchState[MOUSE_LEFT_BUTTON] = 0;
CORE.Input.Touch.currentTouchState[MOUSE_BUTTON_LEFT] = 0;
}
#if defined(SUPPORT_GESTURES_SYSTEM)
@ -6068,11 +6068,11 @@ static void *EventThread(void *arg)
// Touchscreen tap
if (event.code == ABS_PRESSURE)
{
int previousMouseLeftButtonState = CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_LEFT_BUTTON];
int previousMouseLeftButtonState = CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_BUTTON_LEFT];
if (!event.value && previousMouseLeftButtonState)
{
CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_LEFT_BUTTON] = 0;
CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_BUTTON_LEFT] = 0;
#if defined(SUPPORT_GESTURES_SYSTEM)
touchAction = TOUCH_UP;
@ -6082,7 +6082,7 @@ static void *EventThread(void *arg)
if (event.value && !previousMouseLeftButtonState)
{
CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_LEFT_BUTTON] = 1;
CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_BUTTON_LEFT] = 1;
#if defined(SUPPORT_GESTURES_SYSTEM)
touchAction = TOUCH_DOWN;
@ -6099,7 +6099,7 @@ static void *EventThread(void *arg)
// Mouse button parsing
if ((event.code == BTN_TOUCH) || (event.code == BTN_LEFT))
{
CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_LEFT_BUTTON] = event.value;
CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_BUTTON_LEFT] = event.value;
#if defined(SUPPORT_GESTURES_SYSTEM)
if (event.value > 0) touchAction = TOUCH_DOWN;
@ -6108,8 +6108,12 @@ static void *EventThread(void *arg)
#endif
}
if (event.code == BTN_RIGHT) CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_RIGHT_BUTTON] = event.value;
if (event.code == BTN_MIDDLE) CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_MIDDLE_BUTTON] = event.value;
if (event.code == BTN_RIGHT) CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_BUTTON_RIGHT] = event.value;
if (event.code == BTN_MIDDLE) CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_BUTTON_MIDDLE] = event.value;
if (event.code == BTN_SIDE) CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_BUTTON_SIDE] = event.value;
if (event.code == BTN_EXTRA) CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_BUTTON_EXTRA] = event.value;
if (event.code == BTN_FORWARD) CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_BUTTON_FORWARD] = event.value;
if (event.code == BTN_BACK) CORE.Input.Mouse.currentButtonStateEvdev[MOUSE_BUTTON_BACK] = event.value;
}
// Screen confinement

View file

@ -637,11 +637,21 @@ typedef enum {
KEY_VOLUME_DOWN = 25
} KeyboardKey;
// Add backwards compatibility support for deprecated names
#define MOUSE_LEFT_BUTTON MOUSE_BUTTON_LEFT
#define MOUSE_RIGHT_BUTTON MOUSE_BUTTON_RIGHT
#define MOUSE_MIDDLE_BUTTON MOUSE_BUTTON_MIDDLE
// Mouse buttons
typedef enum {
MOUSE_LEFT_BUTTON = 0,
MOUSE_RIGHT_BUTTON = 1,
MOUSE_MIDDLE_BUTTON = 2
MOUSE_BUTTON_LEFT = 0,
MOUSE_BUTTON_RIGHT = 1,
MOUSE_BUTTON_MIDDLE = 2,
MOUSE_BUTTON_SIDE = 3,
MOUSE_BUTTON_EXTRA = 4,
MOUSE_BUTTON_FORWARD = 5,
MOUSE_BUTTON_BACK = 6,
MOUSE_BUTTON_MAX = 7
} MouseButton;
// Mouse cursor