src/video/uikit/SDL_uikitview.m
changeset 11846 a1b2d62d5d73
parent 11845 cf80a56f6d8d
child 12201 8bdc4d340419
     1.1 --- a/src/video/uikit/SDL_uikitview.m	Tue Feb 06 15:03:38 2018 -0800
     1.2 +++ b/src/video/uikit/SDL_uikitview.m	Tue Feb 06 16:43:31 2018 -0800
     1.3 @@ -33,6 +33,9 @@
     1.4  #import "SDL_uikitmodes.h"
     1.5  #import "SDL_uikitwindow.h"
     1.6  
     1.7 +/* This is defined in SDL_sysjoystick.m */
     1.8 +extern int SDL_AppleTVRemoteOpenedAsJoystick;
     1.9 +
    1.10  @implementation SDL_uikitview {
    1.11      SDL_Window *sdlwindow;
    1.12  
    1.13 @@ -44,24 +47,22 @@
    1.14  {
    1.15      if ((self = [super initWithFrame:frame])) {
    1.16  #if TARGET_OS_TV
    1.17 -        if (!SDL_GetHintBoolean(SDL_HINT_TV_REMOTE_AS_JOYSTICK, SDL_TRUE)) {
    1.18 -            /* Apple TV Remote touchpad swipe gestures. */
    1.19 -            UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
    1.20 -            swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
    1.21 -            [self addGestureRecognizer:swipeUp];
    1.22 +        /* Apple TV Remote touchpad swipe gestures. */
    1.23 +        UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
    1.24 +        swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
    1.25 +        [self addGestureRecognizer:swipeUp];
    1.26  
    1.27 -            UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
    1.28 -            swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
    1.29 -            [self addGestureRecognizer:swipeDown];
    1.30 +        UISwipeGestureRecognizer *swipeDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
    1.31 +        swipeDown.direction = UISwipeGestureRecognizerDirectionDown;
    1.32 +        [self addGestureRecognizer:swipeDown];
    1.33  
    1.34 -            UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
    1.35 -            swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
    1.36 -            [self addGestureRecognizer:swipeLeft];
    1.37 +        UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
    1.38 +        swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
    1.39 +        [self addGestureRecognizer:swipeLeft];
    1.40  
    1.41 -            UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
    1.42 -            swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
    1.43 -            [self addGestureRecognizer:swipeRight];
    1.44 -        }
    1.45 +        UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeGesture:)];
    1.46 +        swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
    1.47 +        [self addGestureRecognizer:swipeRight];
    1.48  #endif
    1.49  
    1.50          self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    1.51 @@ -251,7 +252,7 @@
    1.52  
    1.53  - (void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
    1.54  {
    1.55 -	if (!SDL_GetHintBoolean(SDL_HINT_TV_REMOTE_AS_JOYSTICK, SDL_TRUE)) {
    1.56 +	if (!SDL_AppleTVRemoteOpenedAsJoystick) {
    1.57      	for (UIPress *press in presses) {
    1.58          	SDL_Scancode scancode = [self scancodeFromPressType:press.type];
    1.59          	SDL_SendKeyboardKey(SDL_PRESSED, scancode);
    1.60 @@ -262,7 +263,7 @@
    1.61  
    1.62  - (void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
    1.63  {
    1.64 -	if (!SDL_GetHintBoolean(SDL_HINT_TV_REMOTE_AS_JOYSTICK, SDL_TRUE)) {
    1.65 +	if (!SDL_AppleTVRemoteOpenedAsJoystick) {
    1.66  		for (UIPress *press in presses) {
    1.67  			SDL_Scancode scancode = [self scancodeFromPressType:press.type];
    1.68  			SDL_SendKeyboardKey(SDL_RELEASED, scancode);
    1.69 @@ -273,7 +274,7 @@
    1.70  
    1.71  - (void)pressesCancelled:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
    1.72  {
    1.73 -	if (!SDL_GetHintBoolean(SDL_HINT_TV_REMOTE_AS_JOYSTICK, SDL_TRUE)) {
    1.74 +	if (!SDL_AppleTVRemoteOpenedAsJoystick) {
    1.75  		for (UIPress *press in presses) {
    1.76  			SDL_Scancode scancode = [self scancodeFromPressType:press.type];
    1.77  			SDL_SendKeyboardKey(SDL_RELEASED, scancode);
    1.78 @@ -294,25 +295,27 @@
    1.79  {
    1.80      /* Swipe gestures don't trigger begin states. */
    1.81      if (gesture.state == UIGestureRecognizerStateEnded) {
    1.82 -        /* Send arrow key presses for now, as we don't have an external API
    1.83 -         * which better maps to swipe gestures. */
    1.84 -        switch (gesture.direction) {
    1.85 -        case UISwipeGestureRecognizerDirectionUp:
    1.86 -            SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_UP);
    1.87 -            SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_UP);
    1.88 -            break;
    1.89 -        case UISwipeGestureRecognizerDirectionDown:
    1.90 -            SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_DOWN);
    1.91 -            SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_DOWN);
    1.92 -            break;
    1.93 -        case UISwipeGestureRecognizerDirectionLeft:
    1.94 -            SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LEFT);
    1.95 -            SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LEFT);
    1.96 -            break;
    1.97 -        case UISwipeGestureRecognizerDirectionRight:
    1.98 -            SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RIGHT);
    1.99 -            SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RIGHT);
   1.100 -            break;
   1.101 +        if (!SDL_AppleTVRemoteOpenedAsJoystick) {
   1.102 +            /* Send arrow key presses for now, as we don't have an external API
   1.103 +             * which better maps to swipe gestures. */
   1.104 +            switch (gesture.direction) {
   1.105 +            case UISwipeGestureRecognizerDirectionUp:
   1.106 +                SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_UP);
   1.107 +                SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_UP);
   1.108 +                break;
   1.109 +            case UISwipeGestureRecognizerDirectionDown:
   1.110 +                SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_DOWN);
   1.111 +                SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_DOWN);
   1.112 +                break;
   1.113 +            case UISwipeGestureRecognizerDirectionLeft:
   1.114 +                SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LEFT);
   1.115 +                SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LEFT);
   1.116 +                break;
   1.117 +            case UISwipeGestureRecognizerDirectionRight:
   1.118 +                SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RIGHT);
   1.119 +                SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RIGHT);
   1.120 +                break;
   1.121 +            }
   1.122          }
   1.123      }
   1.124  }