From 60d273e31b471b790957bc3349c1f0324f2b4783 Mon Sep 17 00:00:00 2001 From: Ricardo Quesada Date: Wed, 20 Jan 2016 18:41:59 -0800 Subject: [PATCH] underline and strikethrough working ok on system fonts --- cocos/2d/CCLabel.cpp | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index 533fe174b8..cb509bd56c 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -1382,19 +1382,36 @@ void Label::updateContent() if (_underlineNode) { - const float charheight = (_textDesiredHeight / _numberOfLines); - _underlineNode->clear(); - _underlineNode->setLineWidth(charheight/6); - for (int i=0; i<_numberOfLines; ++i) + if (_numberOfLines) { - float offsety = 0; + const float charheight = (_textDesiredHeight / _numberOfLines); + _underlineNode->setLineWidth(charheight/6); + + // atlas font + for (int i=0; i<_numberOfLines; ++i) + { + float offsety = 0; + if (_strikethroughEnabled) + offsety += charheight / 2; + // FIXME: Might not work with different vertical alignments + float y = (_numberOfLines - i - 1) * charheight + offsety; + _underlineNode->drawLine(Vec2(_linesOffsetX[i],y), Vec2(_linesWidth[i] + _linesOffsetX[i],y), _textColorF); + } + } + else if (_textSprite) + { + // system font + float y = 0; + const auto spriteSize = _textSprite->getContentSize(); + _underlineNode->setLineWidth(spriteSize.height/6); + if (_strikethroughEnabled) - offsety += charheight / 2; + // FIXME: system fonts don't report the height of the font correctly. only the size of the texture, which is POT + y += spriteSize.height / 2; // FIXME: Might not work with different vertical alignments - float y = (_numberOfLines - i - 1) * charheight + offsety; - _underlineNode->drawLine(Vec2(_linesOffsetX[i],y), Vec2(_linesWidth[i] + _linesOffsetX[i],y), _textColorF); + _underlineNode->drawLine(Vec2(0,y), Vec2(spriteSize.width,y), Color4F(_textSprite->getDisplayedColor())); } } @@ -1857,6 +1874,9 @@ void Label::updateDisplayedColor(const Color3B& parentColor) { _shadowNode->updateDisplayedColor(_displayedColor); } + + if (_underlineNode) + _contentDirty = true; } for (auto&& it : _letters)