diff --git a/cocos2dx/include/CCDirector.h b/cocos2dx/include/CCDirector.h index 3f07dcc74d..2b478fe525 100644 --- a/cocos2dx/include/CCDirector.h +++ b/cocos2dx/include/CCDirector.h @@ -405,6 +405,11 @@ public: @since v0.8.2 */ static bool setDirectorType(ccDirectorType obDirectorType); + + /** recalculate the projection view and projection size based on the EAGLVIEW + @since v0.99.4 + */ + void recalculateProjectionAndEAGLViewSize(); protected: bool isOpenGLAttached(void); @@ -426,14 +431,9 @@ protected: void showProfilers(void); #endif // CC_ENABLE_PROFILERS - /** recalculate the projection view and projection size based on the EAGLVIEW - @since v0.99.4 - */ - void recalculateProjectionAndEAGLViewSize(); - protected: // compute frame rate - void computeFrameRate(void); + void computeFrameRate(void); // compute delta time between computing frame rate void calculateFramerateDeltaTime(void); diff --git a/cocos2dx/platform/iphone/CCXApplication_iphone.mm b/cocos2dx/platform/iphone/CCXApplication_iphone.mm index ac4f689114..1084d27895 100644 --- a/cocos2dx/platform/iphone/CCXApplication_iphone.mm +++ b/cocos2dx/platform/iphone/CCXApplication_iphone.mm @@ -23,6 +23,7 @@ ****************************************************************************/ #import "CCDirectorCaller.h" +#import #include "CCXApplication_iphone.h" #include "CCXUIImage_iphone.h" @@ -46,6 +47,28 @@ namespace cocos2d { ccDeviceOrientation CCXApplication::setDeviceOrientation(ccDeviceOrientation eOritation) { + ccDeviceOrientation oldOrientation = CCDirector::sharedDirector()->getDeviceOrientation(); + + if (eOritation != oldOrientation) + { + switch (eOritation) { + case CCDeviceOrientationPortrait: + [[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortrait animated: NO]; + break; + case CCDeviceOrientationPortraitUpsideDown: + [[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortraitUpsideDown animated: NO]; + break; + case CCDeviceOrientationLandscapeLeft: + [[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated: NO]; + break; + case CCDeviceOrientationLandscapeRight: + [[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeLeft animated: NO]; + break; + default: + break; + } + } + return eOritation; } diff --git a/cocos2dx/platform/iphone/CCXEGLView_iphone.mm b/cocos2dx/platform/iphone/CCXEGLView_iphone.mm index 67ff1ae768..4b0a1d0629 100644 --- a/cocos2dx/platform/iphone/CCXEGLView_iphone.mm +++ b/cocos2dx/platform/iphone/CCXEGLView_iphone.mm @@ -42,13 +42,13 @@ CCXEGLView::~CCXEGLView() cocos2d::CGSize CCXEGLView::getSize() { - cocos2d::CGSize size([[EAGLView getGlobalView] getWidth], [[EAGLView getGlobalView] getHeight]); + cocos2d::CGSize size([[EAGLView sharedEGLView] getWidth], [[EAGLView sharedEGLView] getHeight]); return size; } bool CCXEGLView::isOpenGLReady() { - return [EAGLView getGlobalView] != NULL; + return [EAGLView sharedEGLView] != NULL; } void CCXEGLView::release() @@ -56,7 +56,7 @@ void CCXEGLView::release() [CCDirectorCaller destroy]; // destroy EAGLView - [[EAGLView getGlobalView] removeFromSuperview]; + [[EAGLView sharedEGLView] removeFromSuperview]; } void CCXEGLView::setTouchDelegate(EGLTouchDelegate * pDelegate) @@ -66,7 +66,7 @@ void CCXEGLView::setTouchDelegate(EGLTouchDelegate * pDelegate) void CCXEGLView::swapBuffers() { - [[EAGLView getGlobalView] swapBuffers]; + [[EAGLView sharedEGLView] swapBuffers]; } void CCXEGLView::touchesBegan(NSSet *set) diff --git a/cocos2dx/platform/iphone/EAGLView.h b/cocos2dx/platform/iphone/EAGLView.h index 042969faef..399d8e4017 100755 --- a/cocos2dx/platform/iphone/EAGLView.h +++ b/cocos2dx/platform/iphone/EAGLView.h @@ -95,7 +95,7 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. /** creates an initializes an EAGLView with a frame, a color buffer format, and a depth buffer format */ + (id) viewWithFrame:(CGRect)frame pixelFormat:(NSString*)format depthFormat:(GLuint)depth preserveBackbuffer:(BOOL)retained; // get the view object -+(id) getGlobalView; ++(id) sharedEGLView; /** Initializes an EAGLView with a frame and 0-bit depth buffer, and a RGB565 color buffer */ - (id) initWithFrame:(CGRect)frame; //These also set the current context @@ -118,6 +118,9 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved. /** EAGLView uses double-buffer. This method swaps the buffers */ -(void) swapBuffers; +- (CGRect) convertRectFromViewToSurface:(CGRect)rect; +- (CGPoint) convertPointFromViewToSurface:(CGPoint)point; + -(int) getWidth; -(int) getHeight; @end diff --git a/cocos2dx/platform/iphone/EAGLView.mm b/cocos2dx/platform/iphone/EAGLView.mm index 2aa46b4a3b..0d99172a47 100755 --- a/cocos2dx/platform/iphone/EAGLView.mm +++ b/cocos2dx/platform/iphone/EAGLView.mm @@ -103,7 +103,7 @@ static EAGLView *view; return [[[self alloc] initWithFrame:frame pixelFormat:format depthFormat:depth preserveBackbuffer:retained] autorelease]; } -+ (id) getGlobalView ++ (id) sharedEGLView { return view; } @@ -199,6 +199,8 @@ static EAGLView *view; { [renderer_ resizeFromLayer:(CAEAGLLayer*)self.layer]; size_ = [renderer_ backingSize]; + + cocos2d::CCDirector::sharedDirector()->recalculateProjectionAndEAGLViewSize(); } - (void) swapBuffers @@ -225,6 +227,30 @@ static EAGLView *view; #pragma mark EAGLView - Point conversion +- (CGPoint) convertPointFromViewToSurface:(CGPoint)point +{ + CGRect bounds = [self bounds]; + + CGPoint ret; + ret.x = (point.x - bounds.origin.x) / bounds.size.width * size_.width; + ret.y = (point.y - bounds.origin.y) / bounds.size.height * size_.height; + + return ret; +} + +- (CGRect) convertRectFromViewToSurface:(CGRect)rect +{ + CGRect bounds = [self bounds]; + + CGRect ret; + ret.origin.x = (rect.origin.x - bounds.origin.x) / bounds.size.width * size_.width; + ret.origin.y = (rect.origin.y - bounds.origin.y) / bounds.size.height * size_.height; + ret.size.width = rect.size.width / bounds.size.width * size_.width; + ret.size.height = rect.size.height / bounds.size.height * size_.height; + + return ret; +} + // Pass the touches to the superview #pragma mark EAGLView - Touch Delegate