diff --git a/Makefile.common b/Makefile.common index be72ceab49..e3a85f5a44 100644 --- a/Makefile.common +++ b/Makefile.common @@ -509,6 +509,7 @@ ifeq ($(HAVE_MENU_COMMON), 1) menu/menu_navigation.o \ menu/menu_setting.o \ menu/menu_shader.o \ + menu/menu_popup.o \ menu/menu_cbs.o \ menu/cbs/menu_cbs_ok.o \ menu/cbs/menu_cbs_cancel.o \ diff --git a/griffin/griffin.c b/griffin/griffin.c index 6567d4a4c6..5bb1de879d 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -891,6 +891,7 @@ MENU #include "../menu/menu_input.c" #include "../menu/menu_entry.c" #include "../menu/menu_entries.c" +#include "../menu/menu_popup.c" #include "../menu/menu_setting.c" #include "../menu/menu_cbs.c" #include "../menu/menu_content.c" diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index eaa8f16282..2004a19630 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -239,7 +239,8 @@ int generic_action_ok_displaylist_push(const char *path, dl_type = DISPLAYLIST_GENERIC; break; case ACTION_OK_DL_HELP: - info_label = label; + info_label = label; + menu->help_screen.type = type; menu->help_screen.push = true; dl_type = DISPLAYLIST_HELP; break; @@ -1444,25 +1445,17 @@ static int generic_action_ok_help(const char *path, enum msg_hash_enums id, enum menu_help_type id2) { const char *lbl = msg_hash_to_str(id); - menu_handle_t *menu = NULL; - menu_driver_ctl(RARCH_MENU_CTL_DRIVER_DATA_GET, &menu); - menu->help_screen.type = id2; - - return generic_action_ok_displaylist_push(path, NULL, lbl, type, idx, + return generic_action_ok_displaylist_push(path, NULL, lbl, id2, idx, entry_idx, ACTION_OK_DL_HELP); } static int action_ok_cheevos(const char *path, const char *label, unsigned type, size_t idx, size_t entry_idx) { - menu_handle_t *menu = NULL; unsigned new_id = type - MENU_SETTINGS_CHEEVOS_START; - menu_driver_ctl(RARCH_MENU_CTL_DRIVER_DATA_GET, &menu); - - menu->help_screen.id = new_id; - return generic_action_ok_help(path, label, type, idx, entry_idx, + return generic_action_ok_help(path, label, new_id, idx, entry_idx, MENU_ENUM_LABEL_CHEEVOS_DESCRIPTION, MENU_HELP_CHEEVOS_DESCRIPTION); } diff --git a/menu/drivers/menu_generic.c b/menu/drivers/menu_generic.c index 0d7a37ce82..3ce95bcb61 100644 --- a/menu/drivers/menu_generic.c +++ b/menu/drivers/menu_generic.c @@ -17,7 +17,6 @@ #include #include -#include #include "menu_generic.h" @@ -26,209 +25,13 @@ #include "../menu_displaylist.h" #include "../menu_navigation.h" #include "../menu_entries.h" +#include "../menu_popup.h" #include "../../configuration.h" #include "../../performance_counters.h" -#include "../../input/input_autodetect.h" -#include "../../input/input_config.h" -#include "../../cheevos.h" #include "../../verbosity.h" -static int action_iterate_help(menu_handle_t *menu, - char *s, size_t len, const char *label) -{ -#ifdef HAVE_CHEEVOS - cheevos_ctx_desc_t desc_info; -#endif - bool do_exit = false; - settings_t *settings = config_get_ptr(); - - switch (menu->help_screen.type) - { - case MENU_HELP_WELCOME: - { - static int64_t timeout_end; - int64_t timeout; - static bool timer_begin = false; - static bool timer_end = false; - int64_t current = cpu_features_get_time_usec(); - - if (!timer_begin) - { - timeout_end = cpu_features_get_time_usec() + - 3 /* seconds */ * 1000000; - timer_begin = true; - timer_end = false; - } - - timeout = (timeout_end - current) / 1000000; - - menu_hash_get_help_enum( - MENU_ENUM_LABEL_WELCOME_TO_RETROARCH, - s, len); - - if (!timer_end && timeout <= 0) - { - timer_end = true; - timer_begin = false; - timeout_end = 0; - do_exit = true; - } - } - break; - case MENU_HELP_CONTROLS: - { - unsigned i; - char s2[PATH_MAX_LENGTH] = {0}; - const unsigned binds[] = { - RETRO_DEVICE_ID_JOYPAD_UP, - RETRO_DEVICE_ID_JOYPAD_DOWN, - RETRO_DEVICE_ID_JOYPAD_A, - RETRO_DEVICE_ID_JOYPAD_B, - RETRO_DEVICE_ID_JOYPAD_SELECT, - RETRO_DEVICE_ID_JOYPAD_START, - RARCH_MENU_TOGGLE, - RARCH_QUIT_KEY, - RETRO_DEVICE_ID_JOYPAD_X, - RETRO_DEVICE_ID_JOYPAD_Y, - }; - char desc[ARRAY_SIZE(binds)][64] = {{0}}; - - for (i = 0; i < ARRAY_SIZE(binds); i++) - { - const struct retro_keybind *keybind = - (const struct retro_keybind*) - &settings->input.binds[0][binds[i]]; - const struct retro_keybind *auto_bind = - (const struct retro_keybind*) - input_get_auto_bind(0, binds[i]); - - input_config_get_bind_string(desc[i], - keybind, auto_bind, sizeof(desc[i])); - } - - menu_hash_get_help_enum(MENU_ENUM_LABEL_VALUE_MENU_ENUM_CONTROLS_PROLOG, - s2, sizeof(s2)); - - snprintf(s, len, - "%s" - "[%s]: " - "%-20s\n" - "[%s]: " - "%-20s\n" - "[%s]: " - "%-20s\n" - "[%s]: " - "%-20s\n" - "[%s]: " - "%-20s\n" - "[%s]: " - "%-20s\n" - "[%s]: " - "%-20s\n" - "[%s]: " - "%-20s\n" - "[%s]: " - "%-20s\n", - - s2, - - msg_hash_to_str( - MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_SCROLL_UP), - desc[0], - - msg_hash_to_str( - MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_SCROLL_DOWN), - desc[1], - - msg_hash_to_str( - MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_CONFIRM), - desc[2], - - msg_hash_to_str( - MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_BACK), - desc[3], - - msg_hash_to_str( - MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_INFO), - desc[4], - - msg_hash_to_str( - MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_START), - desc[5], - - msg_hash_to_str( - MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_TOGGLE_MENU), - desc[6], - - msg_hash_to_str( - MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_QUIT), - desc[7], - - msg_hash_to_str( - MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_TOGGLE_KEYBOARD), - desc[8] - - ); - } - break; - -#ifdef HAVE_CHEEVOS - case MENU_HELP_CHEEVOS_DESCRIPTION: - desc_info.idx = menu->help_screen.id; - desc_info.s = s; - desc_info.len = len; - cheevos_get_description(&desc_info); - break; -#endif - - case MENU_HELP_WHAT_IS_A_CORE: - menu_hash_get_help_enum(MENU_ENUM_LABEL_VALUE_WHAT_IS_A_CORE_DESC, - s, len); - break; - case MENU_HELP_LOADING_CONTENT: - menu_hash_get_help_enum(MENU_ENUM_LABEL_LOAD_CONTENT_LIST, - s, len); - break; - case MENU_HELP_CHANGE_VIRTUAL_GAMEPAD: - menu_hash_get_help_enum( - MENU_ENUM_LABEL_VALUE_HELP_CHANGE_VIRTUAL_GAMEPAD_DESC, - s, len); - break; - case MENU_HELP_AUDIO_VIDEO_TROUBLESHOOTING: - menu_hash_get_help_enum( - MENU_ENUM_LABEL_VALUE_HELP_AUDIO_VIDEO_TROUBLESHOOTING_DESC, - s, len); - break; - case MENU_HELP_SCANNING_CONTENT: - menu_hash_get_help_enum(MENU_ENUM_LABEL_VALUE_HELP_SCANNING_CONTENT_DESC, - s, len); - break; - case MENU_HELP_EXTRACT: - menu_hash_get_help_enum(MENU_ENUM_LABEL_VALUE_EXTRACTING_PLEASE_WAIT, - s, len); - - if (settings->bundle_finished) - { - settings->bundle_finished = false; - do_exit = true; - } - break; - case MENU_HELP_NONE: - default: - break; - } - - if (do_exit) - { - menu->help_screen.type = MENU_HELP_NONE; - return 1; - } - - return 0; -} - static enum action_iterate_type action_iterate_type(uint32_t hash) { switch (hash) @@ -297,7 +100,7 @@ int generic_menu_iterate(void *data, void *userdata, enum menu_action action) switch (iterate_type) { case ITERATE_TYPE_HELP: - ret = action_iterate_help(menu, + ret = menu_popup_iterate_help(menu, menu->menu_state.msg, sizeof(menu->menu_state.msg), label); BIT64_SET(menu->state, MENU_STATE_RENDER_MESSAGEBOX); BIT64_SET(menu->state, MENU_STATE_POST_ITERATE); @@ -429,19 +232,7 @@ int generic_menu_iterate(void *data, void *userdata, enum menu_action action) BIT64_SET(menu->state, MENU_STATE_POST_ITERATE); /* Have to defer it so we let settings refresh. */ - if (menu->help_screen.push) - { - menu_displaylist_info_t info = {0}; - file_list_t *menu_stack = menu_entries_get_menu_stack_ptr(0); - - info.list = menu_stack; - strlcpy(info.label, - msg_hash_to_str(MENU_ENUM_LABEL_HELP), - sizeof(info.label)); - info.enum_idx = MENU_ENUM_LABEL_HELP; - - menu_displaylist_ctl(DISPLAYLIST_HELP, &info); - } + menu_popup_push(menu); break; } diff --git a/menu/menu_popup.c b/menu/menu_popup.c new file mode 100644 index 0000000000..48674d6364 --- /dev/null +++ b/menu/menu_popup.c @@ -0,0 +1,237 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2011-2016 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include +#include + +#include "menu_driver.h" +#include "menu_popup.h" + +#include "../configuration.h" +#ifdef HAVE_CHEEVOS +#include "../cheevos.h" +#endif +#include "../input/input_autodetect.h" +#include "../input/input_config.h" + +int menu_popup_iterate_help(menu_handle_t *menu, + char *s, size_t len, const char *label) +{ +#ifdef HAVE_CHEEVOS + cheevos_ctx_desc_t desc_info; +#endif + bool do_exit = false; + settings_t *settings = config_get_ptr(); + + switch (menu->help_screen.type) + { + case MENU_HELP_WELCOME: + { + static int64_t timeout_end; + int64_t timeout; + static bool timer_begin = false; + static bool timer_end = false; + int64_t current = cpu_features_get_time_usec(); + + if (!timer_begin) + { + timeout_end = cpu_features_get_time_usec() + + 3 /* seconds */ * 1000000; + timer_begin = true; + timer_end = false; + } + + timeout = (timeout_end - current) / 1000000; + + menu_hash_get_help_enum( + MENU_ENUM_LABEL_WELCOME_TO_RETROARCH, + s, len); + + if (!timer_end && timeout <= 0) + { + timer_end = true; + timer_begin = false; + timeout_end = 0; + do_exit = true; + } + } + break; + case MENU_HELP_CONTROLS: + { + unsigned i; + char s2[PATH_MAX_LENGTH] = {0}; + const unsigned binds[] = { + RETRO_DEVICE_ID_JOYPAD_UP, + RETRO_DEVICE_ID_JOYPAD_DOWN, + RETRO_DEVICE_ID_JOYPAD_A, + RETRO_DEVICE_ID_JOYPAD_B, + RETRO_DEVICE_ID_JOYPAD_SELECT, + RETRO_DEVICE_ID_JOYPAD_START, + RARCH_MENU_TOGGLE, + RARCH_QUIT_KEY, + RETRO_DEVICE_ID_JOYPAD_X, + RETRO_DEVICE_ID_JOYPAD_Y, + }; + char desc[ARRAY_SIZE(binds)][64] = {{0}}; + + for (i = 0; i < ARRAY_SIZE(binds); i++) + { + const struct retro_keybind *keybind = + (const struct retro_keybind*) + &settings->input.binds[0][binds[i]]; + const struct retro_keybind *auto_bind = + (const struct retro_keybind*) + input_get_auto_bind(0, binds[i]); + + input_config_get_bind_string(desc[i], + keybind, auto_bind, sizeof(desc[i])); + } + + menu_hash_get_help_enum(MENU_ENUM_LABEL_VALUE_MENU_ENUM_CONTROLS_PROLOG, + s2, sizeof(s2)); + + snprintf(s, len, + "%s" + "[%s]: " + "%-20s\n" + "[%s]: " + "%-20s\n" + "[%s]: " + "%-20s\n" + "[%s]: " + "%-20s\n" + "[%s]: " + "%-20s\n" + "[%s]: " + "%-20s\n" + "[%s]: " + "%-20s\n" + "[%s]: " + "%-20s\n" + "[%s]: " + "%-20s\n", + + s2, + + msg_hash_to_str( + MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_SCROLL_UP), + desc[0], + + msg_hash_to_str( + MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_SCROLL_DOWN), + desc[1], + + msg_hash_to_str( + MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_CONFIRM), + desc[2], + + msg_hash_to_str( + MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_BACK), + desc[3], + + msg_hash_to_str( + MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_INFO), + desc[4], + + msg_hash_to_str( + MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_START), + desc[5], + + msg_hash_to_str( + MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_TOGGLE_MENU), + desc[6], + + msg_hash_to_str( + MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_QUIT), + desc[7], + + msg_hash_to_str( + MENU_ENUM_LABEL_VALUE_BASIC_MENU_CONTROLS_TOGGLE_KEYBOARD), + desc[8] + + ); + } + break; + +#ifdef HAVE_CHEEVOS + case MENU_HELP_CHEEVOS_DESCRIPTION: + desc_info.idx = menu->help_screen.id; + desc_info.s = s; + desc_info.len = len; + cheevos_get_description(&desc_info); + break; +#endif + + case MENU_HELP_WHAT_IS_A_CORE: + menu_hash_get_help_enum(MENU_ENUM_LABEL_VALUE_WHAT_IS_A_CORE_DESC, + s, len); + break; + case MENU_HELP_LOADING_CONTENT: + menu_hash_get_help_enum(MENU_ENUM_LABEL_LOAD_CONTENT_LIST, + s, len); + break; + case MENU_HELP_CHANGE_VIRTUAL_GAMEPAD: + menu_hash_get_help_enum( + MENU_ENUM_LABEL_VALUE_HELP_CHANGE_VIRTUAL_GAMEPAD_DESC, + s, len); + break; + case MENU_HELP_AUDIO_VIDEO_TROUBLESHOOTING: + menu_hash_get_help_enum( + MENU_ENUM_LABEL_VALUE_HELP_AUDIO_VIDEO_TROUBLESHOOTING_DESC, + s, len); + break; + case MENU_HELP_SCANNING_CONTENT: + menu_hash_get_help_enum(MENU_ENUM_LABEL_VALUE_HELP_SCANNING_CONTENT_DESC, + s, len); + break; + case MENU_HELP_EXTRACT: + menu_hash_get_help_enum(MENU_ENUM_LABEL_VALUE_EXTRACTING_PLEASE_WAIT, + s, len); + + if (settings->bundle_finished) + { + settings->bundle_finished = false; + do_exit = true; + } + break; + case MENU_HELP_NONE: + default: + break; + } + + if (do_exit) + { + menu->help_screen.type = MENU_HELP_NONE; + return 1; + } + + return 0; +} + +void menu_popup_push(menu_handle_t *menu) +{ + menu_displaylist_info_t info = {0}; + + if (!menu->help_screen.push) + return; + + info.list = menu_entries_get_menu_stack_ptr(0); + strlcpy(info.label, + msg_hash_to_str(MENU_ENUM_LABEL_HELP), + sizeof(info.label)); + info.enum_idx = MENU_ENUM_LABEL_HELP; + + menu_displaylist_ctl(DISPLAYLIST_HELP, &info); +} diff --git a/menu/menu_popup.h b/menu/menu_popup.h new file mode 100644 index 0000000000..898dd01460 --- /dev/null +++ b/menu/menu_popup.h @@ -0,0 +1,34 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2016 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#ifndef _MENU_POPUP_H +#define _MENU_POPUP_H + +#include +#include + +#include + +RETRO_BEGIN_DECLS + +int menu_popup_iterate_help(menu_handle_t *menu, + char *s, size_t len, const char *label); + +void menu_popup_push(menu_handle_t *menu); + +RETRO_END_DECLS + +#endif