Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/CDropDown.cpp
Show First 20 Lines • Show All 101 Lines • ▼ Show 20 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 = GUI<CGUIList>::GetSetting(this, "list"); | const CGUIList& pList = GetSetting<CGUIList>("list"); | ||||
const bool scrollbar = GUI<bool>::GetSetting(this, "scrollbar"); | const bool scrollbar = GetSetting<bool>("scrollbar"); | ||||
const float scroll = scrollbar ? GetScrollBar(0).GetPos() : 0.f; | 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>(pList.m_Items.size()); ++i) | ||||
{ | { | ||||
if (mouse.y >= rect.top + m_ItemsYPositions[i] && | if (mouse.y >= rect.top + m_ItemsYPositions[i] && | ||||
Show All 13 Lines | if (set != -1) | ||||
//UpdateAutoScroll(); | //UpdateAutoScroll(); | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
case GUIM_MOUSE_ENTER: | case GUIM_MOUSE_ENTER: | ||||
{ | { | ||||
if (GUI<bool>::GetSetting(this, "enabled")) | if (GetSetting<bool>("enabled")) | ||||
PlaySound("sound_enter"); | PlaySound("sound_enter"); | ||||
break; | break; | ||||
} | } | ||||
case GUIM_MOUSE_LEAVE: | case GUIM_MOUSE_LEAVE: | ||||
{ | { | ||||
m_ElementHighlight = GUI<int>::GetSetting(this, "selected"); | m_ElementHighlight = GetSetting<i32>("selected"); | ||||
if (GUI<bool>::GetSetting(this, "enabled")) | if (GetSetting<bool>("enabled")) | ||||
PlaySound("sound_leave"); | PlaySound("sound_leave"); | ||||
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 (!GUI<bool>::GetSetting(this, "enabled")) | if (!GetSetting<bool>("enabled")) | ||||
{ | { | ||||
PlaySound("sound_disabled"); | PlaySound("sound_disabled"); | ||||
break; | break; | ||||
} | } | ||||
if (!m_Open) | if (!m_Open) | ||||
{ | { | ||||
const CGUIList& pList = GUI<CGUIList>::GetSetting(this, "list"); | const CGUIList& pList = GetSetting<CGUIList>("list"); | ||||
if (pList.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 = GUI<int>::GetSetting(this, "selected"); | m_ElementHighlight = GetSetting<i32>("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("sound_opened"); | ||||
return; // overshadow | return; // overshadow | ||||
} | } | ||||
else | else | ||||
Show All 19 Lines | else | ||||
} | } | ||||
} | } | ||||
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 || !GUI<bool>::GetSetting(this, "enabled")) | if (m_Open || !GetSetting<bool>("enabled")) | ||||
break; | break; | ||||
m_ElementHighlight = GUI<int>::GetSetting(this, "selected"); | m_ElementHighlight = GetSetting<i32>("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; | ||||
GUI<int>::SetSetting(this, "selected", m_ElementHighlight); | GUI<int>::SetSetting(this, "selected", m_ElementHighlight); | ||||
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 || !GUI<bool>::GetSetting(this, "enabled")) | if (m_Open || !GetSetting<bool>("enabled")) | ||||
break; | break; | ||||
m_ElementHighlight = GUI<int>::GetSetting(this, "selected"); | m_ElementHighlight = GetSetting<i32>("selected"); | ||||
if (m_ElementHighlight - 1 < 0) | if (m_ElementHighlight - 1 < 0) | ||||
break; | break; | ||||
m_ElementHighlight--; | m_ElementHighlight--; | ||||
GUI<int>::SetSetting(this, "selected", m_ElementHighlight); | GUI<int>::SetSetting(this, "selected", m_ElementHighlight); | ||||
break; | break; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 64 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 = GUI<CGUIList>::GetSetting(this, "list"); | 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>(pList.m_Items.size()); ++i) | ||||
{ | { | ||||
int indexOfDifference = 0; | int indexOfDifference = 0; | ||||
Show All 25 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 = GUI<int>::GetSetting(this, "selected"); | m_ElementHighlight = GetSetting<i32>("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 = GUI<float>::GetSetting(this, "dropdown_size"); | const float size = GetSetting<float>("dropdown_size"); | ||||
const float buffer = GUI<float>::GetSetting(this, "dropdown_buffer"); | const float buffer = GetSetting<float>("dropdown_buffer"); | ||||
const u32 minimumVisibleItems = GUI<u32>::GetSetting(this, "minimum_visible_items"); | 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 + buffer, | ||||
m_CachedActualSize.right, m_CachedActualSize.bottom + buffer + size); | m_CachedActualSize.right, m_CachedActualSize.bottom + buffer + size); | ||||
m_HideScrollBar = false; | m_HideScrollBar = false; | ||||
} | } | ||||
// Too many items so use a scrollbar | // Too many items so use a scrollbar | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | bool CDropDown::IsMouseOver() const | ||||
} | } | ||||
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 = GUI<float>::GetSetting(this, "button_width"); | const float button_width = GetSetting<float>("button_width"); | ||||
const bool enabled = GUI<bool>::GetSetting(this, "enabled"); | const bool enabled = GetSetting<bool>("enabled"); | ||||
const int cell_id = GUI<int>::GetSetting(this, "cell_id"); | const int cell_id = GetSetting<i32>("cell_id"); | ||||
const int selected = GUI<int>::GetSetting(this, "selected"); | const int selected = GetSetting<i32>("selected"); | ||||
CGUISpriteInstance& sprite = GUI<CGUISpriteInstance>::GetSetting(this, enabled ? "sprite" : "sprite_disabled"); | CGUISpriteInstance& sprite = GetSetting<CGUISpriteInstance>(enabled ? "sprite" : "sprite_disabled"); | ||||
CGUISpriteInstance& sprite2 = GUI<CGUISpriteInstance>::GetSetting(this, "sprite2"); | CGUISpriteInstance& sprite2 = GetSetting<CGUISpriteInstance>("sprite2"); | ||||
m_pGUI.DrawSprite(sprite, cell_id, bz, m_CachedActualSize); | m_pGUI.DrawSprite(sprite, cell_id, bz, m_CachedActualSize); | ||||
if (button_width > 0.f) | if (button_width > 0.f) | ||||
{ | { | ||||
CRect rect(m_CachedActualSize.right-button_width, m_CachedActualSize.top, | CRect rect(m_CachedActualSize.right-button_width, m_CachedActualSize.top, | ||||
m_CachedActualSize.right, m_CachedActualSize.bottom); | m_CachedActualSize.right, m_CachedActualSize.bottom); | ||||
if (!enabled) | if (!enabled) | ||||
{ | { | ||||
CGUISpriteInstance& sprite2_second = GUI<CGUISpriteInstance>::GetSetting(this, "sprite2_disabled"); | CGUISpriteInstance& sprite2_second = GetSetting<CGUISpriteInstance>("sprite2_disabled"); | ||||
m_pGUI.DrawSprite(sprite2_second || sprite2, cell_id, 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 = GUI<CGUISpriteInstance>::GetSetting(this, "sprite2_pressed"); | CGUISpriteInstance& sprite2_second = GetSetting<CGUISpriteInstance>("sprite2_pressed"); | ||||
m_pGUI.DrawSprite(sprite2_second || sprite2, cell_id, 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 = GUI<CGUISpriteInstance>::GetSetting(this, "sprite2_over"); | CGUISpriteInstance& sprite2_second = GetSetting<CGUISpriteInstance>("sprite2_over"); | ||||
m_pGUI.DrawSprite(sprite2_second || sprite2, cell_id, 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(sprite2, cell_id, bz + 0.05f, rect); | ||||
} | } | ||||
if (selected != -1) // TODO: Maybe check validity completely? | if (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-button_width, m_CachedActualSize.bottom); | ||||
const CGUIColor& color = GUI<CGUIColor>::GetSetting(this, enabled ? "textcolor_selected" : "textcolor_disabled"); | 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(selected, color, 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 = GUI<bool>::GetSetting(this, "scrollbar"); | bool& scrollbar = GetSetting<bool>("scrollbar"); | ||||
bool old = scrollbar; | bool old = scrollbar; | ||||
if (m_Open) | if (m_Open) | ||||
{ | { | ||||
if (m_HideScrollBar) | if (m_HideScrollBar) | ||||
scrollbar = false; | scrollbar = false; | ||||
DrawList(m_ElementHighlight, "sprite_list", "sprite_selectarea", "textcolor"); | DrawList(m_ElementHighlight, "sprite_list", "sprite_selectarea", "textcolor"); | ||||
Show All 17 Lines |
Wildfire Games · Phabricator