Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8. iOS-improvements
authorAlex Szpakowski <slime73@gmail.com>
Tue, 29 Jul 2014 00:05:48 -0300
branchiOS-improvements
changeset 95056fc615dfc93f
parent 9504 1f3b6fc94fae
child 9506 18e3f94bd860
Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
include/SDL_hints.h
src/video/uikit/SDL_uikitappdelegate.m
src/video/uikit/SDL_uikitmessagebox.m
src/video/uikit/SDL_uikitvideo.m
src/video/uikit/SDL_uikitview.m
src/video/uikit/SDL_uikitviewcontroller.m
src/video/uikit/SDL_uikitwindow.h
src/video/uikit/SDL_uikitwindow.m
     1.1 --- a/include/SDL_hints.h	Thu Jul 24 22:35:25 2014 -0300
     1.2 +++ b/include/SDL_hints.h	Tue Jul 29 00:05:48 2014 -0300
     1.3 @@ -346,7 +346,7 @@
     1.4  
     1.5  
     1.6  /**
     1.7 - *  \brief If set to 1, then do not allow high-DPI windows. ("Retina" on Mac)
     1.8 + *  \brief If set to 1, then do not allow high-DPI windows. ("Retina" on Mac and iOS)
     1.9   */
    1.10  #define SDL_HINT_VIDEO_HIGHDPI_DISABLED "SDL_VIDEO_HIGHDPI_DISABLED"
    1.11  
     2.1 --- a/src/video/uikit/SDL_uikitappdelegate.m	Thu Jul 24 22:35:25 2014 -0300
     2.2 +++ b/src/video/uikit/SDL_uikitappdelegate.m	Tue Jul 29 00:05:48 2014 -0300
     2.3 @@ -244,22 +244,29 @@
     2.4  
     2.5  - (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation
     2.6  {
     2.7 -    UIInterfaceOrientation orientation = application.statusBarOrientation;
     2.8 +    BOOL isLandscape = UIInterfaceOrientationIsLandscape(application.statusBarOrientation);
     2.9      SDL_VideoDevice *_this = SDL_GetVideoDevice();
    2.10  
    2.11      if (_this && _this->num_displays > 0) {
    2.12 -        SDL_VideoDisplay *display = &_this->displays[0]; /* Main screen. */
    2.13 -        SDL_DisplayMode *mode = &display->desktop_mode;
    2.14 +        SDL_DisplayMode *desktopmode = &_this->displays[0].desktop_mode;
    2.15 +        SDL_DisplayMode *currentmode = &_this->displays[0].current_mode;
    2.16  
    2.17          /* The desktop display mode should be kept in sync with the screen
    2.18           * orientation so that updating a window's fullscreen state to
    2.19           * SDL_WINDOW_FULLSCREEN_DESKTOP keeps the window dimensions in the
    2.20           * correct orientation.
    2.21           */
    2.22 -        if (UIInterfaceOrientationIsLandscape(orientation) != (mode->w > mode->h)) {
    2.23 -            int height = mode->w;
    2.24 -            mode->w = mode->h;
    2.25 -            mode->h = height;
    2.26 +        if (isLandscape != (desktopmode->w > desktopmode->h)) {
    2.27 +            int height = desktopmode->w;
    2.28 +            desktopmode->w = desktopmode->h;
    2.29 +            desktopmode->h = height;
    2.30 +        }
    2.31 +
    2.32 +        /* Same deal with the current mode + SDL_GetCurrentDisplayMode. */
    2.33 +        if (isLandscape != (currentmode->w > currentmode->h)) {
    2.34 +            int height = currentmode->w;
    2.35 +            currentmode->w = currentmode->h;
    2.36 +            currentmode->h = height;
    2.37          }
    2.38      }
    2.39  }
     3.1 --- a/src/video/uikit/SDL_uikitmessagebox.m	Thu Jul 24 22:35:25 2014 -0300
     3.2 +++ b/src/video/uikit/SDL_uikitmessagebox.m	Tue Jul 29 00:05:48 2014 -0300
     3.3 @@ -32,7 +32,7 @@
     3.4  
     3.5  @interface UIKit_UIAlertViewDelegate : NSObject <UIAlertViewDelegate>
     3.6  
     3.7 -- (id)initWithButtonIndex:(int *)_buttonIndex;
     3.8 +- (id)initWithButtonIndex:(int *)buttonIndex;
     3.9  - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;
    3.10  
    3.11  @end
     4.1 --- a/src/video/uikit/SDL_uikitvideo.m	Thu Jul 24 22:35:25 2014 -0300
     4.2 +++ b/src/video/uikit/SDL_uikitvideo.m	Tue Jul 29 00:05:48 2014 -0300
     4.3 @@ -78,12 +78,11 @@
     4.4      device->ShowWindow = UIKit_ShowWindow;
     4.5      device->HideWindow = UIKit_HideWindow;
     4.6      device->RaiseWindow = UIKit_RaiseWindow;
     4.7 +    device->SetWindowBordered = UIKit_SetWindowBordered;
     4.8      device->SetWindowFullscreen = UIKit_SetWindowFullscreen;
     4.9      device->DestroyWindow = UIKit_DestroyWindow;
    4.10      device->GetWindowWMInfo = UIKit_GetWindowWMInfo;
    4.11  
    4.12 -    /* !!! FIXME: implement SetWindowBordered */
    4.13 -
    4.14  #if SDL_IPHONE_KEYBOARD
    4.15      device->HasScreenKeyboardSupport = UIKit_HasScreenKeyboardSupport;
    4.16      device->ShowScreenKeyboard = UIKit_ShowScreenKeyboard;
     5.1 --- a/src/video/uikit/SDL_uikitview.m	Thu Jul 24 22:35:25 2014 -0300
     5.2 +++ b/src/video/uikit/SDL_uikitview.m	Tue Jul 29 00:05:48 2014 -0300
     5.3 @@ -51,23 +51,18 @@
     5.4  
     5.5  }
     5.6  
     5.7 -- (void)dealloc
     5.8 -{
     5.9 -    [super dealloc];
    5.10 -}
    5.11 -
    5.12  - (id)initWithFrame:(CGRect)frame
    5.13  {
    5.14 -    self = [super initWithFrame: frame];
    5.15 -
    5.16 +    if (self = [super initWithFrame: frame]) {
    5.17  #if SDL_IPHONE_KEYBOARD
    5.18 -    [self initializeKeyboard];
    5.19 +        [self initializeKeyboard];
    5.20  #endif
    5.21  
    5.22 -    self.multipleTouchEnabled = YES;
    5.23 +        self.multipleTouchEnabled = YES;
    5.24  
    5.25 -    touchId = 1;
    5.26 -    SDL_AddTouch(touchId, "");
    5.27 +        touchId = 1;
    5.28 +        SDL_AddTouch(touchId, "");
    5.29 +    }
    5.30  
    5.31      return self;
    5.32  
     6.1 --- a/src/video/uikit/SDL_uikitviewcontroller.m	Thu Jul 24 22:35:25 2014 -0300
     6.2 +++ b/src/video/uikit/SDL_uikitviewcontroller.m	Tue Jul 29 00:05:48 2014 -0300
     6.3 @@ -40,12 +40,9 @@
     6.4  
     6.5  - (id)initWithSDLWindow:(SDL_Window *)_window
     6.6  {
     6.7 -    self = [self init];
     6.8 -    if (self == nil) {
     6.9 -        return nil;
    6.10 +    if (self = [super initWithNibName:nil bundle:nil]) {
    6.11 +        self.window = _window;
    6.12      }
    6.13 -    self.window = _window;
    6.14 -
    6.15      return self;
    6.16  }
    6.17  
    6.18 @@ -56,8 +53,7 @@
    6.19  
    6.20  - (void)viewDidLayoutSubviews
    6.21  {
    6.22 -    SDL_WindowData *data = window->driverdata;
    6.23 -    const CGSize size = data->view.bounds.size;
    6.24 +    const CGSize size = self.view.bounds.size;
    6.25      int w = (int) size.width;
    6.26      int h = (int) size.height;
    6.27  
     7.1 --- a/src/video/uikit/SDL_uikitwindow.h	Thu Jul 24 22:35:25 2014 -0300
     7.2 +++ b/src/video/uikit/SDL_uikitwindow.h	Tue Jul 29 00:05:48 2014 -0300
     7.3 @@ -32,6 +32,7 @@
     7.4  extern void UIKit_ShowWindow(_THIS, SDL_Window * window);
     7.5  extern void UIKit_HideWindow(_THIS, SDL_Window * window);
     7.6  extern void UIKit_RaiseWindow(_THIS, SDL_Window * window);
     7.7 +extern void UIKit_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
     7.8  extern void UIKit_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
     7.9  extern void UIKit_DestroyWindow(_THIS, SDL_Window * window);
    7.10  extern SDL_bool UIKit_GetWindowWMInfo(_THIS, SDL_Window * window,
    7.11 @@ -39,9 +40,13 @@
    7.12  
    7.13  @class UIWindow;
    7.14  
    7.15 +@interface SDL_uikitwindow : UIWindow
    7.16 +
    7.17 +@end
    7.18 +
    7.19  struct SDL_WindowData
    7.20  {
    7.21 -    UIWindow *uiwindow;
    7.22 +    SDL_uikitwindow *uiwindow;
    7.23      SDL_uikitopenglview *view;
    7.24      SDL_uikitviewcontroller *viewcontroller;
    7.25  };
     8.1 --- a/src/video/uikit/SDL_uikitwindow.m	Thu Jul 24 22:35:25 2014 -0300
     8.2 +++ b/src/video/uikit/SDL_uikitwindow.m	Tue Jul 29 00:05:48 2014 -0300
     8.3 @@ -41,8 +41,23 @@
     8.4  
     8.5  #include <Foundation/Foundation.h>
     8.6  
     8.7 +@implementation SDL_uikitwindow
     8.8  
     8.9 -static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created)
    8.10 +- (void)layoutSubviews
    8.11 +{
    8.12 +    [super layoutSubviews];
    8.13 +
    8.14 +    /* This seems to be needed on iOS 8, otherwise the window's frame is put in
    8.15 +     * an unexpected position when the screen or device is rotated.
    8.16 +     * FIXME: is there a better solution to that problem than this ugly hack?
    8.17 +     */
    8.18 +    self.frame = self.screen.bounds;
    8.19 +}
    8.20 +
    8.21 +@end
    8.22 +
    8.23 +
    8.24 +static int SetupWindowData(_THIS, SDL_Window *window, SDL_uikitwindow *uiwindow, SDL_bool created)
    8.25  {
    8.26      SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
    8.27      SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
    8.28 @@ -181,7 +196,7 @@
    8.29  
    8.30      /* ignore the size user requested, and make a fullscreen window */
    8.31      /* !!! FIXME: can we have a smaller view? */
    8.32 -    UIWindow *uiwindow = [[UIWindow alloc] initWithFrame:[data->uiscreen bounds]];
    8.33 +    SDL_uikitwindow *uiwindow = [[SDL_uikitwindow alloc] initWithFrame:data->uiscreen.bounds];
    8.34  
    8.35      /* put the window on an external display if appropriate. This implicitly
    8.36       * does [uiwindow setframe:[uiscreen bounds]], so don't do it on the
    8.37 @@ -198,7 +213,6 @@
    8.38      }
    8.39  
    8.40      return 1;
    8.41 -
    8.42  }
    8.43  
    8.44  void
    8.45 @@ -228,48 +242,60 @@
    8.46      _this->GL_MakeCurrent(_this, _this->current_glwin, _this->current_glctx);
    8.47  }
    8.48  
    8.49 -void
    8.50 -UIKit_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
    8.51 +static void
    8.52 +UIKit_UpdateWindowBorder(_THIS, SDL_Window * window)
    8.53  {
    8.54 -    SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
    8.55      SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
    8.56      SDL_uikitviewcontroller *viewcontroller = windowdata->viewcontroller;
    8.57      CGRect frame;
    8.58  
    8.59 -    if (fullscreen || (window->flags & SDL_WINDOW_BORDERLESS)) {
    8.60 -        [UIApplication sharedApplication].statusBarHidden = YES;
    8.61 -    } else {
    8.62 -        [UIApplication sharedApplication].statusBarHidden = NO;
    8.63 -    }
    8.64 +    if (windowdata->uiwindow.screen == [UIScreen mainScreen]) {
    8.65 +        if (window->flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS)) {
    8.66 +            [UIApplication sharedApplication].statusBarHidden = YES;
    8.67 +        } else {
    8.68 +            [UIApplication sharedApplication].statusBarHidden = NO;
    8.69 +        }
    8.70  
    8.71 -    /* iOS 7+ won't update the status bar until we tell it to. */
    8.72 -    if ([viewcontroller respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
    8.73 -        [viewcontroller setNeedsStatusBarAppearanceUpdate];
    8.74 +        /* iOS 7+ won't update the status bar until we tell it to. */
    8.75 +        if ([viewcontroller respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
    8.76 +            [viewcontroller setNeedsStatusBarAppearanceUpdate];
    8.77 +        }
    8.78      }
    8.79  
    8.80      /* Update the view's frame to account for the status bar change. */
    8.81 -    frame = UIKit_ComputeViewFrame(window, displaydata->uiscreen);
    8.82 +    frame = UIKit_ComputeViewFrame(window, windowdata->uiwindow.screen);
    8.83 +
    8.84      windowdata->view.frame = frame;
    8.85      [windowdata->view setNeedsLayout];
    8.86      [windowdata->view layoutIfNeeded];
    8.87  
    8.88      /* Get frame dimensions */
    8.89 -    int width = (int) frame.size.width;
    8.90 +    int width  = (int) frame.size.width;
    8.91      int height = (int) frame.size.height;
    8.92  
    8.93      /* We can pick either width or height here and we'll rotate the
    8.94 -       screen to match, so we pick the closest to what we wanted.
    8.95 +     screen to match, so we pick the closest to what we wanted.
    8.96       */
    8.97      if (window->w >= window->h) {
    8.98 -        window->w = SDL_max(width, height);
    8.99 -        window->h = SDL_min(width, height);
   8.100 +        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, SDL_max(width, height), SDL_min(width, height));
   8.101      } else {
   8.102 -        window->w = SDL_min(width, height);
   8.103 -        window->h = SDL_max(width, height);
   8.104 +        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, SDL_min(width, height), SDL_max(width, height));
   8.105      }
   8.106  }
   8.107  
   8.108  void
   8.109 +UIKit_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
   8.110 +{
   8.111 +    UIKit_UpdateWindowBorder(_this, window);
   8.112 +}
   8.113 +
   8.114 +void
   8.115 +UIKit_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
   8.116 +{
   8.117 +    UIKit_UpdateWindowBorder(_this, window);
   8.118 +}
   8.119 +
   8.120 +void
   8.121  UIKit_DestroyWindow(_THIS, SDL_Window * window)
   8.122  {
   8.123      SDL_WindowData *data = (SDL_WindowData *)window->driverdata;