Skip to content

Commit 87f26c8

Browse files
author
ubkp
authored
Fix mouse button order for SDL (#3534)
1 parent 4f67f5f commit 87f26c8

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/platforms/rcore_desktop_sdl.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,14 +1084,26 @@ void PollInputEvents(void)
10841084
// Check mouse events
10851085
case SDL_MOUSEBUTTONDOWN:
10861086
{
1087-
CORE.Input.Mouse.currentButtonState[event.button.button - 1] = 1;
1087+
// NOTE: SDL2 mouse button order is LEFT, MIDDLE, RIGHT, but raylib uses LEFT, RIGHT, MIDDLE like GLFW
1088+
// The following conditions align SDL with raylib.h MouseButton enum order
1089+
int btn = event.button.button - 1;
1090+
if (btn == 2) btn = 1;
1091+
else if (btn == 1) btn = 2;
1092+
1093+
CORE.Input.Mouse.currentButtonState[btn] = 1;
10881094

10891095
touchAction = 1;
10901096
gestureUpdate = true;
10911097
} break;
10921098
case SDL_MOUSEBUTTONUP:
10931099
{
1094-
CORE.Input.Mouse.currentButtonState[event.button.button - 1] = 0;
1100+
// NOTE: SDL2 mouse button order is LEFT, MIDDLE, RIGHT, but raylib uses LEFT, RIGHT, MIDDLE like GLFW
1101+
// The following conditions align SDL with raylib.h MouseButton enum order
1102+
int btn = event.button.button - 1;
1103+
if (btn == 2) btn = 1;
1104+
else if (btn == 1) btn = 2;
1105+
1106+
CORE.Input.Mouse.currentButtonState[btn] = 0;
10951107

10961108
touchAction = 0;
10971109
gestureUpdate = true;

0 commit comments

Comments
 (0)