1.fixed crash if create label by font name and text is empty.
2.fixed getter of font name and font size is incorrect.
This commit is contained in:
Dhilan007 2014-03-12 14:49:19 +08:00
parent cc3981ced7
commit 233b04269b
2 changed files with 31 additions and 3 deletions

View File

@ -273,6 +273,8 @@ Label::Label(FontAtlas *atlas, TextHAlignment alignment, bool useDistanceField,b
, _textSprite(nullptr)
, _contentDirty(false)
, _currentLabelType(LabelType::STRING_TEXTURE)
, _currLabelEffect(LabelEffect::NORMAL)
, _shadowBlurRadius(0)
{
_cascadeColorEnabled = true;
_batchNodes.push_back(this);
@ -938,7 +940,7 @@ void Label::updateContent()
void Label::visit(Renderer *renderer, const kmMat4 &parentTransform, bool parentTransformUpdated)
{
if (! _visible)
if (! _visible || _originalUTF8String.length() == 0)
{
return;
}
@ -999,6 +1001,19 @@ void Label::setFontName(const std::string& fontName)
}
}
const std::string& Label::getFontName() const
{
switch (_currentLabelType)
{
case cocos2d::Label::LabelType::TTF:
return _fontConfig.fontFilePath;
case cocos2d::Label::LabelType::STRING_TEXTURE:
return _fontDefinition._fontName;
default:
return _fontDefinition._fontName;
}
}
void Label::setFontSize(int fontSize)
{
if (_currentLabelType == LabelType::TTF)
@ -1027,6 +1042,19 @@ void Label::setFontSize(int fontSize)
}
}
int Label::getFontSize() const
{
switch (_currentLabelType)
{
case cocos2d::Label::LabelType::TTF:
return _fontConfig.fontSize;
case cocos2d::Label::LabelType::STRING_TEXTURE:
return _fontDefinition._fontSize;
default:
return 0;
}
}
///// PROTOCOL STUFF
Sprite * Label::getLetter(int lettetIndex)
{

View File

@ -197,10 +197,10 @@ public:
virtual void updateContent();
virtual void setFontName(const std::string& fontName);
virtual const std::string& getFontName() const { return _fontDefinition._fontName;}
virtual const std::string& getFontName() const;
virtual void setFontSize(int fontSize);
virtual int getFontSize() const { return _fontDefinition._fontSize;}
virtual int getFontSize() const;
virtual bool isOpacityModifyRGB() const override;
virtual void setOpacityModifyRGB(bool isOpacityModifyRGB) override;