Merge pull request #925 from npwoods/lambdas_for_ui_handlers

Lambdas for ui handlers
This commit is contained in:
hap 2016-06-04 22:26:57 +02:00
commit a96d77eb3c
9 changed files with 199 additions and 151 deletions

View File

@ -29,6 +29,7 @@ public:
virtual void set_startup_text(const char *text, bool force) { } virtual void set_startup_text(const char *text, bool force) { }
// is a menuing system active? we want to disable certain keyboard/mouse inputs under such context
virtual bool is_menu_active() { return false; } virtual bool is_menu_active() { return false; }
bool use_natural_keyboard() const { return m_use_natural_keyboard; } bool use_natural_keyboard() const { return m_use_natural_keyboard; }

View File

@ -1270,7 +1270,7 @@ void menu::do_handle()
// and calls the menu handler // and calls the menu handler
//------------------------------------------------- //-------------------------------------------------
UINT32 menu::ui_handler(mame_ui_manager &mui, render_container *container, UINT32 state) UINT32 menu::ui_handler(render_container *container, mame_ui_manager &mui)
{ {
// if we have no menus stacked up, start with the main menu // if we have no menus stacked up, start with the main menu
if (!menu_stack) if (!menu_stack)

View File

@ -120,7 +120,7 @@ public:
static void draw_arrow(render_container *container, float x0, float y0, float x1, float y1, rgb_t fgcolor, UINT32 orientation); static void draw_arrow(render_container *container, float x0, float y0, float x1, float y1, rgb_t fgcolor, UINT32 orientation);
// master handler // master handler
static UINT32 ui_handler(mame_ui_manager &mui, render_container *container, UINT32 state); static UINT32 ui_handler(render_container *container, mame_ui_manager &mui);
// Used by sliders // Used by sliders
void validate_selection(int scandir); void validate_selection(int scandir);

View File

@ -264,7 +264,7 @@ void menu_sliders::custom_render(void *selectedref, float top, float bottom, flo
standard menu handler standard menu handler
-------------------------------------------------*/ -------------------------------------------------*/
UINT32 menu_sliders::ui_handler(mame_ui_manager &mui, render_container *container, UINT32 state) UINT32 menu_sliders::ui_handler(render_container *container, mame_ui_manager &mui, bool state)
{ {
UINT32 result; UINT32 result;
@ -273,7 +273,7 @@ UINT32 menu_sliders::ui_handler(mame_ui_manager &mui, render_container *containe
menu::stack_push<menu_sliders>(mui, container, true); menu::stack_push<menu_sliders>(mui, container, true);
/* handle standard menus */ /* handle standard menus */
result = menu::ui_handler(mui, container, state); result = menu::ui_handler(container, mui);
/* if we are cancelled, pop the sliders menu */ /* if we are cancelled, pop the sliders menu */
if (result == UI_HANDLER_CANCEL) if (result == UI_HANDLER_CANCEL)

View File

@ -27,7 +27,7 @@ public:
virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2) override; virtual void custom_render(void *selectedref, float top, float bottom, float x, float y, float x2, float y2) override;
static UINT32 ui_handler(mame_ui_manager &mui, render_container *container, UINT32 state); static UINT32 ui_handler(render_container *container, mame_ui_manager &mui, bool state);
private: private:
enum { enum {

View File

@ -242,7 +242,7 @@ void mame_ui_manager::init()
decode_ui_color(0, &machine()); decode_ui_color(0, &machine());
// more initialization // more initialization
set_handler(handler_messagebox, 0); set_handler(UI_CALLBACK_TYPE_GENERAL, &mame_ui_manager::handler_messagebox);
m_non_char_keys_down = std::make_unique<UINT8[]>((ARRAY_LENGTH(non_char_keys) + 7) / 8); m_non_char_keys_down = std::make_unique<UINT8[]>((ARRAY_LENGTH(non_char_keys) + 7) / 8);
m_mouse_show = machine().system().flags & MACHINE_CLICKABLE_ARTWORK ? true : false; m_mouse_show = machine().system().flags & MACHINE_CLICKABLE_ARTWORK ? true : false;
@ -302,11 +302,10 @@ void mame_ui_manager::initialize(running_machine &machine)
// pair for the current UI handler // pair for the current UI handler
//------------------------------------------------- //-------------------------------------------------
UINT32 mame_ui_manager::set_handler(ui_callback callback, UINT32 param) void mame_ui_manager::set_handler(ui_callback_type callback_type, const std::function<UINT32 (render_container *)> callback)
{ {
m_handler_callback = callback; m_handler_callback = callback;
m_handler_param = param; m_handler_callback_type = callback_type;
return param;
} }
@ -334,7 +333,7 @@ void mame_ui_manager::display_startup_screens(bool first_time)
#endif #endif
// loop over states // loop over states
set_handler(handler_ingame, 0); set_handler(UI_CALLBACK_TYPE_GENERAL, &mame_ui_manager::handler_ingame);
for (state = 0; state < maxstate && !machine().scheduled_event_pending() && !ui::menu::stack_has_special_main_menu(); state++) for (state = 0; state < maxstate && !machine().scheduled_event_pending() && !ui::menu::stack_has_special_main_menu(); state++)
{ {
// default to standard colors // default to standard colors
@ -346,7 +345,7 @@ void mame_ui_manager::display_startup_screens(bool first_time)
case 0: case 0:
if (show_warnings && warnings_string(messagebox_text).length() > 0) if (show_warnings && warnings_string(messagebox_text).length() > 0)
{ {
set_handler(handler_messagebox_anykey, 0); set_handler(UI_CALLBACK_TYPE_MODAL, &mame_ui_manager::handler_messagebox_anykey);
if (machine().system().flags & (MACHINE_WRONG_COLORS | MACHINE_IMPERFECT_COLORS | MACHINE_REQUIRES_ARTWORK | MACHINE_IMPERFECT_GRAPHICS | MACHINE_IMPERFECT_SOUND | MACHINE_IMPERFECT_KEYBOARD | MACHINE_NO_SOUND)) if (machine().system().flags & (MACHINE_WRONG_COLORS | MACHINE_IMPERFECT_COLORS | MACHINE_REQUIRES_ARTWORK | MACHINE_IMPERFECT_GRAPHICS | MACHINE_IMPERFECT_SOUND | MACHINE_IMPERFECT_KEYBOARD | MACHINE_NO_SOUND))
messagebox_backcolor = UI_YELLOW_COLOR; messagebox_backcolor = UI_YELLOW_COLOR;
if (machine().system().flags & (MACHINE_NOT_WORKING | MACHINE_UNEMULATED_PROTECTION | MACHINE_MECHANICAL)) if (machine().system().flags & (MACHINE_NOT_WORKING | MACHINE_UNEMULATED_PROTECTION | MACHINE_MECHANICAL))
@ -356,7 +355,7 @@ void mame_ui_manager::display_startup_screens(bool first_time)
case 1: case 1:
if (show_gameinfo && game_info_astring(messagebox_text).length() > 0) if (show_gameinfo && game_info_astring(messagebox_text).length() > 0)
set_handler(handler_messagebox_anykey, 0); set_handler(UI_CALLBACK_TYPE_MODAL, &mame_ui_manager::handler_messagebox_anykey);
break; break;
case 2: case 2:
@ -374,19 +373,19 @@ void mame_ui_manager::display_startup_screens(bool first_time)
while (machine().input().poll_switches() != INPUT_CODE_INVALID) { } while (machine().input().poll_switches() != INPUT_CODE_INVALID) { }
// loop while we have a handler // loop while we have a handler
while (m_handler_callback != handler_ingame && !machine().scheduled_event_pending() && !ui::menu::stack_has_special_main_menu()) while (m_handler_callback_type == UI_CALLBACK_TYPE_MODAL && !machine().scheduled_event_pending() && !ui::menu::stack_has_special_main_menu())
{ {
machine().video().frame_update(); machine().video().frame_update();
} }
// clear the handler and force an update // clear the handler and force an update
set_handler(handler_ingame, 0); set_handler(UI_CALLBACK_TYPE_GENERAL, &mame_ui_manager::handler_ingame);
machine().video().frame_update(); machine().video().frame_update();
} }
// if we're the empty driver, force the menus on // if we're the empty driver, force the menus on
if (ui::menu::stack_has_special_main_menu()) if (ui::menu::stack_has_special_main_menu())
set_handler(ui::menu::ui_handler, 0); show_menu();
} }
@ -443,8 +442,7 @@ void mame_ui_manager::update_and_render(render_container *container)
} }
// call the current UI handler // call the current UI handler
assert(m_handler_callback != nullptr); m_handler_param = m_handler_callback(container);
m_handler_param = (*m_handler_callback)(*this, container, m_handler_param);
// display any popup messages // display any popup messages
if (osd_ticks() < m_popup_text_end) if (osd_ticks() < m_popup_text_end)
@ -472,7 +470,7 @@ void mame_ui_manager::update_and_render(render_container *container)
// cancel takes us back to the ingame handler // cancel takes us back to the ingame handler
if (m_handler_param == UI_HANDLER_CANCEL) if (m_handler_param == UI_HANDLER_CANCEL)
set_handler(handler_ingame, 0); set_handler(UI_CALLBACK_TYPE_GENERAL, &mame_ui_manager::handler_ingame);
} }
@ -946,7 +944,7 @@ bool mame_ui_manager::show_profiler() const
void mame_ui_manager::show_menu() void mame_ui_manager::show_menu()
{ {
set_handler(ui::menu::ui_handler, 0); set_handler<mame_ui_manager&>(UI_CALLBACK_TYPE_MENU, ui::menu::ui_handler, *this);
} }
@ -967,7 +965,7 @@ void mame_ui_manager::show_mouse(bool status)
bool mame_ui_manager::is_menu_active(void) bool mame_ui_manager::is_menu_active(void)
{ {
return (m_handler_callback == ui::menu::ui_handler); return m_handler_callback_type == UI_CALLBACK_TYPE_MENU;
} }
@ -1234,9 +1232,9 @@ std::string &mame_ui_manager::game_info_astring(std::string &str)
// messagebox_text string but handles no input // messagebox_text string but handles no input
//------------------------------------------------- //-------------------------------------------------
UINT32 mame_ui_manager::handler_messagebox(mame_ui_manager &mui, render_container *container, UINT32 state) UINT32 mame_ui_manager::handler_messagebox(render_container *container)
{ {
mui.draw_text_box(container, messagebox_text.c_str(), JUSTIFY_LEFT, 0.5f, 0.5f, messagebox_backcolor); draw_text_box(container, messagebox_text.c_str(), JUSTIFY_LEFT, 0.5f, 0.5f, messagebox_backcolor);
return 0; return 0;
} }
@ -1247,20 +1245,22 @@ UINT32 mame_ui_manager::handler_messagebox(mame_ui_manager &mui, render_containe
// any keypress // any keypress
//------------------------------------------------- //-------------------------------------------------
UINT32 mame_ui_manager::handler_messagebox_anykey(mame_ui_manager &mui, render_container *container, UINT32 state) UINT32 mame_ui_manager::handler_messagebox_anykey(render_container *container)
{ {
UINT32 state = 0;
// draw a standard message window // draw a standard message window
mui.draw_text_box(container, messagebox_text.c_str(), JUSTIFY_LEFT, 0.5f, 0.5f, messagebox_backcolor); draw_text_box(container, messagebox_text.c_str(), JUSTIFY_LEFT, 0.5f, 0.5f, messagebox_backcolor);
// if the user cancels, exit out completely // if the user cancels, exit out completely
if (mui.machine().ui_input().pressed(IPT_UI_CANCEL)) if (machine().ui_input().pressed(IPT_UI_CANCEL))
{ {
mui.machine().schedule_exit(); machine().schedule_exit();
state = UI_HANDLER_CANCEL; state = UI_HANDLER_CANCEL;
} }
// if any key is pressed, just exit // if any key is pressed, just exit
else if (mui.machine().input().poll_switches() != INPUT_CODE_INVALID) else if (machine().input().poll_switches() != INPUT_CODE_INVALID)
state = UI_HANDLER_CANCEL; state = UI_HANDLER_CANCEL;
return state; return state;
@ -1461,62 +1461,62 @@ void mame_ui_manager::image_display(const device_type &type, device_image_interf
// of the standard keypresses // of the standard keypresses
//------------------------------------------------- //-------------------------------------------------
UINT32 mame_ui_manager::handler_ingame(mame_ui_manager &mui, render_container *container, UINT32 state) UINT32 mame_ui_manager::handler_ingame(render_container *container)
{ {
bool is_paused = mui.machine().paused(); bool is_paused = machine().paused();
// first draw the FPS counter // first draw the FPS counter
if (mui.show_fps_counter()) if (show_fps_counter())
{ {
mui.draw_text_full(container, mui.machine().video().speed_text().c_str(), 0.0f, 0.0f, 1.0f, draw_text_full(container, machine().video().speed_text().c_str(), 0.0f, 0.0f, 1.0f,
JUSTIFY_RIGHT, WRAP_WORD, DRAW_OPAQUE, rgb_t::white, rgb_t::black, nullptr, nullptr); JUSTIFY_RIGHT, WRAP_WORD, DRAW_OPAQUE, rgb_t::white, rgb_t::black, nullptr, nullptr);
} }
// Show the duration of current part (intro or gameplay or extra) // Show the duration of current part (intro or gameplay or extra)
if (mui.show_timecode_counter()) { if (show_timecode_counter()) {
std::string tempstring; std::string tempstring;
mui.draw_text_full(container, mui.machine().video().timecode_text(tempstring).c_str(), 0.0f, 0.0f, 1.0f, draw_text_full(container, machine().video().timecode_text(tempstring).c_str(), 0.0f, 0.0f, 1.0f,
JUSTIFY_RIGHT, WRAP_WORD, DRAW_OPAQUE, rgb_t(0xf0,0xf0,0x10,0x10), rgb_t::black, nullptr, nullptr); JUSTIFY_RIGHT, WRAP_WORD, DRAW_OPAQUE, rgb_t(0xf0,0xf0,0x10,0x10), rgb_t::black, nullptr, nullptr);
} }
// Show the total time elapsed for the video preview (all parts intro, gameplay, extras) // Show the total time elapsed for the video preview (all parts intro, gameplay, extras)
if (mui.show_timecode_total()) { if (show_timecode_total()) {
std::string tempstring; std::string tempstring;
mui.draw_text_full(container, mui.machine().video().timecode_total_text(tempstring).c_str(), 0.0f, 0.0f, 1.0f, draw_text_full(container, machine().video().timecode_total_text(tempstring).c_str(), 0.0f, 0.0f, 1.0f,
JUSTIFY_LEFT, WRAP_WORD, DRAW_OPAQUE, rgb_t(0xf0,0x10,0xf0,0x10), rgb_t::black, nullptr, nullptr); JUSTIFY_LEFT, WRAP_WORD, DRAW_OPAQUE, rgb_t(0xf0,0x10,0xf0,0x10), rgb_t::black, nullptr, nullptr);
} }
// draw the profiler if visible // draw the profiler if visible
if (mui.show_profiler()) if (show_profiler())
{ {
const char *text = g_profiler.text(mui.machine()); const char *text = g_profiler.text(machine());
mui.draw_text_full(container, text, 0.0f, 0.0f, 1.0f, JUSTIFY_LEFT, WRAP_WORD, DRAW_OPAQUE, rgb_t::white, rgb_t::black, nullptr, nullptr); draw_text_full(container, text, 0.0f, 0.0f, 1.0f, JUSTIFY_LEFT, WRAP_WORD, DRAW_OPAQUE, rgb_t::white, rgb_t::black, nullptr, nullptr);
} }
// if we're single-stepping, pause now // if we're single-stepping, pause now
if (mui.single_step()) if (single_step())
{ {
mui.machine().pause(); machine().pause();
mui.set_single_step(false); set_single_step(false);
} }
// determine if we should disable the rest of the UI // determine if we should disable the rest of the UI
bool has_keyboard = mui.machine().ioport().has_keyboard(); bool has_keyboard = machine().ioport().has_keyboard();
bool ui_disabled = (has_keyboard && !mui.machine().ui_active()); bool ui_disabled = (has_keyboard && !machine().ui_active());
// is ScrLk UI toggling applicable here? // is ScrLk UI toggling applicable here?
if (has_keyboard) if (has_keyboard)
{ {
// are we toggling the UI with ScrLk? // are we toggling the UI with ScrLk?
if (mui.machine().ui_input().pressed(IPT_UI_TOGGLE_UI)) if (machine().ui_input().pressed(IPT_UI_TOGGLE_UI))
{ {
// toggle the UI // toggle the UI
mui.machine().set_ui_active(!mui.machine().ui_active()); machine().set_ui_active(!machine().ui_active());
// display a popup indicating the new status // display a popup indicating the new status
if (mui.machine().ui_active()) if (machine().ui_active())
{ {
mui.popup_time(2, "%s\n%s\n%s\n%s\n%s\n%s\n", popup_time(2, "%s\n%s\n%s\n%s\n%s\n%s\n",
_("Keyboard Emulation Status"), _("Keyboard Emulation Status"),
"-------------------------", "-------------------------",
_("Mode: PARTIAL Emulation"), _("Mode: PARTIAL Emulation"),
@ -1526,7 +1526,7 @@ UINT32 mame_ui_manager::handler_ingame(mame_ui_manager &mui, render_container *c
} }
else else
{ {
mui.popup_time(2, "%s\n%s\n%s\n%s\n%s\n%s\n", popup_time(2, "%s\n%s\n%s\n%s\n%s\n%s\n",
_("Keyboard Emulation Status"), _("Keyboard Emulation Status"),
"-------------------------", "-------------------------",
_("Mode: FULL Emulation"), _("Mode: FULL Emulation"),
@ -1538,64 +1538,71 @@ UINT32 mame_ui_manager::handler_ingame(mame_ui_manager &mui, render_container *c
} }
// is the natural keyboard enabled? // is the natural keyboard enabled?
if (mui.use_natural_keyboard() && (mui.machine().phase() == MACHINE_PHASE_RUNNING)) if (use_natural_keyboard() && (machine().phase() == MACHINE_PHASE_RUNNING))
mui.process_natural_keyboard(); process_natural_keyboard();
if (!ui_disabled) if (!ui_disabled)
{ {
// paste command // paste command
if (mui.machine().ui_input().pressed(IPT_UI_PASTE)) if (machine().ui_input().pressed(IPT_UI_PASTE))
mui.paste(); paste();
} }
mui.image_handler_ingame(); image_handler_ingame();
// handle a save input timecode request // handle a save input timecode request
if (mui.machine().ui_input().pressed(IPT_UI_TIMECODE)) if (machine().ui_input().pressed(IPT_UI_TIMECODE))
mui.machine().video().save_input_timecode(); machine().video().save_input_timecode();
if (ui_disabled) return ui_disabled; if (ui_disabled) return ui_disabled;
if (mui.machine().ui_input().pressed(IPT_UI_CANCEL)) if (machine().ui_input().pressed(IPT_UI_CANCEL))
{ {
mui.request_quit(); request_quit();
return 0; return 0;
} }
// turn on menus if requested // turn on menus if requested
if (mui.machine().ui_input().pressed(IPT_UI_CONFIGURE)) if (machine().ui_input().pressed(IPT_UI_CONFIGURE))
return mui.set_handler(ui::menu::ui_handler, 0); {
show_menu();
return 0;
}
// if the on-screen display isn't up and the user has toggled it, turn it on // if the on-screen display isn't up and the user has toggled it, turn it on
if ((mui.machine().debug_flags & DEBUG_FLAG_ENABLED) == 0 && mui.machine().ui_input().pressed(IPT_UI_ON_SCREEN_DISPLAY)) if ((machine().debug_flags & DEBUG_FLAG_ENABLED) == 0 && machine().ui_input().pressed(IPT_UI_ON_SCREEN_DISPLAY))
return mui.set_handler(ui::menu_sliders::ui_handler, 1); {
set_handler<mame_ui_manager&, bool>(UI_CALLBACK_TYPE_GENERAL, ui::menu_sliders::ui_handler, *this, true);
return 1;
}
// handle a reset request // handle a reset request
if (mui.machine().ui_input().pressed(IPT_UI_RESET_MACHINE)) if (machine().ui_input().pressed(IPT_UI_RESET_MACHINE))
mui.machine().schedule_hard_reset(); machine().schedule_hard_reset();
if (mui.machine().ui_input().pressed(IPT_UI_SOFT_RESET)) if (machine().ui_input().pressed(IPT_UI_SOFT_RESET))
mui.machine().schedule_soft_reset(); machine().schedule_soft_reset();
// handle a request to display graphics/palette // handle a request to display graphics/palette
if (mui.machine().ui_input().pressed(IPT_UI_SHOW_GFX)) if (machine().ui_input().pressed(IPT_UI_SHOW_GFX))
{ {
if (!is_paused) if (!is_paused)
mui.machine().pause(); machine().pause();
return mui.set_handler(ui_gfx_ui_handler, is_paused); set_handler<mame_ui_manager&, bool>(UI_CALLBACK_TYPE_GENERAL, ui_gfx_ui_handler, *this, is_paused);
return is_paused ? 1 : 0;
} }
// handle a tape control key // handle a tape control key
if (mui.machine().ui_input().pressed(IPT_UI_TAPE_START)) if (machine().ui_input().pressed(IPT_UI_TAPE_START))
{ {
for (cassette_image_device &cass : cassette_device_iterator(mui.machine().root_device())) for (cassette_image_device &cass : cassette_device_iterator(machine().root_device()))
{ {
cass.change_state(CASSETTE_PLAY, CASSETTE_MASK_UISTATE); cass.change_state(CASSETTE_PLAY, CASSETTE_MASK_UISTATE);
return 0; return 0;
} }
} }
if (mui.machine().ui_input().pressed(IPT_UI_TAPE_STOP)) if (machine().ui_input().pressed(IPT_UI_TAPE_STOP))
{ {
for (cassette_image_device &cass : cassette_device_iterator(mui.machine().root_device())) for (cassette_image_device &cass : cassette_device_iterator(machine().root_device()))
{ {
cass.change_state(CASSETTE_STOPPED, CASSETTE_MASK_UISTATE); cass.change_state(CASSETTE_STOPPED, CASSETTE_MASK_UISTATE);
return 0; return 0;
@ -1603,87 +1610,89 @@ UINT32 mame_ui_manager::handler_ingame(mame_ui_manager &mui, render_container *c
} }
// handle a save state request // handle a save state request
if (mui.machine().ui_input().pressed(IPT_UI_SAVE_STATE)) if (machine().ui_input().pressed(IPT_UI_SAVE_STATE))
{ {
mui.machine().pause(); machine().pause();
mui.m_load_save_hold = true; m_load_save_hold = true;
return mui.set_handler(handler_load_save, LOADSAVE_SAVE); set_handler(UI_CALLBACK_TYPE_GENERAL, &mame_ui_manager::handler_load_save, (UINT32)LOADSAVE_SAVE);
return LOADSAVE_SAVE;
} }
// handle a load state request // handle a load state request
if (mui.machine().ui_input().pressed(IPT_UI_LOAD_STATE)) if (machine().ui_input().pressed(IPT_UI_LOAD_STATE))
{ {
mui.machine().pause(); machine().pause();
mui.m_load_save_hold = true; m_load_save_hold = true;
return mui.set_handler(handler_load_save, LOADSAVE_LOAD); set_handler(UI_CALLBACK_TYPE_GENERAL, &mame_ui_manager::handler_load_save, (UINT32)LOADSAVE_LOAD);
return LOADSAVE_LOAD;
} }
// handle a save snapshot request // handle a save snapshot request
if (mui.machine().ui_input().pressed(IPT_UI_SNAPSHOT)) if (machine().ui_input().pressed(IPT_UI_SNAPSHOT))
mui.machine().video().save_active_screen_snapshots(); machine().video().save_active_screen_snapshots();
// toggle pause // toggle pause
if (mui.machine().ui_input().pressed(IPT_UI_PAUSE)) if (machine().ui_input().pressed(IPT_UI_PAUSE))
mui.machine().toggle_pause(); machine().toggle_pause();
// pause single step // pause single step
if (mui.machine().ui_input().pressed(IPT_UI_PAUSE_SINGLE)) if (machine().ui_input().pressed(IPT_UI_PAUSE_SINGLE))
{ {
mui.set_single_step(true); set_single_step(true);
mui.machine().resume(); machine().resume();
} }
// handle a toggle cheats request // handle a toggle cheats request
if (mui.machine().ui_input().pressed(IPT_UI_TOGGLE_CHEAT)) if (machine().ui_input().pressed(IPT_UI_TOGGLE_CHEAT))
mame_machine_manager::instance()->cheat().set_enable(!mame_machine_manager::instance()->cheat().enabled()); mame_machine_manager::instance()->cheat().set_enable(!mame_machine_manager::instance()->cheat().enabled());
// toggle movie recording // toggle movie recording
if (mui.machine().ui_input().pressed(IPT_UI_RECORD_MOVIE)) if (machine().ui_input().pressed(IPT_UI_RECORD_MOVIE))
mui.machine().video().toggle_record_movie(); machine().video().toggle_record_movie();
// toggle profiler display // toggle profiler display
if (mui.machine().ui_input().pressed(IPT_UI_SHOW_PROFILER)) if (machine().ui_input().pressed(IPT_UI_SHOW_PROFILER))
mui.set_show_profiler(!mui.show_profiler()); set_show_profiler(!show_profiler());
// toggle FPS display // toggle FPS display
if (mui.machine().ui_input().pressed(IPT_UI_SHOW_FPS)) if (machine().ui_input().pressed(IPT_UI_SHOW_FPS))
mui.set_show_fps(!mui.show_fps()); set_show_fps(!show_fps());
// increment frameskip? // increment frameskip?
if (mui.machine().ui_input().pressed(IPT_UI_FRAMESKIP_INC)) if (machine().ui_input().pressed(IPT_UI_FRAMESKIP_INC))
mui.increase_frameskip(); increase_frameskip();
// decrement frameskip? // decrement frameskip?
if (mui.machine().ui_input().pressed(IPT_UI_FRAMESKIP_DEC)) if (machine().ui_input().pressed(IPT_UI_FRAMESKIP_DEC))
mui.decrease_frameskip(); decrease_frameskip();
// toggle throttle? // toggle throttle?
if (mui.machine().ui_input().pressed(IPT_UI_THROTTLE)) if (machine().ui_input().pressed(IPT_UI_THROTTLE))
mui.machine().video().toggle_throttle(); machine().video().toggle_throttle();
// toggle autofire // toggle autofire
if (mui.machine().ui_input().pressed(IPT_UI_TOGGLE_AUTOFIRE)) if (machine().ui_input().pressed(IPT_UI_TOGGLE_AUTOFIRE))
{ {
if (!mui.machine().options().cheat()) if (!machine().options().cheat())
{ {
mui.machine().popmessage(_("Autofire can't be enabled")); machine().popmessage(_("Autofire can't be enabled"));
} }
else else
{ {
bool autofire_toggle = mui.machine().ioport().get_autofire_toggle(); bool autofire_toggle = machine().ioport().get_autofire_toggle();
mui.machine().ioport().set_autofire_toggle(!autofire_toggle); machine().ioport().set_autofire_toggle(!autofire_toggle);
mui.machine().popmessage("Autofire %s", autofire_toggle ? _("Enabled") : _("Disabled")); machine().popmessage("Autofire %s", autofire_toggle ? _("Enabled") : _("Disabled"));
} }
} }
// check for fast forward // check for fast forward
if (mui.machine().ioport().type_pressed(IPT_UI_FAST_FORWARD)) if (machine().ioport().type_pressed(IPT_UI_FAST_FORWARD))
{ {
mui.machine().video().set_fastforward(true); machine().video().set_fastforward(true);
mui.show_fps_temp(0.5); show_fps_temp(0.5);
} }
else else
mui.machine().video().set_fastforward(false); machine().video().set_fastforward(false);
return 0; return 0;
} }
@ -1694,7 +1703,7 @@ UINT32 mame_ui_manager::handler_ingame(mame_ui_manager &mui, render_container *c
// specifying a game to save or load // specifying a game to save or load
//------------------------------------------------- //-------------------------------------------------
UINT32 mame_ui_manager::handler_load_save(mame_ui_manager &mui, render_container *container, UINT32 state) UINT32 mame_ui_manager::handler_load_save(render_container *container, UINT32 state)
{ {
char filename[20]; char filename[20];
char file = 0; char file = 0;
@ -1705,52 +1714,52 @@ UINT32 mame_ui_manager::handler_load_save(mame_ui_manager &mui, render_container
// okay, we're waiting for a key to select a slot; display a message // okay, we're waiting for a key to select a slot; display a message
if (state == LOADSAVE_SAVE) if (state == LOADSAVE_SAVE)
mui.draw_message_window(container, _("Select position to save to")); draw_message_window(container, _("Select position to save to"));
else else
mui.draw_message_window(container, _("Select position to load from")); draw_message_window(container, _("Select position to load from"));
// if load/save state sequence is still being pressed, do not read the filename yet // if load/save state sequence is still being pressed, do not read the filename yet
if (mui.m_load_save_hold) { if (m_load_save_hold) {
bool seq_in_progress = false; bool seq_in_progress = false;
const input_seq &load_save_seq = state == LOADSAVE_SAVE ? const input_seq &load_save_seq = state == LOADSAVE_SAVE ?
mui.machine().ioport().type_seq(IPT_UI_SAVE_STATE) : machine().ioport().type_seq(IPT_UI_SAVE_STATE) :
mui.machine().ioport().type_seq(IPT_UI_LOAD_STATE); machine().ioport().type_seq(IPT_UI_LOAD_STATE);
for (int i = 0; i < load_save_seq.length(); i++) for (int i = 0; i < load_save_seq.length(); i++)
if (mui.machine().input().code_pressed_once(load_save_seq[i])) if (machine().input().code_pressed_once(load_save_seq[i]))
seq_in_progress = true; seq_in_progress = true;
if (seq_in_progress) if (seq_in_progress)
return state; return state;
else else
mui.m_load_save_hold = false; m_load_save_hold = false;
} }
// check for cancel key // check for cancel key
if (mui.machine().ui_input().pressed(IPT_UI_CANCEL)) if (machine().ui_input().pressed(IPT_UI_CANCEL))
{ {
// display a popup indicating things were cancelled // display a popup indicating things were cancelled
if (state == LOADSAVE_SAVE) if (state == LOADSAVE_SAVE)
mui.machine().popmessage(_("Save cancelled")); machine().popmessage(_("Save cancelled"));
else else
mui.machine().popmessage(_("Load cancelled")); machine().popmessage(_("Load cancelled"));
// reset the state // reset the state
mui.machine().resume(); machine().resume();
return UI_HANDLER_CANCEL; return UI_HANDLER_CANCEL;
} }
// check for A-Z or 0-9 // check for A-Z or 0-9
for (input_item_id id = ITEM_ID_A; id <= ITEM_ID_Z; ++id) for (input_item_id id = ITEM_ID_A; id <= ITEM_ID_Z; ++id)
if (mui.machine().input().code_pressed_once(input_code(DEVICE_CLASS_KEYBOARD, 0, ITEM_CLASS_SWITCH, ITEM_MODIFIER_NONE, id))) if (machine().input().code_pressed_once(input_code(DEVICE_CLASS_KEYBOARD, 0, ITEM_CLASS_SWITCH, ITEM_MODIFIER_NONE, id)))
file = id - ITEM_ID_A + 'a'; file = id - ITEM_ID_A + 'a';
if (file == 0) if (file == 0)
for (input_item_id id = ITEM_ID_0; id <= ITEM_ID_9; ++id) for (input_item_id id = ITEM_ID_0; id <= ITEM_ID_9; ++id)
if (mui.machine().input().code_pressed_once(input_code(DEVICE_CLASS_KEYBOARD, 0, ITEM_CLASS_SWITCH, ITEM_MODIFIER_NONE, id))) if (machine().input().code_pressed_once(input_code(DEVICE_CLASS_KEYBOARD, 0, ITEM_CLASS_SWITCH, ITEM_MODIFIER_NONE, id)))
file = id - ITEM_ID_0 + '0'; file = id - ITEM_ID_0 + '0';
if (file == 0) if (file == 0)
for (input_item_id id = ITEM_ID_0_PAD; id <= ITEM_ID_9_PAD; ++id) for (input_item_id id = ITEM_ID_0_PAD; id <= ITEM_ID_9_PAD; ++id)
if (mui.machine().input().code_pressed_once(input_code(DEVICE_CLASS_KEYBOARD, 0, ITEM_CLASS_SWITCH, ITEM_MODIFIER_NONE, id))) if (machine().input().code_pressed_once(input_code(DEVICE_CLASS_KEYBOARD, 0, ITEM_CLASS_SWITCH, ITEM_MODIFIER_NONE, id)))
file = id - ITEM_ID_0_PAD + '0'; file = id - ITEM_ID_0_PAD + '0';
if (file == 0) if (file == 0)
{ {
@ -1758,7 +1767,7 @@ UINT32 mame_ui_manager::handler_load_save(mame_ui_manager &mui, render_container
for (int joy_index = 0; joy_index <= MAX_SAVED_STATE_JOYSTICK; joy_index++) for (int joy_index = 0; joy_index <= MAX_SAVED_STATE_JOYSTICK; joy_index++)
for (input_item_id id = ITEM_ID_BUTTON1; id <= ITEM_ID_BUTTON32; ++id) for (input_item_id id = ITEM_ID_BUTTON1; id <= ITEM_ID_BUTTON32; ++id)
if (mui.machine().input().code_pressed_once(input_code(DEVICE_CLASS_JOYSTICK, joy_index, ITEM_CLASS_SWITCH, ITEM_MODIFIER_NONE, id))) if (machine().input().code_pressed_once(input_code(DEVICE_CLASS_JOYSTICK, joy_index, ITEM_CLASS_SWITCH, ITEM_MODIFIER_NONE, id)))
{ {
snprintf(filename, sizeof(filename), "joy%i-%i", joy_index, id - ITEM_ID_BUTTON1 + 1); snprintf(filename, sizeof(filename), "joy%i-%i", joy_index, id - ITEM_ID_BUTTON1 + 1);
found = true; found = true;
@ -1776,20 +1785,20 @@ UINT32 mame_ui_manager::handler_load_save(mame_ui_manager &mui, render_container
// display a popup indicating that the save will proceed // display a popup indicating that the save will proceed
if (state == LOADSAVE_SAVE) if (state == LOADSAVE_SAVE)
{ {
mui.machine().popmessage(_("Save to position %s"), filename); machine().popmessage(_("Save to position %s"), filename);
mui.machine().schedule_save(filename); machine().schedule_save(filename);
} }
else else
{ {
mui.machine().popmessage(_("Load from position %s"), filename); machine().popmessage(_("Load from position %s"), filename);
mui.machine().schedule_load(filename); machine().schedule_load(filename);
} }
// avoid handling the name of the save state slot as a seperate input // avoid handling the name of the save state slot as a seperate input
mui.machine().ui_input().mark_all_as_pressed(); machine().ui_input().mark_all_as_pressed();
// remove the pause and reset the state // remove the pause and reset the state
mui.machine().resume(); machine().resume();
return UI_HANDLER_CANCEL; return UI_HANDLER_CANCEL;
} }
@ -1803,7 +1812,7 @@ void mame_ui_manager::request_quit()
if (!machine().options().confirm_quit()) if (!machine().options().confirm_quit())
machine().schedule_exit(); machine().schedule_exit();
else else
set_handler(handler_confirm_quit, 0); set_handler(UI_CALLBACK_TYPE_GENERAL, &mame_ui_manager::handler_confirm_quit);
} }
@ -1812,13 +1821,15 @@ void mame_ui_manager::request_quit()
// confirming quit emulation // confirming quit emulation
//------------------------------------------------- //-------------------------------------------------
UINT32 mame_ui_manager::handler_confirm_quit(mame_ui_manager &mui, render_container *container, UINT32 state) UINT32 mame_ui_manager::handler_confirm_quit(render_container *container)
{ {
UINT32 state = 0;
// get the text for 'UI Select' // get the text for 'UI Select'
std::string ui_select_text = mui.machine().input().seq_name(mui.machine().ioport().type_seq(IPT_UI_SELECT, 0, SEQ_TYPE_STANDARD)); std::string ui_select_text = machine().input().seq_name(machine().ioport().type_seq(IPT_UI_SELECT, 0, SEQ_TYPE_STANDARD));
// get the text for 'UI Cancel' // get the text for 'UI Cancel'
std::string ui_cancel_text = mui.machine().input().seq_name(mui.machine().ioport().type_seq(IPT_UI_CANCEL, 0, SEQ_TYPE_STANDARD)); std::string ui_cancel_text = machine().input().seq_name(machine().ioport().type_seq(IPT_UI_CANCEL, 0, SEQ_TYPE_STANDARD));
// assemble the quit message // assemble the quit message
std::string quit_message = string_format(_("Are you sure you want to quit?\n\n" std::string quit_message = string_format(_("Are you sure you want to quit?\n\n"
@ -1827,17 +1838,17 @@ UINT32 mame_ui_manager::handler_confirm_quit(mame_ui_manager &mui, render_contai
ui_select_text, ui_select_text,
ui_cancel_text); ui_cancel_text);
mui.draw_text_box(container, quit_message.c_str(), JUSTIFY_CENTER, 0.5f, 0.5f, UI_RED_COLOR); draw_text_box(container, quit_message.c_str(), JUSTIFY_CENTER, 0.5f, 0.5f, UI_RED_COLOR);
mui.machine().pause(); machine().pause();
// if the user press ENTER, quit the game // if the user press ENTER, quit the game
if (mui.machine().ui_input().pressed(IPT_UI_SELECT)) if (machine().ui_input().pressed(IPT_UI_SELECT))
mui.machine().schedule_exit(); machine().schedule_exit();
// if the user press ESC, just continue // if the user press ESC, just continue
else if (mui.machine().ui_input().pressed(IPT_UI_CANCEL)) else if (machine().ui_input().pressed(IPT_UI_CANCEL))
{ {
mui.machine().resume(); machine().resume();
state = UI_HANDLER_CANCEL; state = UI_HANDLER_CANCEL;
} }

View File

@ -154,6 +154,13 @@ enum
class mame_ui_manager; class mame_ui_manager;
typedef UINT32 (*ui_callback)(mame_ui_manager &, render_container *, UINT32); typedef UINT32 (*ui_callback)(mame_ui_manager &, render_container *, UINT32);
enum ui_callback_type
{
UI_CALLBACK_TYPE_GENERAL,
UI_CALLBACK_TYPE_MODAL,
UI_CALLBACK_TYPE_MENU
};
// ======================> mame_ui_manager // ======================> mame_ui_manager
class mame_ui_manager : public ui_manager, public slider_changed_notifier class mame_ui_manager : public ui_manager, public slider_changed_notifier
@ -175,7 +182,35 @@ public:
// methods // methods
void initialize(running_machine &machine); void initialize(running_machine &machine);
std::vector<ui::menu_item> slider_init(running_machine &machine); std::vector<ui::menu_item> slider_init(running_machine &machine);
UINT32 set_handler(ui_callback callback, UINT32 param);
void set_handler(ui_callback_type callback_type, const std::function<UINT32 (render_container *)> callback);
template<typename T, typename... Params>
void set_handler(ui_callback_type callback_type, T &obj, UINT32(T::*callback)(render_container *, Params...), Params ...args)
{
auto lambda = [=, &obj](render_container *container)
{
return ((obj).*(callback))(container, args...);
};
set_handler(callback_type, lambda);
}
template<typename... Params>
void set_handler(ui_callback_type callback_type, UINT32(mame_ui_manager::*callback)(render_container *, Params...), Params ...args)
{
set_handler(callback_type, *this, callback, args...);
}
template<typename... Params>
void set_handler(ui_callback_type callback_type, UINT32(*callback)(render_container *, Params...), Params ...args)
{
auto lambda = [&, callback](render_container *container)
{
return callback(container, args...);
};
set_handler(callback_type, lambda);
}
void display_startup_screens(bool first_time); void display_startup_screens(bool first_time);
virtual void set_startup_text(const char *text, bool force) override; virtual void set_startup_text(const char *text, bool force) override;
void update_and_render(render_container *container); void update_and_render(render_container *container);
@ -236,7 +271,8 @@ public:
private: private:
// instance variables // instance variables
render_font * m_font; render_font * m_font;
ui_callback m_handler_callback; std::function<UINT32 (render_container *)> m_handler_callback;
ui_callback_type m_handler_callback_type;
UINT32 m_handler_param; UINT32 m_handler_param;
bool m_single_step; bool m_single_step;
bool m_showfps; bool m_showfps;
@ -261,11 +297,11 @@ private:
std::string &warnings_string(std::string &buffer); std::string &warnings_string(std::string &buffer);
// UI handlers // UI handlers
static UINT32 handler_messagebox(mame_ui_manager &mui, render_container *container, UINT32 state); UINT32 handler_messagebox(render_container *container);
static UINT32 handler_messagebox_anykey(mame_ui_manager &mui, render_container *container, UINT32 state); UINT32 handler_messagebox_anykey(render_container *container);
static UINT32 handler_ingame(mame_ui_manager &mui, render_container *container, UINT32 state); UINT32 handler_ingame(render_container *container);
static UINT32 handler_load_save(mame_ui_manager &mui, render_container *container, UINT32 state); UINT32 handler_load_save(render_container *container, UINT32 state);
static UINT32 handler_confirm_quit(mame_ui_manager &mui, render_container *container, UINT32 state); UINT32 handler_confirm_quit(render_container *container);
// private methods // private methods
void exit(); void exit();

View File

@ -240,7 +240,7 @@ bool ui_gfx_is_relevant(running_machine &machine)
// ui_gfx_ui_handler - primary UI handler // ui_gfx_ui_handler - primary UI handler
//------------------------------------------------- //-------------------------------------------------
UINT32 ui_gfx_ui_handler(mame_ui_manager &mui, render_container *container, UINT32 uistate) UINT32 ui_gfx_ui_handler(render_container *container, mame_ui_manager &mui, bool uistate)
{ {
ui_gfx_state &state = ui_gfx; ui_gfx_state &state = ui_gfx;

View File

@ -26,7 +26,7 @@ void ui_gfx_init(running_machine &machine);
bool ui_gfx_is_relevant(running_machine &machine); bool ui_gfx_is_relevant(running_machine &machine);
// master handler // master handler
UINT32 ui_gfx_ui_handler(mame_ui_manager &mui, render_container *container, UINT32 state); UINT32 ui_gfx_ui_handler(render_container *container, mame_ui_manager &mui, bool uistate);
#endif /* __UI_VIEWGFX_H__ */ #endif /* __UI_VIEWGFX_H__ */