diff --git a/Classes/Retronator/Xni/Framework/FrameworkEnums.h b/Classes/Retronator/Xni/Framework/FrameworkEnums.h index 00c5b40..76590b9 100644 --- a/Classes/Retronator/Xni/Framework/FrameworkEnums.h +++ b/Classes/Retronator/Xni/Framework/FrameworkEnums.h @@ -1,6 +1,9 @@ +#import + typedef enum { - DisplayOrientationDefault = 2, - DisplayOrientationLandscapeLeft = 1, - DisplayOrientationLandscapeRight = 2, - DisplayOrientationPortrait = 4 + DisplayOrientationDefault = UIInterfaceOrientationMaskAll, + DisplayOrientationLandscapeLeft = UIInterfaceOrientationMaskLandscapeLeft, + DisplayOrientationLandscapeRight = UIInterfaceOrientationMaskLandscapeRight, + DisplayOrientationPortrait = UIInterfaceOrientationMaskPortrait, + DisplayOrientationPortraitUpsideDown = UIInterfaceOrientationMaskPortraitUpsideDown } DisplayOrientation; \ No newline at end of file diff --git a/Classes/Retronator/Xni/Framework/GameViewController.m b/Classes/Retronator/Xni/Framework/GameViewController.m index 338cb30..2dbbf5f 100644 --- a/Classes/Retronator/Xni/Framework/GameViewController.m +++ b/Classes/Retronator/Xni/Framework/GameViewController.m @@ -31,17 +31,17 @@ } + (DisplayOrientation) getDisplayOrientationForInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { - if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) { - return DisplayOrientationPortrait; - } else { - if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) { - return DisplayOrientationLandscapeLeft; - } else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) { - return DisplayOrientationLandscapeRight; - } else { - return DisplayOrientationDefault; - } - } + if (interfaceOrientation == UIInterfaceOrientationPortrait) { + return DisplayOrientationPortrait; + } else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { + return DisplayOrientationPortraitUpsideDown; + } else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) { + return DisplayOrientationLandscapeLeft; + } else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) { + return DisplayOrientationLandscapeRight; + } else{ + return DisplayOrientationDefault; + } } + (UIInterfaceOrientation) getUIInterfaceOrientationFromString:(NSString*)interfaceOrientation { @@ -98,6 +98,14 @@ return supported; } +- (BOOL)shouldAutorotate { + return YES; +} + +- (NSUInteger)supportedInterfaceOrientations { + return supportedOrientations; +} + - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. diff --git a/Classes/Retronator/Xni/Framework/GameWindow.m b/Classes/Retronator/Xni/Framework/GameWindow.m index 35bd681..df8c7f7 100644 --- a/Classes/Retronator/Xni/Framework/GameWindow.m +++ b/Classes/Retronator/Xni/Framework/GameWindow.m @@ -14,7 +14,9 @@ #import "GameView.h" #import "TouchPanel+Internal.h" -@interface GameWindow() +@interface GameWindow() { + BOOL fakeLandscapeBounds; +} - (Rectangle*) calculateClientBounds; @@ -66,9 +68,28 @@ } - (void) endScreenDeviceChangeWithClientWidth:(int)clientWidth clientHeight:(int)clientHeight { - CGRect realFrame = [UIScreen mainScreen].applicationFrame; - float realScale = [UIScreen mainScreen].scale; + // Before iOS 6.0 the orientation is handled with a different set of functions. Get version so we can act acordingly. + float version = [[[UIDevice currentDevice] systemVersion] floatValue]; + + CGRect realFrame = [UIScreen mainScreen].applicationFrame; + float realScale = [UIScreen mainScreen].scale; + + // Set target view frame to full screen frame to determine orientation. + gameViewController.view.frame = realFrame; + + CGRect orientedFrame = gameViewController.view.bounds; + NSLog(@"%f, %f", orientedFrame.size.width, orientedFrame.size.height); + BOOL deviceIsLandscape = orientedFrame.size.width > orientedFrame.size.height; + + BOOL clientWantsOnlyLandscape = !(gameViewController.supportedOrientations & DisplayOrientationPortrait); + + if (deviceIsLandscape || clientWantsOnlyLandscape) { + int height = clientHeight; + clientHeight = clientWidth; + clientWidth = height; + } + float realAspectRatio = realFrame.size.width / realFrame.size.height; if (clientWidth == 0) { @@ -77,7 +98,7 @@ if (clientHeight == 0) { clientHeight = realFrame.size.height * realScale; - } + } float targetAspectRatio = (float)clientWidth/(float)clientHeight; CGRect targetFrame; @@ -108,7 +129,19 @@ // Recalculate client bounds. [clientBounds release]; - clientBounds = [[self calculateClientBounds] retain]; + clientBounds = [[self calculateClientBounds] retain]; + + if (version < 6) { + // If the user requested a landscape backbuffer and our view is still reporting a portrait orientation, + // this will change with a later call, so we should manually adjust the (incorrect) bounds for now. + // Also, don't switch the orientation if it is already correctly in landscape. + if (clientWantsOnlyLandscape && clientBounds.width < clientBounds.height) { + int height = clientBounds.height; + clientBounds.height = clientBounds.width; + clientBounds.width = height; + fakeLandscapeBounds = YES; + } + } } - (void) initialize { @@ -142,6 +175,10 @@ [clientBounds release]; clientBounds = [newClientBounds retain]; [clientSizeChanged raiseWithSender:self]; + } else if (fakeLandscapeBounds) { + // Still call client size changed, since the actual screen was in portrait mode before. + fakeLandscapeBounds = NO; + [clientSizeChanged raiseWithSender:self]; } } diff --git a/XNI.xcodeproj/project.xcworkspace/xcuserdata/Retro.xcuserdatad/UserInterfaceState.xcuserstate b/XNI.xcodeproj/project.xcworkspace/xcuserdata/Retro.xcuserdatad/UserInterfaceState.xcuserstate index cb3069a..c0853e9 100644 Binary files a/XNI.xcodeproj/project.xcworkspace/xcuserdata/Retro.xcuserdatad/UserInterfaceState.xcuserstate and b/XNI.xcodeproj/project.xcworkspace/xcuserdata/Retro.xcuserdatad/UserInterfaceState.xcuserstate differ