Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/CList.cpp
Show First 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | |||||
CList::~CList() | CList::~CList() | ||||
{ | { | ||||
} | } | ||||
void CList::SetupText() | void CList::SetupText() | ||||
{ | { | ||||
m_Modified = true; | m_Modified = true; | ||||
CGUIList* pList; | const CGUIList& pList = GUI<CGUIList>::GetSetting(this, "list"); | ||||
GUI<CGUIList>::GetSettingPointer(this, "list", pList); | |||||
//ENSURE(m_GeneratedTexts.size()>=1); | //ENSURE(m_GeneratedTexts.size()>=1); | ||||
m_ItemsYPositions.resize(pList->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(); | ||||
CStrW font; | CStrW font; | ||||
if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty()) | if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty()) | ||||
Show All 10 Lines | if (scrollbar && GetScrollBar(0).GetStyle()) | ||||
width -= GetScrollBar(0).GetStyle()->m_Width; | width -= GetScrollBar(0).GetStyle()->m_Width; | ||||
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); | ||||
// 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 < pList.m_Items.size(); ++i) | ||||
{ | { | ||||
CGUIText* text; | CGUIText* text; | ||||
if (!pList->m_Items[i].GetOriginalString().empty()) | if (!pList.m_Items[i].GetOriginalString().empty()) | ||||
text = &AddText(pList->m_Items[i], font, width, buffer_zone, this); | text = &AddText(pList.m_Items[i], font, width, buffer_zone, 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, font, width, buffer_zone, this); | ||||
} | } | ||||
m_ItemsYPositions[i] = buffered_y; | m_ItemsYPositions[i] = buffered_y; | ||||
buffered_y += text->GetSize().cy; | buffered_y += text->GetSize().cy; | ||||
} | } | ||||
m_ItemsYPositions[pList->m_Items.size()] = buffered_y; | m_ItemsYPositions[pList.m_Items.size()] = buffered_y; | ||||
// Setup scrollbar | // Setup scrollbar | ||||
if (scrollbar) | if (scrollbar) | ||||
{ | { | ||||
GetScrollBar(0).SetScrollRange(m_ItemsYPositions.back()); | GetScrollBar(0).SetScrollRange(m_ItemsYPositions.back()); | ||||
GetScrollBar(0).SetScrollSpace(GetListRect().GetHeight()); | GetScrollBar(0).SetScrollSpace(GetListRect().GetHeight()); | ||||
CRect rect = GetListRect(); | CRect rect = GetListRect(); | ||||
▲ Show 20 Lines • Show All 191 Lines • ▼ Show 20 Lines | void CList::DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor) | ||||
if (scrollbar) | if (scrollbar) | ||||
IGUIScrollBarOwner::Draw(); | IGUIScrollBarOwner::Draw(); | ||||
if (GetGUI()) | if (GetGUI()) | ||||
{ | { | ||||
CRect rect = GetListRect(); | CRect rect = GetListRect(); | ||||
CGUISpriteInstance* sprite = NULL; | CGUISpriteInstance& sprite = GUI<CGUISpriteInstance>::GetSetting(this, _sprite); | ||||
CGUISpriteInstance* sprite_selectarea = NULL; | CGUISpriteInstance& sprite_selectarea = GUI<CGUISpriteInstance>::GetSetting(this, _sprite_selected); | ||||
int cell_id; | |||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, _sprite, sprite); | |||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, _sprite_selected, sprite_selectarea); | |||||
GUI<int>::GetSetting(this, "cell_id", cell_id); | |||||
CGUIList* pList; | const int cell_id = GUI<int>::GetSetting(this, "cell_id"); | ||||
GUI<CGUIList>::GetSettingPointer(this, "list", pList); | m_pGUI->DrawSprite(sprite, cell_id, bz, rect); | ||||
GetGUI()->DrawSprite(*sprite, cell_id, bz, rect); | |||||
float scroll = 0.f; | float scroll = 0.f; | ||||
if (scrollbar) | if (scrollbar) | ||||
scroll = GetScrollBar(0).GetPos(); | scroll = GetScrollBar(0).GetPos(); | ||||
if (selected >= 0 && selected+1 < (int)m_ItemsYPositions.size()) | if (selected >= 0 && selected+1 < (int)m_ItemsYPositions.size()) | ||||
{ | { | ||||
// Get rectangle of selection: | // Get rectangle of selection: | ||||
Show All 15 Lines | if (selected >= 0 && selected+1 < (int)m_ItemsYPositions.size()) | ||||
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; | ||||
} | } | ||||
GetGUI()->DrawSprite(*sprite_selectarea, cell_id, bz+0.05f, rect_sel); | m_pGUI->DrawSprite(sprite_selectarea, cell_id, bz+0.05f, rect_sel); | ||||
} | } | ||||
} | } | ||||
CGUIColor color; | CGUIColor color; | ||||
GUI<CGUIColor>::GetSetting(this, _textcolor, color); | GUI<CGUIColor>::GetSetting(this, _textcolor, color); | ||||
for (size_t i = 0; i < pList->m_Items.size(); ++i) | const CGUIList& pList = GUI<CGUIList>::GetSetting(this, "list"); | ||||
for (size_t i = 0; i < pList.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; | ||||
// Clipping area (we'll have to substract the scrollbar) | // Clipping area (we'll have to substract the scrollbar) | ||||
CRect cliparea = GetListRect(); | CRect cliparea = GetListRect(); | ||||
Show All 10 Lines | for (size_t i = 0; i < pList.m_Items.size(); ++i) | ||||
DrawText(i, color, rect.TopLeft() - CPos(0.f, scroll - m_ItemsYPositions[i]), bz+0.1f, cliparea); | DrawText(i, color, 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 CStrW& str, const CStrW& data) | ||||
{ | { | ||||
CGUIList* pList; | |||||
CGUIList* pListData; | |||||
GUI<CGUIList>::GetSettingPointer(this, "list", pList); | |||||
GUI<CGUIList>::GetSettingPointer(this, "list_data", pListData); | |||||
CGUIString gui_string; | CGUIString gui_string; | ||||
gui_string.SetValue(str); | gui_string.SetValue(str); | ||||
pList->m_Items.push_back(gui_string); | |||||
// Do not send a settings-changed message | |||||
CGUIList& pList = GUI<CGUIList>::GetSetting(this, "list"); | |||||
pList.m_Items.push_back(gui_string); | |||||
CGUIString data_string; | CGUIString data_string; | ||||
data_string.SetValue(data); | data_string.SetValue(data); | ||||
pListData->m_Items.push_back(data_string); | CGUIList& pListData = GUI<CGUIList>::GetSetting(this, "list_data"); | ||||
pListData.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()); | AddItem(child.GetText().FromUTF8(), child.GetText().FromUTF8()); | ||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
void CList::SelectNextElement() | void CList::SelectNextElement() | ||||
{ | { | ||||
int selected; | int selected = GUI<int>::GetSetting(this, "selected"); | ||||
GUI<int>::GetSetting(this, "selected", selected); | |||||
CGUIList* pList; | const CGUIList& pList = GUI<CGUIList>::GetSetting(this, "list"); | ||||
GUI<CGUIList>::GetSettingPointer(this, "list", pList); | |||||
if (selected != (int)pList->m_Items.size()-1) | if (selected != static_cast<int>(pList.m_Items.size()) - 1) | ||||
{ | { | ||||
++selected; | ++selected; | ||||
GUI<int>::SetSetting(this, "selected", selected); | GUI<int>::SetSetting(this, "selected", selected); | ||||
CStrW soundPath; | CStrW soundPath; | ||||
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) | if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) | ||||
g_SoundManager->PlayAsUI(soundPath.c_str(), false); | g_SoundManager->PlayAsUI(soundPath.c_str(), false); | ||||
} | } | ||||
} | } | ||||
void CList::SelectPrevElement() | void CList::SelectPrevElement() | ||||
{ | { | ||||
int selected; | int selected = GUI<int>::GetSetting(this, "selected"); | ||||
GUI<int>::GetSetting(this, "selected", selected); | |||||
if (selected > 0) | if (selected > 0) | ||||
{ | { | ||||
--selected; | --selected; | ||||
GUI<int>::SetSetting(this, "selected", selected); | GUI<int>::SetSetting(this, "selected", selected); | ||||
CStrW soundPath; | CStrW soundPath; | ||||
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) | if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) | ||||
g_SoundManager->PlayAsUI(soundPath.c_str(), false); | g_SoundManager->PlayAsUI(soundPath.c_str(), false); | ||||
} | } | ||||
} | } | ||||
void CList::SelectFirstElement() | void CList::SelectFirstElement() | ||||
{ | { | ||||
int selected; | if (GUI<int>::GetSetting(this, "selected") >= 0) | ||||
GUI<int>::GetSetting(this, "selected", selected); | |||||
if (selected >= 0) | |||||
GUI<int>::SetSetting(this, "selected", 0); | GUI<int>::SetSetting(this, "selected", 0); | ||||
} | } | ||||
void CList::SelectLastElement() | void CList::SelectLastElement() | ||||
{ | { | ||||
int selected; | const CGUIList& pList = GUI<CGUIList>::GetSetting(this, "list"); | ||||
GUI<int>::GetSetting(this, "selected", selected); | const int index = static_cast<int>(pList.m_Items.size()) - 1; | ||||
CGUIList* pList; | |||||
GUI<CGUIList>::GetSettingPointer(this, "list", pList); | |||||
if (selected != (int)pList->m_Items.size()-1) | if (GUI<int>::GetSetting(this, "selected") != index) | ||||
GUI<int>::SetSetting(this, "selected", (int)pList->m_Items.size()-1); | GUI<int>::SetSetting(this, "selected", index); | ||||
} | } | ||||
void CList::UpdateAutoScroll() | void CList::UpdateAutoScroll() | ||||
{ | { | ||||
int selected; | const int selected = GUI<int>::GetSetting(this, "selected"); | ||||
bool scrollbar; | const bool scrollbar = GUI<bool>::GetSetting(this, "scrollbar"); | ||||
float scroll; | |||||
GUI<int>::GetSetting(this, "selected", selected); | |||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar); | |||||
// No scrollbar, no scrolling (at least it's not made to work properly). | // No scrollbar, no scrolling (at least it's not made to work properly). | ||||
if (!scrollbar || selected < 0 || (std::size_t) selected >= m_ItemsYPositions.size()) | if (!scrollbar || selected < 0 || static_cast<std::size_t>(selected) >= m_ItemsYPositions.size()) | ||||
return; | return; | ||||
scroll = GetScrollBar(0).GetPos(); | float scroll = GetScrollBar(0).GetPos(); | ||||
// Check upper boundary | // Check upper boundary | ||||
if (m_ItemsYPositions[selected] < scroll) | if (m_ItemsYPositions[selected] < scroll) | ||||
{ | { | ||||
GetScrollBar(0).SetPos(m_ItemsYPositions[selected]); | GetScrollBar(0).SetPos(m_ItemsYPositions[selected]); | ||||
return; // this means, if it wants to align both up and down at the same time | return; // this means, if it wants to align both up and down at the same time | ||||
// this will have precedence. | // this will have precedence. | ||||
} | } | ||||
// Check lower boundary | // Check lower boundary | ||||
CRect rect = GetListRect(); | CRect rect = GetListRect(); | ||||
if (m_ItemsYPositions[selected+1]-rect.GetHeight() > scroll) | if (m_ItemsYPositions[selected+1]-rect.GetHeight() > scroll) | ||||
GetScrollBar(0).SetPos(m_ItemsYPositions[selected+1]-rect.GetHeight()); | GetScrollBar(0).SetPos(m_ItemsYPositions[selected+1]-rect.GetHeight()); | ||||
} | } | ||||
int CList::GetHoveredItem() | int CList::GetHoveredItem() | ||||
{ | { | ||||
bool scrollbar; | const bool scrollbar = GUI<bool>::GetSetting(this, "scrollbar"); | ||||
CGUIList* pList; | const float scroll = scrollbar ? GetScrollBar(0).GetPos() : 0.f; | ||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar); | |||||
GUI<CGUIList>::GetSettingPointer(this, "list", pList); | |||||
float scroll = 0.f; | |||||
if (scrollbar) | |||||
scroll = GetScrollBar(0).GetPos(); | |||||
const CRect& rect = GetListRect(); | const CRect& rect = GetListRect(); | ||||
CPos mouse = m_pGUI->GetMousePos(); | CPos mouse = m_pGUI->GetMousePos(); | ||||
mouse.y += scroll; | mouse.y += scroll; | ||||
// Mouse is over scrollbar | // Mouse is over scrollbar | ||||
if (scrollbar && GetScrollBar(0).IsVisible() && | if (scrollbar && GetScrollBar(0).IsVisible() && | ||||
mouse.x >= GetScrollBar(0).GetOuterRect().left && | mouse.x >= GetScrollBar(0).GetOuterRect().left && | ||||
mouse.x <= GetScrollBar(0).GetOuterRect().right) | mouse.x <= GetScrollBar(0).GetOuterRect().right) | ||||
return -1; | return -1; | ||||
for (size_t i = 0; i < pList->m_Items.size(); ++i) | const CGUIList& pList = GUI<CGUIList>::GetSetting(this, "list"); | ||||
for (size_t i = 0; i < pList.m_Items.size(); ++i) | |||||
if (mouse.y >= rect.top + m_ItemsYPositions[i] && | if (mouse.y >= rect.top + m_ItemsYPositions[i] && | ||||
mouse.y < rect.top + m_ItemsYPositions[i + 1]) | mouse.y < rect.top + m_ItemsYPositions[i + 1]) | ||||
return i; | return i; | ||||
return -1; | return -1; | ||||
} | } |
Wildfire Games · Phabricator