21 #include "../../SDL_internal.h" 23 #if SDL_VIDEO_DRIVER_UIKIT 25 #include "../SDL_sysvideo.h" 35 #include "../../events/SDL_events_c.h" 41 static int forward_argc;
42 static char **forward_argv;
43 static int exit_status;
45 int main(
int argc,
char **argv)
51 forward_argv = (
char **)
malloc((argc+1) *
sizeof(
char *));
52 for (i = 0; i < argc; i++) {
53 forward_argv[i] =
malloc( (strlen(argv[i])+1) *
sizeof(
char));
54 strcpy(forward_argv[i], argv[i]);
56 forward_argv[i] =
NULL;
64 for (i = 0; i < forward_argc; i++) {
65 free(forward_argv[i]);
73 SDL_IdleTimerDisabledChanged(
void *userdata,
const char *
name,
const char *oldValue,
const char *hint)
75 BOOL disable = (hint && *hint !=
'0');
76 [UIApplication sharedApplication].idleTimerDisabled = disable;
82 SDL_LoadLaunchImageNamed(NSString *
name,
int screenh)
84 UIInterfaceOrientation curorient = [UIApplication sharedApplication].statusBarOrientation;
85 UIUserInterfaceIdiom idiom = [UIDevice currentDevice].userInterfaceIdiom;
88 if (idiom == UIUserInterfaceIdiomPhone && screenh == 568) {
90 image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-568h", name]];
91 }
else if (idiom == UIUserInterfaceIdiomPad) {
93 if (UIInterfaceOrientationIsLandscape(curorient)) {
94 if (curorient == UIInterfaceOrientationLandscapeLeft) {
95 image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-LandscapeLeft", name]];
97 image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-LandscapeRight", name]];
100 image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-Landscape", name]];
103 if (curorient == UIInterfaceOrientationPortraitUpsideDown) {
104 image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-PortraitUpsideDown", name]];
107 image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-Portrait", name]];
113 image = [UIImage imageNamed:name];
123 - (NSUInteger)supportedInterfaceOrientations;
132 return [
self initWithNibName:nil bundle:[NSBundle mainBundle]];
135 - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
137 if (!(
self = [super initWithNibName:nil bundle:nil])) {
141 NSString *screenname = nibNameOrNil;
142 NSBundle *bundle = nibBundleOrNil;
146 if (screenname && atleastiOS8) {
148 self.view = [bundle loadNibNamed:screenname owner:self options:nil][0];
150 @catch (NSException *exception) {
158 NSArray *launchimages = [bundle objectForInfoDictionaryKey:@"UILaunchImages"];
159 NSString *imagename = nil;
160 UIImage *image = nil;
162 int screenw = (int)([UIScreen mainScreen].bounds.size.width + 0.5);
163 int screenh = (int)([UIScreen mainScreen].bounds.size.height + 0.5);
166 UIInterfaceOrientation curorient = [UIApplication sharedApplication].statusBarOrientation;
169 if (screenw > screenh) {
178 for (NSDictionary *dict
in launchimages) {
179 NSString *minversion = dict[@"UILaunchImageMinimumOSVersion"];
180 NSString *sizestring = dict[@"UILaunchImageSize"];
189 CGSize
size = CGSizeFromString(sizestring);
190 if ((
int)(size.width + 0.5) != screenw || (
int)(size.height + 0.5) != screenh) {
196 UIInterfaceOrientationMask orientmask = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
197 NSString *orientstring = dict[@"UILaunchImageOrientation"];
200 if ([orientstring isEqualToString:
@"PortraitUpsideDown"]) {
201 orientmask = UIInterfaceOrientationMaskPortraitUpsideDown;
202 }
else if ([orientstring isEqualToString:
@"Landscape"]) {
203 orientmask = UIInterfaceOrientationMaskLandscape;
204 }
else if ([orientstring isEqualToString:
@"LandscapeLeft"]) {
205 orientmask = UIInterfaceOrientationMaskLandscapeLeft;
206 }
else if ([orientstring isEqualToString:
@"LandscapeRight"]) {
207 orientmask = UIInterfaceOrientationMaskLandscapeRight;
212 if ((orientmask & (1 << curorient)) == 0) {
217 imagename = dict[@"UILaunchImageName"];
221 image = [UIImage imageNamed:imagename];
226 imagename = [bundle objectForInfoDictionaryKey:@"UILaunchImageFile"];
229 image = SDL_LoadLaunchImageNamed(imagename, screenh);
233 image = SDL_LoadLaunchImageNamed(
@"Default", screenh);
239 UIImageView *view = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
240 UIImageOrientation imageorient = UIImageOrientationUp;
244 if (UIInterfaceOrientationIsLandscape(curorient)) {
245 if (atleastiOS8 && image.size.width < image.size.height) {
250 if (curorient == UIInterfaceOrientationLandscapeLeft) {
251 imageorient = UIImageOrientationRight;
252 }
else if (curorient == UIInterfaceOrientationLandscapeRight) {
253 imageorient = UIImageOrientationLeft;
255 }
else if (!atleastiOS8 && image.size.width > image.size.height) {
259 if (curorient == UIInterfaceOrientationLandscapeLeft) {
260 imageorient = UIImageOrientationLeft;
261 }
else if (curorient == UIInterfaceOrientationLandscapeRight) {
262 imageorient = UIImageOrientationRight;
269 view.image = [[UIImage alloc] initWithCGImage:image.CGImage scale:image.scale orientation:imageorient];
284 - (BOOL)shouldAutorotate
290 - (NSUInteger)supportedInterfaceOrientations
295 return UIInterfaceOrientationMaskAll;
302 UIWindow *launchWindow;
310 return [UIApplication sharedApplication].delegate;
318 return @"SDLUIKitDelegate";
323 UIWindow *
window = launchWindow;
325 if (!window || window.hidden) {
332 [UIView animateWithDuration:0.2 animations:^{
334 } completion:^(BOOL finished) {
339 - (
void)postFinishLaunch
343 [
self performSelector:@selector(hideLaunchScreen) withObject:nil afterDelay:0.0];
347 exit_status =
SDL_main(forward_argc, forward_argv);
351 launchWindow.hidden = YES;
361 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
363 NSBundle *bundle = [NSBundle mainBundle];
365 #if SDL_IPHONE_LAUNCHSCREEN 372 UIViewController *vc = nil;
373 NSString *screenname = nil;
377 screenname = [bundle objectForInfoDictionaryKey:@"UILaunchStoryboardName"];
384 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:screenname bundle:bundle];
385 vc = [storyboard instantiateInitialViewController];
387 @catch (NSException *exception) {
398 launchWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
402 launchWindow.windowLevel = UIWindowLevelNormal + 1.0;
406 launchWindow.hidden = NO;
408 launchWindow.rootViewController = vc;
413 [[NSFileManager defaultManager] changeCurrentDirectoryPath:[bundle resourcePath]];
417 SDL_IdleTimerDisabledChanged,
NULL);
420 [
self performSelector:@selector(postFinishLaunch) withObject:nil afterDelay:0.0];
440 - (
void)setWindow:(UIWindow *)window
446 - (
void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation
448 BOOL isLandscape = UIInterfaceOrientationIsLandscape(application.statusBarOrientation);
459 if (isLandscape != (desktopmode->
w > desktopmode->
h)) {
461 desktopmode->
w = desktopmode->
h;
466 if (isLandscape != (currentmode->
w > currentmode->
h)) {
468 currentmode->
w = currentmode->
h;
475 - (
void)applicationWillTerminate:(UIApplication *)application
480 - (
void)applicationDidReceiveMemoryWarning:(UIApplication *)application
485 - (
void)applicationWillResignActive:(UIApplication*)application
490 - (
void)applicationDidEnterBackground:(UIApplication*)application
495 - (
void)applicationWillEnterForeground:(UIApplication*)application
500 - (
void)applicationDidBecomeActive:(UIApplication*)application
505 - (
void)sendDropFileForURL:(NSURL *)url
507 NSURL *fileURL = url.filePathURL;
508 if (fileURL != nil) {
516 #if TARGET_OS_TV || (defined(__IPHONE_9_0) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0) 518 - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,
id> *)options
521 [
self sendDropFileForURL:url];
527 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(
id)annotation
529 [
self sendDropFileForURL:url];
SDL_bool UIKit_IsSystemVersionAtLeast(double version)
void SDL_OnApplicationWillTerminate(void)
void SDL_OnApplicationDidEnterBackground(void)
int SDL_SendDropFile(SDL_Window *window, const char *file)
The structure that defines a display mode.
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
void SDL_OnApplicationDidBecomeActive(void)
int SDL_SendDropComplete(SDL_Window *window)
GLuint const GLchar * name
GLint GLint GLsizei width
static SDL_VideoDevice * _this
void SDL_OnApplicationDidReceiveMemoryWarning(void)
NSString * getAppDelegateClassName()
SDL_DisplayMode current_mode
SDL_VideoDisplay * displays
#define SDL_HINT_IDLE_TIMER_DISABLED
A variable controlling whether the idle timer is disabled on iOS.
void SDL_OnApplicationWillResignActive(void)
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)
SDL_DisplayMode desktop_mode
GLint GLint GLsizei GLsizei height
EGLSurface EGLNativeWindowType * window
C_LINKAGE SDLMAIN_DECLSPEC int SDL_main(int argc, char *argv[])
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
The type used to identify a window.
#define SDL_AddHintCallback
SDL_VideoDevice * SDL_GetVideoDevice(void)
#define SDL_iPhoneSetEventPump
void SDL_OnApplicationWillEnterForeground(void)