Added support for SDL_SetWindowBordered on iOS. Worked around a bug with rotating the device on iOS 8.
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 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index 1c46515..92f31cd 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -346,7 +346,7 @@ extern "C" {
/**
- * \brief If set to 1, then do not allow high-DPI windows. ("Retina" on Mac)
+ * \brief If set to 1, then do not allow high-DPI windows. ("Retina" on Mac and iOS)
*/
#define SDL_HINT_VIDEO_HIGHDPI_DISABLED "SDL_VIDEO_HIGHDPI_DISABLED"
diff --git a/src/video/uikit/SDL_uikitappdelegate.m b/src/video/uikit/SDL_uikitappdelegate.m
index 8be3790..ed01b70 100644
--- a/src/video/uikit/SDL_uikitappdelegate.m
+++ b/src/video/uikit/SDL_uikitappdelegate.m
@@ -244,22 +244,29 @@ SDL_IdleTimerDisabledChanged(void *userdata, const char *name, const char *oldVa
- (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation
{
- UIInterfaceOrientation orientation = application.statusBarOrientation;
+ BOOL isLandscape = UIInterfaceOrientationIsLandscape(application.statusBarOrientation);
SDL_VideoDevice *_this = SDL_GetVideoDevice();
if (_this && _this->num_displays > 0) {
- SDL_VideoDisplay *display = &_this->displays[0]; /* Main screen. */
- SDL_DisplayMode *mode = &display->desktop_mode;
+ SDL_DisplayMode *desktopmode = &_this->displays[0].desktop_mode;
+ SDL_DisplayMode *currentmode = &_this->displays[0].current_mode;
/* The desktop display mode should be kept in sync with the screen
* orientation so that updating a window's fullscreen state to
* SDL_WINDOW_FULLSCREEN_DESKTOP keeps the window dimensions in the
* correct orientation.
*/
- if (UIInterfaceOrientationIsLandscape(orientation) != (mode->w > mode->h)) {
- int height = mode->w;
- mode->w = mode->h;
- mode->h = height;
+ if (isLandscape != (desktopmode->w > desktopmode->h)) {
+ int height = desktopmode->w;
+ desktopmode->w = desktopmode->h;
+ desktopmode->h = height;
+ }
+
+ /* Same deal with the current mode + SDL_GetCurrentDisplayMode. */
+ if (isLandscape != (currentmode->w > currentmode->h)) {
+ int height = currentmode->w;
+ currentmode->w = currentmode->h;
+ currentmode->h = height;
}
}
}
diff --git a/src/video/uikit/SDL_uikitmessagebox.m b/src/video/uikit/SDL_uikitmessagebox.m
index 4a1d32b..1cb7344 100644
--- a/src/video/uikit/SDL_uikitmessagebox.m
+++ b/src/video/uikit/SDL_uikitmessagebox.m
@@ -32,7 +32,7 @@ static SDL_bool s_showingMessageBox = SDL_FALSE;
@interface UIKit_UIAlertViewDelegate : NSObject <UIAlertViewDelegate>
-- (id)initWithButtonIndex:(int *)_buttonIndex;
+- (id)initWithButtonIndex:(int *)buttonIndex;
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;
@end
diff --git a/src/video/uikit/SDL_uikitvideo.m b/src/video/uikit/SDL_uikitvideo.m
index 01783b2..5d4e812 100644
--- a/src/video/uikit/SDL_uikitvideo.m
+++ b/src/video/uikit/SDL_uikitvideo.m
@@ -78,12 +78,11 @@ UIKit_CreateDevice(int devindex)
device->ShowWindow = UIKit_ShowWindow;
device->HideWindow = UIKit_HideWindow;
device->RaiseWindow = UIKit_RaiseWindow;
+ device->SetWindowBordered = UIKit_SetWindowBordered;
device->SetWindowFullscreen = UIKit_SetWindowFullscreen;
device->DestroyWindow = UIKit_DestroyWindow;
device->GetWindowWMInfo = UIKit_GetWindowWMInfo;
- /* !!! FIXME: implement SetWindowBordered */
-
#if SDL_IPHONE_KEYBOARD
device->HasScreenKeyboardSupport = UIKit_HasScreenKeyboardSupport;
device->ShowScreenKeyboard = UIKit_ShowScreenKeyboard;
diff --git a/src/video/uikit/SDL_uikitview.m b/src/video/uikit/SDL_uikitview.m
index 3a2676e..620ea28 100644
--- a/src/video/uikit/SDL_uikitview.m
+++ b/src/video/uikit/SDL_uikitview.m
@@ -51,23 +51,18 @@ void _uikit_keyboard_init();
}
-- (void)dealloc
-{
- [super dealloc];
-}
-
- (id)initWithFrame:(CGRect)frame
{
- self = [super initWithFrame: frame];
-
+ if (self = [super initWithFrame: frame]) {
#if SDL_IPHONE_KEYBOARD
- [self initializeKeyboard];
+ [self initializeKeyboard];
#endif
- self.multipleTouchEnabled = YES;
+ self.multipleTouchEnabled = YES;
- touchId = 1;
- SDL_AddTouch(touchId, "");
+ touchId = 1;
+ SDL_AddTouch(touchId, "");
+ }
return self;
diff --git a/src/video/uikit/SDL_uikitviewcontroller.m b/src/video/uikit/SDL_uikitviewcontroller.m
index c7b3d09..9e5b026 100644
--- a/src/video/uikit/SDL_uikitviewcontroller.m
+++ b/src/video/uikit/SDL_uikitviewcontroller.m
@@ -40,12 +40,9 @@
- (id)initWithSDLWindow:(SDL_Window *)_window
{
- self = [self init];
- if (self == nil) {
- return nil;
+ if (self = [super initWithNibName:nil bundle:nil]) {
+ self.window = _window;
}
- self.window = _window;
-
return self;
}
@@ -56,8 +53,7 @@
- (void)viewDidLayoutSubviews
{
- SDL_WindowData *data = window->driverdata;
- const CGSize size = data->view.bounds.size;
+ const CGSize size = self.view.bounds.size;
int w = (int) size.width;
int h = (int) size.height;
diff --git a/src/video/uikit/SDL_uikitwindow.h b/src/video/uikit/SDL_uikitwindow.h
index 494b028..f6d67f0 100644
--- a/src/video/uikit/SDL_uikitwindow.h
+++ b/src/video/uikit/SDL_uikitwindow.h
@@ -32,6 +32,7 @@ extern int UIKit_CreateWindow(_THIS, SDL_Window * window);
extern void UIKit_ShowWindow(_THIS, SDL_Window * window);
extern void UIKit_HideWindow(_THIS, SDL_Window * window);
extern void UIKit_RaiseWindow(_THIS, SDL_Window * window);
+extern void UIKit_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
extern void UIKit_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
extern void UIKit_DestroyWindow(_THIS, SDL_Window * window);
extern SDL_bool UIKit_GetWindowWMInfo(_THIS, SDL_Window * window,
@@ -39,9 +40,13 @@ extern SDL_bool UIKit_GetWindowWMInfo(_THIS, SDL_Window * window,
@class UIWindow;
+@interface SDL_uikitwindow : UIWindow
+
+@end
+
struct SDL_WindowData
{
- UIWindow *uiwindow;
+ SDL_uikitwindow *uiwindow;
SDL_uikitopenglview *view;
SDL_uikitviewcontroller *viewcontroller;
};
diff --git a/src/video/uikit/SDL_uikitwindow.m b/src/video/uikit/SDL_uikitwindow.m
index 02dafd6..7e3fac6 100644
--- a/src/video/uikit/SDL_uikitwindow.m
+++ b/src/video/uikit/SDL_uikitwindow.m
@@ -41,8 +41,23 @@
#include <Foundation/Foundation.h>
+@implementation SDL_uikitwindow
-static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created)
+- (void)layoutSubviews
+{
+ [super layoutSubviews];
+
+ /* This seems to be needed on iOS 8, otherwise the window's frame is put in
+ * an unexpected position when the screen or device is rotated.
+ * FIXME: is there a better solution to that problem than this ugly hack?
+ */
+ self.frame = self.screen.bounds;
+}
+
+@end
+
+
+static int SetupWindowData(_THIS, SDL_Window *window, SDL_uikitwindow *uiwindow, SDL_bool created)
{
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
@@ -181,7 +196,7 @@ UIKit_CreateWindow(_THIS, SDL_Window *window)
/* ignore the size user requested, and make a fullscreen window */
/* !!! FIXME: can we have a smaller view? */
- UIWindow *uiwindow = [[UIWindow alloc] initWithFrame:[data->uiscreen bounds]];
+ SDL_uikitwindow *uiwindow = [[SDL_uikitwindow alloc] initWithFrame:data->uiscreen.bounds];
/* put the window on an external display if appropriate. This implicitly
* does [uiwindow setframe:[uiscreen bounds]], so don't do it on the
@@ -198,7 +213,6 @@ UIKit_CreateWindow(_THIS, SDL_Window *window)
}
return 1;
-
}
void
@@ -228,48 +242,60 @@ UIKit_RaiseWindow(_THIS, SDL_Window * window)
_this->GL_MakeCurrent(_this, _this->current_glwin, _this->current_glctx);
}
-void
-UIKit_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
+static void
+UIKit_UpdateWindowBorder(_THIS, SDL_Window * window)
{
- SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
SDL_WindowData *windowdata = (SDL_WindowData *) window->driverdata;
SDL_uikitviewcontroller *viewcontroller = windowdata->viewcontroller;
CGRect frame;
- if (fullscreen || (window->flags & SDL_WINDOW_BORDERLESS)) {
- [UIApplication sharedApplication].statusBarHidden = YES;
- } else {
- [UIApplication sharedApplication].statusBarHidden = NO;
- }
+ if (windowdata->uiwindow.screen == [UIScreen mainScreen]) {
+ if (window->flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS)) {
+ [UIApplication sharedApplication].statusBarHidden = YES;
+ } else {
+ [UIApplication sharedApplication].statusBarHidden = NO;
+ }
- /* iOS 7+ won't update the status bar until we tell it to. */
- if ([viewcontroller respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
- [viewcontroller setNeedsStatusBarAppearanceUpdate];
+ /* iOS 7+ won't update the status bar until we tell it to. */
+ if ([viewcontroller respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
+ [viewcontroller setNeedsStatusBarAppearanceUpdate];
+ }
}
/* Update the view's frame to account for the status bar change. */
- frame = UIKit_ComputeViewFrame(window, displaydata->uiscreen);
+ frame = UIKit_ComputeViewFrame(window, windowdata->uiwindow.screen);
+
windowdata->view.frame = frame;
[windowdata->view setNeedsLayout];
[windowdata->view layoutIfNeeded];
/* Get frame dimensions */
- int width = (int) frame.size.width;
+ int width = (int) frame.size.width;
int height = (int) frame.size.height;
/* We can pick either width or height here and we'll rotate the
- screen to match, so we pick the closest to what we wanted.
+ screen to match, so we pick the closest to what we wanted.
*/
if (window->w >= window->h) {
- window->w = SDL_max(width, height);
- window->h = SDL_min(width, height);
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, SDL_max(width, height), SDL_min(width, height));
} else {
- window->w = SDL_min(width, height);
- window->h = SDL_max(width, height);
+ SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, SDL_min(width, height), SDL_max(width, height));
}
}
void
+UIKit_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
+{
+ UIKit_UpdateWindowBorder(_this, window);
+}
+
+void
+UIKit_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen)
+{
+ UIKit_UpdateWindowBorder(_this, window);
+}
+
+void
UIKit_DestroyWindow(_THIS, SDL_Window * window)
{
SDL_WindowData *data = (SDL_WindowData *)window->driverdata;