src/video/uikit/SDL_uikitview.m
changeset 4694 c24ba2cc9583
parent 4565 e2d46c5c7483
parent 4678 f8431f66613d
child 5051 a69e36365766
     1.1 --- a/src/video/uikit/SDL_uikitview.m	Sun Aug 22 11:56:07 2010 -0700
     1.2 +++ b/src/video/uikit/SDL_uikitview.m	Sun Aug 22 12:07:55 2010 -0700
     1.3 @@ -24,6 +24,7 @@
     1.4  
     1.5  #include "../../events/SDL_keyboard_c.h"
     1.6  #include "../../events/SDL_mouse_c.h"
     1.7 +#include "../../events/SDL_touch_c.h"
     1.8  
     1.9  #if SDL_IPHONE_KEYBOARD
    1.10  #import "keyinfotable.h"
    1.11 @@ -48,16 +49,27 @@
    1.12  	[self initializeKeyboard];
    1.13  #endif	
    1.14  
    1.15 -#if FIXME_MULTITOUCH
    1.16 -	int i;
    1.17 -	for (i=0; i<MAX_SIMULTANEOUS_TOUCHES; i++) {
    1.18 -        mice[i].id = i;
    1.19 -		mice[i].driverdata = NULL;
    1.20 -		SDL_AddMouse(&mice[i], "Mouse", 0, 0, 1);
    1.21 -	}
    1.22 -	self.multipleTouchEnabled = YES;
    1.23 +#ifdef FIXED_MULTITOUCH
    1.24 +	SDL_Touch touch;
    1.25 +	touch.id = 0; //TODO: Should be -1?
    1.26 +
    1.27 +	//touch.driverdata = SDL_malloc(sizeof(EventTouchData));
    1.28 +	//EventTouchData* data = (EventTouchData*)(touch.driverdata);
    1.29 +	
    1.30 +	touch.x_min = 0;
    1.31 +	touch.x_max = frame.size.width;
    1.32 +	touch.native_xres = touch.x_max - touch.x_min;
    1.33 +	touch.y_min = 0;
    1.34 +	touch.y_max = frame.size.height;
    1.35 +	touch.native_yres = touch.y_max - touch.y_min;
    1.36 +	touch.pressure_min = 0;
    1.37 +	touch.pressure_max = 1;
    1.38 +	touch.native_pressureres = touch.pressure_max - touch.pressure_min;
    1.39 +
    1.40 +
    1.41 +	touchId = SDL_AddTouch(&touch, "IPHONE SCREEN");
    1.42  #endif
    1.43 -			
    1.44 +
    1.45  	return self;
    1.46  
    1.47  }
    1.48 @@ -67,48 +79,8 @@
    1.49  	NSEnumerator *enumerator = [touches objectEnumerator];
    1.50  	UITouch *touch = (UITouch*)[enumerator nextObject];
    1.51  	
    1.52 -#if FIXME_MULTITOUCH
    1.53 -	/* associate touches with mice, so long as we have slots */
    1.54 -	int i;
    1.55 -	int found = 0;
    1.56 -	for(i=0; touch && i < MAX_SIMULTANEOUS_TOUCHES; i++) {
    1.57 +	//NSLog("Click");
    1.58  	
    1.59 -		/* check if this mouse is already tracking a touch */
    1.60 -		if (mice[i].driverdata != NULL) {
    1.61 -			continue;
    1.62 -		}
    1.63 -		/*	
    1.64 -			mouse not associated with anything right now,
    1.65 -			associate the touch with this mouse
    1.66 -		*/
    1.67 -		found = 1;
    1.68 -		
    1.69 -		/* save old mouse so we can switch back */
    1.70 -		int oldMouse = SDL_SelectMouse(-1);
    1.71 -		
    1.72 -		/* select this slot's mouse */
    1.73 -		SDL_SelectMouse(i);
    1.74 -		CGPoint locationInView = [touch locationInView: self];
    1.75 -		
    1.76 -		/* set driver data to touch object, we'll use touch object later */
    1.77 -		mice[i].driverdata = [touch retain];
    1.78 -		
    1.79 -		/* send moved event */
    1.80 -		SDL_SendMouseMotion(i, 0, locationInView.x, locationInView.y, 0);
    1.81 -		
    1.82 -		/* send mouse down event */
    1.83 -		SDL_SendMouseButton(i, SDL_PRESSED, SDL_BUTTON_LEFT);
    1.84 -		
    1.85 -		/* re-calibrate relative mouse motion */
    1.86 -		SDL_GetRelativeMouseState(i, NULL, NULL);
    1.87 -		
    1.88 -		/* switch back to our old mouse */
    1.89 -		SDL_SelectMouse(oldMouse);
    1.90 -		
    1.91 -		/* grab next touch */
    1.92 -		touch = (UITouch*)[enumerator nextObject]; 
    1.93 -	}
    1.94 -#else
    1.95  	if (touch) {
    1.96  		CGPoint locationInView = [touch locationInView: self];
    1.97  			
    1.98 @@ -118,6 +90,37 @@
    1.99  		/* send mouse down event */
   1.100  		SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT);
   1.101  	}
   1.102 +
   1.103 +#ifdef FIXED_MULTITOUCH
   1.104 +	while(touch) {
   1.105 +	  CGPoint locationInView = [touch locationInView: self];
   1.106 +
   1.107 +
   1.108 +#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
   1.109 +	  //FIXME: TODO: Using touch as the fingerId is potentially dangerous
   1.110 +	  //It is also much more efficient than storing the UITouch pointer
   1.111 +	  //and comparing it to the incoming event.
   1.112 +	  SDL_SendFingerDown(touchId,(long)touch,
   1.113 +			     SDL_TRUE,locationInView.x,locationInView.y,
   1.114 +			     1);
   1.115 +#else
   1.116 +	  int i;
   1.117 +	  for(i = 0;i < MAX_SIMULTANEOUS_TOUCHES;i++) {
   1.118 +	    if(finger[i] == NULL) {
   1.119 +	      finger[i] = touch;
   1.120 +	      SDL_SendFingerDown(touchId,i,
   1.121 +				 SDL_TRUE,locationInView.x,locationInView.y,
   1.122 +				 1);
   1.123 +	      break;
   1.124 +	    }
   1.125 +	  }
   1.126 +#endif
   1.127 +	  
   1.128 +
   1.129 +	  
   1.130 +
   1.131 +	  touch = (UITouch*)[enumerator nextObject]; 
   1.132 +	}
   1.133  #endif
   1.134  }
   1.135  
   1.136 @@ -126,30 +129,34 @@
   1.137  	NSEnumerator *enumerator = [touches objectEnumerator];
   1.138  	UITouch *touch = (UITouch*)[enumerator nextObject];
   1.139  	
   1.140 -#if FIXME_MULTITOUCH
   1.141 -	while(touch) {
   1.142 -		/* search for the mouse slot associated with this touch */
   1.143 -		int i, found = NO;
   1.144 -		for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
   1.145 -			if (mice[i].driverdata == touch) {
   1.146 -				/* found the mouse associate with the touch */
   1.147 -				[(UITouch*)(mice[i].driverdata) release];
   1.148 -				mice[i].driverdata = NULL;
   1.149 -				/* send mouse up */
   1.150 -				SDL_SendMouseButton(i, SDL_RELEASED, SDL_BUTTON_LEFT);
   1.151 -				/* discontinue search for this touch */
   1.152 -				found = YES;
   1.153 -			}
   1.154 -		}
   1.155 -		
   1.156 -		/* grab next touch */
   1.157 -		touch = (UITouch*)[enumerator nextObject]; 
   1.158 -	}
   1.159 -#else
   1.160  	if (touch) {
   1.161  		/* send mouse up */
   1.162  		SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT);
   1.163  	}
   1.164 +
   1.165 +#ifdef FIXED_MULTITOUCH
   1.166 +	while(touch) {
   1.167 +	  CGPoint locationInView = [touch locationInView: self];
   1.168 +	  
   1.169 +
   1.170 +#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
   1.171 +	  SDL_SendFingerDown(touchId,(long)touch,
   1.172 +			     SDL_FALSE,locationInView.x,locationInView.y,
   1.173 +			     1);
   1.174 +#else
   1.175 +	  int i;
   1.176 +	  for(i = 0;i < MAX_SIMULTANEOUS_TOUCHES;i++) {
   1.177 +	    if(finger[i] == touch) {
   1.178 +	      SDL_SendFingerDown(touchId,i,
   1.179 +				 SDL_FALSE,locationInView.x,locationInView.y,
   1.180 +				 1);
   1.181 +	      break;
   1.182 +	    }
   1.183 +	  }
   1.184 +#endif
   1.185 +
   1.186 +	  touch = (UITouch*)[enumerator nextObject]; 
   1.187 +	}
   1.188  #endif
   1.189  }
   1.190  
   1.191 @@ -167,31 +174,36 @@
   1.192  	NSEnumerator *enumerator = [touches objectEnumerator];
   1.193  	UITouch *touch = (UITouch*)[enumerator nextObject];
   1.194  	
   1.195 -#if FIXME_MULTITOUCH
   1.196 -	while(touch) {
   1.197 -		/* try to find the mouse associated with this touch */
   1.198 -		int i, found = NO;
   1.199 -		for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
   1.200 -			if (mice[i].driverdata == touch) {
   1.201 -				/* found proper mouse */
   1.202 -				CGPoint locationInView = [touch locationInView: self];
   1.203 -				/* send moved event */
   1.204 -				SDL_SendMouseMotion(i, 0, locationInView.x, locationInView.y, 0);
   1.205 -				/* discontinue search */
   1.206 -				found = YES;
   1.207 -			}
   1.208 -		}
   1.209 -		
   1.210 -		/* grab next touch */
   1.211 -		touch = (UITouch*)[enumerator nextObject]; 
   1.212 -	}
   1.213 -#else
   1.214  	if (touch) {
   1.215  		CGPoint locationInView = [touch locationInView: self];
   1.216  
   1.217  		/* send moved event */
   1.218  		SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
   1.219  	}
   1.220 +
   1.221 +#ifdef FIXED_MULTITOUCH
   1.222 +	while(touch) {
   1.223 +	  CGPoint locationInView = [touch locationInView: self];
   1.224 +	  
   1.225 +
   1.226 +#ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS
   1.227 +	  SDL_SendTouchMotion(touchId,(long)touch,
   1.228 +			      SDL_FALSE,locationInView.x,locationInView.y,
   1.229 +			      1);
   1.230 +#else
   1.231 +	  int i;
   1.232 +	  for(i = 0;i < MAX_SIMULTANEOUS_TOUCHES;i++) {
   1.233 +	    if(finger[i] == touch) {
   1.234 +	      SDL_SendTouchMotion(touchId,i,
   1.235 +				  SDL_FALSE,locationInView.x,locationInView.y,
   1.236 +				  1);
   1.237 +	      break;
   1.238 +	    }
   1.239 +	  }
   1.240 +#endif
   1.241 +
   1.242 +	  touch = (UITouch*)[enumerator nextObject]; 
   1.243 +	}
   1.244  #endif
   1.245  }
   1.246