Fixed SDL_HINT_ORIENTATIONS to properly allow disabling custom orientations if the hint is set with no valid orientations. iOS-improvements
authorAlex Szpakowski <slime73@gmail.com>
Wed, 16 Jul 2014 21:06:15 -0300
branchiOS-improvements
changeset 9493961d593034b5
parent 9492 cad5a9995bde
child 9494 435b95e7b712
Fixed SDL_HINT_ORIENTATIONS to properly allow disabling custom orientations if the hint is set with no valid orientations.
src/video/uikit/SDL_uikitviewcontroller.m
     1.1 --- a/src/video/uikit/SDL_uikitviewcontroller.m	Wed Jul 16 20:05:00 2014 -0300
     1.2 +++ b/src/video/uikit/SDL_uikitviewcontroller.m	Wed Jul 16 21:06:15 2014 -0300
     1.3 @@ -69,13 +69,12 @@
     1.4  - (NSUInteger)supportedInterfaceOrientations
     1.5  {
     1.6      NSUInteger orientationMask = 0;
     1.7 +    const char *orientationsHint = SDL_GetHint(SDL_HINT_ORIENTATIONS);
     1.8  
     1.9 -    const char *orientationsCString;
    1.10 -    if ((orientationsCString = SDL_GetHint(SDL_HINT_ORIENTATIONS)) != NULL) {
    1.11 -        BOOL rotate = NO;
    1.12 -        NSString *orientationsNSString = [NSString stringWithCString:orientationsCString
    1.13 -                                                            encoding:NSUTF8StringEncoding];
    1.14 -        NSArray *orientations = [orientationsNSString componentsSeparatedByCharactersInSet:
    1.15 +    if (orientationsHint != NULL) {
    1.16 +        NSString *orientationsString = [NSString stringWithCString:orientationsHint
    1.17 +                                                          encoding:NSUTF8StringEncoding];
    1.18 +        NSArray *orientations = [orientationsString componentsSeparatedByCharactersInSet:
    1.19                                   [NSCharacterSet characterSetWithCharactersInString:@" "]];
    1.20  
    1.21          if ([orientations containsObject:@"LandscapeLeft"]) {
    1.22 @@ -90,14 +89,17 @@
    1.23          if ([orientations containsObject:@"PortraitUpsideDown"]) {
    1.24              orientationMask |= UIInterfaceOrientationMaskPortraitUpsideDown;
    1.25          }
    1.26 +    }
    1.27  
    1.28 -    } else if (self->window->flags & SDL_WINDOW_RESIZABLE) {
    1.29 +    if (orientationMask == 0 && window->flags & SDL_WINDOW_RESIZABLE) {
    1.30          orientationMask = UIInterfaceOrientationMaskAll;  /* any orientation is okay. */
    1.31 -    } else {
    1.32 -        if (self->window->w >= self->window->h) {
    1.33 +    }
    1.34 +
    1.35 +    if (orientationMask == 0) {
    1.36 +        if (window->w >= window->h) {
    1.37              orientationMask |= UIInterfaceOrientationMaskLandscape;
    1.38          }
    1.39 -        if (self->window->h >= self->window->w) {
    1.40 +        if (window->h >= window->w) {
    1.41              orientationMask |= (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
    1.42          }
    1.43      }
    1.44 @@ -117,7 +119,7 @@
    1.45  
    1.46  - (BOOL)prefersStatusBarHidden
    1.47  {
    1.48 -    if (self->window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) {
    1.49 +    if (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) {
    1.50          return YES;
    1.51      } else {
    1.52          return NO;
    1.53 @@ -129,7 +131,7 @@
    1.54  #ifdef __IPHONE_7_0
    1.55      return UIStatusBarStyleLightContent;
    1.56  #else
    1.57 -    /* This is only called in iOS 7+, so the return value isn't important. */
    1.58 +    /* This method is only used in iOS 7+, so the return value here isn't important. */
    1.59      return UIStatusBarStyleBlackTranslucent;
    1.60  #endif
    1.61  }