Fixed SDL_SetWindowFullscreen on iOS to properly update the view's frame. iOS-improvements
authorAlex Szpakowski <slime73@gmail.com>
Tue, 22 Jul 2014 16:48:35 -0300
branchiOS-improvements
changeset 9497 fa0f79fc320d
parent 9496 abc8df8ce987
child 9498 d02c27e3f698
Fixed SDL_SetWindowFullscreen on iOS to properly update the view's frame.
src/video/uikit/SDL_uikitwindow.m
--- a/src/video/uikit/SDL_uikitwindow.m	Mon Jul 21 02:46:53 2014 -0300
+++ b/src/video/uikit/SDL_uikitwindow.m	Tue Jul 22 16:48:35 2014 -0300
@@ -240,6 +240,7 @@
     SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
     SDL_uikitviewcontroller *viewcontroller = windowdata->viewcontroller;
     UIWindow *uiwindow = windowdata->uiwindow;
+    CGRect bounds;
 
     if (fullscreen || (window->flags & SDL_WINDOW_BORDERLESS)) {
         [UIApplication sharedApplication].statusBarHidden = YES;
@@ -253,13 +254,17 @@
     }
 #endif
 
-    CGRect bounds;
-    if (fullscreen) {
+    if (fullscreen || (window->flags & SDL_WINDOW_BORDERLESS)) {
         bounds = [displaydata->uiscreen bounds];
     } else {
         bounds = [displaydata->uiscreen applicationFrame];
     }
 
+    /* Update the view's frame to account for the status bar change. */
+    windowdata->view.frame = bounds;
+    [windowdata->view setNeedsLayout];
+    [windowdata->view layoutIfNeeded];
+
     /* Get frame dimensions */
     int width = (int) bounds.size.width;
     int height = (int) bounds.size.height;
@@ -268,21 +273,11 @@
        screen to match, so we pick the closest to what we wanted.
      */
     if (window->w >= window->h) {
-        if (width > height) {
-            window->w = width;
-            window->h = height;
-        } else {
-            window->w = height;
-            window->h = width;
-        }
+        window->w = SDL_max(width, height);
+        window->h = SDL_min(width, height);
     } else {
-        if (width > height) {
-            window->w = height;
-            window->h = width;
-        } else {
-            window->w = width;
-            window->h = height;
-        }
+        window->w = SDL_min(width, height);
+        window->h = SDL_max(width, height);
     }
 }