project_files/HedgewarsMobile/Classes/OverlayViewController.m
changeset 3680 aaf832c6fbd7
parent 3672 f225b94a4411
child 3697 d5b30d6373fc
equal deleted inserted replaced
3678:00428183300f 3680:aaf832c6fbd7
    41     [UIView beginAnimations:@"rotation" context:NULL];
    41     [UIView beginAnimations:@"rotation" context:NULL];
    42     [UIView setAnimationDuration:0.8f];
    42     [UIView setAnimationDuration:0.8f];
    43     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    43     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    44     switch (orientation) {
    44     switch (orientation) {
    45         case UIDeviceOrientationLandscapeLeft:
    45         case UIDeviceOrientationLandscapeLeft:
    46             sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
    46             sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(0));
    47             self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
    47             self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
    48             HW_setLandscape(YES);
    48             HW_setLandscape(YES);
    49             break;
    49             break;
    50         case UIDeviceOrientationLandscapeRight:
    50         case UIDeviceOrientationLandscapeRight:
    51             sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
    51             sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(180));
    52             self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
    52             self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
    53             HW_setLandscape(YES);
    53             HW_setLandscape(YES);
    54             break;
    54             break;
    55         /*
    55         /*
    56         case UIDeviceOrientationPortrait:
    56         case UIDeviceOrientationPortrait:
    57             if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    57             if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    88     // set initial orientation
    88     // set initial orientation
    89     UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    89     UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    90     UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG];
    90     UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG];
    91     switch (orientation) {
    91     switch (orientation) {
    92         case UIDeviceOrientationLandscapeLeft:
    92         case UIDeviceOrientationLandscapeLeft:
    93             sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
    93             sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(0));
    94             self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
    94             self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
    95             break;
    95             break;
    96         case UIDeviceOrientationLandscapeRight:
    96         case UIDeviceOrientationLandscapeRight:
    97             sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(180));
    97             sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(180));
    98             self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90));
    98             self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
    99             break;
    99             break;
   100         default:
   100         default:
   101             break;
   101             break;
   102     }
   102     }
   103     CGRect rect = [[UIScreen mainScreen] bounds];
   103     CGRect rect = [[UIScreen mainScreen] bounds];
   358     
   358     
   359     switch ([allTouches count]) {
   359     switch ([allTouches count]) {
   360         case 1:
   360         case 1:
   361             // if we're in the menu we just click in the point
   361             // if we're in the menu we just click in the point
   362             if (HW_isAmmoOpen()) {
   362             if (HW_isAmmoOpen()) {
   363                 HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y));
   363                 HW_setCursor(HWXZ(currentPosition.x), HWYZ(currentPosition.y));
   364                 // this click doesn't need any wrapping because the ammoMenu already limits the cursor
   364                 // this click doesn't need any wrapping because the ammoMenu already limits the cursor
   365                 HW_click();
   365                 HW_click();
   366             } else 
   366             } else 
   367                 // if weapon requires a further click, ask for tapping again
   367                 // if weapon requires a further click, ask for tapping again
   368                 if (HW_isWeaponRequiringClick()) {
   368                 if (HW_isWeaponRequiringClick()) {
   460     switch ([allTouches count]) {
   460     switch ([allTouches count]) {
   461         case 1:
   461         case 1:
   462             touch = [[allTouches allObjects] objectAtIndex:0];
   462             touch = [[allTouches allObjects] objectAtIndex:0];
   463             CGPoint currentPosition = [touch locationInView:self.view];
   463             CGPoint currentPosition = [touch locationInView:self.view];
   464 
   464 
   465             if (HW_isAmmoOpen() || HW_isWeaponRequiringClick()) {
   465             if (HW_isAmmoOpen()) {
   466                 // moves the cursor around
   466                 // no zoom consideration for this
   467                 HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y));
   467                 HW_setCursor(HWXZ(currentPosition.x), HWYZ(currentPosition.y));
   468             } else {
   468             } else
   469                 // panning \o/
   469                 if (HW_isWeaponRequiringClick()) {
   470                 dx = startingPoint.x - currentPosition.x;
   470                     // moves the cursor around wrt zoom
   471                 dy = currentPosition.y - startingPoint.y;
   471                     HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y));
   472                 HW_getCursor(&x, &y);
   472                 } else {
   473                 // momentum (or something like that)
   473                     // panning \o/
   474                 if (abs(dx) > 40) dx *= log(abs(dx)/4);
   474                     dx = startingPoint.x - currentPosition.x;
   475                 if (abs(dy) > 40) dy *= log(abs(dy)/4);
   475                     dy = currentPosition.y - startingPoint.y;
   476                 HW_setCursor(x + dx, y + dy);
   476                     HW_getCursor(&x, &y);
   477                 startingPoint = currentPosition;
   477                     // momentum (or something like that)
   478             }
   478                     /*if (abs(dx) > 40)
       
   479                         dx *= log(abs(dx)/4);
       
   480                     if (abs(dy) > 40)
       
   481                         dy *= log(abs(dy)/4);*/
       
   482                     HW_setCursor(x + dx/HW_zoomFactor(), y + dy/HW_zoomFactor());
       
   483                     startingPoint = currentPosition;
       
   484                 }
   479             break;
   485             break;
   480         case 2:
   486         case 2:
   481             first = [[allTouches allObjects] objectAtIndex:0];
   487             first = [[allTouches allObjects] objectAtIndex:0];
   482             second = [[allTouches allObjects] objectAtIndex:1];
   488             second = [[allTouches allObjects] objectAtIndex:1];
   483             CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]);
   489             CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]);