3280: Fix text color change r=def- a=Jupeyy

fixes #3278

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Jupeyy <jupjopjap@gmail.com>
This commit is contained in:
bors[bot] 2020-11-08 22:08:20 +00:00 committed by GitHub
commit e828e36c5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 1 deletions

View file

@ -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");

View file

@ -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;

View file

@ -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;
}

View file

@ -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)
{