diff options
Diffstat (limited to 'src/emu/ui/submenu.cpp')
-rw-r--r-- | src/emu/ui/submenu.cpp | 165 |
1 files changed, 111 insertions, 54 deletions
diff --git a/src/emu/ui/submenu.cpp b/src/emu/ui/submenu.cpp index acda370cd53..a06d75adb83 100644 --- a/src/emu/ui/submenu.cpp +++ b/src/emu/ui/submenu.cpp @@ -13,6 +13,7 @@ #include "ui/submenu.h" #include "ui/utils.h" #include <limits> +#include <iterator> //------------------------------------------------- // ctor / dtor @@ -24,19 +25,65 @@ ui_submenu::ui_submenu(running_machine &machine, render_container *container, st { for (auto & sm_option : m_options) { - if (sm_option.type < ui_submenu::EMU) - continue; - - // fixme use switch - sm_option.entry = machine.options().get_entry(sm_option.name); - if (sm_option.entry == nullptr) - { - sm_option.entry = machine.ui().options().get_entry(sm_option.name); - sm_option.options = dynamic_cast<core_options*>(&machine.ui().options()); - } - else + switch (sm_option.type) { - sm_option.options = dynamic_cast<core_options*>(&machine.options()); + case ui_submenu::EMU: + sm_option.entry = machine.options().get_entry(sm_option.name); + sm_option.options = dynamic_cast<core_options*>(&machine.options()); + if (sm_option.entry->type() == OPTION_STRING) + { + sm_option.value.clear(); + std::string namestr(sm_option.entry->description()); + int lparen = namestr.find_first_of('(', 0); + int vslash = namestr.find_first_of('|', lparen + 1); + int rparen = namestr.find_first_of(')', vslash + 1); + if (lparen != -1 && vslash != -1 && rparen != -1) + { + int semi; + namestr.erase(rparen); + namestr.erase(0, lparen + 1); + while ((semi = namestr.find_first_of('|')) != -1) + { + sm_option.value.emplace_back(namestr.substr(0, semi)); + namestr.erase(0, semi + 1); + } + sm_option.value.emplace_back(namestr); + } + } + break; + case ui_submenu::OSD: + sm_option.entry = machine.options().get_entry(sm_option.name); + sm_option.options = dynamic_cast<core_options*>(&machine.options()); + if (sm_option.entry->type() == OPTION_STRING) + { + sm_option.value.clear(); + std::string descr(sm_option.entry->description()), delim(", "); + descr.erase(0, descr.find(":") + 2); + size_t p1, p2 = 0; + while ((p1 = descr.find_first_not_of(delim, p2)) != std::string::npos) + { + p2 = descr.find_first_of(delim, p1 + 1); + if (p2 != std::string::npos) + { + std::string txt(descr.substr(p1, p2 - p1)); + if (txt != "or") + sm_option.value.push_back(txt); + } + else + { + sm_option.value.push_back(descr.substr(p1)); + break; + } + } + } + break; + case ui_submenu::UI: + sm_option.entry = machine.ui().options().get_entry(sm_option.name); + sm_option.options = dynamic_cast<core_options*>(&machine.ui().options()); + break; + default: + continue; + break; } } } @@ -53,7 +100,6 @@ void ui_submenu::handle() { bool changed = false; std::string error_string, tmptxt; - int i_cur; float f_cur, f_step; // process the menu @@ -80,7 +126,7 @@ void ui_submenu::handle() if (m_event->iptkey == IPT_UI_LEFT || m_event->iptkey == IPT_UI_RIGHT) { changed = true; - i_cur = atof(sm_option->entry->value()); + int i_cur = atoi(sm_option->entry->value()); (m_event->iptkey == IPT_UI_LEFT) ? i_cur-- : i_cur++; sm_option->options->set_value(sm_option->name, i_cur, OPTION_PRIORITY_CMDLINE, error_string); sm_option->entry->mark_changed(); @@ -116,6 +162,20 @@ void ui_submenu::handle() sm_option->entry->mark_changed(); } break; + case OPTION_STRING: + if (m_event->iptkey == IPT_UI_LEFT || m_event->iptkey == IPT_UI_RIGHT) + { + changed = true; + std::string v_cur(sm_option->entry->value()); + int cur_value = std::distance(sm_option->value.begin(), std::find(sm_option->value.begin(), sm_option->value.end(), v_cur)); + if (m_event->iptkey == IPT_UI_LEFT) + v_cur = sm_option->value[--cur_value]; + else + v_cur = sm_option->value[++cur_value]; + sm_option->options->set_value(sm_option->name, v_cur.c_str(), OPTION_PRIORITY_CMDLINE, error_string); + sm_option->entry->mark_changed(); + } + break; } break; default: @@ -135,9 +195,6 @@ void ui_submenu::handle() void ui_submenu::populate() { UINT32 arrow_flags; - std::string tmptxt; - float f_min, f_max, f_cur; - int i_min, i_max, i_cur; // add options for (auto sm_option = m_options.begin(); sm_option < m_options.end(); sm_option++) @@ -164,16 +221,18 @@ void ui_submenu::populate() case OPTION_BOOLEAN: arrow_flags = sm_option->options->bool_value(sm_option->name) ? MENU_FLAG_RIGHT_ARROW : MENU_FLAG_LEFT_ARROW; item_append(_(sm_option->description), - (arrow_flags == MENU_FLAG_RIGHT_ARROW) ? "On" : "Off", - arrow_flags, - static_cast<void*>(&(*sm_option))); + (arrow_flags == MENU_FLAG_RIGHT_ARROW) ? "On" : "Off", + arrow_flags, + static_cast<void*>(&(*sm_option))); break; case OPTION_INTEGER: - i_cur = atof(sm_option->entry->value()); + { + int i_min, i_max; + int i_cur = atoi(sm_option->entry->value()); if (sm_option->entry->has_range()) { - i_min = atof(sm_option->entry->minimum()); - i_max = atof(sm_option->entry->maximum()); + i_min = atoi(sm_option->entry->minimum()); + i_max = atoi(sm_option->entry->maximum()); } else { @@ -182,12 +241,15 @@ void ui_submenu::populate() } arrow_flags = get_arrow_flags(i_min, i_max, i_cur); item_append(_(sm_option->description), - sm_option->entry->value(), - arrow_flags, - static_cast<void*>(&(*sm_option))); + sm_option->entry->value(), + arrow_flags, + static_cast<void*>(&(*sm_option))); break; + } case OPTION_FLOAT: - f_cur = atof(sm_option->entry->value()); + { + float f_min, f_max; + float f_cur = atof(sm_option->entry->value()); if (sm_option->entry->has_range()) { f_min = atof(sm_option->entry->minimum()); @@ -199,17 +261,28 @@ void ui_submenu::populate() f_max = std::numeric_limits<float>::max(); } arrow_flags = get_arrow_flags(f_min, f_max, f_cur); - tmptxt = string_format("%g", f_cur); + std::string tmptxt = string_format("%g", f_cur); + item_append(_(sm_option->description), + tmptxt.c_str(), + arrow_flags, + static_cast<void*>(&(*sm_option))); + break; + } + case OPTION_STRING: + { + std::string v_cur(sm_option->entry->value()); + int cur_value = std::distance(sm_option->value.begin(), std::find(sm_option->value.begin(), sm_option->value.end(), v_cur)); + arrow_flags = get_arrow_flags(0, sm_option->value.size() - 1, cur_value); item_append(_(sm_option->description), - tmptxt.c_str(), - arrow_flags, - static_cast<void*>(&(*sm_option))); + sm_option->options->value(sm_option->name), + arrow_flags, static_cast<void*>(&(*sm_option))); break; + } default: arrow_flags = MENU_FLAG_RIGHT_ARROW; item_append(_(sm_option->description), - sm_option->options->value(sm_option->name), - arrow_flags, static_cast<void*>(&(*sm_option))); + sm_option->options->value(sm_option->name), + arrow_flags, static_cast<void*>(&(*sm_option))); break; } break; @@ -229,14 +302,11 @@ void ui_submenu::populate() void ui_submenu::custom_render(void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2) { - static int interval = 0; - static ui_submenu::option *last_sm_option = nullptr; - float width; ui_manager &mui = machine().ui(); mui.draw_text_full(container, _(m_options[0].description), 0.0f, 0.0f, 1.0f, JUSTIFY_CENTER, WRAP_TRUNCATE, - DRAW_NONE, ARGB_WHITE, ARGB_BLACK, &width, nullptr); + DRAW_NONE, ARGB_WHITE, ARGB_BLACK, &width, nullptr); width += 2 * UI_BOX_LR_BORDER; float maxwidth = MAX(origx2 - origx1, width); @@ -256,22 +326,14 @@ void ui_submenu::custom_render(void *selectedref, float top, float bottom, float // draw the text within it mui.draw_text_full(container, _(m_options[0].description), x1, y1, x2 - x1, JUSTIFY_CENTER, WRAP_TRUNCATE, - DRAW_NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, nullptr, nullptr); + DRAW_NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, nullptr, nullptr); if (selectedref != nullptr) { ui_submenu::option *selected_sm_option = (ui_submenu::option *)selectedref; - - if (last_sm_option == selected_sm_option) { - if (interval <= 30) interval++; - } else { - last_sm_option = selected_sm_option; - interval = 0; - } - - if (interval > 30 && last_sm_option->entry != nullptr) + if (selected_sm_option->entry != nullptr) { - mui.draw_text_full(container, last_sm_option->entry->description(), 0.0f, 0.0f, 1.0f, JUSTIFY_CENTER, WRAP_TRUNCATE, + mui.draw_text_full(container, selected_sm_option->entry->description(), 0.0f, 0.0f, 1.0f, JUSTIFY_CENTER, WRAP_TRUNCATE, DRAW_NONE, ARGB_WHITE, ARGB_BLACK, &width, nullptr); width += 2 * UI_BOX_LR_BORDER; @@ -292,13 +354,8 @@ void ui_submenu::custom_render(void *selectedref, float top, float bottom, float y1 += UI_BOX_TB_BORDER; // draw the text within it - mui.draw_text_full(container, last_sm_option->entry->description(), x1, y1, x2 - x1, JUSTIFY_CENTER, WRAP_NEVER, + mui.draw_text_full(container, selected_sm_option->entry->description(), x1, y1, x2 - x1, JUSTIFY_CENTER, WRAP_NEVER, DRAW_NORMAL, UI_TEXT_COLOR, UI_TEXT_BG_COLOR, nullptr, nullptr); } } - else - { - last_sm_option = nullptr; - interval = 0; - } } |