55 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(180)); |
55 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(180)); |
56 self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90)); |
56 self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90)); |
57 [self chatDisappear]; |
57 [self chatDisappear]; |
58 HW_setLandscape(YES); |
58 HW_setLandscape(YES); |
59 break; |
59 break; |
|
60 /* |
60 case UIDeviceOrientationPortrait: |
61 case UIDeviceOrientationPortrait: |
61 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
62 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
62 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(270)); |
63 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(270)); |
63 self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0)); |
64 self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0)); |
64 [self chatAppear]; |
65 [self chatAppear]; |
240 |
242 |
241 // show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize |
243 // show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize |
242 // on iphone instead just use the tableViewController directly (and implement manually all animations) |
244 // on iphone instead just use the tableViewController directly (and implement manually all animations) |
243 -(IBAction) showPopover{ |
245 -(IBAction) showPopover{ |
244 isPopoverVisible = YES; |
246 isPopoverVisible = YES; |
245 CGRect anchorForPopover; |
|
246 |
247 |
247 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
248 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
248 if (popupMenu == nil) |
249 if (popupMenu == nil) |
249 popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStylePlain]; |
250 popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStylePlain]; |
250 if (popoverController == nil) { |
251 if (popoverController == nil) { |
251 popoverController = [[UIPopoverController alloc] initWithContentViewController:popupMenu]; |
252 popoverController = [[UIPopoverController alloc] initWithContentViewController:popupMenu]; |
252 [popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES]; |
253 [popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES]; |
253 [popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]]; |
254 [popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]]; |
254 } |
255 } |
255 |
256 |
256 if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation])) |
257 [popoverController presentPopoverFromRect:CGRectMake(1000, 0, 220, 32) |
257 anchorForPopover = CGRectMake(960, 0, 220, 32); |
|
258 else |
|
259 anchorForPopover = CGRectMake(736, 0, 220, 32); |
|
260 |
|
261 [popoverController presentPopoverFromRect:anchorForPopover |
|
262 inView:self.view |
258 inView:self.view |
263 permittedArrowDirections:UIPopoverArrowDirectionUp |
259 permittedArrowDirections:UIPopoverArrowDirectionUp |
264 animated:YES]; |
260 animated:YES]; |
265 } else { |
261 } else { |
266 if (popupMenu == nil) { |
262 if (popupMenu == nil) { |
301 [sender resignFirstResponder]; |
297 [sender resignFirstResponder]; |
302 } |
298 } |
303 |
299 |
304 // this function is called by pascal FinishProgress and removes the spinning wheel when loading is done |
300 // this function is called by pascal FinishProgress and removes the spinning wheel when loading is done |
305 void spinningWheelDone (void) { |
301 void spinningWheelDone (void) { |
306 [UIView beginAnimations:@"hiding spinning wheel" context:NULL]; |
302 [singleton stopAnimating]; |
307 [UIView setAnimationDuration:0.7]; |
303 singleton = nil; |
308 singleton.alpha = 0; |
|
309 [UIView commitAnimations]; |
|
310 [singleton performSelector:@selector(stopAnimating) withObject:nil afterDelay:0.7]; |
|
311 canDim = YES; |
304 canDim = YES; |
312 } |
305 } |
313 |
306 |
314 #pragma mark - |
307 #pragma mark - |
315 #pragma mark Custom touch event handling |
308 #pragma mark Custom touch event handling |
316 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
309 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
317 NSArray *twoTouches; |
310 NSArray *twoTouches; |
318 UITouch *touch = [touches anyObject]; |
311 UITouch *touch = [touches anyObject]; |
|
312 CGRect screen = [[UIScreen mainScreen] bounds]; |
|
313 CGPoint currentPosition = [touch locationInView:self.view]; |
319 |
314 |
320 if (isPopoverVisible) { |
315 if (isPopoverVisible) { |
321 [self dismissPopover]; |
316 [self dismissPopover]; |
322 } |
317 } |
323 if (writeChatTextField) { |
318 if (writeChatTextField) { |
324 [self.writeChatTextField resignFirstResponder]; |
319 [self.writeChatTextField resignFirstResponder]; |
325 [dimTimer setFireDate:HIDING_TIME_DEFAULT]; |
320 [dimTimer setFireDate:HIDING_TIME_DEFAULT]; |
326 } |
321 } |
327 |
322 |
328 gestureStartPoint = [touch locationInView:self.view]; |
|
329 |
|
330 switch ([touches count]) { |
323 switch ([touches count]) { |
331 /*case 1: |
324 case 1: |
332 initialDistanceForPinching = 0; |
325 DLog(@"X:%d Y:%d", HWX(currentPosition.x), HWY(currentPosition.y)); |
333 switch ([touch tapCount]) { |
326 HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
334 case 1: |
327 break; |
335 NSLog(@"X:%d Y:%d", (int)gestureStartPoint.x, (int)gestureStartPoint.y ); |
|
336 //SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, |
|
337 // (int)gestureStartPoint.y, width - (int)gestureStartPoint.x); |
|
338 //HW_click(); |
|
339 break; |
|
340 case 2: |
|
341 HW_ammoMenu(); |
|
342 break; |
|
343 default: |
|
344 break; |
|
345 } |
|
346 break;*/ |
|
347 case 2: |
328 case 2: |
348 if (2 == [touch tapCount]) { |
329 if (2 == [touch tapCount] && currentPosition.y < screen.size.width - 100) { |
349 HW_zoomReset(); |
330 HW_ammoMenu(); |
|
331 //HW_zoomReset(); |
350 } |
332 } |
351 |
333 |
352 // pinching |
334 // pinching |
353 gestureStartPoint = CGPointMake(0, 0); |
|
354 twoTouches = [touches allObjects]; |
335 twoTouches = [touches allObjects]; |
355 UITouch *first = [twoTouches objectAtIndex:0]; |
336 UITouch *first = [twoTouches objectAtIndex:0]; |
356 UITouch *second = [twoTouches objectAtIndex:1]; |
337 UITouch *second = [twoTouches objectAtIndex:1]; |
357 initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
338 initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
358 break; |
339 break; |
361 } |
342 } |
362 |
343 |
363 } |
344 } |
364 |
345 |
365 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
346 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
366 gestureStartPoint = CGPointMake(0, 0); |
|
367 initialDistanceForPinching = 0; |
347 initialDistanceForPinching = 0; |
368 //HW_allKeysUp(); |
348 //HW_allKeysUp(); |
|
349 HW_click(); |
369 } |
350 } |
370 |
351 |
371 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
352 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
372 // this can happen if the user puts more than 5 touches on the screen at once, or perhaps in other circumstances |
353 // this can happen if the user puts more than 5 touches on the screen at once, or perhaps in other circumstances |
373 [self touchesEnded:touches withEvent:event]; |
354 [self touchesEnded:touches withEvent:event]; |
374 } |
355 } |
375 |
356 |
376 -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
357 -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
377 CGFloat minimumGestureLength; |
358 CGRect screen = [[UIScreen mainScreen] bounds]; |
378 int logCoeff; |
|
379 |
|
380 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
381 minimumGestureLength = 5.0f; |
|
382 logCoeff = 19; |
|
383 } else { |
|
384 minimumGestureLength = 3.0f; |
|
385 logCoeff = 3; |
|
386 } |
|
387 |
359 |
388 NSArray *twoTouches; |
360 NSArray *twoTouches; |
389 CGPoint currentPosition; |
361 CGPoint currentPosition; |
390 UITouch *touch = [touches anyObject]; |
362 UITouch *touch = [touches anyObject]; |
391 |
363 |
392 switch ([touches count]) { |
364 switch ([touches count]) { |
393 /*case 1: |
365 case 1: |
394 currentPosition = [touch locationInView:self.view]; |
366 if (HW_isAmmoOpen()) { |
395 // panning |
367 currentPosition = [touch locationInView:self.view]; |
396 CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x); |
368 DLog(@"X:%d Y:%d", HWX(currentPosition.x), HWY(currentPosition.y)); |
397 CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y); |
369 HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
398 |
|
399 // the two ifs are not mutually exclusive |
|
400 if (deltaX >= minimumGestureLength) { |
|
401 DLog(@"deltaX: %f deltaY: %f", deltaX, deltaY); |
|
402 if (currentPosition.x > gestureStartPoint.x) { |
|
403 HW_cursorLeft(logCoeff*log(deltaX)); |
|
404 } else { |
|
405 HW_cursorRight(logCoeff*log(deltaX)); |
|
406 } |
|
407 |
|
408 } |
|
409 if (deltaY >= minimumGestureLength) { |
|
410 DLog(@"deltaX: %f deltaY: %f", deltaX, deltaY); |
|
411 if (currentPosition.y < gestureStartPoint.y) { |
|
412 HW_cursorDown(logCoeff*log(deltaY)); |
|
413 } else { |
|
414 HW_cursorUp(logCoeff*log(deltaY)); |
|
415 } |
|
416 } |
370 } |
417 |
371 break; |
418 break;*/ |
|
419 case 2: |
372 case 2: |
420 twoTouches = [touches allObjects]; |
373 twoTouches = [touches allObjects]; |
421 UITouch *first = [twoTouches objectAtIndex:0]; |
374 UITouch *first = [twoTouches objectAtIndex:0]; |
422 UITouch *second = [twoTouches objectAtIndex:1]; |
375 UITouch *second = [twoTouches objectAtIndex:1]; |
423 CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
376 CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |