Added default init method for CCLabelTTF (See: 24125b93aad2d4fc7ebf1bc6e4ef6b8b83ff770d).

This commit is contained in:
Nicolas Gramlich 2012-05-30 15:34:50 -07:00
parent 827ee160b5
commit 9ca7fa468a
2 changed files with 49 additions and 0 deletions

View File

@ -52,6 +52,20 @@ CCLabelTTF::~CCLabelTTF()
CC_SAFE_DELETE(m_pString);
}
CCLabelTTF * CCLabelTTF::node()
{
CCLabelTTF * pRet = new CCLabelTTF();
if (pRet && pRet->init())
{
pRet->autorelease();
}
else
{
CC_SAFE_DELETE(pRet);
}
return pRet;
}
CCLabelTTF * CCLabelTTF::labelWithString(const char *label, const CCSize& dimensions, CCTextAlignment alignment, const char *fontName, float fontSize)
{
CCLabelTTF *pRet = new CCLabelTTF();
@ -119,6 +133,34 @@ bool CCLabelTTF::initWithString(const char *label, const char *fontName, float f
}
return false;
}
void CCLabelTTF::setFontName(const char *fontName)
{
if(this->m_pFontName == NULL || strcmp(this->m_pFontName->c_str(), fontName))
{
CC_SAFE_DELETE(m_pFontName);
this->m_pFontName = new std::string(fontName);
this->setString(this->m_pString->c_str());
}
}
void CCLabelTTF::setFontSize(float fontSize)
{
if(this->m_fFontSize != fontSize)
{
this->m_fFontSize = fontSize;
this->setString(this->m_pString->c_str());
}
}
void CCLabelTTF::setHorizontalAlignment(CCTextAlignment pCCTextAlignment)
{
if(this->m_eAlignment != pCCTextAlignment)
{
this->m_eAlignment = pCCTextAlignment;
this->setString(this->m_pString->c_str());
}
}
void CCLabelTTF::setString(const char *label)
{
if (m_pString)

View File

@ -52,11 +52,18 @@ public:
bool initWithString(const char *label, const char *fontName, float fontSize);
/** initializes the CCLabelTTF */
bool init();
/** Creates an label.
*/
static CCLabelTTF * node();
/** changes the string to render
* @warning Changing the string is as expensive as creating a new CCLabelTTF. To obtain better performance use CCLabelAtlas
*/
virtual void setString(const char *label);
virtual const char* getString(void);
virtual void setFontName(const char *fontName);
virtual void setFontSize(float fontSize);
virtual void setHorizontalAlignment(CCTextAlignment);
// virtual void setVerticalAlignment(...); // ( See: 63d9724ac4d81a05c6ec7feea0c01bcd27c8fc6b )
virtual CCLabelProtocol* convertToLabelProtocol() { return (CCLabelProtocol*)this; }
protected: