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
79 self.frame =
self.screen.bounds;
81 [
super layoutSubviews];
103 window->driverdata = (
void *) CFBridgingRetain(
data);
105 data.uiwindow = uiwindow;
108 window->flags &= ~SDL_WINDOW_HIDDEN;
110 if (displaydata.
uiscreen != [UIScreen mainScreen]) {
111 window->flags &= ~SDL_WINDOW_RESIZABLE;
112 window->flags &= ~SDL_WINDOW_INPUT_FOCUS;
117 if (displaydata.
uiscreen == [UIScreen mainScreen]) {
127 BOOL supportsLandscape = (orients & UIInterfaceOrientationMaskLandscape) != 0;
128 BOOL supportsPortrait = (orients & (UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown)) != 0;
154 [view setSDLWindow:window];
171 return SDL_SetError(
"Only one window allowed per display.");
178 const CGSize origsize =
data.uiscreen.currentMode.size;
179 if ((origsize.width == 0.0f) && (origsize.height == 0.0f)) {
204 if (
data.uiscreen == [UIScreen mainScreen]) {
206 [UIApplication sharedApplication].statusBarHidden = YES;
208 [UIApplication sharedApplication].statusBarHidden = NO;
215 UIWindow *uiwindow = [[SDL_uikitwindow alloc] initWithFrame:data.uiscreen.bounds];
218 if (
data.uiscreen != [UIScreen mainScreen]) {
219 [uiwindow setScreen:data.uiscreen];
244 [
data.uiwindow makeKeyAndVisible];
249 if (displaydata.
uiscreen == [UIScreen mainScreen]) {
282 if (
data.uiwindow.screen == [UIScreen mainScreen]) {
284 [UIApplication sharedApplication].statusBarHidden = YES;
286 [UIApplication sharedApplication].statusBarHidden = NO;
290 if ([viewcontroller respondsToSelector:
@selector(setNeedsStatusBarAppearanceUpdate)]) {
291 [viewcontroller setNeedsStatusBarAppearanceUpdate];
296 viewcontroller.view.frame = UIKit_ComputeViewFrame(
window,
data.uiwindow.screen);
299#ifdef SDL_IPHONE_KEYBOARD
301 [viewcontroller updateKeyboard];
304 [viewcontroller.view setNeedsLayout];
305 [viewcontroller.view layoutIfNeeded];
330 NSArray *views = nil;
332 [data.viewcontroller stopAnimation];
337 views = [data.views copy];
339 [view setSDLWindow:NULL];
347 data.uiwindow.hidden = YES;
373 info->
info.uikit.framebuffer = 0;
374 info->
info.uikit.colorbuffer = 0;
375 info->
info.uikit.resolveFramebuffer = 0;
393 NSUInteger validOrientations = UIInterfaceOrientationMaskAll;
394 NSUInteger orientationMask = 0;
398 UIApplication *app = [UIApplication sharedApplication];
402 if ([app.delegate respondsToSelector:
@selector(application:supportedInterfaceOrientationsForWindow:)]) {
403 validOrientations = [app.delegate application:app supportedInterfaceOrientationsForWindow:data.uiwindow];
404 }
else if ([app respondsToSelector:
@selector(supportedInterfaceOrientationsForWindow:)]) {
405 validOrientations = [app supportedInterfaceOrientationsForWindow:data.uiwindow];
409 NSArray *orientations = [@(hint) componentsSeparatedByString:@" "];
411 if ([orientations containsObject:
@"LandscapeLeft"]) {
412 orientationMask |= UIInterfaceOrientationMaskLandscapeLeft;
414 if ([orientations containsObject:
@"LandscapeRight"]) {
415 orientationMask |= UIInterfaceOrientationMaskLandscapeRight;
417 if ([orientations containsObject:
@"Portrait"]) {
418 orientationMask |= UIInterfaceOrientationMaskPortrait;
420 if ([orientations containsObject:
@"PortraitUpsideDown"]) {
421 orientationMask |= UIInterfaceOrientationMaskPortraitUpsideDown;
427 orientationMask = UIInterfaceOrientationMaskAll;
430 if (orientationMask == 0) {
432 orientationMask |= UIInterfaceOrientationMaskLandscape;
435 orientationMask |= (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
440 if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
441 orientationMask &= ~UIInterfaceOrientationMaskPortraitUpsideDown;
447 if ((validOrientations & orientationMask) == 0) {
448 orientationMask = validOrientations;
452 return orientationMask;
465 [
data.viewcontroller setAnimationCallback:interval
467 callbackParam:callbackParam];
#define SDL_assert(condition)
#define SDL_iPhoneSetAnimationCallback
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
#define SDL_OutOfMemory()
#define SDL_HINT_ORIENTATIONS
A variable controlling which orientations are allowed on iOS/Android.
void SDL_SetKeyboardFocus(SDL_Window *window)
void SDL_SetMouseFocus(SDL_Window *window)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLint GLint GLsizei width
GLint GLint GLsizei GLsizei height
SDL_VideoDisplay * SDL_GetDisplayForWindow(SDL_Window *window)
SDL_bool UIKit_IsSystemVersionAtLeast(double version)
void UIKit_ShowWindow(_THIS, SDL_Window *window)
void UIKit_RaiseWindow(_THIS, SDL_Window *window)
SDL_bool UIKit_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
void UIKit_SetWindowBordered(_THIS, SDL_Window *window, SDL_bool bordered)
void UIKit_SetWindowTitle(_THIS, SDL_Window *window)
void UIKit_DestroyWindow(_THIS, SDL_Window *window)
void UIKit_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *display, SDL_bool fullscreen)
NSUInteger UIKit_GetSupportedOrientations(SDL_Window *window)
int UIKit_CreateWindow(_THIS, SDL_Window *window)
void UIKit_HideWindow(_THIS, SDL_Window *window)
#define SDL_MINOR_VERSION
#define SDL_MAJOR_VERSION
#define SDL_VERSIONNUM(X, Y, Z)
static SDL_VideoDevice * _this
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)
EGLSurface EGLNativeWindowType * window
GLuint drawableFramebuffer
GLuint msaaResolveFramebuffer
GLuint drawableRenderbuffer
UIScreenMode * uiscreenmode
The structure that defines a display mode.
union SDL_SysWMinfo::@17 info
int(* GL_MakeCurrent)(_THIS, SDL_Window *window, SDL_GLContext context)
SDL_GLContext current_glctx
void(* GetDisplayModes)(_THIS, SDL_VideoDisplay *display)
SDL_Window * current_glwin
SDL_DisplayMode * display_modes
SDL_DisplayMode current_mode
SDL_uikitviewcontroller * viewcontroller
The type used to identify a window.
static Uint32 callback(Uint32 interval, void *param)