Fixed SDL_SetWindowFullscreen on iOS causing the window's reported dimensions and supported orientations to go out of sync with what they should be, if the device orientation was different from the screen orientation when the function call was made. iOS-improvements
authorAlex Szpakowski <slime73@gmail.com>
Thu, 24 Jul 2014 22:35:25 -0300
branchiOS-improvements
changeset 9504 1f3b6fc94fae
parent 9503 bff6f1fecc5d
child 9505 6fc615dfc93f
Fixed SDL_SetWindowFullscreen on iOS causing the window's reported dimensions and supported orientations to go out of sync with what they should be, if the device orientation was different from the screen orientation when the function call was made.
src/video/uikit/SDL_uikitappdelegate.m
--- a/src/video/uikit/SDL_uikitappdelegate.m	Wed Jul 23 22:35:14 2014 -0300
+++ b/src/video/uikit/SDL_uikitappdelegate.m	Thu Jul 24 22:35:25 2014 -0300
@@ -242,6 +242,28 @@
     SDL_SendAppEvent(SDL_APP_LOWMEMORY);
 }
 
+- (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation
+{
+    UIInterfaceOrientation orientation = application.statusBarOrientation;
+    SDL_VideoDevice *_this = SDL_GetVideoDevice();
+
+    if (_this && _this->num_displays > 0) {
+        SDL_VideoDisplay *display = &_this->displays[0]; /* Main screen. */
+        SDL_DisplayMode *mode = &display->desktop_mode;
+
+        /* The desktop display mode should be kept in sync with the screen
+         * orientation so that updating a window's fullscreen state to
+         * SDL_WINDOW_FULLSCREEN_DESKTOP keeps the window dimensions in the
+         * correct orientation.
+         */
+        if (UIInterfaceOrientationIsLandscape(orientation) != (mode->w > mode->h)) {
+            int height = mode->w;
+            mode->w = mode->h;
+            mode->h = height;
+        }
+    }
+}
+
 - (void) applicationWillResignActive:(UIApplication*)application
 {
     SDL_VideoDevice *_this = SDL_GetVideoDevice();