diff options
Diffstat (limited to 'src/frontend/mame/ui')
-rw-r--r-- | src/frontend/mame/ui/inputmap.cpp | 22 | ||||
-rw-r--r-- | src/frontend/mame/ui/inputmap.h | 2 | ||||
-rw-r--r-- | src/frontend/mame/ui/pluginopt.cpp | 1 | ||||
-rw-r--r-- | src/frontend/mame/ui/state.cpp | 5 | ||||
-rw-r--r-- | src/frontend/mame/ui/state.h | 4 | ||||
-rw-r--r-- | src/frontend/mame/ui/ui.cpp | 114 | ||||
-rw-r--r-- | src/frontend/mame/ui/ui.h | 3 |
7 files changed, 73 insertions, 78 deletions
diff --git a/src/frontend/mame/ui/inputmap.cpp b/src/frontend/mame/ui/inputmap.cpp index 0d49fc1ad29..94643849893 100644 --- a/src/frontend/mame/ui/inputmap.cpp +++ b/src/frontend/mame/ui/inputmap.cpp @@ -240,7 +240,7 @@ menu_input::menu_input(mame_ui_manager &mui, render_container &container) : menu(mui, container) , data() , pollingitem(nullptr) - , seq_poll(machine().input()) + , seq_poll() , errormsg() , erroritem(nullptr) , lastitem(nullptr) @@ -269,7 +269,7 @@ void menu_input::custom_render(void *selectedref, float top, float bottom, float { if (pollingitem) { - const std::string seqname = machine().input().seq_name(seq_poll.sequence()); + const std::string seqname = machine().input().seq_name(seq_poll->sequence()); char const *const text[] = { seqname.c_str() }; draw_text_box( std::begin(text), std::end(text), @@ -326,7 +326,7 @@ void menu_input::handle() { // if UI_CANCEL is pressed, abort pollingitem = nullptr; - if (!seq_poll.modified()) + if (!seq_poll->modified()) { // cancelled immediately - toggle between default and none record_next = false; @@ -338,14 +338,15 @@ void menu_input::handle() // entered something before cancelling - abandon change invalidate = true; } + seq_poll.reset(); } - else if (seq_poll.poll()) // poll again; if finished, update the sequence + else if (seq_poll->poll()) // poll again; if finished, update the sequence { pollingitem = nullptr; - if (seq_poll.valid()) + if (seq_poll->valid()) { record_next = true; - item->seq = seq_poll.sequence(); + item->seq = seq_poll->sequence(); seqchangeditem = item; } else @@ -355,6 +356,7 @@ void menu_input::handle() errormsg = _("Invalid sequence entered"); erroritem = item; } + seq_poll.reset(); } } else if (menu_event && menu_event->itemref) @@ -369,10 +371,14 @@ void menu_input::handle() pollingitem = &item; lastitem = &item; starting_seq = item.seq; + if (INPUT_TYPE_ANALOG == item.type) + seq_poll.reset(new axis_sequence_poller(machine().input())); + else + seq_poll.reset(new switch_sequence_poller(machine().input())); if (record_next) - seq_poll.start((item.type == INPUT_TYPE_ANALOG) ? ITEM_CLASS_ABSOLUTE : ITEM_CLASS_SWITCH, item.seq); + seq_poll->start(item.seq); else - seq_poll.start((item.type == INPUT_TYPE_ANALOG) ? ITEM_CLASS_ABSOLUTE : ITEM_CLASS_SWITCH); + seq_poll->start(); invalidate = true; break; diff --git a/src/frontend/mame/ui/inputmap.h b/src/frontend/mame/ui/inputmap.h index 01649b0b1ef..bdc1449c89b 100644 --- a/src/frontend/mame/ui/inputmap.h +++ b/src/frontend/mame/ui/inputmap.h @@ -70,7 +70,7 @@ protected: input_item_data *pollingitem; private: - input_sequence_poller seq_poll; + std::unique_ptr<input_sequence_poller> seq_poll; std::string errormsg; input_item_data *erroritem; input_item_data *lastitem; diff --git a/src/frontend/mame/ui/pluginopt.cpp b/src/frontend/mame/ui/pluginopt.cpp index 2fb36393ba7..90522bc48ae 100644 --- a/src/frontend/mame/ui/pluginopt.cpp +++ b/src/frontend/mame/ui/pluginopt.cpp @@ -18,6 +18,7 @@ namespace ui { + void menu_plugin::handle() { const event *menu_event = process(0); diff --git a/src/frontend/mame/ui/state.cpp b/src/frontend/mame/ui/state.cpp index 3064fd654dd..81c210cced2 100644 --- a/src/frontend/mame/ui/state.cpp +++ b/src/frontend/mame/ui/state.cpp @@ -84,6 +84,7 @@ menu_load_save_state_base::file_entry::file_entry(std::string &&file_name, std:: menu_load_save_state_base::menu_load_save_state_base(mame_ui_manager &mui, render_container &container, std::string_view header, std::string_view footer, bool must_exist) : menu(mui, container) + , m_switch_poller(machine().input()) , m_header(header) , m_footer(footer) , m_must_exist(must_exist) @@ -224,7 +225,7 @@ void menu_load_save_state_base::populate(float &customtop, float &custombottom) machine().pause(); // get ready to poll inputs - machine().input().reset_polling(); + m_switch_poller.reset(); m_keys_released = false; } @@ -279,7 +280,7 @@ std::string menu_load_save_state_base::get_visible_name(const std::string &file_ std::string menu_load_save_state_base::poll_inputs() { - input_code const code = machine().input().poll_switches(); + input_code const code = m_switch_poller.poll(); if (INPUT_CODE_INVALID == code) { m_keys_released = true; diff --git a/src/frontend/mame/ui/state.h b/src/frontend/mame/ui/state.h index 30bd9513bf3..cdf597db7d1 100644 --- a/src/frontend/mame/ui/state.h +++ b/src/frontend/mame/ui/state.h @@ -14,9 +14,12 @@ #include "ui/menu.h" +#include "iptseqpoll.h" + #include <chrono> #include <unordered_map> + namespace ui { // ======================> menu_load_save_state_base @@ -54,6 +57,7 @@ private: static std::string s_last_file_selected; + switch_code_poller m_switch_poller; std::unordered_map<std::string, file_entry> m_file_entries; std::unordered_map<std::string, std::string> m_filename_to_code_map; std::string_view const m_header; diff --git a/src/frontend/mame/ui/ui.cpp b/src/frontend/mame/ui/ui.cpp index 5918d0e13d6..1273c5e92df 100644 --- a/src/frontend/mame/ui/ui.cpp +++ b/src/frontend/mame/ui/ui.cpp @@ -11,8 +11,9 @@ #include "emu.h" #include "ui/ui.h" -#include "luaengine.h" #include "infoxml.h" +#include "iptseqpoll.h" +#include "luaengine.h" #include "mame.h" #include "ui/filemngr.h" #include "ui/info.h" @@ -110,7 +111,6 @@ static input_item_id const non_char_keys[] = // messagebox buffer std::string mame_ui_manager::messagebox_text; std::string mame_ui_manager::messagebox_poptext; -rgb_t mame_ui_manager::messagebox_backcolor; // slider info std::vector<ui::menu_item> mame_ui_manager::slider_list; @@ -203,8 +203,13 @@ void mame_ui_manager::init() update_target_font_height(); // more initialization - using namespace std::placeholders; - set_handler(ui_callback_type::GENERAL, std::bind(&mame_ui_manager::handler_messagebox, this, _1)); + set_handler( + ui_callback_type::GENERAL, + [this] (render_container &container) -> uint32_t + { + draw_text_box(container, messagebox_text, ui::text_layout::LEFT, 0.5f, 0.5f, colors().background_color()); + return 0; + }); m_non_char_keys_down = std::make_unique<uint8_t[]>((ARRAY_LENGTH(non_char_keys) + 7) / 8); m_mouse_show = machine().system().flags & machine_flags::CLICKABLE_ARTWORK ? true : false; @@ -406,31 +411,56 @@ void mame_ui_manager::display_startup_screens(bool first_time) show_gameinfo = show_warnings = false; #endif - // loop over states + // set up event handlers using namespace std::placeholders; + switch_code_poller poller(machine().input()); + std::string warning_text; + rgb_t warning_color; + auto handler_messagebox_anykey = + [this, &poller, &warning_text, &warning_color] (render_container &container) -> uint32_t + { + // draw a standard message window + draw_text_box(container, warning_text, ui::text_layout::LEFT, 0.5f, 0.5f, warning_color); + + if (machine().ui_input().pressed(IPT_UI_CANCEL)) + { + // if the user cancels, exit out completely + machine().schedule_exit(); + return UI_HANDLER_CANCEL; + } + else if (poller.poll() != INPUT_CODE_INVALID) + { + // if any key is pressed, just exit + return UI_HANDLER_CANCEL; + } + + return 0; + }; set_handler(ui_callback_type::GENERAL, std::bind(&mame_ui_manager::handler_ingame, this, _1)); + + // loop over states for (int state = 0; state < maxstate && !machine().scheduled_event_pending() && !ui::menu::stack_has_special_main_menu(machine()); state++) { // default to standard colors - messagebox_backcolor = colors().background_color(); - messagebox_text.clear(); + warning_color = colors().background_color(); + warning_text.clear(); // pick the next state switch (state) { case 0: if (show_gameinfo) - messagebox_text = machine_info().game_info_string(); - if (!messagebox_text.empty()) + warning_text = machine_info().game_info_string(); + if (!warning_text.empty()) { - messagebox_text.append(_("\n\nPress any key to continue")); - set_handler(ui_callback_type::MODAL, std::bind(&mame_ui_manager::handler_messagebox_anykey, this, _1)); + warning_text.append(_("\n\nPress any key to continue")); + set_handler(ui_callback_type::MODAL, handler_messagebox_anykey); } break; case 1: - messagebox_text = machine_info().warnings_string(); - m_has_warnings = !messagebox_text.empty(); + warning_text = machine_info().warnings_string(); + m_has_warnings = !warning_text.empty(); if (show_warnings) { bool need_warning = m_has_warnings; @@ -496,9 +526,9 @@ void mame_ui_manager::display_startup_screens(bool first_time) } if (need_warning) { - messagebox_text.append(_("\n\nPress any key to continue")); - set_handler(ui_callback_type::MODAL, std::bind(&mame_ui_manager::handler_messagebox_anykey, this, _1)); - messagebox_backcolor = machine_info().warnings_color(); + warning_text.append(_("\n\nPress any key to continue")); + set_handler(ui_callback_type::MODAL, handler_messagebox_anykey); + warning_color = machine_info().warnings_color(); } } break; @@ -519,15 +549,13 @@ void mame_ui_manager::display_startup_screens(bool first_time) break; } - // clear the input memory - machine().input().reset_polling(); - while (machine().input().poll_switches() != INPUT_CODE_INVALID) { } + // clear the input memory and wait for all keys to be released + poller.reset(); + while (poller.poll() != INPUT_CODE_INVALID) { } // loop while we have a handler while (m_handler_callback_type == ui_callback_type::MODAL && !machine().scheduled_event_pending() && !ui::menu::stack_has_special_main_menu(machine())) - { machine().video().frame_update(); - } // clear the handler and force an update set_handler(ui_callback_type::GENERAL, std::bind(&mame_ui_manager::handler_ingame, this, _1)); @@ -556,7 +584,6 @@ void mame_ui_manager::set_startup_text(const char *text, bool force) // copy in the new text messagebox_text.assign(text); - messagebox_backcolor = colors().background_color(); // don't update more than 4 times/second if (force || (curtime - lastupdatetime) > osd_ticks_per_second() / 4) @@ -598,7 +625,7 @@ void mame_ui_manager::update_and_render(render_container &container) // display any popup messages if (osd_ticks() < m_popup_text_end) - draw_text_box(container, messagebox_poptext, ui::text_layout::CENTER, 0.5f, 0.9f, messagebox_backcolor); + draw_text_box(container, messagebox_poptext, ui::text_layout::CENTER, 0.5f, 0.9f, colors().background_color()); else m_popup_text_end = 0; @@ -947,46 +974,6 @@ bool mame_ui_manager::is_menu_active(void) ***************************************************************************/ //------------------------------------------------- -// handler_messagebox - displays the current -// messagebox_text string but handles no input -//------------------------------------------------- - -uint32_t mame_ui_manager::handler_messagebox(render_container &container) -{ - draw_text_box(container, messagebox_text, ui::text_layout::LEFT, 0.5f, 0.5f, messagebox_backcolor); - return 0; -} - - -//------------------------------------------------- -// handler_messagebox_anykey - displays the -// current messagebox_text string and waits for -// any keypress -//------------------------------------------------- - -uint32_t mame_ui_manager::handler_messagebox_anykey(render_container &container) -{ - uint32_t state = 0; - - // draw a standard message window - draw_text_box(container, messagebox_text, ui::text_layout::LEFT, 0.5f, 0.5f, messagebox_backcolor); - - // if the user cancels, exit out completely - if (machine().ui_input().pressed(IPT_UI_CANCEL)) - { - machine().schedule_exit(); - state = UI_HANDLER_CANCEL; - } - - // if any key is pressed, just exit - else if (machine().input().poll_switches() != INPUT_CODE_INVALID) - state = UI_HANDLER_CANCEL; - - return state; -} - - -//------------------------------------------------- // process_natural_keyboard - processes any // natural keyboard input //------------------------------------------------- @@ -2232,7 +2219,6 @@ void mame_ui_manager::popup_time_string(int seconds, std::string message) { // extract the text messagebox_poptext = message; - messagebox_backcolor = colors().background_color(); // set a timer m_popup_text_end = osd_ticks() + osd_ticks_per_second() * seconds; diff --git a/src/frontend/mame/ui/ui.h b/src/frontend/mame/ui/ui.h index d2fcd19d512..932957d9f9d 100644 --- a/src/frontend/mame/ui/ui.h +++ b/src/frontend/mame/ui/ui.h @@ -299,14 +299,11 @@ private: // static variables static std::string messagebox_text; static std::string messagebox_poptext; - static rgb_t messagebox_backcolor; static std::vector<ui::menu_item> slider_list; static slider_state *slider_current; // UI handlers - uint32_t handler_messagebox(render_container &container); - uint32_t handler_messagebox_anykey(render_container &container); uint32_t handler_ingame(render_container &container); uint32_t handler_load_save(render_container &container, uint32_t state); uint32_t handler_confirm_quit(render_container &container); |