diff options
| author | Lambert Wang <[email protected]> | 2021-05-08 09:26:24 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-05-08 18:26:24 +0200 |
| commit | 2545f62565fd246d1c59bf9a6bcf4942f4ad12ad (patch) | |
| tree | 817bd3580c3b7c4037a545d552d90f699be879b3 /src | |
| parent | 2565c011580fda074e0f3dceacd5e6a1476b3284 (diff) | |
| download | raylib-2545f62565fd246d1c59bf9a6bcf4942f4ad12ad.tar.gz raylib-2545f62565fd246d1c59bf9a6bcf4942f4ad12ad.zip | |
Added support for additional mouse buttons (#1753)
* Added support for additional mouse buttons
* Renamed mouse button enum
Co-authored-by: Lambert Wang <[email protected]>
Diffstat (limited to 'src')
| -rw-r--r-- | src/camera.h | 2 | ||||
| -rw-r--r-- | src/core.c | 26 | ||||
| -rw-r--r-- | src/raylib.h | 16 |
3 files changed, 29 insertions, 15 deletions
diff --git a/src/camera.h b/src/camera.h index cd42b54b..35eda831 100644 --- a/src/camera.h +++ b/src/camera.h @@ -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 }; //---------------------------------------------------------------------------------- @@ -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 diff --git a/src/raylib.h b/src/raylib.h index bb67c126..53c81648 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -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 |
