Changeset View
Changeset View
Standalone View
Standalone View
source/gui/CList.cpp
Show All 21 Lines | |||||
#include "gui/CGUI.h" | #include "gui/CGUI.h" | ||||
#include "gui/CGUIColor.h" | #include "gui/CGUIColor.h" | ||||
#include "gui/CGUIList.h" | #include "gui/CGUIList.h" | ||||
#include "gui/CGUIScrollBarVertical.h" | #include "gui/CGUIScrollBarVertical.h" | ||||
#include "lib/external_libraries/libsdl.h" | #include "lib/external_libraries/libsdl.h" | ||||
#include "lib/timer.h" | #include "lib/timer.h" | ||||
CList::CList(CGUI& pGUI) | CList::CList(CGUI& pGUI) | ||||
: IGUIObject(pGUI), IGUITextOwner(pGUI), IGUIScrollBarOwner(pGUI), | : IGUIObject(pGUI), | ||||
m_Modified(false), m_PrevSelectedItem(-1), m_LastItemClickTime(0) | IGUITextOwner(pGUI), | ||||
{ | IGUIScrollBarOwner(pGUI), | ||||
m_Modified(false), | |||||
m_PrevSelectedItem(-1), | |||||
m_LastItemClickTime(0), | |||||
m_BufferZone(), | |||||
m_Font(), | |||||
m_ScrollBar(), | |||||
m_ScrollBarStyle(), | |||||
m_SoundDisabled(), | |||||
m_SoundSelected(), | |||||
m_Sprite(), | |||||
m_SpriteSelectArea(), | |||||
m_CellID(), | |||||
m_TextAlign(), | |||||
m_TextColor(), | |||||
m_TextColorSelected(), | |||||
m_Selected(), | |||||
m_AutoScroll(), | |||||
m_Hovered(), | |||||
m_List(), | |||||
m_ListData() | |||||
{ | |||||
RegisterSetting("buffer_zone", m_BufferZone); | |||||
RegisterSetting("font", m_Font); | |||||
RegisterSetting("scrollbar", m_ScrollBar); | |||||
RegisterSetting("scrollbar_style", m_ScrollBarStyle); | |||||
RegisterSetting("sound_disabled", m_SoundDisabled); | |||||
RegisterSetting("sound_selected", m_SoundSelected); | |||||
RegisterSetting("sprite", m_Sprite); | |||||
// Add sprite_disabled! TODO | // Add sprite_disabled! TODO | ||||
AddSetting<float>("buffer_zone"); | RegisterSetting("sprite_selectarea", m_SpriteSelectArea); | ||||
AddSetting<CStrW>("font"); | RegisterSetting("cell_id", m_CellID); | ||||
AddSetting<bool>("scrollbar"); | RegisterSetting("text_align", m_TextAlign); | ||||
AddSetting<CStr>("scrollbar_style"); | RegisterSetting("textcolor", m_TextColor); | ||||
AddSetting<CStrW>("sound_disabled"); | RegisterSetting("textcolor_selected", m_TextColorSelected); | ||||
AddSetting<CStrW>("sound_selected"); | RegisterSetting("selected", m_Selected); // Index selected. -1 is none. | ||||
AddSetting<CGUISpriteInstance>("sprite"); | RegisterSetting("auto_scroll", m_AutoScroll); | ||||
AddSetting<CGUISpriteInstance>("sprite_selectarea"); | RegisterSetting("hovered", m_Hovered); | ||||
AddSetting<i32>("cell_id"); | |||||
AddSetting<EAlign>("text_align"); | |||||
AddSetting<CGUIColor>("textcolor"); | |||||
AddSetting<CGUIColor>("textcolor_selected"); | |||||
AddSetting<i32>("selected"); // Index selected. -1 is none. | |||||
AddSetting<bool>("auto_scroll"); | |||||
AddSetting<i32>("hovered"); | |||||
// Each list item has both a name (in 'list') and an associated data string (in 'list_data') | // Each list item has both a name (in 'list') and an associated data string (in 'list_data') | ||||
AddSetting<CGUIList>("list"); | RegisterSetting("list", m_List); | ||||
AddSetting<CGUIList>("list_data"); | RegisterSetting("list_data", m_ListData); | ||||
SetSetting<bool>("scrollbar", false, true); | SetSetting<bool>("scrollbar", false, true); | ||||
SetSetting<i32>("selected", -1, true); | SetSetting<i32>("selected", -1, true); | ||||
SetSetting<i32>("hovered", -1, true); | SetSetting<i32>("hovered", -1, true); | ||||
SetSetting<bool>("auto_scroll", false, true); | SetSetting<bool>("auto_scroll", false, true); | ||||
// Add scroll-bar | // Add scroll-bar | ||||
CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(pGUI); | CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(pGUI); | ||||
bar->SetRightAligned(true); | bar->SetRightAligned(true); | ||||
AddScrollBar(bar); | AddScrollBar(bar); | ||||
} | } | ||||
CList::~CList() | CList::~CList() | ||||
{ | { | ||||
} | } | ||||
void CList::SetupText() | void CList::SetupText() | ||||
{ | { | ||||
m_Modified = true; | m_Modified = true; | ||||
const CGUIList& pList = GetSetting<CGUIList>("list"); | |||||
//ENSURE(m_GeneratedTexts.size()>=1); | 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"); | |||||
float width = GetListRect().GetWidth(); | float width = GetListRect().GetWidth(); | ||||
// remove scrollbar if applicable | // remove scrollbar if applicable | ||||
if (scrollbar && GetScrollBar(0).GetStyle()) | if (m_ScrollBar && GetScrollBar(0).GetStyle()) | ||||
width -= GetScrollBar(0).GetStyle()->m_Width; | width -= GetScrollBar(0).GetStyle()->m_Width; | ||||
const float buffer_zone = GetSetting<float>("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 < m_List.m_Items.size(); ++i) | ||||
{ | { | ||||
CGUIText* text; | CGUIText* text; | ||||
if (!pList.m_Items[i].GetOriginalString().empty()) | if (!m_List.m_Items[i].GetOriginalString().empty()) | ||||
text = &AddText(pList.m_Items[i], font, width, buffer_zone, this); | text = &AddText(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); | ||||
} | } | ||||
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[m_List.m_Items.size()] = buffered_y; | ||||
// Setup scrollbar | // Setup scrollbar | ||||
if (scrollbar) | if (m_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(); | ||||
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 13 Lines | case GUIM_SETTINGS_UPDATED: | ||||
if (Message.value == "list") | if (Message.value == "list") | ||||
SetupText(); | SetupText(); | ||||
// If selected is changed, call "SelectionChange" | // If selected is changed, call "SelectionChange" | ||||
if (Message.value == "selected") | if (Message.value == "selected") | ||||
{ | { | ||||
// TODO: Check range | // TODO: Check range | ||||
if (GetSetting<bool>("auto_scroll")) | if (m_AutoScroll) | ||||
UpdateAutoScroll(); | UpdateAutoScroll(); | ||||
// TODO only works if lower-case, shouldn't it be made case sensitive instead? | // TODO only works if lower-case, shouldn't it be made case sensitive instead? | ||||
ScriptEvent("selectionchange"); | ScriptEvent("selectionchange"); | ||||
} | } | ||||
if (Message.value == "scrollbar") | if (Message.value == "scrollbar") | ||||
SetupText(); | SetupText(); | ||||
// Update scrollbar | // Update scrollbar | ||||
if (Message.value == "scrollbar_style") | if (Message.value == "scrollbar_style") | ||||
{ | { | ||||
GetScrollBar(0).SetScrollBarStyle(GetSetting<CStr>(Message.value)); | GetScrollBar(0).SetScrollBarStyle(m_ScrollBarStyle); | ||||
SetupText(); | SetupText(); | ||||
} | } | ||||
break; | break; | ||||
case GUIM_MOUSE_PRESS_LEFT: | case GUIM_MOUSE_PRESS_LEFT: | ||||
{ | { | ||||
if (!GetSetting<bool>("enabled")) | if (!m_Enabled) | ||||
{ | { | ||||
PlaySound("sound_disabled"); | PlaySound(m_SoundDisabled); | ||||
break; | break; | ||||
} | } | ||||
int hovered = GetHoveredItem(); | int hovered = GetHoveredItem(); | ||||
if (hovered == -1) | if (hovered == -1) | ||||
break; | break; | ||||
SetSetting<i32>("selected", hovered, true); | SetSetting<i32>("selected", hovered, true); | ||||
UpdateAutoScroll(); | UpdateAutoScroll(); | ||||
PlaySound("sound_selected"); | PlaySound(m_SoundSelected); | ||||
if (timer_Time() - m_LastItemClickTime < SELECT_DBLCLICK_RATE && hovered == m_PrevSelectedItem) | if (timer_Time() - m_LastItemClickTime < SELECT_DBLCLICK_RATE && hovered == m_PrevSelectedItem) | ||||
this->SendEvent(GUIM_MOUSE_DBLCLICK_LEFT_ITEM, "mouseleftdoubleclickitem"); | this->SendEvent(GUIM_MOUSE_DBLCLICK_LEFT_ITEM, "mouseleftdoubleclickitem"); | ||||
else | else | ||||
this->SendEvent(GUIM_MOUSE_PRESS_LEFT_ITEM, "mouseleftclickitem"); | this->SendEvent(GUIM_MOUSE_PRESS_LEFT_ITEM, "mouseleftclickitem"); | ||||
m_LastItemClickTime = timer_Time(); | m_LastItemClickTime = timer_Time(); | ||||
m_PrevSelectedItem = hovered; | m_PrevSelectedItem = hovered; | ||||
break; | break; | ||||
} | } | ||||
case GUIM_MOUSE_LEAVE: | case GUIM_MOUSE_LEAVE: | ||||
{ | { | ||||
if (GetSetting<i32>("hovered") == -1) | if (m_Hovered == -1) | ||||
break; | break; | ||||
SetSetting<i32>("hovered", -1, true); | SetSetting<i32>("hovered", -1, true); | ||||
ScriptEvent("hoverchange"); | ScriptEvent("hoverchange"); | ||||
break; | break; | ||||
} | } | ||||
case GUIM_MOUSE_OVER: | case GUIM_MOUSE_OVER: | ||||
{ | { | ||||
int hovered = GetHoveredItem(); | int hovered = GetHoveredItem(); | ||||
if (hovered == GetSetting<i32>("hovered")) | if (hovered == m_Hovered) | ||||
break; | break; | ||||
SetSetting<i32>("hovered", hovered, true); | SetSetting<i32>("hovered", hovered, true); | ||||
ScriptEvent("hoverchange"); | ScriptEvent("hoverchange"); | ||||
break; | break; | ||||
} | } | ||||
case GUIM_LOAD: | case GUIM_LOAD: | ||||
{ | { | ||||
GetScrollBar(0).SetScrollBarStyle(GetSetting<CStr>("scrollbar_style")); | GetScrollBar(0).SetScrollBarStyle(m_ScrollBarStyle); | ||||
break; | break; | ||||
} | } | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
IGUITextOwner::HandleMessage(Message); | IGUITextOwner::HandleMessage(Message); | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | if (ev->ev.type == SDL_KEYDOWN) | ||||
} | } | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
void CList::Draw() | void CList::Draw() | ||||
{ | { | ||||
DrawList(GetSetting<i32>("selected"), "sprite", "sprite_selectarea", "textcolor"); | DrawList(m_Selected, m_Sprite, m_SpriteSelectArea, m_TextColor); | ||||
} | } | ||||
void CList::DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor) | void CList::DrawList(const int& selected, const CGUISpriteInstance& sprite, const CGUISpriteInstance& sprite_selectarea, const CGUIColor& textcolor) | ||||
{ | { | ||||
float bz = GetBufferedZ(); | float bz = GetBufferedZ(); | ||||
// First call draw on ScrollBarOwner | // First call draw on ScrollBarOwner | ||||
const bool scrollbar = GetSetting<bool>("scrollbar"); | if (m_ScrollBar) | ||||
if (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(); | ||||
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: | ||||
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; | ||||
} | } | ||||
m_pGUI.DrawSprite(sprite_selectarea, cell_id, bz+0.05f, rect_sel); | m_pGUI.DrawSprite(sprite_selectarea, m_CellID, bz + 0.05f, rect_sel); | ||||
} | } | ||||
} | } | ||||
const CGUIList& pList = GetSetting<CGUIList>("list"); | for (size_t i = 0; i < m_List.m_Items.size(); ++i) | ||||
const CGUIColor& color = GetSetting<CGUIColor>(_textcolor); | |||||
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(); | ||||
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; | ||||
} | } | ||||
DrawText(i, color, 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 CStrW& str, const CStrW& data) | ||||
{ | { | ||||
CGUIString gui_string; | CGUIString gui_string; | ||||
gui_string.SetValue(str); | gui_string.SetValue(str); | ||||
// Do not send a settings-changed message | // Do not send a settings-changed message | ||||
CGUIList& pList = GetSetting<CGUIList>("list"); | m_List.m_Items.push_back(gui_string); | ||||
pList.m_Items.push_back(gui_string); | |||||
CGUIString data_string; | CGUIString data_string; | ||||
data_string.SetValue(data); | data_string.SetValue(data); | ||||
CGUIList& pListData = GetSetting<CGUIList>("list_data"); | |||||
pListData.m_Items.push_back(data_string); | 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()); | AddItem(child.GetText().FromUTF8(), child.GetText().FromUTF8()); | ||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
void CList::SelectNextElement() | void CList::SelectNextElement() | ||||
{ | { | ||||
int selected = GetSetting<i32>("selected"); | if (m_Selected != static_cast<int>(m_List.m_Items.size()) - 1) | ||||
const CGUIList& pList = GetSetting<CGUIList>("list"); | |||||
if (selected != static_cast<int>(pList.m_Items.size()) - 1) | |||||
{ | { | ||||
++selected; | SetSetting<i32>("selected", m_Selected + 1, true); | ||||
SetSetting<i32>("selected", selected, true); | PlaySound(m_SoundSelected); | ||||
PlaySound("sound_selected"); | |||||
} | } | ||||
} | } | ||||
void CList::SelectPrevElement() | void CList::SelectPrevElement() | ||||
{ | { | ||||
int selected = GetSetting<i32>("selected"); | if (m_Selected > 0) | ||||
if (selected > 0) | |||||
{ | { | ||||
--selected; | SetSetting<i32>("selected", m_Selected - 1, true); | ||||
SetSetting<i32>("selected", selected, true); | PlaySound(m_SoundSelected); | ||||
PlaySound("sound_selected"); | |||||
} | } | ||||
} | } | ||||
void CList::SelectFirstElement() | void CList::SelectFirstElement() | ||||
{ | { | ||||
if (GetSetting<i32>("selected") >= 0) | if (m_Selected >= 0) | ||||
SetSetting<i32>("selected", 0, true); | SetSetting<i32>("selected", 0, true); | ||||
} | } | ||||
void CList::SelectLastElement() | void CList::SelectLastElement() | ||||
{ | { | ||||
const CGUIList& pList = GetSetting<CGUIList>("list"); | const int index = static_cast<int>(m_List.m_Items.size()) - 1; | ||||
const int index = static_cast<int>(pList.m_Items.size()) - 1; | |||||
if (GetSetting<i32>("selected") != index) | if (m_Selected != index) | ||||
SetSetting<i32>("selected", index, true); | SetSetting<i32>("selected", index, true); | ||||
} | } | ||||
void CList::UpdateAutoScroll() | void CList::UpdateAutoScroll() | ||||
{ | { | ||||
const int selected = GetSetting<i32>("selected"); | |||||
const bool scrollbar = GetSetting<bool>("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 || static_cast<std::size_t>(selected) >= m_ItemsYPositions.size()) | if (!m_ScrollBar || m_Selected < 0 || static_cast<std::size_t>(m_Selected) >= m_ItemsYPositions.size()) | ||||
return; | return; | ||||
float scroll = GetScrollBar(0).GetPos(); | float scroll = GetScrollBar(0).GetPos(); | ||||
// Check upper boundary | // Check upper boundary | ||||
if (m_ItemsYPositions[selected] < scroll) | if (m_ItemsYPositions[m_Selected] < scroll) | ||||
{ | { | ||||
GetScrollBar(0).SetPos(m_ItemsYPositions[selected]); | GetScrollBar(0).SetPos(m_ItemsYPositions[m_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[m_Selected+1]-rect.GetHeight() > scroll) | ||||
GetScrollBar(0).SetPos(m_ItemsYPositions[selected+1]-rect.GetHeight()); | GetScrollBar(0).SetPos(m_ItemsYPositions[m_Selected+1]-rect.GetHeight()); | ||||
} | } | ||||
int CList::GetHoveredItem() | int CList::GetHoveredItem() | ||||
{ | { | ||||
const bool scrollbar = GetSetting<bool>("scrollbar"); | const float scroll = m_ScrollBar ? GetScrollBar(0).GetPos() : 0.f; | ||||
const float scroll = scrollbar ? GetScrollBar(0).GetPos() : 0.f; | |||||
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 (m_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; | ||||
const CGUIList& pList = GetSetting<CGUIList>("list"); | for (size_t i = 0; i < m_List.m_Items.size(); ++i) | ||||
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