Changeset View
Changeset View
Standalone View
Standalone View
source/gui/COList.cpp
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | void COList::SetupText() | ||||
bool scrollbar; | bool scrollbar; | ||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar); | GUI<bool>::GetSetting(this, "scrollbar", scrollbar); | ||||
float width = GetListRect().GetWidth(); | float width = GetListRect().GetWidth(); | ||||
// remove scrollbar if applicable | // remove scrollbar if applicable | ||||
if (scrollbar && GetScrollBar(0).GetStyle()) | if (scrollbar && GetScrollBar(0).GetStyle()) | ||||
width -= GetScrollBar(0).GetStyle()->m_Width; | width -= GetScrollBar(0).GetStyle()->m_Width; | ||||
m_TotalAvailableColumnWidth = width; | m_TotalAvailableRelativeColumnWidth = m_TotalAvailableColumnWidth = width; | ||||
float total_sum = 0.f; | |||||
for (const COListColumn& column : m_Columns) | |||||
Sandarac: const ref? (Though I notice it's not done for the other similar loops already in this file...) | |||||
{ | |||||
bool hidden = false; | |||||
GUI<bool>::GetSetting(this, "hidden_" + column.m_Id, hidden); | |||||
if (hidden) | |||||
continue; | |||||
if (column.m_Width < 1) | |||||
total_sum += column.m_Width; | |||||
else | |||||
m_TotalAvailableRelativeColumnWidth -= column.m_Width; | |||||
} | |||||
// In normal case total_sum should be equal to 1.0 (all columns in total give 100%) | |||||
// So normalize availabe relative width | |||||
if (total_sum > 0.f) | |||||
m_TotalAvailableRelativeColumnWidth /= total_sum; | |||||
float buffer_zone = 0.f; | float buffer_zone = 0.f; | ||||
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone); | GUI<float>::GetSetting(this, "buffer_zone", buffer_zone); | ||||
for (COListColumn column : m_Columns) | for (const COListColumn& column : m_Columns) | ||||
{ | { | ||||
SGUIText* text = new SGUIText(); | SGUIText* text = new SGUIText(); | ||||
CGUIString gui_string; | CGUIString gui_string; | ||||
gui_string.SetValue(column.m_Heading); | gui_string.SetValue(column.m_Heading); | ||||
*text = GetGUI()->GenerateText(gui_string, font, width, buffer_zone, this); | *text = GetGUI()->GenerateText(gui_string, font, width, buffer_zone, this); | ||||
AddText(text); | AddText(text); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | case GUIM_MOUSE_PRESS_LEFT: | ||||
CStr selectedColumn; | CStr selectedColumn; | ||||
GUI<CStr>::GetSetting(this, "selected_column", selectedColumn); | GUI<CStr>::GetSetting(this, "selected_column", selectedColumn); | ||||
int selectedColumnOrder; | int selectedColumnOrder; | ||||
GUI<int>::GetSetting(this, "selected_column_order", selectedColumnOrder); | GUI<int>::GetSetting(this, "selected_column_order", selectedColumnOrder); | ||||
float headingHeight; | float headingHeight; | ||||
GUI<float>::GetSetting(this, "heading_height", headingHeight); | GUI<float>::GetSetting(this, "heading_height", headingHeight); | ||||
float xpos = 0; | float xpos = 0; | ||||
for (COListColumn column : m_Columns) | for (const COListColumn& column : m_Columns) | ||||
{ | { | ||||
bool hidden = false; | bool hidden = false; | ||||
GUI<bool>::GetSetting(this, "hidden_" + column.m_Id, hidden); | GUI<bool>::GetSetting(this, "hidden_" + column.m_Id, hidden); | ||||
if (hidden) | if (hidden) | ||||
continue; | continue; | ||||
float width = column.m_Width; | float width = GetColumnWidth(column); | ||||
// Check if it's a decimal value, and if so, assume relative positioning. | |||||
if (column.m_Width < 1 && column.m_Width > 0) | |||||
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 + headingHeight) | mouse.y < leftTopCorner.y + headingHeight) | ||||
{ | { | ||||
if (column.m_Id != selectedColumn) | if (column.m_Id != selectedColumn) | ||||
{ | { | ||||
selectedColumnOrder = 1; | selectedColumnOrder = 1; | ||||
▲ Show 20 Lines • Show All 211 Lines • ▼ Show 20 Lines | void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor) | ||||
int selectedColumnOrder; | int selectedColumnOrder; | ||||
GUI<int>::GetSetting(this, "selected_column_order", selectedColumnOrder); | GUI<int>::GetSetting(this, "selected_column_order", selectedColumnOrder); | ||||
CColor color; | CColor color; | ||||
GUI<CColor>::GetSetting(this, _textcolor, color); | GUI<CColor>::GetSetting(this, _textcolor, color); | ||||
float xpos = 0; | float xpos = 0; | ||||
for (size_t col = 0; col < m_Columns.size(); ++col) | for (size_t col = 0; col < m_Columns.size(); ++col) | ||||
elexisUnsubmitted Not Done Inline ActionsAfaics this could become a range based loop too, but would have to touch a number of lines, so not here, not now. elexis: Afaics this could become a range based loop too, but would have to touch a number of lines, so… | |||||
vladislavbelovAuthorUnsubmitted Not Done Inline ActionsNope, col uses here: DrawText(col, color, leftTopCorner + CPos(0, 4), bz + 0.1f, rect_head);` And column doesn't know its order number. So the current loop is ok. vladislavbelov: Nope, `col` uses here:
```lang=cpp
DrawText(col, color, leftTopCorner + CPos(0, 4), bz + 0.1f… | |||||
{ | { | ||||
bool hidden = false; | bool hidden = false; | ||||
GUI<bool>::GetSetting(this, "hidden_" + m_Columns[col].m_Id, hidden); | GUI<bool>::GetSetting(this, "hidden_" + m_Columns[col].m_Id, hidden); | ||||
if (hidden) | if (hidden) | ||||
continue; | continue; | ||||
// Check if it's a decimal value, and if so, assume relative positioning. | float width = GetColumnWidth(m_Columns[col]); | ||||
float width = m_Columns[col].m_Width; | |||||
if (m_Columns[col].m_Width < 1 && m_Columns[col].m_Width > 0) | |||||
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 (sortable) | ||||
{ | { | ||||
CGUISpriteInstance* sprite; | CGUISpriteInstance* sprite; | ||||
if (selectedColumn == m_Columns[col].m_Id) | if (selectedColumn == m_Columns[col].m_Id) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | for (size_t col = 0; col < objectsCount; ++col) | ||||
bool hidden = false; | bool hidden = false; | ||||
GUI<bool>::GetSetting(this, "hidden_" + m_Columns[col].m_Id, hidden); | GUI<bool>::GetSetting(this, "hidden_" + m_Columns[col].m_Id, hidden); | ||||
if (hidden) | if (hidden) | ||||
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 = GetColumnWidth(m_Columns[col]); | ||||
// 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) | |||||
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, m_Columns[col].m_TextColor, textPos, bz + 0.1f, cliparea2); | ||||
xpos += width; | xpos += width; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
float COList::GetColumnWidth(const COListColumn& column) const | |||||
{ | |||||
// Check if it's a decimal value, and if so, assume relative positioning. | |||||
return column.m_Width < 1 && column.m_Width > 0 ? | |||||
column.m_Width * m_TotalAvailableRelativeColumnWidth : column.m_Width; | |||||
} |
Wildfire Games · Phabricator
const ref? (Though I notice it's not done for the other similar loops already in this file...)