21 #include "../../SDL_internal.h" 23 #if SDL_VIDEO_DRIVER_UIKIT 30 #include "../SDL_sysvideo.h" 31 #include "../SDL_pixels_c.h" 32 #include "../../events/SDL_events_c.h" 43 #include <Foundation/Foundation.h> 53 if ((
self = [super init])) {
54 views = [NSMutableArray new];
62 @interface SDL_uikitwindow : UIWindow
64 - (
void)layoutSubviews;
68 @implementation SDL_uikitwindow
70 - (
void)layoutSubviews
73 self.frame =
self.screen.bounds;
74 [
super layoutSubviews];
86 CGRect
frame = UIKit_ComputeViewFrame(window, displaydata.
uiscreen);
95 window->
driverdata = (
void *) CFBridgingRetain(data);
102 if (displaydata.
uiscreen != [UIScreen mainScreen]) {
109 if (displaydata.
uiscreen == [UIScreen mainScreen]) {
111 BOOL supportsLandscape = (orients & UIInterfaceOrientationMaskLandscape) != 0;
112 BOOL supportsPortrait = (orients & (UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown)) != 0;
115 if ((width >
height && !supportsLandscape) || (
height > width && !supportsPortrait)) {
138 [view setSDLWindow:window];
141 if (displaydata.
uiscreen == [UIScreen mainScreen]) {
161 return SDL_SetError(
"Only one window allowed per display.");
168 const CGSize origsize = data.
uiscreen.currentMode.size;
169 if ((origsize.width == 0.0f) && (origsize.height == 0.0f)) {
178 if ((mode->
w >= window->
w) && (mode->
h >= window->
h)) {
194 if (data.
uiscreen == [UIScreen mainScreen]) {
196 [UIApplication sharedApplication].statusBarHidden = YES;
198 [UIApplication sharedApplication].statusBarHidden = NO;
205 UIWindow *uiwindow = [[SDL_uikitwindow alloc] initWithFrame:data.uiscreen.bounds];
208 if (data.
uiscreen != [UIScreen mainScreen]) {
209 [uiwindow setScreen:data.uiscreen];
212 if (SetupWindowData(
_this, window, uiwindow,
SDL_TRUE) < 0) {
264 if (data.
uiwindow.screen == [UIScreen mainScreen]) {
266 [UIApplication sharedApplication].statusBarHidden = YES;
268 [UIApplication sharedApplication].statusBarHidden = NO;
272 if ([
viewcontroller respondsToSelector:
@selector(setNeedsStatusBarAppearanceUpdate)]) {
273 [viewcontroller setNeedsStatusBarAppearanceUpdate];
281 #ifdef SDL_IPHONE_KEYBOARD 283 [viewcontroller updateKeyboard];
286 [viewcontroller.view setNeedsLayout];
287 [viewcontroller.view layoutIfNeeded];
294 UIKit_UpdateWindowBorder(
_this, window);
302 UIKit_UpdateWindowBorder(
_this, window);
312 NSArray *
views = nil;
314 [data.viewcontroller stopAnimation];
319 views = [data.views copy];
321 [view setSDLWindow:NULL];
328 data.
uiwindow.rootViewController = nil;
350 SDL_uikitopenglview *glview = (SDL_uikitopenglview *)data.
viewcontroller.view;
355 info->
info.uikit.framebuffer = 0;
356 info->
info.uikit.colorbuffer = 0;
357 info->
info.uikit.resolveFramebuffer = 0;
363 SDL_SetError(
"Application not compiled with SDL %d.%d\n",
375 NSUInteger validOrientations = UIInterfaceOrientationMaskAll;
376 NSUInteger orientationMask = 0;
380 UIApplication *app = [UIApplication sharedApplication];
384 if ([app.delegate respondsToSelector:
@selector(application:supportedInterfaceOrientationsForWindow:)]) {
385 validOrientations = [app.delegate application:app supportedInterfaceOrientationsForWindow:data.uiwindow];
386 }
else if ([app respondsToSelector:
@selector(supportedInterfaceOrientationsForWindow:)]) {
387 validOrientations = [app supportedInterfaceOrientationsForWindow:data.uiwindow];
391 NSArray *orientations = [@(hint) componentsSeparatedByString:@" "];
393 if ([orientations containsObject:
@"LandscapeLeft"]) {
394 orientationMask |= UIInterfaceOrientationMaskLandscapeLeft;
396 if ([orientations containsObject:
@"LandscapeRight"]) {
397 orientationMask |= UIInterfaceOrientationMaskLandscapeRight;
399 if ([orientations containsObject:
@"Portrait"]) {
400 orientationMask |= UIInterfaceOrientationMaskPortrait;
402 if ([orientations containsObject:
@"PortraitUpsideDown"]) {
403 orientationMask |= UIInterfaceOrientationMaskPortraitUpsideDown;
409 orientationMask = UIInterfaceOrientationMaskAll;
412 if (orientationMask == 0) {
413 if (window->
w >= window->
h) {
414 orientationMask |= UIInterfaceOrientationMaskLandscape;
416 if (window->
h >= window->
w) {
417 orientationMask |= (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
422 if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
423 orientationMask &= ~UIInterfaceOrientationMaskPortraitUpsideDown;
429 if ((validOrientations & orientationMask) == 0) {
430 orientationMask = validOrientations;
434 return orientationMask;
449 callbackParam:callbackParam];
#define SDL_MINOR_VERSION
SDL_bool UIKit_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
void SDL_SetKeyboardFocus(SDL_Window *window)
int UIKit_CreateWindow(_THIS, SDL_Window *window)
GLint GLint GLsizei width
GLuint drawableRenderbuffer
void UIKit_DestroyWindow(_THIS, SDL_Window *window)
#define SDL_MAJOR_VERSION
SDL_uikitviewcontroller * viewcontroller
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
The structure that defines a display mode.
void UIKit_SetWindowTitle(_THIS, SDL_Window *window)
void UIKit_RaiseWindow(_THIS, SDL_Window *window)
void UIKit_HideWindow(_THIS, SDL_Window *window)
void SDL_SetMouseFocus(SDL_Window *window)
GLuint drawableFramebuffer
GLuint msaaResolveFramebuffer
GLint GLint GLsizei GLsizei height
void UIKit_SetWindowBordered(_THIS, SDL_Window *window, SDL_bool bordered)
NSUInteger UIKit_GetSupportedOrientations(SDL_Window *window)
static SDL_VideoDevice * _this
SDL_GLContext current_glctx
void UIKit_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
int(* GL_MakeCurrent)(_THIS, SDL_Window *window, SDL_GLContext context)
#define SDL_VERSIONNUM(X, Y, Z)
SDL_DisplayMode * display_modes
SDL_DisplayMode current_mode
static Uint32 callback(Uint32 interval, void *param)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
#define SDL_assert(condition)
void(* GetDisplayModes)(_THIS, SDL_VideoDisplay *display)
#define SDL_HINT_ORIENTATIONS
A variable controlling which orientations are allowed on iOS.
#define SDL_OutOfMemory()
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
UIScreenMode * uiscreenmode
SDL_VideoDisplay * SDL_GetDisplayForWindow(SDL_Window *window)
The type used to identify a window.
union SDL_SysWMinfo::@18 info
void UIKit_ShowWindow(_THIS, SDL_Window *window)
SDL_Window * current_glwin
#define SDL_iPhoneSetAnimationCallback