diff options
| author | ubkp <[email protected]> | 2023-11-12 20:16:31 -0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-11-13 00:16:31 +0100 |
| commit | 87f26c845c1b13b75ed379917180c8ae1ac1635e (patch) | |
| tree | e73a28d2edaece35983e54aaebac680ef052e67b | |
| parent | 4f67f5f1593ac7b97c7492e28b5f6703ee84ee26 (diff) | |
| download | raylib-87f26c845c1b13b75ed379917180c8ae1ac1635e.tar.gz raylib-87f26c845c1b13b75ed379917180c8ae1ac1635e.zip | |
Fix mouse button order for SDL (#3534)
| -rw-r--r-- | src/platforms/rcore_desktop_sdl.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/platforms/rcore_desktop_sdl.c b/src/platforms/rcore_desktop_sdl.c index 87ceacb8..a84b0fe8 100644 --- a/src/platforms/rcore_desktop_sdl.c +++ b/src/platforms/rcore_desktop_sdl.c @@ -1084,14 +1084,26 @@ void PollInputEvents(void) // Check mouse events case SDL_MOUSEBUTTONDOWN: { - CORE.Input.Mouse.currentButtonState[event.button.button - 1] = 1; + // NOTE: SDL2 mouse button order is LEFT, MIDDLE, RIGHT, but raylib uses LEFT, RIGHT, MIDDLE like GLFW + // The following conditions align SDL with raylib.h MouseButton enum order + int btn = event.button.button - 1; + if (btn == 2) btn = 1; + else if (btn == 1) btn = 2; + + CORE.Input.Mouse.currentButtonState[btn] = 1; touchAction = 1; gestureUpdate = true; } break; case SDL_MOUSEBUTTONUP: { - CORE.Input.Mouse.currentButtonState[event.button.button - 1] = 0; + // NOTE: SDL2 mouse button order is LEFT, MIDDLE, RIGHT, but raylib uses LEFT, RIGHT, MIDDLE like GLFW + // The following conditions align SDL with raylib.h MouseButton enum order + int btn = event.button.button - 1; + if (btn == 2) btn = 1; + else if (btn == 1) btn = 2; + + CORE.Input.Mouse.currentButtonState[btn] = 0; touchAction = 0; gestureUpdate = true; |
