This commit is contained in:
cracyc 2016-07-08 10:11:54 -05:00
commit 0e8446aff6
7 changed files with 56 additions and 63 deletions

View File

@ -60,7 +60,7 @@ void menu_barcode_reader::populate()
item_append(current_display_name(), "", current_display_flags(), ITEMREF_SELECT_READER); item_append(current_display_name(), "", current_display_flags(), ITEMREF_SELECT_READER);
// append the "New Barcode" item // append the "New Barcode" item
if (get_selection() == ITEMREF_NEW_BARCODE) if (get_selection_ref() == ITEMREF_NEW_BARCODE)
{ {
buffer.append(m_barcode_buffer); buffer.append(m_barcode_buffer);
new_barcode = buffer.c_str(); new_barcode = buffer.c_str();
@ -129,7 +129,7 @@ void menu_barcode_reader::handle()
break; break;
case IPT_SPECIAL: case IPT_SPECIAL:
if (get_selection() == ITEMREF_NEW_BARCODE) if (get_selection_ref() == ITEMREF_NEW_BARCODE)
{ {
auto const buflen = std::strlen(m_barcode_buffer); auto const buflen = std::strlen(m_barcode_buffer);

View File

@ -189,7 +189,7 @@ void menu_file_create::populate()
const std::string *new_image_name; const std::string *new_image_name;
// append the "New Image Name" item // append the "New Image Name" item
if (get_selection() == ITEMREF_NEW_IMAGE_NAME) if (get_selection_ref() == ITEMREF_NEW_IMAGE_NAME)
{ {
buffer = m_filename + "_"; buffer = m_filename + "_";
new_image_name = &buffer; new_image_name = &buffer;
@ -246,7 +246,7 @@ void menu_file_create::handle()
break; break;
case IPT_SPECIAL: case IPT_SPECIAL:
if (get_selection() == ITEMREF_NEW_IMAGE_NAME) if (get_selection_ref() == ITEMREF_NEW_IMAGE_NAME)
{ {
input_character(m_filename, event->unichar, &osd_is_valid_filename_char); input_character(m_filename, event->unichar, &osd_is_valid_filename_char);
reset(reset_options::REMEMBER_POSITION); reset(reset_options::REMEMBER_POSITION);

View File

@ -460,7 +460,7 @@ void menu_file_selector::handle()
if (update_selected) if (update_selected)
{ {
const file_selector_entry *cur_selected = (const file_selector_entry *)get_selection(); file_selector_entry const *const cur_selected(reinterpret_cast<file_selector_entry const *>(get_selection_ref()));
// check for entries which matches our m_filename_buffer: // check for entries which matches our m_filename_buffer:
for (auto &entry : m_entrylist) for (auto &entry : m_entrylist)

View File

@ -211,6 +211,8 @@ menu::menu(mame_ui_manager &mui, render_container *_container)
, m_event() , m_event()
, m_pool(nullptr) , m_pool(nullptr)
, m_focus(focused_menu::main) , m_focus(focused_menu::main)
, m_resetpos(0)
, m_resetref(nullptr)
{ {
container = _container; container = _container;
@ -244,12 +246,12 @@ menu::~menu()
void menu::reset(reset_options options) void menu::reset(reset_options options)
{ {
// based on the reset option, set the reset info // based on the reset option, set the reset info
resetpos = 0; m_resetpos = 0;
resetref = nullptr; m_resetref = nullptr;
if (options == reset_options::REMEMBER_POSITION) if (options == reset_options::REMEMBER_POSITION)
resetpos = selected; m_resetpos = selected;
else if (options == reset_options::REMEMBER_REF) else if (options == reset_options::REMEMBER_REF)
resetref = item[selected].ref; m_resetref = get_selection_ref();
// reset all the pools and the item.size() back to 0 // reset all the pools and the item.size() back to 0
for (pool *ppool = m_pool; ppool != nullptr; ppool = ppool->next) for (pool *ppool = m_pool; ppool != nullptr; ppool = ppool->next)
@ -368,9 +370,9 @@ void menu::item_append(std::string &&text, std::string &&subtext, UINT32 flags,
item.emplace_back(std::move(pitem)); item.emplace_back(std::move(pitem));
// update the selection if we need to // update the selection if we need to
if (resetpos == index || (resetref != nullptr && resetref == ref)) if (m_resetpos == index || (m_resetref != nullptr && m_resetref == ref))
selected = index; selected = index;
if (resetpos == item.size() - 1) if (m_resetpos == (item.size() - 1))
selected = item.size() - 1; selected = item.size() - 1;
} }
@ -420,7 +422,7 @@ const menu::event *menu::process(UINT32 flags, float x0, float y0)
} }
// update the selected item in the event // update the selected item in the event
if (m_event.iptkey != IPT_INVALID && selected >= 0 && selected < item.size()) if ((m_event.iptkey != IPT_INVALID) && selection_valid())
{ {
m_event.itemref = item[selected].ref; m_event.itemref = item[selected].ref;
m_event.type = item[selected].type; m_event.type = item[selected].type;
@ -462,17 +464,6 @@ void *menu::m_pool_alloc(size_t size)
} }
//-------------------------------------------------
// get_selection - retrieves the index
// of the currently selected menu item
//-------------------------------------------------
void *menu::get_selection()
{
return (selected >= 0 && selected < item.size()) ? item[selected].ref : nullptr;
}
//------------------------------------------------- //-------------------------------------------------
// set_selection - changes the index // set_selection - changes the index
// of the currently selected menu item // of the currently selected menu item
@ -482,12 +473,14 @@ void menu::set_selection(void *selected_itemref)
{ {
selected = -1; selected = -1;
for (int itemnum = 0; itemnum < item.size(); itemnum++) for (int itemnum = 0; itemnum < item.size(); itemnum++)
{
if (item[itemnum].ref == selected_itemref) if (item[itemnum].ref == selected_itemref)
{ {
selected = itemnum; selected = itemnum;
break; break;
} }
} }
}
@ -570,7 +563,7 @@ void menu::draw(UINT32 flags, float origx0, float origy0)
if (!customonly) if (!customonly)
ui().draw_outlined_box(container, x1, y1, x2, y2, UI_BACKGROUND_COLOR); ui().draw_outlined_box(container, x1, y1, x2, y2, UI_BACKGROUND_COLOR);
if (top_line < 0 || selected == 0) if (top_line < 0 || is_first_selected())
top_line = 0; top_line = 0;
if (selected >= (top_line + visible_lines)) if (selected >= (top_line + visible_lines))
top_line = selected - (visible_lines / 2); top_line = selected - (visible_lines / 2);
@ -778,7 +771,7 @@ void menu::draw(UINT32 flags, float origx0, float origy0)
} }
// if there is something special to add, do it by calling the virtual method // if there is something special to add, do it by calling the virtual method
custom_render((selected >= 0 && selected < item.size()) ? item[selected].ref : nullptr, customtop, custombottom, x1, y1, x2, y2); custom_render(get_selection_ref(), customtop, custombottom, x1, y1, x2, y2);
} }
void menu::custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2) void menu::custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2)
@ -907,7 +900,7 @@ void menu::handle_events(UINT32 flags)
{ {
selected = hover; selected = hover;
m_event.iptkey = IPT_UI_SELECT; m_event.iptkey = IPT_UI_SELECT;
if (selected == item.size() - 1) if (is_last_selected())
{ {
m_event.iptkey = IPT_UI_CANCEL; m_event.iptkey = IPT_UI_CANCEL;
menu::stack_pop(machine()); menu::stack_pop(machine());
@ -927,7 +920,7 @@ void menu::handle_events(UINT32 flags)
top_line -= local_menu_event.num_lines; top_line -= local_menu_event.num_lines;
return; return;
} }
(selected == 0) ? selected = top_line = item.size() - 1 : selected -= local_menu_event.num_lines; is_first_selected() ? selected = top_line = item.size() - 1 : selected -= local_menu_event.num_lines;
validate_selection(-1); validate_selection(-1);
top_line -= (selected <= top_line && top_line != 0); top_line -= (selected <= top_line && top_line != 0);
if (selected <= top_line && visitems != visible_lines) if (selected <= top_line && visitems != visible_lines)
@ -940,7 +933,7 @@ void menu::handle_events(UINT32 flags)
top_line += local_menu_event.num_lines; top_line += local_menu_event.num_lines;
return; return;
} }
(selected == item.size() - 1) ? selected = top_line = 0 : selected += local_menu_event.num_lines; is_last_selected() ? selected = top_line = 0 : selected += local_menu_event.num_lines;
validate_selection(1); validate_selection(1);
top_line += (selected >= top_line + visitems + (top_line != 0)); top_line += (selected >= top_line + visitems + (top_line != 0));
if (selected >= (top_line + visitems + (top_line != 0))) if (selected >= (top_line + visitems + (top_line != 0)))
@ -981,7 +974,7 @@ void menu::handle_keys(UINT32 flags)
// if we hit select, return TRUE or pop the stack, depending on the item // if we hit select, return TRUE or pop the stack, depending on the item
if (exclusive_input_pressed(IPT_UI_SELECT, 0)) if (exclusive_input_pressed(IPT_UI_SELECT, 0))
{ {
if (selected == item.size() - 1) if (is_last_selected())
{ {
m_event.iptkey = IPT_UI_CANCEL; m_event.iptkey = IPT_UI_CANCEL;
menu::stack_pop(machine()); menu::stack_pop(machine());
@ -1025,7 +1018,7 @@ void menu::handle_keys(UINT32 flags)
top_line--; top_line--;
return; return;
} }
(selected == 0) ? selected = top_line = item.size() - 1 : --selected; is_first_selected() ? selected = top_line = item.size() - 1 : --selected;
validate_selection(-1); validate_selection(-1);
top_line -= (selected <= top_line && top_line != 0); top_line -= (selected <= top_line && top_line != 0);
if (selected <= top_line && visitems != visible_lines) if (selected <= top_line && visitems != visible_lines)
@ -1040,7 +1033,7 @@ void menu::handle_keys(UINT32 flags)
top_line++; top_line++;
return; return;
} }
(selected == item.size() - 1) ? selected = top_line = 0 : ++selected; is_last_selected() ? selected = top_line = 0 : ++selected;
validate_selection(1); validate_selection(1);
top_line += (selected >= top_line + visitems + (top_line != 0)); top_line += (selected >= top_line + visitems + (top_line != 0));
if (selected >= (top_line + visitems + (top_line != 0))) if (selected >= (top_line + visitems + (top_line != 0)))
@ -1484,7 +1477,7 @@ void menu::draw_select_game(UINT32 flags)
if (visible_items < visible_lines) if (visible_items < visible_lines)
visible_lines = visible_items; visible_lines = visible_items;
if (top_line < 0 || selected == 0) if (top_line < 0 || is_first_selected())
top_line = 0; top_line = 0;
if (selected < visible_items && top_line + visible_lines >= visible_items) if (selected < visible_items && top_line + visible_lines >= visible_items)
top_line = visible_items - visible_lines; top_line = visible_items - visible_lines;
@ -1633,13 +1626,13 @@ void menu::draw_select_game(UINT32 flags)
x1 = x2; x1 = x2;
x2 += right_panel_size; x2 += right_panel_size;
draw_right_panel((selected >= 0 && selected < item.size()) ? item[selected].ref : nullptr, x1, y1, x2, y2); draw_right_panel(get_selection_ref(), x1, y1, x2, y2);
x1 = primary_left - UI_BOX_LR_BORDER; x1 = primary_left - UI_BOX_LR_BORDER;
x2 = primary_left + primary_width + UI_BOX_LR_BORDER; x2 = primary_left + primary_width + UI_BOX_LR_BORDER;
// if there is something special to add, do it by calling the virtual method // if there is something special to add, do it by calling the virtual method
custom_render((selected >= 0 && selected < item.size()) ? item[selected].ref : nullptr, customtop, custombottom, x1, y1, x2, y2); custom_render(get_selection_ref(), customtop, custombottom, x1, y1, x2, y2);
// return the number of visible lines, minus 1 for top arrow and 1 for bottom arrow // return the number of visible lines, minus 1 for top arrow and 1 for bottom arrow
visitems = visible_lines - (top_line != 0) - (top_line + visible_lines != visible_items); visitems = visible_lines - (top_line != 0) - (top_line + visible_lines != visible_items);
@ -1711,7 +1704,7 @@ void menu::handle_main_keys(UINT32 flags)
// if we hit select, return TRUE or pop the stack, depending on the item // if we hit select, return TRUE or pop the stack, depending on the item
if (exclusive_input_pressed(IPT_UI_SELECT, 0)) if (exclusive_input_pressed(IPT_UI_SELECT, 0))
{ {
if (selected == item.size() - 1 && m_focus == focused_menu::main) if (is_last_selected() && m_focus == focused_menu::main)
{ {
m_event.iptkey = IPT_UI_CANCEL; m_event.iptkey = IPT_UI_CANCEL;
menu::stack_pop(machine()); menu::stack_pop(machine());
@ -1771,7 +1764,7 @@ void menu::handle_main_keys(UINT32 flags)
return; return;
} }
if (selected == visible_items + 1 || selected == 0 || ui_error) if (selected == visible_items + 1 || is_first_selected() || ui_error)
return; return;
selected--; selected--;
@ -1798,7 +1791,7 @@ void menu::handle_main_keys(UINT32 flags)
return; return;
} }
if (selected == item.size() - 1 || selected == visible_items - 1 || ui_error) if (is_last_selected() || selected == visible_items - 1 || ui_error)
return; return;
selected++; selected++;
@ -2744,7 +2737,7 @@ void menu::draw_palette_menu()
} }
// if there is something special to add, do it by calling the virtual method // if there is something special to add, do it by calling the virtual method
custom_render((selected >= 0 && selected < item.size()) ? item[selected].ref : nullptr, customtop, custombottom, x1, y1, x2, y2); custom_render(get_selection_ref(), customtop, custombottom, x1, y1, x2, y2);
// return the number of visible lines, minus 1 for top arrow and 1 for bottom arrow // return the number of visible lines, minus 1 for top arrow and 1 for bottom arrow
visitems = visible_lines - (top_line != 0) - (top_line + visible_lines != item.size()); visitems = visible_lines - (top_line != 0) - (top_line + visible_lines != item.size());
@ -2890,7 +2883,7 @@ void menu::draw_dats_menu()
} }
// if there is something special to add, do it by calling the virtual method // if there is something special to add, do it by calling the virtual method
custom_render((selected >= 0 && selected < item.size()) ? item[selected].ref : nullptr, customtop, custombottom, x1, y1, x2, y2); custom_render(get_selection_ref(), customtop, custombottom, x1, y1, x2, y2);
// return the number of visible lines, minus 1 for top arrow and 1 for bottom arrow // return the number of visible lines, minus 1 for top arrow and 1 for bottom arrow
visitems = visible_lines - (top_line != 0) - (top_line + visible_lines != visible_items); visitems = visible_lines - (top_line != 0) - (top_line + visible_lines != visible_items);

View File

@ -53,9 +53,6 @@ public:
running_machine &machine() const { return m_ui.machine(); } running_machine &machine() const { return m_ui.machine(); }
render_container *container; // render_container we render to render_container *container; // render_container we render to
int resetpos; // reset position
void *resetref; // reset reference
int selected; // which item is selected
int hover; // which item is being hovered over int hover; // which item is being hovered over
int visitems; // number of visible items int visitems; // number of visible items
float customtop; // amount of extra height to add at the top float customtop; // amount of extra height to add at the top
@ -74,12 +71,6 @@ public:
// allocate temporary memory from the menu's memory pool // allocate temporary memory from the menu's memory pool
void *m_pool_alloc(size_t size); void *m_pool_alloc(size_t size);
// retrieves the index of the currently selected menu item
void *get_selection();
// changes the index of the currently selected menu item
void set_selection(void *selected_itemref);
// request the specific handling of the game selection main menu // request the specific handling of the game selection main menu
bool is_special_main_menu() const; bool is_special_main_menu() const;
@ -253,6 +244,7 @@ protected:
int l_hover; int l_hover;
int totallines; int totallines;
int skip_main_items; int skip_main_items;
int selected; // which item is selected
menu(mame_ui_manager &mui, render_container *container); menu(mame_ui_manager &mui, render_container *container);
@ -268,6 +260,15 @@ protected:
focused_menu get_focus() const { return m_focus; } focused_menu get_focus() const { return m_focus; }
void set_focus(focused_menu focus) { m_focus = focus; } void set_focus(focused_menu focus) { m_focus = focus; }
// retrieves the ref of the currently selected menu item or nullptr
void *get_selection_ref() const { return selection_valid() ? item[selected].ref : nullptr; }
bool selection_valid() const { return (0 <= selected) && (item.size() > selected); }
bool is_first_selected() const { return 0 == selected; }
bool is_last_selected() const { return (item.size() - 1) == selected; }
// changes the index of the currently selected menu item
void set_selection(void *selected_itemref);
// draw right box // draw right box
float draw_right_box_title(float x1, float y1, float x2, float y2); float draw_right_box_title(float x1, float y1, float x2, float y2);
@ -355,6 +356,9 @@ private:
event m_event; // the UI event that occurred event m_event; // the UI event that occurred
pool *m_pool; // list of memory pools pool *m_pool; // list of memory pools
focused_menu m_focus; focused_menu m_focus;
int m_resetpos; // reset position
void *m_resetref; // reset reference
static std::vector<const game_driver *> m_old_icons; static std::vector<const game_driver *> m_old_icons;
static std::unique_ptr<menu> menu_stack; static std::unique_ptr<menu> menu_stack;

View File

@ -145,13 +145,8 @@ menu_select_game::menu_select_game(mame_ui_manager &mui, render_container *conta
menu_select_game::~menu_select_game() menu_select_game::~menu_select_game()
{ {
std::string error_string, last_driver; std::string error_string, last_driver;
const game_driver *driver = nullptr; game_driver const *const driver(isfavorite() ? nullptr : reinterpret_cast<game_driver const *>(get_selection_ref()));
ui_software_info *swinfo = nullptr; ui_software_info *const swinfo(isfavorite() ? reinterpret_cast<ui_software_info *>(get_selection_ref()) : nullptr);
ui_options &mopt = ui().options();
if (isfavorite())
swinfo = (selected >= 0 && selected < item.size()) ? (ui_software_info *)item[selected].ref : nullptr;
else
driver = (selected >= 0 && selected < item.size()) ? (const game_driver *)item[selected].ref : nullptr;
if ((FPTR)driver > skip_main_items) if ((FPTR)driver > skip_main_items)
last_driver = driver->name; last_driver = driver->name;
@ -165,6 +160,7 @@ menu_select_game::~menu_select_game()
else if (main_filters::actual == FILTER_YEAR) else if (main_filters::actual == FILTER_YEAR)
filter.append(",").append(c_year::ui[c_year::actual]); filter.append(",").append(c_year::ui[c_year::actual]);
ui_options &mopt = ui().options();
mopt.set_value(OPTION_LAST_USED_FILTER, filter.c_str(), OPTION_PRIORITY_CMDLINE, error_string); mopt.set_value(OPTION_LAST_USED_FILTER, filter.c_str(), OPTION_PRIORITY_CMDLINE, error_string);
mopt.set_value(OPTION_LAST_USED_MACHINE, last_driver.c_str(), OPTION_PRIORITY_CMDLINE, error_string); mopt.set_value(OPTION_LAST_USED_MACHINE, last_driver.c_str(), OPTION_PRIORITY_CMDLINE, error_string);
mopt.set_value(OPTION_HIDE_PANELS, ui_globals::panels_status, OPTION_PRIORITY_CMDLINE, error_string); mopt.set_value(OPTION_HIDE_PANELS, ui_globals::panels_status, OPTION_PRIORITY_CMDLINE, error_string);

View File

@ -276,8 +276,8 @@ void menu_software_list::handle()
if (update_selected) if (update_selected)
{ {
// identify the selected entry // identify the selected entry
const entry_info *cur_selected = ((FPTR)event->itemref != 1) entry_info const *const cur_selected = (FPTR(event->itemref) != 1)
? (const entry_info *)get_selection() ? reinterpret_cast<entry_info const *>(get_selection_ref())
: nullptr; : nullptr;
// loop through all entries // loop through all entries