# HG changeset patch # User Holmes Futrell # Date 1218845792 0 # Node ID 96124abbcede225ac8532facc74f7626d8fe34bf # Parent 4a07dc228e93f13c9a3ceb6a1f94d380a63f26c6 Added comments, view now deletes keyboard upon dealloc, function declarations for iPhone keyboard additions now moved to SDL_uikitkeyboard.h. diff -r 4a07dc228e93 -r 96124abbcede src/video/uikit/SDL_uikitview.h --- a/src/video/uikit/SDL_uikitview.h Sat Aug 16 00:14:35 2008 +0000 +++ b/src/video/uikit/SDL_uikitview.h Sat Aug 16 00:16:32 2008 +0000 @@ -53,11 +53,4 @@ @property (readonly) BOOL keyboardVisible; #endif -@end - -#if SDL_IPHONE_KEYBOARD -extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardShow(SDL_WindowID windowID); -extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardHide(SDL_WindowID windowID); -extern DECLSPEC SDL_bool SDLCALL SDL_iPhoneKeyboardIsShown(SDL_WindowID windowID); -extern DECLSPEC int SDLCALL SDL_iPhoneKeyboardToggle(SDL_WindowID windowID); -#endif +@end \ No newline at end of file diff -r 4a07dc228e93 -r 96124abbcede src/video/uikit/SDL_uikitview.m --- a/src/video/uikit/SDL_uikitview.m Sat Aug 16 00:14:35 2008 +0000 +++ b/src/video/uikit/SDL_uikitview.m Sat Aug 16 00:16:32 2008 +0000 @@ -33,6 +33,7 @@ - (void)dealloc { #if SDL_IPHONE_KEYBOARD + SDL_DelKeyboard(0); [textField release]; #endif [super dealloc]; @@ -60,29 +61,46 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSEnumerator *enumerator = [touches objectEnumerator]; - UITouch *touch=(UITouch*)[enumerator nextObject]; + UITouch *touch =(UITouch*)[enumerator nextObject]; - // associate touches with mice, so long as we have slots + /* associate touches with mice, so long as we have slots */ int i; int found = 0; for(i=0; touch && i < MAX_SIMULTANEOUS_TOUCHES; i++) { - // check if this mouse is already tracking a touch + /* check if this mouse is already tracking a touch */ if (mice[i].driverdata != NULL) { continue; } - + /* + mouse not associated with anything right now, + associate the touch with this mouse + */ found = 1; + /* save old mouse so we can switch back */ int oldMouse = SDL_SelectMouse(-1); + + /* select this slot's mouse */ SDL_SelectMouse(i); CGPoint locationInView = [touch locationInView: self]; + + /* set driver data to touch object, we'll use touch object later */ mice[i].driverdata = [touch retain]; + + /* send moved event */ SDL_SendMouseMotion(i, 0, locationInView.x, locationInView.y); + + /* send mouse down event */ SDL_SendMouseButton(i, SDL_PRESSED, SDL_BUTTON_LEFT); + + /* re-calibrate relative mouse motion */ SDL_GetRelativeMouseState(NULL, NULL); + + /* grab next touch */ touch = (UITouch*)[enumerator nextObject]; + /* switch back to our old mouse */ SDL_SelectMouse(oldMouse); } @@ -94,13 +112,16 @@ UITouch *touch=nil; while(touch = (UITouch *)[enumerator nextObject]) { + /* search for the mouse slot associated with this touch */ int i, found = NO; for (i=0; ikeyboard = SDL_AddKeyboard(&keyboard, -1); - /* - We'll need to delete this keyboard ... - */ SDL_AddKeyboard(&keyboard, 0); SDLKey keymap[SDL_NUM_SCANCODES]; SDL_GetDefaultKeymap(keymap); @@ -180,16 +200,19 @@ } +/* reveal onscreen virtual keyboard */ - (void)showKeyboard { keyboardVisible = YES; [textField becomeFirstResponder]; } +/* hide onscreen virtual keyboard */ - (void)hideKeyboard { keyboardVisible = NO; [textField resignFirstResponder]; } +/* UITextFieldDelegate method. Invoked when user types something. */ - (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if ([string length] == 0) { @@ -198,7 +221,8 @@ SDL_SendKeyboardKey( 0, SDL_RELEASED, SDL_SCANCODE_DELETE); } else { - + /* go through all the characters in the string we've been sent + and convert them to key presses */ int i; for (i=0; i<[string length]; i++) { @@ -208,27 +232,30 @@ SDL_scancode code; if (c < 127) { + /* figure out the SDL_scancode and SDL_keymod for this unichar */ code = unicharToUIKeyInfoTable[c].code; mod = unicharToUIKeyInfoTable[c].mod; } else { + /* we only deal with ASCII right now */ code = SDL_SCANCODE_UNKNOWN; mod = 0; } if (mod & KMOD_SHIFT) { + /* If character uses shift, press shift down */ SDL_SendKeyboardKey( 0, SDL_PRESSED, SDL_SCANCODE_LSHIFT); } + /* send a keydown and keyup even for the character */ SDL_SendKeyboardKey( 0, SDL_PRESSED, code); SDL_SendKeyboardKey( 0, SDL_RELEASED, code); if (mod & KMOD_SHIFT) { + /* If character uses shift, press shift back up */ SDL_SendKeyboardKey( 0, SDL_RELEASED, SDL_SCANCODE_LSHIFT); } - } - } - return NO; /* don't allow the edit(!) */ + return NO; /* don't allow the edit! (keep placeholder text there) */ } /* Terminates the editing session */ @@ -241,8 +268,6 @@ @end - - /* iPhone keyboard addition functions */ #if SDL_IPHONE_KEYBOARD @@ -348,6 +373,8 @@ #else +/* stubs, used if compiled without keyboard support */ + int SDL_iPhoneKeyboardShow(SDL_WindowID windowID) { SDL_SetError("Not compiled with keyboard support"); return -1;