author | koda |
Sun, 24 Jan 2010 19:52:30 +0000 | |
changeset 2714 | c85ffe57d971 |
parent 2705 | 2b5625c4ec16 |
child 2724 | 601158aaa201 |
permissions | -rw-r--r-- |
2688 | 1 |
/* |
2 |
SDL - Simple DirectMedia Layer |
|
3 |
Copyright (C) 1997-2009 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, mods for Hedgewars by Vittorio Giovara |
|
20 |
slouken@libsdl.org, vittorio.giovara@gmail.com |
|
21 |
*/ |
|
22 |
||
23 |
#include "PascalImports.h" |
|
24 |
#import "SDL_uikitview.h" |
|
25 |
#import "SDL_uikitappdelegate.h" |
|
26 |
||
27 |
#if SDL_IPHONE_KEYBOARD |
|
28 |
#import "SDL_keyboard_c.h" |
|
29 |
#import "keyinfotable.h" |
|
30 |
#import "SDL_uikitwindow.h" |
|
31 |
#endif |
|
32 |
||
33 |
@implementation SDL_uikitview |
|
34 |
||
35 |
@synthesize initialDistance, gestureStartPoint; |
|
36 |
||
2689 | 37 |
// they have to be global variables to allow showControls() to use them |
38 |
UIButton *attackButton, *menuButton; |
|
39 |
||
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2705
diff
changeset
|
40 |
-(void) dealloc { |
2688 | 41 |
#if SDL_IPHONE_KEYBOARD |
42 |
SDL_DelKeyboard(0); |
|
43 |
[textField release]; |
|
44 |
#endif |
|
2689 | 45 |
[menuButton release]; |
46 |
[attackButton release]; |
|
2688 | 47 |
[super dealloc]; |
48 |
} |
|
49 |
||
50 |
- (id)initWithFrame:(CGRect)frame { |
|
2689 | 51 |
// the addTarget parameter for the buttons below is set like that because |
52 |
// this object is inherited by SDL_openglesview.m which is the one allocated by SDL. |
|
53 |
// We select this class with [self superclass] and call the selectors with "+" because |
|
54 |
// they are superclass methods |
|
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2705
diff
changeset
|
55 |
self = [super initWithFrame:frame]; |
2688 | 56 |
|
57 |
#if SDL_IPHONE_KEYBOARD |
|
58 |
[self initializeKeyboard]; |
|
59 |
#endif |
|
60 |
||
61 |
int i; |
|
62 |
for (i=0; i<MAX_SIMULTANEOUS_TOUCHES; i++) { |
|
63 |
mice[i].id = i; |
|
64 |
mice[i].driverdata = NULL; |
|
65 |
SDL_AddMouse(&mice[i], "Mouse", 0, 0, 1); |
|
66 |
} |
|
67 |
||
2689 | 68 |
attackButton = [[UIButton alloc] initWithFrame:CGRectMake(30, 480, 260,50)]; |
2688 | 69 |
[attackButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateNormal]; |
2705
2b5625c4ec16
fix a nasty 196 bytes memory leak in engine, plus other stuff for iphone frontend
koda
parents:
2701
diff
changeset
|
70 |
[attackButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateHighlighted]; |
2688 | 71 |
[attackButton addTarget:[self superclass] action:@selector(attackButtonPressed) forControlEvents:UIControlEventTouchDown]; |
72 |
[attackButton addTarget:[self superclass] action:@selector(attackButtonReleased) forControlEvents:UIControlEventTouchUpInside|UIControlEventTouchUpOutside]; |
|
2689 | 73 |
[self addSubview:attackButton]; |
74 |
||
75 |
menuButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 480, 30,50)]; |
|
76 |
[menuButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateNormal]; |
|
77 |
[menuButton addTarget:[self superclass] action:@selector(attackButtonPressed) forControlEvents:UIControlEventTouchUpInside]; |
|
78 |
[self addSubview:menuButton]; |
|
2688 | 79 |
|
80 |
self.multipleTouchEnabled = YES; |
|
2689 | 81 |
|
2688 | 82 |
return self; |
83 |
} |
|
84 |
||
85 |
#pragma mark - |
|
2690 | 86 |
#pragma mark Exported functions for FreePascal |
2689 | 87 |
|
2690 | 88 |
const char* IPH_getDocumentsPath() { |
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2705
diff
changeset
|
89 |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2705
diff
changeset
|
90 |
NSString *documentsDirectory = [paths objectAtIndex: 0]; |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2705
diff
changeset
|
91 |
return [documentsDirectory UTF8String]; |
2690 | 92 |
} |
93 |
||
94 |
void IPH_showControls (void) { |
|
2689 | 95 |
NSLog(@"Showing controls"); |
96 |
[UIView beginAnimations:nil context:NULL]; |
|
97 |
[UIView setAnimationDuration:0.5]; |
|
98 |
attackButton.frame = CGRectMake(30, 430, 260, 50); |
|
99 |
menuButton.frame = CGRectMake(0, 430, 30, 50); |
|
100 |
[UIView commitAnimations]; |
|
101 |
} |
|
102 |
||
103 |
#pragma mark - |
|
2688 | 104 |
#pragma mark Superclass methods |
2689 | 105 |
|
2688 | 106 |
+(void) attackButtonPressed { |
107 |
HW_shoot(); |
|
108 |
} |
|
109 |
||
110 |
+(void) attackButtonReleased { |
|
111 |
HW_allKeysUp(); |
|
112 |
} |
|
113 |
||
114 |
#pragma mark - |
|
115 |
#pragma mark Custom SDL_UIView input handling |
|
116 |
||
117 |
// we override default touch input to implement our own gestures |
|
118 |
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
|
119 |
/*NSEnumerator *enumerator = [touches objectEnumerator]; |
|
120 |
UITouch *touch =(UITouch*)[enumerator nextObject]; |
|
121 |
||
122 |
/* associate touches with mice, so long as we have slots |
|
123 |
int i; |
|
124 |
int found = 0; |
|
125 |
for(i=0; touch && i < MAX_SIMULTANEOUS_TOUCHES; i++) { |
|
126 |
||
127 |
/* check if this mouse is already tracking a touch |
|
128 |
if (mice[i].driverdata != NULL) { |
|
129 |
continue; |
|
130 |
} |
|
131 |
/* |
|
132 |
mouse not associated with anything right now, |
|
133 |
associate the touch with this mouse |
|
134 |
||
135 |
found = 1; |
|
136 |
||
137 |
/* save old mouse so we can switch back |
|
138 |
int oldMouse = SDL_SelectMouse(-1); |
|
139 |
||
140 |
/* select this slot's mouse |
|
141 |
SDL_SelectMouse(i); |
|
142 |
CGPoint locationInView = [touch locationInView: self]; |
|
143 |
||
144 |
/* set driver data to touch object, we'll use touch object later |
|
145 |
mice[i].driverdata = [touch retain]; |
|
146 |
||
147 |
/* send moved event |
|
148 |
SDL_SendMouseMotion(i, 0, locationInView.x, locationInView.y, 0); |
|
149 |
||
150 |
/* send mouse down event |
|
151 |
SDL_SendMouseButton(i, SDL_PRESSED, SDL_BUTTON_LEFT); |
|
152 |
||
153 |
/* re-calibrate relative mouse motion |
|
154 |
SDL_GetRelativeMouseState(i, NULL, NULL); |
|
155 |
||
156 |
/* grab next touch |
|
157 |
touch = (UITouch*)[enumerator nextObject]; |
|
158 |
||
159 |
/* switch back to our old mouse |
|
160 |
SDL_SelectMouse(oldMouse); |
|
161 |
||
162 |
} */ |
|
163 |
||
164 |
UITouch *touch = [touches anyObject]; |
|
165 |
gestureStartPoint = [touch locationInView:self]; |
|
166 |
||
167 |
// one tap - single click |
|
168 |
if (1 == [touch tapCount] ) { |
|
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2705
diff
changeset
|
169 |
//SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, gestureStartPoint.x, gestureStartPoint.y); |
2688 | 170 |
HW_click(); |
171 |
} |
|
172 |
||
173 |
// two taps - right click |
|
174 |
if (2 == [touch tapCount] ) { |
|
175 |
HW_ammoMenu(); |
|
176 |
} |
|
177 |
||
178 |
// two taps with two fingers - middle click |
|
179 |
if (2 == [touch tapCount] && 2 == [touches count]) { |
|
180 |
HW_zoomReset(); |
|
181 |
} |
|
182 |
||
183 |
// two fingers - begin pinching |
|
184 |
if (2 == [touches count]) { |
|
185 |
NSArray *twoTouches = [touches allObjects]; |
|
186 |
UITouch *first = [twoTouches objectAtIndex:0]; |
|
187 |
UITouch *second = [twoTouches objectAtIndex:1]; |
|
188 |
initialDistance = distanceBetweenPoints([first locationInView:self], [second locationInView:self]); |
|
189 |
} |
|
190 |
} |
|
191 |
||
192 |
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
|
193 |
initialDistance = 0; |
|
194 |
// NSLog(@"touches ended, sigh"); |
|
195 |
||
196 |
HW_allKeysUp(); |
|
197 |
/*NSEnumerator *enumerator = [touches objectEnumerator]; |
|
198 |
UITouch *touch=nil; |
|
199 |
||
200 |
while(touch = (UITouch *)[enumerator nextObject]) { |
|
201 |
/* search for the mouse slot associated with this touch |
|
202 |
int i, found = NO; |
|
203 |
for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) { |
|
204 |
if (mice[i].driverdata == touch) { |
|
205 |
/* found the mouse associate with the touch |
|
206 |
[(UITouch*)(mice[i].driverdata) release]; |
|
207 |
mice[i].driverdata = NULL; |
|
208 |
/* send mouse up |
|
209 |
SDL_SendMouseButton(i, SDL_RELEASED, SDL_BUTTON_LEFT); |
|
210 |
/* discontinue search for this touch |
|
211 |
found = YES; |
|
212 |
} |
|
213 |
} |
|
214 |
}*/ |
|
215 |
} |
|
216 |
||
217 |
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
|
218 |
/* |
|
219 |
this can happen if the user puts more than 5 touches on the screen |
|
220 |
at once, or perhaps in other circumstances. Usually (it seems) |
|
221 |
all active touches are canceled. |
|
222 |
*/ |
|
223 |
[self touchesEnded: touches withEvent: event]; |
|
224 |
} |
|
225 |
||
226 |
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
|
227 |
UITouch *touch = [touches anyObject]; |
|
228 |
CGPoint currentPosition = [touch locationInView:self]; |
|
229 |
||
230 |
CGFloat Xdiff = gestureStartPoint.x - currentPosition.x; |
|
231 |
CGFloat Ydiff = gestureStartPoint.y - currentPosition.y; |
|
232 |
CGFloat deltaX = fabsf(Xdiff); |
|
2701
3a8560c00f78
settings tab has now a very nice iphone-like interface
koda
parents:
2696
diff
changeset
|
233 |
CGFloat deltaY = fabsf(Ydiff); |
2688 | 234 |
|
235 |
if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance) { |
|
236 |
NSLog(@"Horizontal swipe detected, begX:%f curX:%f", gestureStartPoint.x, currentPosition.x); |
|
237 |
if (Xdiff > 0) HW_walkLeft(); |
|
238 |
else HW_walkRight(); |
|
2701
3a8560c00f78
settings tab has now a very nice iphone-like interface
koda
parents:
2696
diff
changeset
|
239 |
} |
3a8560c00f78
settings tab has now a very nice iphone-like interface
koda
parents:
2696
diff
changeset
|
240 |
else if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance){ |
2688 | 241 |
NSLog(@"Vertical swipe detected, begY:%f curY:%f", gestureStartPoint.y, currentPosition.y); |
242 |
if (Ydiff > 0) HW_aimUp(); |
|
243 |
else HW_aimDown(); |
|
244 |
} |
|
245 |
||
246 |
// end pinch detection |
|
247 |
if (2 == [touches count]) { |
|
248 |
NSArray *twoTouches = [touches allObjects]; |
|
249 |
UITouch *first = [twoTouches objectAtIndex:0]; |
|
250 |
UITouch *second = [twoTouches objectAtIndex:1]; |
|
251 |
CGFloat currentDistance = distanceBetweenPoints([first locationInView:self], [second locationInView:self]); |
|
2701
3a8560c00f78
settings tab has now a very nice iphone-like interface
koda
parents:
2696
diff
changeset
|
252 |
|
2688 | 253 |
if (0 == initialDistance) |
254 |
initialDistance = currentDistance; |
|
255 |
else if (currentDistance - initialDistance > kMinimumPinchDelta) { |
|
256 |
NSLog(@"Outward pinch detected"); |
|
257 |
HW_zoomOut(); |
|
258 |
} |
|
259 |
else if (initialDistance - currentDistance > kMinimumPinchDelta) { |
|
260 |
NSLog(@"Inward pinch detected"); |
|
261 |
HW_zoomIn(); |
|
262 |
} |
|
263 |
} |
|
264 |
||
265 |
/*NSEnumerator *enumerator = [touches objectEnumerator]; |
|
266 |
UITouch *touch=nil;while(touch = (UITouch *)[enumerator nextObject]) { |
|
267 |
// try to find the mouse associated with this touch |
|
268 |
int i, found = NO; |
|
269 |
for (i=0; i<MAX_SIMULTANEOUS_TOUCHES && !found; i++) { |
|
270 |
if (mice[i].driverdata == touch) { |
|
271 |
// found proper mouse |
|
272 |
CGPoint locationInView = [touch locationInView: self]; |
|
273 |
// send moved event |
|
274 |
SDL_SendMouseMotion(i, 0, locationInView.x, locationInView.y, 0); |
|
275 |
// discontinue search |
|
276 |
found = YES; |
|
277 |
} |
|
278 |
} |
|
279 |
}*/ |
|
280 |
} |
|
281 |
||
282 |
#pragma mark - |
|
283 |
#pragma mark default routines |
|
284 |
/* |
|
285 |
---- Keyboard related functionality below this line ---- |
|
286 |
*/ |
|
287 |
#if SDL_IPHONE_KEYBOARD |
|
288 |
||
289 |
/* Is the iPhone virtual keyboard visible onscreen? */ |
|
290 |
- (BOOL)keyboardVisible { |
|
291 |
return keyboardVisible; |
|
292 |
} |
|
293 |
||
294 |
/* Set ourselves up as a UITextFieldDelegate */ |
|
295 |
- (void)initializeKeyboard { |
|
296 |
||
297 |
textField = [[[UITextField alloc] initWithFrame: CGRectZero] autorelease]; |
|
298 |
textField.delegate = self; |
|
299 |
/* placeholder so there is something to delete! */ |
|
300 |
textField.text = @" "; |
|
301 |
||
302 |
/* set UITextInputTrait properties, mostly to defaults */ |
|
303 |
textField.autocapitalizationType = UITextAutocapitalizationTypeNone; |
|
304 |
textField.autocorrectionType = UITextAutocorrectionTypeNo; |
|
305 |
textField.enablesReturnKeyAutomatically = NO; |
|
306 |
textField.keyboardAppearance = UIKeyboardAppearanceDefault; |
|
307 |
textField.keyboardType = UIKeyboardTypeDefault; |
|
308 |
textField.returnKeyType = UIReturnKeyDefault; |
|
309 |
textField.secureTextEntry = NO; |
|
310 |
||
311 |
textField.hidden = YES; |
|
312 |
keyboardVisible = NO; |
|
313 |
/* add the UITextField (hidden) to our view */ |
|
314 |
[self addSubview: textField]; |
|
315 |
||
316 |
/* create our SDL_Keyboard */ |
|
317 |
SDL_Keyboard keyboard; |
|
318 |
SDL_zero(keyboard); |
|
319 |
SDL_AddKeyboard(&keyboard, 0); |
|
320 |
SDLKey keymap[SDL_NUM_SCANCODES]; |
|
321 |
SDL_GetDefaultKeymap(keymap); |
|
322 |
SDL_SetKeymap(0, 0, keymap, SDL_NUM_SCANCODES); |
|
323 |
||
324 |
} |
|
325 |
||
326 |
/* reveal onscreen virtual keyboard */ |
|
327 |
- (void)showKeyboard { |
|
328 |
keyboardVisible = YES; |
|
329 |
[textField becomeFirstResponder]; |
|
330 |
} |
|
331 |
||
332 |
/* hide onscreen virtual keyboard */ |
|
333 |
- (void)hideKeyboard { |
|
334 |
keyboardVisible = NO; |
|
335 |
[textField resignFirstResponder]; |
|
336 |
} |
|
337 |
||
338 |
/* UITextFieldDelegate method. Invoked when user types something. */ |
|
339 |
- (BOOL)textField:(UITextField *)_textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { |
|
340 |
||
341 |
if ([string length] == 0) { |
|
342 |
/* it wants to replace text with nothing, ie a delete */ |
|
343 |
SDL_SendKeyboardKey( 0, SDL_PRESSED, SDL_SCANCODE_DELETE); |
|
344 |
SDL_SendKeyboardKey( 0, SDL_RELEASED, SDL_SCANCODE_DELETE); |
|
345 |
} |
|
346 |
else { |
|
347 |
/* go through all the characters in the string we've been sent |
|
348 |
and convert them to key presses */ |
|
349 |
int i; |
|
350 |
for (i=0; i<[string length]; i++) { |
|
351 |
||
352 |
unichar c = [string characterAtIndex: i]; |
|
353 |
||
354 |
Uint16 mod = 0; |
|
355 |
SDL_scancode code; |
|
356 |
||
357 |
if (c < 127) { |
|
358 |
/* figure out the SDL_scancode and SDL_keymod for this unichar */ |
|
359 |
code = unicharToUIKeyInfoTable[c].code; |
|
360 |
mod = unicharToUIKeyInfoTable[c].mod; |
|
361 |
} |
|
362 |
else { |
|
363 |
/* we only deal with ASCII right now */ |
|
364 |
code = SDL_SCANCODE_UNKNOWN; |
|
365 |
mod = 0; |
|
366 |
} |
|
367 |
||
368 |
if (mod & KMOD_SHIFT) { |
|
369 |
/* If character uses shift, press shift down */ |
|
370 |
SDL_SendKeyboardKey( 0, SDL_PRESSED, SDL_SCANCODE_LSHIFT); |
|
371 |
} |
|
372 |
/* send a keydown and keyup even for the character */ |
|
373 |
SDL_SendKeyboardKey( 0, SDL_PRESSED, code); |
|
374 |
SDL_SendKeyboardKey( 0, SDL_RELEASED, code); |
|
375 |
if (mod & KMOD_SHIFT) { |
|
376 |
/* If character uses shift, press shift back up */ |
|
377 |
SDL_SendKeyboardKey( 0, SDL_RELEASED, SDL_SCANCODE_LSHIFT); |
|
378 |
} |
|
379 |
} |
|
380 |
} |
|
381 |
return NO; /* don't allow the edit! (keep placeholder text there) */ |
|
382 |
} |
|
383 |
||
384 |
/* Terminates the editing session */ |
|
385 |
- (BOOL)textFieldShouldReturn:(UITextField*)_textField { |
|
386 |
[self hideKeyboard]; |
|
387 |
return YES; |
|
388 |
} |
|
389 |
||
390 |
#endif |
|
391 |
||
392 |
@end |
|
393 |
||
394 |
/* iPhone keyboard addition functions */ |
|
395 |
#if SDL_IPHONE_KEYBOARD |
|
396 |
||
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2705
diff
changeset
|
397 |
int SDL_iPhoneKeyboardShow(SDL_Window *window) { |
2688 | 398 |
SDL_WindowData *data; |
399 |
SDL_uikitview *view; |
|
400 |
||
401 |
if (NULL == window) { |
|
402 |
SDL_SetError("Window does not exist"); |
|
403 |
return -1; |
|
404 |
} |
|
405 |
||
406 |
data = (SDL_WindowData *)window->driverdata; |
|
407 |
view = data->view; |
|
408 |
||
409 |
if (nil == view) { |
|
410 |
SDL_SetError("Window has no view"); |
|
411 |
return -1; |
|
412 |
} |
|
413 |
else { |
|
414 |
[view showKeyboard]; |
|
415 |
return 0; |
|
416 |
} |
|
417 |
} |
|
418 |
||
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2705
diff
changeset
|
419 |
int SDL_iPhoneKeyboardHide(SDL_Window *window) { |
2688 | 420 |
SDL_WindowData *data; |
421 |
SDL_uikitview *view; |
|
422 |
||
423 |
if (NULL == window) { |
|
424 |
SDL_SetError("Window does not exist"); |
|
425 |
return -1; |
|
426 |
} |
|
427 |
||
428 |
data = (SDL_WindowData *)window->driverdata; |
|
429 |
view = data->view; |
|
430 |
||
431 |
if (NULL == view) { |
|
432 |
SDL_SetError("Window has no view"); |
|
433 |
return -1; |
|
434 |
} |
|
435 |
else { |
|
436 |
[view hideKeyboard]; |
|
437 |
return 0; |
|
438 |
} |
|
439 |
} |
|
440 |
||
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2705
diff
changeset
|
441 |
SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window *window) { |
2688 | 442 |
SDL_WindowData *data; |
443 |
SDL_uikitview *view; |
|
444 |
||
445 |
if (NULL == window) { |
|
446 |
SDL_SetError("Window does not exist"); |
|
447 |
return -1; |
|
448 |
} |
|
449 |
||
450 |
data = (SDL_WindowData *)window->driverdata; |
|
451 |
view = data->view; |
|
452 |
||
453 |
if (NULL == view) { |
|
454 |
SDL_SetError("Window has no view"); |
|
455 |
return 0; |
|
456 |
} |
|
457 |
else { |
|
458 |
return view.keyboardVisible; |
|
459 |
} |
|
460 |
} |
|
461 |
||
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2705
diff
changeset
|
462 |
int SDL_iPhoneKeyboardToggle(SDL_Window *window) { |
2688 | 463 |
SDL_WindowData *data; |
464 |
SDL_uikitview *view; |
|
465 |
||
466 |
if (NULL == window) { |
|
467 |
SDL_SetError("Window does not exist"); |
|
468 |
return -1; |
|
469 |
} |
|
470 |
||
471 |
data = (SDL_WindowData *)window->driverdata; |
|
472 |
view = data->view; |
|
473 |
||
474 |
if (NULL == view) { |
|
475 |
SDL_SetError("Window has no view"); |
|
476 |
return -1; |
|
477 |
} |
|
478 |
else { |
|
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2705
diff
changeset
|
479 |
if (SDL_iPhoneKeyboardIsShown(window)) { |
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2705
diff
changeset
|
480 |
SDL_iPhoneKeyboardHide(window); |
2688 | 481 |
} |
482 |
else { |
|
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2705
diff
changeset
|
483 |
SDL_iPhoneKeyboardShow(window); |
2688 | 484 |
} |
485 |
return 0; |
|
486 |
} |
|
487 |
} |
|
488 |
||
489 |
#else |
|
490 |
||
491 |
/* stubs, used if compiled without keyboard support */ |
|
492 |
||
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2705
diff
changeset
|
493 |
int SDL_iPhoneKeyboardShow(SDL_Window *window) { |
2688 | 494 |
SDL_SetError("Not compiled with keyboard support"); |
495 |
return -1; |
|
496 |
} |
|
497 |
||
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2705
diff
changeset
|
498 |
int SDL_iPhoneKeyboardHide(SDL_Window *window) { |
2688 | 499 |
SDL_SetError("Not compiled with keyboard support"); |
500 |
return -1; |
|
501 |
} |
|
502 |
||
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2705
diff
changeset
|
503 |
SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window *window) { |
2688 | 504 |
return 0; |
505 |
} |
|
506 |
||
2714
c85ffe57d971
update iphone frontend to the new (silly) sdl api, code cleanups for other sections
koda
parents:
2705
diff
changeset
|
507 |
int SDL_iPhoneKeyboardToggle(SDL_Window *window) { |
2688 | 508 |
SDL_SetError("Not compiled with keyboard support"); |
509 |
return -1; |
|
510 |
} |
|
511 |
||
512 |
||
513 |
#endif /* SDL_IPHONE_KEYBOARD */ |