From f6db9ce04ddb4b2d27c4fb2181fb21fb7514c6f2 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 30 Dec 2019 05:57:32 +0100 Subject: [PATCH] Move menu_subsystem_populate to menu_displaylist.c --- menu/menu_displaylist.c | 184 +++++++++++++++++++++++++++++++++++++++- menu/menu_driver.c | 177 -------------------------------------- menu/menu_driver.h | 2 - 3 files changed, 182 insertions(+), 181 deletions(-) diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 7fe83ae9e0..7c0a45f46e 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -96,6 +96,7 @@ #include "../performance_counters.h" #include "../core_info.h" #include "../wifi/wifi_driver.h" +#include "../tasks/task_content.h" #include "../tasks/tasks_internal.h" #include "../dynamic.h" #include "../runtime_file.h" @@ -6986,6 +6987,185 @@ static unsigned menu_displaylist_build_shader_parameter( return count; } +static unsigned menu_displaylist_populate_subsystem( + const struct retro_subsystem_info* subsystem, void *data) +{ + unsigned count = 0; + settings_t *settings = config_get_ptr(); + file_list_t *list = (file_list_t*)data; + /* Note: Create this string here explicitly (rather than + * using a #define elsewhere) since we need to be aware of + * its length... */ +#if defined(__APPLE__) + /* UTF-8 support is currently broken on Apple devices... */ + static const char utf8_star_char[] = "*"; +#else + /* + * UCN equivalent: "\u2605" */ + static const char utf8_star_char[] = "\xE2\x98\x85"; +#endif + char star_char[16]; + unsigned i = 0; + int n = 0; + bool is_rgui = string_is_equal(settings->arrays.menu_driver, "rgui"); + + /* Select appropriate 'star' marker for subsystem menu entries + * (i.e. RGUI does not support unicode, so use a 'standard' + * character fallback) */ + snprintf(star_char, sizeof(star_char), "%s", is_rgui ? "*" : utf8_star_char); + + if (subsystem && subsystem_current_count > 0) + { + for (i = 0; i < subsystem_current_count; i++, subsystem++) + { + char s[PATH_MAX_LENGTH]; + if (content_get_subsystem() == i) + { + if (content_get_subsystem_rom_id() < subsystem->num_roms) + { + snprintf(s, sizeof(s), + "Load %s %s", + subsystem->desc, + star_char); + + /* If using RGUI with sublabels disabled, add the + * appropriate text to the menu entry itself... */ + if (is_rgui && !settings->bools.menu_show_sublabels) + { + char tmp[PATH_MAX_LENGTH]; + + n = snprintf(tmp, sizeof(tmp), + "%s [%s %s]", s, "Current Content:", + subsystem->roms[content_get_subsystem_rom_id()].desc); + + /* Stupid GCC will warn about snprintf() truncation even though + * we couldn't care less about it (if the menu entry label gets + * truncated then the string will already be too long to view in + * any usable manner on screen, so the fact that the end is + * missing is irrelevant). There are two ways to silence this noise: + * 1) Make the destination buffers large enough that text cannot be + * truncated. This is a waste of memory. + * 2) Check the snprintf() return value (and take action). This is + * the most harmless option, so we just print a warning if anything + * is truncated. + * To reiterate: The actual warning generated here is pointless, and + * should be ignored. */ + if ((n < 0) || (n >= PATH_MAX_LENGTH)) + { + if (verbosity_is_enabled()) + { + RARCH_WARN("Menu subsystem entry: Description label truncated.\n"); + } + } + + strlcpy(s, tmp, sizeof(s)); + } + + if (menu_entries_append_enum(list, + s, + msg_hash_to_str(MENU_ENUM_LABEL_SUBSYSTEM_ADD), + MENU_ENUM_LABEL_SUBSYSTEM_ADD, + MENU_SETTINGS_SUBSYSTEM_ADD + i, 0, 0)) + count++; + } + else + { + snprintf(s, sizeof(s), + "Start %s %s", + subsystem->desc, + star_char); + + /* If using RGUI with sublabels disabled, add the + * appropriate text to the menu entry itself... */ + if (is_rgui && !settings->bools.menu_show_sublabels) + { + unsigned j = 0; + char rom_buff[PATH_MAX_LENGTH]; + char tmp[PATH_MAX_LENGTH]; + rom_buff[0] = '\0'; + + for (j = 0; j < content_get_subsystem_rom_id(); j++) + { + strlcat(rom_buff, + path_basename(content_get_subsystem_rom(j)), sizeof(rom_buff)); + if (j != content_get_subsystem_rom_id() - 1) + strlcat(rom_buff, "|", sizeof(rom_buff)); + } + + if (!string_is_empty(rom_buff)) + { + n = snprintf(tmp, sizeof(tmp), "%s [%s]", s, rom_buff); + + /* More snprintf() gcc warning suppression... */ + if ((n < 0) || (n >= PATH_MAX_LENGTH)) + { + if (verbosity_is_enabled()) + { + RARCH_WARN("Menu subsystem entry: Description label truncated.\n"); + } + } + + strlcpy(s, tmp, sizeof(s)); + } + } + + if (menu_entries_append_enum(list, + s, + msg_hash_to_str(MENU_ENUM_LABEL_SUBSYSTEM_LOAD), + MENU_ENUM_LABEL_SUBSYSTEM_LOAD, + MENU_SETTINGS_SUBSYSTEM_LOAD, 0, 0)) + count++; + } + } + else + { + snprintf(s, sizeof(s), + "Load %s", + subsystem->desc); + + /* If using RGUI with sublabels disabled, add the + * appropriate text to the menu entry itself... */ + if (is_rgui && !settings->bools.menu_show_sublabels) + { + /* This check is probably not required (it's not done + * in menu_cbs_sublabel.c action_bind_sublabel_subsystem_add(), + * anyway), but no harm in being safe... */ + if (subsystem->num_roms > 0) + { + char tmp[PATH_MAX_LENGTH]; + + n = snprintf(tmp, sizeof(tmp), + "%s [%s %s]", s, "Current Content:", + subsystem->roms[0].desc); + + /* More snprintf() gcc warning suppression... */ + if ((n < 0) || (n >= PATH_MAX_LENGTH)) + { + if (verbosity_is_enabled()) + { + RARCH_WARN("Menu subsystem entry: Description label truncated.\n"); + } + } + + strlcpy(s, tmp, sizeof(s)); + } + } + + if (menu_entries_append_enum(list, + s, + msg_hash_to_str(MENU_ENUM_LABEL_SUBSYSTEM_ADD), + MENU_ENUM_LABEL_SUBSYSTEM_ADD, + MENU_SETTINGS_SUBSYSTEM_ADD + i, 0, 0)) + count++; + } + } + } + + return count; +} + + + bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, menu_displaylist_info_t *info) { @@ -7021,7 +7201,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, if (sys_info && sys_info->subsystem.data) subsystem = sys_info->subsystem.data; - count = menu_subsystem_populate(subsystem, info->list); + count = menu_displaylist_populate_subsystem(subsystem, info->list); if (count == 0) menu_entries_append_enum(info->list, @@ -9254,7 +9434,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, if (sys_info && sys_info->subsystem.data) subsystem = sys_info->subsystem.data; - menu_subsystem_populate(subsystem, info->list); + menu_displaylist_populate_subsystem(subsystem, info->list); } if (settings->bools.menu_content_show_history) diff --git a/menu/menu_driver.c b/menu/menu_driver.c index f99621ba9a..e53a33a3ea 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -3966,183 +3966,6 @@ void hex32_to_rgba_normalized(uint32_t hex, float* rgba, float alpha) rgba[3] = rgba[7] = rgba[11] = rgba[15] = alpha; } -unsigned menu_subsystem_populate(const struct retro_subsystem_info* subsystem, void *data) -{ - unsigned count = 0; - settings_t *settings = config_get_ptr(); - file_list_t *list = (file_list_t*)data; - /* Note: Create this string here explicitly (rather than - * using a #define elsewhere) since we need to be aware of - * its length... */ -#if defined(__APPLE__) - /* UTF-8 support is currently broken on Apple devices... */ - static const char utf8_star_char[] = "*"; -#else - /* - * UCN equivalent: "\u2605" */ - static const char utf8_star_char[] = "\xE2\x98\x85"; -#endif - char star_char[16]; - unsigned i = 0; - int n = 0; - bool is_rgui = string_is_equal(settings->arrays.menu_driver, "rgui"); - - /* Select appropriate 'star' marker for subsystem menu entries - * (i.e. RGUI does not support unicode, so use a 'standard' - * character fallback) */ - snprintf(star_char, sizeof(star_char), "%s", is_rgui ? "*" : utf8_star_char); - - if (subsystem && subsystem_current_count > 0) - { - for (i = 0; i < subsystem_current_count; i++, subsystem++) - { - char s[PATH_MAX_LENGTH]; - if (content_get_subsystem() == i) - { - if (content_get_subsystem_rom_id() < subsystem->num_roms) - { - snprintf(s, sizeof(s), - "Load %s %s", - subsystem->desc, - star_char); - - /* If using RGUI with sublabels disabled, add the - * appropriate text to the menu entry itself... */ - if (is_rgui && !settings->bools.menu_show_sublabels) - { - char tmp[PATH_MAX_LENGTH]; - - n = snprintf(tmp, sizeof(tmp), - "%s [%s %s]", s, "Current Content:", - subsystem->roms[content_get_subsystem_rom_id()].desc); - - /* Stupid GCC will warn about snprintf() truncation even though - * we couldn't care less about it (if the menu entry label gets - * truncated then the string will already be too long to view in - * any usable manner on screen, so the fact that the end is - * missing is irrelevant). There are two ways to silence this noise: - * 1) Make the destination buffers large enough that text cannot be - * truncated. This is a waste of memory. - * 2) Check the snprintf() return value (and take action). This is - * the most harmless option, so we just print a warning if anything - * is truncated. - * To reiterate: The actual warning generated here is pointless, and - * should be ignored. */ - if ((n < 0) || (n >= PATH_MAX_LENGTH)) - { - if (verbosity_is_enabled()) - { - RARCH_WARN("Menu subsystem entry: Description label truncated.\n"); - } - } - - strlcpy(s, tmp, sizeof(s)); - } - - if (menu_entries_append_enum(list, - s, - msg_hash_to_str(MENU_ENUM_LABEL_SUBSYSTEM_ADD), - MENU_ENUM_LABEL_SUBSYSTEM_ADD, - MENU_SETTINGS_SUBSYSTEM_ADD + i, 0, 0)) - count++; - } - else - { - snprintf(s, sizeof(s), - "Start %s %s", - subsystem->desc, - star_char); - - /* If using RGUI with sublabels disabled, add the - * appropriate text to the menu entry itself... */ - if (is_rgui && !settings->bools.menu_show_sublabels) - { - unsigned j = 0; - char rom_buff[PATH_MAX_LENGTH]; - char tmp[PATH_MAX_LENGTH]; - rom_buff[0] = '\0'; - - for (j = 0; j < content_get_subsystem_rom_id(); j++) - { - strlcat(rom_buff, - path_basename(content_get_subsystem_rom(j)), sizeof(rom_buff)); - if (j != content_get_subsystem_rom_id() - 1) - strlcat(rom_buff, "|", sizeof(rom_buff)); - } - - if (!string_is_empty(rom_buff)) - { - n = snprintf(tmp, sizeof(tmp), "%s [%s]", s, rom_buff); - - /* More snprintf() gcc warning suppression... */ - if ((n < 0) || (n >= PATH_MAX_LENGTH)) - { - if (verbosity_is_enabled()) - { - RARCH_WARN("Menu subsystem entry: Description label truncated.\n"); - } - } - - strlcpy(s, tmp, sizeof(s)); - } - } - - if (menu_entries_append_enum(list, - s, - msg_hash_to_str(MENU_ENUM_LABEL_SUBSYSTEM_LOAD), - MENU_ENUM_LABEL_SUBSYSTEM_LOAD, - MENU_SETTINGS_SUBSYSTEM_LOAD, 0, 0)) - count++; - } - } - else - { - snprintf(s, sizeof(s), - "Load %s", - subsystem->desc); - - /* If using RGUI with sublabels disabled, add the - * appropriate text to the menu entry itself... */ - if (is_rgui && !settings->bools.menu_show_sublabels) - { - /* This check is probably not required (it's not done - * in menu_cbs_sublabel.c action_bind_sublabel_subsystem_add(), - * anyway), but no harm in being safe... */ - if (subsystem->num_roms > 0) - { - char tmp[PATH_MAX_LENGTH]; - - n = snprintf(tmp, sizeof(tmp), - "%s [%s %s]", s, "Current Content:", - subsystem->roms[0].desc); - - /* More snprintf() gcc warning suppression... */ - if ((n < 0) || (n >= PATH_MAX_LENGTH)) - { - if (verbosity_is_enabled()) - { - RARCH_WARN("Menu subsystem entry: Description label truncated.\n"); - } - } - - strlcpy(s, tmp, sizeof(s)); - } - } - - if (menu_entries_append_enum(list, - s, - msg_hash_to_str(MENU_ENUM_LABEL_SUBSYSTEM_ADD), - MENU_ENUM_LABEL_SUBSYSTEM_ADD, - MENU_SETTINGS_SUBSYSTEM_ADD + i, 0, 0)) - count++; - } - } - } - - return count; -} - - void get_current_menu_value(char* retstr, size_t max) { const char* entry_label; diff --git a/menu/menu_driver.h b/menu/menu_driver.h index d5a5dec975..80914f382b 100644 --- a/menu/menu_driver.h +++ b/menu/menu_driver.h @@ -713,8 +713,6 @@ void menu_driver_destroy(void); void hex32_to_rgba_normalized(uint32_t hex, float* rgba, float alpha); -unsigned menu_subsystem_populate(const struct retro_subsystem_info* subsystem, void *data); - menu_handle_t *menu_driver_get_ptr(void); extern uintptr_t menu_display_white_texture;