From b23bf4ae7290011988139152175a13708b79baf2 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Sun, 14 Nov 2021 05:40:31 +1100 Subject: frontend: Various minor improvements. Made a few more menus reset values to the default in response to the UI clear input. Made the minimum info text size less unreasonable, and fixed a locale issue in the font/size selection menu when parsing option strings. Made the keyboard mode menu toggle items on double click or UI select. Made the menuless sliders menu remember the last slider shown (this probably broke when sliders were moved out of the UI manager itself). Made a few menus just update the highlighted options when it's adjusted rather than unnecessarily rebuilding the menu. Made a few more menus reset on being reactivated to cope with scripts or other things changing stuff out from under them. --- src/frontend/mame/ui/analogipt.cpp | 51 +++++--- src/frontend/mame/ui/analogipt.h | 3 + src/frontend/mame/ui/custui.cpp | 240 ++++++++++++++++++++++--------------- src/frontend/mame/ui/custui.h | 28 +---- src/frontend/mame/ui/inputmap.cpp | 2 +- src/frontend/mame/ui/keyboard.cpp | 33 +++-- src/frontend/mame/ui/keyboard.h | 3 + src/frontend/mame/ui/menu.cpp | 2 +- src/frontend/mame/ui/menu.h | 4 +- src/frontend/mame/ui/moptions.cpp | 2 +- src/frontend/mame/ui/sliders.cpp | 47 +++++++- src/frontend/mame/ui/sliders.h | 2 + 12 files changed, 267 insertions(+), 150 deletions(-) diff --git a/src/frontend/mame/ui/analogipt.cpp b/src/frontend/mame/ui/analogipt.cpp index 20791328392..6dfe4165788 100644 --- a/src/frontend/mame/ui/analogipt.cpp +++ b/src/frontend/mame/ui/analogipt.cpp @@ -189,6 +189,13 @@ void menu_analog::custom_render(void *selectedref, float top, float bottom, floa } +void menu_analog::menu_activated() +{ + // scripts could have changed something in the mean time + reset(reset_options::REMEMBER_POSITION); +} + + void menu_analog::handle(event const *ev) { // handle events @@ -313,9 +320,11 @@ void menu_analog::handle(event const *ev) case ANALOG_ITEM_SENSITIVITY: settings.sensitivity = newval; break; } data.field.get().set_user_settings(settings); + data.cur = newval; - // rebuild the menu - reset(reset_options::REMEMBER_POSITION); + // update the menu item + ev->item->set_subtext(item_text(data.type, newval)); + ev->item->set_flags((data.cur <= data.min) ? FLAG_RIGHT_ARROW : (data.cur >= data.max) ? FLAG_LEFT_ARROW : FLAG_LEFT_ARROW | FLAG_RIGHT_ARROW); } } } @@ -334,7 +343,6 @@ void menu_analog::populate(float &customtop, float &custombottom) // add the items std::string text; - std::string subtext; for (item_data &data : m_item_data) { // get the user settings @@ -359,38 +367,31 @@ void menu_analog::populate(float &customtop, float &custombottom) default: case ANALOG_ITEM_KEYSPEED: text = string_format(_("%1$s Increment/Decrement Speed"), field->name()); - subtext = string_format("%d", settings.delta); data.cur = settings.delta; break; case ANALOG_ITEM_CENTERSPEED: text = string_format(_("%1$s Auto-centering Speed"), field->name()); - subtext = string_format("%d", settings.centerdelta); data.cur = settings.centerdelta; break; case ANALOG_ITEM_REVERSE: text = string_format(_("%1$s Reverse"), field->name()); - subtext.assign(settings.reverse ? "On" : "Off"); data.cur = settings.reverse; break; case ANALOG_ITEM_SENSITIVITY: text = string_format(_("%1$s Sensitivity"), field->name()); - subtext = string_format("%d", settings.sensitivity); data.cur = settings.sensitivity; break; } - // put on arrows - uint32_t flags(0U); - if (data.cur > data.min) - flags |= FLAG_LEFT_ARROW; - if (data.cur < data.max) - flags |= FLAG_RIGHT_ARROW; - // append a menu item - item_append(std::move(text), std::move(subtext), flags, &data); + item_append( + std::move(text), + item_text(data.type, data.cur), + (data.cur <= data.min) ? FLAG_RIGHT_ARROW : (data.cur >= data.max) ? FLAG_LEFT_ARROW : FLAG_LEFT_ARROW | FLAG_RIGHT_ARROW, + &data); } item_append(menu_item_type::SEPARATOR); @@ -454,4 +455,24 @@ void menu_analog::find_fields() m_visible_fields = m_field_data.size(); } + +std::string menu_analog::item_text(int type, int value) +{ + switch (type) + { + default: + case ANALOG_ITEM_KEYSPEED: + return string_format("%d", value); + + case ANALOG_ITEM_CENTERSPEED: + return string_format("%d", value); + + case ANALOG_ITEM_REVERSE: + return value ? _("On") : _("Off"); + + case ANALOG_ITEM_SENSITIVITY: + return string_format("%d", value); + } +} + } // namespace ui diff --git a/src/frontend/mame/ui/analogipt.h b/src/frontend/mame/ui/analogipt.h index fbc9907a0df..f6807947ce6 100644 --- a/src/frontend/mame/ui/analogipt.h +++ b/src/frontend/mame/ui/analogipt.h @@ -28,6 +28,7 @@ public: protected: virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2) override; + virtual void menu_activated() override; private: enum @@ -70,6 +71,8 @@ private: void find_fields(); + static std::string item_text(int type, int value); + item_data_vector m_item_data; field_data_vector m_field_data; std::string m_prompt; diff --git a/src/frontend/mame/ui/custui.cpp b/src/frontend/mame/ui/custui.cpp index 89d06ba74d6..62396d7840b 100644 --- a/src/frontend/mame/ui/custui.cpp +++ b/src/frontend/mame/ui/custui.cpp @@ -24,17 +24,49 @@ #include #include +#include +#include #include namespace ui { -const char *const menu_custom_ui::HIDE_STATUS[] = { +namespace { + +enum +{ + LANGUAGE_MENU = 1, + SYSNAMES_MENU, + FONT_MENU, + COLORS_MENU, + HIDE_MENU, + + INFOS_SIZE = 1, + FONT_SIZE, + MUI_FNT, + MUI_BOLD, + MUI_ITALIC +}; + +const char *const HIDE_STATUS[] = { N_("Show All"), N_("Hide Filters"), N_("Hide Info/Image"), N_("Hide Both") }; +template +T parse_number(U &&s) +{ + T result(T(0)); + std::istringstream ss(std::forward(s)); + ss.imbue(std::locale::classic()); + ss >> result; + return result; +} + +} // anonymous namespace + + //------------------------------------------------- // ctor //------------------------------------------------- @@ -75,8 +107,6 @@ menu_custom_ui::~menu_custom_ui() void menu_custom_ui::handle(event const *ev) { - bool changed = false; - // process the menu if (ev && ev->itemref) { @@ -84,85 +114,90 @@ void menu_custom_ui::handle(event const *ev) { case FONT_MENU: if (ev->iptkey == IPT_UI_SELECT) - menu::stack_push( - ui(), - container(), - [this] (bool changed) - { - if (changed) - reset(reset_options::REMEMBER_REF); - }); + menu::stack_push(ui(), container(), nullptr); break; case COLORS_MENU: if (ev->iptkey == IPT_UI_SELECT) menu::stack_push(ui(), container()); break; - case HIDE_MENU: - if (ev->iptkey == IPT_UI_LEFT || ev->iptkey == IPT_UI_RIGHT) - { - changed = true; - (ev->iptkey == IPT_UI_RIGHT) ? ui_globals::panels_status++ : ui_globals::panels_status--; - } - else if (ev->iptkey == IPT_UI_SELECT) - { - std::vector s_sel(std::size(HIDE_STATUS)); - std::transform(std::begin(HIDE_STATUS), std::end(HIDE_STATUS), s_sel.begin(), [](auto &s) { return _(s); }); - menu::stack_push( - ui(), container(), std::move(s_sel), ui_globals::panels_status, - [this] (int selection) - { - ui_globals::panels_status = selection; - reset(reset_options::REMEMBER_REF); - }); - } - break; case LANGUAGE_MENU: - if (ev->iptkey == IPT_UI_LEFT || ev->iptkey == IPT_UI_RIGHT) + if ((ev->iptkey == IPT_UI_LEFT) || (ev->iptkey == IPT_UI_RIGHT) || (ev->iptkey == IPT_UI_CLEAR)) { - changed = true; if (ev->iptkey == IPT_UI_LEFT) - m_currlang = (m_currlang ? m_currlang : m_languages.size())- 1; - else if (++m_currlang >= m_languages.size()) + --m_currlang; + else if (ev->iptkey == IPT_UI_RIGHT) + ++m_currlang; + else m_currlang = 0; + ev->item->set_subtext(m_languages[m_currlang]); + ev->item->set_flags(get_arrow_flags(0, m_languages.size() - 1, m_currlang)); } else if (ev->iptkey == IPT_UI_SELECT) { // copying list of language names - expensive menu::stack_push( ui(), container(), std::vector(m_languages), m_currlang, - [this] (int selection) + [this, item = ev->item] (int selection) { m_currlang = selection; - reset(reset_options::REMEMBER_REF); + item->set_subtext(m_languages[selection]); + item->set_flags(get_arrow_flags(0, m_languages.size() - 1, selection)); }); } break; case SYSNAMES_MENU: - if (ev->iptkey == IPT_UI_LEFT || ev->iptkey == IPT_UI_RIGHT) + if ((ev->iptkey == IPT_UI_LEFT) || (ev->iptkey == IPT_UI_RIGHT) || (ev->iptkey == IPT_UI_CLEAR)) { - changed = true; if (ev->iptkey == IPT_UI_LEFT) - m_currsysnames = (m_currsysnames ? m_currsysnames : m_sysnames.size())- 1; - else if (++m_currsysnames >= m_sysnames.size()) + --m_currsysnames; + else if (ev->iptkey == IPT_UI_RIGHT) + ++m_currsysnames; + else m_currsysnames = 0; + ev->item->set_subtext(m_sysnames[m_currsysnames]); + ev->item->set_flags(get_arrow_flags(0, m_sysnames.size() - 1, m_currsysnames)); } else if (ev->iptkey == IPT_UI_SELECT) { // copying list of file names - expensive menu::stack_push( ui(), container(), std::vector(m_sysnames), m_currsysnames, - [this] (int selection) + [this, item = ev->item] (int selection) { m_currsysnames = selection; - reset(reset_options::REMEMBER_REF); + item->set_subtext(m_sysnames[selection]); + item->set_flags(get_arrow_flags(0, m_sysnames.size() - 1, selection)); + }); + } + break; + case HIDE_MENU: + if ((ev->iptkey == IPT_UI_LEFT) || (ev->iptkey == IPT_UI_RIGHT) || (ev->iptkey == IPT_UI_CLEAR)) + { + if (ev->iptkey == IPT_UI_LEFT) + --ui_globals::panels_status; + else if (ev->iptkey == IPT_UI_RIGHT) + ++ui_globals::panels_status; + else + ui_globals::panels_status = 0; + ev->item->set_subtext(_(HIDE_STATUS[ui_globals::panels_status])); + ev->item->set_flags(get_arrow_flags(0, HIDE_BOTH, ui_globals::panels_status)); + } + else if (ev->iptkey == IPT_UI_SELECT) + { + std::vector s_sel(std::size(HIDE_STATUS)); + std::transform(std::begin(HIDE_STATUS), std::end(HIDE_STATUS), s_sel.begin(), [](auto &s) { return _(s); }); + menu::stack_push( + ui(), container(), std::move(s_sel), ui_globals::panels_status, + [item = ev->item] (int selection) + { + ui_globals::panels_status = selection; + item->set_subtext(_(HIDE_STATUS[selection])); + item->set_flags(get_arrow_flags(0, HIDE_BOTH, selection)); }); } break; } } - - if (changed) - reset(reset_options::REMEMBER_REF); } //------------------------------------------------- @@ -298,11 +333,11 @@ menu_font_ui::menu_font_ui(mame_ui_manager &mui, render_container &container, st : menu(mui, container) , m_handler(std::move(handler)) , m_fonts() - , m_font_min(atof(mui.options().get_entry(OPTION_FONT_ROWS)->minimum())) - , m_font_max(atof(mui.options().get_entry(OPTION_FONT_ROWS)->maximum())) + , m_font_min(parse_number(mui.options().get_entry(OPTION_FONT_ROWS)->minimum())) + , m_font_max(parse_number(mui.options().get_entry(OPTION_FONT_ROWS)->maximum())) , m_font_size(mui.options().font_rows()) - , m_info_min(atof(mui.options().get_entry(OPTION_INFOS_SIZE)->minimum())) - , m_info_max(atof(mui.options().get_entry(OPTION_INFOS_SIZE)->maximum())) + , m_info_min(parse_number(mui.options().get_entry(OPTION_INFOS_SIZE)->minimum())) + , m_info_max(parse_number(mui.options().get_entry(OPTION_INFOS_SIZE)->maximum())) , m_info_size(mui.options().infos_size()) , m_changed(false) , m_actual(0U) @@ -377,35 +412,52 @@ menu_font_ui::~menu_font_ui() void menu_font_ui::handle(event const *ev) { - bool changed = false; - // process the menu if (ev && ev->itemref) { switch ((uintptr_t)ev->itemref) { - case INFOS_SIZE: - if (ev->iptkey == IPT_UI_LEFT || ev->iptkey == IPT_UI_RIGHT) + case FONT_SIZE: + if ((ev->iptkey == IPT_UI_LEFT) || (ev->iptkey == IPT_UI_RIGHT) || (ev->iptkey == IPT_UI_CLEAR)) { - (ev->iptkey == IPT_UI_RIGHT) ? m_info_size += 0.05f : m_info_size -= 0.05f; - changed = true; + m_changed = true; + if (ev->iptkey == IPT_UI_LEFT) + --m_font_size; + else if (ev->iptkey == IPT_UI_RIGHT) + ++m_font_size; + else + m_font_size = parse_number(ui().options().get_entry(OPTION_FONT_ROWS)->default_value().c_str()); + ev->item->set_subtext(string_format("%d", m_font_size)); + ev->item->set_flags(get_arrow_flags(m_font_min, m_font_max, m_font_size)); } break; - case FONT_SIZE: - if (ev->iptkey == IPT_UI_LEFT || ev->iptkey == IPT_UI_RIGHT) + case INFOS_SIZE: + if ((ev->iptkey == IPT_UI_LEFT) || (ev->iptkey == IPT_UI_RIGHT) || (ev->iptkey == IPT_UI_CLEAR)) { - (ev->iptkey == IPT_UI_RIGHT) ? m_font_size++ : m_font_size--; - changed = true; + m_changed = true; + if (ev->iptkey == IPT_UI_LEFT) + m_info_size -= 0.05f; + else if (ev->iptkey == IPT_UI_RIGHT) + m_info_size += 0.05f; + else + m_info_size = parse_number(ui().options().get_entry(OPTION_INFOS_SIZE)->default_value().c_str()); + ev->item->set_subtext(string_format("%.2f", m_info_size)); + ev->item->set_flags(get_arrow_flags(m_info_min, m_info_max, m_info_size)); } break; - case MUI_FNT: - if (ev->iptkey == IPT_UI_LEFT || ev->iptkey == IPT_UI_RIGHT) + if ((ev->iptkey == IPT_UI_LEFT) || (ev->iptkey == IPT_UI_RIGHT) || (ev->iptkey == IPT_UI_CLEAR)) { - (ev->iptkey == IPT_UI_RIGHT) ? m_actual++ : m_actual--; - changed = true; + m_changed = true; + if (ev->iptkey == IPT_UI_LEFT) + --m_actual; + else if (ev->iptkey == IPT_UI_RIGHT) + ++m_actual; + else + m_actual = 0; + reset(reset_options::REMEMBER_REF); } else if (ev->iptkey == IPT_UI_SELECT) { @@ -427,21 +479,21 @@ void menu_font_ui::handle(event const *ev) #ifdef UI_WINDOWS case MUI_BOLD: case MUI_ITALIC: - if (ev->iptkey == IPT_UI_LEFT || ev->iptkey == IPT_UI_RIGHT || ev->iptkey == IPT_UI_SELECT) + if ((ev->iptkey == IPT_UI_LEFT) || (ev->iptkey == IPT_UI_RIGHT) || (ev->iptkey == IPT_UI_SELECT) || (ev->iptkey == IPT_UI_CLEAR)) { - ((uintptr_t)ev->itemref == MUI_BOLD) ? m_bold = !m_bold : m_italic = !m_italic; - changed = true; + m_changed = true; + bool &val = ((uintptr_t)ev->itemref == MUI_BOLD) ? m_bold : m_italic; + if (ev->iptkey == IPT_UI_CLEAR) + val = false; + else + val = !val; + ev->item->set_subtext(val ? _("On") : _("Off")); + ev->item->set_flags(val ? FLAG_LEFT_ARROW : FLAG_RIGHT_ARROW); } break; #endif } } - - if (changed) - { - m_changed = true; - reset(reset_options::REMEMBER_REF); - } } //------------------------------------------------- @@ -453,7 +505,6 @@ void menu_font_ui::populate(float &customtop, float &custombottom) // set filter arrow uint32_t arrow_flags; - // add fonts option arrow_flags = get_arrow_flags(0, m_fonts.size() - 1, m_actual); item_append(_("UI Font"), m_fonts[m_actual].second, arrow_flags, (void *)(uintptr_t)MUI_FNT); @@ -466,13 +517,12 @@ void menu_font_ui::populate(float &customtop, float &custombottom) #endif arrow_flags = get_arrow_flags(m_font_min, m_font_max, m_font_size); - item_append(_("Lines"), string_format("%2d", m_font_size), arrow_flags, (void *)(uintptr_t)FONT_SIZE); + item_append(_("Lines"), string_format("%d", m_font_size), arrow_flags, (void *)(uintptr_t)FONT_SIZE); item_append(menu_item_type::SEPARATOR); - // add item arrow_flags = get_arrow_flags(m_info_min, m_info_max, m_info_size); - item_append(_("Infos text size"), string_format("%3.2f", m_info_size), arrow_flags, (void *)(uintptr_t)INFOS_SIZE); + item_append(_("Infos text size"), string_format("%.2f", m_info_size), arrow_flags, (void *)(uintptr_t)INFOS_SIZE); item_append(menu_item_type::SEPARATOR); @@ -552,8 +602,6 @@ menu_colors_ui::~menu_colors_ui() void menu_colors_ui::handle(event const *ev) { - bool changed = false; - // process the menu if (ev && ev->itemref && ev->iptkey == IPT_UI_SELECT) { @@ -563,13 +611,9 @@ void menu_colors_ui::handle(event const *ev) } else { - changed = true; restore_colors(); } } - - if (changed) - reset(reset_options::REMEMBER_REF); } //------------------------------------------------- @@ -596,6 +640,7 @@ void menu_colors_ui::populate(float &customtop, float &custombottom) item_append(_("color-option", "Mouse down background color"), 0, (void *)(uintptr_t)MUI_MOUSEDOWN_BG_COLOR); item_append(menu_item_type::SEPARATOR); + item_append(_("Restore default colors"), 0, (void *)(uintptr_t)MUI_RESTORE); custombottom = customtop = ui().get_line_height() + 3.0f * ui().box_tb_border(); @@ -786,12 +831,12 @@ void menu_rgb_ui::handle(event const *ev) // process the menu if (ev && ev->itemref) { - bool changed = false; switch (ev->iptkey) { case IPT_UI_LEFT: case IPT_UI_RIGHT: { + bool changed = false; int updated = (IPT_UI_LEFT == ev->iptkey) ? -1 : 1; switch (uintptr_t(ev->itemref)) { @@ -828,6 +873,11 @@ void menu_rgb_ui::handle(event const *ev) } break; } + if (changed) + { + ev->item->set_subtext(string_format("%3u", updated)); + ev->item->set_flags(get_arrow_flags(0, 255, updated)); + } } break; @@ -846,14 +896,10 @@ void menu_rgb_ui::handle(event const *ev) case RGB_GREEN: case RGB_BLUE: inkey_special(ev); - changed = true; break; } break; } - - if (changed) - reset(reset_options::REMEMBER_REF); } } @@ -1026,17 +1072,21 @@ void menu_rgb_ui::inkey_special(const event *menu_event) m_search.erase(); m_lock_ref = 0; - return; + + menu_event->item->set_subtext(string_format("%3u", val)); + menu_event->item->set_flags(get_arrow_flags(0, 255, val)); + } + else + { + menu_event->item->set_subtext("_"); + menu_event->item->set_flags(0); } } - - if (!m_key_active) + else if (m_key_active) { - m_search.erase(); - return; + input_character(m_search, 3, menu_event->unichar, uchar_is_digit); + menu_event->item->set_subtext(m_search + "_"); } - - input_character(m_search, 3, menu_event->unichar, uchar_is_digit); } std::pair const menu_palette_sel::s_palette[] = { @@ -1081,7 +1131,7 @@ void menu_palette_sel::handle(event const *ev) if (ev->iptkey == IPT_UI_SELECT) { m_original = rgb_t(uint32_t(strtoul(selected_item().subtext().c_str(), nullptr, 16))); - reset_parent(reset_options::SELECT_FIRST); + reset_parent(reset_options::REMEMBER_REF); stack_pop(); } } diff --git a/src/frontend/mame/ui/custui.h b/src/frontend/mame/ui/custui.h index f693b9eab24..34d417c8774 100644 --- a/src/frontend/mame/ui/custui.h +++ b/src/frontend/mame/ui/custui.h @@ -34,23 +34,12 @@ protected: virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2) override; private: - enum - { - LANGUAGE_MENU = 1, - SYSNAMES_MENU, - FONT_MENU, - COLORS_MENU, - HIDE_MENU - }; - virtual void populate(float &customtop, float &custombottom) override; virtual void handle(event const *ev) override; void find_languages(); void find_sysnames(); - static const char *const HIDE_STATUS[]; - std::function m_handler; std::vector m_languages; std::vector m_sysnames; @@ -72,15 +61,6 @@ protected: virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2) override; private: - enum - { - INFOS_SIZE = 1, - FONT_SIZE, - MUI_FNT, - MUI_BOLD, - MUI_ITALIC - }; - virtual void populate(float &customtop, float &custombottom) override; virtual void handle(event const *ev) override; @@ -88,15 +68,15 @@ private: std::function m_handler; std::vector > m_fonts; - const int m_font_min, m_font_max; + int const m_font_min, m_font_max; int m_font_size; - const float m_info_min, m_info_max; + float const m_info_min, m_info_max; float m_info_size; bool m_changed; - std::uint16_t m_actual; + std::uint16_t m_actual; #ifdef UI_WINDOWS - bool m_bold, m_italic; + bool m_bold, m_italic; #endif }; diff --git a/src/frontend/mame/ui/inputmap.cpp b/src/frontend/mame/ui/inputmap.cpp index a747c468f72..ada0d087505 100644 --- a/src/frontend/mame/ui/inputmap.cpp +++ b/src/frontend/mame/ui/inputmap.cpp @@ -273,7 +273,7 @@ menu_input::~menu_input() void menu_input::menu_activated() { // scripts can change settings out from under us - reset(reset_options::REMEMBER_REF); + reset(reset_options::REMEMBER_POSITION); } diff --git a/src/frontend/mame/ui/keyboard.cpp b/src/frontend/mame/ui/keyboard.cpp index 7f6ffefb064..cbdc3324212 100644 --- a/src/frontend/mame/ui/keyboard.cpp +++ b/src/frontend/mame/ui/keyboard.cpp @@ -28,6 +28,12 @@ menu_keyboard_mode::menu_keyboard_mode(mame_ui_manager &mui, render_container &c { } +void menu_keyboard_mode::menu_activated() +{ + // scripts could have changed something behind our back + reset(reset_options::REMEMBER_POSITION); +} + void menu_keyboard_mode::populate(float &customtop, float &custombottom) { natural_keyboard &natkbd(machine().natkeyboard()); @@ -70,25 +76,38 @@ void menu_keyboard_mode::handle(event const *ev) { natural_keyboard &natkbd(machine().natkeyboard()); uintptr_t const ref(uintptr_t(ev->itemref)); - bool const left(IPT_UI_LEFT == ev->iptkey); - bool const right(IPT_UI_RIGHT == ev->iptkey); + bool left(IPT_UI_LEFT == ev->iptkey); + bool right(IPT_UI_RIGHT == ev->iptkey); if (ITEM_KBMODE == ref) { + if (IPT_UI_SELECT == ev->iptkey) + { + left = natkbd.in_use(); + right = !left; + } if ((left || right) && (natkbd.in_use() != right)) { natkbd.set_in_use(right); - reset(reset_options::REMEMBER_REF); + ev->item->set_subtext(right ? _("Natural") : _("Emulated")); + ev->item->set_flags(right ? FLAG_LEFT_ARROW : FLAG_RIGHT_ARROW); } } else if (ITEM_KBDEV_FIRST <= ref) { - if ((left || right) && (natkbd.keyboard_enabled(ref - ITEM_KBDEV_FIRST) != right)) + auto const kbdno(ref - ITEM_KBDEV_FIRST); + if (IPT_UI_SELECT == ev->iptkey) + { + left = natkbd.keyboard_enabled(kbdno); + right = !left; + } + if ((left || right) && (natkbd.keyboard_enabled(kbdno) != right)) { if (right) - natkbd.enable_keyboard(ref - ITEM_KBDEV_FIRST); + natkbd.enable_keyboard(kbdno); else - natkbd.disable_keyboard(ref - ITEM_KBDEV_FIRST); - reset(reset_options::REMEMBER_REF); + natkbd.disable_keyboard(kbdno); + ev->item->set_subtext(right ? _("Enabled") : _("Disabled")); + ev->item->set_flags(right ? FLAG_LEFT_ARROW : FLAG_RIGHT_ARROW); } } } diff --git a/src/frontend/mame/ui/keyboard.h b/src/frontend/mame/ui/keyboard.h index 22ab3fe759a..36371f5711c 100644 --- a/src/frontend/mame/ui/keyboard.h +++ b/src/frontend/mame/ui/keyboard.h @@ -23,6 +23,9 @@ public: menu_keyboard_mode(mame_ui_manager &mui, render_container &container); virtual ~menu_keyboard_mode(); +protected: + virtual void menu_activated() override; + private: virtual void populate(float &customtop, float &custombottom) override; virtual void handle(event const *ev) override; diff --git a/src/frontend/mame/ui/menu.cpp b/src/frontend/mame/ui/menu.cpp index 4313a956643..4dc265f5d14 100644 --- a/src/frontend/mame/ui/menu.cpp +++ b/src/frontend/mame/ui/menu.cpp @@ -405,7 +405,7 @@ const menu::event *menu::process() if ((m_event.iptkey != IPT_INVALID) && selection_valid()) { m_event.itemref = get_selection_ref(); - m_event.type = m_items[m_selected].type(); + m_event.item = &m_items[m_selected]; return &m_event; } else diff --git a/src/frontend/mame/ui/menu.h b/src/frontend/mame/ui/menu.h index a6e6c25d174..6b137a99631 100644 --- a/src/frontend/mame/ui/menu.h +++ b/src/frontend/mame/ui/menu.h @@ -117,8 +117,8 @@ protected: // menu-related events struct event { - void *itemref; // reference for the selected item - menu_item_type type; // item type (eventually will go away when itemref is proper ui_menu_item class rather than void*) + void *itemref; // reference for the selected item or nullptr + menu_item *item; // selected item or nullptr int iptkey; // one of the IPT_* values from inptport.h char32_t unichar; // unicode character if iptkey == IPT_SPECIAL render_bounds mouse; // mouse position if iptkey == IPT_CUSTOM diff --git a/src/frontend/mame/ui/moptions.cpp b/src/frontend/mame/ui/moptions.cpp index 375bbddf16a..e02d453202a 100644 --- a/src/frontend/mame/ui/moptions.cpp +++ b/src/frontend/mame/ui/moptions.cpp @@ -61,7 +61,7 @@ const options_entry ui_options::s_option_entries[] = // UI options { nullptr, nullptr, OPTION_HEADER, "UI OPTIONS" }, - { OPTION_INFOS_SIZE "(0.05-1.00)", "0.75", OPTION_FLOAT, "UI right panel infos text size (0.05 - 1.00)" }, + { OPTION_INFOS_SIZE "(0.20-1.00)", "0.75", OPTION_FLOAT, "UI right panel infos text size (0.20 - 1.00)" }, { OPTION_FONT_ROWS "(25-40)", "30", OPTION_INTEGER, "UI font lines per screen (25 - 40)" }, { OPTION_HIDE_PANELS "(0-3)", "0", OPTION_INTEGER, "UI hide left/right panel in main view (0 = Show all, 1 = hide left, 2 = hide right, 3 = hide both" }, { OPTION_UI_BORDER_COLOR, "ffffffff", OPTION_STRING, "UI border color (ARGB)" }, diff --git a/src/frontend/mame/ui/sliders.cpp b/src/frontend/mame/ui/sliders.cpp index f17a0bf9781..404e174f803 100644 --- a/src/frontend/mame/ui/sliders.cpp +++ b/src/frontend/mame/ui/sliders.cpp @@ -25,6 +25,7 @@ menu_sliders::menu_sliders(mame_ui_manager &mui, render_container &container, bo , m_hidden(menuless_mode) { set_one_shot(menuless_mode); + set_needs_prev_menu_item(!menuless_mode); set_process_flags(PROCESS_LR_REPEAT | (m_hidden ? PROCESS_CUSTOM_ONLY : 0)); } @@ -32,6 +33,7 @@ menu_sliders::~menu_sliders() { } + //------------------------------------------------- // menu_sliders - handle the sliders menu //------------------------------------------------- @@ -55,15 +57,15 @@ void menu_sliders::handle(event const *ev) } } - else if (ev->itemref && (ev->type == menu_item_type::SLIDER)) + else if (ev->itemref && (ev->item->type() == menu_item_type::SLIDER)) { // handle keys if there is a valid item selected const slider_state *slider = (const slider_state *)ev->itemref; int32_t curvalue = slider->update(nullptr, SLIDER_NOCHANGE); int32_t increment = 0; - bool alt_pressed = machine().input().code_pressed(KEYCODE_LALT) || machine().input().code_pressed(KEYCODE_RALT); - bool ctrl_pressed = machine().input().code_pressed(KEYCODE_LCONTROL) || machine().input().code_pressed(KEYCODE_RCONTROL); - bool shift_pressed = machine().input().code_pressed(KEYCODE_LSHIFT) || machine().input().code_pressed(KEYCODE_RSHIFT); + bool const alt_pressed = machine().input().code_pressed(KEYCODE_LALT) || machine().input().code_pressed(KEYCODE_RALT); + bool const ctrl_pressed = machine().input().code_pressed(KEYCODE_LCONTROL) || machine().input().code_pressed(KEYCODE_RCONTROL); + bool const shift_pressed = machine().input().code_pressed(KEYCODE_LSHIFT) || machine().input().code_pressed(KEYCODE_RSHIFT); switch (ev->iptkey) { @@ -97,6 +99,7 @@ void menu_sliders::handle(event const *ev) // restore default case IPT_UI_SELECT: + case IPT_UI_CLEAR: increment = slider->defval - curvalue; break; } @@ -114,6 +117,8 @@ void menu_sliders::handle(event const *ev) // update the slider and recompute the menu slider->update(nullptr, newvalue); + if (m_menuless_mode) + ui().get_session_data(nullptr) = ev->itemref; reset(reset_options::REMEMBER_REF); } } @@ -124,7 +129,9 @@ void menu_sliders::handle(event const *ev) { // if we got here via up or page up, select the previous item if (is_first_selected()) + { select_last_item(); + } else { set_selected_index(selected_index() - 1); @@ -209,9 +216,18 @@ void menu_sliders::populate(float &customtop, float &custombottom) } } + // reselect last slider used in menuless mode + if (m_menuless_mode) + { + auto const ref = ui().get_session_data(nullptr); + if (ref) + set_selection(ref); + } + custombottom = 2.0f * ui().get_line_height() + 2.0f * ui().box_tb_border(); } + //------------------------------------------------- // menu_sliders_custom_render - perform our special // rendering @@ -291,4 +307,27 @@ void menu_sliders::custom_render(void *selectedref, float top, float bottom, flo } } + +//------------------------------------------------- +// menu_activated - handle menu gaining focus +//------------------------------------------------- + +void menu_sliders::menu_activated() +{ + // scripts or the other form of the menu could have changed something in the mean time + reset(reset_options::REMEMBER_POSITION); +} + + +//------------------------------------------------- +// menu_deactivated - handle menu losing focus +//------------------------------------------------- + +void menu_sliders::menu_deactivated() +{ + // save active slider for next time in menuless mode + if (m_menuless_mode) + ui().get_session_data(nullptr) = get_selection_ref(); +} + } // namespace ui diff --git a/src/frontend/mame/ui/sliders.h b/src/frontend/mame/ui/sliders.h index a1ac25bf96c..99a5c6e9cfb 100644 --- a/src/frontend/mame/ui/sliders.h +++ b/src/frontend/mame/ui/sliders.h @@ -26,6 +26,8 @@ public: protected: virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2) override; + virtual void menu_activated() override; + virtual void menu_deactivated() override; private: virtual void populate(float &customtop, float &custombottom) override; -- cgit v1.2.3