Skip to content

Commit

Permalink
Fixed mouse button mapping on iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Apr 14, 2020
1 parent e1215e8 commit 3e4856c
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions src/video/uikit/SDL_uikitview.m
Expand Up @@ -34,7 +34,7 @@
#import "SDL_uikitwindow.h"

/* 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 */
extern int SDL_AppleTVRemoteOpenedAsJoystick;
Expand Down Expand Up @@ -228,12 +228,23 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

for (i = 1; i <= MAX_MOUSE_BUTTONS; ++i) {
if (event.buttonMask & SDL_BUTTON(i)) {
if (i == 2) {
i = SDL_BUTTON_RIGHT;
} else if (i == 3) {
i = SDL_BUTTON_MIDDLE;
Uint8 button;

switch (i) {
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;
Expand Down Expand Up @@ -270,12 +281,23 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

for (i = 1; i <= MAX_MOUSE_BUTTONS; ++i) {
if (!(event.buttonMask & SDL_BUTTON(i))) {
if (i == 2) {
i = SDL_BUTTON_RIGHT;
} else if (i == 3) {
i = SDL_BUTTON_MIDDLE;
Uint8 button;

switch (i) {
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;
Expand Down

0 comments on commit 3e4856c

Please sign in to comment.