Fixed SDL_SetWindowFullscreen on iOS for the last time, hopefully. iOS-improvements
authorAlex Szpakowski <slime73@gmail.com>
Wed, 23 Jul 2014 21:55:42 -0300
branchiOS-improvements
changeset 9502933ed557b7c1
parent 9501 574db299498f
child 9503 bff6f1fecc5d
Fixed SDL_SetWindowFullscreen on iOS for the last time, hopefully.

Fixed iOS version checking code.
src/video/uikit/SDL_uikitopengles.m
src/video/uikit/SDL_uikitopenglview.m
src/video/uikit/SDL_uikitvideo.h
src/video/uikit/SDL_uikitvideo.m
src/video/uikit/SDL_uikitwindow.m
     1.1 --- a/src/video/uikit/SDL_uikitopengles.m	Wed Jul 23 03:05:31 2014 -0300
     1.2 +++ b/src/video/uikit/SDL_uikitopengles.m	Wed Jul 23 21:55:42 2014 -0300
     1.3 @@ -116,6 +116,7 @@
     1.4      SDL_uikitopenglview *view;
     1.5      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     1.6      UIWindow *uiwindow = data->uiwindow;
     1.7 +    CGRect frame = UIKit_ComputeViewFrame(window, uiwindow.screen);
     1.8      EAGLSharegroup *share_group = nil;
     1.9      CGFloat scale = 1.0;
    1.10  
    1.11 @@ -124,7 +125,7 @@
    1.12             dimensions of the OpenGL view will match the pixel dimensions of the
    1.13             screen rather than the dimensions in points.
    1.14           */
    1.15 -        scale = [uiwindow screen].scale;
    1.16 +        scale = uiwindow.screen.scale;
    1.17      }
    1.18  
    1.19      if (_this->gl_config.share_with_current_context) {
    1.20 @@ -132,13 +133,6 @@
    1.21          share_group = [view.context sharegroup];
    1.22      }
    1.23  
    1.24 -    CGRect frame;
    1.25 -    if (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) {
    1.26 -        frame = [[uiwindow screen] bounds];
    1.27 -    } else {
    1.28 -        frame = [[uiwindow screen] applicationFrame];
    1.29 -    }
    1.30 -
    1.31      /* construct our view, passing in SDL's OpenGL configuration data */
    1.32      view = [[SDL_uikitopenglview alloc] initWithFrame: frame
    1.33                                                  scale: scale
    1.34 @@ -175,7 +169,7 @@
    1.35      }
    1.36  
    1.37      /* Make this window the current mouse focus for touch input */
    1.38 -    if ([uiwindow screen] == [UIScreen mainScreen]) {
    1.39 +    if (uiwindow.screen == [UIScreen mainScreen]) {
    1.40          SDL_SetMouseFocus(window);
    1.41          SDL_SetKeyboardFocus(window);
    1.42      }
     2.1 --- a/src/video/uikit/SDL_uikitopenglview.m	Wed Jul 23 03:05:31 2014 -0300
     2.2 +++ b/src/video/uikit/SDL_uikitopenglview.m	Wed Jul 23 21:55:42 2014 -0300
     2.3 @@ -26,6 +26,7 @@
     2.4  #include <OpenGLES/EAGLDrawable.h>
     2.5  #include "SDL_uikitopenglview.h"
     2.6  #include "SDL_uikitmessagebox.h"
     2.7 +#include "SDL_uikitvideo.h"
     2.8  
     2.9  
    2.10  @implementation SDL_uikitopenglview {
    2.11 @@ -89,8 +90,7 @@
    2.12              return nil;
    2.13          }
    2.14  
    2.15 -        BOOL hasiOS7 = [[UIDevice currentDevice].systemVersion compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending;
    2.16 -        if (sRGB && hasiOS7) {
    2.17 +        if (sRGB && UIKit_IsSystemVersionAtLeast(@"7.0")) {
    2.18               /* sRGB EAGL drawable support was added in iOS 7 */
    2.19              colorFormat = kEAGLColorFormatSRGBA8;
    2.20          } else if (rBits >= 8 && gBits >= 8 && bBits >= 8) {
     3.1 --- a/src/video/uikit/SDL_uikitvideo.h	Wed Jul 23 03:05:31 2014 -0300
     3.2 +++ b/src/video/uikit/SDL_uikitvideo.h	Wed Jul 23 21:55:42 2014 -0300
     3.3 @@ -25,6 +25,8 @@
     3.4  
     3.5  #include "../SDL_sysvideo.h"
     3.6  
     3.7 +BOOL UIKit_IsSystemVersionAtLeast(NSString *version);
     3.8 +CGRect UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen);
     3.9  
    3.10  #endif /* _SDL_uikitvideo_h */
    3.11  
     4.1 --- a/src/video/uikit/SDL_uikitvideo.m	Wed Jul 23 03:05:31 2014 -0300
     4.2 +++ b/src/video/uikit/SDL_uikitvideo.m	Wed Jul 23 21:55:42 2014 -0300
     4.3 @@ -130,6 +130,26 @@
     4.4      UIKit_QuitModes(_this);
     4.5  }
     4.6  
     4.7 +BOOL
     4.8 +UIKit_IsSystemVersionAtLeast(NSString *version)
     4.9 +{
    4.10 +    NSString *sysversion = [UIDevice currentDevice].systemVersion;
    4.11 +    return [sysversion compare:version options:NSNumericSearch] != NSOrderedAscending;
    4.12 +}
    4.13 +
    4.14 +CGRect
    4.15 +UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen)
    4.16 +{
    4.17 +    BOOL hasiOS7 = UIKit_IsSystemVersionAtLeast(@"7.0");
    4.18 +
    4.19 +    if (hasiOS7 || (window->flags & (SDL_WINDOW_BORDERLESS|SDL_WINDOW_FULLSCREEN))) {
    4.20 +        /* The view should always show behind the status bar in iOS 7+. */
    4.21 +        return screen.bounds;
    4.22 +    } else {
    4.23 +        return screen.applicationFrame;
    4.24 +    }
    4.25 +}
    4.26 +
    4.27  /*
    4.28   * iOS log support.
    4.29   *
     5.1 --- a/src/video/uikit/SDL_uikitwindow.m	Wed Jul 23 03:05:31 2014 -0300
     5.2 +++ b/src/video/uikit/SDL_uikitwindow.m	Wed Jul 23 21:55:42 2014 -0300
     5.3 @@ -62,16 +62,11 @@
     5.4          window->x = 0;
     5.5          window->y = 0;
     5.6  
     5.7 -        CGRect bounds;
     5.8 -        if (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) {
     5.9 -            bounds = [displaydata->uiscreen bounds];
    5.10 -        } else {
    5.11 -            bounds = [displaydata->uiscreen applicationFrame];
    5.12 -        }
    5.13 +        CGRect frame = UIKit_ComputeViewFrame(window, displaydata->uiscreen);
    5.14  
    5.15          /* Get frame dimensions */
    5.16 -        int width = (int) bounds.size.width;
    5.17 -        int height = (int) bounds.size.height;
    5.18 +        int width = (int) frame.size.width;
    5.19 +        int height = (int) frame.size.height;
    5.20  
    5.21          /* Make sure the width/height are oriented correctly */
    5.22          if (UIKit_IsDisplayLandscape(displaydata->uiscreen) != (width > height)) {
    5.23 @@ -239,7 +234,7 @@
    5.24      SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
    5.25      SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
    5.26      SDL_uikitviewcontroller *viewcontroller = windowdata->viewcontroller;
    5.27 -    CGRect bounds;
    5.28 +    CGRect frame;
    5.29  
    5.30      if (fullscreen || (window->flags & SDL_WINDOW_BORDERLESS)) {
    5.31          [UIApplication sharedApplication].statusBarHidden = YES;
    5.32 @@ -252,20 +247,15 @@
    5.33          [viewcontroller setNeedsStatusBarAppearanceUpdate];
    5.34      }
    5.35  
    5.36 -    if (fullscreen || (window->flags & SDL_WINDOW_BORDERLESS)) {
    5.37 -        bounds = [displaydata->uiscreen bounds];
    5.38 -    } else {
    5.39 -        bounds = [displaydata->uiscreen applicationFrame];
    5.40 -    }
    5.41 -
    5.42      /* Update the view's frame to account for the status bar change. */
    5.43 -    windowdata->view.frame = bounds;
    5.44 +    frame = UIKit_ComputeViewFrame(window, displaydata->uiscreen);
    5.45 +    windowdata->view.frame = frame;
    5.46      [windowdata->view setNeedsLayout];
    5.47      [windowdata->view layoutIfNeeded];
    5.48  
    5.49      /* Get frame dimensions */
    5.50 -    int width = (int) bounds.size.width;
    5.51 -    int height = (int) bounds.size.height;
    5.52 +    int width = (int) frame.size.width;
    5.53 +    int height = (int) frame.size.height;
    5.54  
    5.55      /* We can pick either width or height here and we'll rotate the
    5.56         screen to match, so we pick the closest to what we wanted.