From a9631bf9cd71bb4e7b6a67e71976a7c9eace8bd5 Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Sun, 8 Nov 2020 19:41:16 +0100 Subject: [PATCH] Fix text color change --- src/engine/client/text.cpp | 3 +++ src/engine/textrender.h | 8 ++++++++ src/game/client/ui.cpp | 5 ++++- src/game/client/ui.h | 3 +++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/engine/client/text.cpp b/src/engine/client/text.cpp index dc1517ae7..c1a0e9ddc 100644 --- a/src/engine/client/text.cpp +++ b/src/engine/client/text.cpp @@ -840,6 +840,9 @@ public: } virtual void TextOutlineColor(ColorRGBA rgb) { m_OutlineColor = rgb; }; + virtual ColorRGBA GetTextColor() { return m_Color; } + virtual ColorRGBA GetTextOutlineColor() { return m_OutlineColor; } + virtual void TextEx(CTextCursor *pCursor, const char *pText, int Length) { dbg_assert(pText != NULL, "null text pointer"); diff --git a/src/engine/textrender.h b/src/engine/textrender.h index da7760ebb..f2f01aa68 100644 --- a/src/engine/textrender.h +++ b/src/engine/textrender.h @@ -77,6 +77,11 @@ struct STextRenderColor m_A = a; } + bool operator!=(const STextRenderColor &Other) + { + return m_R != Other.m_R || m_G != Other.m_G || m_B != Other.m_B || m_A != Other.m_A; + } + float m_R, m_G, m_B, m_A; }; @@ -129,6 +134,9 @@ public: virtual float TextWidth(void *pFontSetV, float Size, const char *pText, int StrLength, float LineWidth, float *pAlignedHeight = NULL, float *pMaxCharacterHeightInLine = NULL) = 0; virtual int TextLineCount(void *pFontSetV, float Size, const char *pText, float LineWidth) = 0; + virtual ColorRGBA GetTextColor() = 0; + virtual ColorRGBA GetTextOutlineColor() = 0; + virtual void OnWindowResize() = 0; virtual float GetGlyphOffsetX(int FontSize, char TextCharacter) = 0; diff --git a/src/game/client/ui.cpp b/src/game/client/ui.cpp index 316b4de88..e2d0bb754 100644 --- a/src/game/client/ui.cpp +++ b/src/game/client/ui.cpp @@ -511,12 +511,15 @@ void CUI::DoLabel(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, cons RectEl.m_UITextContainer = TextRender()->CreateTextContainer(&Cursor, pText, StrLen); RectEl.m_Cursor = Cursor; + RectEl.m_TextColor = TextRender()->GetTextColor(); + RectEl.m_TextOutlineColor = TextRender()->GetTextOutlineColor(); } void CUI::DoLabelStreamed(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, int MaxWidth, int AlignVertically, bool StopAtEnd, int StrLen, CTextCursor *pReadCursor) { bool NeedsRecreate = false; - if(RectEl.m_UITextContainer == -1 || RectEl.m_X != pRect->x || RectEl.m_Y != pRect->y || RectEl.m_Width != pRect->w || RectEl.m_Height != pRect->h) + bool ColorChanged = RectEl.m_TextColor != TextRender()->GetTextColor() || RectEl.m_TextOutlineColor != TextRender()->GetTextOutlineColor(); + if(RectEl.m_UITextContainer == -1 || RectEl.m_X != pRect->x || RectEl.m_Y != pRect->y || RectEl.m_Width != pRect->w || RectEl.m_Height != pRect->h || ColorChanged) { NeedsRecreate = true; } diff --git a/src/game/client/ui.h b/src/game/client/ui.h index f98843d78..6ab98544f 100644 --- a/src/game/client/ui.h +++ b/src/game/client/ui.h @@ -126,6 +126,9 @@ public: CTextCursor m_Cursor; + STextRenderColor m_TextColor; + STextRenderColor m_TextOutlineColor; + SUIElementRect() : m_UIRectQuadContainer(-1), m_UITextContainer(-1), m_X(-1), m_Y(-1), m_Width(-1), m_Height(-1) {