Fixed mouse button mapping on iOS

Sam Lantinga 2020-04-13 23:07:54 -07:00
parent e1215e857f
commit 3e4856c97f
1 changed files with 33 additions and 11 deletions

View File

@ -34,7 +34,7 @@
#import "SDL_uikitwindow.h" #import "SDL_uikitwindow.h"
/* The maximum number of mouse buttons we support */ /* The maximum number of mouse buttons we support */
#define MAX_MOUSE_BUTTONS 5 #define MAX_MOUSE_BUTTONS 5
/* This is defined in SDL_sysjoystick.m */ /* This is defined in SDL_sysjoystick.m */
extern int SDL_AppleTVRemoteOpenedAsJoystick; extern int SDL_AppleTVRemoteOpenedAsJoystick;
@ -228,12 +228,23 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
for (i = 1; i <= MAX_MOUSE_BUTTONS; ++i) { for (i = 1; i <= MAX_MOUSE_BUTTONS; ++i) {
if (event.buttonMask & SDL_BUTTON(i)) { if (event.buttonMask & SDL_BUTTON(i)) {
if (i == 2) { Uint8 button;
i = SDL_BUTTON_RIGHT;
} else if (i == 3) { switch (i) {
i = SDL_BUTTON_MIDDLE; case 1:
button = SDL_BUTTON_LEFT;
break;
case 2:
button = SDL_BUTTON_RIGHT;
break;
case 3:
button = SDL_BUTTON_MIDDLE;
break;
default:
button = (Uint8)i;
break;
} }
SDL_SendMouseButton(sdlwindow, 0, SDL_PRESSED, i); SDL_SendMouseButton(sdlwindow, 0, SDL_PRESSED, button);
} }
} }
handled = YES; handled = YES;
@ -270,12 +281,23 @@ extern int SDL_AppleTVRemoteOpenedAsJoystick;
for (i = 1; i <= MAX_MOUSE_BUTTONS; ++i) { for (i = 1; i <= MAX_MOUSE_BUTTONS; ++i) {
if (!(event.buttonMask & SDL_BUTTON(i))) { if (!(event.buttonMask & SDL_BUTTON(i))) {
if (i == 2) { Uint8 button;
i = SDL_BUTTON_RIGHT;
} else if (i == 3) { switch (i) {
i = SDL_BUTTON_MIDDLE; case 1:
button = SDL_BUTTON_LEFT;
break;
case 2:
button = SDL_BUTTON_RIGHT;
break;
case 3:
button = SDL_BUTTON_MIDDLE;
break;
default:
button = (Uint8)i;
break;
} }
SDL_SendMouseButton(sdlwindow, 0, SDL_RELEASED, i); SDL_SendMouseButton(sdlwindow, 0, SDL_RELEASED, button);
} }
} }
handled = YES; handled = YES;