* SDL_IOS_ORIENTATIONS hint
authorTim Angus <tim@blackcompanystudios.co.uk>
Fri, 10 Jun 2011 14:23:24 +0100
changeset 55544b4258be8699
parent 5553 418675ebba17
child 5555 3ecad5e5dbe4
* SDL_IOS_ORIENTATIONS hint
include/SDL_hints.h
src/video/uikit/SDL_uikitwindow.m
     1.1 --- a/include/SDL_hints.h	Sun Jun 12 12:23:39 2011 -0400
     1.2 +++ b/include/SDL_hints.h	Fri Jun 10 14:23:24 2011 +0100
     1.3 @@ -118,6 +118,17 @@
     1.4   *  By default SDL does not sync screen surface updates with vertical refresh.
     1.5   */
     1.6  #define SDL_HINT_RENDER_VSYNC               "SDL_RENDER_VSYNC"
     1.7 +	
     1.8 +/**
     1.9 + *  \brief  A variable controlling which orientations are allowed on iOS.
    1.10 + *
    1.11 + *  In some circumstances it is necessary to be able to explicitly control
    1.12 + *  which UI orientations are allowed.
    1.13 + *
    1.14 + *  This variable is a space delimited list of the following values:
    1.15 + *    "LandscapeLeft", "LandscapeRight", "Portrait" "PortraitUpsideDown"
    1.16 + */
    1.17 +#define SDL_HINT_ORIENTATIONS "SDL_IOS_ORIENTATIONS"
    1.18  
    1.19  
    1.20  /**
     2.1 --- a/src/video/uikit/SDL_uikitwindow.m	Sun Jun 12 12:23:39 2011 -0400
     2.2 +++ b/src/video/uikit/SDL_uikitwindow.m	Fri Jun 10 14:23:24 2011 +0100
     2.3 @@ -24,6 +24,7 @@
     2.4  #include "SDL_video.h"
     2.5  #include "SDL_mouse.h"
     2.6  #include "SDL_assert.h"
     2.7 +#include "SDL_hints.h"
     2.8  #include "../SDL_sysvideo.h"
     2.9  #include "../SDL_pixels_c.h"
    2.10  #include "../../events/SDL_events_c.h"
    2.11 @@ -48,6 +49,37 @@
    2.12  }
    2.13  
    2.14  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient {
    2.15 +    const char *orientationsCString;
    2.16 +    if ((orientationsCString = SDL_GetHint(SDL_HINT_ORIENTATIONS)) != NULL) {
    2.17 +        BOOL rotate = NO;
    2.18 +        NSString *orientationsNSString = [NSString stringWithCString:orientationsCString
    2.19 +                                                            encoding:NSUTF8StringEncoding];
    2.20 +        NSArray *orientations = [orientationsNSString componentsSeparatedByCharactersInSet:
    2.21 +                                 [NSCharacterSet characterSetWithCharactersInString:@" "]];
    2.22 +        
    2.23 +        switch (orient) {
    2.24 +            case UIInterfaceOrientationLandscapeLeft:
    2.25 +                rotate = [orientations containsObject:@"LandscapeLeft"];
    2.26 +                break;
    2.27 +                
    2.28 +            case UIInterfaceOrientationLandscapeRight:
    2.29 +                rotate = [orientations containsObject:@"LandscapeRight"];
    2.30 +                break;
    2.31 +                
    2.32 +            case UIInterfaceOrientationPortrait:
    2.33 +                rotate = [orientations containsObject:@"Portrait"];
    2.34 +                break;
    2.35 +                
    2.36 +            case UIInterfaceOrientationPortraitUpsideDown:
    2.37 +                rotate = [orientations containsObject:@"PortraitUpsideDown"];
    2.38 +                break;
    2.39 +                
    2.40 +            default: break;
    2.41 +        }
    2.42 +        
    2.43 +        return rotate;
    2.44 +    }
    2.45 +
    2.46      if (self->window->flags & SDL_WINDOW_RESIZABLE) {
    2.47          return YES;  // any orientation is okay.
    2.48      }