Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Remember what finger was used for left button down and only send mous…
Browse files Browse the repository at this point in the history
…e events for that finger.
  • Loading branch information
slouken committed Oct 22, 2012
1 parent d1e9cd0 commit 93ac678
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 42 deletions.
8 changes: 4 additions & 4 deletions src/video/uikit/SDL_uikitview.h
Expand Up @@ -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
Expand All @@ -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;
Expand Down
64 changes: 26 additions & 38 deletions src/video/uikit/SDL_uikitview.m
Expand Up @@ -50,7 +50,6 @@ - (id)initWithFrame:(CGRect)frame
[self initializeKeyboard];
#endif

#ifdef FIXED_MULTITOUCH
self.multipleTouchEnabled = YES;

SDL_Touch touch;
Expand All @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -135,26 +132,23 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
}
}
#endif

touch = (UITouch*)[enumerator nextObject];
}
#endif
}

- (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,
Expand All @@ -171,10 +165,8 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
}
}
#endif

touch = (UITouch*)[enumerator nextObject];
}
#endif
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
Expand All @@ -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,
Expand All @@ -218,10 +208,8 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
}
}
#endif

touch = (UITouch*)[enumerator nextObject];
}
#endif
}

/*
Expand Down

0 comments on commit 93ac678

Please sign in to comment.