Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cocos2dx/include/CCLabelTTF.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ namespace cocos2d{
class CC_DLL CCLabelTTF : public CCSprite, public CCLabelProtocol
{
public:
CCLabelTTF() {}
virtual ~CCLabelTTF(){}
CCLabelTTF();
virtual ~CCLabelTTF();
char * description();
/** creates a CCLabelTTF from a fontname, alignment, dimension and font size */
static CCLabelTTF * labelWithString(const char *label, CCSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize);
Expand All @@ -59,9 +59,9 @@ namespace cocos2d{
protected:
CCSize m_tDimensions;
UITextAlignment m_eAlignment;
ccxScopedPtr<std::string> m_pFontName;
std::string * m_pFontName;
float m_fFontSize;
ccxScopedPtr<std::string> m_pString;
std::string * m_pString;
};

} //namespace cocos2d
Expand Down
47 changes: 44 additions & 3 deletions cocos2dx/label_nodes/CCLabelTTF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@ namespace cocos2d{
//
//CCLabelTTF
//
CCLabelTTF::CCLabelTTF()
: m_pFontName(NULL)
, m_pString(NULL)
{
}

CCLabelTTF::~CCLabelTTF()
{
if (m_pFontName)
{
delete m_pFontName;
m_pFontName = NULL;
}

if (m_pString)
{
delete m_pString;
m_pString = NULL;
}

}

CCLabelTTF * CCLabelTTF::labelWithString(const char *label, CCSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize)
{
CCLabelTTF *pRet = new CCLabelTTF();
Expand Down Expand Up @@ -57,7 +79,14 @@ namespace cocos2d{
{
m_tDimensions = CCSizeMake( dimensions.width * CC_CONTENT_SCALE_FACTOR(), dimensions.height * CC_CONTENT_SCALE_FACTOR() );
m_eAlignment = alignment;
m_pFontName.reset(new std::string(fontName));

if (m_pFontName)
{
delete m_pFontName;
m_pFontName = NULL;
}
m_pFontName = new std::string(fontName);

m_fFontSize = fontSize * CC_CONTENT_SCALE_FACTOR();
this->setString(label);
return true;
Expand All @@ -70,7 +99,14 @@ namespace cocos2d{
if (CCSprite::init())
{
m_tDimensions = CCSizeZero;
m_pFontName.reset(new std::string(fontName));

if (m_pFontName)
{
delete m_pFontName;
m_pFontName = NULL;
}
m_pFontName = new std::string(fontName);

m_fFontSize = fontSize * CC_CONTENT_SCALE_FACTOR();
this->setString(label);
return true;
Expand All @@ -79,7 +115,12 @@ namespace cocos2d{
}
void CCLabelTTF::setString(const char *label)
{
m_pString.reset(new std::string(label));
if (m_pString)
{
delete m_pString;
m_pString = NULL;
}
m_pString = new std::string(label);

CCTexture2D *texture;
if( CCSize::CCSizeEqualToSize( m_tDimensions, CCSizeZero ) )
Expand Down