src/video/uikit/SDL_uikitmodes.m
changeset 12144 c48e1ae67968
parent 11811 5d94cb6b24d3
child 12183 364f514f94d8
     1.1 --- a/src/video/uikit/SDL_uikitmodes.m	Wed Aug 22 21:48:28 2018 -0700
     1.2 +++ b/src/video/uikit/SDL_uikitmodes.m	Wed Aug 22 23:47:29 2018 -0700
     1.3 @@ -25,6 +25,8 @@
     1.4  #include "SDL_assert.h"
     1.5  #include "SDL_uikitmodes.h"
     1.6  
     1.7 +#include "../../events/SDL_events_c.h"
     1.8 +
     1.9  @implementation SDL_DisplayData
    1.10  
    1.11  @synthesize uiscreen;
    1.12 @@ -188,6 +190,9 @@
    1.13                  return -1;
    1.14              }
    1.15          }
    1.16 +#if !TARGET_OS_TV
    1.17 +		SDL_OnApplicationDidChangeStatusBarOrientation();
    1.18 +#endif
    1.19      }
    1.20  
    1.21      return 0;
    1.22 @@ -319,6 +324,55 @@
    1.23      }
    1.24  }
    1.25  
    1.26 +void SDL_OnApplicationDidChangeStatusBarOrientation()
    1.27 +{
    1.28 +    BOOL isLandscape = UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation);
    1.29 +    SDL_VideoDisplay *display = SDL_GetDisplay(0);
    1.30 +
    1.31 +    if (display) {
    1.32 +        SDL_DisplayMode *desktopmode = &display->desktop_mode;
    1.33 +        SDL_DisplayMode *currentmode = &display->current_mode;
    1.34 +        SDL_DisplayOrientation orientation = SDL_ORIENTATION_UNKNOWN;
    1.35 +
    1.36 +        /* The desktop display mode should be kept in sync with the screen
    1.37 +         * orientation so that updating a window's fullscreen state to
    1.38 +         * SDL_WINDOW_FULLSCREEN_DESKTOP keeps the window dimensions in the
    1.39 +         * correct orientation. */
    1.40 +        if (isLandscape != (desktopmode->w > desktopmode->h)) {
    1.41 +            int height = desktopmode->w;
    1.42 +            desktopmode->w = desktopmode->h;
    1.43 +            desktopmode->h = height;
    1.44 +        }
    1.45 +
    1.46 +        /* Same deal with the current mode + SDL_GetCurrentDisplayMode. */
    1.47 +        if (isLandscape != (currentmode->w > currentmode->h)) {
    1.48 +            int height = currentmode->w;
    1.49 +            currentmode->w = currentmode->h;
    1.50 +            currentmode->h = height;
    1.51 +        }
    1.52 +
    1.53 +        switch ([UIApplication sharedApplication].statusBarOrientation) {
    1.54 +        case UIInterfaceOrientationPortrait:
    1.55 +            orientation = SDL_ORIENTATION_PORTRAIT;
    1.56 +            break;
    1.57 +        case UIInterfaceOrientationPortraitUpsideDown:
    1.58 +            orientation = SDL_ORIENTATION_PORTRAIT_FLIPPED;
    1.59 +            break;
    1.60 +        case UIInterfaceOrientationLandscapeLeft:
    1.61 +            /* Bug: UIInterfaceOrientationLandscapeLeft/Right are reversed - http://openradar.appspot.com/7216046 */
    1.62 +            orientation = SDL_ORIENTATION_LANDSCAPE_FLIPPED;
    1.63 +            break;
    1.64 +        case UIInterfaceOrientationLandscapeRight:
    1.65 +            /* Bug: UIInterfaceOrientationLandscapeLeft/Right are reversed - http://openradar.appspot.com/7216046 */
    1.66 +            orientation = SDL_ORIENTATION_LANDSCAPE;
    1.67 +            break;
    1.68 +        default:
    1.69 +            break;
    1.70 +        }
    1.71 +        SDL_SendDisplayEvent(display, SDL_DISPLAYEVENT_ORIENTATION, orientation);
    1.72 +    }
    1.73 +}
    1.74 +
    1.75  #endif /* SDL_VIDEO_DRIVER_UIKIT */
    1.76  
    1.77  /* vi: set ts=4 sw=4 expandtab: */