cocoaTouch/SDLOverrides/SDL_uikitview.m
changeset 2734 fb9ad1587054
parent 2725 89908847b155
child 2738 bfccb2ec4334
equal deleted inserted replaced
2733:52a5a160566f 2734:fb9ad1587054
    74 	[self addSubview:attackButton];
    74 	[self addSubview:attackButton];
    75 
    75 
    76 	menuButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 480, 30,50)];
    76 	menuButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 480, 30,50)];
    77 	[menuButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateNormal];
    77 	[menuButton setBackgroundImage:[UIImage imageNamed:@"Default.png"] forState:UIControlStateNormal];
    78 	[menuButton addTarget:[self superclass] action:@selector(attackButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    78 	[menuButton addTarget:[self superclass] action:@selector(attackButtonPressed) forControlEvents:UIControlEventTouchUpInside];
       
    79 	[menuButton addTarget:[self superclass] action:@selector(attackButtonReleased) forControlEvents:UIControlEventTouchUpInside|UIControlEventTouchUpOutside];
    79 	[self addSubview:menuButton];
    80 	[self addSubview:menuButton];
    80 
    81 
    81 
    82 
    82 	return self;
    83 	return self;
    83 }
    84 }
    90 	return [documentsDirectory UTF8String];
    91 	return [documentsDirectory UTF8String];
    91 }
    92 }
    92 
    93 
    93 void IPH_showControls (void) {
    94 void IPH_showControls (void) {
    94 	NSLog(@"Showing controls");
    95 	NSLog(@"Showing controls");
    95 	/*[UIView beginAnimations:nil context:NULL];
    96 	/*
       
    97 	[UIView beginAnimations:nil context:NULL];
    96 	[UIView setAnimationDuration:0.5];
    98 	[UIView setAnimationDuration:0.5];
    97 	attackButton.frame = CGRectMake(30, 430, 260, 50);
    99 	attackButton.frame = CGRectMake(30, 430, 260, 50);
    98 	menuButton.frame = CGRectMake(0, 430, 30, 50);
   100 	menuButton.frame = CGRectMake(0, 430, 30, 50);
    99 	[UIView commitAnimations];
   101 	[UIView commitAnimations];
   100 */}
   102 	*/
       
   103 }
   101 
   104 
   102 #pragma mark -
   105 #pragma mark -
   103 #pragma mark Superclass methods
   106 #pragma mark Superclass methods
   104 +(void) attackButtonPressed {
   107 +(void) attackButtonPressed {
   105 	HW_shoot();
   108 	HW_shoot();
   172 		case 1:
   175 		case 1:
   173 			gestureStartPoint = [touch locationInView:self];
   176 			gestureStartPoint = [touch locationInView:self];
   174 			initialDistanceForPinching = 0;
   177 			initialDistanceForPinching = 0;
   175 			switch ([touch tapCount]) {
   178 			switch ([touch tapCount]) {
   176 				case 1:
   179 				case 1:
   177 					NSLog(@"x:%d y:%d",(int)gestureStartPoint.x,(int)gestureStartPoint.y);
   180 					SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
   178 					SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, (int)gestureStartPoint.y - 250, (int)gestureStartPoint.x);
   181 							      (int)gestureStartPoint.y, 320 - (int)gestureStartPoint.x);
   179 					HW_click();
   182 					HW_click();
   180 					break;
   183 					break;
   181 				case 2:
   184 				case 2:
   182 					HW_ammoMenu();
   185 					HW_ammoMenu();
   183 					break;
   186 					break;
   241 	UITouch *touch = [touches anyObject];
   244 	UITouch *touch = [touches anyObject];
   242 
   245 
   243 	switch ([touches count]) {
   246 	switch ([touches count]) {
   244 		case 1:
   247 		case 1:
   245 			currentPosition = [touch locationInView:self];
   248 			currentPosition = [touch locationInView:self];
   246 			
   249 			// panning
       
   250 			SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, 
       
   251 							(int)gestureStartPoint.y, 320 - (int)gestureStartPoint.x);
   247 			// remember that we have x and y inverted
   252 			// remember that we have x and y inverted
   248 			CGFloat vertDiff = gestureStartPoint.x - currentPosition.x;
   253 			/* temporarily disabling hog movements for camera panning testing
       
   254 			 CGFloat vertDiff = gestureStartPoint.x - currentPosition.x;
   249 			CGFloat horizDiff = gestureStartPoint.y - currentPosition.y;
   255 			CGFloat horizDiff = gestureStartPoint.y - currentPosition.y;
   250 			CGFloat deltaX = fabsf(vertDiff);
   256 			CGFloat deltaX = fabsf(vertDiff);
   251 			CGFloat deltaY = fabsf(horizDiff);
   257 			CGFloat deltaY = fabsf(horizDiff);
   252 			
   258 			
   253 			if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance) {
   259 			if (deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance) {
   257 			} else if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance){
   263 			} else if (deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance){
   258 				NSLog(@"Vertical swipe detected, begY:%f curY:%f", gestureStartPoint.y, currentPosition.y);
   264 				NSLog(@"Vertical swipe detected, begY:%f curY:%f", gestureStartPoint.y, currentPosition.y);
   259 				if (vertDiff < 0) HW_aimUp();
   265 				if (vertDiff < 0) HW_aimUp();
   260 				else HW_aimDown();
   266 				else HW_aimDown();
   261 			}
   267 			}
       
   268 			*/
   262 			break;
   269 			break;
   263 		case 2:
   270 		case 2:
   264 			twoTouches = [touches allObjects];
   271 			twoTouches = [touches allObjects];
   265 			UITouch *first = [twoTouches objectAtIndex:0];
   272 			UITouch *first = [twoTouches objectAtIndex:0];
   266 			UITouch *second = [twoTouches objectAtIndex:1];
   273 			UITouch *second = [twoTouches objectAtIndex:1];
   270 				initialDistanceForPinching = currentDistanceOfPinching;
   277 				initialDistanceForPinching = currentDistanceOfPinching;
   271 
   278 
   272 			if (currentDistanceOfPinching < initialDistanceForPinching + kMinimumPinchDelta) {
   279 			if (currentDistanceOfPinching < initialDistanceForPinching + kMinimumPinchDelta) {
   273 				NSLog(@"Outward pinch detected");
   280 				NSLog(@"Outward pinch detected");
   274 				HW_zoomOut();
   281 				HW_zoomOut();
   275 			}
   282 			} else if (currentDistanceOfPinching > initialDistanceForPinching + kMinimumPinchDelta){
   276 			if (currentDistanceOfPinching > initialDistanceForPinching + kMinimumPinchDelta){
       
   277 				NSLog(@"Inward pinch detected");
   283 				NSLog(@"Inward pinch detected");
   278 				HW_zoomIn();
   284 				HW_zoomIn();
   279 			}
   285 			} 			
   280 			
       
   281 			currentDistanceOfPinching = initialDistanceForPinching;
   286 			currentDistanceOfPinching = initialDistanceForPinching;
   282 			break;
   287 			break;
   283 		default:
   288 		default:
   284 			break;
   289 			break;
   285 	}
   290 	}