Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Keep the launch image up until the application has created an OpenGL …
Browse files Browse the repository at this point in the history
…view
  • Loading branch information
slouken committed Oct 4, 2012
1 parent a10ad9e commit d338b5f
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 24 deletions.
114 changes: 105 additions & 9 deletions src/video/uikit/SDL_uikitappdelegate.m
Expand Up @@ -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
Expand All @@ -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)
{
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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.
Expand All @@ -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]];

Expand Down
15 changes: 15 additions & 0 deletions src/video/uikit/SDL_uikitvideo.h
Expand Up @@ -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: */
15 changes: 0 additions & 15 deletions src/video/uikit/SDL_uikitviewcontroller.m
Expand Up @@ -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;
Expand Down

0 comments on commit d338b5f

Please sign in to comment.