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;
81 SDL_LoadLaunchImageNamed(NSString *
name,
int screenh)
83 UIInterfaceOrientation curorient = [UIApplication sharedApplication].statusBarOrientation;
84 UIUserInterfaceIdiom idiom = [UIDevice currentDevice].userInterfaceIdiom;
87 if (idiom == UIUserInterfaceIdiomPhone && screenh == 568) {
89 image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-568h", name]];
90 }
else if (idiom == UIUserInterfaceIdiomPad) {
92 if (UIInterfaceOrientationIsLandscape(curorient)) {
93 if (curorient == UIInterfaceOrientationLandscapeLeft) {
94 image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-LandscapeLeft", name]];
96 image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-LandscapeRight", name]];
99 image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-Landscape", name]];
102 if (curorient == UIInterfaceOrientationPortraitUpsideDown) {
103 image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-PortraitUpsideDown", name]];
106 image = [UIImage imageNamed:[NSString stringWithFormat:@"%@-Portrait", name]];
112 image = [UIImage imageNamed:name];
122 if (!(
self = [super initWithNibName:nil bundle:nil])) {
126 NSBundle *bundle = [NSBundle mainBundle];
127 NSString *screenname = [bundle objectForInfoDictionaryKey:@"UILaunchStoryboardName"];
131 if (screenname && atleastiOS8) {
133 self.view = [bundle loadNibNamed:screenname owner:self options:nil][0];
135 @catch (NSException *exception) {
143 NSArray *launchimages = [bundle objectForInfoDictionaryKey:@"UILaunchImages"];
144 UIInterfaceOrientation curorient = [UIApplication sharedApplication].statusBarOrientation;
145 NSString *imagename = nil;
146 UIImage *image = nil;
148 int screenw = (int)([UIScreen mainScreen].bounds.size.width + 0.5);
149 int screenh = (int)([UIScreen mainScreen].bounds.size.height + 0.5);
152 if (screenw > screenh) {
160 for (NSDictionary *dict
in launchimages) {
161 UIInterfaceOrientationMask orientmask = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
162 NSString *minversion = dict[@"UILaunchImageMinimumOSVersion"];
163 NSString *sizestring = dict[@"UILaunchImageSize"];
164 NSString *orientstring = dict[@"UILaunchImageOrientation"];
173 CGSize
size = CGSizeFromString(sizestring);
174 if ((
int)(size.width + 0.5) != screenw || (
int)(size.height + 0.5) != screenh) {
180 if ([orientstring isEqualToString:
@"PortraitUpsideDown"]) {
181 orientmask = UIInterfaceOrientationMaskPortraitUpsideDown;
182 }
else if ([orientstring isEqualToString:
@"Landscape"]) {
183 orientmask = UIInterfaceOrientationMaskLandscape;
184 }
else if ([orientstring isEqualToString:
@"LandscapeLeft"]) {
185 orientmask = UIInterfaceOrientationMaskLandscapeLeft;
186 }
else if ([orientstring isEqualToString:
@"LandscapeRight"]) {
187 orientmask = UIInterfaceOrientationMaskLandscapeRight;
192 if ((orientmask & (1 << curorient)) == 0) {
196 imagename = dict[@"UILaunchImageName"];
200 image = [UIImage imageNamed:imagename];
203 imagename = [bundle objectForInfoDictionaryKey:@"UILaunchImageFile"];
206 image = SDL_LoadLaunchImageNamed(imagename, screenh);
210 image = SDL_LoadLaunchImageNamed(
@"Default", screenh);
215 UIImageView *view = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].bounds];
216 UIImageOrientation imageorient = UIImageOrientationUp;
219 if (UIInterfaceOrientationIsLandscape(curorient)) {
220 if (atleastiOS8 && image.size.width < image.size.height) {
225 if (curorient == UIInterfaceOrientationLandscapeLeft) {
226 imageorient = UIImageOrientationRight;
227 }
else if (curorient == UIInterfaceOrientationLandscapeRight) {
228 imageorient = UIImageOrientationLeft;
230 }
else if (!atleastiOS8 && image.size.width > image.size.height) {
234 if (curorient == UIInterfaceOrientationLandscapeLeft) {
235 imageorient = UIImageOrientationLeft;
236 }
else if (curorient == UIInterfaceOrientationLandscapeRight) {
237 imageorient = UIImageOrientationRight;
243 view.image = [[UIImage alloc] initWithCGImage:image.CGImage scale:image.scale orientation:imageorient];
257 - (BOOL)shouldAutorotate
268 return UIInterfaceOrientationMaskAll;
274 UIWindow *launchWindow;
282 return [UIApplication sharedApplication].delegate;
290 return @"SDLUIKitDelegate";
295 UIWindow *
window = launchWindow;
297 if (!window || window.hidden) {
304 [UIView animateWithDuration:0.2 animations:^{
306 } completion:^(BOOL finished) {
311 - (
void)postFinishLaunch
315 [
self performSelector:@selector(hideLaunchScreen) withObject:nil afterDelay:0.0];
319 exit_status =
SDL_main(forward_argc, forward_argv);
323 launchWindow.hidden = YES;
333 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
335 NSBundle *bundle = [NSBundle mainBundle];
336 NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
338 #if SDL_IPHONE_LAUNCHSCREEN 347 if (viewcontroller.view) {
348 launchWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
352 launchWindow.windowLevel = UIWindowLevelNormal + 1.0;
356 launchWindow.hidden = NO;
358 launchWindow.rootViewController = viewcontroller;
363 [[NSFileManager defaultManager] changeCurrentDirectoryPath:[bundle resourcePath]];
367 SDL_IdleTimerDisabledChanged,
NULL);
370 [
self performSelector:@selector(postFinishLaunch) withObject:nil afterDelay:0.0];
375 - (
void)applicationWillTerminate:(UIApplication *)application
380 - (
void)applicationDidReceiveMemoryWarning:(UIApplication *)application
385 - (
void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation
387 BOOL isLandscape = UIInterfaceOrientationIsLandscape(application.statusBarOrientation);
398 if (isLandscape != (desktopmode->
w > desktopmode->
h)) {
400 desktopmode->
w = desktopmode->
h;
405 if (isLandscape != (currentmode->
w > currentmode->
h)) {
407 currentmode->
w = currentmode->
h;
413 - (
void)applicationWillResignActive:(UIApplication*)application
418 for (window = _this->
windows; window != nil; window = window->
next) {
426 - (
void)applicationDidEnterBackground:(UIApplication*)application
431 - (
void)applicationWillEnterForeground:(UIApplication*)application
436 - (
void)applicationDidBecomeActive:(UIApplication*)application
443 for (window = _this->
windows; window != nil; window = window->
next) {
450 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(
id)annotation
452 NSURL *fileURL = url.filePathURL;
453 if (fileURL != nil) {
GLint GLint GLsizei width
BOOL UIKit_IsSystemVersionAtLeast(double version)
The structure that defines a display mode.
GLuint const GLchar * name
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
GLint GLint GLsizei GLsizei height
static SDL_VideoDevice * _this
NSUInteger supportedInterfaceOrientations()
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.
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
C_LINKAGE 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
int SDL_SendDropFile(const char *file)
The type used to identify a window.
#define SDL_AddHintCallback
SDL_VideoDevice * SDL_GetVideoDevice(void)
int SDL_SendAppEvent(SDL_EventType eventType)
#define SDL_iPhoneSetEventPump