Changeset View
Changeset View
Standalone View
Standalone View
source/gui/COList.cpp
Show All 24 Lines | |||||
#include "gui/IGUIScrollBar.h" | #include "gui/IGUIScrollBar.h" | ||||
#include "i18n/L10n.h" | #include "i18n/L10n.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
const float SORT_SPRITE_DIM = 16.0f; | const float SORT_SPRITE_DIM = 16.0f; | ||||
const CPos COLUMN_SHIFT = CPos(0, 4); | const CPos COLUMN_SHIFT = CPos(0, 4); | ||||
COList::COList(CGUI& pGUI) | COList::COList(CGUI& pGUI) | ||||
: CList(pGUI), IGUIObject(pGUI) | : CList(pGUI), | ||||
{ | IGUIObject(pGUI), | ||||
AddSetting<CGUISpriteInstance>("sprite_heading"); | m_SpriteHeading(), | ||||
AddSetting<bool>("sortable"); // The actual sorting is done in JS for more versatility | m_Sortable(), | ||||
AddSetting<CStr>("selected_column"); | m_SelectedColumn(), | ||||
AddSetting<i32>("selected_column_order"); | m_SelectedColumnOrder(), | ||||
AddSetting<CGUISpriteInstance>("sprite_asc"); // Show the order of sorting | m_SpriteAsc(), | ||||
AddSetting<CGUISpriteInstance>("sprite_desc"); | m_SpriteDesc(), | ||||
AddSetting<CGUISpriteInstance>("sprite_not_sorted"); | m_SpriteNotSorted() | ||||
{ | |||||
RegisterSetting("sprite_heading", m_SpriteHeading); | |||||
RegisterSetting("sortable", m_Sortable); // The actual sorting is done in JS for more versatility | |||||
RegisterSetting("selected_column", m_SelectedColumn); | |||||
RegisterSetting("selected_column_order", m_SelectedColumnOrder); | |||||
RegisterSetting("sprite_asc", m_SpriteAsc); // Show the order of sorting | |||||
RegisterSetting("sprite_desc", m_SpriteDesc); | |||||
RegisterSetting("sprite_not_sorted", m_SpriteNotSorted); | |||||
} | } | ||||
void COList::SetupText() | void COList::SetupText() | ||||
{ | { | ||||
const CGUIList& pList = GetSetting<CGUIList>("list"); | m_ItemsYPositions.resize(m_List.m_Items.size() + 1); | ||||
m_ItemsYPositions.resize(pList.m_Items.size() + 1); | |||||
// Delete all generated texts. Some could probably be saved, | // Delete all generated texts. Some could probably be saved, | ||||
// but this is easier, and this function will never be called | // but this is easier, and this function will never be called | ||||
// continuously, or even often, so it'll probably be okay. | // continuously, or even often, so it'll probably be okay. | ||||
m_GeneratedTexts.clear(); | m_GeneratedTexts.clear(); | ||||
const CStrW& font = GetSetting<CStrW>("font"); | |||||
const bool scrollbar = GetSetting<bool>("scrollbar"); | |||||
m_TotalAvailableColumnWidth = GetListRect().GetWidth(); | m_TotalAvailableColumnWidth = GetListRect().GetWidth(); | ||||
// remove scrollbar if applicable | // remove scrollbar if applicable | ||||
if (scrollbar && GetScrollBar(0).GetStyle()) | if (m_ScrollBar && GetScrollBar(0).GetStyle()) | ||||
m_TotalAvailableColumnWidth -= GetScrollBar(0).GetStyle()->m_Width; | m_TotalAvailableColumnWidth -= GetScrollBar(0).GetStyle()->m_Width; | ||||
const float buffer_zone = GetSetting<float>("buffer_zone"); | |||||
m_HeadingHeight = SORT_SPRITE_DIM; // At least the size of the sorting sprite | m_HeadingHeight = SORT_SPRITE_DIM; // At least the size of the sorting sprite | ||||
for (const COListColumn& column : m_Columns) | for (const COListColumn& column : m_Columns) | ||||
{ | { | ||||
float width = column.m_Width; | float width = column.m_Width; | ||||
if (column.m_Width > 0 && column.m_Width < 1) | if (column.m_Width > 0 && column.m_Width < 1) | ||||
width *= m_TotalAvailableColumnWidth; | width *= m_TotalAvailableColumnWidth; | ||||
CGUIString gui_string; | CGUIString gui_string; | ||||
gui_string.SetValue(column.m_Heading); | gui_string.SetValue(column.m_Heading); | ||||
const CGUIText& text = AddText(gui_string, font, width, buffer_zone, this); | const CGUIText& text = AddText(gui_string, m_Font, width, m_BufferZone, this); | ||||
m_HeadingHeight = std::max(m_HeadingHeight, text.GetSize().cy + COLUMN_SHIFT.y); | m_HeadingHeight = std::max(m_HeadingHeight, text.GetSize().cy + COLUMN_SHIFT.y); | ||||
} | } | ||||
// Generate texts | // Generate texts | ||||
float buffered_y = 0.f; | float buffered_y = 0.f; | ||||
for (size_t i = 0; i < pList.m_Items.size(); ++i) | for (size_t i = 0; i < m_List.m_Items.size(); ++i) | ||||
{ | { | ||||
m_ItemsYPositions[i] = buffered_y; | m_ItemsYPositions[i] = buffered_y; | ||||
float shift = 0.0f; | float shift = 0.0f; | ||||
for (const COListColumn& column : m_Columns) | for (const COListColumn& column : m_Columns) | ||||
{ | { | ||||
float width = column.m_Width; | float width = column.m_Width; | ||||
if (column.m_Width > 0 && column.m_Width < 1) | if (column.m_Width > 0 && column.m_Width < 1) | ||||
width *= m_TotalAvailableColumnWidth; | width *= m_TotalAvailableColumnWidth; | ||||
CGUIList& pList_c = GetSetting<CGUIList>("list_" + column.m_Id); | |||||
CGUIText* text; | CGUIText* text; | ||||
if (!pList_c.m_Items[i].GetOriginalString().empty()) | if (!column.m_List.m_Items[i].GetOriginalString().empty()) | ||||
text = &AddText(pList_c.m_Items[i], font, width, buffer_zone, this); | text = &AddText(column.m_List.m_Items[i], m_Font, width, m_BufferZone, this); | ||||
else | else | ||||
{ | { | ||||
// Minimum height of a space character of the current font size | // Minimum height of a space character of the current font size | ||||
CGUIString align_string; | CGUIString align_string; | ||||
align_string.SetValue(L" "); | align_string.SetValue(L" "); | ||||
text = &AddText(align_string, font, width, buffer_zone, this); | text = &AddText(align_string, m_Font, width, m_BufferZone, this); | ||||
} | } | ||||
shift = std::max(shift, text->GetSize().cy); | shift = std::max(shift, text->GetSize().cy); | ||||
} | } | ||||
buffered_y += shift; | buffered_y += shift; | ||||
} | } | ||||
m_ItemsYPositions[pList.m_Items.size()] = buffered_y; | m_ItemsYPositions[m_List.m_Items.size()] = buffered_y; | ||||
if (scrollbar) | if (m_ScrollBar) | ||||
{ | { | ||||
CRect rect = GetListRect(); | CRect rect = GetListRect(); | ||||
GetScrollBar(0).SetScrollRange(m_ItemsYPositions.back()); | GetScrollBar(0).SetScrollRange(m_ItemsYPositions.back()); | ||||
GetScrollBar(0).SetScrollSpace(rect.GetHeight()); | GetScrollBar(0).SetScrollSpace(rect.GetHeight()); | ||||
GetScrollBar(0).SetX(rect.right); | GetScrollBar(0).SetX(rect.right); | ||||
GetScrollBar(0).SetY(rect.top); | GetScrollBar(0).SetY(rect.top); | ||||
GetScrollBar(0).SetZ(GetBufferedZ()); | GetScrollBar(0).SetZ(GetBufferedZ()); | ||||
Show All 10 Lines | |||||
{ | { | ||||
CList::HandleMessage(Message); | CList::HandleMessage(Message); | ||||
switch (Message.type) | switch (Message.type) | ||||
{ | { | ||||
// If somebody clicks on the column heading | // If somebody clicks on the column heading | ||||
case GUIM_MOUSE_PRESS_LEFT: | case GUIM_MOUSE_PRESS_LEFT: | ||||
{ | { | ||||
if (!GetSetting<bool>("sortable")) | if (!m_Sortable) | ||||
return; | return; | ||||
const CPos& mouse = m_pGUI.GetMousePos(); | const CPos& mouse = m_pGUI.GetMousePos(); | ||||
if (!m_CachedActualSize.PointInside(mouse)) | if (!m_CachedActualSize.PointInside(mouse)) | ||||
return; | return; | ||||
// Copies, so that these settings are only modfied via SetSettings later. | |||||
CStr selectedColumn = GetSetting<CStr>("selected_column"); | |||||
int selectedColumnOrder = GetSetting<i32>("selected_column_order"); | |||||
float xpos = 0; | float xpos = 0; | ||||
for (const COListColumn& column : m_Columns) | for (const COListColumn& column : m_Columns) | ||||
{ | { | ||||
if (GetSetting<bool>("hidden_" + column.m_Id)) | if (column.m_Hidden) | ||||
continue; | continue; | ||||
float width = column.m_Width; | float width = column.m_Width; | ||||
// Check if it's a decimal value, and if so, assume relative positioning. | // Check if it's a decimal value, and if so, assume relative positioning. | ||||
if (column.m_Width < 1 && column.m_Width > 0) | if (column.m_Width < 1 && column.m_Width > 0) | ||||
width *= m_TotalAvailableColumnWidth; | width *= m_TotalAvailableColumnWidth; | ||||
CPos leftTopCorner = m_CachedActualSize.TopLeft() + CPos(xpos, 0); | CPos leftTopCorner = m_CachedActualSize.TopLeft() + CPos(xpos, 0); | ||||
if (mouse.x >= leftTopCorner.x && | if (mouse.x >= leftTopCorner.x && | ||||
mouse.x < leftTopCorner.x + width && | mouse.x < leftTopCorner.x + width && | ||||
mouse.y < leftTopCorner.y + m_HeadingHeight) | mouse.y < leftTopCorner.y + m_HeadingHeight) | ||||
{ | { | ||||
if (column.m_Id != selectedColumn) | if (column.m_Id != m_SelectedColumn) | ||||
{ | { | ||||
selectedColumnOrder = 1; | SetSetting<i32>("selected_column_order", -1, true); | ||||
selectedColumn = column.m_Id; | CStr cstr = column.m_Id; | ||||
SetSetting<CStr>("selected_column", cstr, true); | |||||
} | } | ||||
else | else | ||||
selectedColumnOrder = -selectedColumnOrder; | SetSetting<i32>("selected_column_order", -m_SelectedColumnOrder, true); | ||||
SetSetting<CStr>("selected_column", selectedColumn, true); | |||||
SetSetting<i32>("selected_column_order", selectedColumnOrder, true); | |||||
ScriptEvent("selectioncolumnchange"); | ScriptEvent("selectioncolumnchange"); | ||||
PlaySound("sound_selected"); | PlaySound(m_SoundSelected); | ||||
return; | return; | ||||
} | } | ||||
xpos += width; | xpos += width; | ||||
} | } | ||||
return; | return; | ||||
} | } | ||||
default: | default: | ||||
return; | return; | ||||
Show All 13 Lines | bool COList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile) | ||||
if (child.GetNodeName() == elmt_item) | if (child.GetNodeName() == elmt_item) | ||||
{ | { | ||||
AddItem(child.GetText().FromUTF8(), child.GetText().FromUTF8()); | AddItem(child.GetText().FromUTF8(), child.GetText().FromUTF8()); | ||||
return true; | return true; | ||||
} | } | ||||
else if (child.GetNodeName() == elmt_column) | else if (child.GetNodeName() == elmt_column) | ||||
{ | { | ||||
COListColumn column; | COListColumn column; | ||||
bool hidden = false; | |||||
for (XMBAttribute attr : child.GetAttributes()) | for (XMBAttribute attr : child.GetAttributes()) | ||||
{ | { | ||||
CStr attr_name(pFile->GetAttributeString(attr.Name)); | CStr attr_name(pFile->GetAttributeString(attr.Name)); | ||||
CStr attr_value(attr.Value); | CStr attr_value(attr.Value); | ||||
if (attr_name == "color") | if (attr_name == "color") | ||||
{ | { | ||||
if (!CGUI::ParseString<CGUIColor>(&m_pGUI, attr_value.FromUTF8(), column.m_TextColor)) | if (!CGUI::ParseString<CGUIColor>(&m_pGUI, attr_value.FromUTF8(), column.m_TextColor)) | ||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str()); | LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str()); | ||||
} | } | ||||
else if (attr_name == "id") | else if (attr_name == "id") | ||||
{ | { | ||||
column.m_Id = attr_value; | column.m_Id = attr_value; | ||||
} | } | ||||
else if (attr_name == "hidden") | else if (attr_name == "hidden") | ||||
{ | { | ||||
bool hidden = false; | |||||
if (!CGUI::ParseString<bool>(&m_pGUI, attr_value.FromUTF8(), hidden)) | if (!CGUI::ParseString<bool>(&m_pGUI, attr_value.FromUTF8(), hidden)) | ||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str()); | LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str()); | ||||
else | |||||
column.m_Hidden = hidden; | |||||
} | } | ||||
else if (attr_name == "width") | else if (attr_name == "width") | ||||
{ | { | ||||
float width; | float width; | ||||
if (!CGUI::ParseString<float>(&m_pGUI, attr_value.FromUTF8(), width)) | if (!CGUI::ParseString<float>(&m_pGUI, attr_value.FromUTF8(), width)) | ||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str()); | LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str()); | ||||
else | else | ||||
{ | { | ||||
Show All 34 Lines | for (XMBElement grandchild : child.GetChildNodes()) | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
CStr translatedValue(g_L10n.Translate(value)); | CStr translatedValue(g_L10n.Translate(value)); | ||||
column.m_Heading = translatedValue.FromUTF8(); | column.m_Heading = translatedValue.FromUTF8(); | ||||
} | } | ||||
} | } | ||||
AddSetting<CGUIList>("list_" + column.m_Id); | |||||
AddSetting<bool>("hidden_" + column.m_Id); | |||||
SetSetting<bool>("hidden_" + column.m_Id, hidden, true); | |||||
m_Columns.emplace_back(std::move(column)); | m_Columns.emplace_back(std::move(column)); | ||||
SetupText(); | |||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor) | void COList::AdditionalChildrenHandled() | ||||
{ | |||||
SetupText(); | |||||
// Do this after the last push_back call to avoid iterator invalidation | |||||
for (COListColumn& column : m_Columns) | |||||
{ | |||||
RegisterSetting("list_" + column.m_Id, column.m_List); | |||||
RegisterSetting("hidden_" + column.m_Id, column.m_Hidden); | |||||
} | |||||
} | |||||
void COList::DrawList(const int& selected, const CGUISpriteInstance& sprite, const CGUISpriteInstance& sprite_selected, const CGUIColor& textcolor) | |||||
{ | { | ||||
const float bz = GetBufferedZ(); | const float bz = GetBufferedZ(); | ||||
const bool scrollbar = GetSetting<bool>("scrollbar"); | |||||
if (scrollbar) | if (m_ScrollBar) | ||||
IGUIScrollBarOwner::Draw(); | IGUIScrollBarOwner::Draw(); | ||||
CRect rect = GetListRect(); | CRect rect = GetListRect(); | ||||
CGUISpriteInstance& sprite = GetSetting<CGUISpriteInstance>(_sprite); | m_pGUI.DrawSprite(sprite, m_CellID, bz, rect); | ||||
CGUISpriteInstance& sprite_selectarea = GetSetting<CGUISpriteInstance>(_sprite_selected); | |||||
const int cell_id = GetSetting<i32>("cell_id"); | |||||
m_pGUI.DrawSprite(sprite, cell_id, bz, rect); | |||||
float scroll = 0.f; | float scroll = 0.f; | ||||
if (scrollbar) | if (m_ScrollBar) | ||||
scroll = GetScrollBar(0).GetPos(); | scroll = GetScrollBar(0).GetPos(); | ||||
// Draw item selection | // Draw item selection | ||||
if (selected != -1) | if (selected != -1) | ||||
{ | { | ||||
ENSURE(selected >= 0 && selected+1 < (int)m_ItemsYPositions.size()); | ENSURE(selected >= 0 && selected+1 < (int)m_ItemsYPositions.size()); | ||||
// Get rectangle of selection: | // Get rectangle of selection: | ||||
CRect rect_sel(rect.left, rect.top + m_ItemsYPositions[selected] - scroll, | CRect rect_sel(rect.left, rect.top + m_ItemsYPositions[selected] - scroll, | ||||
rect.right, rect.top + m_ItemsYPositions[selected+1] - scroll); | rect.right, rect.top + m_ItemsYPositions[selected+1] - scroll); | ||||
if (rect_sel.top <= rect.bottom && | if (rect_sel.top <= rect.bottom && | ||||
rect_sel.bottom >= rect.top) | rect_sel.bottom >= rect.top) | ||||
{ | { | ||||
if (rect_sel.bottom > rect.bottom) | if (rect_sel.bottom > rect.bottom) | ||||
rect_sel.bottom = rect.bottom; | rect_sel.bottom = rect.bottom; | ||||
if (rect_sel.top < rect.top) | if (rect_sel.top < rect.top) | ||||
rect_sel.top = rect.top; | rect_sel.top = rect.top; | ||||
if (scrollbar) | if (m_ScrollBar) | ||||
{ | { | ||||
// Remove any overlapping area of the scrollbar. | // Remove any overlapping area of the scrollbar. | ||||
if (rect_sel.right > GetScrollBar(0).GetOuterRect().left && | if (rect_sel.right > GetScrollBar(0).GetOuterRect().left && | ||||
rect_sel.right <= GetScrollBar(0).GetOuterRect().right) | rect_sel.right <= GetScrollBar(0).GetOuterRect().right) | ||||
rect_sel.right = GetScrollBar(0).GetOuterRect().left; | rect_sel.right = GetScrollBar(0).GetOuterRect().left; | ||||
if (rect_sel.left >= GetScrollBar(0).GetOuterRect().left && | if (rect_sel.left >= GetScrollBar(0).GetOuterRect().left && | ||||
rect_sel.left < GetScrollBar(0).GetOuterRect().right) | rect_sel.left < GetScrollBar(0).GetOuterRect().right) | ||||
rect_sel.left = GetScrollBar(0).GetOuterRect().right; | rect_sel.left = GetScrollBar(0).GetOuterRect().right; | ||||
} | } | ||||
// Draw item selection | // Draw item selection | ||||
m_pGUI.DrawSprite(sprite_selectarea, cell_id, bz+0.05f, rect_sel); | m_pGUI.DrawSprite(sprite_selected, m_CellID, bz + 0.05f, rect_sel); | ||||
} | } | ||||
} | } | ||||
// Draw line above column header | // Draw line above column header | ||||
CGUISpriteInstance& sprite_heading = GetSetting<CGUISpriteInstance>("sprite_heading"); | |||||
CRect rect_head(m_CachedActualSize.left, m_CachedActualSize.top, m_CachedActualSize.right, | CRect rect_head(m_CachedActualSize.left, m_CachedActualSize.top, m_CachedActualSize.right, | ||||
m_CachedActualSize.top + m_HeadingHeight); | m_CachedActualSize.top + m_HeadingHeight); | ||||
m_pGUI.DrawSprite(sprite_heading, cell_id, bz, rect_head); | m_pGUI.DrawSprite(m_SpriteHeading, m_CellID, bz, rect_head); | ||||
// Draw column headers | // Draw column headers | ||||
const bool sortable = GetSetting<bool>("sortable"); | |||||
const CStr& selectedColumn = GetSetting<CStr>("selected_column"); | |||||
const int selectedColumnOrder = GetSetting<i32>("selected_column_order"); | |||||
const CGUIColor& color = GetSetting<CGUIColor>(_textcolor); | |||||
float xpos = 0; | float xpos = 0; | ||||
for (size_t col = 0; col < m_Columns.size(); ++col) | size_t col = 0; | ||||
for (const COListColumn& column : m_Columns) | |||||
{ | |||||
if (column.m_Hidden) | |||||
{ | { | ||||
if (GetSetting<bool>("hidden_" + m_Columns[col].m_Id)) | ++col; | ||||
continue; | continue; | ||||
} | |||||
// Check if it's a decimal value, and if so, assume relative positioning. | // Check if it's a decimal value, and if so, assume relative positioning. | ||||
float width = m_Columns[col].m_Width; | float width = column.m_Width; | ||||
if (m_Columns[col].m_Width < 1 && m_Columns[col].m_Width > 0) | if (column.m_Width < 1 && column.m_Width > 0) | ||||
width *= m_TotalAvailableColumnWidth; | width *= m_TotalAvailableColumnWidth; | ||||
CPos leftTopCorner = m_CachedActualSize.TopLeft() + CPos(xpos, 0); | CPos leftTopCorner = m_CachedActualSize.TopLeft() + CPos(xpos, 0); | ||||
// Draw sort arrows in colum header | // Draw sort arrows in colum header | ||||
if (sortable) | if (m_Sortable) | ||||
{ | { | ||||
CStr spriteName; | const CGUISpriteInstance* sprite; | ||||
if (selectedColumn == m_Columns[col].m_Id) | if (m_SelectedColumn == column.m_Id) | ||||
{ | { | ||||
if (selectedColumnOrder == 0) | if (m_SelectedColumnOrder == 0) | ||||
LOGERROR("selected_column_order must not be 0"); | LOGERROR("selected_column_order must not be 0"); | ||||
if (selectedColumnOrder != -1) | if (m_SelectedColumnOrder != -1) | ||||
spriteName = "sprite_asc"; | sprite = &m_SpriteAsc; | ||||
else | else | ||||
spriteName = "sprite_desc"; | sprite = &m_SpriteDesc; | ||||
} | } | ||||
else | else | ||||
spriteName = "sprite_not_sorted"; | sprite = &m_SpriteNotSorted; | ||||
CGUISpriteInstance& sprite = GetSetting<CGUISpriteInstance>(spriteName); | m_pGUI.DrawSprite(*sprite, m_CellID, bz + 0.1f, CRect(leftTopCorner + CPos(width - SORT_SPRITE_DIM, 0), leftTopCorner + CPos(width, SORT_SPRITE_DIM))); | ||||
m_pGUI.DrawSprite(sprite, cell_id, bz + 0.1f, CRect(leftTopCorner + CPos(width - SORT_SPRITE_DIM, 0), leftTopCorner + CPos(width, SORT_SPRITE_DIM))); | |||||
} | } | ||||
// Draw column header text | // Draw column header text | ||||
DrawText(col, color, leftTopCorner + COLUMN_SHIFT, bz + 0.1f, rect_head); | DrawText(col, textcolor, leftTopCorner + COLUMN_SHIFT, bz + 0.1f, rect_head); | ||||
xpos += width; | xpos += width; | ||||
++col; | |||||
} | } | ||||
// Draw list items for each column | // Draw list items for each column | ||||
const CGUIList& pList = GetSetting<CGUIList>("list"); | |||||
const size_t objectsCount = m_Columns.size(); | const size_t objectsCount = m_Columns.size(); | ||||
for (size_t i = 0; i < pList.m_Items.size(); ++i) | for (size_t i = 0; i < m_List.m_Items.size(); ++i) | ||||
{ | { | ||||
if (m_ItemsYPositions[i+1] - scroll < 0 || | if (m_ItemsYPositions[i+1] - scroll < 0 || | ||||
m_ItemsYPositions[i] - scroll > rect.GetHeight()) | m_ItemsYPositions[i] - scroll > rect.GetHeight()) | ||||
continue; | continue; | ||||
const float rowHeight = m_ItemsYPositions[i+1] - m_ItemsYPositions[i]; | const float rowHeight = m_ItemsYPositions[i+1] - m_ItemsYPositions[i]; | ||||
// Clipping area (we'll have to substract the scrollbar) | // Clipping area (we'll have to substract the scrollbar) | ||||
CRect cliparea = GetListRect(); | CRect cliparea = GetListRect(); | ||||
if (scrollbar) | if (m_ScrollBar) | ||||
{ | { | ||||
if (cliparea.right > GetScrollBar(0).GetOuterRect().left && | if (cliparea.right > GetScrollBar(0).GetOuterRect().left && | ||||
cliparea.right <= GetScrollBar(0).GetOuterRect().right) | cliparea.right <= GetScrollBar(0).GetOuterRect().right) | ||||
cliparea.right = GetScrollBar(0).GetOuterRect().left; | cliparea.right = GetScrollBar(0).GetOuterRect().left; | ||||
if (cliparea.left >= GetScrollBar(0).GetOuterRect().left && | if (cliparea.left >= GetScrollBar(0).GetOuterRect().left && | ||||
cliparea.left < GetScrollBar(0).GetOuterRect().right) | cliparea.left < GetScrollBar(0).GetOuterRect().right) | ||||
cliparea.left = GetScrollBar(0).GetOuterRect().right; | cliparea.left = GetScrollBar(0).GetOuterRect().right; | ||||
} | } | ||||
// Draw all items for that column | // Draw all items for that column | ||||
xpos = 0; | xpos = 0; | ||||
for (size_t col = 0; col < objectsCount; ++col) | size_t col = 0; | ||||
for (const COListColumn& column : m_Columns) | |||||
{ | { | ||||
if (GetSetting<bool>("hidden_" + m_Columns[col].m_Id)) | if (column.m_Hidden) | ||||
{ | |||||
++col; | |||||
continue; | continue; | ||||
} | |||||
// Determine text position and width | // Determine text position and width | ||||
const CPos textPos = rect.TopLeft() + CPos(xpos, -scroll + m_ItemsYPositions[i]); | const CPos textPos = rect.TopLeft() + CPos(xpos, -scroll + m_ItemsYPositions[i]); | ||||
float width = m_Columns[col].m_Width; | float width = column.m_Width; | ||||
// Check if it's a decimal value, and if so, assume relative positioning. | // Check if it's a decimal value, and if so, assume relative positioning. | ||||
if (m_Columns[col].m_Width < 1 && m_Columns[col].m_Width > 0) | if (column.m_Width < 1 && column.m_Width > 0) | ||||
width *= m_TotalAvailableColumnWidth; | width *= m_TotalAvailableColumnWidth; | ||||
// Clip text to the column (to prevent drawing text into the neighboring column) | // Clip text to the column (to prevent drawing text into the neighboring column) | ||||
CRect cliparea2 = cliparea; | CRect cliparea2 = cliparea; | ||||
cliparea2.right = std::min(cliparea2.right, textPos.x + width); | cliparea2.right = std::min(cliparea2.right, textPos.x + width); | ||||
cliparea2.bottom = std::min(cliparea2.bottom, textPos.y + rowHeight); | cliparea2.bottom = std::min(cliparea2.bottom, textPos.y + rowHeight); | ||||
// Draw list item | // Draw list item | ||||
DrawText(objectsCount * (i +/*Heading*/1) + col, m_Columns[col].m_TextColor, textPos, bz + 0.1f, cliparea2); | DrawText(objectsCount * (i +/*Heading*/1) + col, column.m_TextColor, textPos, bz + 0.1f, cliparea2); | ||||
xpos += width; | xpos += width; | ||||
++col; | |||||
} | } | ||||
} | } | ||||
} | } |
Wildfire Games · Phabricator