Remember what finger was used for left button down and only send mouse events for that finger.
authorSam Lantinga <slouken@libsdl.org>
Sun, 21 Oct 2012 22:38:09 -0700
changeset 6597d359909f8121
parent 6596 b00cf2e4835c
child 6598 81d643a61b54
Remember what finger was used for left button down and only send mouse events for that finger.
src/video/uikit/SDL_uikitview.h
src/video/uikit/SDL_uikitview.m
     1.1 --- a/src/video/uikit/SDL_uikitview.h	Sun Oct 21 22:18:36 2012 -0700
     1.2 +++ b/src/video/uikit/SDL_uikitview.h	Sun Oct 21 22:38:09 2012 -0700
     1.3 @@ -22,8 +22,9 @@
     1.4  #import <UIKit/UIKit.h>
     1.5  #import "SDL_uikitviewcontroller.h"
     1.6  
     1.7 +#include "SDL_touch.h"
     1.8 +
     1.9  #define IPHONE_TOUCH_EFFICIENT_DANGEROUS
    1.10 -#define FIXED_MULTITOUCH
    1.11  
    1.12  #ifndef IPHONE_TOUCH_EFFICIENT_DANGEROUS
    1.13  #define MAX_SIMULTANEOUS_TOUCHES 5
    1.14 @@ -35,12 +36,11 @@
    1.15  @interface SDL_uikitview : UIView {
    1.16  #endif
    1.17  
    1.18 -#ifdef FIXED_MULTITOUCH
    1.19 -    long touchId;
    1.20 +    SDL_TouchID touchId;
    1.21 +    SDL_FingerID leftFingerDown;
    1.22  #ifndef IPHONE_TOUCH_EFFICIENT_DANGEROUS
    1.23      UITouch *finger[MAX_SIMULTANEOUS_TOUCHES];
    1.24  #endif
    1.25 -#endif
    1.26  
    1.27  #if SDL_IPHONE_KEYBOARD
    1.28      UITextField *textField;
     2.1 --- a/src/video/uikit/SDL_uikitview.m	Sun Oct 21 22:18:36 2012 -0700
     2.2 +++ b/src/video/uikit/SDL_uikitview.m	Sun Oct 21 22:38:09 2012 -0700
     2.3 @@ -50,7 +50,6 @@
     2.4      [self initializeKeyboard];
     2.5  #endif
     2.6  
     2.7 -#ifdef FIXED_MULTITOUCH
     2.8      self.multipleTouchEnabled = YES;
     2.9  
    2.10      SDL_Touch touch;
    2.11 @@ -69,9 +68,7 @@
    2.12      touch.pressure_max = 1;
    2.13      touch.native_pressureres = touch.pressure_max - touch.pressure_min;
    2.14  
    2.15 -
    2.16      touchId = SDL_AddTouch(&touch, "IPHONE SCREEN");
    2.17 -#endif
    2.18  
    2.19      return self;
    2.20  
    2.21 @@ -102,25 +99,25 @@
    2.22      NSEnumerator *enumerator = [touches objectEnumerator];
    2.23      UITouch *touch = (UITouch*)[enumerator nextObject];
    2.24  
    2.25 -    if (touch) {
    2.26 -        CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
    2.27 +    while (touch) {
    2.28 +        if (!leftFingerDown) {
    2.29 +            CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
    2.30  
    2.31 -        /* send moved event */
    2.32 -        SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
    2.33 +            /* send moved event */
    2.34 +            SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
    2.35  
    2.36 -        /* send mouse down event */
    2.37 -        SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT);
    2.38 -    }
    2.39 +            /* send mouse down event */
    2.40 +            SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT);
    2.41  
    2.42 -#ifdef FIXED_MULTITOUCH
    2.43 -    while(touch) {
    2.44 +            leftFingerDown = (SDL_FingerID)touch;
    2.45 +        }
    2.46 +
    2.47          CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
    2.48 -
    2.49  #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
    2.50 -        //FIXME: TODO: Using touch as the fingerId is potentially dangerous
    2.51 -        //It is also much more efficient than storing the UITouch pointer
    2.52 -        //and comparing it to the incoming event.
    2.53 -        SDL_SendFingerDown(touchId, (long)touch,
    2.54 +        // FIXME: TODO: Using touch as the fingerId is potentially dangerous
    2.55 +        // It is also much more efficient than storing the UITouch pointer
    2.56 +        // and comparing it to the incoming event.
    2.57 +        SDL_SendFingerDown(touchId, (SDL_FingerID)touch,
    2.58                             SDL_TRUE, locationInView.x, locationInView.y,
    2.59                             1);
    2.60  #else
    2.61 @@ -135,10 +132,8 @@
    2.62              }
    2.63          }
    2.64  #endif
    2.65 -
    2.66          touch = (UITouch*)[enumerator nextObject];
    2.67      }
    2.68 -#endif
    2.69  }
    2.70  
    2.71  - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    2.72 @@ -146,15 +141,14 @@
    2.73      NSEnumerator *enumerator = [touches objectEnumerator];
    2.74      UITouch *touch = (UITouch*)[enumerator nextObject];
    2.75  
    2.76 -    if (touch) {
    2.77 -        /* send mouse up */
    2.78 -        SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT);
    2.79 -    }
    2.80 +    while(touch) {
    2.81 +        if ((SDL_FingerID)touch == leftFingerDown) {
    2.82 +            /* send mouse up */
    2.83 +            SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT);
    2.84 +            leftFingerDown = 0;
    2.85 +        }
    2.86  
    2.87 -#ifdef FIXED_MULTITOUCH
    2.88 -    while(touch) {
    2.89          CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
    2.90 -
    2.91  #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
    2.92          SDL_SendFingerDown(touchId, (long)touch,
    2.93                             SDL_FALSE, locationInView.x, locationInView.y,
    2.94 @@ -171,10 +165,8 @@
    2.95              }
    2.96          }
    2.97  #endif
    2.98 -
    2.99          touch = (UITouch*)[enumerator nextObject];
   2.100      }
   2.101 -#endif
   2.102  }
   2.103  
   2.104  - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
   2.105 @@ -192,17 +184,15 @@
   2.106      NSEnumerator *enumerator = [touches objectEnumerator];
   2.107      UITouch *touch = (UITouch*)[enumerator nextObject];
   2.108  
   2.109 -    if (touch) {
   2.110 -        CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
   2.111 +    while (touch) {
   2.112 +        if ((SDL_FingerID)touch == leftFingerDown) {
   2.113 +            CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
   2.114  
   2.115 -        /* send moved event */
   2.116 -        SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
   2.117 -    }
   2.118 +            /* send moved event */
   2.119 +            SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
   2.120 +        }
   2.121  
   2.122 -#ifdef FIXED_MULTITOUCH
   2.123 -    while(touch) {
   2.124          CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
   2.125 -
   2.126  #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
   2.127          SDL_SendTouchMotion(touchId, (long)touch,
   2.128                              SDL_FALSE, locationInView.x, locationInView.y,
   2.129 @@ -218,10 +208,8 @@
   2.130              }
   2.131          }
   2.132  #endif
   2.133 -
   2.134          touch = (UITouch*)[enumerator nextObject];
   2.135      }
   2.136 -#endif
   2.137  }
   2.138  
   2.139  /*