Changeset View
Changeset View
Standalone View
Standalone View
source/gui/ObjectTypes/CList.cpp
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
Stan: Copyright | |||||
* 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 78 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
CList::~CList() | CList::~CList() | ||||
{ | { | ||||
} | } | ||||
void CList::SetupText() | void CList::SetupText() | ||||
{ | { | ||||
SetupText(false); | |||||
} | |||||
void CList::SetupText(bool appendMode) | |||||
{ | |||||
m_Modified = true; | m_Modified = true; | ||||
m_ItemsYPositions.resize(m_List.m_Items.size() + 1); | m_ItemsYPositions.resize(m_List.m_Items.size() + 1); | ||||
// Delete all generated texts. Some could probably be saved, | if (!appendMode) | ||||
// but this is easier, and this function will never be called | // Delete all generated texts. | ||||
// continuously, or even often, so it'll probably be okay. | // TODO: try to be cleverer if we want to update items before the end. | ||||
m_GeneratedTexts.clear(); | m_GeneratedTexts.clear(); | ||||
float width = GetListRect().GetWidth(); | float width = GetListRect().GetWidth(); | ||||
// remove scrollbar if applicable | // remove scrollbar if applicable | ||||
if (m_ScrollBar && GetScrollBar(0).GetStyle()) | if (m_ScrollBar && GetScrollBar(0).GetStyle()) | ||||
width -= GetScrollBar(0).GetStyle()->m_Width; | width -= GetScrollBar(0).GetStyle()->m_Width; | ||||
// Generate texts | // Generate texts | ||||
float buffered_y = 0.f; | float buffered_y = 0.f; | ||||
for (size_t i = 0; i < m_List.m_Items.size(); ++i) | if (appendMode) | ||||
buffered_y = m_ItemsYPositions[m_List.m_Items.size() - 1]; | |||||
for (size_t i = appendMode ? m_List.m_Items.size() - 1 : 0; i < m_List.m_Items.size(); ++i) | |||||
Not Done Inline ActionsCan't you add the ternary to the above check ? And use a range loop afterwards ? Stan: Can't you add the ternary to the above check ?
And use a range loop afterwards ?
Actually you… | |||||
Done Inline ActionsI'm not sure what you mean. In "append" mode, I only want to generate the latest item, not the whole thing. A range-for loop will never allow that. wraitii: I'm not sure what you mean. In "append" mode, I only want to generate the latest item, not the… | |||||
Not Done Inline ActionsRight but you still check for that boolean three times :) Stan: Right but you still check for that boolean three times :) | |||||
Done Inline ActionsThink I'm going to call that a feature, I think it makes the code more readable. wraitii: Think I'm going to call that a feature, I think it makes the code more readable. | |||||
{ | { | ||||
CGUIText* text; | CGUIText* text; | ||||
if (!m_List.m_Items[i].GetOriginalString().empty()) | if (!m_List.m_Items[i].GetOriginalString().empty()) | ||||
text = &AddText(m_List.m_Items[i], m_Font, width, m_BufferZone); | text = &AddText(m_List.m_Items[i], m_Font, width, m_BufferZone); | ||||
else | else | ||||
{ | { | ||||
// Minimum height of a space character of the current font size | // Minimum height of a space character of the current font size | ||||
▲ Show 20 Lines • Show All 253 Lines • ▼ Show 20 Lines | for (size_t i = 0; i < m_List.m_Items.size(); ++i) | ||||
cliparea.left = GetScrollBar(0).GetOuterRect().right; | cliparea.left = GetScrollBar(0).GetOuterRect().right; | ||||
} | } | ||||
DrawText(i, textcolor, rect.TopLeft() - CPos(0.f, scroll - m_ItemsYPositions[i]), bz + 0.1f, cliparea); | DrawText(i, textcolor, rect.TopLeft() - CPos(0.f, scroll - m_ItemsYPositions[i]), bz + 0.1f, cliparea); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
void CList::AddItem(const CStrW& str, const CStrW& data) | void CList::AddItem(const CGUIString& str, const CGUIString& data) | ||||
{ | { | ||||
CGUIString gui_string; | |||||
gui_string.SetValue(str); | |||||
// Do not send a settings-changed message | // Do not send a settings-changed message | ||||
m_List.m_Items.push_back(gui_string); | m_List.m_Items.push_back(str); | ||||
m_ListData.m_Items.push_back(data); | |||||
CGUIString data_string; | |||||
data_string.SetValue(data); | |||||
m_ListData.m_Items.push_back(data_string); | |||||
// TODO Temp | // TODO Temp | ||||
SetupText(); | SetupText(); | ||||
} | } | ||||
bool CList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile) | bool CList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile) | ||||
{ | { | ||||
int elmt_item = pFile->GetElementID("item"); | int elmt_item = pFile->GetElementID("item"); | ||||
if (child.GetNodeName() == elmt_item) | if (child.GetNodeName() == elmt_item) | ||||
{ | { | ||||
AddItem(child.GetText().FromUTF8(), child.GetText().FromUTF8()); | CGUIString vlist; | ||||
vlist.SetValue(child.GetText().FromUTF8()); | |||||
AddItem(vlist, vlist); | |||||
Not Done Inline ActionsDuplication with COList ? Stan: Duplication with COList ? | |||||
Done Inline Actionsyeah, but not easily avoidable wraitii: yeah, but not easily avoidable | |||||
Not Done Inline ActionsMmhh Stan: Mmhh | |||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
void CList::SelectNextElement() | void CList::SelectNextElement() | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 73 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Copyright