Finish implementing property "textcolor_selected" for list GUI objects

Fixes #6920
Patch by: @Vantha
Differential Revision: https://code.wildfiregames.com/D5269
This was SVN commit r28135.
This commit is contained in:
Stan 2024-07-03 08:32:52 +00:00
parent 4bcbc72274
commit a4d9993e86
4 changed files with 19 additions and 4 deletions

View File

@ -591,6 +591,11 @@
<ref name="ccolor"/>
</attribute>
</optional>
<optional>
<attribute name="textcolor_selected">
<ref name="ccolor"/>
</attribute>
</optional>
<optional>
<attribute name="heading"/>
</optional>

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2021 Wildfire Games.
/* Copyright (C) 2024 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -368,7 +368,9 @@ void CList::DrawList(CCanvas2D& canvas, const int& selected, const CGUISpriteIns
cliparea.left = GetScrollBar(0).GetOuterRect().right;
}
DrawText(canvas, i, textColor, rect.TopLeft() - CVector2D(0.f, scroll - m_ItemsYPositions[i]), cliparea);
const CGUIColor& finalTextColor = (drawSelected && static_cast<size_t>(selected) == i && *m_TextColorSelected) ? m_TextColorSelected : textColor;
DrawText(canvas, i, finalTextColor, rect.TopLeft() - CVector2D(0.f, scroll - m_ItemsYPositions[i]), cliparea);
}
// Draw scrollbars on top of the content

View File

@ -219,6 +219,11 @@ bool COList::HandleAdditionalChildren(const XMBData& xmb, const XMBElement& chil
if (!CGUI::ParseString<CGUIColor>(&m_pGUI, attr_value.FromUTF8(), column.m_TextColor))
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name.data(), attr_value.c_str());
}
else if (attr_name == "textcolor_selected")
{
if (!CGUI::ParseString<CGUIColor>(&m_pGUI, attr_value.FromUTF8(), column.m_TextColorSelected))
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name.data(), attr_value.c_str());
}
else if (attr_name == "hidden")
{
bool hidden = false;
@ -435,8 +440,10 @@ void COList::DrawList(CCanvas2D& canvas, const int& selected, const CGUISpriteIn
cliparea2.right = std::min(cliparea2.right, textPos.X + width);
cliparea2.bottom = std::min(cliparea2.bottom, textPos.Y + rowHeight);
const CGUIColor& finalTextColor = (drawSelected && static_cast<size_t>(selected) == i && column.m_TextColorSelected) ? column.m_TextColorSelected : column.m_TextColor;
// Draw list item
DrawText(canvas, objectsCount * (i +/*Heading*/1) + colIdx, column.m_TextColor, textPos, cliparea2);
DrawText(canvas, objectsCount * (i +/*Heading*/1) + colIdx, finalTextColor, textPos, cliparea2);
xpos += width;
}
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2023 Wildfire Games.
/* Copyright (C) 2024 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -38,6 +38,7 @@ public:
COListColumn& operator=(COListColumn&&) = delete;
CGUIColor m_TextColor;
CGUIColor m_TextColorSelected;
CStr m_Id;
float m_Width;
CGUISimpleSetting<CStrW> m_Heading; // CGUIString??