Keep the launch image up until the application has created an OpenGL view
authorSam Lantinga <slouken@libsdl.org>
Thu, 04 Oct 2012 02:13:12 -0700
changeset 6556d5e854f0d9a9
parent 6555 f2c03c06d987
child 6557 87ba88e3f2a9
Keep the launch image up until the application has created an OpenGL view
src/video/uikit/SDL_uikitappdelegate.m
src/video/uikit/SDL_uikitvideo.h
src/video/uikit/SDL_uikitviewcontroller.m
     1.1 --- a/src/video/uikit/SDL_uikitappdelegate.m	Wed Oct 03 20:49:16 2012 -0700
     1.2 +++ b/src/video/uikit/SDL_uikitappdelegate.m	Thu Oct 04 02:13:12 2012 -0700
     1.3 @@ -22,16 +22,16 @@
     1.4  
     1.5  #if SDL_VIDEO_DRIVER_UIKIT
     1.6  
     1.7 -#import "../SDL_sysvideo.h"
     1.8 -#import "SDL_assert.h"
     1.9 -#import "SDL_hints.h"
    1.10 -#import "../../SDL_hints_c.h"
    1.11 -#import "SDL_system.h"
    1.12 +#include "../SDL_sysvideo.h"
    1.13 +#include "SDL_assert.h"
    1.14 +#include "SDL_hints.h"
    1.15 +#include "../../SDL_hints_c.h"
    1.16 +#include "SDL_system.h"
    1.17  
    1.18 -#import "SDL_uikitappdelegate.h"
    1.19 -#import "SDL_uikitopenglview.h"
    1.20 -#import "../../events/SDL_events_c.h"
    1.21 -#import "jumphack.h"
    1.22 +#include "SDL_uikitappdelegate.h"
    1.23 +#include "SDL_uikitmodes.h"
    1.24 +#include "../../events/SDL_events_c.h"
    1.25 +#include "jumphack.h"
    1.26  
    1.27  #ifdef main
    1.28  #undef main
    1.29 @@ -41,6 +41,7 @@
    1.30  static int forward_argc;
    1.31  static char **forward_argv;
    1.32  static int exit_status;
    1.33 +static UIWindow *launch_window;
    1.34  
    1.35  int main(int argc, char **argv)
    1.36  {
    1.37 @@ -77,6 +78,87 @@
    1.38      [UIApplication sharedApplication].idleTimerDisabled = disable;
    1.39  }
    1.40  
    1.41 +@interface SDL_splashviewcontroller : UIViewController {
    1.42 +    UIImageView *splash;
    1.43 +    UIImage *splashPortrait;
    1.44 +    UIImage *splashLandscape;
    1.45 +}
    1.46 +
    1.47 +- (void)updateSplashImage:(UIInterfaceOrientation)interfaceOrientation;
    1.48 +@end
    1.49 +
    1.50 +@implementation SDL_splashviewcontroller
    1.51 +
    1.52 +- (id)init
    1.53 +{
    1.54 +    self = [super init];
    1.55 +    if (self == nil) {
    1.56 +        return nil;
    1.57 +    }
    1.58 +
    1.59 +    self->splash = [[UIImageView alloc] init];
    1.60 +    [self setView:self->splash];
    1.61 +
    1.62 +    self->splashPortrait = [UIImage imageNamed:@"Default.png"];
    1.63 +    self->splashLandscape = [UIImage imageNamed:@"Default-Landscape.png"];
    1.64 +    if (!self->splashLandscape && self->splashPortrait)
    1.65 +    {
    1.66 +        self->splashLandscape = [[UIImage alloc] initWithCGImage: self->splashPortrait.CGImage
    1.67 +                                                           scale: 1.0
    1.68 +                                                     orientation: UIImageOrientationRight];
    1.69 +    }
    1.70 +    if (self->splashPortrait) {
    1.71 +        [self->splashPortrait retain];
    1.72 +    }
    1.73 +    if (self->splashLandscape) {
    1.74 +        [self->splashLandscape retain];
    1.75 +    }
    1.76 + 
    1.77 +    [self updateSplashImage:[[UIApplication sharedApplication] statusBarOrientation]];
    1.78 +
    1.79 +    return self;
    1.80 +}
    1.81 +
    1.82 +- (NSUInteger)supportedInterfaceOrientations
    1.83 +{
    1.84 +    NSUInteger orientationMask = UIInterfaceOrientationMaskAll;
    1.85 +    
    1.86 +    // Don't allow upside-down orientation on the phone, so answering calls is in the natural orientation
    1.87 +    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    1.88 +        orientationMask &= ~UIInterfaceOrientationMaskPortraitUpsideDown;
    1.89 +    }
    1.90 +    return orientationMask;
    1.91 +}
    1.92 +
    1.93 +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient
    1.94 +{
    1.95 +    NSUInteger orientationMask = [self supportedInterfaceOrientations];
    1.96 +    return (orientationMask & (1 << orient));
    1.97 +}
    1.98 +
    1.99 +- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
   1.100 +{
   1.101 +    [self updateSplashImage:interfaceOrientation];
   1.102 +}
   1.103 +
   1.104 +- (void)updateSplashImage:(UIInterfaceOrientation)interfaceOrientation
   1.105 +{
   1.106 +    UIImage *image;
   1.107 +    
   1.108 +    if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
   1.109 +        image = self->splashLandscape;
   1.110 +    } else {
   1.111 +        image = self->splashPortrait;
   1.112 +    }
   1.113 +    if (image)
   1.114 +    {
   1.115 +        splash.image = image;
   1.116 +    }
   1.117 +}
   1.118 +
   1.119 +@end
   1.120 +
   1.121 +
   1.122  @implementation SDLUIKitDelegate
   1.123  
   1.124  /* convenience method */
   1.125 @@ -106,6 +188,12 @@
   1.126      exit_status = SDL_main(forward_argc, forward_argv);
   1.127      SDL_iPhoneSetEventPump(SDL_FALSE);
   1.128  
   1.129 +    /* If we showed a splash image, clean it up */
   1.130 +    if (launch_window) {
   1.131 +        [launch_window release];
   1.132 +        launch_window = NULL;
   1.133 +    }
   1.134 +
   1.135      /* exit, passing the return status from the user's application */
   1.136      // We don't actually exit to support applications that do setup in
   1.137      // their main function and then allow the Cocoa event loop to run.
   1.138 @@ -114,6 +202,14 @@
   1.139  
   1.140  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
   1.141  {
   1.142 +    /* Keep the launch image up until we set a video mode */
   1.143 +    launch_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
   1.144 +
   1.145 +    UIViewController *splashViewController = [[SDL_splashviewcontroller alloc] init];
   1.146 +    launch_window.rootViewController = splashViewController;
   1.147 +    [launch_window addSubview:splashViewController.view];
   1.148 +    [launch_window makeKeyAndVisible];
   1.149 +
   1.150      /* Set working directory to resource path */
   1.151      [[NSFileManager defaultManager] changeCurrentDirectoryPath: [[NSBundle mainBundle] resourcePath]];
   1.152  
     2.1 --- a/src/video/uikit/SDL_uikitvideo.h	Wed Oct 03 20:49:16 2012 -0700
     2.2 +++ b/src/video/uikit/SDL_uikitvideo.h	Thu Oct 04 02:13:12 2012 -0700
     2.3 @@ -25,6 +25,21 @@
     2.4  
     2.5  #include "../SDL_sysvideo.h"
     2.6  
     2.7 +#ifndef __IPHONE_6_0
     2.8 +// 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
     2.9 +enum UIInterfaceOrientationMask
    2.10 +{
    2.11 +    UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait),
    2.12 +    UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft),
    2.13 +    UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight),
    2.14 +    UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown),
    2.15 +    UIInterfaceOrientationMaskLandscape = (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),
    2.16 +    UIInterfaceOrientationMaskAll = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown),
    2.17 +    UIInterfaceOrientationMaskAllButUpsideDown = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),
    2.18 +};
    2.19 +#endif // !__IPHONE_6_0
    2.20 +
    2.21 +
    2.22  #endif /* _SDL_uikitvideo_h */
    2.23  
    2.24  /* vi: set ts=4 sw=4 expandtab: */
     3.1 --- a/src/video/uikit/SDL_uikitviewcontroller.m	Wed Oct 03 20:49:16 2012 -0700
     3.2 +++ b/src/video/uikit/SDL_uikitviewcontroller.m	Thu Oct 04 02:13:12 2012 -0700
     3.3 @@ -34,21 +34,6 @@
     3.4  #include "SDL_uikitwindow.h"
     3.5  
     3.6  
     3.7 -#ifndef __IPHONE_6_0
     3.8 -// 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
     3.9 -enum UIInterfaceOrientationMask
    3.10 -{
    3.11 -    UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait),
    3.12 -    UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft),
    3.13 -    UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight),
    3.14 -    UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown),
    3.15 -    UIInterfaceOrientationMaskLandscape = (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),
    3.16 -    UIInterfaceOrientationMaskAll = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown),
    3.17 -    UIInterfaceOrientationMaskAllButUpsideDown = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),
    3.18 -};
    3.19 -#endif // !__IPHONE_6_0
    3.20 -
    3.21 -    
    3.22  @implementation SDL_uikitviewcontroller
    3.23  
    3.24  @synthesize window;