35 @synthesize initialDistance, gestureStartPoint; |
35 @synthesize initialDistance, gestureStartPoint; |
36 |
36 |
37 // they have to be global variables to allow showControls() to use them |
37 // they have to be global variables to allow showControls() to use them |
38 UIButton *attackButton, *menuButton; |
38 UIButton *attackButton, *menuButton; |
39 |
39 |
40 - (void)dealloc { |
40 -(void) dealloc { |
41 #if SDL_IPHONE_KEYBOARD |
41 #if SDL_IPHONE_KEYBOARD |
42 SDL_DelKeyboard(0); |
42 SDL_DelKeyboard(0); |
43 [textField release]; |
43 [textField release]; |
44 #endif |
44 #endif |
45 [menuButton release]; |
45 [menuButton release]; |
50 - (id)initWithFrame:(CGRect)frame { |
50 - (id)initWithFrame:(CGRect)frame { |
51 // the addTarget parameter for the buttons below is set like that because |
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. |
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 |
53 // We select this class with [self superclass] and call the selectors with "+" because |
54 // they are superclass methods |
54 // they are superclass methods |
55 self = [super initWithFrame: frame]; |
55 self = [super initWithFrame:frame]; |
56 |
56 |
57 #if SDL_IPHONE_KEYBOARD |
57 #if SDL_IPHONE_KEYBOARD |
58 [self initializeKeyboard]; |
58 [self initializeKeyboard]; |
59 #endif |
59 #endif |
60 |
60 |
75 menuButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 480, 30,50)]; |
75 menuButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 480, 30,50)]; |
76 [menuButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateNormal]; |
76 [menuButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateNormal]; |
77 [menuButton addTarget:[self superclass] action:@selector(attackButtonPressed) forControlEvents:UIControlEventTouchUpInside]; |
77 [menuButton addTarget:[self superclass] action:@selector(attackButtonPressed) forControlEvents:UIControlEventTouchUpInside]; |
78 [self addSubview:menuButton]; |
78 [self addSubview:menuButton]; |
79 |
79 |
80 [[SDLUIKitDelegate sharedAppDelegate].window makeKeyAndVisible]; |
|
81 self.multipleTouchEnabled = YES; |
80 self.multipleTouchEnabled = YES; |
82 |
81 |
83 return self; |
82 return self; |
84 } |
83 } |
85 |
84 |
86 #pragma mark - |
85 #pragma mark - |
87 #pragma mark Exported functions for FreePascal |
86 #pragma mark Exported functions for FreePascal |
88 |
87 |
89 const char* IPH_getDocumentsPath() { |
88 const char* IPH_getDocumentsPath() { |
90 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); |
89 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); |
91 NSString *documentsDirectory = [paths objectAtIndex: 0]; |
90 NSString *documentsDirectory = [paths objectAtIndex: 0]; |
92 return [documentsDirectory UTF8String]; |
91 return [documentsDirectory UTF8String]; |
93 } |
92 } |
94 |
93 |
95 void IPH_showControls (void) { |
94 void IPH_showControls (void) { |
96 NSLog(@"Showing controls"); |
95 NSLog(@"Showing controls"); |
97 [UIView beginAnimations:nil context:NULL]; |
96 [UIView beginAnimations:nil context:NULL]; |
165 UITouch *touch = [touches anyObject]; |
164 UITouch *touch = [touches anyObject]; |
166 gestureStartPoint = [touch locationInView:self]; |
165 gestureStartPoint = [touch locationInView:self]; |
167 |
166 |
168 // one tap - single click |
167 // one tap - single click |
169 if (1 == [touch tapCount] ) { |
168 if (1 == [touch tapCount] ) { |
170 //SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].windowID, gestureStartPoint.x, gestureStartPoint.y); |
169 //SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, gestureStartPoint.x, gestureStartPoint.y); |
171 HW_click(); |
170 HW_click(); |
172 } |
171 } |
173 |
172 |
174 // two taps - right click |
173 // two taps - right click |
175 if (2 == [touch tapCount] ) { |
174 if (2 == [touch tapCount] ) { |
393 @end |
392 @end |
394 |
393 |
395 /* iPhone keyboard addition functions */ |
394 /* iPhone keyboard addition functions */ |
396 #if SDL_IPHONE_KEYBOARD |
395 #if SDL_IPHONE_KEYBOARD |
397 |
396 |
398 int SDL_iPhoneKeyboardShow(SDL_WindowID windowID) { |
397 int SDL_iPhoneKeyboardShow(SDL_Window *window) { |
399 |
|
400 SDL_Window *window = SDL_GetWindowFromID(windowID); |
|
401 SDL_WindowData *data; |
398 SDL_WindowData *data; |
402 SDL_uikitview *view; |
399 SDL_uikitview *view; |
403 |
400 |
404 if (NULL == window) { |
401 if (NULL == window) { |
405 SDL_SetError("Window does not exist"); |
402 SDL_SetError("Window does not exist"); |
464 else { |
457 else { |
465 return view.keyboardVisible; |
458 return view.keyboardVisible; |
466 } |
459 } |
467 } |
460 } |
468 |
461 |
469 int SDL_iPhoneKeyboardToggle(SDL_WindowID windowID) { |
462 int SDL_iPhoneKeyboardToggle(SDL_Window *window) { |
470 |
|
471 SDL_Window *window = SDL_GetWindowFromID(windowID); |
|
472 SDL_WindowData *data; |
463 SDL_WindowData *data; |
473 SDL_uikitview *view; |
464 SDL_uikitview *view; |
474 |
465 |
475 if (NULL == window) { |
466 if (NULL == window) { |
476 SDL_SetError("Window does not exist"); |
467 SDL_SetError("Window does not exist"); |
483 if (NULL == view) { |
474 if (NULL == view) { |
484 SDL_SetError("Window has no view"); |
475 SDL_SetError("Window has no view"); |
485 return -1; |
476 return -1; |
486 } |
477 } |
487 else { |
478 else { |
488 if (SDL_iPhoneKeyboardIsShown(windowID)) { |
479 if (SDL_iPhoneKeyboardIsShown(window)) { |
489 SDL_iPhoneKeyboardHide(windowID); |
480 SDL_iPhoneKeyboardHide(window); |
490 } |
481 } |
491 else { |
482 else { |
492 SDL_iPhoneKeyboardShow(windowID); |
483 SDL_iPhoneKeyboardShow(window); |
493 } |
484 } |
494 return 0; |
485 return 0; |
495 } |
486 } |
496 } |
487 } |
497 |
488 |
498 #else |
489 #else |
499 |
490 |
500 /* stubs, used if compiled without keyboard support */ |
491 /* stubs, used if compiled without keyboard support */ |
501 |
492 |
502 int SDL_iPhoneKeyboardShow(SDL_WindowID windowID) { |
493 int SDL_iPhoneKeyboardShow(SDL_Window *window) { |
503 SDL_SetError("Not compiled with keyboard support"); |
494 SDL_SetError("Not compiled with keyboard support"); |
504 return -1; |
495 return -1; |
505 } |
496 } |
506 |
497 |
507 int SDL_iPhoneKeyboardHide(SDL_WindowID windowID) { |
498 int SDL_iPhoneKeyboardHide(SDL_Window *window) { |
508 SDL_SetError("Not compiled with keyboard support"); |
499 SDL_SetError("Not compiled with keyboard support"); |
509 return -1; |
500 return -1; |
510 } |
501 } |
511 |
502 |
512 SDL_bool SDL_iPhoneKeyboardIsShown(SDL_WindowID windowID) { |
503 SDL_bool SDL_iPhoneKeyboardIsShown(SDL_Window *window) { |
513 return 0; |
504 return 0; |
514 } |
505 } |
515 |
506 |
516 int SDL_iPhoneKeyboardToggle(SDL_WindowID windowID) { |
507 int SDL_iPhoneKeyboardToggle(SDL_Window *window) { |
517 SDL_SetError("Not compiled with keyboard support"); |
508 SDL_SetError("Not compiled with keyboard support"); |
518 return -1; |
509 return -1; |
519 } |
510 } |
520 |
511 |
521 |
512 |