32 |
32 |
33 @implementation SDL_uikitview |
33 @implementation SDL_uikitview |
34 |
34 |
35 @synthesize initialDistance, gestureStartPoint; |
35 @synthesize initialDistance, gestureStartPoint; |
36 |
36 |
|
37 // they have to be global variables to allow showControls() to use them |
|
38 UIButton *attackButton, *menuButton; |
|
39 |
37 - (void)dealloc { |
40 - (void)dealloc { |
38 #if SDL_IPHONE_KEYBOARD |
41 #if SDL_IPHONE_KEYBOARD |
39 SDL_DelKeyboard(0); |
42 SDL_DelKeyboard(0); |
40 [textField release]; |
43 [textField release]; |
41 #endif |
44 #endif |
|
45 [menuButton release]; |
|
46 [attackButton release]; |
42 [super dealloc]; |
47 [super dealloc]; |
43 } |
48 } |
44 |
49 |
45 - (id)initWithFrame:(CGRect)frame { |
50 - (id)initWithFrame:(CGRect)frame { |
46 |
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 |
47 self = [super initWithFrame: frame]; |
55 self = [super initWithFrame: frame]; |
48 |
56 |
49 #if SDL_IPHONE_KEYBOARD |
57 #if SDL_IPHONE_KEYBOARD |
50 [self initializeKeyboard]; |
58 [self initializeKeyboard]; |
51 #endif |
59 #endif |
54 for (i=0; i<MAX_SIMULTANEOUS_TOUCHES; i++) { |
62 for (i=0; i<MAX_SIMULTANEOUS_TOUCHES; i++) { |
55 mice[i].id = i; |
63 mice[i].id = i; |
56 mice[i].driverdata = NULL; |
64 mice[i].driverdata = NULL; |
57 SDL_AddMouse(&mice[i], "Mouse", 0, 0, 1); |
65 SDL_AddMouse(&mice[i], "Mouse", 0, 0, 1); |
58 } |
66 } |
59 |
67 |
60 UIButton *attackButton; |
68 attackButton = [[UIButton alloc] initWithFrame:CGRectMake(30, 480, 260,50)]; |
61 |
|
62 attackButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 90,60)]; |
|
63 [attackButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateNormal]; |
69 [attackButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateNormal]; |
64 // this object is inherited by SDL_openglesview.m which is the one allocated by SDL. |
|
65 // We select this class with [self superclass] and call the selectors with "+" because |
|
66 // they are superclass methods |
|
67 [attackButton addTarget:[self superclass] action:@selector(attackButtonPressed) forControlEvents:UIControlEventTouchDown]; |
70 [attackButton addTarget:[self superclass] action:@selector(attackButtonPressed) forControlEvents:UIControlEventTouchDown]; |
68 [attackButton addTarget:[self superclass] action:@selector(attackButtonReleased) forControlEvents:UIControlEventTouchUpInside|UIControlEventTouchUpOutside]; |
71 [attackButton addTarget:[self superclass] action:@selector(attackButtonReleased) forControlEvents:UIControlEventTouchUpInside|UIControlEventTouchUpOutside]; |
69 [self insertSubview:attackButton atIndex:10]; |
72 [self addSubview:attackButton]; |
70 [attackButton release]; |
73 |
|
74 menuButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 480, 30,50)]; |
|
75 [menuButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateNormal]; |
|
76 [menuButton addTarget:[self superclass] action:@selector(attackButtonPressed) forControlEvents:UIControlEventTouchUpInside]; |
|
77 [self addSubview:menuButton]; |
71 |
78 |
72 self.multipleTouchEnabled = YES; |
79 self.multipleTouchEnabled = YES; |
73 |
80 |
74 return self; |
81 return self; |
|
82 } |
|
83 |
|
84 #pragma mark - |
|
85 #pragma mark Show and Hide overlaid buttons |
|
86 |
|
87 // standard C function to be called from pascal |
|
88 void showControls(void) { |
|
89 NSLog(@"Showing controls"); |
|
90 [UIView beginAnimations:nil context:NULL]; |
|
91 [UIView setAnimationDuration:0.5]; |
|
92 attackButton.frame = CGRectMake(30, 430, 260, 50); |
|
93 menuButton.frame = CGRectMake(0, 430, 30, 50); |
|
94 [UIView commitAnimations]; |
75 } |
95 } |
76 |
96 |
77 #pragma mark - |
97 #pragma mark - |
78 #pragma mark Superclass methods |
98 #pragma mark Superclass methods |
|
99 |
79 +(void) attackButtonPressed { |
100 +(void) attackButtonPressed { |
80 HW_shoot(); |
101 HW_shoot(); |
81 } |
102 } |
82 |
103 |
83 +(void) attackButtonReleased { |
104 +(void) attackButtonReleased { |