src/video/uikit/SDL_uikitwindow.m
changeset 9584 fceb5503cadf
parent 9540 32ddc92d78cf
child 9585 8339700453c6
equal deleted inserted replaced
9583:0bd764eb2b99 9584:fceb5503cadf
   189                 display->current_mode = *bestmode;
   189                 display->current_mode = *bestmode;
   190             }
   190             }
   191         }
   191         }
   192 
   192 
   193         if (data.uiscreen == [UIScreen mainScreen]) {
   193         if (data.uiscreen == [UIScreen mainScreen]) {
   194             NSUInteger orientations = UIKit_GetSupportedOrientations(window);
       
   195             UIApplication *app = [UIApplication sharedApplication];
       
   196 
       
   197             if (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) {
   194             if (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) {
   198                 app.statusBarHidden = YES;
   195                 [UIApplication sharedApplication].statusBarHidden = YES;
   199             } else {
   196             } else {
   200                 app.statusBarHidden = NO;
   197                 [UIApplication sharedApplication].statusBarHidden = NO;
   201             }
   198             }
   202         }
   199         }
   203 
   200 
   204         /* ignore the size user requested, and make a fullscreen window */
   201         /* ignore the size user requested, and make a fullscreen window */
   205         /* !!! FIXME: can we have a smaller view? */
   202         /* !!! FIXME: can we have a smaller view? */
   343 
   340 
   344 NSUInteger
   341 NSUInteger
   345 UIKit_GetSupportedOrientations(SDL_Window * window)
   342 UIKit_GetSupportedOrientations(SDL_Window * window)
   346 {
   343 {
   347     const char *hint = SDL_GetHint(SDL_HINT_ORIENTATIONS);
   344     const char *hint = SDL_GetHint(SDL_HINT_ORIENTATIONS);
       
   345     NSUInteger validOrientations = UIInterfaceOrientationMaskAll;
   348     NSUInteger orientationMask = 0;
   346     NSUInteger orientationMask = 0;
   349 
   347 
   350     @autoreleasepool {
   348     @autoreleasepool {
       
   349         SDL_WindowData *data = (__bridge SDL_WindowData *) window->driverdata;
       
   350         UIApplication *app = [UIApplication sharedApplication];
       
   351 
       
   352         /* Get all possible valid orientations. If the app delegate doesn't tell
       
   353          * us, we get the orientations from Info.plist via UIApplication. */
       
   354         if ([app.delegate respondsToSelector:@selector(application:supportedInterfaceOrientationsForWindow:)]) {
       
   355             validOrientations = [app.delegate application:app supportedInterfaceOrientationsForWindow:data.uiwindow];
       
   356         } else if ([app respondsToSelector:@selector(supportedInterfaceOrientationsForWindow:)]) {
       
   357             validOrientations = [app supportedInterfaceOrientationsForWindow:data.uiwindow];
       
   358         }
       
   359 
   351         if (hint != NULL) {
   360         if (hint != NULL) {
   352             NSArray *orientations = [@(hint) componentsSeparatedByString:@" "];
   361             NSArray *orientations = [@(hint) componentsSeparatedByString:@" "];
   353 
   362 
   354             if ([orientations containsObject:@"LandscapeLeft"]) {
   363             if ([orientations containsObject:@"LandscapeLeft"]) {
   355                 orientationMask |= UIInterfaceOrientationMaskLandscapeLeft;
   364                 orientationMask |= UIInterfaceOrientationMaskLandscapeLeft;
   377             if (window->h >= window->w) {
   386             if (window->h >= window->w) {
   378                 orientationMask |= (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
   387                 orientationMask |= (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
   379             }
   388             }
   380         }
   389         }
   381 
   390 
   382         /* Don't allow upside-down orientation on the phone, so answering calls is in the natural orientation */
   391         /* Don't allow upside-down orientation on phones, so answering calls is in the natural orientation */
   383         if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
   392         if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
   384             orientationMask &= ~UIInterfaceOrientationMaskPortraitUpsideDown;
   393             orientationMask &= ~UIInterfaceOrientationMaskPortraitUpsideDown;
       
   394         }
       
   395 
       
   396         /* If none of the specified orientations are actually supported by the
       
   397          * app, we'll revert to what the app supports. An exception would be
       
   398          * thrown by the system otherwise. */
       
   399         if ((validOrientations & orientationMask) == 0) {
       
   400             orientationMask = validOrientations;
   385         }
   401         }
   386     }
   402     }
   387 
   403 
   388     return orientationMask;
   404     return orientationMask;
   389 }
   405 }