ui/menu.cpp: Provide more helpers (nw)

This commit is contained in:
AJR 2019-05-22 13:08:45 -04:00
parent 9f1b5ec931
commit 54fb431400
4 changed files with 71 additions and 24 deletions

View File

@ -1010,8 +1010,13 @@ void menu::handle_events(uint32_t flags, event &ev)
top_line -= local_menu_event.num_lines;
return;
}
is_first_selected() ? m_selected = top_line = m_items.size() - 1 : m_selected -= local_menu_event.num_lines;
validate_selection(-1);
if (is_first_selected())
select_last_item();
else
{
m_selected -= local_menu_event.num_lines;
validate_selection(-1);
}
top_line -= (m_selected <= top_line && top_line != 0);
if (m_selected <= top_line && m_visible_items != m_visible_lines)
top_line -= local_menu_event.num_lines;
@ -1023,8 +1028,13 @@ void menu::handle_events(uint32_t flags, event &ev)
top_line += local_menu_event.num_lines;
return;
}
is_last_selected() ? m_selected = top_line = 0 : m_selected += local_menu_event.num_lines;
validate_selection(1);
if (is_last_selected())
select_first_item();
else
{
m_selected += local_menu_event.num_lines;
validate_selection(1);
}
top_line += (m_selected >= top_line + m_visible_items + (top_line != 0));
if (m_selected >= (top_line + m_visible_items + (top_line != 0)))
top_line += local_menu_event.num_lines;
@ -1108,8 +1118,13 @@ void menu::handle_keys(uint32_t flags, int &iptkey)
top_line--;
return;
}
is_first_selected() ? m_selected = top_line = m_items.size() - 1 : --m_selected;
validate_selection(-1);
if (is_first_selected())
select_last_item();
else
{
--m_selected;
validate_selection(-1);
}
top_line -= (m_selected <= top_line && top_line != 0);
if (m_selected <= top_line && m_visible_items != m_visible_lines)
top_line--;
@ -1123,8 +1138,13 @@ void menu::handle_keys(uint32_t flags, int &iptkey)
top_line++;
return;
}
is_last_selected() ? m_selected = top_line = 0 : ++m_selected;
validate_selection(1);
if (is_last_selected())
select_first_item();
else
{
++m_selected;
validate_selection(1);
}
top_line += (m_selected >= top_line + m_visible_items + (top_line != 0));
if (m_selected >= (top_line + m_visible_items + (top_line != 0)))
top_line++;
@ -1153,17 +1173,11 @@ void menu::handle_keys(uint32_t flags, int &iptkey)
// home goes to the start
if (exclusive_input_pressed(iptkey, IPT_UI_HOME, 0))
{
m_selected = top_line = 0;
validate_selection(1);
}
select_first_item();
// end goes to the last
if (exclusive_input_pressed(iptkey, IPT_UI_END, 0))
{
m_selected = top_line = m_items.size() - 1;
validate_selection(-1);
}
select_last_item();
// pause enables/disables pause
if (!ignorepause && exclusive_input_pressed(iptkey, IPT_UI_PAUSE, 0))
@ -1192,6 +1206,30 @@ void menu::handle_keys(uint32_t flags, int &iptkey)
}
//-------------------------------------------------
// select_first_item - select the first item in
// the menu
//-------------------------------------------------
void menu::select_first_item()
{
m_selected = top_line = 0;
validate_selection(1);
}
//-------------------------------------------------
// select_last_item - select the last item in the
// menu
//-------------------------------------------------
void menu::select_last_item()
{
m_selected = top_line = m_items.size() - 1;
validate_selection(-1);
}
//-------------------------------------------------
// validate_selection - validate the
// current selection and ensure it is on a

View File

@ -175,6 +175,8 @@ protected:
// changes the index of the currently selected menu item
void set_selection(void *selected_itemref);
void set_selected_index(int index) { m_selected = index; }
void select_first_item();
void select_last_item();
int hover() const { return m_hover; }
void set_hover(int index) { m_hover = index; }

View File

@ -1465,10 +1465,7 @@ void menu_select_launch::handle_keys(uint32_t flags, int &iptkey)
}
if (selected_index() < visible_items && !m_ui_error)
{
set_selected_index(0);
top_line = 0;
}
select_first_item();
}
// end goes to the last

View File

@ -115,15 +115,25 @@ void menu_sliders::handle()
// if we got here via up or page up, select the previous item
if (menu_event->iptkey == IPT_UI_UP || menu_event->iptkey == IPT_UI_PAGE_UP)
{
set_selected_index((selected_index() + item_count() - 1) % item_count());
validate_selection(-1);
if (is_first_selected())
select_last_item();
else
{
set_selected_index(selected_index() - 1);
validate_selection(-1);
}
}
// otherwise select the next item
else if (menu_event->iptkey == IPT_UI_DOWN || menu_event->iptkey == IPT_UI_PAGE_DOWN)
{
set_selected_index((selected_index() + 1) % item_count());
validate_selection(1);
if (is_last_selected())
select_first_item();
else
{
set_selected_index(selected_index() + 1);
validate_selection(1);
}
}
}
}