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 dbf7f84 commit e1215e8
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/video/uikit/SDL_uikitview.m
Expand Up @@ -33,6 +33,9 @@
#import "SDL_uikitmodes.h"
#import "SDL_uikitwindow.h"

/* The maximum number of mouse buttons we support */
#define MAX_MOUSE_BUTTONS 5

/* This is defined in SDL_sysjoystick.m */
extern int SDL_AppleTVRemoteOpenedAsJoystick;

Expand Down Expand Up @@ -223,8 +226,13 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
if (touch.type == UITouchTypeIndirectPointer) {
int i;

for (i = SDL_BUTTON_LEFT; i <= SDL_BUTTON_X2; ++i) {
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;
}
SDL_SendMouseButton(sdlwindow, 0, SDL_PRESSED, i);
}
}
Expand Down Expand Up @@ -260,8 +268,13 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
if (touch.type == UITouchTypeIndirectPointer) {
int i;

for (i = SDL_BUTTON_LEFT; i <= SDL_BUTTON_X2; ++i) {
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;
}
SDL_SendMouseButton(sdlwindow, 0, SDL_RELEASED, i);
}
}
Expand Down

0 comments on commit e1215e8

Please sign in to comment.