From f8d498e4b25e44921dfee99656356b68336994f4 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Mon, 3 May 2021 13:10:42 +0300 Subject: [PATCH] Minor refactor --- nel/include/nel/gui/group_html.h | 4 +++ nel/src/gui/group_html.cpp | 50 ++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/nel/include/nel/gui/group_html.h b/nel/include/nel/gui/group_html.h index a16a16d82..351c232d2 100644 --- a/nel/include/nel/gui/group_html.h +++ b/nel/include/nel/gui/group_html.h @@ -36,6 +36,7 @@ typedef void CURLM; namespace NLGUI { + class CViewLink; class CCtrlButton; class CCtrlTextButton; class CCtrlScroll; @@ -301,6 +302,9 @@ namespace NLGUI // Translate a char bool translateChar(u32char &output, u32char input, u32char lastChar) const; + // return true if text has same style + bool isSameStyle(CViewLink *text, const CStyleParams &style) const; + // Add a string in the current paragraph void addString(const std::string &str); diff --git a/nel/src/gui/group_html.cpp b/nel/src/gui/group_html.cpp index 9939b4794..b649693cd 100644 --- a/nel/src/gui/group_html.cpp +++ b/nel/src/gui/group_html.cpp @@ -2359,6 +2359,34 @@ namespace NLGUI } } + // *************************************************************************** + bool CGroupHTML::isSameStyle(CViewLink *text, const CStyleParams &style) const + { + if (!text) return false; + + bool embolden = style.FontWeight >= FONT_WEIGHT_BOLD; + bool sameShadow = style.TextShadow.Enabled && text->getShadow(); + if (sameShadow && style.TextShadow.Enabled) + { + sint sx, sy; + text->getShadowOffset(sx, sy); + sameShadow = (style.TextShadow.Color == text->getShadowColor()); + sameShadow = sameShadow && (style.TextShadow.Outline == text->getShadowOutline()); + sameShadow = sameShadow && (style.TextShadow.X == sx) && (style.TextShadow.Y == sy); + } + // Compatible with current parameters ? + return sameShadow && + (style.TextColor == text->getColor()) && + (style.FontFamily == text->getFontName()) && + (style.FontSize == (uint)text->getFontSize()) && + (style.Underlined == text->getUnderlined()) && + (style.StrikeThrough == text->getStrikeThrough()) && + (embolden == text->getEmbolden()) && + (style.FontOblique == text->getOblique()) && + (getLink() == text->Link) && + (style.GlobalColor == text->getModulateGlobalColor()); + } + // *************************************************************************** void CGroupHTML::addString(const std::string &str) @@ -2433,32 +2461,12 @@ namespace NLGUI // Text added ? bool added = false; - bool embolden = style.FontWeight >= FONT_WEIGHT_BOLD; // Number of child in this paragraph if (_CurrentViewLink) { bool skipLine = !_CurrentViewLink->getText().empty() && *(_CurrentViewLink->getText().rbegin()) == '\n'; - bool sameShadow = style.TextShadow.Enabled && _CurrentViewLink->getShadow(); - if (sameShadow && style.TextShadow.Enabled) - { - sint sx, sy; - _CurrentViewLink->getShadowOffset(sx, sy); - sameShadow = (style.TextShadow.Color == _CurrentViewLink->getShadowColor()); - sameShadow = sameShadow && (style.TextShadow.Outline == _CurrentViewLink->getShadowOutline()); - sameShadow = sameShadow && (style.TextShadow.X == sx) && (style.TextShadow.Y == sy); - } - // Compatible with current parameters ? - if (!skipLine && sameShadow && - (style.TextColor == _CurrentViewLink->getColor()) && - (style.FontFamily == _CurrentViewLink->getFontName()) && - (style.FontSize == (uint)_CurrentViewLink->getFontSize()) && - (style.Underlined == _CurrentViewLink->getUnderlined()) && - (style.StrikeThrough == _CurrentViewLink->getStrikeThrough()) && - (embolden == _CurrentViewLink->getEmbolden()) && - (style.FontOblique == _CurrentViewLink->getOblique()) && - (getLink() == _CurrentViewLink->Link) && - (style.GlobalColor == _CurrentViewLink->getModulateGlobalColor())) + if (!skipLine && isSameStyle(_CurrentViewLink, style)) { // Concat the text _CurrentViewLink->setText(_CurrentViewLink->getText()+tmpStr);