new CCLabelTTF (static) create with fontDefinition method, and new CPP test using it

This commit is contained in:
carlo morgantini 2013-06-07 16:33:01 -07:00
parent 2107fdddf1
commit b7ffb5b810
3 changed files with 28 additions and 14 deletions

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

@ -1497,7 +1497,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 };
@ -1506,9 +1506,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");
@ -1519,17 +1516,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");
@ -1540,7 +1536,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);
@ -1549,8 +1546,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");
@ -1566,13 +1561,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()