Skip to content

Commit

Permalink
Fix to support PortraitUpsideDown for iPad; moved class methods for E…
Browse files Browse the repository at this point in the history
…JApp to instance methods
  • Loading branch information
phoboslab committed Sep 27, 2012
1 parent a79a2f4 commit 58a1f21
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 32 deletions.
7 changes: 4 additions & 3 deletions Classes/Ejecta/EJApp.h
Expand Up @@ -21,6 +21,7 @@

@interface EJApp : UIViewController {
BOOL paused;
BOOL landscapeMode;
JSGlobalContextRef jsGlobalContext;
UIWindow * window;
NSMutableDictionary * jsClasses;
Expand All @@ -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;

Expand All @@ -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;
Expand Down
50 changes: 26 additions & 24 deletions Classes/Ejecta/EJApp.m
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}


Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion Classes/Ejecta/EJAudio/EJBindingAudio.m
Expand Up @@ -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];

Expand Down
4 changes: 2 additions & 2 deletions Classes/Ejecta/EJBindingEjectaCore.m
Expand Up @@ -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"
);
Expand Down
2 changes: 1 addition & 1 deletion Classes/Ejecta/EJCanvas/EJBindingImage.m
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion Classes/Ejecta/EJUtils/EJBindingAdBanner.m
Expand Up @@ -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];
Expand Down
2 changes: 2 additions & 0 deletions Ejecta-Info.plist
Expand Up @@ -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.