Minor refactor

feature/develop-atys
Nimetu 4 years ago
parent cd4914ab94
commit f8d498e4b2

@ -36,6 +36,7 @@ typedef void CURLM;
namespace NLGUI namespace NLGUI
{ {
class CViewLink;
class CCtrlButton; class CCtrlButton;
class CCtrlTextButton; class CCtrlTextButton;
class CCtrlScroll; class CCtrlScroll;
@ -301,6 +302,9 @@ namespace NLGUI
// Translate a char // Translate a char
bool translateChar(u32char &output, u32char input, u32char lastChar) const; 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 // Add a string in the current paragraph
void addString(const std::string &str); void addString(const std::string &str);

@ -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) void CGroupHTML::addString(const std::string &str)
@ -2433,32 +2461,12 @@ namespace NLGUI
// Text added ? // Text added ?
bool added = false; bool added = false;
bool embolden = style.FontWeight >= FONT_WEIGHT_BOLD;
// Number of child in this paragraph // Number of child in this paragraph
if (_CurrentViewLink) if (_CurrentViewLink)
{ {
bool skipLine = !_CurrentViewLink->getText().empty() && *(_CurrentViewLink->getText().rbegin()) == '\n'; bool skipLine = !_CurrentViewLink->getText().empty() && *(_CurrentViewLink->getText().rbegin()) == '\n';
bool sameShadow = style.TextShadow.Enabled && _CurrentViewLink->getShadow(); if (!skipLine && isSameStyle(_CurrentViewLink, style))
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()))
{ {
// Concat the text // Concat the text
_CurrentViewLink->setText(_CurrentViewLink->getText()+tmpStr); _CurrentViewLink->setText(_CurrentViewLink->getText()+tmpStr);

Loading…
Cancel
Save