From d338b5f2ea95e814d1cb6846f6c0d6f15a84877a Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 4 Oct 2012 02:13:12 -0700 Subject: [PATCH] Keep the launch image up until the application has created an OpenGL view --- src/video/uikit/SDL_uikitappdelegate.m | 114 ++++++++++++++++++++-- src/video/uikit/SDL_uikitvideo.h | 15 +++ src/video/uikit/SDL_uikitviewcontroller.m | 15 --- 3 files changed, 120 insertions(+), 24 deletions(-) diff --git a/src/video/uikit/SDL_uikitappdelegate.m b/src/video/uikit/SDL_uikitappdelegate.m index 338845274..ab7531749 100644 --- a/src/video/uikit/SDL_uikitappdelegate.m +++ b/src/video/uikit/SDL_uikitappdelegate.m @@ -22,16 +22,16 @@ #if SDL_VIDEO_DRIVER_UIKIT -#import "../SDL_sysvideo.h" -#import "SDL_assert.h" -#import "SDL_hints.h" -#import "../../SDL_hints_c.h" -#import "SDL_system.h" +#include "../SDL_sysvideo.h" +#include "SDL_assert.h" +#include "SDL_hints.h" +#include "../../SDL_hints_c.h" +#include "SDL_system.h" -#import "SDL_uikitappdelegate.h" -#import "SDL_uikitopenglview.h" -#import "../../events/SDL_events_c.h" -#import "jumphack.h" +#include "SDL_uikitappdelegate.h" +#include "SDL_uikitmodes.h" +#include "../../events/SDL_events_c.h" +#include "jumphack.h" #ifdef main #undef main @@ -41,6 +41,7 @@ static int forward_argc; static char **forward_argv; static int exit_status; +static UIWindow *launch_window; int main(int argc, char **argv) { @@ -77,6 +78,87 @@ static void SDL_IdleTimerDisabledChanged(const char *name, const char *oldValue, [UIApplication sharedApplication].idleTimerDisabled = disable; } +@interface SDL_splashviewcontroller : UIViewController { + UIImageView *splash; + UIImage *splashPortrait; + UIImage *splashLandscape; +} + +- (void)updateSplashImage:(UIInterfaceOrientation)interfaceOrientation; +@end + +@implementation SDL_splashviewcontroller + +- (id)init +{ + self = [super init]; + if (self == nil) { + return nil; + } + + self->splash = [[UIImageView alloc] init]; + [self setView:self->splash]; + + self->splashPortrait = [UIImage imageNamed:@"Default.png"]; + self->splashLandscape = [UIImage imageNamed:@"Default-Landscape.png"]; + if (!self->splashLandscape && self->splashPortrait) + { + self->splashLandscape = [[UIImage alloc] initWithCGImage: self->splashPortrait.CGImage + scale: 1.0 + orientation: UIImageOrientationRight]; + } + if (self->splashPortrait) { + [self->splashPortrait retain]; + } + if (self->splashLandscape) { + [self->splashLandscape retain]; + } + + [self updateSplashImage:[[UIApplication sharedApplication] statusBarOrientation]]; + + return self; +} + +- (NSUInteger)supportedInterfaceOrientations +{ + NSUInteger orientationMask = UIInterfaceOrientationMaskAll; + + // Don't allow upside-down orientation on the phone, so answering calls is in the natural orientation + if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { + orientationMask &= ~UIInterfaceOrientationMaskPortraitUpsideDown; + } + return orientationMask; +} + +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient +{ + NSUInteger orientationMask = [self supportedInterfaceOrientations]; + return (orientationMask & (1 << orient)); +} + +- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration +{ + [self updateSplashImage:interfaceOrientation]; +} + +- (void)updateSplashImage:(UIInterfaceOrientation)interfaceOrientation +{ + UIImage *image; + + if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) { + image = self->splashLandscape; + } else { + image = self->splashPortrait; + } + if (image) + { + splash.image = image; + } +} + +@end + + @implementation SDLUIKitDelegate /* convenience method */ @@ -106,6 +188,12 @@ - (void)postFinishLaunch exit_status = SDL_main(forward_argc, forward_argv); SDL_iPhoneSetEventPump(SDL_FALSE); + /* If we showed a splash image, clean it up */ + if (launch_window) { + [launch_window release]; + launch_window = NULL; + } + /* exit, passing the return status from the user's application */ // We don't actually exit to support applications that do setup in // their main function and then allow the Cocoa event loop to run. @@ -114,6 +202,14 @@ - (void)postFinishLaunch - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + /* Keep the launch image up until we set a video mode */ + launch_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + + UIViewController *splashViewController = [[SDL_splashviewcontroller alloc] init]; + launch_window.rootViewController = splashViewController; + [launch_window addSubview:splashViewController.view]; + [launch_window makeKeyAndVisible]; + /* Set working directory to resource path */ [[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]]; diff --git a/src/video/uikit/SDL_uikitvideo.h b/src/video/uikit/SDL_uikitvideo.h index 8218af1cf..1cf608b4e 100644 --- a/src/video/uikit/SDL_uikitvideo.h +++ b/src/video/uikit/SDL_uikitvideo.h @@ -25,6 +25,21 @@ #include "../SDL_sysvideo.h" +#ifndef __IPHONE_6_0 +// This enum isn't available in older SDKs, but we use it for our own purposes on iOS 5.1 and for the system on iOS 6.0 +enum UIInterfaceOrientationMask +{ + UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait), + UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft), + UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight), + UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown), + UIInterfaceOrientationMaskLandscape = (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight), + UIInterfaceOrientationMaskAll = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown), + UIInterfaceOrientationMaskAllButUpsideDown = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight), +}; +#endif // !__IPHONE_6_0 + + #endif /* _SDL_uikitvideo_h */ /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/uikit/SDL_uikitviewcontroller.m b/src/video/uikit/SDL_uikitviewcontroller.m index 7f49563eb..3b8cb6565 100644 --- a/src/video/uikit/SDL_uikitviewcontroller.m +++ b/src/video/uikit/SDL_uikitviewcontroller.m @@ -34,21 +34,6 @@ #include "SDL_uikitwindow.h" -#ifndef __IPHONE_6_0 -// This enum isn't available in older SDKs, but we use it for our own purposes on iOS 5.1 and for the system on iOS 6.0 -enum UIInterfaceOrientationMask -{ - UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait), - UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft), - UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight), - UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown), - UIInterfaceOrientationMaskLandscape = (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight), - UIInterfaceOrientationMaskAll = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown), - UIInterfaceOrientationMaskAllButUpsideDown = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight), -}; -#endif // !__IPHONE_6_0 - - @implementation SDL_uikitviewcontroller @synthesize window;