Work in progress fixing support for rotated video modes
authorSam Lantinga <slouken@libsdl.org>
Thu, 10 Nov 2011 03:48:59 -0500
changeset 6077 ee00e4b80f79
parent 6076 e69b1bd26e0b
child 6078 718b49ec039e
Work in progress fixing support for rotated video modes
src/video/uikit/SDL_uikitvideo.m
src/video/uikit/SDL_uikitviewcontroller.m
src/video/uikit/SDL_uikitwindow.m
--- a/src/video/uikit/SDL_uikitvideo.m	Thu Nov 10 00:22:44 2011 -0500
+++ b/src/video/uikit/SDL_uikitvideo.m	Thu Nov 10 03:48:59 2011 -0500
@@ -238,6 +238,13 @@
     } else {
         UIScreenMode *uimode = (UIScreenMode *) mode->driverdata;
         [uiscreen setCurrentMode:uimode];
+
+        CGSize size = [uimode size];
+        if (size.width >= size.height) {
+            [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
+        } else {
+            [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
+        }
     }
 
     return 0;
--- a/src/video/uikit/SDL_uikitviewcontroller.m	Thu Nov 10 00:22:44 2011 -0500
+++ b/src/video/uikit/SDL_uikitviewcontroller.m	Thu Nov 10 03:48:59 2011 -0500
@@ -111,15 +111,11 @@
 // Send a resized event when the orientation changes.
 - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
 {
-    if ((self->window->flags & SDL_WINDOW_RESIZABLE) == 0) {
-        return;   // don't care, we're just flipping over in this case.
-    }
-
     const UIInterfaceOrientation toInterfaceOrientation = [self interfaceOrientation];
     SDL_WindowData *data = self->window->driverdata;
     UIWindow *uiwindow = data->uiwindow;
     UIScreen *uiscreen = [uiwindow screen];
-    const int noborder = self->window->flags & SDL_WINDOW_BORDERLESS;
+    const int noborder = (self->window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS));
     CGRect frame = noborder ? [uiscreen bounds] : [uiscreen applicationFrame];
     const CGSize size = frame.size;
     int w, h;
@@ -142,6 +138,10 @@
             return;
     }
 
+    if (w == frame.size.width && h == frame.size.height) {
+        return;
+    }
+
     frame.size.width = w;
     frame.size.height = h;
     frame.origin.x = 0;
--- a/src/video/uikit/SDL_uikitwindow.m	Thu Nov 10 00:22:44 2011 -0500
+++ b/src/video/uikit/SDL_uikitwindow.m	Thu Nov 10 03:48:59 2011 -0500
@@ -63,8 +63,27 @@
     {
         window->x = 0;
         window->y = 0;
-        window->w = (int)uiwindow.frame.size.width;
-        window->h = (int)uiwindow.frame.size.height;
+
+        /* We can pick either width or height here and we'll rotate the
+           screen to match, so we pick the closest to what we wanted.
+         */
+        if (window->w >= window->h) {
+            if (uiwindow.frame.size.width > uiwindow.frame.size.height) {
+                window->w = (int)uiwindow.frame.size.width;
+                window->h = (int)uiwindow.frame.size.height;
+            } else {
+                window->w = (int)uiwindow.frame.size.height;
+                window->h = (int)uiwindow.frame.size.width;
+            }
+        } else {
+            if (uiwindow.frame.size.width > uiwindow.frame.size.height) {
+                window->w = (int)uiwindow.frame.size.height;
+                window->h = (int)uiwindow.frame.size.width;
+            } else {
+                window->w = (int)uiwindow.frame.size.width;
+                window->h = (int)uiwindow.frame.size.height;
+            }
+        }
     }
 
     window->driverdata = data;
@@ -199,6 +218,27 @@
         [UIApplication sharedApplication].statusBarHidden = NO;
         uiwindow.frame = [uiscreen applicationFrame];
     }
+
+    /* We can pick either width or height here and we'll rotate the
+       screen to match, so we pick the closest to what we wanted.
+     */
+    if (window->w >= window->h) {
+        if (uiwindow.frame.size.width > uiwindow.frame.size.height) {
+            window->w = (int)uiwindow.frame.size.width;
+            window->h = (int)uiwindow.frame.size.height;
+        } else {
+            window->w = (int)uiwindow.frame.size.height;
+            window->h = (int)uiwindow.frame.size.width;
+        }
+    } else {
+        if (uiwindow.frame.size.width > uiwindow.frame.size.height) {
+            window->w = (int)uiwindow.frame.size.height;
+            window->h = (int)uiwindow.frame.size.width;
+        } else {
+            window->w = (int)uiwindow.frame.size.width;
+            window->h = (int)uiwindow.frame.size.height;
+        }
+    }
 }
 
 void