src/video/uikit/SDL_uikitview.m
changeset 10340 5724f5087acd
parent 9998 f67cf37e9cd4
child 10366 e1b52e69578b
     1.1 --- a/src/video/uikit/SDL_uikitview.m	Tue Sep 13 19:51:10 2016 -0300
     1.2 +++ b/src/video/uikit/SDL_uikitview.m	Tue Sep 13 22:18:06 2016 -0300
     1.3 @@ -45,7 +45,9 @@
     1.4          self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
     1.5          self.autoresizesSubviews = YES;
     1.6  
     1.7 +#if !TARGET_OS_TV
     1.8          self.multipleTouchEnabled = YES;
     1.9 +#endif
    1.10  
    1.11          touchId = 1;
    1.12          SDL_AddTouch(touchId, "");
    1.13 @@ -197,6 +199,69 @@
    1.14      }
    1.15  }
    1.16  
    1.17 +#if TARGET_OS_TV || defined(__IPHONE_9_1)
    1.18 +- (SDL_Scancode)scancodeFromPressType:(UIPressType)presstype
    1.19 +{
    1.20 +    switch (presstype) {
    1.21 +    case UIPressTypeUpArrow:
    1.22 +        return SDL_SCANCODE_UP;
    1.23 +    case UIPressTypeDownArrow:
    1.24 +        return SDL_SCANCODE_DOWN;
    1.25 +    case UIPressTypeLeftArrow:
    1.26 +        return SDL_SCANCODE_LEFT;
    1.27 +    case UIPressTypeRightArrow:
    1.28 +        return SDL_SCANCODE_RIGHT;
    1.29 +    case UIPressTypeSelect:
    1.30 +        /* HIG says: "primary button behavior" */
    1.31 +        return SDL_SCANCODE_SELECT;
    1.32 +    case UIPressTypeMenu:
    1.33 +        /* HIG says: "returns to previous screen" */
    1.34 +        return SDL_SCANCODE_MENU;
    1.35 +    case UIPressTypePlayPause:
    1.36 +        /* HIG says: "secondary button behavior" */
    1.37 +        return SDL_SCANCODE_PAUSE;
    1.38 +    default:
    1.39 +        return SDL_SCANCODE_UNKNOWN;
    1.40 +    }
    1.41 +}
    1.42 +
    1.43 +- (void)pressesBegan:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
    1.44 +{
    1.45 +    for (UIPress *press in presses) {
    1.46 +        SDL_Scancode scancode = [self scancodeFromPressType:press.type];
    1.47 +        SDL_SendKeyboardKey(SDL_PRESSED, scancode);
    1.48 +    }
    1.49 +
    1.50 +    [super pressesBegan:presses withEvent:event];
    1.51 +}
    1.52 +
    1.53 +- (void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
    1.54 +{
    1.55 +    for (UIPress *press in presses) {
    1.56 +        SDL_Scancode scancode = [self scancodeFromPressType:press.type];
    1.57 +        SDL_SendKeyboardKey(SDL_RELEASED, scancode);
    1.58 +    }
    1.59 +
    1.60 +    [super pressesEnded:presses withEvent:event];
    1.61 +}
    1.62 +
    1.63 +- (void)pressesCancelled:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
    1.64 +{
    1.65 +    for (UIPress *press in presses) {
    1.66 +        SDL_Scancode scancode = [self scancodeFromPressType:press.type];
    1.67 +        SDL_SendKeyboardKey(SDL_RELEASED, scancode);
    1.68 +    }
    1.69 +
    1.70 +    [super pressesCancelled:presses withEvent:event];
    1.71 +}
    1.72 +
    1.73 +- (void)pressesChanged:(NSSet<UIPress *> *)presses withEvent:(UIPressesEvent *)event
    1.74 +{
    1.75 +    /* This is only called when the force of a press changes. */
    1.76 +    [super pressesChanged:presses withEvent:event];
    1.77 +}
    1.78 +#endif /* TARGET_OS_TV || defined(__IPHONE_9_1) */
    1.79 +
    1.80  @end
    1.81  
    1.82  #endif /* SDL_VIDEO_DRIVER_UIKIT */