54 for (i=0; i<MAX_SIMULTANEOUS_TOUCHES; i++) { |
54 for (i=0; i<MAX_SIMULTANEOUS_TOUCHES; i++) { |
55 mice[i].id = i; |
55 mice[i].id = i; |
56 mice[i].driverdata = NULL; |
56 mice[i].driverdata = NULL; |
57 SDL_AddMouse(&mice[i], "Mouse", 0, 0, 1); |
57 SDL_AddMouse(&mice[i], "Mouse", 0, 0, 1); |
58 } |
58 } |
|
59 |
|
60 UIButton *attackButton; |
|
61 |
|
62 attackButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 90,60)]; |
|
63 [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]; |
|
68 [attackButton addTarget:[self superclass] action:@selector(attackButtonReleased) forControlEvents:UIControlEventTouchUpInside|UIControlEventTouchUpOutside]; |
|
69 [self insertSubview:attackButton atIndex:10]; |
|
70 [attackButton release]; |
|
71 |
59 self.multipleTouchEnabled = YES; |
72 self.multipleTouchEnabled = YES; |
60 |
73 |
61 return self; |
74 return self; |
62 |
75 } |
|
76 |
|
77 #pragma mark - |
|
78 #pragma mark Superclass methods |
|
79 +(void) attackButtonPressed { |
|
80 HW_shoot(); |
|
81 } |
|
82 |
|
83 +(void) attackButtonReleased { |
|
84 HW_allKeysUp(); |
63 } |
85 } |
64 |
86 |
65 #pragma mark - |
87 #pragma mark - |
66 #pragma mark Custom SDL_UIView input handling |
88 #pragma mark Custom SDL_UIView input handling |
67 |
89 |
113 } */ |
135 } */ |
114 |
136 |
115 UITouch *touch = [touches anyObject]; |
137 UITouch *touch = [touches anyObject]; |
116 gestureStartPoint = [touch locationInView:self]; |
138 gestureStartPoint = [touch locationInView:self]; |
117 |
139 |
|
140 // one tap - single click |
118 if (1 == [touch tapCount] ) { |
141 if (1 == [touch tapCount] ) { |
119 //SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].windowID, gestureStartPoint.x, gestureStartPoint.y); |
142 //SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].windowID, gestureStartPoint.x, gestureStartPoint.y); |
120 HW_click(); |
143 HW_click(); |
121 } |
144 } |
122 |
145 |
|
146 // two taps - right click |
123 if (2 == [touch tapCount] ) { |
147 if (2 == [touch tapCount] ) { |
124 HW_ammoMenu(); |
148 HW_ammoMenu(); |
125 } |
149 } |
126 |
150 |
|
151 // two taps with two fingers - middle click |
|
152 if (2 == [touch tapCount] && 2 == [touches count]) { |
|
153 HW_zoomReset(); |
|
154 } |
|
155 |
|
156 // two fingers - begin pinching |
127 if (2 == [touches count]) { |
157 if (2 == [touches count]) { |
128 NSArray *twoTouches = [touches allObjects]; |
158 NSArray *twoTouches = [touches allObjects]; |
129 UITouch *first = [twoTouches objectAtIndex:0]; |
159 UITouch *first = [twoTouches objectAtIndex:0]; |
130 UITouch *second = [twoTouches objectAtIndex:1]; |
160 UITouch *second = [twoTouches objectAtIndex:1]; |
131 initialDistance = distanceBetweenPoints([first locationInView:self], [second locationInView:self]); |
161 initialDistance = distanceBetweenPoints([first locationInView:self], [second locationInView:self]); |
164 all active touches are canceled. |
194 all active touches are canceled. |
165 */ |
195 */ |
166 [self touchesEnded: touches withEvent: event]; |
196 [self touchesEnded: touches withEvent: event]; |
167 } |
197 } |
168 |
198 |
169 |
|
170 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
199 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
171 UITouch *touch = [touches anyObject]; |
200 UITouch *touch = [touches anyObject]; |
172 CGPoint currentPosition = [touch locationInView:self]; |
201 CGPoint currentPosition = [touch locationInView:self]; |
173 |
202 |
174 CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x); |
203 CGFloat Xdiff = gestureStartPoint.x - currentPosition.x; |
175 CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y); |
204 CGFloat Ydiff = gestureStartPoint.y - currentPosition.y; |
|
205 CGFloat deltaX = fabsf(Xdiff); |
|
206 CGFloat deltaY = fabsf(Ydiff); |
176 |
207 |
177 if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance) { |
208 if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance) { |
178 NSLog(@"Horizontal swipe detected, begX:%f curX:%f", gestureStartPoint.x, currentPosition.x); |
209 NSLog(@"Horizontal swipe detected, begX:%f curX:%f", gestureStartPoint.x, currentPosition.x); |
179 HW_walkLeft(); |
210 if (Xdiff > 0) HW_walkLeft(); |
|
211 else HW_walkRight(); |
180 } |
212 } |
181 else if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance){ |
213 else if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance){ |
182 NSLog(@"Vertical swipe detected, begY:%f curY:%f", gestureStartPoint.y, currentPosition.y); |
214 NSLog(@"Vertical swipe detected, begY:%f curY:%f", gestureStartPoint.y, currentPosition.y); |
183 HW_walkRight(); |
215 if (Ydiff > 0) HW_aimUp(); |
184 } |
216 else HW_aimDown(); |
|
217 } |
185 |
218 |
186 if (2 == [touches count]) { |
219 if (2 == [touches count]) { |
187 NSArray *twoTouches = [touches allObjects]; |
220 NSArray *twoTouches = [touches allObjects]; |
188 UITouch *first = [twoTouches objectAtIndex:0]; |
221 UITouch *first = [twoTouches objectAtIndex:0]; |
189 UITouch *second = [twoTouches objectAtIndex:1]; |
222 UITouch *second = [twoTouches objectAtIndex:1]; |