Re-implemented single mouse touches on the iPhone/iPad
authorSam Lantinga <slouken@libsdl.org>
Tue, 06 Jul 2010 22:08:19 -0700
changeset 44886dc6a2bdd55e
parent 4487 ba7b2bc1f1a1
child 4489 2bb1bfeee9e2
Re-implemented single mouse touches on the iPhone/iPad
src/video/uikit/SDL_uikitopengles.m
src/video/uikit/SDL_uikitview.h
src/video/uikit/SDL_uikitview.m
     1.1 --- a/src/video/uikit/SDL_uikitopengles.m	Tue Jul 06 10:58:23 2010 -0700
     1.2 +++ b/src/video/uikit/SDL_uikitopengles.m	Tue Jul 06 22:08:19 2010 -0700
     1.3 @@ -125,7 +125,10 @@
     1.4          UIKit_GL_DeleteContext(_this, view);
     1.5          return NULL;
     1.6      }
     1.7 -		
     1.8 +
     1.9 +	/* Make this window the current mouse focus for touch input */
    1.10 +	SDL_SetMouseFocus(window);
    1.11 +
    1.12  	return view;
    1.13  }
    1.14  
     2.1 --- a/src/video/uikit/SDL_uikitview.h	Tue Jul 06 10:58:23 2010 -0700
     2.2 +++ b/src/video/uikit/SDL_uikitview.h	Tue Jul 06 22:08:19 2010 -0700
     2.3 @@ -38,7 +38,7 @@
     2.4  #else
     2.5  @interface SDL_uikitview : UIView {
     2.6  #endif
     2.7 -	
     2.8 +
     2.9  #if FIXME_MULTITOUCH
    2.10  	SDL_Mouse mice[MAX_SIMULTANEOUS_TOUCHES];
    2.11  #endif
     3.1 --- a/src/video/uikit/SDL_uikitview.m	Tue Jul 06 10:58:23 2010 -0700
     3.2 +++ b/src/video/uikit/SDL_uikitview.m	Tue Jul 06 22:08:19 2010 -0700
     3.3 @@ -64,7 +64,7 @@
     3.4  - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
     3.5  
     3.6  	NSEnumerator *enumerator = [touches objectEnumerator];
     3.7 -	UITouch *touch =(UITouch*)[enumerator nextObject];
     3.8 +	UITouch *touch = (UITouch*)[enumerator nextObject];
     3.9  	
    3.10  #if FIXME_MULTITOUCH
    3.11  	/* associate touches with mice, so long as we have slots */
    3.12 @@ -101,12 +101,21 @@
    3.13  		/* re-calibrate relative mouse motion */
    3.14  		SDL_GetRelativeMouseState(i, NULL, NULL);
    3.15  		
    3.16 -		/* grab next touch */
    3.17 -		touch = (UITouch*)[enumerator nextObject]; 
    3.18 -		
    3.19  		/* switch back to our old mouse */
    3.20  		SDL_SelectMouse(oldMouse);
    3.21  		
    3.22 +		/* grab next touch */
    3.23 +		touch = (UITouch*)[enumerator nextObject]; 
    3.24 +	}
    3.25 +#else
    3.26 +	if (touch) {
    3.27 +		CGPoint locationInView = [touch locationInView: self];
    3.28 +			
    3.29 +		/* send moved event */
    3.30 +		SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
    3.31 +
    3.32 +		/* send mouse down event */
    3.33 +		SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT);
    3.34  	}
    3.35  #endif
    3.36  }
    3.37 @@ -114,10 +123,10 @@
    3.38  - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    3.39  	
    3.40  	NSEnumerator *enumerator = [touches objectEnumerator];
    3.41 -	UITouch *touch=nil;
    3.42 +	UITouch *touch = (UITouch*)[enumerator nextObject];
    3.43  	
    3.44  #if FIXME_MULTITOUCH
    3.45 -	while(touch = (UITouch *)[enumerator nextObject]) {
    3.46 +	while(touch) {
    3.47  		/* search for the mouse slot associated with this touch */
    3.48  		int i, found = NO;
    3.49  		for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
    3.50 @@ -131,6 +140,14 @@
    3.51  				found = YES;
    3.52  			}
    3.53  		}
    3.54 +		
    3.55 +		/* grab next touch */
    3.56 +		touch = (UITouch*)[enumerator nextObject]; 
    3.57 +	}
    3.58 +#else
    3.59 +	if (touch) {
    3.60 +		/* send mouse up */
    3.61 +		SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT);
    3.62  	}
    3.63  #endif
    3.64  }
    3.65 @@ -147,10 +164,10 @@
    3.66  - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    3.67  	
    3.68  	NSEnumerator *enumerator = [touches objectEnumerator];
    3.69 -	UITouch *touch=nil;
    3.70 +	UITouch *touch = (UITouch*)[enumerator nextObject];
    3.71  	
    3.72  #if FIXME_MULTITOUCH
    3.73 -	while(touch = (UITouch *)[enumerator nextObject]) {
    3.74 +	while(touch) {
    3.75  		/* try to find the mouse associated with this touch */
    3.76  		int i, found = NO;
    3.77  		for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
    3.78 @@ -163,6 +180,16 @@
    3.79  				found = YES;
    3.80  			}
    3.81  		}
    3.82 +		
    3.83 +		/* grab next touch */
    3.84 +		touch = (UITouch*)[enumerator nextObject]; 
    3.85 +	}
    3.86 +#else
    3.87 +	if (touch) {
    3.88 +		CGPoint locationInView = [touch locationInView: self];
    3.89 +
    3.90 +		/* send moved event */
    3.91 +		SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
    3.92  	}
    3.93  #endif
    3.94  }