issue #2430: Refactoring enum 'ResolutionPolicy'.

This commit is contained in:
James Chen 2013-07-26 18:18:58 +08:00
parent 2f8d3587bd
commit e16a5f469b
16 changed files with 54 additions and 40 deletions

View File

@ -178,16 +178,23 @@ const LanguageType kLanguagePolish = LanguageType::POLISH;
const Application::Platform kTargetWindows = Application::Platform::WINDOWS;
const Application::Platform kTargetLinux = Application::Platform::LINUX;
const Application::Platform kTargetMacOS = Application::Platform::MACOS;
const Application::Platform kTargetAndroid = Application::Platform::ANDROID;
const Application::Platform kTargetIphone = Application::Platform::IPHONE;
const Application::Platform kTargetIpad = Application::Platform::IPAD;
const Application::Platform kTargetBlackBerry = Application::Platform::BLACKBERRY;
const Application::Platform kTargetNaCl = Application::Platform::NACL;
const Application::Platform kTargetEmscripten = Application::Platform::EMSCRIPTEN;
const Application::Platform kTargetTizen = Application::Platform::TIZEN;
const Application::Platform kTargetWindows = Application::Platform::OS_WINDOWS;
const Application::Platform kTargetLinux = Application::Platform::OS_LINUX;
const Application::Platform kTargetMacOS = Application::Platform::OS_MACOS;
const Application::Platform kTargetAndroid = Application::Platform::OS_ANDROID;
const Application::Platform kTargetIphone = Application::Platform::OS_IPHONE;
const Application::Platform kTargetIpad = Application::Platform::OS_IPAD;
const Application::Platform kTargetBlackBerry = Application::Platform::OS_BLACKBERRY;
const Application::Platform kTargetNaCl = Application::Platform::OS_NACL;
const Application::Platform kTargetEmscripten = Application::Platform::OS_EMSCRIPTEN;
const Application::Platform kTargetTizen = Application::Platform::OS_TIZEN;
const ResolutionPolicy kResolutionExactFit = ResolutionPolicy::EXACTFIT;
const ResolutionPolicy kResolutionNoBorder = ResolutionPolicy::NO_BORDER;
const ResolutionPolicy kResolutionShowAll = ResolutionPolicy::SHOW_ALL;
const ResolutionPolicy kResolutionFixedHeight = ResolutionPolicy::FIXED_HEIGHT;
const ResolutionPolicy kResolutionFixedWidth = ResolutionPolicy::FIXED_WIDTH;
const ResolutionPolicy kResolutionUnKnown = ResolutionPolicy::UNKNOWN;
void ccDrawInit()
{

View File

@ -967,6 +967,13 @@ CC_DEPRECATED_ATTRIBUTE extern const Application::Platform kTargetEmscripten;
CC_DEPRECATED_ATTRIBUTE extern const Application::Platform kTargetTizen;
CC_DEPRECATED_ATTRIBUTE typedef Application::Platform TargetPlatform;
CC_DEPRECATED_ATTRIBUTE extern const ResolutionPolicy kResolutionExactFit;
CC_DEPRECATED_ATTRIBUTE extern const ResolutionPolicy kResolutionNoBorder;
CC_DEPRECATED_ATTRIBUTE extern const ResolutionPolicy kResolutionShowAll;
CC_DEPRECATED_ATTRIBUTE extern const ResolutionPolicy kResolutionFixedHeight;
CC_DEPRECATED_ATTRIBUTE extern const ResolutionPolicy kResolutionFixedWidth;
CC_DEPRECATED_ATTRIBUTE extern const ResolutionPolicy kResolutionUnKnown;
#define kCCTMXTileHorizontalFlag kTMXTileHorizontalFlag
#define kCCTMXTileVerticalFlag kTMXTileVerticalFlag
#define kCCTMXTileDiagonalFlag kTMXTileDiagonalFlag

View File

@ -46,7 +46,7 @@ EGLViewProtocol::EGLViewProtocol()
: _delegate(NULL)
, _scaleX(1.0f)
, _scaleY(1.0f)
, _resolutionPolicy(kResolutionUnKnown)
, _resolutionPolicy(ResolutionPolicy::UNKNOWN)
{
}
@ -57,7 +57,7 @@ EGLViewProtocol::~EGLViewProtocol()
void EGLViewProtocol::setDesignResolutionSize(float width, float height, ResolutionPolicy resolutionPolicy)
{
CCASSERT(resolutionPolicy != kResolutionUnKnown, "should set resolutionPolicy");
CCASSERT(resolutionPolicy != ResolutionPolicy::UNKNOWN, "should set resolutionPolicy");
if (width == 0.0f || height == 0.0f)
{
@ -69,22 +69,22 @@ void EGLViewProtocol::setDesignResolutionSize(float width, float height, Resolut
_scaleX = (float)_screenSize.width / _designResolutionSize.width;
_scaleY = (float)_screenSize.height / _designResolutionSize.height;
if (resolutionPolicy == kResolutionNoBorder)
if (resolutionPolicy == ResolutionPolicy::NO_BORDER)
{
_scaleX = _scaleY = MAX(_scaleX, _scaleY);
}
if (resolutionPolicy == kResolutionShowAll)
if (resolutionPolicy == ResolutionPolicy::SHOW_ALL)
{
_scaleX = _scaleY = MIN(_scaleX, _scaleY);
}
if ( resolutionPolicy == kResolutionFixedHeight) {
if ( resolutionPolicy == ResolutionPolicy::FIXED_HEIGHT) {
_scaleX = _scaleY;
_designResolutionSize.width = ceilf(_screenSize.width/_scaleX);
}
if ( resolutionPolicy == kResolutionFixedWidth) {
if ( resolutionPolicy == ResolutionPolicy::FIXED_WIDTH) {
_scaleY = _scaleX;
_designResolutionSize.height = ceilf(_screenSize.height/_scaleY);
}
@ -120,7 +120,7 @@ void EGLViewProtocol::setFrameSize(float width, float height)
Size EGLViewProtocol::getVisibleSize() const
{
if (_resolutionPolicy == kResolutionNoBorder)
if (_resolutionPolicy == ResolutionPolicy::NO_BORDER)
{
return Size(_screenSize.width/_scaleX, _screenSize.height/_scaleY);
}
@ -132,7 +132,7 @@ Size EGLViewProtocol::getVisibleSize() const
Point EGLViewProtocol::getVisibleOrigin() const
{
if (_resolutionPolicy == kResolutionNoBorder)
if (_resolutionPolicy == ResolutionPolicy::NO_BORDER)
{
return Point((_designResolutionSize.width - _screenSize.width/_scaleX)/2,
(_designResolutionSize.height - _screenSize.height/_scaleY)/2);

View File

@ -3,29 +3,29 @@
#include "ccTypes.h"
enum ResolutionPolicy
enum class ResolutionPolicy
{
// 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.
kResolutionExactFit,
EXACTFIT,
// The entire application fills the specified area, without distortion but possibly with some cropping,
// while maintaining the original aspect ratio of the application.
kResolutionNoBorder,
NO_BORDER,
// 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.
kResolutionShowAll,
SHOW_ALL,
// The application takes the height of the design resolution size and modifies the width of the internal
// canvas so that it fits the aspect ratio of the device
// no distortion will occur however you must make sure your application works on different
// aspect ratios
kResolutionFixedHeight,
FIXED_HEIGHT,
// The application takes the width of the design resolution size and modifies the height of the internal
// canvas so that it fits the aspect ratio of the device
// no distortion will occur however you must make sure your application works on different
// aspect ratios
kResolutionFixedWidth,
FIXED_WIDTH,
kResolutionUnKnown,
UNKNOWN,
};
NS_CC_BEGIN
@ -84,9 +84,9 @@ public:
* @param width Design resolution width.
* @param height Design resolution height.
* @param resolutionPolicy The resolution policy desired, you may choose:
* [1] kResolutionExactFit Fill screen by stretch-to-fit: if the design resolution ratio of width to height is different from the screen resolution ratio, your game view will be stretched.
* [2] kResolutionNoBorder Full screen without black border: if the design resolution ratio of width to height is different from the screen resolution ratio, two areas of your game view will be cut.
* [3] kResolutionShowAll Full screen with black border: if the design resolution ratio of width to height is different from the screen resolution ratio, two black borders will be shown.
* [1] EXACTFIT Fill screen by stretch-to-fit: if the design resolution ratio of width to height is different from the screen resolution ratio, your game view will be stretched.
* [2] NO_BORDER Full screen without black border: if the design resolution ratio of width to height is different from the screen resolution ratio, two areas of your game view will be cut.
* [3] SHOW_ALL Full screen with black border: if the design resolution ratio of width to height is different from the screen resolution ratio, two black borders will be shown.
*/
virtual void setDesignResolutionSize(float width, float height, ResolutionPolicy resolutionPolicy);

View File

@ -48,7 +48,7 @@ bool EGLView::isOpenGLReady()
bool EGLView::setContentScaleFactor(float contentScaleFactor)
{
assert(_resolutionPolicy == kResolutionUnKnown); // cannot enable retina mode
assert(_resolutionPolicy == ResolutionPolicy::UNKNOWN); // cannot enable retina mode
_scaleX = _scaleY = contentScaleFactor;
[[CCEAGLView sharedEGLView] setNeedsLayout];

View File

@ -18,7 +18,7 @@ bool AppDelegate::applicationDidFinishLaunching() {
pDirector->setOpenGLView(pEGLView);
pEGLView->setDesignResolutionSize(960.0f, 640.0f, kResolutionNoBorder);
pEGLView->setDesignResolutionSize(960.0f, 640.0f, ResolutionPolicy::NO_BORDER);
// turn on display FPS
pDirector->setDisplayStats(true);

View File

@ -27,7 +27,7 @@ bool AppDelegate::applicationDidFinishLaunching() {
Size size = director->getWinSize();
// Set the design resolution
glView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionNoBorder);
glView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
Size frameSize = glView->getFrameSize();

View File

@ -36,7 +36,7 @@ bool AppDelegate::applicationDidFinishLaunching() {
FileUtils::getInstance()->setSearchPaths(searchPaths);
EGLView::getInstance()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionNoBorder);
EGLView::getInstance()->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER);
// turn on display FPS
director->setDisplayStats(true);

View File

@ -48,7 +48,7 @@ bool AppDelegate::applicationDidFinishLaunching()
director->setContentScaleFactor(resourceSize.height/designSize.height);
}
EGLView::getInstance()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionNoBorder);
EGLView::getInstance()->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER);
auto scene = Scene::create();
auto layer = new TestController();

View File

@ -109,7 +109,7 @@ bool AppDelegate::applicationDidFinishLaunching()
pDirector->setContentScaleFactor(resourceSize.width/designSize.width);
EGLView::getInstance()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionNoBorder);
EGLView::getInstance()->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER);
// turn on display FPS
pDirector->setDisplayStats(true);

View File

@ -91,7 +91,7 @@ bool AppDelegate::applicationDidFinishLaunching()
}
pDirector->setContentScaleFactor(resourceSize.width/designSize.width);
EGLView::getInstance()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionShowAll);
EGLView::getInstance()->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::SHOW_ALL);
// turn on display FPS
pDirector->setDisplayStats(true);

View File

@ -32,7 +32,7 @@ bool AppDelegate::applicationDidFinishLaunching()
pDirector->setProjection(Director::Projection::_2D);
// Set the design resolution
EGLView::getInstance()->setDesignResolutionSize(320, 480, kResolutionShowAll);
EGLView::getInstance()->setDesignResolutionSize(320, 480, ResolutionPolicy::SHOW_ALL);
// turn on display FPS
pDirector->setDisplayStats(true);

View File

@ -33,7 +33,7 @@ bool AppDelegate::applicationDidFinishLaunching()
pDirector->setOpenGLView(EGLView::getInstance());
// JS-Test in Html5 uses 800x450 as design resolution
EGLView::getInstance()->setDesignResolutionSize(800, 450, kResolutionFixedHeight);
EGLView::getInstance()->setDesignResolutionSize(800, 450, ResolutionPolicy::FIXED_HEIGHT);
// turn on display FPS
pDirector->setDisplayStats(true);

View File

@ -36,7 +36,7 @@ bool AppDelegate::applicationDidFinishLaunching()
// set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60);
EGLView::getInstance()->setDesignResolutionSize(480, 320, kResolutionFixedHeight);
EGLView::getInstance()->setDesignResolutionSize(480, 320, ResolutionPolicy::FIXED_HEIGHT);
ScriptingCore* sc = ScriptingCore::getInstance();
sc->addRegisterCallback(register_all_cocos2dx);

View File

@ -26,7 +26,7 @@ bool AppDelegate::applicationDidFinishLaunching()
Director *pDirector = Director::getInstance();
pDirector->setOpenGLView(EGLView::getInstance());
EGLView::getInstance()->setDesignResolutionSize(480, 320, kResolutionNoBorder);
EGLView::getInstance()->setDesignResolutionSize(480, 320, ResolutionPolicy::NO_BORDER);
// turn on display FPS
pDirector->setDisplayStats(true);

View File

@ -44,7 +44,7 @@ bool AppDelegate::applicationDidFinishLaunching()
pDirector->setContentScaleFactor(resourceSize.height/designSize.height);
}
EGLView::getInstance()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionFixedHeight);
EGLView::getInstance()->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::FIXED_HEIGHT);
// register lua engine
LuaEngine* pEngine = LuaEngine::getInstance();