diff --git a/Classes/Ejecta/EJApp.h b/Classes/Ejecta/EJApp.h index a701640d..ea362330 100644 --- a/Classes/Ejecta/EJApp.h +++ b/Classes/Ejecta/EJApp.h @@ -21,6 +21,7 @@ @interface EJApp : UIViewController { BOOL paused; + BOOL landscapeMode; JSGlobalContextRef jsGlobalContext; UIWindow * window; NSMutableDictionary * jsClasses; @@ -45,6 +46,7 @@ - (void)run:(CADisplayLink *)sender; - (void)pause; - (void)resume; +- (NSString *)pathForResource:(NSString *)resourcePath; - (JSValueRef)createTimer:(JSContextRef)ctx argc:(size_t)argc argv:(const JSValueRef [])argv repeat:(BOOL)repeat; - (JSValueRef)deleteTimer:(JSContextRef)ctx argc:(size_t)argc argv:(const JSValueRef [])argv; @@ -56,10 +58,9 @@ + (EJApp *)instance; -+ (NSString *)pathForResource:(NSString *)resourcePath; -+ (BOOL)landscapeMode; -+ (BOOL)statusBarHidden; + +@property (nonatomic, readonly) BOOL landscapeMode; @property (nonatomic, readonly) JSGlobalContextRef jsGlobalContext; @property (nonatomic, readonly) UIWindow * window; @property (nonatomic, retain) NSObject * touchDelegate; diff --git a/Classes/Ejecta/EJApp.m b/Classes/Ejecta/EJApp.m index 52092786..42966d8b 100644 --- a/Classes/Ejecta/EJApp.m +++ b/Classes/Ejecta/EJApp.m @@ -46,6 +46,7 @@ JSObjectRef ej_callAsConstructor(JSContextRef ctx, JSObjectRef constructor, size // the initial JavaScript source files @implementation EJApp +@synthesize landscapeMode; @synthesize jsGlobalContext; @synthesize window; @synthesize touchDelegate; @@ -63,6 +64,10 @@ + (EJApp *)instance { - (id)initWithWindow:(UIWindow *)windowp { if( self = [super init] ) { + + landscapeMode = [[[[NSBundle mainBundle] infoDictionary] + objectForKey:@"UIInterfaceOrientation"] hasPrefix:@"UIInterfaceOrientationLandscape"]; + ejectaInstance = self; window = windowp; @@ -135,17 +140,28 @@ - (void)dealloc { -(NSUInteger)supportedInterfaceOrientations { - return [EJApp landscapeMode] ? UIInterfaceOrientationMaskLandscape : UIInterfaceOrientationMaskPortrait; + if( landscapeMode ) { + // Allow Landscape Left and Right + return UIInterfaceOrientationMaskLandscape; + } + else { + if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) { + // Allow Portrait UpsideDown on iPad + return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown; + } + else { + // Only Allow Portrait + return UIInterfaceOrientationMaskPortrait; + } + } } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation { // Deprecated in iOS6 - supportedInterfaceOrientations is the new way to do this - BOOL landscape = [EJApp landscapeMode]; - return ( - (landscape && UIInterfaceOrientationIsLandscape(orientation)) || - (!landscape && UIInterfaceOrientationIsPortrait(orientation)) - ); + // We just use the mask returned by supportedInterfaceOrientations here to check if + // this particular orientation is allowed. + return (self.supportedInterfaceOrientations & orientation); } @@ -191,12 +207,15 @@ - (void)hideLoadingScreen { //loadingScreen = nil; } +- (NSString *)pathForResource:(NSString *)path { + return [NSString stringWithFormat:@"%@/" EJECTA_APP_FOLDER "%@", [[NSBundle mainBundle] resourcePath], path]; +} // --------------------------------------------------------------------------------- // Script loading and execution - (void)loadScriptAtPath:(NSString *)path { - NSString * script = [NSString stringWithContentsOfFile:[EJApp pathForResource:path] encoding:NSUTF8StringEncoding error:NULL]; + NSString * script = [NSString stringWithContentsOfFile:[self pathForResource:path] encoding:NSUTF8StringEncoding error:NULL]; if( !script ) { NSLog(@"Error: Can't Find Script %@", path ); @@ -313,21 +332,4 @@ - (void)setCurrentRenderingContext:(EJCanvasContext *)renderingContext { } } - -// --------------------------------------------------------------------------------- -// Utilities - -+ (NSString *)pathForResource:(NSString *)path { - return [NSString stringWithFormat:@"%@/" EJECTA_APP_FOLDER "%@", [[NSBundle mainBundle] resourcePath], path]; -} - -+ (BOOL)landscapeMode { - return [[[[NSBundle mainBundle] infoDictionary] - objectForKey:@"UIInterfaceOrientation"] hasPrefix:@"UIInterfaceOrientationLandscape"]; -} - -+ (BOOL)statusBarHidden { - return [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"UIStatusBarHidden"] boolValue]; -} - @end diff --git a/Classes/Ejecta/EJAudio/EJBindingAudio.m b/Classes/Ejecta/EJAudio/EJBindingAudio.m index ba164a95..cff866ca 100644 --- a/Classes/Ejecta/EJAudio/EJBindingAudio.m +++ b/Classes/Ejecta/EJAudio/EJBindingAudio.m @@ -52,7 +52,7 @@ - (void)load { if( source || !path ) { return; } // Decide whether to load the sound as OpenAL or AVAudioPlayer source - NSString * fullPath = [EJApp pathForResource:path]; + NSString * fullPath = [[EJApp instance] pathForResource:path]; unsigned long long size = [[[NSFileManager defaultManager] attributesOfItemAtPath:fullPath error:nil] fileSize]; diff --git a/Classes/Ejecta/EJBindingEjectaCore.m b/Classes/Ejecta/EJBindingEjectaCore.m index b221d1a1..045cceee 100644 --- a/Classes/Ejecta/EJBindingEjectaCore.m +++ b/Classes/Ejecta/EJBindingEjectaCore.m @@ -75,7 +75,7 @@ - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)index } EJ_BIND_GET(landscapeMode, ctx ) { - return JSValueMakeBoolean( ctx, [EJApp landscapeMode] ); + return JSValueMakeBoolean( ctx, [EJApp instance].landscapeMode ); } EJ_BIND_GET(userAgent, ctx ) { @@ -83,7 +83,7 @@ - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)index // Only iPad is different return NSStringToJSValue(ctx, - [[[UIDevice currentDevice] model] hasPrefix:@"iPad"] + (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) ? @"iPad" : @"iPhone" ); diff --git a/Classes/Ejecta/EJCanvas/EJBindingImage.m b/Classes/Ejecta/EJCanvas/EJBindingImage.m index 693dccfe..c6360933 100644 --- a/Classes/Ejecta/EJCanvas/EJBindingImage.m +++ b/Classes/Ejecta/EJCanvas/EJBindingImage.m @@ -21,7 +21,7 @@ - (void)load:(EAGLContext *)context { NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; NSLog(@"Loading Image: %@", path ); - EJTexture * tempTex = [[[EJTexture alloc] initWithPath:[EJApp pathForResource:path] context:context] autorelease]; + EJTexture * tempTex = [[[EJTexture alloc] initWithPath:[[EJApp instance] pathForResource:path] context:context] autorelease]; [self performSelectorOnMainThread:@selector(endLoad:) withObject:tempTex waitUntilDone:NO]; [autoreleasepool release]; diff --git a/Classes/Ejecta/EJUtils/EJBindingAdBanner.m b/Classes/Ejecta/EJUtils/EJBindingAdBanner.m index e3c5ae40..5988f50b 100644 --- a/Classes/Ejecta/EJUtils/EJBindingAdBanner.m +++ b/Classes/Ejecta/EJUtils/EJBindingAdBanner.m @@ -14,7 +14,7 @@ - (id)initWithContext:(JSContextRef)ctx object:(JSObjectRef)obj argc:(size_t)arg banner.hidden = YES; banner.requiredContentSizeIdentifiers = [NSSet setWithObjects: - ([EJApp landscapeMode] + ([[EJApp instance] landscapeMode] ? ADBannerContentSizeIdentifierLandscape : ADBannerContentSizeIdentifierPortrait), nil]; diff --git a/Ejecta-Info.plist b/Ejecta-Info.plist index a07ecd12..3fbd5d65 100644 --- a/Ejecta-Info.plist +++ b/Ejecta-Info.plist @@ -48,5 +48,7 @@ UISupportedInterfaceOrientations + UISupportedInterfaceOrientations~ipad +