This commit is contained in:
Ming 2010-11-16 04:02:45 +00:00
parent 2587114512
commit 0aab635d85
5 changed files with 64 additions and 12 deletions

View File

@ -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);

View File

@ -23,6 +23,7 @@
****************************************************************************/
#import "CCDirectorCaller.h"
#import <UIKit/UIKit.h>
#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;
}

View File

@ -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)

View File

@ -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

View File

@ -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