Merge pull request #2816 from dumganhar/develop

[develop] new CCLabelTTF (static) create with fontDefinition method, and new CPP test using it
This commit is contained in:
James Chen 2013-06-07 20:02:22 -07:00
commit cc1bbd9508
4 changed files with 29 additions and 14 deletions

View File

@ -24,6 +24,7 @@ Developers:
carlomorgantinizynga
CCLabelTTF supports for shadow and stroke
Adding CCLabelTTF::createWithFontDefinition.
James Gregory (j4m3z0r, Zynga)
Maintainer of Emscripten port.

View File

@ -96,6 +96,18 @@ CCLabelTTF* CCLabelTTF::create(const char *string, const char *fontName, float f
return NULL;
}
CCLabelTTF * CCLabelTTF::createWithFontDefinition(const char *string, ccFontDefinition &textDefinition)
{
CCLabelTTF *pRet = new CCLabelTTF();
if(pRet && pRet->initWithStringAndTextDefinition(string, textDefinition))
{
pRet->autorelease();
return pRet;
}
CC_SAFE_DELETE(pRet);
return NULL;
}
bool CCLabelTTF::init()
{
return this->initWithString("", "Helvetica", 12);

View File

@ -70,6 +70,10 @@ public:
const CCSize& dimensions, CCTextAlignment hAlignment,
CCVerticalTextAlignment vAlignment);
/** Create a lable with string and a font definition*/
static CCLabelTTF * createWithFontDefinition(const char *string, ccFontDefinition &textDefinition);
/** initializes the CCLabelTTF with a font name and font size */
bool initWithString(const char *string, const char *fontName, float fontSize);

View File

@ -1470,7 +1470,7 @@ TTFFontShadowAndStroke::TTFFontShadowAndStroke()
addChild(layer, -10);
CCSize s = CCDirector::sharedDirector()->getWinSize();
ccColor3B tintColorRed = { 255, 0, 0 };
ccColor3B tintColorYellow = { 255, 255, 0 };
ccColor3B tintColorBlue = { 0, 0, 255 };
@ -1479,9 +1479,6 @@ TTFFontShadowAndStroke::TTFFontShadowAndStroke()
CCSize shadowOffset(12.0, 12.0);
// create the label shadow only
CCLabelTTF* fontShadow = new CCLabelTTF();
ccFontDefinition shadowTextDef;
shadowTextDef.m_fontSize = 20;
shadowTextDef.m_fontName = std::string("Marker Felt");
@ -1492,17 +1489,16 @@ TTFFontShadowAndStroke::TTFFontShadowAndStroke()
shadowTextDef.m_shadow.m_shadowBlur = 1.0;
shadowTextDef.m_fontFillColor = tintColorRed;
fontShadow->initWithStringAndTextDefinition("Shadow Only Red Text", shadowTextDef);
// shadow only label
CCLabelTTF* fontShadow = CCLabelTTF::createWithFontDefinition("Shadow Only Red Text", shadowTextDef);
// add label to the scene
this->addChild(fontShadow);
fontShadow->setPosition(ccp(s.width/2,s.height/4*2.5));
// create the label stroke only
CCLabelTTF* fontStroke = new CCLabelTTF();
// create the stroke only label
ccFontDefinition strokeTextDef;
strokeTextDef.m_fontSize = 20;
strokeTextDef.m_fontName = std::string("Marker Felt");
@ -1513,7 +1509,8 @@ TTFFontShadowAndStroke::TTFFontShadowAndStroke()
strokeTextDef.m_fontFillColor = tintColorYellow;
fontStroke->initWithStringAndTextDefinition("Stroke Only Yellow Text", strokeTextDef);
// stroke only label
CCLabelTTF* fontStroke = CCLabelTTF::createWithFontDefinition("Stroke Only Yellow Text", strokeTextDef);
// add label to the scene
this->addChild(fontStroke);
@ -1522,8 +1519,6 @@ TTFFontShadowAndStroke::TTFFontShadowAndStroke()
// create the label stroke and shadow
CCLabelTTF* fontStrokeAndShadow = new CCLabelTTF();
ccFontDefinition strokeShaodwTextDef;
strokeShaodwTextDef.m_fontSize = 20;
strokeShaodwTextDef.m_fontName = std::string("Marker Felt");
@ -1539,13 +1534,16 @@ TTFFontShadowAndStroke::TTFFontShadowAndStroke()
strokeShaodwTextDef.m_fontFillColor = tintColorBlue;
fontStrokeAndShadow->initWithStringAndTextDefinition("Stroke & Shadow Blue Text", strokeShaodwTextDef);
// shadow + stroke label
CCLabelTTF* fontStrokeAndShadow = CCLabelTTF::createWithFontDefinition("Stroke & Shadow Blue Text", strokeShaodwTextDef);
// add label to the scene
this->addChild(fontStrokeAndShadow);
fontStrokeAndShadow->setPosition(ccp(s.width/2,s.height/4*1.1));
}
std::string TTFFontShadowAndStroke::title()