From 93ac678288a917178dbe945df620119d65e1b041 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 21 Oct 2012 22:38:09 -0700 Subject: [PATCH] Remember what finger was used for left button down and only send mouse events for that finger. --- src/video/uikit/SDL_uikitview.h | 8 ++--- src/video/uikit/SDL_uikitview.m | 64 ++++++++++++++------------------- 2 files changed, 30 insertions(+), 42 deletions(-) diff --git a/src/video/uikit/SDL_uikitview.h b/src/video/uikit/SDL_uikitview.h index 20e330745..c60830ab1 100644 --- a/src/video/uikit/SDL_uikitview.h +++ b/src/video/uikit/SDL_uikitview.h @@ -22,8 +22,9 @@ #import #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; diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m index 801acd719..a54cc501d 100644 --- a/src/video/uikit/SDL_uikitview.m +++ b/src/video/uikit/SDL_uikitview.m @@ -50,7 +50,6 @@ - (id)initWithFrame:(CGRect)frame [self initializeKeyboard]; #endif -#ifdef FIXED_MULTITOUCH self.multipleTouchEnabled = YES; SDL_Touch touch; @@ -69,9 +68,7 @@ - (id)initWithFrame:(CGRect)frame 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 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 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) { - CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES]; + 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 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event } } #endif - touch = (UITouch*)[enumerator nextObject]; } -#endif } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event @@ -146,15 +141,14 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event NSEnumerator *enumerator = [touches objectEnumerator]; UITouch *touch = (UITouch*)[enumerator nextObject]; - if (touch) { - /* send mouse up */ - SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT); - } - -#ifdef FIXED_MULTITOUCH while(touch) { - CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES]; + if ((SDL_FingerID)touch == leftFingerDown) { + /* send mouse up */ + SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT); + leftFingerDown = 0; + } + 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 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event } } #endif - touch = (UITouch*)[enumerator nextObject]; } -#endif } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event @@ -192,17 +184,15 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 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 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event } } #endif - touch = (UITouch*)[enumerator nextObject]; } -#endif } /*