Added Iphone support (untested)
authorJim Grandpre <jim.tla@gmail.com>
Mon, 12 Jul 2010 22:03:25 -0400
changeset 4660b15e7017409b
parent 4659 063b9455bd1a
child 4661 03dcb795c583
Added Iphone support (untested)
src/video/uikit/SDL_uikitview.h
src/video/uikit/SDL_uikitview.m
     1.1 --- a/src/video/uikit/SDL_uikitview.h	Sun Jul 11 01:15:39 2010 -0400
     1.2 +++ b/src/video/uikit/SDL_uikitview.h	Mon Jul 12 22:03:25 2010 -0400
     1.3 @@ -22,8 +22,6 @@
     1.4  
     1.5  #import <UIKit/UIKit.h>
     1.6  #include "SDL_stdinc.h"
     1.7 -#include "SDL_mouse.h"
     1.8 -#include "SDL_mouse_c.h"
     1.9  #include "SDL_events.h"
    1.10  
    1.11  #if SDL_IPHONE_MULTIPLE_MICE
    1.12 @@ -38,8 +36,14 @@
    1.13  #else
    1.14  @interface SDL_uikitview : UIView {
    1.15  #endif
    1.16 -		
    1.17 +
    1.18 +#if FIXME_MULTITOUCH
    1.19  	SDL_Mouse mice[MAX_SIMULTANEOUS_TOUCHES];
    1.20 +#endif
    1.21 +
    1.22 +#if FIXED_MULTITOUCH
    1.23 +	int touchId;
    1.24 +#endif
    1.25  
    1.26  #if SDL_IPHONE_KEYBOARD
    1.27  	UITextField *textField;
     2.1 --- a/src/video/uikit/SDL_uikitview.m	Sun Jul 11 01:15:39 2010 -0400
     2.2 +++ b/src/video/uikit/SDL_uikitview.m	Mon Jul 12 22:03:25 2010 -0400
     2.3 @@ -22,8 +22,10 @@
     2.4  
     2.5  #import "SDL_uikitview.h"
     2.6  
     2.7 +#include "../../events/SDL_keyboard_c.h"
     2.8 +#include "../../events/SDL_mouse_c.h"
     2.9 +
    2.10  #if SDL_IPHONE_KEYBOARD
    2.11 -#import "SDL_keyboard_c.h"
    2.12  #import "keyinfotable.h"
    2.13  #import "SDL_uikitappdelegate.h"
    2.14  #import "SDL_uikitwindow.h"
    2.15 @@ -33,7 +35,6 @@
    2.16  
    2.17  - (void)dealloc {
    2.18  #if SDL_IPHONE_KEYBOARD
    2.19 -	SDL_DelKeyboard(0);
    2.20  	[textField release];
    2.21  #endif
    2.22  	[super dealloc];
    2.23 @@ -47,6 +48,7 @@
    2.24  	[self initializeKeyboard];
    2.25  #endif	
    2.26  
    2.27 +#if FIXME_MULTITOUCH
    2.28  	int i;
    2.29  	for (i=0; i<MAX_SIMULTANEOUS_TOUCHES; i++) {
    2.30          mice[i].id = i;
    2.31 @@ -54,6 +56,27 @@
    2.32  		SDL_AddMouse(&mice[i], "Mouse", 0, 0, 1);
    2.33  	}
    2.34  	self.multipleTouchEnabled = YES;
    2.35 +#endif
    2.36 +#if FIXED_MULTITOUCH
    2.37 +	SDL_Touch touch;
    2.38 +	touch.id = 0; //TODO: Should be -1?
    2.39 +
    2.40 +	//touch.driverdata = SDL_malloc(sizeof(EventTouchData));
    2.41 +	//EventTouchData* data = (EventTouchData*)(touch.driverdata);
    2.42 +	
    2.43 +	touch.x_min = 0;
    2.44 +	touch.x_max = frame.size.width;
    2.45 +	touch.xres = touch.x_max - touch.x_min;
    2.46 +	touch.y_min = 0;
    2.47 +	touch.y_max = frame.size.height;
    2.48 +	touch.yres = touch.y_max - touch.y_min;
    2.49 +	touch.pressure_min = 0;
    2.50 +	touch.pressure_max = 1;
    2.51 +	touch.pressureres = touch.pressure_max - touch.pressure_min;
    2.52 +
    2.53 +
    2.54 +	touchId = SDL_AddTouch(&touch, "IPHONE SCREEN");
    2.55 +#endif
    2.56  			
    2.57  	return self;
    2.58  
    2.59 @@ -62,8 +85,9 @@
    2.60  - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    2.61  
    2.62  	NSEnumerator *enumerator = [touches objectEnumerator];
    2.63 -	UITouch *touch =(UITouch*)[enumerator nextObject];
    2.64 +	UITouch *touch = (UITouch*)[enumerator nextObject];
    2.65  	
    2.66 +#if FIXME_MULTITOUCH
    2.67  	/* associate touches with mice, so long as we have slots */
    2.68  	int i;
    2.69  	int found = 0;
    2.70 @@ -98,21 +122,43 @@
    2.71  		/* re-calibrate relative mouse motion */
    2.72  		SDL_GetRelativeMouseState(i, NULL, NULL);
    2.73  		
    2.74 -		/* grab next touch */
    2.75 -		touch = (UITouch*)[enumerator nextObject]; 
    2.76 -		
    2.77  		/* switch back to our old mouse */
    2.78  		SDL_SelectMouse(oldMouse);
    2.79  		
    2.80 -	}	
    2.81 +		/* grab next touch */
    2.82 +		touch = (UITouch*)[enumerator nextObject]; 
    2.83 +	}
    2.84 +#else
    2.85 +	if (touch) {
    2.86 +		CGPoint locationInView = [touch locationInView: self];
    2.87 +			
    2.88 +		/* send moved event */
    2.89 +		SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
    2.90 +
    2.91 +		/* send mouse down event */
    2.92 +		SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT);
    2.93 +	}
    2.94 +#endif
    2.95 +
    2.96 +#if FIXED_MULTITOUCH
    2.97 +	while(touch) {
    2.98 +	  CGPoint locationInView = [touch locationInView: self];
    2.99 +	  SDL_SendFingerDown(touchId,(int)touch,
   2.100 +			     SDL_TRUE,locationInView.x,locationInView.y,
   2.101 +			     1);
   2.102 +
   2.103 +	  touch = (UITouch*)[enumerator nextObject]; 
   2.104 +	}
   2.105 +#endif
   2.106  }
   2.107  
   2.108  - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   2.109  	
   2.110  	NSEnumerator *enumerator = [touches objectEnumerator];
   2.111 -	UITouch *touch=nil;
   2.112 +	UITouch *touch = (UITouch*)[enumerator nextObject];
   2.113  	
   2.114 -	while(touch = (UITouch *)[enumerator nextObject]) {
   2.115 +#if FIXME_MULTITOUCH
   2.116 +	while(touch) {
   2.117  		/* search for the mouse slot associated with this touch */
   2.118  		int i, found = NO;
   2.119  		for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
   2.120 @@ -126,7 +172,26 @@
   2.121  				found = YES;
   2.122  			}
   2.123  		}
   2.124 +		
   2.125 +		/* grab next touch */
   2.126 +		touch = (UITouch*)[enumerator nextObject]; 
   2.127  	}
   2.128 +#else
   2.129 +	if (touch) {
   2.130 +		/* send mouse up */
   2.131 +		SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT);
   2.132 +	}
   2.133 +#endif
   2.134 +#if FIXED_MULTITOUCH
   2.135 +	while(touch) {
   2.136 +	  CGPoint locationInView = [touch locationInView: self];
   2.137 +	  SDL_SendFingerDown(touchId,(int)touch,
   2.138 +			     SDL_FALSE,locationInView.x,locationInView.y,
   2.139 +			     1);
   2.140 +
   2.141 +	  touch = (UITouch*)[enumerator nextObject]; 
   2.142 +	}
   2.143 +#endif
   2.144  }
   2.145  
   2.146  - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
   2.147 @@ -141,9 +206,10 @@
   2.148  - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
   2.149  	
   2.150  	NSEnumerator *enumerator = [touches objectEnumerator];
   2.151 -	UITouch *touch=nil;
   2.152 +	UITouch *touch = (UITouch*)[enumerator nextObject];
   2.153  	
   2.154 -	while(touch = (UITouch *)[enumerator nextObject]) {
   2.155 +#if FIXME_MULTITOUCH
   2.156 +	while(touch) {
   2.157  		/* try to find the mouse associated with this touch */
   2.158  		int i, found = NO;
   2.159  		for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) {
   2.160 @@ -156,7 +222,29 @@
   2.161  				found = YES;
   2.162  			}
   2.163  		}
   2.164 +		
   2.165 +		/* grab next touch */
   2.166 +		touch = (UITouch*)[enumerator nextObject]; 
   2.167  	}
   2.168 +#else
   2.169 +	if (touch) {
   2.170 +		CGPoint locationInView = [touch locationInView: self];
   2.171 +
   2.172 +		/* send moved event */
   2.173 +		SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y);
   2.174 +	}
   2.175 +#endif
   2.176 +
   2.177 +#if FIXED_MULTITOUCH
   2.178 +	while(touch) {
   2.179 +	  CGPoint locationInView = [touch locationInView: self];
   2.180 +	  SDL_SendTouchMotion(touchId,(int)touch,
   2.181 +			     SDL_FALSE,locationInView.x,locationInView.y,
   2.182 +			     1);
   2.183 +
   2.184 +	  touch = (UITouch*)[enumerator nextObject]; 
   2.185 +	}
   2.186 +#endif
   2.187  }
   2.188  
   2.189  /*
   2.190 @@ -190,15 +278,6 @@
   2.191  	keyboardVisible = NO;
   2.192  	/* add the UITextField (hidden) to our view */
   2.193  	[self addSubview: textField];
   2.194 -	
   2.195 -	/* create our SDL_Keyboard */
   2.196 -	SDL_Keyboard keyboard;
   2.197 -	SDL_zero(keyboard);
   2.198 -	SDL_AddKeyboard(&keyboard, 0);
   2.199 -	SDLKey keymap[SDL_NUM_SCANCODES];
   2.200 -	SDL_GetDefaultKeymap(keymap);
   2.201 -	SDL_SetKeymap(0, 0, keymap, SDL_NUM_SCANCODES);
   2.202 -	
   2.203  }
   2.204  
   2.205  /* reveal onscreen virtual keyboard */
   2.206 @@ -218,8 +297,8 @@
   2.207  	
   2.208  	if ([string length] == 0) {
   2.209  		/* it wants to replace text with nothing, ie a delete */
   2.210 -		SDL_SendKeyboardKey( 0, SDL_PRESSED, SDL_SCANCODE_DELETE);
   2.211 -		SDL_SendKeyboardKey( 0, SDL_RELEASED, SDL_SCANCODE_DELETE);
   2.212 +		SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_DELETE);
   2.213 +		SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_DELETE);
   2.214  	}
   2.215  	else {
   2.216  		/* go through all the characters in the string we've been sent
   2.217 @@ -245,14 +324,14 @@
   2.218  			
   2.219  			if (mod & KMOD_SHIFT) {
   2.220  				/* If character uses shift, press shift down */
   2.221 -				SDL_SendKeyboardKey( 0, SDL_PRESSED, SDL_SCANCODE_LSHIFT);
   2.222 +				SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LSHIFT);
   2.223  			}
   2.224  			/* send a keydown and keyup even for the character */
   2.225 -			SDL_SendKeyboardKey( 0, SDL_PRESSED, code);
   2.226 -			SDL_SendKeyboardKey( 0, SDL_RELEASED, code);
   2.227 +			SDL_SendKeyboardKey(SDL_PRESSED, code);
   2.228 +			SDL_SendKeyboardKey(SDL_RELEASED, code);
   2.229  			if (mod & KMOD_SHIFT) {
   2.230  				/* If character uses shift, press shift back up */
   2.231 -				SDL_SendKeyboardKey( 0, SDL_RELEASED, SDL_SCANCODE_LSHIFT);
   2.232 +				SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT);
   2.233  			}			
   2.234  		}
   2.235  	}