From dc37896ed925af617583fbd36ebb76e906d20fde Mon Sep 17 00:00:00 2001 From: Walzer Date: Wed, 1 Aug 2012 13:24:23 +0800 Subject: [PATCH] change the param sequence of CCLabelTTF::create and initWithString, according to JS APIs --- cocos2dx/label_nodes/CCLabelTTF.cpp | 35 +++++++++------ cocos2dx/label_nodes/CCLabelTTF.h | 43 +++++++++++-------- cocos2dx/platform/CCPlatformMacros.h | 12 +++--- cocos2dx/text_input_node/CCTextFieldTTF.cpp | 2 +- samples/TestCpp/Classes/FontTest/FontTest.cpp | 9 ++-- .../TestCpp/Classes/LabelTest/LabelTest.cpp | 22 ++++++---- 6 files changed, 73 insertions(+), 50 deletions(-) diff --git a/cocos2dx/label_nodes/CCLabelTTF.cpp b/cocos2dx/label_nodes/CCLabelTTF.cpp index 236057746a..14953f500f 100644 --- a/cocos2dx/label_nodes/CCLabelTTF.cpp +++ b/cocos2dx/label_nodes/CCLabelTTF.cpp @@ -79,28 +79,35 @@ CCLabelTTF * CCLabelTTF::labelWithString(const char *string, const char *fontNam CCLabelTTF * CCLabelTTF::create(const char *string, const char *fontName, float fontSize) { - return CCLabelTTF::create(string, CCSizeZero, kCCTextAlignmentCenter, kCCVerticalTextAlignmentTop, fontName, fontSize); + return CCLabelTTF::create(string, fontName, fontSize, + CCSizeZero, kCCTextAlignmentCenter, kCCVerticalTextAlignmentTop); } CCLabelTTF * CCLabelTTF::labelWithString(const char *string, const CCSize& dimensions, CCTextAlignment hAlignment, const char *fontName, float fontSize) { - return CCLabelTTF::create(string, dimensions, hAlignment, kCCVerticalTextAlignmentTop, fontName, fontSize); + return CCLabelTTF::create(string, fontName, fontSize, + dimensions, hAlignment, kCCVerticalTextAlignmentTop); } -CCLabelTTF * CCLabelTTF::create(const char *string, const CCSize& dimensions, CCTextAlignment hAlignment, const char *fontName, float fontSize) +CCLabelTTF * CCLabelTTF::create(const char *string, const char *fontName, float fontSize, + const CCSize& dimensions, CCTextAlignment hAlignment) { - return CCLabelTTF::create(string, dimensions, hAlignment, kCCVerticalTextAlignmentTop, fontName, fontSize); + return CCLabelTTF::create(string, fontName, fontSize, dimensions, hAlignment, kCCVerticalTextAlignmentTop); } -CCLabelTTF* CCLabelTTF::labelWithString(const char *string, const cocos2d::CCSize &dimensions, CCTextAlignment hAlignment, CCVerticalTextAlignment vAlignment, const char *fontName, float fontSize) +CCLabelTTF* CCLabelTTF::labelWithString(const char *string, const cocos2d::CCSize &dimensions, + CCTextAlignment hAlignment, CCVerticalTextAlignment vAlignment, + const char *fontName, float fontSize) { - return CCLabelTTF::create(string, dimensions, hAlignment, vAlignment, fontName, fontSize); + return CCLabelTTF::create(string, fontName, fontSize, dimensions, hAlignment, vAlignment); } -CCLabelTTF* CCLabelTTF::create(const char *string, const cocos2d::CCSize &dimensions, CCTextAlignment hAlignment, CCVerticalTextAlignment vAlignment, const char *fontName, float fontSize) +CCLabelTTF* CCLabelTTF::create(const char *string, const char *fontName, float fontSize, + const CCSize &dimensions, CCTextAlignment hAlignment, + CCVerticalTextAlignment vAlignment) { CCLabelTTF *pRet = new CCLabelTTF(); - if(pRet && pRet->initWithString(string, dimensions, hAlignment, vAlignment, fontName, fontSize)) + if(pRet && pRet->initWithString(string, fontName, fontSize, dimensions, hAlignment, vAlignment)) { pRet->autorelease(); return pRet; @@ -114,17 +121,21 @@ bool CCLabelTTF::init() return this->initWithString("", "Helvetica", 12); } -bool CCLabelTTF::initWithString(const char *label, const CCSize& dimensions, CCTextAlignment alignment, const char *fontName, float fontSize) +bool CCLabelTTF::initWithString(const char *label, const char *fontName, float fontSize, + const CCSize& dimensions, CCTextAlignment alignment) { - return this->initWithString(label, dimensions, alignment, kCCVerticalTextAlignmentTop, fontName, fontSize); + return this->initWithString(label, fontName, fontSize, dimensions, alignment, kCCVerticalTextAlignmentTop); } bool CCLabelTTF::initWithString(const char *label, const char *fontName, float fontSize) { - return this->initWithString(label, CCSizeZero, kCCTextAlignmentLeft, kCCVerticalTextAlignmentTop, fontName, fontSize); + return this->initWithString(label, fontName, fontSize, + CCSizeZero, kCCTextAlignmentLeft, kCCVerticalTextAlignmentTop); } -bool CCLabelTTF::initWithString(const char *string, const cocos2d::CCSize &dimensions, CCTextAlignment hAlignment, CCVerticalTextAlignment vAlignment, const char *fontName, float fontSize) +bool CCLabelTTF::initWithString(const char *string, const char *fontName, float fontSize, + const cocos2d::CCSize &dimensions, CCTextAlignment hAlignment, + CCVerticalTextAlignment vAlignment) { if (CCSprite::init()) { diff --git a/cocos2dx/label_nodes/CCLabelTTF.h b/cocos2dx/label_nodes/CCLabelTTF.h index 3f1a0cb72f..9ee126c316 100644 --- a/cocos2dx/label_nodes/CCLabelTTF.h +++ b/cocos2dx/label_nodes/CCLabelTTF.h @@ -59,38 +59,43 @@ public: @deprecated: This interface will be deprecated sooner or later. @since v1.0 */ - CC_DEPRECATED_ATTRIBUTE static CCLabelTTF * labelWithString(const char *string, const CCSize& dimensions, CCTextAlignment hAlignment, - const char *fontName, float fontSize); + CC_DEPRECATED_ATTRIBUTE static CCLabelTTF * labelWithString(const char *string, const CCSize& dimensions, CCTextAlignment hAlignment, const char *fontName, float fontSize); /** creates a CCLabel from a fontname, alignment, dimension in points and font size in points @deprecated: This interface will be deprecated sooner or later. */ - CC_DEPRECATED_ATTRIBUTE static CCLabelTTF * labelWithString(const char *string, const CCSize& dimensions, CCTextAlignment hAlignment, - CCVerticalTextAlignment vAlignment, const char *fontName, float fontSize); + CC_DEPRECATED_ATTRIBUTE static CCLabelTTF * labelWithString(const char *string, const CCSize& dimensions, CCTextAlignment hAlignment, CCVerticalTextAlignment vAlignment, const char *fontName, float fontSize); - /** creates a CCLabelTTF with a font name and font size in points*/ + /** creates a CCLabelTTF with a font name and font size in points + @since v2.0.1 + */ static CCLabelTTF * create(const char *string, const char *fontName, float fontSize); /** creates a CCLabelTTF from a fontname, horizontal alignment, dimension in points, and font size in points. - @since v1.0 + @since v2.0.1 */ - static CCLabelTTF * create(const char *string, const CCSize& dimensions, CCTextAlignment hAlignment, - const char *fontName, float fontSize); - - /** creates a CCLabel from a fontname, alignment, dimension in points and font size in points*/ - static CCLabelTTF * create(const char *string, const CCSize& dimensions, CCTextAlignment hAlignment, - CCVerticalTextAlignment vAlignment, const char *fontName, float fontSize); - - /** initializes the CCLabelTTF with a font name, alignment, dimension and font size */ - bool initWithString(const char *string, const CCSize& dimensions, CCTextAlignment hAlignment, const char *fontName, float fontSize); - - /** initializes the CCLabelTTF with a font name, alignment, dimension and font size */ - bool initWithString(const char *string, const CCSize& dimensions, CCTextAlignment hAlignment, - CCVerticalTextAlignment vAlignment, const char *fontName, float fontSize); + static CCLabelTTF * create(const char *string, const char *fontName, float fontSize, + const CCSize& dimensions, CCTextAlignment hAlignment); + + /** creates a CCLabel from a fontname, alignment, dimension in points and font size in points + @since v2.0.1 + */ + static CCLabelTTF * create(const char *string, const char *fontName, float fontSize, + const CCSize& dimensions, CCTextAlignment hAlignment, + CCVerticalTextAlignment vAlignment); /** initializes the CCLabelTTF with a font name and font size */ bool initWithString(const char *string, const char *fontName, float fontSize); + /** initializes the CCLabelTTF with a font name, alignment, dimension and font size */ + bool initWithString(const char *string, const char *fontName, float fontSize, + const CCSize& dimensions, CCTextAlignment hAlignment); + + /** initializes the CCLabelTTF with a font name, alignment, dimension and font size */ + bool initWithString(const char *string, const char *fontName, float fontSize, + const CCSize& dimensions, CCTextAlignment hAlignment, + CCVerticalTextAlignment vAlignment); + /** initializes the CCLabelTTF */ bool init(); /** Creates an label. diff --git a/cocos2dx/platform/CCPlatformMacros.h b/cocos2dx/platform/CCPlatformMacros.h index 7abab28297..8399de2a90 100644 --- a/cocos2dx/platform/CCPlatformMacros.h +++ b/cocos2dx/platform/CCPlatformMacros.h @@ -194,12 +194,12 @@ public: virtual void set##funName(varType var) \ /* * only certain compilers support __attribute__((deprecated)) */ -// #if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))) -// #define CC_DEPRECATED_ATTRIBUTE __attribute__((deprecated)) -// #elif _MSC_VER >= 1400 //vs 2005 or higher -// #define CC_DEPRECATED_ATTRIBUTE __declspec(deprecated) -// #else +#if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))) + #define CC_DEPRECATED_ATTRIBUTE __attribute__((deprecated)) +#elif _MSC_VER >= 1400 //vs 2005 or higher + #define CC_DEPRECATED_ATTRIBUTE __declspec(deprecated) +#else #define CC_DEPRECATED_ATTRIBUTE -// #endif +#endif #endif // __CC_PLATFORM_MACROS_H__ diff --git a/cocos2dx/text_input_node/CCTextFieldTTF.cpp b/cocos2dx/text_input_node/CCTextFieldTTF.cpp index 497a383cb7..b0d6d36879 100644 --- a/cocos2dx/text_input_node/CCTextFieldTTF.cpp +++ b/cocos2dx/text_input_node/CCTextFieldTTF.cpp @@ -112,7 +112,7 @@ bool CCTextFieldTTF::initWithPlaceHolder(const char *placeholder, const CCSize& CC_SAFE_DELETE(m_pPlaceHolder); m_pPlaceHolder = new std::string(placeholder); } - return CCLabelTTF::initWithString(m_pPlaceHolder->c_str(), dimensions, alignment, fontName, fontSize); + return CCLabelTTF::initWithString(m_pPlaceHolder->c_str(), fontName, fontSize, dimensions, alignment); } bool CCTextFieldTTF::initWithPlaceHolder(const char *placeholder, const char *fontName, float fontSize) { diff --git a/samples/TestCpp/Classes/FontTest/FontTest.cpp b/samples/TestCpp/Classes/FontTest/FontTest.cpp index 62b854677f..4d0720e754 100644 --- a/samples/TestCpp/Classes/FontTest/FontTest.cpp +++ b/samples/TestCpp/Classes/FontTest/FontTest.cpp @@ -94,9 +94,12 @@ void FontTest::showFont(const char *pFont) removeChildByTag(kTagLabel4, true); CCLabelTTF *top = CCLabelTTF::create(pFont, pFont, 24); - CCLabelTTF *left = CCLabelTTF::create("alignment left", blockSize, kCCTextAlignmentLeft, verticalAlignment[vAlignIdx], pFont, fontSize); - CCLabelTTF *center = CCLabelTTF::create("alignment center", blockSize, kCCTextAlignmentCenter, verticalAlignment[vAlignIdx], pFont, fontSize); - CCLabelTTF *right = CCLabelTTF::create("alignment right", blockSize, kCCTextAlignmentRight, verticalAlignment[vAlignIdx], pFont, fontSize); + CCLabelTTF *left = CCLabelTTF::create("alignment left", pFont, fontSize, + blockSize, kCCTextAlignmentLeft, verticalAlignment[vAlignIdx]); + CCLabelTTF *center = CCLabelTTF::create("alignment center", pFont, fontSize, + blockSize, kCCTextAlignmentCenter, verticalAlignment[vAlignIdx]); + CCLabelTTF *right = CCLabelTTF::create("alignment right", pFont, fontSize, + blockSize, kCCTextAlignmentRight, verticalAlignment[vAlignIdx]); CCLayerColor *leftColor = CCLayerColor::create(ccc4(100, 100, 100, 255), blockSize.width, blockSize.height); CCLayerColor *centerColor = CCLayerColor::create(ccc4(200, 100, 100, 255), blockSize.width, blockSize.height); diff --git a/samples/TestCpp/Classes/LabelTest/LabelTest.cpp b/samples/TestCpp/Classes/LabelTest/LabelTest.cpp index b7671c2d7a..9ca92c5024 100644 --- a/samples/TestCpp/Classes/LabelTest/LabelTest.cpp +++ b/samples/TestCpp/Classes/LabelTest/LabelTest.cpp @@ -371,17 +371,20 @@ LabelTTFAlignment::LabelTTFAlignment() { CCSize s = CCDirector::sharedDirector()->getWinSize(); - CCLabelTTF* ttf0 = CCLabelTTF::create("Alignment 0\nnew line", CCSizeMake(256, 32), kCCTextAlignmentLeft, "Helvetica", 12); + CCLabelTTF* ttf0 = CCLabelTTF::create("Alignment 0\nnew line", "Helvetica", 12, + CCSizeMake(256, 32), kCCTextAlignmentLeft); ttf0->setPosition(ccp(s.width/2,(s.height/6)*2)); ttf0->setAnchorPoint(ccp(0.5f,0.5f)); this->addChild(ttf0); - CCLabelTTF* ttf1 = CCLabelTTF::create("Alignment 1\nnew line", CCSizeMake(245, 32), kCCTextAlignmentCenter, "Helvetica", 12); + CCLabelTTF* ttf1 = CCLabelTTF::create("Alignment 1\nnew line", "Helvetica", 12, + CCSizeMake(245, 32), kCCTextAlignmentCenter); ttf1->setPosition(ccp(s.width/2,(s.height/6)*3)); ttf1->setAnchorPoint(ccp(0.5f,0.5f)); this->addChild(ttf1); - CCLabelTTF* ttf2 = CCLabelTTF::create("Alignment 2\nnew line", CCSizeMake(245, 32), kCCTextAlignmentRight, "Helvetica", 12); + CCLabelTTF* ttf2 = CCLabelTTF::create("Alignment 2\nnew line", "Helvetica", 12, + CCSizeMake(245, 32), kCCTextAlignmentRight); ttf2->setPosition(ccp(s.width/2,(s.height/6)*4)); ttf2->setAnchorPoint(ccp(0.5f,0.5f)); this->addChild(ttf2); @@ -997,7 +1000,8 @@ void LabelTTFTest::updateAlignment() m_plabel->removeFromParentAndCleanup(true); } - m_plabel = CCLabelTTF::create(this->getCurrentAlignment(), blockSize, m_eHorizAlign, m_eVertAlign, "Marker Felt", 32); + m_plabel = CCLabelTTF::create(this->getCurrentAlignment(), "Marker Felt", 32, + blockSize, m_eHorizAlign, m_eVertAlign); m_plabel->retain(); m_plabel->setAnchorPoint(ccp(0,0)); @@ -1087,11 +1091,11 @@ LabelTTFMultiline::LabelTTFMultiline() CCSize s = CCDirector::sharedDirector()->getWinSize(); CCLabelTTF *center = CCLabelTTF::create("word wrap \"testing\" (bla0) bla1 'bla2' [bla3] (bla4) {bla5} {bla6} [bla7] (bla8) [bla9] 'bla0' \"bla1\"", - CCSizeMake(s.width/2,200), - kCCTextAlignmentCenter, - kCCVerticalTextAlignmentTop, - "Paint Boy", - 32); + "Paint Boy", + 32, + CCSizeMake(s.width/2,200), + kCCTextAlignmentCenter, + kCCVerticalTextAlignmentTop); center->setPosition(ccp(s.width / 2, 150));