project_files/HedgewarsMobile/Classes/OverlayViewController.m
changeset 5109 6d2e8a24277e
parent 4976 088d40d8aba2
child 5154 851f36579ed4
equal deleted inserted replaced
5106:517bdd3865f1 5109:6d2e8a24277e
    37 
    37 
    38 #define removeInputWidget() [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview]; \
    38 #define removeInputWidget() [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview]; \
    39                             [[self.view viewWithTag:GRENADE_TAG] removeFromSuperview];
    39                             [[self.view viewWithTag:GRENADE_TAG] removeFromSuperview];
    40 
    40 
    41 @implementation OverlayViewController
    41 @implementation OverlayViewController
    42 @synthesize popoverController, popupMenu, helpPage, amvc, isNetGame, useClassicMenu, initialOrientation, containerWindow;
    42 @synthesize popoverController, popupMenu, helpPage, amvc, isNetGame, useClassicMenu, initialOrientation;
    43 
    43 
    44 #pragma mark -
    44 #pragma mark -
    45 #pragma mark rotation
    45 #pragma mark rotation
       
    46 
    46 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    47 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    47     // don't rotate until the game is running for performance and synchronization with the sdlview
    48     // don't rotate until the game is running for performance and synchronization with the sdlview
    48     if (isGameRunning() == NO)
    49     if (isGameRunning() == NO)
    49         return (interfaceOrientation == (UIInterfaceOrientation) self.initialOrientation);
    50         return (interfaceOrientation == (UIInterfaceOrientation) self.initialOrientation);
    50     return rotationManager(interfaceOrientation);
    51     return rotationManager(interfaceOrientation);
    96 -(void) dualHeadRotation:(NSNotification *)notification {
    97 -(void) dualHeadRotation:(NSNotification *)notification {
    97     if (isGameRunning() == NO)
    98     if (isGameRunning() == NO)
    98         return;
    99         return;
    99 
   100 
   100     UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
   101     UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
   101     
   102     UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG];
       
   103 
   102     [UIView beginAnimations:@"rotation" context:NULL];
   104     [UIView beginAnimations:@"rotation" context:NULL];
   103     [UIView setAnimationDuration:0.7];
   105     [UIView setAnimationDuration:0.7];
   104     switch (orientation) {
   106     switch (orientation) {
   105         case UIDeviceOrientationLandscapeLeft:
   107         case UIDeviceOrientationLandscapeLeft:
   106             self.view.frame = [[UIScreen mainScreen] bounds];
   108             self.view.frame = [[UIScreen mainScreen] bounds];
   107             self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
   109             self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
       
   110             sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(a));
   108             break;
   111             break;
   109         case UIDeviceOrientationLandscapeRight:
   112         case UIDeviceOrientationLandscapeRight:
   110             self.view.frame = [[UIScreen mainScreen] bounds];
   113             self.view.frame = [[UIScreen mainScreen] bounds];
   111             self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
   114             self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
       
   115             sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(b));
   112             break;
   116             break;
   113         default:
   117         default:
   114             // a debug log would spam too much
   118             // a debug log would spam too much
   115             break;
   119             break;
   116     }
   120     }
   149         initialScreenCount = [[UIScreen screens] count];
   153         initialScreenCount = [[UIScreen screens] count];
   150     else
   154     else
   151         initialScreenCount = 1;
   155         initialScreenCount = 1;
   152 
   156 
   153     // set initial orientation of the controller orientation
   157     // set initial orientation of the controller orientation
   154     if (IS_DUALHEAD()) {
       
   155         switch (self.interfaceOrientation) {
   158         switch (self.interfaceOrientation) {
   156             case UIDeviceOrientationLandscapeLeft:
   159             case UIDeviceOrientationLandscapeLeft:
   157                 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
   160                 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
   158                 break;
   161                 break;
   159             case UIDeviceOrientationLandscapeRight:
   162             case UIDeviceOrientationLandscapeRight:
   166         [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
   169         [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
   167         [[NSNotificationCenter defaultCenter] addObserver:self
   170         [[NSNotificationCenter defaultCenter] addObserver:self
   168                                                  selector:@selector(dualHeadRotation:)
   171                                                  selector:@selector(dualHeadRotation:)
   169                                                      name:UIDeviceOrientationDidChangeNotification
   172                                                      name:UIDeviceOrientationDidChangeNotification
   170                                                    object:nil];
   173                                                    object:nil];
   171     }
       
   172 
   174 
   173     // the timer used to dim the overlay
   175     // the timer used to dim the overlay
   174     dimTimer = [[NSTimer alloc] initWithFireDate:(IS_DUALHEAD()) ? HIDING_TIME_NEVER : [NSDate dateWithTimeIntervalSinceNow:6]
   176     dimTimer = [[NSTimer alloc] initWithFireDate:(IS_DUALHEAD()) ? HIDING_TIME_NEVER : [NSDate dateWithTimeIntervalSinceNow:6]
   175                                         interval:1000
   177                                         interval:1000
   176                                           target:self
   178                                           target:self
   203                                                  selector:@selector(numberOfScreensDecreased)
   205                                                  selector:@selector(numberOfScreensDecreased)
   204                                                      name:UIScreenDidDisconnectNotification
   206                                                      name:UIScreenDidDisconnectNotification
   205                                                    object:nil];
   207                                                    object:nil];
   206     }
   208     }
   207     
   209     
   208     self.containerWindow = [[UIApplication sharedApplication] keyWindow];
       
   209 
       
   210     // present the overlay
   210     // present the overlay
   211     [UIView beginAnimations:@"showing overlay" context:NULL];
   211     [UIView beginAnimations:@"showing overlay" context:NULL];
   212     [UIView setAnimationDuration:2];
   212     [UIView setAnimationDuration:2];
   213     self.view.alpha = 1;
   213     self.view.alpha = 1;
   214     [UIView commitAnimations];
   214     [UIView commitAnimations];