Moved display orientation handling on iOS out to a separate function for Qt apps
authorSam Lantinga <slouken@libsdl.org>
Wed, 22 Aug 2018 23:47:29 -0700
changeset 12144c48e1ae67968
parent 12143 673ec0369266
child 12145 1f17cc93857c
Moved display orientation handling on iOS out to a separate function for Qt apps
src/video/uikit/SDL_uikitappdelegate.m
src/video/uikit/SDL_uikitmodes.h
src/video/uikit/SDL_uikitmodes.m
     1.1 --- a/src/video/uikit/SDL_uikitappdelegate.m	Wed Aug 22 21:48:28 2018 -0700
     1.2 +++ b/src/video/uikit/SDL_uikitappdelegate.m	Wed Aug 22 23:47:29 2018 -0700
     1.3 @@ -445,51 +445,7 @@
     1.4  #if !TARGET_OS_TV
     1.5  - (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation
     1.6  {
     1.7 -    BOOL isLandscape = UIInterfaceOrientationIsLandscape(application.statusBarOrientation);
     1.8 -    SDL_VideoDevice *_this = SDL_GetVideoDevice();
     1.9 -
    1.10 -    if (_this && _this->num_displays > 0) {
    1.11 -        SDL_DisplayMode *desktopmode = &_this->displays[0].desktop_mode;
    1.12 -        SDL_DisplayMode *currentmode = &_this->displays[0].current_mode;
    1.13 -        SDL_DisplayOrientation orientation = SDL_ORIENTATION_UNKNOWN;
    1.14 -
    1.15 -        /* The desktop display mode should be kept in sync with the screen
    1.16 -         * orientation so that updating a window's fullscreen state to
    1.17 -         * SDL_WINDOW_FULLSCREEN_DESKTOP keeps the window dimensions in the
    1.18 -         * correct orientation. */
    1.19 -        if (isLandscape != (desktopmode->w > desktopmode->h)) {
    1.20 -            int height = desktopmode->w;
    1.21 -            desktopmode->w = desktopmode->h;
    1.22 -            desktopmode->h = height;
    1.23 -        }
    1.24 -
    1.25 -        /* Same deal with the current mode + SDL_GetCurrentDisplayMode. */
    1.26 -        if (isLandscape != (currentmode->w > currentmode->h)) {
    1.27 -            int height = currentmode->w;
    1.28 -            currentmode->w = currentmode->h;
    1.29 -            currentmode->h = height;
    1.30 -        }
    1.31 -
    1.32 -        switch (application.statusBarOrientation) {
    1.33 -        case UIInterfaceOrientationPortrait:
    1.34 -            orientation = SDL_ORIENTATION_PORTRAIT;
    1.35 -            break;
    1.36 -        case UIInterfaceOrientationPortraitUpsideDown:
    1.37 -            orientation = SDL_ORIENTATION_PORTRAIT_FLIPPED;
    1.38 -            break;
    1.39 -        case UIInterfaceOrientationLandscapeLeft:
    1.40 -            /* Bug: UIInterfaceOrientationLandscapeLeft/Right are reversed - http://openradar.appspot.com/7216046 */
    1.41 -            orientation = SDL_ORIENTATION_LANDSCAPE_FLIPPED;
    1.42 -            break;
    1.43 -        case UIInterfaceOrientationLandscapeRight:
    1.44 -            /* Bug: UIInterfaceOrientationLandscapeLeft/Right are reversed - http://openradar.appspot.com/7216046 */
    1.45 -            orientation = SDL_ORIENTATION_LANDSCAPE;
    1.46 -            break;
    1.47 -        default:
    1.48 -            break;
    1.49 -        }
    1.50 -        SDL_SendDisplayEvent(&_this->displays[0], SDL_DISPLAYEVENT_ORIENTATION, orientation);
    1.51 -    }
    1.52 +	SDL_OnApplicationDidChangeStatusBarOrientation();
    1.53  }
    1.54  #endif
    1.55  
     2.1 --- a/src/video/uikit/SDL_uikitmodes.h	Wed Aug 22 21:48:28 2018 -0700
     2.2 +++ b/src/video/uikit/SDL_uikitmodes.h	Wed Aug 22 23:47:29 2018 -0700
     2.3 @@ -45,6 +45,10 @@
     2.4  extern void UIKit_QuitModes(_THIS);
     2.5  extern int UIKit_GetDisplayUsableBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
     2.6  
     2.7 +#if !TARGET_OS_TV
     2.8 +extern void SDL_OnApplicationDidChangeStatusBarOrientation(void);
     2.9 +#endif
    2.10 +
    2.11  #endif /* SDL_uikitmodes_h_ */
    2.12  
    2.13  /* vi: set ts=4 sw=4 expandtab: */
     3.1 --- a/src/video/uikit/SDL_uikitmodes.m	Wed Aug 22 21:48:28 2018 -0700
     3.2 +++ b/src/video/uikit/SDL_uikitmodes.m	Wed Aug 22 23:47:29 2018 -0700
     3.3 @@ -25,6 +25,8 @@
     3.4  #include "SDL_assert.h"
     3.5  #include "SDL_uikitmodes.h"
     3.6  
     3.7 +#include "../../events/SDL_events_c.h"
     3.8 +
     3.9  @implementation SDL_DisplayData
    3.10  
    3.11  @synthesize uiscreen;
    3.12 @@ -188,6 +190,9 @@
    3.13                  return -1;
    3.14              }
    3.15          }
    3.16 +#if !TARGET_OS_TV
    3.17 +		SDL_OnApplicationDidChangeStatusBarOrientation();
    3.18 +#endif
    3.19      }
    3.20  
    3.21      return 0;
    3.22 @@ -319,6 +324,55 @@
    3.23      }
    3.24  }
    3.25  
    3.26 +void SDL_OnApplicationDidChangeStatusBarOrientation()
    3.27 +{
    3.28 +    BOOL isLandscape = UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation);
    3.29 +    SDL_VideoDisplay *display = SDL_GetDisplay(0);
    3.30 +
    3.31 +    if (display) {
    3.32 +        SDL_DisplayMode *desktopmode = &display->desktop_mode;
    3.33 +        SDL_DisplayMode *currentmode = &display->current_mode;
    3.34 +        SDL_DisplayOrientation orientation = SDL_ORIENTATION_UNKNOWN;
    3.35 +
    3.36 +        /* The desktop display mode should be kept in sync with the screen
    3.37 +         * orientation so that updating a window's fullscreen state to
    3.38 +         * SDL_WINDOW_FULLSCREEN_DESKTOP keeps the window dimensions in the
    3.39 +         * correct orientation. */
    3.40 +        if (isLandscape != (desktopmode->w > desktopmode->h)) {
    3.41 +            int height = desktopmode->w;
    3.42 +            desktopmode->w = desktopmode->h;
    3.43 +            desktopmode->h = height;
    3.44 +        }
    3.45 +
    3.46 +        /* Same deal with the current mode + SDL_GetCurrentDisplayMode. */
    3.47 +        if (isLandscape != (currentmode->w > currentmode->h)) {
    3.48 +            int height = currentmode->w;
    3.49 +            currentmode->w = currentmode->h;
    3.50 +            currentmode->h = height;
    3.51 +        }
    3.52 +
    3.53 +        switch ([UIApplication sharedApplication].statusBarOrientation) {
    3.54 +        case UIInterfaceOrientationPortrait:
    3.55 +            orientation = SDL_ORIENTATION_PORTRAIT;
    3.56 +            break;
    3.57 +        case UIInterfaceOrientationPortraitUpsideDown:
    3.58 +            orientation = SDL_ORIENTATION_PORTRAIT_FLIPPED;
    3.59 +            break;
    3.60 +        case UIInterfaceOrientationLandscapeLeft:
    3.61 +            /* Bug: UIInterfaceOrientationLandscapeLeft/Right are reversed - http://openradar.appspot.com/7216046 */
    3.62 +            orientation = SDL_ORIENTATION_LANDSCAPE_FLIPPED;
    3.63 +            break;
    3.64 +        case UIInterfaceOrientationLandscapeRight:
    3.65 +            /* Bug: UIInterfaceOrientationLandscapeLeft/Right are reversed - http://openradar.appspot.com/7216046 */
    3.66 +            orientation = SDL_ORIENTATION_LANDSCAPE;
    3.67 +            break;
    3.68 +        default:
    3.69 +            break;
    3.70 +        }
    3.71 +        SDL_SendDisplayEvent(display, SDL_DISPLAYEVENT_ORIENTATION, orientation);
    3.72 +    }
    3.73 +}
    3.74 +
    3.75  #endif /* SDL_VIDEO_DRIVER_UIKIT */
    3.76  
    3.77  /* vi: set ts=4 sw=4 expandtab: */