226 |
226 |
227 #pragma mark - |
227 #pragma mark - |
228 #pragma mark Custom touch event handling |
228 #pragma mark Custom touch event handling |
229 |
229 |
230 #define kMinimumPinchDelta 50 |
230 #define kMinimumPinchDelta 50 |
231 #define kMinimumGestureLength 10 |
231 |
232 #define kMaximumVariance 3 |
|
233 |
232 |
234 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
233 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
235 NSArray *twoTouches; |
234 NSArray *twoTouches; |
236 UITouch *touch = [touches anyObject]; |
235 UITouch *touch = [touches anyObject]; |
237 int width = [[UIScreen mainScreen] bounds].size.width; |
|
238 |
236 |
239 if (isPopoverVisible) { |
237 if (isPopoverVisible) { |
240 [self dismissPopover]; |
238 [self dismissPopover]; |
241 } |
239 } |
|
240 |
|
241 gestureStartPoint = [touch locationInView:self.view]; |
242 |
242 |
243 switch ([touches count]) { |
243 switch ([touches count]) { |
244 case 1: |
244 case 1: |
245 gestureStartPoint = [touch locationInView:self.view]; |
|
246 initialDistanceForPinching = 0; |
245 initialDistanceForPinching = 0; |
247 switch ([touch tapCount]) { |
246 switch ([touch tapCount]) { |
248 case 1: |
247 case 1: |
249 NSLog(@"X:%d Y:%d", (int)gestureStartPoint.x, (int)gestureStartPoint.y ); |
248 NSLog(@"X:%d Y:%d", (int)gestureStartPoint.x, (int)gestureStartPoint.y ); |
250 SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, |
249 //SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, |
251 (int)gestureStartPoint.y, width - (int)gestureStartPoint.x); |
250 // (int)gestureStartPoint.y, width - (int)gestureStartPoint.x); |
252 HW_click(); |
251 //HW_click(); |
253 break; |
252 break; |
254 case 2: |
253 case 2: |
255 HW_ammoMenu(); |
254 HW_ammoMenu(); |
256 break; |
255 break; |
257 default: |
256 default: |
275 |
276 |
276 } |
277 } |
277 |
278 |
278 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
279 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
279 initialDistanceForPinching = 0; |
280 initialDistanceForPinching = 0; |
280 gestureStartPoint.x = 0; |
|
281 gestureStartPoint.y = 0; |
|
282 HW_allKeysUp(); |
281 HW_allKeysUp(); |
283 } |
282 } |
284 |
283 |
285 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
284 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
286 // this can happen if the user puts more than 5 touches on the screen at once, or perhaps in other circumstances. |
285 // this can happen if the user puts more than 5 touches on the screen at once, or perhaps in other circumstances |
287 [self touchesEnded:touches withEvent:event]; |
286 [self touchesEnded:touches withEvent:event]; |
288 } |
287 } |
289 |
288 |
290 -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
289 -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
|
290 int minimumGestureLength; |
|
291 int logCoeff; |
|
292 |
|
293 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
294 minimumGestureLength = 5; |
|
295 logCoeff = 19; |
|
296 } else { |
|
297 minimumGestureLength = 3; |
|
298 logCoeff = 3; |
|
299 } |
|
300 |
291 NSArray *twoTouches; |
301 NSArray *twoTouches; |
292 CGPoint currentPosition; |
302 CGPoint currentPosition; |
293 UITouch *touch = [touches anyObject]; |
303 UITouch *touch = [touches anyObject]; |
294 int width = [[UIScreen mainScreen] bounds].size.width; |
|
295 |
304 |
296 switch ([touches count]) { |
305 switch ([touches count]) { |
297 case 1: |
306 case 1: |
298 currentPosition = [touch locationInView:self.view]; |
307 currentPosition = [touch locationInView:self.view]; |
299 // panning |
308 // panning |
300 SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, |
309 CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x); |
301 (int)gestureStartPoint.y, width - (int)gestureStartPoint.x); |
310 CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y); |
302 // remember that we have x and y inverted |
|
303 /* temporarily disabling hog movements for camera panning testing |
|
304 CGFloat vertDiff = gestureStartPoint.x - currentPosition.x; |
|
305 CGFloat horizDiff = gestureStartPoint.y - currentPosition.y; |
|
306 CGFloat deltaX = fabsf(vertDiff); |
|
307 CGFloat deltaY = fabsf(horizDiff); |
|
308 |
311 |
309 if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance) { |
312 if (deltaX >= minimumGestureLength) { |
310 NSLog(@"Horizontal swipe detected, begX:%f curX:%f", gestureStartPoint.x, currentPosition.x); |
313 NSLog(@"Horizontal swipe detected, deltaX: %f deltaY: %f",deltaX, deltaY); |
311 if (horizDiff > 0) HW_walkLeft(); |
314 if (currentPosition.x > gestureStartPoint.x ) { |
312 else HW_walkRight(); |
315 NSLog(@"Right movement"); |
313 } else if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance){ |
316 HW_cursorRight(logCoeff*log(deltaX)); |
314 NSLog(@"Vertical swipe detected, begY:%f curY:%f", gestureStartPoint.y, currentPosition.y); |
317 } else { |
315 if (vertDiff < 0) HW_aimUp(); |
318 NSLog(@"Left movement"); |
316 else HW_aimDown(); |
319 HW_cursorLeft(logCoeff*log(deltaX)); |
317 } |
320 } |
318 */ |
321 |
|
322 } |
|
323 if (deltaY >= minimumGestureLength) { |
|
324 NSLog(@"Horizontal swipe detected, deltaX: %f deltaY: %f",deltaX, deltaY); |
|
325 if (currentPosition.y < gestureStartPoint.y ) { |
|
326 NSLog(@"Up movement"); |
|
327 HW_cursorUp(logCoeff*log(deltaY)); |
|
328 } else { |
|
329 HW_cursorDown(logCoeff*log(deltaY)); |
|
330 NSLog(@"Down movement"); |
|
331 } |
|
332 } |
|
333 |
319 break; |
334 break; |
320 case 2: |
335 case 2: |
321 twoTouches = [touches allObjects]; |
336 twoTouches = [touches allObjects]; |
322 UITouch *first = [twoTouches objectAtIndex:0]; |
337 UITouch *first = [twoTouches objectAtIndex:0]; |
323 UITouch *second = [twoTouches objectAtIndex:1]; |
338 UITouch *second = [twoTouches objectAtIndex:1]; |