* SDL_IOS_ORIENTATIONS hint
authorTim Angus <tim@blackcompanystudios.co.uk>
Fri, 10 Jun 2011 14:23:24 +0100
changeset 5554 4b4258be8699
parent 5553 418675ebba17
child 5555 3ecad5e5dbe4
* SDL_IOS_ORIENTATIONS hint
include/SDL_hints.h
src/video/uikit/SDL_uikitwindow.m
--- a/include/SDL_hints.h	Sun Jun 12 12:23:39 2011 -0400
+++ b/include/SDL_hints.h	Fri Jun 10 14:23:24 2011 +0100
@@ -118,6 +118,17 @@
  *  By default SDL does not sync screen surface updates with vertical refresh.
  */
 #define SDL_HINT_RENDER_VSYNC               "SDL_RENDER_VSYNC"
+	
+/**
+ *  \brief  A variable controlling which orientations are allowed on iOS.
+ *
+ *  In some circumstances it is necessary to be able to explicitly control
+ *  which UI orientations are allowed.
+ *
+ *  This variable is a space delimited list of the following values:
+ *    "LandscapeLeft", "LandscapeRight", "Portrait" "PortraitUpsideDown"
+ */
+#define SDL_HINT_ORIENTATIONS "SDL_IOS_ORIENTATIONS"
 
 
 /**
--- a/src/video/uikit/SDL_uikitwindow.m	Sun Jun 12 12:23:39 2011 -0400
+++ b/src/video/uikit/SDL_uikitwindow.m	Fri Jun 10 14:23:24 2011 +0100
@@ -24,6 +24,7 @@
 #include "SDL_video.h"
 #include "SDL_mouse.h"
 #include "SDL_assert.h"
+#include "SDL_hints.h"
 #include "../SDL_sysvideo.h"
 #include "../SDL_pixels_c.h"
 #include "../../events/SDL_events_c.h"
@@ -48,6 +49,37 @@
 }
 
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient {
+    const char *orientationsCString;
+    if ((orientationsCString = SDL_GetHint(SDL_HINT_ORIENTATIONS)) != NULL) {
+        BOOL rotate = NO;
+        NSString *orientationsNSString = [NSString stringWithCString:orientationsCString
+                                                            encoding:NSUTF8StringEncoding];
+        NSArray *orientations = [orientationsNSString componentsSeparatedByCharactersInSet:
+                                 [NSCharacterSet characterSetWithCharactersInString:@" "]];
+        
+        switch (orient) {
+            case UIInterfaceOrientationLandscapeLeft:
+                rotate = [orientations containsObject:@"LandscapeLeft"];
+                break;
+                
+            case UIInterfaceOrientationLandscapeRight:
+                rotate = [orientations containsObject:@"LandscapeRight"];
+                break;
+                
+            case UIInterfaceOrientationPortrait:
+                rotate = [orientations containsObject:@"Portrait"];
+                break;
+                
+            case UIInterfaceOrientationPortraitUpsideDown:
+                rotate = [orientations containsObject:@"PortraitUpsideDown"];
+                break;
+                
+            default: break;
+        }
+        
+        return rotate;
+    }
+
     if (self->window->flags & SDL_WINDOW_RESIZABLE) {
         return YES;  // any orientation is okay.
     }