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

Commit

Permalink
Re-implemented single mouse touches on the iPhone/iPad
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jul 7, 2010
1 parent 7361be2 commit 8037039
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/video/uikit/SDL_uikitopengles.m
Expand Up @@ -125,7 +125,10 @@ SDL_GLContext UIKit_GL_CreateContext(_THIS, SDL_Window * window)
UIKit_GL_DeleteContext(_this, view);
return NULL;
}


/* Make this window the current mouse focus for touch input */
SDL_SetMouseFocus(window);

return view;
}

Expand Down
2 changes: 1 addition & 1 deletion src/video/uikit/SDL_uikitview.h
Expand Up @@ -38,7 +38,7 @@
#else
@interface SDL_uikitview : UIView {
#endif

#if FIXME_MULTITOUCH
SDL_Mouse mice[MAX_SIMULTANEOUS_TOUCHES];
#endif
Expand Down
43 changes: 35 additions & 8 deletions src/video/uikit/SDL_uikitview.m
Expand Up @@ -64,7 +64,7 @@ - (id)initWithFrame:(CGRect)frame {
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

NSEnumerator *enumerator = [touches objectEnumerator];
UITouch *touch =(UITouch*)[enumerator nextObject];
UITouch *touch = (UITouch*)[enumerator nextObject];

#if FIXME_MULTITOUCH
/* associate touches with mice, so long as we have slots */
Expand Down Expand Up @@ -101,23 +101,32 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* re-calibrate relative mouse motion */
SDL_GetRelativeMouseState(i, NULL, NULL);

/* grab next touch */
touch = (UITouch*)[enumerator nextObject];

/* switch back to our old mouse */
SDL_SelectMouse(oldMouse);

/* grab next touch */
touch = (UITouch*)[enumerator nextObject];
}
#else
if (touch) {
CGPoint locationInView = [touch locationInView: self];

/* send moved event */
SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);

/* send mouse down event */
SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT);
}
#endif
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

NSEnumerator *enumerator = [touches objectEnumerator];
UITouch *touch=nil;
UITouch *touch = (UITouch*)[enumerator nextObject];

#if FIXME_MULTITOUCH
while(touch = (UITouch *)[enumerator nextObject]) {
while(touch) {
/* search for the mouse slot associated with this touch */
int i, found = NO;
for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
Expand All @@ -131,6 +140,14 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
found = YES;
}
}

/* grab next touch */
touch = (UITouch*)[enumerator nextObject];
}
#else
if (touch) {
/* send mouse up */
SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT);
}
#endif
}
Expand All @@ -147,10 +164,10 @@ - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

NSEnumerator *enumerator = [touches objectEnumerator];
UITouch *touch=nil;
UITouch *touch = (UITouch*)[enumerator nextObject];

#if FIXME_MULTITOUCH
while(touch = (UITouch *)[enumerator nextObject]) {
while(touch) {
/* try to find the mouse associated with this touch */
int i, found = NO;
for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
Expand All @@ -163,6 +180,16 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
found = YES;
}
}

/* grab next touch */
touch = (UITouch*)[enumerator nextObject];
}
#else
if (touch) {
CGPoint locationInView = [touch locationInView: self];

/* send moved event */
SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
}
#endif
}
Expand Down

0 comments on commit 8037039

Please sign in to comment.