Fixed mismatching orientations for the window width and height on iOS when the window is created or the app is brought to the foreground, when SDL_HINT_ORIENTATIONS or SDL_WINDOW_FULLSCREEN is used.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
diff --git a/src/video/uikit/SDL_uikitviewcontroller.m b/src/video/uikit/SDL_uikitviewcontroller.m
index 0a9fbab..de5b300 100644
--- a/src/video/uikit/SDL_uikitviewcontroller.m
+++ b/src/video/uikit/SDL_uikitviewcontroller.m
@@ -62,44 +62,7 @@
- (NSUInteger)supportedInterfaceOrientations
{
- NSUInteger orientationMask = 0;
- const char *hint = SDL_GetHint(SDL_HINT_ORIENTATIONS);
-
- if (hint != NULL) {
- NSArray *orientations = [@(hint) componentsSeparatedByString:@" "];
-
- if ([orientations containsObject:@"LandscapeLeft"]) {
- orientationMask |= UIInterfaceOrientationMaskLandscapeLeft;
- }
- if ([orientations containsObject:@"LandscapeRight"]) {
- orientationMask |= UIInterfaceOrientationMaskLandscapeRight;
- }
- if ([orientations containsObject:@"Portrait"]) {
- orientationMask |= UIInterfaceOrientationMaskPortrait;
- }
- if ([orientations containsObject:@"PortraitUpsideDown"]) {
- orientationMask |= UIInterfaceOrientationMaskPortraitUpsideDown;
- }
- }
-
- if (orientationMask == 0 && (window->flags & SDL_WINDOW_RESIZABLE)) {
- orientationMask = UIInterfaceOrientationMaskAll; /* any orientation is okay. */
- }
-
- if (orientationMask == 0) {
- if (window->w >= window->h) {
- orientationMask |= UIInterfaceOrientationMaskLandscape;
- }
- if (window->h >= window->w) {
- orientationMask |= (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
- }
- }
-
- /* Don't allow upside-down orientation on the phone, so answering calls is in the natural orientation */
- if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
- orientationMask &= ~UIInterfaceOrientationMaskPortraitUpsideDown;
- }
- return orientationMask;
+ return UIKit_GetSupportedOrientations(window);
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient
@@ -119,7 +82,7 @@
- (UIStatusBarStyle)preferredStatusBarStyle
{
- /* We assume most games don't have a bright white background. */
+ /* We assume most SDL apps don't have a bright white background. */
return UIStatusBarStyleLightContent;
}
diff --git a/src/video/uikit/SDL_uikitwindow.h b/src/video/uikit/SDL_uikitwindow.h
index 17e9e1b..c279d0f 100644
--- a/src/video/uikit/SDL_uikitwindow.h
+++ b/src/video/uikit/SDL_uikitwindow.h
@@ -36,6 +36,8 @@ extern void UIKit_DestroyWindow(_THIS, SDL_Window * window);
extern SDL_bool UIKit_GetWindowWMInfo(_THIS, SDL_Window * window,
struct SDL_SysWMinfo * info);
+extern NSUInteger UIKit_GetSupportedOrientations(SDL_Window * window);
+
@class UIWindow;
@interface SDL_uikitwindow : UIWindow
diff --git a/src/video/uikit/SDL_uikitwindow.m b/src/video/uikit/SDL_uikitwindow.m
index a250ca5..0c2f120 100644
--- a/src/video/uikit/SDL_uikitwindow.m
+++ b/src/video/uikit/SDL_uikitwindow.m
@@ -80,9 +80,6 @@ static int SetupWindowData(_THIS, SDL_Window *window, SDL_uikitwindow *uiwindow,
/* Fill in the SDL window with the window data */
{
- window->x = 0;
- window->y = 0;
-
CGRect frame = UIKit_ComputeViewFrame(window, displaydata.uiscreen);
/* Get frame dimensions */
@@ -96,6 +93,8 @@ static int SetupWindowData(_THIS, SDL_Window *window, SDL_uikitwindow *uiwindow,
height = temp;
}
+ window->x = 0;
+ window->y = 0;
window->w = width;
window->h = height;
}
@@ -182,21 +181,32 @@ UIKit_CreateWindow(_THIS, SDL_Window *window)
}
if (data.uiscreen == [UIScreen mainScreen]) {
+ NSUInteger orientations = UIKit_GetSupportedOrientations(window);
+ UIApplication *app = [UIApplication sharedApplication];
+
if (window->flags & (SDL_WINDOW_FULLSCREEN|SDL_WINDOW_BORDERLESS)) {
- [UIApplication sharedApplication].statusBarHidden = YES;
+ app.statusBarHidden = YES;
} else {
- [UIApplication sharedApplication].statusBarHidden = NO;
+ app.statusBarHidden = NO;
}
- }
- if (!(window->flags & SDL_WINDOW_RESIZABLE)) {
- if (window->w > window->h) {
- if (!UIKit_IsDisplayLandscape(data.uiscreen)) {
- [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
+ /* Make sure the screen is using a supported orientation. We do it
+ * now so that SetupWindowData assigns the properly oriented width
+ * and height to the window's w and h variables.
+ */
+ if (UIKit_IsDisplayLandscape(data.uiscreen)) {
+ if (!(orientations & UIInterfaceOrientationMaskLandscape)) {
+ [app setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
}
- } else if (window->w < window->h) {
- if (UIKit_IsDisplayLandscape(data.uiscreen)) {
- [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
+ } else {
+ if (!(orientations & (UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown))) {
+ UIInterfaceOrientation orient = UIInterfaceOrientationLandscapeLeft;
+
+ if (orientations & UIInterfaceOrientationMaskLandscapeRight) {
+ orient = UIInterfaceOrientationLandscapeRight;
+ }
+
+ [app setStatusBarOrientation:orient animated:NO];
}
}
}
@@ -228,7 +238,6 @@ UIKit_ShowWindow(_THIS, SDL_Window * window)
{
@autoreleasepool {
UIWindow *uiwindow = ((__bridge SDL_WindowData *) window->driverdata).uiwindow;
-
[uiwindow makeKeyAndVisible];
}
}
@@ -238,7 +247,6 @@ UIKit_HideWindow(_THIS, SDL_Window * window)
{
@autoreleasepool {
UIWindow *uiwindow = ((__bridge SDL_WindowData *) window->driverdata).uiwindow;
-
uiwindow.hidden = YES;
}
}
@@ -341,6 +349,53 @@ UIKit_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
}
}
+NSUInteger
+UIKit_GetSupportedOrientations(SDL_Window * window)
+{
+ const char *hint = SDL_GetHint(SDL_HINT_ORIENTATIONS);
+ NSUInteger orientationMask = 0;
+
+ @autoreleasepool {
+ if (hint != NULL) {
+ NSArray *orientations = [@(hint) componentsSeparatedByString:@" "];
+
+ if ([orientations containsObject:@"LandscapeLeft"]) {
+ orientationMask |= UIInterfaceOrientationMaskLandscapeLeft;
+ }
+ if ([orientations containsObject:@"LandscapeRight"]) {
+ orientationMask |= UIInterfaceOrientationMaskLandscapeRight;
+ }
+ if ([orientations containsObject:@"Portrait"]) {
+ orientationMask |= UIInterfaceOrientationMaskPortrait;
+ }
+ if ([orientations containsObject:@"PortraitUpsideDown"]) {
+ orientationMask |= UIInterfaceOrientationMaskPortraitUpsideDown;
+ }
+ }
+
+ if (orientationMask == 0 && (window->flags & SDL_WINDOW_RESIZABLE)) {
+ /* any orientation is okay. */
+ orientationMask = UIInterfaceOrientationMaskAll;
+ }
+
+ if (orientationMask == 0) {
+ if (window->w >= window->h) {
+ orientationMask |= UIInterfaceOrientationMaskLandscape;
+ }
+ if (window->h >= window->w) {
+ orientationMask |= (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
+ }
+ }
+
+ /* Don't allow upside-down orientation on the phone, so answering calls is in the natural orientation */
+ if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
+ orientationMask &= ~UIInterfaceOrientationMaskPortraitUpsideDown;
+ }
+ }
+
+ return orientationMask;
+}
+
int
SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam)
{