Permalink
Browse files

Fix to support PortraitUpsideDown for iPad; moved class methods for E…

…JApp to instance methods
  • Loading branch information...
phoboslab committed Sep 27, 2012
1 parent a79a2f4 commit 58a1f215f9f53874fc42e57e1b5435fb9a96530d
View
@@ -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> * touchDelegate;
View
@@ -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
@@ -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];
@@ -75,15 +75,15 @@ - (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 ) {
// FIXME?! iPhone3/4/5 and iPod all have the same user agent string ('iPhone')
// Only iPad is different
return NSStringToJSValue(ctx,
- [[[UIDevice currentDevice] model] hasPrefix:@"iPad"]
+ (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
? @"iPad"
: @"iPhone"
);
@@ -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];
@@ -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];
View
@@ -48,5 +48,7 @@
<true/>
<key>UISupportedInterfaceOrientations</key>
<array/>
+ <key>UISupportedInterfaceOrientations~ipad</key>
+ <array/>
</dict>
</plist>

0 comments on commit 58a1f21

Please sign in to comment.