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 6597 d359909f8121
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
--- a/src/video/uikit/SDL_uikitview.h	Sun Oct 21 22:18:36 2012 -0700
+++ b/src/video/uikit/SDL_uikitview.h	Sun Oct 21 22:38:09 2012 -0700
@@ -22,8 +22,9 @@
 #import <UIKit/UIKit.h>
 #import "SDL_uikitviewcontroller.h"
 
+#include "SDL_touch.h"
+
 #define IPHONE_TOUCH_EFFICIENT_DANGEROUS
-#define FIXED_MULTITOUCH
 
 #ifndef IPHONE_TOUCH_EFFICIENT_DANGEROUS
 #define MAX_SIMULTANEOUS_TOUCHES 5
@@ -35,12 +36,11 @@
 @interface SDL_uikitview : UIView {
 #endif
 
-#ifdef FIXED_MULTITOUCH
-    long touchId;
+    SDL_TouchID touchId;
+    SDL_FingerID leftFingerDown;
 #ifndef IPHONE_TOUCH_EFFICIENT_DANGEROUS
     UITouch *finger[MAX_SIMULTANEOUS_TOUCHES];
 #endif
-#endif
 
 #if SDL_IPHONE_KEYBOARD
     UITextField *textField;
--- a/src/video/uikit/SDL_uikitview.m	Sun Oct 21 22:18:36 2012 -0700
+++ b/src/video/uikit/SDL_uikitview.m	Sun Oct 21 22:38:09 2012 -0700
@@ -50,7 +50,6 @@
     [self initializeKeyboard];
 #endif
 
-#ifdef FIXED_MULTITOUCH
     self.multipleTouchEnabled = YES;
 
     SDL_Touch touch;
@@ -69,9 +68,7 @@
     touch.pressure_max = 1;
     touch.native_pressureres = touch.pressure_max - touch.pressure_min;
 
-
     touchId = SDL_AddTouch(&touch, "IPHONE SCREEN");
-#endif
 
     return self;
 
@@ -102,25 +99,25 @@
     NSEnumerator *enumerator = [touches objectEnumerator];
     UITouch *touch = (UITouch*)[enumerator nextObject];
 
-    if (touch) {
-        CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
+    while (touch) {
+        if (!leftFingerDown) {
+            CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
 
-        /* send moved event */
-        SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
+            /* send moved event */
+            SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
 
-        /* send mouse down event */
-        SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT);
-    }
+            /* send mouse down event */
+            SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT);
 
-#ifdef FIXED_MULTITOUCH
-    while(touch) {
+            leftFingerDown = (SDL_FingerID)touch;
+        }
+
         CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
-
 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
-        //FIXME: TODO: Using touch as the fingerId is potentially dangerous
-        //It is also much more efficient than storing the UITouch pointer
-        //and comparing it to the incoming event.
-        SDL_SendFingerDown(touchId, (long)touch,
+        // FIXME: TODO: Using touch as the fingerId is potentially dangerous
+        // It is also much more efficient than storing the UITouch pointer
+        // and comparing it to the incoming event.
+        SDL_SendFingerDown(touchId, (SDL_FingerID)touch,
                            SDL_TRUE, locationInView.x, locationInView.y,
                            1);
 #else
@@ -135,10 +132,8 @@
             }
         }
 #endif
-
         touch = (UITouch*)[enumerator nextObject];
     }
-#endif
 }
 
 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
@@ -146,15 +141,14 @@
     NSEnumerator *enumerator = [touches objectEnumerator];
     UITouch *touch = (UITouch*)[enumerator nextObject];
 
-    if (touch) {
-        /* send mouse up */
-        SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT);
-    }
+    while(touch) {
+        if ((SDL_FingerID)touch == leftFingerDown) {
+            /* send mouse up */
+            SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT);
+            leftFingerDown = 0;
+        }
 
-#ifdef FIXED_MULTITOUCH
-    while(touch) {
         CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
-
 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
         SDL_SendFingerDown(touchId, (long)touch,
                            SDL_FALSE, locationInView.x, locationInView.y,
@@ -171,10 +165,8 @@
             }
         }
 #endif
-
         touch = (UITouch*)[enumerator nextObject];
     }
-#endif
 }
 
 - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
@@ -192,17 +184,15 @@
     NSEnumerator *enumerator = [touches objectEnumerator];
     UITouch *touch = (UITouch*)[enumerator nextObject];
 
-    if (touch) {
-        CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
+    while (touch) {
+        if ((SDL_FingerID)touch == leftFingerDown) {
+            CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
 
-        /* send moved event */
-        SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
-    }
+            /* send moved event */
+            SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
+        }
 
-#ifdef FIXED_MULTITOUCH
-    while(touch) {
         CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
-
 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
         SDL_SendTouchMotion(touchId, (long)touch,
                             SDL_FALSE, locationInView.x, locationInView.y,
@@ -218,10 +208,8 @@
             }
         }
 #endif
-
         touch = (UITouch*)[enumerator nextObject];
     }
-#endif
 }
 
 /*