From c34812567f4ac7e445a6a7ea4ae475a1d18fe62c Mon Sep 17 00:00:00 2001 From: minggo Date: Thu, 9 Aug 2012 10:23:39 +0800 Subject: [PATCH] issue #1405: modify macro names and comment and add getVisibleSize and getVisibleOrigin in CCDirector --- cocos2dx/CCDirector.cpp | 26 +++++++++++++++++++- cocos2dx/CCDirector.h | 10 ++++++++ cocos2dx/platform/CCEGLViewProtocol.cpp | 8 +++--- cocos2dx/platform/CCEGLViewProtocol.h | 15 ++++++----- samples/HelloCpp/Classes/AppDelegate.cpp | 10 +++++--- samples/HelloCpp/Classes/HelloWorldScene.cpp | 4 +-- 6 files changed, 56 insertions(+), 17 deletions(-) diff --git a/cocos2dx/CCDirector.cpp b/cocos2dx/CCDirector.cpp index 89a76db206..d3c91f9603 100644 --- a/cocos2dx/CCDirector.cpp +++ b/cocos2dx/CCDirector.cpp @@ -62,7 +62,7 @@ THE SOFTWARE. Default: 0,0 (bottom-left corner) */ #ifndef CC_DIRECTOR_STATS_POSITION -#define CC_DIRECTOR_STATS_POSITION CCDirector::sharedDirector()->getOpenGLView()->getVisibleOrigin() +#define CC_DIRECTOR_STATS_POSITION CCDirector::sharedDirector()->getVisibleOrigin() #endif using namespace std; @@ -474,6 +474,30 @@ CCSize CCDirector::getWinSizeInPixels() return m_obWinSizeInPixels; } +CCSize CCDirector::getVisibleSize() +{ + if (m_pobOpenGLView) + { + return m_pobOpenGLView->getVisibleSize(); + } + else + { + return CCSizeZero; + } +} + +CCPoint CCDirector::getVisibleOrigin() +{ + if (m_pobOpenGLView) + { + return m_pobOpenGLView->getVisibleOrigin(); + } + else + { + return CCPointZero; + } +} + void CCDirector::reshapeProjection(const CCSize& newWindowSize) { CC_UNUSED_PARAM(newWindowSize); diff --git a/cocos2dx/CCDirector.h b/cocos2dx/CCDirector.h index a918f75043..dd413deebe 100644 --- a/cocos2dx/CCDirector.h +++ b/cocos2dx/CCDirector.h @@ -165,6 +165,16 @@ public: /** returns the size of the OpenGL view in pixels. */ CCSize getWinSizeInPixels(void); + + /** returns visible size of the OpenGL view in points. + * the value is equal to getWinSize if don't invoke + * CCEGLView::setDesignResolutionSize() + */ + CCSize getVisibleSize(); + + /** returns visible origin of the OpenGL view in points. + */ + CCPoint getVisibleOrigin(); /** changes the projection size */ void reshapeProjection(const CCSize& newWindowSize); diff --git a/cocos2dx/platform/CCEGLViewProtocol.cpp b/cocos2dx/platform/CCEGLViewProtocol.cpp index 96313bd1e9..e71ba6cd97 100644 --- a/cocos2dx/platform/CCEGLViewProtocol.cpp +++ b/cocos2dx/platform/CCEGLViewProtocol.cpp @@ -72,12 +72,12 @@ void CCEGLViewProtocol::setDesignResolutionSize(float width, float height, Resol m_fXScale = (float)m_obScreenSize.width / m_obDesignResolutionSize.width; m_fYScale = (float)m_obScreenSize.height / m_obDesignResolutionSize.height; - if (resolutionPolicy == kResolutionScaleFullScreen) + if (resolutionPolicy == kCCResolutionNoBorder) { m_fXScale = m_fYScale = MAX(m_fXScale, m_fYScale); } - if (resolutionPolicy == kResolutionScaleNotFullScreen) + if (resolutionPolicy == kCCResolutionShowAll) { m_fXScale = m_fYScale = MIN(m_fXScale, m_fYScale); } @@ -115,7 +115,7 @@ void CCEGLViewProtocol::setSize(float width, float height) CCSize CCEGLViewProtocol::getVisibleSize() { - if (m_eResolutionPolicy == kResolutionScaleFullScreen) + if (m_eResolutionPolicy == kCCResolutionNoBorder) { return CCSizeMake(m_obScreenSize.width/m_fXScale, m_obScreenSize.height/m_fYScale); } @@ -127,7 +127,7 @@ CCSize CCEGLViewProtocol::getVisibleSize() CCPoint CCEGLViewProtocol::getVisibleOrigin() { - if (m_eResolutionPolicy == kResolutionScaleFullScreen) + if (m_eResolutionPolicy == kCCResolutionNoBorder) { return CCPointMake((m_obDesignResolutionSize.width - m_obScreenSize.width/m_fXScale)/2, (m_obDesignResolutionSize.height - m_obScreenSize.height/m_fYScale)/2); diff --git a/cocos2dx/platform/CCEGLViewProtocol.h b/cocos2dx/platform/CCEGLViewProtocol.h index 36ef4d05b7..0cb3be3574 100644 --- a/cocos2dx/platform/CCEGLViewProtocol.h +++ b/cocos2dx/platform/CCEGLViewProtocol.h @@ -5,12 +5,15 @@ enum ResolutionPolicy { - // the output will fill the screen, scale of x and y may be different - kResolutionFullScreen, - // the output will fill the screen, scale of x and y is the same - kResolutionScaleFullScreen, - // scale of x and y is the same, there may be black block in x or y coordinate - kResolutionScaleNotFullScreen, + // The entire application is visible in the specified area without trying to preserve the original aspect ratio. + // Distortion can occur, and the application may appear stretched or compressed. + kCCResolutionExactFit, + // The entire application fills the specified area, without distortion but possibly with some cropping, + // while maintaining the original aspect ratio of the application. + kCCResolutionNoBorder, + // The entire application is visible in the specified area without distortion while maintaining the original + // aspect ratio of the application. Borders can appear on two sides of the application. + kCCResolutionShowAll, kResolutionUnKnown, }; diff --git a/samples/HelloCpp/Classes/AppDelegate.cpp b/samples/HelloCpp/Classes/AppDelegate.cpp index 2e5f46876f..5cae0b6b44 100644 --- a/samples/HelloCpp/Classes/AppDelegate.cpp +++ b/samples/HelloCpp/Classes/AppDelegate.cpp @@ -24,7 +24,7 @@ bool AppDelegate::applicationDidFinishLaunching() { CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd"); // don't enable retina because we don't have ipad hd resource - CCEGLView::sharedOpenGLView().setDesignResolutionSize(960, 640, kResolutionScaleFullScreen); + CCEGLView::sharedOpenGLView().setDesignResolutionSize(960, 640, kCCResolutionNoBorder); } else { @@ -32,20 +32,22 @@ bool AppDelegate::applicationDidFinishLaunching() { if (pDirector->enableRetinaDisplay(true)) { - // iphone + // iphone hd CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd"); } else { if (isIos()) { + // iphone CCFileUtils::sharedFileUtils()->setResourceDirectory("iphone"); } else { - CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd"); // android or other platform, use hd resource - CCEGLView::sharedOpenGLView().setDesignResolutionSize(960, 640, kResolutionScaleFullScreen); + + CCFileUtils::sharedFileUtils()->setResourceDirectory("iphonehd"); + CCEGLView::sharedOpenGLView().setDesignResolutionSize(960, 640, kCCResolutionNoBorder); } } } diff --git a/samples/HelloCpp/Classes/HelloWorldScene.cpp b/samples/HelloCpp/Classes/HelloWorldScene.cpp index f2cf2bfdf6..df74a4bba0 100644 --- a/samples/HelloCpp/Classes/HelloWorldScene.cpp +++ b/samples/HelloCpp/Classes/HelloWorldScene.cpp @@ -27,8 +27,8 @@ bool HelloWorld::init() return false; } - CCSize visibleSize = CCDirector::sharedDirector()->getOpenGLView()->getVisibleSize(); - CCPoint origin = CCDirector::sharedDirector()->getOpenGLView()->getVisibleOrigin(); + CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); + CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program