src/video/uikit/SDL_uikitview.m
changeset 12404 eb60e952b13f
parent 12201 8bdc4d340419
child 12503 806492103856
     1.1 --- a/src/video/uikit/SDL_uikitview.m	Wed Nov 07 07:52:39 2018 -0800
     1.2 +++ b/src/video/uikit/SDL_uikitview.m	Sat Nov 10 16:15:48 2018 -0400
     1.3 @@ -39,7 +39,9 @@
     1.4  @implementation SDL_uikitview {
     1.5      SDL_Window *sdlwindow;
     1.6  
     1.7 -    SDL_TouchID touchId;
     1.8 +    SDL_TouchID directTouchId;
     1.9 +    SDL_TouchID indirectTouchId;
    1.10 +
    1.11      UITouch * __weak firstFingerDown;
    1.12  }
    1.13  
    1.14 @@ -68,12 +70,13 @@
    1.15          self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    1.16          self.autoresizesSubviews = YES;
    1.17  
    1.18 +        directTouchId = 1;
    1.19 +        indirectTouchId = 2;
    1.20 +
    1.21  #if !TARGET_OS_TV
    1.22          self.multipleTouchEnabled = YES;
    1.23 +        SDL_AddTouch(directTouchId, SDL_TOUCH_DEVICE_DIRECT, "");
    1.24  #endif
    1.25 -
    1.26 -        touchId = 1;
    1.27 -        SDL_AddTouch(touchId, "");
    1.28      }
    1.29  
    1.30      return self;
    1.31 @@ -135,6 +138,30 @@
    1.32      sdlwindow = window;
    1.33  }
    1.34  
    1.35 +- (SDL_TouchDeviceType)touchTypeForTouch:(UITouch *)touch
    1.36 +{
    1.37 +#ifdef __IPHONE_9_0
    1.38 +    if ([touch respondsToSelector:@selector((type))]) {
    1.39 +        if (touch.type == UITouchTypeIndirect) {
    1.40 +            return SDL_TOUCH_DEVICE_INDIRECT_RELATIVE;
    1.41 +        }
    1.42 +    }
    1.43 +#endif
    1.44 +
    1.45 +    return SDL_TOUCH_DEVICE_DIRECT;
    1.46 +}
    1.47 +
    1.48 +- (SDL_TouchID)touchIdForType:(SDL_TouchDeviceType)type
    1.49 +{
    1.50 +    switch (type) {
    1.51 +        case SDL_TOUCH_DEVICE_DIRECT:
    1.52 +        default:
    1.53 +            return directTouchId;
    1.54 +        case SDL_TOUCH_DEVICE_INDIRECT_RELATIVE:
    1.55 +            return indirectTouchId;
    1.56 +    }
    1.57 +}
    1.58 +
    1.59  - (CGPoint)touchLocation:(UITouch *)touch shouldNormalize:(BOOL)normalize
    1.60  {
    1.61      CGPoint point = [touch locationInView:self];
    1.62 @@ -162,8 +189,14 @@
    1.63  - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    1.64  {
    1.65      for (UITouch *touch in touches) {
    1.66 +        SDL_TouchDeviceType touchType = [self touchTypeForTouch:touch];
    1.67 +        SDL_TouchID touchId = [self touchIdForType:touchType];
    1.68          float pressure = [self pressureForTouch:touch];
    1.69  
    1.70 +        if (SDL_AddTouch(touchId, touchType, "") < 0) {
    1.71 +            continue;
    1.72 +        }
    1.73 +
    1.74          if (!firstFingerDown) {
    1.75              CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
    1.76              int clicks = (int) touch.tapCount;
    1.77 @@ -186,8 +219,14 @@
    1.78  - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    1.79  {
    1.80      for (UITouch *touch in touches) {
    1.81 +        SDL_TouchDeviceType touchType = [self touchTypeForTouch:touch];
    1.82 +        SDL_TouchID touchId = [self touchIdForType:touchType];
    1.83          float pressure = [self pressureForTouch:touch];
    1.84  
    1.85 +        if (SDL_AddTouch(touchId, touchType, "") < 0) {
    1.86 +            continue;
    1.87 +        }
    1.88 +
    1.89          if (touch == firstFingerDown) {
    1.90              /* send mouse up */
    1.91              int clicks = (int) touch.tapCount;
    1.92 @@ -209,8 +248,14 @@
    1.93  - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    1.94  {
    1.95      for (UITouch *touch in touches) {
    1.96 +        SDL_TouchDeviceType touchType = [self touchTypeForTouch:touch];
    1.97 +        SDL_TouchID touchId = [self touchIdForType:touchType];
    1.98          float pressure = [self pressureForTouch:touch];
    1.99  
   1.100 +        if (SDL_AddTouch(touchId, touchType, "") < 0) {
   1.101 +            continue;
   1.102 +        }
   1.103 +
   1.104          if (touch == firstFingerDown) {
   1.105              CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
   1.106