project_files/HedgewarsMobile/Classes/OverlayViewController.m
changeset 3523 6592fbb969da
parent 3514 59dbd31e9953
child 3525 1d7b056ff866
equal deleted inserted replaced
3522:156c04c6a3d8 3523:6592fbb969da
    73                 [self chatAppear];
    73                 [self chatAppear];
    74                 HW_setLandscape(NO);
    74                 HW_setLandscape(NO);
    75             }
    75             }
    76             break;
    76             break;
    77         default:
    77         default:
    78             DLog(@"Unknown rotation status");
       
    79             break;
    78             break;
    80     }
    79     }
    81     self.view.frame = usefulRect;
    80     self.view.frame = usefulRect;
    82     //sdlView.frame = usefulRect;
    81     //sdlView.frame = usefulRect;
    83     [UIView commitAnimations];
    82     [UIView commitAnimations];
   106     writeChatTextField.alpha = 0;
   105     writeChatTextField.alpha = 0;
   107     [writeChatTextField resignFirstResponder];
   106     [writeChatTextField resignFirstResponder];
   108     [dimTimer setFireDate:HIDING_TIME_DEFAULT];
   107     [dimTimer setFireDate:HIDING_TIME_DEFAULT];
   109 }
   108 }
   110 
   109 
       
   110 #pragma mark -
       
   111 #pragma mark View Management
   111 -(void) viewDidLoad {
   112 -(void) viewDidLoad {
   112     isPopoverVisible = NO;
   113     isPopoverVisible = NO;
   113     self.view.alpha = 0;
   114     self.view.alpha = 0;
   114     self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0);
   115     self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0);
   115     
   116     
   158     [popoverController release];
   159     [popoverController release];
   159     // dimTimer is autoreleased
   160     // dimTimer is autoreleased
   160     [super dealloc];
   161     [super dealloc];
   161 }
   162 }
   162 
   163 
       
   164 #pragma mark -
       
   165 #pragma mark Overlay actions and members
   163 // dim the overlay when there's no more input for a certain amount of time
   166 // dim the overlay when there's no more input for a certain amount of time
   164 -(IBAction) buttonReleased:(id) sender {
   167 -(IBAction) buttonReleased:(id) sender {
   165 	HW_allKeysUp();
   168 	HW_allKeysUp();
   166     [dimTimer setFireDate:HIDING_TIME_DEFAULT];
   169     [dimTimer setFireDate:HIDING_TIME_DEFAULT];
   167 }
   170 }
   295     [sender resignFirstResponder];
   298     [sender resignFirstResponder];
   296 }
   299 }
   297 
   300 
   298 #pragma mark -
   301 #pragma mark -
   299 #pragma mark Custom touch event handling
   302 #pragma mark Custom touch event handling
   300 
       
   301 #define kMinimumPinchDelta      50
       
   302 
       
   303 
       
   304 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   303 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   305 	NSArray *twoTouches;
   304 	NSArray *twoTouches;
   306 	UITouch *touch = [touches anyObject];
   305 	UITouch *touch = [touches anyObject];
   307     
   306     
   308     if (isPopoverVisible) {
   307     if (isPopoverVisible) {
   314     }
   313     }
   315     
   314     
   316     gestureStartPoint = [touch locationInView:self.view];
   315     gestureStartPoint = [touch locationInView:self.view];
   317         
   316         
   318 	switch ([touches count]) {
   317 	switch ([touches count]) {
   319 		case 1:
   318 		/*case 1:
   320 			initialDistanceForPinching = 0;
   319 			initialDistanceForPinching = 0;
   321 			switch ([touch tapCount]) {
   320 			switch ([touch tapCount]) {
   322 				case 1:
   321 				case 1:
   323 					NSLog(@"X:%d Y:%d", (int)gestureStartPoint.x, (int)gestureStartPoint.y );
   322 					NSLog(@"X:%d Y:%d", (int)gestureStartPoint.x, (int)gestureStartPoint.y );
   324 					//SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
   323 					//SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
   329 					HW_ammoMenu();
   328 					HW_ammoMenu();
   330 					break;
   329 					break;
   331 				default:
   330 				default:
   332 					break;
   331 					break;
   333 			}
   332 			}
   334 			break;
   333 			break;*/
   335 		case 2:
   334 		case 2:
   336 			if (2 == [touch tapCount]) {
   335 			if (2 == [touch tapCount]) {
   337 				HW_zoomReset();
   336 				HW_zoomReset();
   338 			}
   337 			}
   339 			
   338 			
   340 			// pinching
   339 			// pinching
   341             gestureStartPoint.x = 0;
   340             gestureStartPoint = CGPointMake(0, 0);
   342             gestureStartPoint.y = 0;
       
   343 			twoTouches = [touches allObjects];
   341 			twoTouches = [touches allObjects];
   344 			UITouch *first = [twoTouches objectAtIndex:0];
   342 			UITouch *first = [twoTouches objectAtIndex:0];
   345 			UITouch *second = [twoTouches objectAtIndex:1];
   343 			UITouch *second = [twoTouches objectAtIndex:1];
   346 			initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]);
   344 			initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]);
   347 			break;
   345 			break;
   350 	}
   348 	}
   351 
   349 
   352 }
   350 }
   353 
   351 
   354 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   352 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
       
   353     gestureStartPoint = CGPointMake(0, 0);
   355 	initialDistanceForPinching = 0;
   354 	initialDistanceForPinching = 0;
   356 	HW_allKeysUp();
   355 	//HW_allKeysUp();
   357 }
   356 }
   358 
   357 
   359 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
   358 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
   360 	// this can happen if the user puts more than 5 touches on the screen at once, or perhaps in other circumstances
   359 	// this can happen if the user puts more than 5 touches on the screen at once, or perhaps in other circumstances
   361 	[self touchesEnded:touches withEvent:event];
   360 	[self touchesEnded:touches withEvent:event];
   376 	NSArray *twoTouches;
   375 	NSArray *twoTouches;
   377 	CGPoint currentPosition;
   376 	CGPoint currentPosition;
   378 	UITouch *touch = [touches anyObject];
   377 	UITouch *touch = [touches anyObject];
   379 
   378 
   380 	switch ([touches count]) {
   379 	switch ([touches count]) {
   381 		case 1:
   380 		/*case 1:
   382 			currentPosition = [touch locationInView:self.view];
   381 			currentPosition = [touch locationInView:self.view];
   383 			// panning
   382 			// panning
   384 			CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
   383 			CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
   385 			CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);
   384 			CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);
   386 			
   385 			
       
   386             // the two ifs are not mutually exclusive
   387             if (deltaX >= minimumGestureLength) {
   387             if (deltaX >= minimumGestureLength) {
   388                 NSLog(@"Horizontal swipe detected, deltaX: %f deltaY: %f",deltaX, deltaY);
   388                 Dlog(@"deltaX: %f deltaY: %f", deltaX, deltaY);
   389                 if (currentPosition.x > gestureStartPoint.x) {
   389                 if (currentPosition.x > gestureStartPoint.x) {
   390                     HW_cursorLeft(logCoeff*log(deltaX));
   390                     HW_cursorLeft(logCoeff*log(deltaX));
   391                 } else {
   391                 } else {
   392                     HW_cursorRight(logCoeff*log(deltaX));
   392                     HW_cursorRight(logCoeff*log(deltaX));
   393                 }
   393                 }
   394 
   394 
   395             } 
   395             } 
   396             if (deltaY >= minimumGestureLength) {
   396             if (deltaY >= minimumGestureLength) {
   397                 NSLog(@"Horizontal swipe detected, deltaX: %f deltaY: %f",deltaX, deltaY);
   397                 DLog(@"deltaX: %f deltaY: %f", deltaX, deltaY);
   398                 if (currentPosition.y < gestureStartPoint.y) {
   398                 if (currentPosition.y < gestureStartPoint.y) {
   399                     HW_cursorDown(logCoeff*log(deltaY));
   399                     HW_cursorDown(logCoeff*log(deltaY));
   400                 } else {
   400                 } else {
   401                     HW_cursorUp(logCoeff*log(deltaY));
   401                     HW_cursorUp(logCoeff*log(deltaY));
   402                 }            
   402                 }            
   403             }
   403             }
   404 
   404 
   405 			break;
   405 			break;*/
   406 		case 2:
   406 		case 2:
   407 			twoTouches = [touches allObjects];
   407 			twoTouches = [touches allObjects];
   408 			UITouch *first = [twoTouches objectAtIndex:0];
   408 			UITouch *first = [twoTouches objectAtIndex:0];
   409 			UITouch *second = [twoTouches objectAtIndex:1];
   409 			UITouch *second = [twoTouches objectAtIndex:1];
   410 			CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]);
   410 			CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]);
   411 			
   411 			const int pinchDelta = 40;
   412 			if (0 == initialDistanceForPinching) 
   412             
   413 				initialDistanceForPinching = currentDistanceOfPinching;
   413 			if (0 != initialDistanceForPinching) {
   414 
   414                 if (currentDistanceOfPinching - initialDistanceForPinching > pinchDelta) {
   415 			if (currentDistanceOfPinching < initialDistanceForPinching + kMinimumPinchDelta)
   415                     HW_zoomIn();
   416 				HW_zoomOut();
   416                     initialDistanceForPinching = currentDistanceOfPinching;
   417 			else if (currentDistanceOfPinching > initialDistanceForPinching + kMinimumPinchDelta)
   417                 }
   418 				HW_zoomIn();
   418                 else if (initialDistanceForPinching - currentDistanceOfPinching > pinchDelta) {
   419 
   419                     HW_zoomOut();
   420 			currentDistanceOfPinching = initialDistanceForPinching;
   420                     initialDistanceForPinching = currentDistanceOfPinching;
       
   421                 }
       
   422             } else 
       
   423                 initialDistanceForPinching = currentDistanceOfPinching;
       
   424             
   421 			break;
   425 			break;
   422 		default:
   426 		default:
   423 			break;
   427 			break;
   424 	}
   428 	}
   425 }
   429 }