21 #include "../../SDL_internal.h" 23 #if SDL_VIDEO_DRIVER_UIKIT 25 #include "../SDL_sysvideo.h" 35 #include "../../events/SDL_events_c.h" 42 static int forward_argc;
43 static char **forward_argv;
44 static int exit_status;
46 #if defined(SDL_MAIN_NEEDED) && !defined(IOS_DYLIB) 48 int main(
int argc,
char *argv[])
59 forward_main = mainFunction;
61 forward_argv = (
char **)
malloc((argc+1) *
sizeof(
char *));
62 for (i = 0; i < argc; i++) {
63 forward_argv[i] =
malloc( (strlen(argv[i])+1) *
sizeof(
char));
64 strcpy(forward_argv[i], argv[i]);
66 forward_argv[i] =
NULL;
74 for (i = 0; i < forward_argc; i++) {
75 free(forward_argv[i]);
83 SDL_IdleTimerDisabledChanged(
void *userdata,
const char *
name,
const char *oldValue,
const char *hint)
85 BOOL disable = (hint && *hint !=
'0');
86 [UIApplication sharedApplication].idleTimerDisabled = disable;
92 SDL_LoadLaunchImageNamed(NSString *
name,
int screenh)
94 UIInterfaceOrientation curorient = [UIApplication sharedApplication].statusBarOrientation;
95 UIUserInterfaceIdiom idiom = [UIDevice currentDevice].userInterfaceIdiom;
98 if (idiom == UIUserInterfaceIdiomPhone && screenh == 568) {
100 image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-568h", name]];
101 }
else if (idiom == UIUserInterfaceIdiomPad) {
103 if (UIInterfaceOrientationIsLandscape(curorient)) {
104 if (curorient == UIInterfaceOrientationLandscapeLeft) {
105 image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-LandscapeLeft", name]];
107 image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-LandscapeRight", name]];
110 image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-Landscape", name]];
113 if (curorient == UIInterfaceOrientationPortraitUpsideDown) {
114 image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-PortraitUpsideDown", name]];
117 image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-Portrait", name]];
123 image = [UIImage imageNamed:name];
133 - (NSUInteger)supportedInterfaceOrientations;
142 return [
self initWithNibName:nil bundle:[NSBundle mainBundle]];
145 - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
147 if (!(
self = [super initWithNibName:nil bundle:nil])) {
151 NSString *screenname = nibNameOrNil;
152 NSBundle *bundle = nibBundleOrNil;
156 if (screenname && atleastiOS8) {
158 self.view = [bundle loadNibNamed:screenname owner:self options:nil][0];
160 @catch (NSException *exception) {
168 NSArray *launchimages = [bundle objectForInfoDictionaryKey:@"UILaunchImages"];
169 NSString *imagename = nil;
170 UIImage *image = nil;
172 int screenw = (int)([UIScreen mainScreen].bounds.size.width + 0.5);
173 int screenh = (int)([UIScreen mainScreen].bounds.size.height + 0.5);
176 UIInterfaceOrientation curorient = [UIApplication sharedApplication].statusBarOrientation;
179 if (screenw > screenh) {
188 for (NSDictionary *dict
in launchimages) {
189 NSString *minversion = dict[@"UILaunchImageMinimumOSVersion"];
190 NSString *sizestring = dict[@"UILaunchImageSize"];
199 CGSize
size = CGSizeFromString(sizestring);
200 if ((
int)(size.width + 0.5) != screenw || (
int)(size.height + 0.5) != screenh) {
206 UIInterfaceOrientationMask orientmask = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
207 NSString *orientstring = dict[@"UILaunchImageOrientation"];
210 if ([orientstring isEqualToString:
@"PortraitUpsideDown"]) {
211 orientmask = UIInterfaceOrientationMaskPortraitUpsideDown;
212 }
else if ([orientstring isEqualToString:
@"Landscape"]) {
213 orientmask = UIInterfaceOrientationMaskLandscape;
214 }
else if ([orientstring isEqualToString:
@"LandscapeLeft"]) {
215 orientmask = UIInterfaceOrientationMaskLandscapeLeft;
216 }
else if ([orientstring isEqualToString:
@"LandscapeRight"]) {
217 orientmask = UIInterfaceOrientationMaskLandscapeRight;
222 if ((orientmask & (1 << curorient)) == 0) {
227 imagename = dict[@"UILaunchImageName"];
231 image = [UIImage imageNamed:imagename];
236 imagename = [bundle objectForInfoDictionaryKey:@"UILaunchImageFile"];
239 image = SDL_LoadLaunchImageNamed(imagename, screenh);
243 image = SDL_LoadLaunchImageNamed(
@"Default", screenh);
249 UIImageView *view = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
250 UIImageOrientation imageorient = UIImageOrientationUp;
254 if (UIInterfaceOrientationIsLandscape(curorient)) {
255 if (atleastiOS8 && image.size.width < image.size.height) {
260 if (curorient == UIInterfaceOrientationLandscapeLeft) {
261 imageorient = UIImageOrientationRight;
262 }
else if (curorient == UIInterfaceOrientationLandscapeRight) {
263 imageorient = UIImageOrientationLeft;
265 }
else if (!atleastiOS8 && image.size.width > image.size.height) {
269 if (curorient == UIInterfaceOrientationLandscapeLeft) {
270 imageorient = UIImageOrientationLeft;
271 }
else if (curorient == UIInterfaceOrientationLandscapeRight) {
272 imageorient = UIImageOrientationRight;
279 view.image = [[UIImage alloc] initWithCGImage:image.CGImage scale:image.scale orientation:imageorient];
294 - (BOOL)shouldAutorotate
300 - (NSUInteger)supportedInterfaceOrientations
305 return UIInterfaceOrientationMaskAll;
312 UIWindow *launchWindow;
320 return [UIApplication sharedApplication].delegate;
328 return @"SDLUIKitDelegate";
333 UIWindow *
window = launchWindow;
335 if (!window || window.hidden) {
342 [UIView animateWithDuration:0.2 animations:^{
344 } completion:^(BOOL finished) {
346 UIKit_ForceUpdateHomeIndicator();
350 - (
void)postFinishLaunch
354 [
self performSelector:@selector(hideLaunchScreen) withObject:nil afterDelay:0.0];
358 exit_status = forward_main(forward_argc, forward_argv);
362 launchWindow.hidden = YES;
372 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
374 NSBundle *bundle = [NSBundle mainBundle];
376 #if SDL_IPHONE_LAUNCHSCREEN 383 UIViewController *vc = nil;
384 NSString *screenname = nil;
388 screenname = [bundle objectForInfoDictionaryKey:@"UILaunchStoryboardName"];
395 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:screenname bundle:bundle];
396 vc = [storyboard instantiateInitialViewController];
398 @catch (NSException *exception) {
409 launchWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
413 launchWindow.windowLevel = UIWindowLevelNormal + 1.0;
417 launchWindow.hidden = NO;
419 launchWindow.rootViewController = vc;
424 [[NSFileManager defaultManager] changeCurrentDirectoryPath:[bundle resourcePath]];
428 SDL_IdleTimerDisabledChanged,
NULL);
431 [
self performSelector:@selector(postFinishLaunch) withObject:nil afterDelay:0.0];
451 - (
void)setWindow:(UIWindow *)window
457 - (
void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation
463 - (
void)applicationWillTerminate:(UIApplication *)application
468 - (
void)applicationDidReceiveMemoryWarning:(UIApplication *)application
473 - (
void)applicationWillResignActive:(UIApplication*)application
478 - (
void)applicationDidEnterBackground:(UIApplication*)application
483 - (
void)applicationWillEnterForeground:(UIApplication*)application
488 - (
void)applicationDidBecomeActive:(UIApplication*)application
493 - (
void)sendDropFileForURL:(NSURL *)url
495 NSURL *fileURL = url.filePathURL;
496 if (fileURL != nil) {
504 #if TARGET_OS_TV || (defined(__IPHONE_9_0) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0) 506 - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,
id> *)options
509 [
self sendDropFileForURL:url];
515 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(
id)annotation
517 [
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)
int(* SDL_main_func)(int argc, char *argv[])
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()
SDLMAIN_DECLSPEC int SDL_main(int argc, char *argv[])
#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)
EGLSurface EGLNativeWindowType * window
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_OnApplicationDidChangeStatusBarOrientation(void)
void SDL_OnApplicationWillEnterForeground(void)