Mercurial > sdl-ios-xcode
annotate src/video/uikit/SDL_uikitview.m @ 5284:96a22141cf86 tip
Changed output directory of Universal libSDL.a for iOS to respect build configurations. Template generator was updated to reflect these changes as well.
author | Eric Wing <ewing . public |-at-| gmail . com> |
---|---|
date | Sat, 12 Feb 2011 21:52:30 -0800 |
parents | b530ef003506 |
children |
rev | line source |
---|---|
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
5267 | 2 SDL - Simple DirectMedia Layer |
3 Copyright (C) 1997-2011 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Lesser General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2.1 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Lesser General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Lesser General Public | |
16 License along with this library; if not, write to the Free Software | |
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@libsdl.org | |
21 */ | |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 #import "SDL_uikitview.h" |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 |
4490
06c7423f8c60
Updated iPhone keyboard code (which builds and runs on the iPad and iPhone simulator now)
Sam Lantinga <slouken@libsdl.org>
parents:
4488
diff
changeset
|
25 #include "../../events/SDL_keyboard_c.h" |
06c7423f8c60
Updated iPhone keyboard code (which builds and runs on the iPad and iPhone simulator now)
Sam Lantinga <slouken@libsdl.org>
parents:
4488
diff
changeset
|
26 #include "../../events/SDL_mouse_c.h" |
4677
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
4662
diff
changeset
|
27 #include "../../events/SDL_touch_c.h" |
4490
06c7423f8c60
Updated iPhone keyboard code (which builds and runs on the iPad and iPhone simulator now)
Sam Lantinga <slouken@libsdl.org>
parents:
4488
diff
changeset
|
28 |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 #if SDL_IPHONE_KEYBOARD |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 #import "keyinfotable.h" |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 #import "SDL_uikitappdelegate.h" |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 #import "SDL_uikitwindow.h" |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 #endif |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 @implementation SDL_uikitview |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 - (void)dealloc { |
5134 | 38 [super dealloc]; |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 } |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 - (id)initWithFrame:(CGRect)frame { |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 |
5134 | 43 self = [super initWithFrame: frame]; |
44 | |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 #if SDL_IPHONE_KEYBOARD |
5134 | 46 [self initializeKeyboard]; |
47 #endif | |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 |
4677
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
4662
diff
changeset
|
49 #ifdef FIXED_MULTITOUCH |
5134 | 50 SDL_Touch touch; |
51 touch.id = 0; //TODO: Should be -1? | |
4660
b15e7017409b
Added Iphone support (untested)
Jim Grandpre <jim.tla@gmail.com>
parents:
3685
diff
changeset
|
52 |
5134 | 53 //touch.driverdata = SDL_malloc(sizeof(EventTouchData)); |
54 //EventTouchData* data = (EventTouchData*)(touch.driverdata); | |
55 | |
56 touch.x_min = 0; | |
57 touch.x_max = frame.size.width; | |
58 touch.native_xres = touch.x_max - touch.x_min; | |
59 touch.y_min = 0; | |
60 touch.y_max = frame.size.height; | |
61 touch.native_yres = touch.y_max - touch.y_min; | |
62 touch.pressure_min = 0; | |
63 touch.pressure_max = 1; | |
64 touch.native_pressureres = touch.pressure_max - touch.pressure_min; | |
4660
b15e7017409b
Added Iphone support (untested)
Jim Grandpre <jim.tla@gmail.com>
parents:
3685
diff
changeset
|
65 |
b15e7017409b
Added Iphone support (untested)
Jim Grandpre <jim.tla@gmail.com>
parents:
3685
diff
changeset
|
66 |
5134 | 67 touchId = SDL_AddTouch(&touch, "IPHONE SCREEN"); |
4465
3e69e077cb95
Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
68 #endif |
4661
03dcb795c583
Merged changes from the main SDL codebase
Sam Lantinga <slouken@libsdl.org>
diff
changeset
|
69 |
5134 | 70 return self; |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 } |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 |
5134 | 76 NSEnumerator *enumerator = [touches objectEnumerator]; |
77 UITouch *touch = (UITouch*)[enumerator nextObject]; | |
78 | |
79 //NSLog("Click"); | |
80 | |
81 if (touch) { | |
82 CGPoint locationInView = [touch locationInView: self]; | |
83 | |
84 /* send moved event */ | |
85 SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y); | |
4488
6dc6a2bdd55e
Re-implemented single mouse touches on the iPhone/iPad
Sam Lantinga <slouken@libsdl.org>
parents:
4465
diff
changeset
|
86 |
5134 | 87 /* send mouse down event */ |
88 SDL_SendMouseButton(NULL, SDL_PRESSED, SDL_BUTTON_LEFT); | |
89 } | |
4660
b15e7017409b
Added Iphone support (untested)
Jim Grandpre <jim.tla@gmail.com>
parents:
3685
diff
changeset
|
90 |
4677
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
4662
diff
changeset
|
91 #ifdef FIXED_MULTITOUCH |
5134 | 92 while(touch) { |
93 CGPoint locationInView = [touch locationInView: self]; | |
4662
3c4e0130c9b1
Added alternative finger tracking method. Still prefer IPHONE_TOUCH_EFFICIENT_DANGEROUS.
Jim Grandpre <jim.tla@gmail.com>
parents:
4661
diff
changeset
|
94 |
3c4e0130c9b1
Added alternative finger tracking method. Still prefer IPHONE_TOUCH_EFFICIENT_DANGEROUS.
Jim Grandpre <jim.tla@gmail.com>
parents:
4661
diff
changeset
|
95 |
3c4e0130c9b1
Added alternative finger tracking method. Still prefer IPHONE_TOUCH_EFFICIENT_DANGEROUS.
Jim Grandpre <jim.tla@gmail.com>
parents:
4661
diff
changeset
|
96 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS |
5134 | 97 //FIXME: TODO: Using touch as the fingerId is potentially dangerous |
98 //It is also much more efficient than storing the UITouch pointer | |
99 //and comparing it to the incoming event. | |
100 SDL_SendFingerDown(touchId,(long)touch, | |
101 SDL_TRUE,locationInView.x,locationInView.y, | |
102 1); | |
4662
3c4e0130c9b1
Added alternative finger tracking method. Still prefer IPHONE_TOUCH_EFFICIENT_DANGEROUS.
Jim Grandpre <jim.tla@gmail.com>
parents:
4661
diff
changeset
|
103 #else |
5134 | 104 int i; |
105 for(i = 0;i < MAX_SIMULTANEOUS_TOUCHES;i++) { | |
106 if(finger[i] == NULL) { | |
107 finger[i] = touch; | |
108 SDL_SendFingerDown(touchId,i, | |
109 SDL_TRUE,locationInView.x,locationInView.y, | |
110 1); | |
111 break; | |
112 } | |
113 } | |
4662
3c4e0130c9b1
Added alternative finger tracking method. Still prefer IPHONE_TOUCH_EFFICIENT_DANGEROUS.
Jim Grandpre <jim.tla@gmail.com>
parents:
4661
diff
changeset
|
114 #endif |
5134 | 115 |
4662
3c4e0130c9b1
Added alternative finger tracking method. Still prefer IPHONE_TOUCH_EFFICIENT_DANGEROUS.
Jim Grandpre <jim.tla@gmail.com>
parents:
4661
diff
changeset
|
116 |
5134 | 117 |
4660
b15e7017409b
Added Iphone support (untested)
Jim Grandpre <jim.tla@gmail.com>
parents:
3685
diff
changeset
|
118 |
5134 | 119 touch = (UITouch*)[enumerator nextObject]; |
120 } | |
4465
3e69e077cb95
Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
121 #endif |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 } |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
5134 | 125 |
126 NSEnumerator *enumerator = [touches objectEnumerator]; | |
127 UITouch *touch = (UITouch*)[enumerator nextObject]; | |
128 | |
129 if (touch) { | |
130 /* send mouse up */ | |
131 SDL_SendMouseButton(NULL, SDL_RELEASED, SDL_BUTTON_LEFT); | |
132 } | |
4661
03dcb795c583
Merged changes from the main SDL codebase
Sam Lantinga <slouken@libsdl.org>
diff
changeset
|
133 |
4677
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
4662
diff
changeset
|
134 #ifdef FIXED_MULTITOUCH |
5134 | 135 while(touch) { |
136 CGPoint locationInView = [touch locationInView: self]; | |
137 | |
4662
3c4e0130c9b1
Added alternative finger tracking method. Still prefer IPHONE_TOUCH_EFFICIENT_DANGEROUS.
Jim Grandpre <jim.tla@gmail.com>
parents:
4661
diff
changeset
|
138 |
3c4e0130c9b1
Added alternative finger tracking method. Still prefer IPHONE_TOUCH_EFFICIENT_DANGEROUS.
Jim Grandpre <jim.tla@gmail.com>
parents:
4661
diff
changeset
|
139 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS |
5134 | 140 SDL_SendFingerDown(touchId,(long)touch, |
141 SDL_FALSE,locationInView.x,locationInView.y, | |
142 1); | |
4662
3c4e0130c9b1
Added alternative finger tracking method. Still prefer IPHONE_TOUCH_EFFICIENT_DANGEROUS.
Jim Grandpre <jim.tla@gmail.com>
parents:
4661
diff
changeset
|
143 #else |
5134 | 144 int i; |
145 for(i = 0;i < MAX_SIMULTANEOUS_TOUCHES;i++) { | |
146 if(finger[i] == touch) { | |
147 SDL_SendFingerDown(touchId,i, | |
148 SDL_FALSE,locationInView.x,locationInView.y, | |
149 1); | |
150 break; | |
151 } | |
152 } | |
4662
3c4e0130c9b1
Added alternative finger tracking method. Still prefer IPHONE_TOUCH_EFFICIENT_DANGEROUS.
Jim Grandpre <jim.tla@gmail.com>
parents:
4661
diff
changeset
|
153 #endif |
4660
b15e7017409b
Added Iphone support (untested)
Jim Grandpre <jim.tla@gmail.com>
parents:
3685
diff
changeset
|
154 |
5134 | 155 touch = (UITouch*)[enumerator nextObject]; |
156 } | |
4465
3e69e077cb95
Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
157 #endif |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 } |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
5134 | 161 /* |
162 this can happen if the user puts more than 5 touches on the screen | |
163 at once, or perhaps in other circumstances. Usually (it seems) | |
164 all active touches are canceled. | |
165 */ | |
166 [self touchesEnded: touches withEvent: event]; | |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 } |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
5134 | 170 |
171 NSEnumerator *enumerator = [touches objectEnumerator]; | |
172 UITouch *touch = (UITouch*)[enumerator nextObject]; | |
173 | |
174 if (touch) { | |
175 CGPoint locationInView = [touch locationInView: self]; | |
4488
6dc6a2bdd55e
Re-implemented single mouse touches on the iPhone/iPad
Sam Lantinga <slouken@libsdl.org>
parents:
4465
diff
changeset
|
176 |
5134 | 177 /* send moved event */ |
178 SDL_SendMouseMotion(NULL, 0, locationInView.x, locationInView.y); | |
179 } | |
4660
b15e7017409b
Added Iphone support (untested)
Jim Grandpre <jim.tla@gmail.com>
parents:
3685
diff
changeset
|
180 |
4677
31607094315c
Added Iphone project. Iphone multi-touch is now functional.
jimtla
parents:
4662
diff
changeset
|
181 #ifdef FIXED_MULTITOUCH |
5134 | 182 while(touch) { |
183 CGPoint locationInView = [touch locationInView: self]; | |
184 | |
4662
3c4e0130c9b1
Added alternative finger tracking method. Still prefer IPHONE_TOUCH_EFFICIENT_DANGEROUS.
Jim Grandpre <jim.tla@gmail.com>
parents:
4661
diff
changeset
|
185 |
3c4e0130c9b1
Added alternative finger tracking method. Still prefer IPHONE_TOUCH_EFFICIENT_DANGEROUS.
Jim Grandpre <jim.tla@gmail.com>
parents:
4661
diff
changeset
|
186 #ifdef IPHONE_TOUCH_EFFICIENT_DANGEROUS |
5134 | 187 SDL_SendTouchMotion(touchId,(long)touch, |
188 SDL_FALSE,locationInView.x,locationInView.y, | |
189 1); | |
4662
3c4e0130c9b1
Added alternative finger tracking method. Still prefer IPHONE_TOUCH_EFFICIENT_DANGEROUS.
Jim Grandpre <jim.tla@gmail.com>
parents:
4661
diff
changeset
|
190 #else |
5134 | 191 int i; |
192 for(i = 0;i < MAX_SIMULTANEOUS_TOUCHES;i++) { | |
193 if(finger[i] == touch) { | |
194 SDL_SendTouchMotion(touchId,i, | |
195 SDL_FALSE,locationInView.x,locationInView.y, | |
196 1); | |
197 break; | |
198 } | |
199 } | |
4662
3c4e0130c9b1
Added alternative finger tracking method. Still prefer IPHONE_TOUCH_EFFICIENT_DANGEROUS.
Jim Grandpre <jim.tla@gmail.com>
parents:
4661
diff
changeset
|
200 #endif |
4660
b15e7017409b
Added Iphone support (untested)
Jim Grandpre <jim.tla@gmail.com>
parents:
3685
diff
changeset
|
201 |
5134 | 202 touch = (UITouch*)[enumerator nextObject]; |
203 } | |
4465
3e69e077cb95
Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents:
3685
diff
changeset
|
204 #endif |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
205 } |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
206 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
207 /* |
5134 | 208 ---- Keyboard related functionality below this line ---- |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
209 */ |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
210 #if SDL_IPHONE_KEYBOARD |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
211 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 /* Is the iPhone virtual keyboard visible onscreen? */ |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
213 - (BOOL)keyboardVisible { |
5134 | 214 return keyboardVisible; |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
215 } |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
216 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
217 /* Set ourselves up as a UITextFieldDelegate */ |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
218 - (void)initializeKeyboard { |
5134 | 219 |
220 textField = [[UITextField alloc] initWithFrame: CGRectZero]; | |
221 textField.delegate = self; | |
222 /* placeholder so there is something to delete! */ | |
223 textField.text = @" "; | |
224 | |
225 /* set UITextInputTrait properties, mostly to defaults */ | |
226 textField.autocapitalizationType = UITextAutocapitalizationTypeNone; | |
227 textField.autocorrectionType = UITextAutocorrectionTypeNo; | |
228 textField.enablesReturnKeyAutomatically = NO; | |
229 textField.keyboardAppearance = UIKeyboardAppearanceDefault; | |
230 textField.keyboardType = UIKeyboardTypeDefault; | |
231 textField.returnKeyType = UIReturnKeyDefault; | |
232 textField.secureTextEntry = NO; | |
233 | |
234 textField.hidden = YES; | |
235 keyboardVisible = NO; | |
236 /* add the UITextField (hidden) to our view */ | |
237 [self addSubview: textField]; | |
238 [textField release]; | |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
239 } |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
240 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
241 /* reveal onscreen virtual keyboard */ |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
242 - (void)showKeyboard { |
5134 | 243 keyboardVisible = YES; |
244 [textField becomeFirstResponder]; | |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
245 } |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
246 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
247 /* hide onscreen virtual keyboard */ |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
248 - (void)hideKeyboard { |
5134 | 249 keyboardVisible = NO; |
250 [textField resignFirstResponder]; | |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
251 } |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
252 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
253 /* UITextFieldDelegate method. Invoked when user types something. */ |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
254 - (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { |
5134 | 255 |
256 if ([string length] == 0) { | |
257 /* it wants to replace text with nothing, ie a delete */ | |
258 SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_DELETE); | |
259 SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_DELETE); | |
260 } | |
261 else { | |
262 /* go through all the characters in the string we've been sent | |
263 and convert them to key presses */ | |
264 int i; | |
265 for (i=0; i<[string length]; i++) { | |
266 | |
267 unichar c = [string characterAtIndex: i]; | |
268 | |
269 Uint16 mod = 0; | |
5223
572a73d71b5f
Sheena pointed out that "scancode" and "keysym" are single words and shouldn't be camel-cased.
Sam Lantinga <slouken@libsdl.org>
parents:
5137
diff
changeset
|
270 SDL_Scancode code; |
5134 | 271 |
272 if (c < 127) { | |
5223
572a73d71b5f
Sheena pointed out that "scancode" and "keysym" are single words and shouldn't be camel-cased.
Sam Lantinga <slouken@libsdl.org>
parents:
5137
diff
changeset
|
273 /* figure out the SDL_Scancode and SDL_keymod for this unichar */ |
5134 | 274 code = unicharToUIKeyInfoTable[c].code; |
275 mod = unicharToUIKeyInfoTable[c].mod; | |
276 } | |
277 else { | |
278 /* we only deal with ASCII right now */ | |
279 code = SDL_SCANCODE_UNKNOWN; | |
280 mod = 0; | |
281 } | |
282 | |
283 if (mod & KMOD_SHIFT) { | |
284 /* If character uses shift, press shift down */ | |
285 SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_LSHIFT); | |
286 } | |
287 /* send a keydown and keyup even for the character */ | |
288 SDL_SendKeyboardKey(SDL_PRESSED, code); | |
289 SDL_SendKeyboardKey(SDL_RELEASED, code); | |
290 if (mod & KMOD_SHIFT) { | |
291 /* If character uses shift, press shift back up */ | |
292 SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_LSHIFT); | |
293 } | |
294 } | |
295 } | |
296 return NO; /* don't allow the edit! (keep placeholder text there) */ | |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
297 } |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
298 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
299 /* Terminates the editing session */ |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
300 - (BOOL)textFieldShouldReturn:(UITextField*)_textField { |
5137
c63b901d97ab
Fixed bug #1025 (iphone keyboard doesn't send 'return' and 'backspace' events)
Sam Lantinga <slouken@libsdl.org>
parents:
5135
diff
changeset
|
301 SDL_SendKeyboardKey(SDL_PRESSED, SDL_SCANCODE_RETURN); |
5134 | 302 [self hideKeyboard]; |
303 return YES; | |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
304 } |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
305 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 #endif |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
307 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 @end |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
309 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
310 /* iPhone keyboard addition functions */ |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
311 #if SDL_IPHONE_KEYBOARD |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 |
3685
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
313 int SDL_iPhoneKeyboardShow(SDL_Window * window) { |
5134 | 314 |
315 SDL_WindowData *data; | |
316 SDL_uikitview *view; | |
317 | |
318 if (NULL == window) { | |
319 SDL_SetError("Window does not exist"); | |
320 return -1; | |
321 } | |
322 | |
323 data = (SDL_WindowData *)window->driverdata; | |
324 view = data->view; | |
325 | |
326 if (nil == view) { | |
327 SDL_SetError("Window has no view"); | |
328 return -1; | |
329 } | |
330 else { | |
331 [view showKeyboard]; | |
332 return 0; | |
333 } | |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
334 } |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
335 |
3685
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
336 int SDL_iPhoneKeyboardHide(SDL_Window * window) { |
5134 | 337 |
338 SDL_WindowData *data; | |
339 SDL_uikitview *view; | |
340 | |
341 if (NULL == window) { | |
342 SDL_SetError("Window does not exist"); | |
343 return -1; | |
344 } | |
345 | |
346 data = (SDL_WindowData *)window->driverdata; | |
347 view = data->view; | |
348 | |
349 if (NULL == view) { | |
350 SDL_SetError("Window has no view"); | |
351 return -1; | |
352 } | |
353 else { | |
354 [view hideKeyboard]; | |
355 return 0; | |
356 } | |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
357 } |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
358 |
3685
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
359 SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window * window) { |
5134 | 360 |
361 SDL_WindowData *data; | |
362 SDL_uikitview *view; | |
363 | |
364 if (NULL == window) { | |
365 SDL_SetError("Window does not exist"); | |
366 return -1; | |
367 } | |
368 | |
369 data = (SDL_WindowData *)window->driverdata; | |
370 view = data->view; | |
371 | |
372 if (NULL == view) { | |
373 SDL_SetError("Window has no view"); | |
374 return 0; | |
375 } | |
376 else { | |
377 return view.keyboardVisible; | |
378 } | |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
379 } |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
380 |
3685
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
381 int SDL_iPhoneKeyboardToggle(SDL_Window * window) { |
5134 | 382 |
383 SDL_WindowData *data; | |
384 SDL_uikitview *view; | |
385 | |
386 if (NULL == window) { | |
387 SDL_SetError("Window does not exist"); | |
388 return -1; | |
389 } | |
390 | |
391 data = (SDL_WindowData *)window->driverdata; | |
392 view = data->view; | |
393 | |
394 if (NULL == view) { | |
395 SDL_SetError("Window has no view"); | |
396 return -1; | |
397 } | |
398 else { | |
399 if (SDL_iPhoneKeyboardIsShown(window)) { | |
400 SDL_iPhoneKeyboardHide(window); | |
401 } | |
402 else { | |
403 SDL_iPhoneKeyboardShow(window); | |
404 } | |
405 return 0; | |
406 } | |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
407 } |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
408 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
409 #else |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
410 |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
411 /* stubs, used if compiled without keyboard support */ |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
412 |
3685
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
413 int SDL_iPhoneKeyboardShow(SDL_Window * window) { |
5134 | 414 SDL_SetError("Not compiled with keyboard support"); |
415 return -1; | |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
416 } |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
417 |
3685
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
418 int SDL_iPhoneKeyboardHide(SDL_Window * window) { |
5134 | 419 SDL_SetError("Not compiled with keyboard support"); |
420 return -1; | |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
421 } |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
422 |
3685
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
423 SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window * window) { |
5134 | 424 return 0; |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
425 } |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
426 |
3685
64ce267332c6
Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents:
2940
diff
changeset
|
427 int SDL_iPhoneKeyboardToggle(SDL_Window * window) { |
5134 | 428 SDL_SetError("Not compiled with keyboard support"); |
429 return -1; | |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
430 } |
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
431 |
5135 | 432 #endif /* SDL_IPHONE_KEYBOARD */ |
2765
f55c87ae336b
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
433 |
5135 | 434 /* vi: set ts=4 sw=4 expandtab: */ |