Changeset View
Changeset View
Standalone View
Standalone View
source/gui/CDropDown.cpp
Show All 22 Lines | |||||
#include "gui/CGUIColor.h" | #include "gui/CGUIColor.h" | ||||
#include "gui/CGUIList.h" | #include "gui/CGUIList.h" | ||||
#include "gui/IGUIScrollBar.h" | #include "gui/IGUIScrollBar.h" | ||||
#include "lib/external_libraries/libsdl.h" | #include "lib/external_libraries/libsdl.h" | ||||
#include "lib/timer.h" | #include "lib/timer.h" | ||||
#include "ps/Profile.h" | #include "ps/Profile.h" | ||||
CDropDown::CDropDown(CGUI& pGUI) | CDropDown::CDropDown(CGUI& pGUI) | ||||
: CList(pGUI), IGUIObject(pGUI), | : CList(pGUI), | ||||
m_Open(false), m_HideScrollBar(false), m_ElementHighlight(-1) | IGUIObject(pGUI), | ||||
{ | m_Open(false), | ||||
AddSetting<float>("button_width"); | m_HideScrollBar(false), | ||||
AddSetting<float>("dropdown_size"); | m_ElementHighlight(-1), | ||||
AddSetting<float>("dropdown_buffer"); | m_ButtonWidth(), | ||||
AddSetting<u32>("minimum_visible_items"); | m_DropDownSize(), | ||||
AddSetting<CStrW>("sound_closed"); | m_DropDownBuffer(), | ||||
AddSetting<CStrW>("sound_enter"); | m_MinimumVisibleItems(), | ||||
AddSetting<CStrW>("sound_leave"); | m_SoundClosed(), | ||||
AddSetting<CStrW>("sound_opened"); | m_SoundEnter(), | ||||
m_SoundLeave(), | |||||
m_SoundOpened(), | |||||
m_SpriteDisabled(), | |||||
m_SpriteList(), | |||||
m_Sprite2(), | |||||
m_Sprite2Over(), | |||||
m_Sprite2Pressed(), | |||||
m_Sprite2Disabled(), | |||||
m_TextColorDisabled(), | |||||
m_TextVAlign() | |||||
{ | |||||
RegisterSetting("button_width", m_ButtonWidth); | |||||
RegisterSetting("dropdown_size", m_DropDownSize); | |||||
RegisterSetting("dropdown_buffer", m_DropDownBuffer); | |||||
RegisterSetting("minimum_visible_items", m_MinimumVisibleItems); | |||||
RegisterSetting("sound_closed", m_SoundClosed); | |||||
RegisterSetting("sound_enter", m_SoundEnter); | |||||
RegisterSetting("sound_leave", m_SoundLeave); | |||||
RegisterSetting("sound_opened", m_SoundOpened); | |||||
// Setting "sprite" is registered by CList and used as the background | // Setting "sprite" is registered by CList and used as the background | ||||
AddSetting<CGUISpriteInstance>("sprite_disabled"); | RegisterSetting("sprite_disabled", m_SpriteDisabled); | ||||
AddSetting<CGUISpriteInstance>("sprite_list"); // Background of the drop down list | RegisterSetting("sprite_list", m_SpriteList); // Background of the drop down list | ||||
AddSetting<CGUISpriteInstance>("sprite2"); // Button that sits to the right | RegisterSetting("sprite2", m_Sprite2); // Button that sits to the right | ||||
AddSetting<CGUISpriteInstance>("sprite2_over"); | RegisterSetting("sprite2_over", m_Sprite2Over); | ||||
AddSetting<CGUISpriteInstance>("sprite2_pressed"); | RegisterSetting("sprite2_pressed", m_Sprite2Pressed); | ||||
AddSetting<CGUISpriteInstance>("sprite2_disabled"); | RegisterSetting("sprite2_disabled", m_Sprite2Disabled); | ||||
AddSetting<EVAlign>("text_valign"); | RegisterSetting("textcolor_disabled", m_TextColorDisabled); | ||||
RegisterSetting("text_valign", m_TextVAlign); | |||||
// Add these in CList! And implement TODO | // Add these in CList! And implement TODO | ||||
//AddSetting<CGUIColor>("textcolor_over"); | //RegisterSetting("textcolor_over"); | ||||
//AddSetting<CGUIColor>("textcolor_pressed"); | //RegisterSetting("textcolor_pressed"); | ||||
AddSetting<CGUIColor>("textcolor_disabled"); | |||||
// Scrollbar is forced to be true. | // Scrollbar is forced to be true. | ||||
SetSetting<bool>("scrollbar", true, true); | SetSetting<bool>("scrollbar", true, true); | ||||
} | } | ||||
CDropDown::~CDropDown() | CDropDown::~CDropDown() | ||||
{ | { | ||||
} | } | ||||
Show All 38 Lines | case GUIM_MOUSE_MOTION: | ||||
if (!m_Open) | if (!m_Open) | ||||
break; | break; | ||||
CPos mouse = m_pGUI.GetMousePos(); | CPos mouse = m_pGUI.GetMousePos(); | ||||
if (!GetListRect().PointInside(mouse)) | if (!GetListRect().PointInside(mouse)) | ||||
break; | break; | ||||
const CGUIList& pList = GetSetting<CGUIList>("list"); | const float scroll = m_ScrollBar ? GetScrollBar(0).GetPos() : 0.f; | ||||
const bool scrollbar = GetSetting<bool>("scrollbar"); | |||||
const float scroll = scrollbar ? GetScrollBar(0).GetPos() : 0.f; | |||||
CRect rect = GetListRect(); | CRect rect = GetListRect(); | ||||
mouse.y += scroll; | mouse.y += scroll; | ||||
int set = -1; | int set = -1; | ||||
for (int i = 0; i < static_cast<int>(pList.m_Items.size()); ++i) | for (int i = 0; i < static_cast<int>(m_List.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] && | ||||
// mouse is not over scroll-bar | // mouse is not over scroll-bar | ||||
(m_HideScrollBar || | (m_HideScrollBar || | ||||
mouse.x < GetScrollBar(0).GetOuterRect().left || | mouse.x < GetScrollBar(0).GetOuterRect().left || | ||||
mouse.x > GetScrollBar(0).GetOuterRect().right)) | mouse.x > GetScrollBar(0).GetOuterRect().right)) | ||||
{ | { | ||||
set = i; | set = i; | ||||
} | } | ||||
} | } | ||||
if (set != -1) | if (set != -1) | ||||
{ | { | ||||
m_ElementHighlight = set; | m_ElementHighlight = set; | ||||
//UpdateAutoScroll(); | //UpdateAutoScroll(); | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
case GUIM_MOUSE_ENTER: | case GUIM_MOUSE_ENTER: | ||||
{ | { | ||||
if (GetSetting<bool>("enabled")) | if (m_Enabled) | ||||
PlaySound("sound_enter"); | PlaySound(m_SoundEnter); | ||||
break; | break; | ||||
} | } | ||||
case GUIM_MOUSE_LEAVE: | case GUIM_MOUSE_LEAVE: | ||||
{ | { | ||||
m_ElementHighlight = GetSetting<i32>("selected"); | m_ElementHighlight = m_Selected; | ||||
if (GetSetting<bool>("enabled")) | if (m_Enabled) | ||||
PlaySound("sound_leave"); | PlaySound(m_SoundLeave); | ||||
break; | break; | ||||
} | } | ||||
// We can't inherent this routine from CList, because we need to include | // We can't inherent this routine from CList, because we need to include | ||||
// a mouse click to open the dropdown, also the coordinates are changed. | // a mouse click to open the dropdown, also the coordinates are changed. | ||||
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; | ||||
} | } | ||||
if (!m_Open) | if (!m_Open) | ||||
{ | { | ||||
const CGUIList& pList = GetSetting<CGUIList>("list"); | if (m_List.m_Items.empty()) | ||||
if (pList.m_Items.empty()) | |||||
return; | return; | ||||
m_Open = true; | m_Open = true; | ||||
GetScrollBar(0).SetZ(GetBufferedZ()); | GetScrollBar(0).SetZ(GetBufferedZ()); | ||||
m_ElementHighlight = GetSetting<i32>("selected"); | m_ElementHighlight = m_Selected; | ||||
// Start at the position of the selected item, if possible. | // Start at the position of the selected item, if possible. | ||||
GetScrollBar(0).SetPos(m_ItemsYPositions.empty() ? 0 : m_ItemsYPositions[m_ElementHighlight] - 60); | GetScrollBar(0).SetPos(m_ItemsYPositions.empty() ? 0 : m_ItemsYPositions[m_ElementHighlight] - 60); | ||||
PlaySound("sound_opened"); | PlaySound(m_SoundOpened); | ||||
return; // overshadow | return; // overshadow | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
const CPos& mouse = m_pGUI.GetMousePos(); | const CPos& mouse = m_pGUI.GetMousePos(); | ||||
// If the regular area is pressed, then abort, and close. | // If the regular area is pressed, then abort, and close. | ||||
if (m_CachedActualSize.PointInside(mouse)) | if (m_CachedActualSize.PointInside(mouse)) | ||||
{ | { | ||||
m_Open = false; | m_Open = false; | ||||
GetScrollBar(0).SetZ(GetBufferedZ()); | GetScrollBar(0).SetZ(GetBufferedZ()); | ||||
PlaySound("sound_closed"); | PlaySound(m_SoundClosed); | ||||
return; // overshadow | return; // overshadow | ||||
} | } | ||||
if (m_HideScrollBar || | if (m_HideScrollBar || | ||||
mouse.x < GetScrollBar(0).GetOuterRect().left || | mouse.x < GetScrollBar(0).GetOuterRect().left || | ||||
mouse.x > GetScrollBar(0).GetOuterRect().right || | mouse.x > GetScrollBar(0).GetOuterRect().right || | ||||
mouse.y < GetListRect().top) | mouse.y < GetListRect().top) | ||||
{ | { | ||||
m_Open = false; | m_Open = false; | ||||
GetScrollBar(0).SetZ(GetBufferedZ()); | GetScrollBar(0).SetZ(GetBufferedZ()); | ||||
} | } | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
case GUIM_MOUSE_WHEEL_DOWN: | case GUIM_MOUSE_WHEEL_DOWN: | ||||
{ | { | ||||
// Don't switch elements by scrolling when open, causes a confusing interaction between this and the scrollbar. | // Don't switch elements by scrolling when open, causes a confusing interaction between this and the scrollbar. | ||||
if (m_Open || !GetSetting<bool>("enabled")) | if (m_Open || !m_Enabled) | ||||
break; | break; | ||||
m_ElementHighlight = GetSetting<i32>("selected"); | m_ElementHighlight = m_Selected; | ||||
if (m_ElementHighlight + 1 >= (int)m_ItemsYPositions.size() - 1) | if (m_ElementHighlight + 1 >= (int)m_ItemsYPositions.size() - 1) | ||||
break; | break; | ||||
++m_ElementHighlight; | ++m_ElementHighlight; | ||||
SetSetting<i32>("selected", m_ElementHighlight, true); | SetSetting<i32>("selected", m_ElementHighlight, true); | ||||
break; | break; | ||||
} | } | ||||
case GUIM_MOUSE_WHEEL_UP: | case GUIM_MOUSE_WHEEL_UP: | ||||
{ | { | ||||
// Don't switch elements by scrolling when open, causes a confusing interaction between this and the scrollbar. | // Don't switch elements by scrolling when open, causes a confusing interaction between this and the scrollbar. | ||||
if (m_Open || !GetSetting<bool>("enabled")) | if (m_Open || !m_Enabled) | ||||
break; | break; | ||||
m_ElementHighlight = GetSetting<i32>("selected"); | m_ElementHighlight = m_Selected; | ||||
if (m_ElementHighlight - 1 < 0) | if (m_ElementHighlight - 1 < 0) | ||||
break; | break; | ||||
--m_ElementHighlight; | --m_ElementHighlight; | ||||
SetSetting<i32>("selected", m_ElementHighlight, true); | SetSetting<i32>("selected", m_ElementHighlight, true); | ||||
break; | break; | ||||
} | } | ||||
case GUIM_LOST_FOCUS: | case GUIM_LOST_FOCUS: | ||||
{ | { | ||||
if (m_Open) | if (m_Open) | ||||
PlaySound("sound_closed"); | PlaySound(m_SoundClosed); | ||||
m_Open = false; | m_Open = false; | ||||
break; | break; | ||||
} | } | ||||
case GUIM_LOAD: | case GUIM_LOAD: | ||||
SetupListRect(); | SetupListRect(); | ||||
break; | break; | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | default: | ||||
// maximal amount of characters is 100, which imo is far more than enough. | // maximal amount of characters is 100, which imo is far more than enough. | ||||
if (timer_Time() - m_TimeOfLastInput > 1.0 || m_InputBuffer.length() >= 100) | if (timer_Time() - m_TimeOfLastInput > 1.0 || m_InputBuffer.length() >= 100) | ||||
m_InputBuffer = szChar; | m_InputBuffer = szChar; | ||||
else | else | ||||
m_InputBuffer += szChar; | m_InputBuffer += szChar; | ||||
m_TimeOfLastInput = timer_Time(); | m_TimeOfLastInput = timer_Time(); | ||||
const CGUIList& pList = GetSetting<CGUIList>("list"); | |||||
// let's look for the closest element | // let's look for the closest element | ||||
// basically it's alphabetic order and "as many letters as we can get". | // basically it's alphabetic order and "as many letters as we can get". | ||||
int closest = -1; | int closest = -1; | ||||
int bestIndex = -1; | int bestIndex = -1; | ||||
int difference = 1250; | int difference = 1250; | ||||
for (int i = 0; i < static_cast<int>(pList.m_Items.size()); ++i) | for (int i = 0; i < static_cast<int>(m_List.m_Items.size()); ++i) | ||||
{ | { | ||||
int indexOfDifference = 0; | int indexOfDifference = 0; | ||||
int diff = 0; | int diff = 0; | ||||
for (size_t j = 0; j < m_InputBuffer.length(); ++j) | for (size_t j = 0; j < m_InputBuffer.length(); ++j) | ||||
{ | { | ||||
diff = std::abs(static_cast<int>(pList.m_Items[i].GetRawString().LowerCase()[j]) - static_cast<int>(m_InputBuffer[j])); | diff = std::abs(static_cast<int>(m_List.m_Items[i].GetRawString().LowerCase()[j]) - static_cast<int>(m_InputBuffer[j])); | ||||
if (diff == 0) | if (diff == 0) | ||||
indexOfDifference = j+1; | indexOfDifference = j+1; | ||||
else | else | ||||
break; | break; | ||||
} | } | ||||
if (indexOfDifference > bestIndex || (indexOfDifference >= bestIndex && diff < difference)) | if (indexOfDifference > bestIndex || (indexOfDifference >= bestIndex && diff < difference)) | ||||
{ | { | ||||
bestIndex = indexOfDifference; | bestIndex = indexOfDifference; | ||||
Show All 13 Lines | default: | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
if (CList::ManuallyHandleEvent(ev) == IN_HANDLED) | if (CList::ManuallyHandleEvent(ev) == IN_HANDLED) | ||||
result = IN_HANDLED; | result = IN_HANDLED; | ||||
if (update_highlight) | if (update_highlight) | ||||
m_ElementHighlight = GetSetting<i32>("selected"); | m_ElementHighlight = m_Selected; | ||||
return result; | return result; | ||||
} | } | ||||
void CDropDown::SetupListRect() | void CDropDown::SetupListRect() | ||||
{ | { | ||||
extern int g_yres; | extern int g_yres; | ||||
extern float g_GuiScale; | extern float g_GuiScale; | ||||
const float yres = g_yres / g_GuiScale; | const float yres = g_yres / g_GuiScale; | ||||
const float size = GetSetting<float>("dropdown_size"); | |||||
const float buffer = GetSetting<float>("dropdown_buffer"); | |||||
const u32 minimumVisibleItems = GetSetting<u32>("minimum_visible_items"); | |||||
if (m_ItemsYPositions.empty()) | if (m_ItemsYPositions.empty()) | ||||
{ | { | ||||
m_CachedListRect = CRect(m_CachedActualSize.left, m_CachedActualSize.bottom + buffer, | m_CachedListRect = CRect(m_CachedActualSize.left, m_CachedActualSize.bottom + m_DropDownBuffer, | ||||
m_CachedActualSize.right, m_CachedActualSize.bottom + buffer + size); | m_CachedActualSize.right, m_CachedActualSize.bottom + m_DropDownBuffer + m_DropDownSize); | ||||
m_HideScrollBar = false; | m_HideScrollBar = false; | ||||
} | } | ||||
// Too many items so use a scrollbar | // Too many items so use a scrollbar | ||||
else if (m_ItemsYPositions.back() > size) | else if (m_ItemsYPositions.back() > m_DropDownSize) | ||||
{ | { | ||||
// Place items below if at least some items can be placed below | // Place items below if at least some items can be placed below | ||||
if (m_CachedActualSize.bottom + buffer + size <= yres) | if (m_CachedActualSize.bottom + m_DropDownBuffer + m_DropDownSize <= yres) | ||||
m_CachedListRect = CRect(m_CachedActualSize.left, m_CachedActualSize.bottom + buffer, | m_CachedListRect = CRect(m_CachedActualSize.left, m_CachedActualSize.bottom + m_DropDownBuffer, | ||||
m_CachedActualSize.right, m_CachedActualSize.bottom + buffer + size); | m_CachedActualSize.right, m_CachedActualSize.bottom + m_DropDownBuffer + m_DropDownSize); | ||||
else if ((m_ItemsYPositions.size() > minimumVisibleItems && yres - m_CachedActualSize.bottom - buffer >= m_ItemsYPositions[minimumVisibleItems]) || | else if ((m_ItemsYPositions.size() > m_MinimumVisibleItems && yres - m_CachedActualSize.bottom - m_DropDownBuffer >= m_ItemsYPositions[m_MinimumVisibleItems]) || | ||||
m_CachedActualSize.top < yres - m_CachedActualSize.bottom) | m_CachedActualSize.top < yres - m_CachedActualSize.bottom) | ||||
m_CachedListRect = CRect(m_CachedActualSize.left, m_CachedActualSize.bottom + buffer, | m_CachedListRect = CRect(m_CachedActualSize.left, m_CachedActualSize.bottom + m_DropDownBuffer, | ||||
m_CachedActualSize.right, yres); | m_CachedActualSize.right, yres); | ||||
// Not enough space below, thus place items above | // Not enough space below, thus place items above | ||||
else | else | ||||
m_CachedListRect = CRect(m_CachedActualSize.left, std::max(0.f, m_CachedActualSize.top - buffer - size), | m_CachedListRect = CRect(m_CachedActualSize.left, std::max(0.f, m_CachedActualSize.top - m_DropDownBuffer - m_DropDownSize), | ||||
m_CachedActualSize.right, m_CachedActualSize.top - buffer); | m_CachedActualSize.right, m_CachedActualSize.top - m_DropDownBuffer); | ||||
m_HideScrollBar = false; | m_HideScrollBar = false; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
// Enough space below, no scrollbar needed | // Enough space below, no scrollbar needed | ||||
if (m_CachedActualSize.bottom + buffer + m_ItemsYPositions.back() <= yres) | if (m_CachedActualSize.bottom + m_DropDownBuffer + m_ItemsYPositions.back() <= yres) | ||||
{ | { | ||||
m_CachedListRect = CRect(m_CachedActualSize.left, m_CachedActualSize.bottom + buffer, | m_CachedListRect = CRect(m_CachedActualSize.left, m_CachedActualSize.bottom + m_DropDownBuffer, | ||||
m_CachedActualSize.right, m_CachedActualSize.bottom + buffer + m_ItemsYPositions.back()); | m_CachedActualSize.right, m_CachedActualSize.bottom + m_DropDownBuffer + m_ItemsYPositions.back()); | ||||
m_HideScrollBar = true; | m_HideScrollBar = true; | ||||
} | } | ||||
// Enough space below for some items, but not all, so place items below and use a scrollbar | // Enough space below for some items, but not all, so place items below and use a scrollbar | ||||
else if ((m_ItemsYPositions.size() > minimumVisibleItems && yres - m_CachedActualSize.bottom - buffer >= m_ItemsYPositions[minimumVisibleItems]) || | else if ((m_ItemsYPositions.size() > m_MinimumVisibleItems && yres - m_CachedActualSize.bottom - m_DropDownBuffer >= m_ItemsYPositions[m_MinimumVisibleItems]) || | ||||
m_CachedActualSize.top < yres - m_CachedActualSize.bottom) | m_CachedActualSize.top < yres - m_CachedActualSize.bottom) | ||||
{ | { | ||||
m_CachedListRect = CRect(m_CachedActualSize.left, m_CachedActualSize.bottom + buffer, | m_CachedListRect = CRect(m_CachedActualSize.left, m_CachedActualSize.bottom + m_DropDownBuffer, | ||||
m_CachedActualSize.right, yres); | m_CachedActualSize.right, yres); | ||||
m_HideScrollBar = false; | m_HideScrollBar = false; | ||||
} | } | ||||
// Not enough space below, thus place items above. Hide the scrollbar accordingly | // Not enough space below, thus place items above. Hide the scrollbar accordingly | ||||
else | else | ||||
{ | { | ||||
m_CachedListRect = CRect(m_CachedActualSize.left, std::max(0.f, m_CachedActualSize.top - buffer - m_ItemsYPositions.back()), | m_CachedListRect = CRect(m_CachedActualSize.left, std::max(0.f, m_CachedActualSize.top - m_DropDownBuffer - m_ItemsYPositions.back()), | ||||
m_CachedActualSize.right, m_CachedActualSize.top - buffer); | m_CachedActualSize.right, m_CachedActualSize.top - m_DropDownBuffer); | ||||
m_HideScrollBar = m_CachedActualSize.top > m_ItemsYPositions.back() + buffer; | m_HideScrollBar = m_CachedActualSize.top > m_ItemsYPositions.back() + m_DropDownBuffer; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
CRect CDropDown::GetListRect() const | CRect CDropDown::GetListRect() const | ||||
{ | { | ||||
return m_CachedListRect; | return m_CachedListRect; | ||||
} | } | ||||
bool CDropDown::IsMouseOver() const | bool CDropDown::IsMouseOver() const | ||||
{ | { | ||||
if (m_Open) | if (m_Open) | ||||
{ | { | ||||
CRect rect(m_CachedActualSize.left, std::min(m_CachedActualSize.top, GetListRect().top), | CRect rect(m_CachedActualSize.left, std::min(m_CachedActualSize.top, GetListRect().top), | ||||
m_CachedActualSize.right, std::max(m_CachedActualSize.bottom, GetListRect().bottom)); | m_CachedActualSize.right, std::max(m_CachedActualSize.bottom, GetListRect().bottom)); | ||||
return rect.PointInside(m_pGUI.GetMousePos()); | return rect.PointInside(m_pGUI.GetMousePos()); | ||||
} | } | ||||
else | else | ||||
return m_CachedActualSize.PointInside(m_pGUI.GetMousePos()); | return m_CachedActualSize.PointInside(m_pGUI.GetMousePos()); | ||||
} | } | ||||
void CDropDown::Draw() | void CDropDown::Draw() | ||||
{ | { | ||||
const float bz = GetBufferedZ(); | const float bz = GetBufferedZ(); | ||||
const float button_width = GetSetting<float>("button_width"); | const CGUISpriteInstance& sprite = m_Enabled ? m_Sprite : m_SpriteDisabled; | ||||
const bool enabled = GetSetting<bool>("enabled"); | |||||
const int cell_id = GetSetting<i32>("cell_id"); | |||||
const int selected = GetSetting<i32>("selected"); | |||||
CGUISpriteInstance& sprite = GetSetting<CGUISpriteInstance>(enabled ? "sprite" : "sprite_disabled"); | |||||
CGUISpriteInstance& sprite2 = GetSetting<CGUISpriteInstance>("sprite2"); | |||||
m_pGUI.DrawSprite(sprite, cell_id, bz, m_CachedActualSize); | m_pGUI.DrawSprite(sprite, m_CellID, bz, m_CachedActualSize); | ||||
if (button_width > 0.f) | if (m_ButtonWidth > 0.f) | ||||
{ | { | ||||
CRect rect(m_CachedActualSize.right-button_width, m_CachedActualSize.top, | CRect rect(m_CachedActualSize.right - m_ButtonWidth, m_CachedActualSize.top, | ||||
m_CachedActualSize.right, m_CachedActualSize.bottom); | m_CachedActualSize.right, m_CachedActualSize.bottom); | ||||
if (!enabled) | if (!m_Enabled) | ||||
{ | { | ||||
CGUISpriteInstance& sprite2_second = GetSetting<CGUISpriteInstance>("sprite2_disabled"); | m_pGUI.DrawSprite(m_Sprite2Disabled || m_Sprite2, m_CellID, bz + 0.05f, rect); | ||||
m_pGUI.DrawSprite(sprite2_second || sprite2, cell_id, bz + 0.05f, rect); | |||||
} | } | ||||
else if (m_Open) | else if (m_Open) | ||||
{ | { | ||||
CGUISpriteInstance& sprite2_second = GetSetting<CGUISpriteInstance>("sprite2_pressed"); | m_pGUI.DrawSprite(m_Sprite2Pressed || m_Sprite2, m_CellID, bz + 0.05f, rect); | ||||
m_pGUI.DrawSprite(sprite2_second || sprite2, cell_id, bz + 0.05f, rect); | |||||
} | } | ||||
else if (m_MouseHovering) | else if (m_MouseHovering) | ||||
{ | { | ||||
CGUISpriteInstance& sprite2_second = GetSetting<CGUISpriteInstance>("sprite2_over"); | m_pGUI.DrawSprite(m_Sprite2Over || m_Sprite2, m_CellID, bz + 0.05f, rect); | ||||
m_pGUI.DrawSprite(sprite2_second || sprite2, cell_id, bz + 0.05f, rect); | |||||
} | } | ||||
else | else | ||||
m_pGUI.DrawSprite(sprite2, cell_id, bz + 0.05f, rect); | m_pGUI.DrawSprite(m_Sprite2, m_CellID, bz + 0.05f, rect); | ||||
} | } | ||||
if (selected != -1) // TODO: Maybe check validity completely? | if (m_Selected != -1) // TODO: Maybe check validity completely? | ||||
{ | { | ||||
CRect cliparea(m_CachedActualSize.left, m_CachedActualSize.top, | CRect cliparea(m_CachedActualSize.left, m_CachedActualSize.top, | ||||
m_CachedActualSize.right-button_width, m_CachedActualSize.bottom); | m_CachedActualSize.right - m_ButtonWidth, m_CachedActualSize.bottom); | ||||
const CGUIColor& color = GetSetting<CGUIColor>(enabled ? "textcolor_selected" : "textcolor_disabled"); | |||||
CPos pos(m_CachedActualSize.left, m_CachedActualSize.top); | CPos pos(m_CachedActualSize.left, m_CachedActualSize.top); | ||||
DrawText(selected, color, pos, bz+0.1f, cliparea); | DrawText(m_Selected, m_Enabled ? m_TextColorSelected : m_TextColorDisabled, pos, bz + 0.1f, cliparea); | ||||
} | } | ||||
// Disable scrollbar during drawing without sending a setting-changed message | // Disable scrollbar during drawing without sending a setting-changed message | ||||
bool& scrollbar = GetSetting<bool>("scrollbar"); | bool old = m_ScrollBar; | ||||
bool old = scrollbar; | |||||
if (m_Open) | if (m_Open) | ||||
{ | { | ||||
// TODO: drawScrollbar as an argument of DrawList? | |||||
if (m_HideScrollBar) | if (m_HideScrollBar) | ||||
scrollbar = false; | m_ScrollBar = false; | ||||
DrawList(m_ElementHighlight, "sprite_list", "sprite_selectarea", "textcolor"); | DrawList(m_ElementHighlight, m_SpriteList, m_SpriteSelectArea, m_TextColor); | ||||
if (m_HideScrollBar) | if (m_HideScrollBar) | ||||
scrollbar = old; | m_ScrollBar = old; | ||||
} | } | ||||
} | } | ||||
// When a dropdown list is opened, it needs to be visible above all the other | // When a dropdown list is opened, it needs to be visible above all the other | ||||
// controls on the page. The only way I can think of to do this is to increase | // controls on the page. The only way I can think of to do this is to increase | ||||
// its z value when opened, so that it's probably on top. | // its z value when opened, so that it's probably on top. | ||||
float CDropDown::GetBufferedZ() const | float CDropDown::GetBufferedZ() const | ||||
{ | { | ||||
float bz = CList::GetBufferedZ(); | float bz = CList::GetBufferedZ(); | ||||
if (m_Open) | if (m_Open) | ||||
return std::min(bz + 500.f, 1000.f); // TODO - don't use magic number for max z value | return std::min(bz + 500.f, 1000.f); // TODO - don't use magic number for max z value | ||||
else | else | ||||
return bz; | return bz; | ||||
} | } |
Wildfire Games · Phabricator