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