Skip to content

Commit

Permalink
Implement gradient color customization
Browse files Browse the repository at this point in the history
  • Loading branch information
St4lker0k765 committed Mar 8, 2025
1 parent 8e6f305 commit 711f6d9
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/Layers/xrRender/dxFontRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,8 @@ void dxFontRender::OnRender(CGameFont& owner) {

u32 clr, clr2;
clr2 = clr = str.c;
if(str.gradient) {
u32 _R = color_get_R(clr) / 2;
u32 _G = color_get_G(clr) / 2;
u32 _B = color_get_B(clr) / 2;
u32 _A = color_get_A(clr);
clr2 = color_rgba(_R, _G, _B, _A);
if(str.gradient) {;
clr2 = str.gradientColor;
}

X -= 0.5f;
Expand Down
1 change: 1 addition & 0 deletions src/xrEngine/GameFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ void CGameFont::MasterOut(
rs.x = (bUseCoords ? (bScaleCoords ? (DI2PX(_x)) : _x) : fCurrentX);
rs.y = (bUseCoords ? (bScaleCoords ? (DI2PY(_y)) : _y) : fCurrentY);
rs.c = dwCurrentColor;
rs.gradientColor = dwGradientColor;
rs.height = fCurrentHeight;
rs.align = eCurrentAlignment;
rs.gradient = fGradientEnabled;
Expand Down
3 changes: 3 additions & 0 deletions src/xrEngine/GameFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ENGINE_API CGameFont
EAligment align;
bool gradient;
EGradientMode gradientMode;
u32 gradientColor;
};

struct BaseData
Expand All @@ -63,6 +64,7 @@ class ENGINE_API CGameFont

u32 uFlags;
u32 dwCurrentColor;
u32 dwGradientColor;

EAligment eCurrentAlignment;
xr_vector<String> strings;
Expand All @@ -87,6 +89,7 @@ class ENGINE_API CGameFont

void ReInit();
inline void SetColor(u32 C) { dwCurrentColor = C; };
inline void SetGradientColor(u32 C) { dwGradientColor = C; };

//inline void SetHeightI(float S);
inline void SetHeight(float S);
Expand Down
20 changes: 20 additions & 0 deletions src/xrUI/UIXmlInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,14 @@ bool CUIXmlInit::InitText(CUIXml& xml_doc, LPCSTR path, int index, CUILines* pLi
else if (_stricmp(mode_str, "down") == 0) { mode = CGameFont::gm_down; }
pLines->SetTextGradientMode(mode);

u32 color2;
u32 _R = color_get_R(color) / 2;
u32 _G = color_get_G(color) / 2;
u32 _B = color_get_B(color) / 2;
u32 _A = color_get_A(color);
color2 = GetGradientColor(xml_doc, path, index, color_rgba(_R, _G, _B, _A));
pLines->SetTextGradientColor(color2);

shared_str text = xml_doc.Read(path, index, nullptr);
if (text.size())
pLines->SetText(g_pStringTable->translate(text).c_str());
Expand Down Expand Up @@ -1320,6 +1328,18 @@ u32 CUIXmlInit::GetColor(CUIXml& xml_doc, LPCSTR path, int index, u32 def_clr)

}

u32 CUIXmlInit::GetGradientColor(CUIXml& xml_doc, LPCSTR path, int index, u32 def_clr)
{
LPCSTR clr_def = xml_doc.ReadAttrib(path, index, "gradient_color", nullptr);
if (clr_def) {
VERIFY(GetColorDefs()->find(clr_def) != GetColorDefs()->end());
return (*m_pColorDefs)[clr_def];
}
else {
return def_clr;
}
}

bool CUIXmlInit::InitHintWindow(CUIXml& xml_doc, LPCSTR path, int index, UIHintWindow* pWnd)
{
VERIFY( pWnd );
Expand Down
1 change: 1 addition & 0 deletions src/xrUI/UIXmlInit.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class UI_API CUIXmlInit
static bool InitHintWindow (CUIXml& xml_doc, LPCSTR path, int index, UIHintWindow* pWnd);
static Frect GetFRect (CUIXml& xml_doc, LPCSTR path, int index);
static u32 GetColor (CUIXml& xml_doc, LPCSTR path, int index, u32 def_clr);
static u32 GetGradientColor (CUIXml& xml_doc, LPCSTR path, int index, u32 def_clr);
public:

static bool InitAlignment(CUIXml &xml_doc, const char *path,
Expand Down
10 changes: 10 additions & 0 deletions src/xrUI/Widgets/UILines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ CUILines::CUILines()
m_eTextAlign = CGameFont::alLeft;
m_eVTextAlign = valTop;
m_dwTextColor = 0xffffffff;
m_dwTextGradientColor = 0xff888888;
m_TextOffset.set (0.0f,0.0f);
m_text ="";
uFlags.zero();
Expand Down Expand Up @@ -321,6 +322,14 @@ void CUILines::SetTextColor(u32 color)
m_dwTextColor = color;
}

void CUILines::SetTextGradientColor(u32 color)
{
if (color == m_dwTextGradientColor)
return;
uFlags.set(flNeedReparse, true);
m_dwTextGradientColor = color;
}

void CUILines::SetFont(CGameFont* pFont)
{
if (pFont == m_pFont)
Expand Down Expand Up @@ -384,6 +393,7 @@ void CUILines::Draw(float x, float y)

R_ASSERT(m_pFont);
m_pFont->SetColor(m_dwTextColor);
m_pFont->SetGradientColor(m_dwTextGradientColor);

if (!uFlags.is(flComplexMode))
{
Expand Down
3 changes: 3 additions & 0 deletions src/xrUI/Widgets/UILines.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class UI_API CUILines :
//--
void SetTextColor(u32 color);
u32 GetTextColor() {return m_dwTextColor;}
void SetTextGradientColor(u32 color);
u32 GetTextGradientColor() {return m_dwTextGradientColor;}
void SetFont(CGameFont* pFont);
void SetTextGradient(bool val);
CGameFont* GetFont() {return m_pFont;}
Expand Down Expand Up @@ -70,6 +72,7 @@ CGameFont::EGradientMode GetTextGradientMode() {return m_eTextGradientMode;
ETextAlignment m_eTextAlign;
EVTextAlignment m_eVTextAlign;
u32 m_dwTextColor;
u32 m_dwTextGradientColor;

CGameFont* m_pFont;

Expand Down

0 comments on commit 711f6d9

Please sign in to comment.