Updated iPhone keyboard code (which builds and runs on the iPad and iPhone simulator now)
authorSam Lantinga <slouken@libsdl.org>
Wed, 07 Jul 2010 18:58:51 -0700
changeset 449006c7423f8c60
parent 4489 2bb1bfeee9e2
child 4491 2cd7bb613a83
Updated iPhone keyboard code (which builds and runs on the iPad and iPhone simulator now)
Updated iPhone demos (which build and run again)
Xcode-iPhoneOS/Demos/DemosiPhoneOS.xcodeproj/project.pbxproj
Xcode-iPhoneOS/Demos/src/fireworks.c
Xcode-iPhoneOS/Demos/src/mixer.c
Xcode-iPhoneOS/Demos/src/touch.c
Xcode-iPhoneOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj
include/SDL_config_iphoneos.h
src/events/SDL_keyboard.c
src/video/uikit/SDL_uikitopengles.m
src/video/uikit/SDL_uikitview.h
src/video/uikit/SDL_uikitview.m
     1.1 --- a/Xcode-iPhoneOS/Demos/DemosiPhoneOS.xcodeproj/project.pbxproj	Tue Jul 06 22:26:03 2010 -0700
     1.2 +++ b/Xcode-iPhoneOS/Demos/DemosiPhoneOS.xcodeproj/project.pbxproj	Wed Jul 07 18:58:51 2010 -0700
     1.3 @@ -105,6 +105,13 @@
     1.4  /* End PBXBuildFile section */
     1.5  
     1.6  /* Begin PBXContainerItemProxy section */
     1.7 +		04AB757011E563D200BE9753 /* PBXContainerItemProxy */ = {
     1.8 +			isa = PBXContainerItemProxy;
     1.9 +			containerPortal = FD1B48920E313154007AB34E /* SDLiPhoneOS.xcodeproj */;
    1.10 +			proxyType = 2;
    1.11 +			remoteGlobalIDString = 006E982211955059001DE610 /* testsdl.app */;
    1.12 +			remoteInfo = testsdl;
    1.13 +		};
    1.14  		FD1B489D0E313154007AB34E /* PBXContainerItemProxy */ = {
    1.15  			isa = PBXContainerItemProxy;
    1.16  			containerPortal = FD1B48920E313154007AB34E /* SDLiPhoneOS.xcodeproj */;
    1.17 @@ -318,6 +325,7 @@
    1.18  			isa = PBXGroup;
    1.19  			children = (
    1.20  				FD1B489E0E313154007AB34E /* libSDLiPhoneOS.a */,
    1.21 +				04AB757111E563D200BE9753 /* testsdl.app */,
    1.22  			);
    1.23  			name = Products;
    1.24  			sourceTree = "<group>";
    1.25 @@ -523,6 +531,13 @@
    1.26  /* End PBXProject section */
    1.27  
    1.28  /* Begin PBXReferenceProxy section */
    1.29 +		04AB757111E563D200BE9753 /* testsdl.app */ = {
    1.30 +			isa = PBXReferenceProxy;
    1.31 +			fileType = wrapper.application;
    1.32 +			path = testsdl.app;
    1.33 +			remoteRef = 04AB757011E563D200BE9753 /* PBXContainerItemProxy */;
    1.34 +			sourceTree = BUILT_PRODUCTS_DIR;
    1.35 +		};
    1.36  		FD1B489E0E313154007AB34E /* libSDLiPhoneOS.a */ = {
    1.37  			isa = PBXReferenceProxy;
    1.38  			fileType = archive.ar;
    1.39 @@ -731,7 +746,7 @@
    1.40  				OTHER_CFLAGS = "";
    1.41  				PREBINDING = NO;
    1.42  				PRELINK_LIBS = "";
    1.43 -				SDKROOT = iphoneos2.0;
    1.44 +				SDKROOT = iphoneos3.2;
    1.45  			};
    1.46  			name = Debug;
    1.47  		};
    1.48 @@ -749,7 +764,7 @@
    1.49  				OTHER_CFLAGS = "";
    1.50  				PREBINDING = NO;
    1.51  				PRELINK_LIBS = "";
    1.52 -				SDKROOT = iphoneos2.0;
    1.53 +				SDKROOT = iphoneos3.2;
    1.54  			};
    1.55  			name = Release;
    1.56  		};
     2.1 --- a/Xcode-iPhoneOS/Demos/src/fireworks.c	Tue Jul 06 22:26:03 2010 -0700
     2.2 +++ b/Xcode-iPhoneOS/Demos/src/fireworks.c	Wed Jul 07 18:58:51 2010 -0700
     2.3 @@ -430,9 +430,7 @@
     2.4                  done = 1;
     2.5              }
     2.6              if (event.type == SDL_MOUSEBUTTONDOWN) {
     2.7 -                int which = event.button.which;
     2.8                  int x, y;
     2.9 -                SDL_SelectMouse(which);
    2.10                  SDL_GetMouseState(&x, &y);
    2.11                  spawnEmitterParticle(x, y);
    2.12              }
     3.1 --- a/Xcode-iPhoneOS/Demos/src/mixer.c	Tue Jul 06 22:26:03 2010 -0700
     3.2 +++ b/Xcode-iPhoneOS/Demos/src/mixer.c	Wed Jul 07 18:58:51 2010 -0700
     3.3 @@ -124,10 +124,9 @@
     3.4  
     3.5      int x, y, mouseIndex, i, drumIndex;
     3.6  
     3.7 -    mouseIndex = event->button.which;
     3.8 +    mouseIndex = 0;
     3.9      drumIndex = -1;
    3.10  
    3.11 -    SDL_SelectMouse(mouseIndex);
    3.12      SDL_GetMouseState(&x, &y);
    3.13      /* check if we hit any of the drum buttons */
    3.14      for (i = 0; i < NUM_DRUMS; i++) {
    3.15 @@ -153,7 +152,7 @@
    3.16  handleMouseButtonUp(SDL_Event * event)
    3.17  {
    3.18      int i;
    3.19 -    int mouseIndex = event->button.which;
    3.20 +    int mouseIndex = 0;
    3.21      /* check if this should cause any of the buttons to become unpressed */
    3.22      for (i = 0; i < NUM_DRUMS; i++) {
    3.23          if (buttons[i].touchIndex == mouseIndex) {
     4.1 --- a/Xcode-iPhoneOS/Demos/src/touch.c	Tue Jul 06 22:26:03 2010 -0700
     4.2 +++ b/Xcode-iPhoneOS/Demos/src/touch.c	Wed Jul 07 18:58:51 2010 -0700
     4.3 @@ -106,7 +106,6 @@
     4.4              done = 1;
     4.5              break;
     4.6          case SDL_MOUSEMOTION:
     4.7 -            SDL_SelectMouse(event.motion.which);        /* select 'mouse' (touch) that moved */
     4.8              state = SDL_GetMouseState(&x, &y);  /* get its location */
     4.9              SDL_GetRelativeMouseState(&dx, &dy);        /* find how much the mouse moved */
    4.10              if (state & SDL_BUTTON_LMASK) {     /* is the mouse (touch) down? */
     5.1 --- a/Xcode-iPhoneOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj	Tue Jul 06 22:26:03 2010 -0700
     5.2 +++ b/Xcode-iPhoneOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj	Wed Jul 07 18:58:51 2010 -0700
     5.3 @@ -287,6 +287,13 @@
     5.4  /* End PBXBuildFile section */
     5.5  
     5.6  /* Begin PBXContainerItemProxy section */
     5.7 +		0466EE6F11E565E4000198A4 /* PBXContainerItemProxy */ = {
     5.8 +			isa = PBXContainerItemProxy;
     5.9 +			containerPortal = FD1B48AC0E3131CA007AB34E /* SDLiPhoneOS.xcodeproj */;
    5.10 +			proxyType = 2;
    5.11 +			remoteGlobalIDString = 006E982211955059001DE610 /* testsdl.app */;
    5.12 +			remoteInfo = testsdl;
    5.13 +		};
    5.14  		FD1B48B70E3131CA007AB34E /* PBXContainerItemProxy */ = {
    5.15  			isa = PBXContainerItemProxy;
    5.16  			containerPortal = FD1B48AC0E3131CA007AB34E /* SDLiPhoneOS.xcodeproj */;
    5.17 @@ -298,9 +305,7 @@
    5.18  
    5.19  /* Begin PBXFileReference section */
    5.20  		1D6058910D05DD3D006BFB54 /* testwm2.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = testwm2.app; sourceTree = BUILT_PRODUCTS_DIR; };
    5.21 -		56ED04F7118A8FCC00A56AA6 /* testpower-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "testpower-Info.plist"; sourceTree = "<group>"; };
    5.22  		56ED050D118A8FE400A56AA6 /* testpower.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = testpower.app; sourceTree = BUILT_PRODUCTS_DIR; };
    5.23 -		56ED050F118A8FE400A56AA6 /* Info copy.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info copy.plist"; sourceTree = "<group>"; };
    5.24  		56ED0510118A904200A56AA6 /* testpower.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testpower.c; path = ../../test/testpower.c; sourceTree = SOURCE_ROOT; };
    5.25  		FD1B48AC0E3131CA007AB34E /* SDLiPhoneOS.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SDLiPhoneOS.xcodeproj; path = ../SDL/SDLiPhoneOS.xcodeproj; sourceTree = SOURCE_ROOT; };
    5.26  		FDA8A7400E2D0F1600EA573E /* testalpha.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testalpha.c; path = ../../test/testalpha.c; sourceTree = SOURCE_ROOT; };
    5.27 @@ -861,14 +866,11 @@
    5.28  		29B97314FDCFA39411CA2CEA /* CustomTemplate */ = {
    5.29  			isa = PBXGroup;
    5.30  			children = (
    5.31 -				56ED0510118A904200A56AA6 /* testpower.c */,
    5.32  				FD1B48AC0E3131CA007AB34E /* SDLiPhoneOS.xcodeproj */,
    5.33  				FDA8AAD60E2D339A00EA573E /* Resources */,
    5.34  				FDA8A7C30E2D10FA00EA573E /* Linked Frameworks */,
    5.35  				FDA8A73B0E2D0F0400EA573E /* src */,
    5.36  				19C28FACFE9D520D11CA2CBB /* Products */,
    5.37 -				56ED04F7118A8FCC00A56AA6 /* testpower-Info.plist */,
    5.38 -				56ED050F118A8FE400A56AA6 /* Info copy.plist */,
    5.39  			);
    5.40  			name = CustomTemplate;
    5.41  			sourceTree = "<group>";
    5.42 @@ -877,6 +879,7 @@
    5.43  			isa = PBXGroup;
    5.44  			children = (
    5.45  				FD1B48B80E3131CA007AB34E /* libSDLiPhoneOS.a */,
    5.46 +				0466EE7011E565E4000198A4 /* testsdl.app */,
    5.47  			);
    5.48  			name = Products;
    5.49  			sourceTree = "<group>";
    5.50 @@ -910,6 +913,7 @@
    5.51  				FDA8A7540E2D0F1600EA573E /* testoverlay2.c */,
    5.52  				FDA8A7550E2D0F1600EA573E /* testpalette.c */,
    5.53  				FDA8A7560E2D0F1600EA573E /* testplatform.c */,
    5.54 +				56ED0510118A904200A56AA6 /* testpower.c */,
    5.55  				FDA8A7570E2D0F1600EA573E /* testsem.c */,
    5.56  				FDA8A7580E2D0F1600EA573E /* testsprite.c */,
    5.57  				FDA8A7590E2D0F1600EA573E /* testsprite2.c */,
    5.58 @@ -1502,6 +1506,13 @@
    5.59  /* End PBXProject section */
    5.60  
    5.61  /* Begin PBXReferenceProxy section */
    5.62 +		0466EE7011E565E4000198A4 /* testsdl.app */ = {
    5.63 +			isa = PBXReferenceProxy;
    5.64 +			fileType = wrapper.application;
    5.65 +			path = testsdl.app;
    5.66 +			remoteRef = 0466EE6F11E565E4000198A4 /* PBXContainerItemProxy */;
    5.67 +			sourceTree = BUILT_PRODUCTS_DIR;
    5.68 +		};
    5.69  		FD1B48B80E3131CA007AB34E /* libSDLiPhoneOS.a */ = {
    5.70  			isa = PBXReferenceProxy;
    5.71  			fileType = archive.ar;
    5.72 @@ -2034,7 +2045,7 @@
    5.73  				ONLY_ACTIVE_ARCH = YES;
    5.74  				PREBINDING = NO;
    5.75  				"PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
    5.76 -				SDKROOT = iphoneos2.2.1;
    5.77 +				SDKROOT = iphoneos3.2;
    5.78  			};
    5.79  			name = Debug;
    5.80  		};
    5.81 @@ -2049,7 +2060,7 @@
    5.82  				HEADER_SEARCH_PATHS = ../../include;
    5.83  				PREBINDING = NO;
    5.84  				"PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
    5.85 -				SDKROOT = iphoneos2.2.1;
    5.86 +				SDKROOT = iphoneos3.2;
    5.87  			};
    5.88  			name = Release;
    5.89  		};
     6.1 --- a/include/SDL_config_iphoneos.h	Tue Jul 06 22:26:03 2010 -0700
     6.2 +++ b/include/SDL_config_iphoneos.h	Wed Jul 07 18:58:51 2010 -0700
     6.3 @@ -145,12 +145,9 @@
     6.4  #define SDL_POWER_UIKIT 1
     6.5  
     6.6  /* enable iPhone keyboard support */
     6.7 -#define SDL_IPHONE_KEYBOARD 0
     6.8 +#define SDL_IPHONE_KEYBOARD 1
     6.9  
    6.10 -/* Enable emulation of multiple mice through multi-touch */
    6.11 -#define SDL_IPHONE_MULTIPLE_MICE 1
    6.12 -
    6.13 -/* Set max recognized G-force from acceleromter
    6.14 +/* Set max recognized G-force from accelerometer
    6.15     See src/joystick/uikit/SDLUIAccelerationDelegate.m for notes on why this is needed
    6.16   */
    6.17  #define SDL_IPHONE_MAX_GFORCE 5.0
     7.1 --- a/src/events/SDL_keyboard.c	Tue Jul 06 22:26:03 2010 -0700
     7.2 +++ b/src/events/SDL_keyboard.c	Wed Jul 07 18:58:51 2010 -0700
     7.3 @@ -551,6 +551,10 @@
     7.4  int
     7.5  SDL_KeyboardInit(void)
     7.6  {
     7.7 +    SDL_Keyboard *keyboard = &SDL_keyboard;
     7.8 +
     7.9 +    /* Set the default keymap */
    7.10 +    SDL_memcpy(keyboard->keymap, SDL_default_keymap, sizeof(SDL_default_keymap));
    7.11      return (0);
    7.12  }
    7.13  
     8.1 --- a/src/video/uikit/SDL_uikitopengles.m	Tue Jul 06 22:26:03 2010 -0700
     8.2 +++ b/src/video/uikit/SDL_uikitopengles.m	Wed Jul 07 18:58:51 2010 -0700
     8.3 @@ -26,6 +26,8 @@
     8.4  #include "SDL_uikitwindow.h"
     8.5  #include "jumphack.h"
     8.6  #include "SDL_sysvideo.h"
     8.7 +#include "../../events/SDL_keyboard_c.h"
     8.8 +#include "../../events/SDL_mouse_c.h"
     8.9  #include "SDL_loadso.h"
    8.10  #include <dlfcn.h>
    8.11  
    8.12 @@ -128,6 +130,7 @@
    8.13  
    8.14  	/* Make this window the current mouse focus for touch input */
    8.15  	SDL_SetMouseFocus(window);
    8.16 +	SDL_SetKeyboardFocus(window);
    8.17  
    8.18  	return view;
    8.19  }
     9.1 --- a/src/video/uikit/SDL_uikitview.h	Tue Jul 06 22:26:03 2010 -0700
     9.2 +++ b/src/video/uikit/SDL_uikitview.h	Wed Jul 07 18:58:51 2010 -0700
     9.3 @@ -22,8 +22,6 @@
     9.4  
     9.5  #import <UIKit/UIKit.h>
     9.6  #include "SDL_stdinc.h"
     9.7 -#include "SDL_mouse.h"
     9.8 -#include "SDL_mouse_c.h"
     9.9  #include "SDL_events.h"
    9.10  
    9.11  #if SDL_IPHONE_MULTIPLE_MICE
    10.1 --- a/src/video/uikit/SDL_uikitview.m	Tue Jul 06 22:26:03 2010 -0700
    10.2 +++ b/src/video/uikit/SDL_uikitview.m	Wed Jul 07 18:58:51 2010 -0700
    10.3 @@ -22,8 +22,10 @@
    10.4  
    10.5  #import "SDL_uikitview.h"
    10.6  
    10.7 +#include "../../events/SDL_keyboard_c.h"
    10.8 +#include "../../events/SDL_mouse_c.h"
    10.9 +
   10.10  #if SDL_IPHONE_KEYBOARD
   10.11 -#import "SDL_keyboard_c.h"
   10.12  #import "keyinfotable.h"
   10.13  #import "SDL_uikitappdelegate.h"
   10.14  #import "SDL_uikitwindow.h"
   10.15 @@ -33,7 +35,6 @@
   10.16  
   10.17  - (void)dealloc {
   10.18  #if SDL_IPHONE_KEYBOARD
   10.19 -	SDL_DelKeyboard(0);
   10.20  	[textField release];
   10.21  #endif
   10.22  	[super dealloc];
   10.23 @@ -225,15 +226,6 @@
   10.24  	keyboardVisible = NO;
   10.25  	/* add the UITextField (hidden) to our view */
   10.26  	[self addSubview: textField];
   10.27 -	
   10.28 -	/* create our SDL_Keyboard */
   10.29 -	SDL_Keyboard keyboard;
   10.30 -	SDL_zero(keyboard);
   10.31 -	SDL_AddKeyboard(&keyboard, 0);
   10.32 -	SDLKey keymap[SDL_NUM_SCANCODES];
   10.33 -	SDL_GetDefaultKeymap(keymap);
   10.34 -	SDL_SetKeymap(0, 0, keymap, SDL_NUM_SCANCODES);
   10.35 -	
   10.36  }
   10.37  
   10.38  /* reveal onscreen virtual keyboard */
   10.39 @@ -253,8 +245,8 @@
   10.40  	
   10.41  	if ([string length] == 0) {
   10.42  		/* it wants to replace text with nothing, ie a delete */
   10.43 -		SDL_SendKeyboardKey( 0, SDL_PRESSED, SDL_SCANCODE_DELETE);
   10.44 -		SDL_SendKeyboardKey( 0, SDL_RELEASED, SDL_SCANCODE_DELETE);
   10.45 +		SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_DELETE);
   10.46 +		SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_DELETE);
   10.47  	}
   10.48  	else {
   10.49  		/* go through all the characters in the string we've been sent
   10.50 @@ -280,14 +272,14 @@
   10.51  			
   10.52  			if (mod & KMOD_SHIFT) {
   10.53  				/* If character uses shift, press shift down */
   10.54 -				SDL_SendKeyboardKey( 0, SDL_PRESSED, SDL_SCANCODE_LSHIFT);
   10.55 +				SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LSHIFT);
   10.56  			}
   10.57  			/* send a keydown and keyup even for the character */
   10.58 -			SDL_SendKeyboardKey( 0, SDL_PRESSED, code);
   10.59 -			SDL_SendKeyboardKey( 0, SDL_RELEASED, code);
   10.60 +			SDL_SendKeyboardKey(SDL_PRESSED, code);
   10.61 +			SDL_SendKeyboardKey(SDL_RELEASED, code);
   10.62  			if (mod & KMOD_SHIFT) {
   10.63  				/* If character uses shift, press shift back up */
   10.64 -				SDL_SendKeyboardKey( 0, SDL_RELEASED, SDL_SCANCODE_LSHIFT);
   10.65 +				SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT);
   10.66  			}			
   10.67  		}
   10.68  	}