Changeset View
Changeset View
Standalone View
Standalone View
source/gui/ObjectTypes/COList.cpp
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 349 Lines • ▼ Show 20 Lines | for (const COListColumn& column : m_Columns) | ||||
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); | ||||
// Draw sort arrows in colum header | // Draw sort arrows in colum header | ||||
if (m_Sortable) | if (m_Sortable) | ||||
{ | { | ||||
const CGUISpriteInstance* sprite; | const CGUISpriteInstance* pSprite; | ||||
if (m_SelectedColumn == column.m_Id) | if (m_SelectedColumn == column.m_Id) | ||||
{ | { | ||||
if (m_SelectedColumnOrder == 0) | if (m_SelectedColumnOrder == 0) | ||||
LOGERROR("selected_column_order must not be 0"); | LOGERROR("selected_column_order must not be 0"); | ||||
if (m_SelectedColumnOrder != -1) | if (m_SelectedColumnOrder != -1) | ||||
sprite = &m_SpriteAsc; | pSprite = &m_SpriteAsc; | ||||
else | else | ||||
sprite = &m_SpriteDesc; | pSprite = &m_SpriteDesc; | ||||
} | } | ||||
else | else | ||||
sprite = &m_SpriteNotSorted; | pSprite = &m_SpriteNotSorted; | ||||
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(*pSprite, m_CellID, 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, textcolor, leftTopCorner + COLUMN_SHIFT, bz + 0.1f, rect_head); | DrawText(col, textcolor, leftTopCorner + COLUMN_SHIFT, bz + 0.1f, rect_head); | ||||
xpos += width; | xpos += width; | ||||
++col; | ++col; | ||||
} | } | ||||
Show All 18 Lines | if (m_ScrollBar) | ||||
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; | ||||
size_t col = 0; | size_t colIdx = 0; | ||||
for (const COListColumn& column : m_Columns) | for (const COListColumn& column : m_Columns) | ||||
wraitii: Feels like the for-range is the wrong choice if an index is needed also. Just revert to an… | |||||
{ | { | ||||
if (column.m_Hidden) | if (column.m_Hidden) | ||||
{ | { | ||||
++col; | ++colIdx; | ||||
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 = 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; | ||||
// 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, column.m_TextColor, textPos, bz + 0.1f, cliparea2); | DrawText(objectsCount * (i +/*Heading*/1) + colIdx, column.m_TextColor, textPos, bz + 0.1f, cliparea2); | ||||
xpos += width; | xpos += width; | ||||
++col; | ++colIdx; | ||||
} | } | ||||
} | } | ||||
} | } |
Wildfire Games · Phabricator
Feels like the for-range is the wrong choice if an index is needed also. Just revert to an index imo.