Remember what finger was used for left button down and only send mouse events for that finger.

This commit is contained in:
Sam Lantinga 2012-10-21 22:38:09 -07:00
parent 995e8dc838
commit 59f291a1a3
2 changed files with 30 additions and 42 deletions

View file

@ -22,8 +22,9 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "SDL_uikitviewcontroller.h" #import "SDL_uikitviewcontroller.h"
#include "SDL_touch.h"
#define IPHONE_TOUCH_EFFICIENT_DANGEROUS #define IPHONE_TOUCH_EFFICIENT_DANGEROUS
#define FIXED_MULTITOUCH
#ifndef IPHONE_TOUCH_EFFICIENT_DANGEROUS #ifndef IPHONE_TOUCH_EFFICIENT_DANGEROUS
#define MAX_SIMULTANEOUS_TOUCHES 5 #define MAX_SIMULTANEOUS_TOUCHES 5
@ -35,12 +36,11 @@
@interface SDL_uikitview : UIView { @interface SDL_uikitview : UIView {
#endif #endif
#ifdef FIXED_MULTITOUCH SDL_TouchID touchId;
long touchId; SDL_FingerID leftFingerDown;
#ifndef IPHONE_TOUCH_EFFICIENT_DANGEROUS #ifndef IPHONE_TOUCH_EFFICIENT_DANGEROUS
UITouch *finger[MAX_SIMULTANEOUS_TOUCHES]; UITouch *finger[MAX_SIMULTANEOUS_TOUCHES];
#endif #endif
#endif
#if SDL_IPHONE_KEYBOARD #if SDL_IPHONE_KEYBOARD
UITextField *textField; UITextField *textField;

View file

@ -50,7 +50,6 @@
[self initializeKeyboard]; [self initializeKeyboard];
#endif #endif
#ifdef FIXED_MULTITOUCH
self.multipleTouchEnabled = YES; self.multipleTouchEnabled = YES;
SDL_Touch touch; SDL_Touch touch;
@ -69,9 +68,7 @@
touch.pressure_max = 1; touch.pressure_max = 1;
touch.native_pressureres = touch.pressure_max - touch.pressure_min; touch.native_pressureres = touch.pressure_max - touch.pressure_min;
touchId = SDL_AddTouch(&touch, "IPHONE SCREEN"); touchId = SDL_AddTouch(&touch, "IPHONE SCREEN");
#endif
return self; return self;
@ -102,25 +99,25 @@
NSEnumerator *enumerator = [touches objectEnumerator]; NSEnumerator *enumerator = [touches objectEnumerator];
UITouch *touch = (UITouch*)[enumerator nextObject]; UITouch *touch = (UITouch*)[enumerator nextObject];
if (touch) { while (touch) {
CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO]; if (!leftFingerDown) {
CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
/* send moved event */ /* send moved event */
SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y); SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
/* send mouse down event */ /* send mouse down event */
SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT); SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT);
}
leftFingerDown = (SDL_FingerID)touch;
}
#ifdef FIXED_MULTITOUCH
while(touch) {
CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES]; CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
//FIXME: TODO: Using touch as the fingerId is potentially dangerous // FIXME: TODO: Using touch as the fingerId is potentially dangerous
//It is also much more efficient than storing the UITouch pointer // It is also much more efficient than storing the UITouch pointer
//and comparing it to the incoming event. // and comparing it to the incoming event.
SDL_SendFingerDown(touchId, (long)touch, SDL_SendFingerDown(touchId, (SDL_FingerID)touch,
SDL_TRUE, locationInView.x, locationInView.y, SDL_TRUE, locationInView.x, locationInView.y,
1); 1);
#else #else
@ -135,10 +132,8 @@
} }
} }
#endif #endif
touch = (UITouch*)[enumerator nextObject]; touch = (UITouch*)[enumerator nextObject];
} }
#endif
} }
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
@ -146,15 +141,14 @@
NSEnumerator *enumerator = [touches objectEnumerator]; NSEnumerator *enumerator = [touches objectEnumerator];
UITouch *touch = (UITouch*)[enumerator nextObject]; UITouch *touch = (UITouch*)[enumerator nextObject];
if (touch) {
/* send mouse up */
SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT);
}
#ifdef FIXED_MULTITOUCH
while(touch) { 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 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
SDL_SendFingerDown(touchId, (long)touch, SDL_SendFingerDown(touchId, (long)touch,
SDL_FALSE, locationInView.x, locationInView.y, SDL_FALSE, locationInView.x, locationInView.y,
@ -171,10 +165,8 @@
} }
} }
#endif #endif
touch = (UITouch*)[enumerator nextObject]; touch = (UITouch*)[enumerator nextObject];
} }
#endif
} }
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
@ -192,17 +184,15 @@
NSEnumerator *enumerator = [touches objectEnumerator]; NSEnumerator *enumerator = [touches objectEnumerator];
UITouch *touch = (UITouch*)[enumerator nextObject]; UITouch *touch = (UITouch*)[enumerator nextObject];
if (touch) { while (touch) {
CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO]; if ((SDL_FingerID)touch == leftFingerDown) {
CGPoint locationInView = [self touchLocation:touch shouldNormalize:NO];
/* send moved event */ /* send moved event */
SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y); SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
} }
#ifdef FIXED_MULTITOUCH
while(touch) {
CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES]; CGPoint locationInView = [self touchLocation:touch shouldNormalize:YES];
#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
SDL_SendTouchMotion(touchId, (long)touch, SDL_SendTouchMotion(touchId, (long)touch,
SDL_FALSE, locationInView.x, locationInView.y, SDL_FALSE, locationInView.x, locationInView.y,
@ -218,10 +208,8 @@
} }
} }
#endif #endif
touch = (UITouch*)[enumerator nextObject]; touch = (UITouch*)[enumerator nextObject];
} }
#endif
} }
/* /*