From 2f2a843d77bdf69581449a8240e478de5eaab20d Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 26 Sep 2015 02:22:01 +0200 Subject: [PATCH] Create menu_setting_get_type --- menu/cbs/menu_cbs_deferred_push.c | 2 +- menu/cbs/menu_cbs_left.c | 4 +-- menu/cbs/menu_cbs_ok.c | 2 +- menu/cbs/menu_cbs_right.c | 4 +-- menu/cbs/menu_cbs_select.c | 37 ++++++++++----------- menu/cbs/menu_cbs_title.c | 2 +- menu/menu_displaylist.c | 55 +++++++++++++++++-------------- menu/menu_entry.c | 12 ++++--- menu/menu_setting.c | 38 +++++++++++++++------ menu/menu_setting.h | 2 ++ 10 files changed, 92 insertions(+), 66 deletions(-) diff --git a/menu/cbs/menu_cbs_deferred_push.c b/menu/cbs/menu_cbs_deferred_push.c index 850f9353e3..090885e8cf 100644 --- a/menu/cbs/menu_cbs_deferred_push.c +++ b/menu/cbs/menu_cbs_deferred_push.c @@ -740,7 +740,7 @@ int menu_cbs_init_bind_deferred_push(menu_file_list_cbs_t *cbs, { uint32_t parent_group_hash = menu_hash_calculate(cbs->setting->parent_group); - if ((parent_group_hash == MENU_VALUE_MAIN_MENU) && cbs->setting->type == ST_GROUP) + if ((parent_group_hash == MENU_VALUE_MAIN_MENU) && menu_setting_get_type(cbs->setting) == ST_GROUP) { if (!settings->menu.collapse_subgroups_enable) { diff --git a/menu/cbs/menu_cbs_left.c b/menu/cbs/menu_cbs_left.c index ae240bf194..119fe21f41 100644 --- a/menu/cbs/menu_cbs_left.c +++ b/menu/cbs/menu_cbs_left.c @@ -230,7 +230,7 @@ static int action_left_shader_filter_default(unsigned type, const char *label, if (!setting) return -1; return menu_action_handle_setting(setting, - setting->type, MENU_ACTION_LEFT, wraparound); + menu_setting_get_type(setting), MENU_ACTION_LEFT, wraparound); #else return 0; #endif @@ -333,7 +333,7 @@ static int menu_cbs_init_bind_left_compare_label(menu_file_list_cbs_t *cbs, { uint32_t parent_group_hash = menu_hash_calculate(cbs->setting->parent_group); - if ((parent_group_hash == MENU_VALUE_MAIN_MENU) && (cbs->setting->type == ST_GROUP)) + if ((parent_group_hash == MENU_VALUE_MAIN_MENU) && (menu_setting_get_type(cbs->setting) == ST_GROUP)) { cbs->action_left = action_left_scroll; return 0; diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 0ac4a05f7b..f276aa6088 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -943,7 +943,7 @@ static int action_ok_file_load(const char *path, setting = menu_setting_find(menu_label); - if (setting && setting->type == ST_PATH) + if (menu_setting_get_type(setting) == ST_PATH) return action_ok_set_path(path, label, type, idx, entry_idx); if (type == MENU_FILE_IN_CARCHIVE) diff --git a/menu/cbs/menu_cbs_right.c b/menu/cbs/menu_cbs_right.c index 2ed78cb798..7cfd849743 100644 --- a/menu/cbs/menu_cbs_right.c +++ b/menu/cbs/menu_cbs_right.c @@ -254,7 +254,7 @@ static int action_right_shader_filter_default(unsigned type, const char *label, rarch_setting_t *setting = menu_setting_find(menu_hash_to_str(MENU_LABEL_VIDEO_SMOOTH)); if (!setting) return -1; - return menu_action_handle_setting(setting, setting->type, MENU_ACTION_RIGHT, + return menu_action_handle_setting(setting, menu_setting_get_type(setting), MENU_ACTION_RIGHT, wraparound); #else return 0; @@ -440,7 +440,7 @@ static int menu_cbs_init_bind_right_compare_label(menu_file_list_cbs_t *cbs, { uint32_t parent_group_hash = menu_hash_calculate(cbs->setting->parent_group); - if ((parent_group_hash == MENU_LABEL_SETTINGS) && (cbs->setting->type == ST_GROUP)) + if ((parent_group_hash == MENU_LABEL_SETTINGS) && (menu_setting_get_type(cbs->setting) == ST_GROUP)) { cbs->action_right = action_right_scroll; return 0; diff --git a/menu/cbs/menu_cbs_select.c b/menu/cbs/menu_cbs_select.c index 9b38681e84..714274b296 100644 --- a/menu/cbs/menu_cbs_select.c +++ b/menu/cbs/menu_cbs_select.c @@ -33,27 +33,24 @@ static int action_select_default(const char *path, const char *label, unsigned t cbs = menu_list_get_actiondata_at_offset(menu_list->selection_buf, idx); - if (cbs->setting) + switch (menu_setting_get_type(cbs->setting)) { - switch (cbs->setting->type) - { - case ST_BOOL: - case ST_INT: - case ST_UINT: - case ST_FLOAT: - action = MENU_ACTION_RIGHT; - break; - case ST_PATH: - case ST_DIR: - case ST_ACTION: - case ST_STRING: - case ST_HEX: - case ST_BIND: - action = MENU_ACTION_OK; - break; - default: - break; - } + case ST_BOOL: + case ST_INT: + case ST_UINT: + case ST_FLOAT: + action = MENU_ACTION_RIGHT; + break; + case ST_PATH: + case ST_DIR: + case ST_ACTION: + case ST_STRING: + case ST_HEX: + case ST_BIND: + action = MENU_ACTION_OK; + break; + default: + break; } if (action == MENU_ACTION_NOOP) diff --git a/menu/cbs/menu_cbs_title.c b/menu/cbs/menu_cbs_title.c index 76d9bc5439..875a41d132 100644 --- a/menu/cbs/menu_cbs_title.c +++ b/menu/cbs/menu_cbs_title.c @@ -473,7 +473,7 @@ static int menu_cbs_init_bind_title_compare_label(menu_file_list_cbs_t *cbs, { uint32_t parent_group_hash = menu_hash_calculate(cbs->setting->parent_group); - if ((parent_group_hash == MENU_VALUE_MAIN_MENU) && cbs->setting->type == ST_GROUP) + if ((parent_group_hash == MENU_VALUE_MAIN_MENU) && menu_setting_get_type(cbs->setting) == ST_GROUP) { cbs->action_get_title = action_get_title_group_settings; return 0; diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index e6d7151792..e821693abb 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -1554,13 +1554,14 @@ static void menu_displaylist_realloc_settings(menu_entries_t *entries, unsigned static int menu_setting_set_flags(rarch_setting_t *setting) { + enum setting_type setting_type = menu_setting_get_type(setting); if (!setting) return 0; if (setting->flags & SD_FLAG_IS_DRIVER) return MENU_SETTING_DRIVER; - switch (setting->type) + switch (setting_type) { case ST_ACTION: return MENU_SETTING_ACTION; @@ -1592,9 +1593,9 @@ static int menu_displaylist_parse_settings(menu_handle_t *menu, return -1; - for (; setting->type != ST_END_GROUP; setting++) + for (; menu_setting_get_type(setting) != ST_END_GROUP; setting++) { - switch (setting->type) + switch (menu_setting_get_type(setting)) { case ST_GROUP: case ST_SUB_GROUP: @@ -1657,7 +1658,7 @@ static int menu_displaylist_parse_settings_in_subgroup(menu_displaylist_info_t * while (1) { - if (info->setting->type == ST_SUB_GROUP) + if (menu_setting_get_type(info->setting) == ST_SUB_GROUP) { if ((strlen(info->setting->name) != 0) && !strcmp(info->setting->name, elem1)) break; @@ -1668,7 +1669,7 @@ static int menu_displaylist_parse_settings_in_subgroup(menu_displaylist_info_t * info->setting++; - for (; info->setting->type != ST_END_SUB_GROUP; info->setting++) + for (; menu_setting_get_type(info->setting) != ST_END_SUB_GROUP; info->setting++) menu_list_push(info->list, info->setting->short_description, info->setting->name, menu_setting_set_flags(info->setting), 0, 0); @@ -2512,9 +2513,9 @@ int menu_displaylist_push_list(menu_displaylist_info_t *info, unsigned type) if (settings->menu.collapse_subgroups_enable) { - for (; setting->type != ST_NONE; setting++) + for (; menu_setting_get_type(setting) != ST_NONE; setting++) { - if (setting->type == ST_GROUP) + if (menu_setting_get_type(setting) == ST_GROUP) { if (setting->flags & SD_FLAG_ADVANCED && !settings->menu.show_advanced_settings) @@ -2526,29 +2527,35 @@ int menu_displaylist_push_list(menu_displaylist_info_t *info, unsigned type) } else { - for (; setting->type != ST_NONE; setting++) + for (; menu_setting_get_type(setting) != ST_NONE; setting++) { - char group_label[PATH_MAX_LENGTH] = {0}; - char subgroup_label[PATH_MAX_LENGTH] = {0}; + char group_label[PATH_MAX_LENGTH], subgroup_label[PATH_MAX_LENGTH]; + enum setting_type setting_type = menu_setting_get_type(setting); - if (setting->type == ST_GROUP) - strlcpy(group_label, setting->name, sizeof(group_label)); - else if (setting->type == ST_SUB_GROUP) + switch (setting_type) { - char new_label[PATH_MAX_LENGTH] = {0}; - char new_path[PATH_MAX_LENGTH] = {0}; + case ST_GROUP: + strlcpy(group_label, setting->name, sizeof(group_label)); + break; + case ST_SUB_GROUP: + { + char new_label[PATH_MAX_LENGTH], new_path[PATH_MAX_LENGTH]; - strlcpy(subgroup_label, setting->name, sizeof(group_label)); - strlcpy(new_label, group_label, sizeof(new_label)); - strlcat(new_label, "|", sizeof(new_label)); - strlcat(new_label, subgroup_label, sizeof(new_label)); + strlcpy(subgroup_label, setting->name, sizeof(group_label)); + strlcpy(new_label, group_label, sizeof(new_label)); + strlcat(new_label, "|", sizeof(new_label)); + strlcat(new_label, subgroup_label, sizeof(new_label)); - strlcpy(new_path, group_label, sizeof(new_path)); - strlcat(new_path, " - ", sizeof(new_path)); - strlcat(new_path, setting->short_description, sizeof(new_path)); + strlcpy(new_path, group_label, sizeof(new_path)); + strlcat(new_path, " - ", sizeof(new_path)); + strlcat(new_path, setting->short_description, sizeof(new_path)); - menu_list_push(info->list, new_path, - new_label, MENU_SETTING_SUBGROUP, 0, 0); + menu_list_push(info->list, new_path, + new_label, MENU_SETTING_SUBGROUP, 0, 0); + } + break; + default: + break; } } } diff --git a/menu/menu_entry.c b/menu/menu_entry.c index 783ca75b1a..9dfa65b1dc 100644 --- a/menu/menu_entry.c +++ b/menu/menu_entry.c @@ -66,12 +66,14 @@ enum menu_entry_type menu_entry_get_type(uint32_t i) if (menu_setting_is_of_path_type(setting)) return MENU_ENTRY_PATH; - if (setting && (setting->type == ST_STRING) && setting->values) - return MENU_ENTRY_ENUM; - if (setting) { - switch (setting->type) + enum setting_type setting_type = menu_setting_get_type(setting); + + if ((setting_type == ST_STRING) && setting->values) + return MENU_ENTRY_ENUM; + + switch (setting_type) { case ST_BOOL: return MENU_ENTRY_BOOL; @@ -224,7 +226,7 @@ int menu_entry_pathdir_set_value(uint32_t i, const char *s) if (!cbs || !cbs->setting) return -1; - if (cbs->setting->type != ST_DIR) + if (menu_setting_get_type(cbs->setting) != ST_DIR) return -1; setting_set_with_string_representation(cbs->setting, menu_path); diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 54ffa1d20e..ff5b97ffba 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -43,6 +43,13 @@ #include "../file_ext.h" #include "../performance.h" +enum setting_type menu_setting_get_type(rarch_setting_t *setting) +{ + if (!setting) + return ST_NONE; + return setting->type; +} + static void menu_settings_info_list_free(rarch_setting_info_t *list_info) { if (list_info) @@ -186,12 +193,15 @@ static int setting_handler(rarch_setting_t *setting, unsigned action) int menu_action_handle_setting(rarch_setting_t *setting, unsigned type, unsigned action, bool wraparound) { + enum setting_type setting_type; menu_displaylist_info_t info = {0}; if (!setting) return -1; - switch (setting->type) + setting_type = menu_setting_get_type(setting); + + switch (setting_type) { case ST_PATH: if (action == MENU_ACTION_OK) @@ -249,9 +259,9 @@ rarch_setting_t *menu_setting_find(const char *label) needle = menu_hash_calculate(label); - for (; settings->type != ST_NONE; settings++) + for (; menu_setting_get_type(settings) != ST_NONE; settings++) { - if (needle == settings->name_hash && settings->type <= ST_GROUP) + if (needle == settings->name_hash && menu_setting_get_type(settings) <= ST_GROUP) { /* make sure this isn't a collision */ if (strcmp(label, settings->name) != 0) @@ -302,10 +312,13 @@ int menu_setting_set(unsigned type, const char *label, **/ static void setting_reset_setting(rarch_setting_t* setting) { + enum setting_type setting_type; if (!setting) return; - switch (setting->type) + setting_type = menu_setting_get_type(setting); + + switch (setting_type) { case ST_BOOL: *setting->value.boolean = setting->default_value.boolean; @@ -327,7 +340,7 @@ static void setting_reset_setting(rarch_setting_t* setting) case ST_DIR: if (setting->default_value.string) { - if (setting->type == ST_STRING) + if (menu_setting_get_type(setting) == ST_STRING) setting_set_with_string_representation(setting, setting->default_value.string); else fill_pathname_expand_special(setting->value.string, @@ -367,10 +380,13 @@ static void setting_reset_setting(rarch_setting_t* setting) int setting_set_with_string_representation(rarch_setting_t* setting, const char* value) { + enum setting_type setting_type; if (!setting || !value) return -1; - switch (setting->type) + setting_type = menu_setting_get_type(setting); + + switch (setting_type) { case ST_INT: sscanf(value, "%d", setting->value.integer); @@ -1064,6 +1080,7 @@ static int setting_action_ok_video_refresh_rate_auto(void *data, bool wraparound static int setting_generic_action_ok_linefeed(void *data, bool wraparound) { + enum setting_type setting_type; input_keyboard_line_complete_t cb = NULL; rarch_setting_t *setting = (rarch_setting_t*)data; @@ -1071,8 +1088,9 @@ static int setting_generic_action_ok_linefeed(void *data, bool wraparound) return -1; (void)wraparound; + setting_type = menu_setting_get_type(setting); - switch (setting->type) + switch (setting_type) { case ST_UINT: cb = menu_input_st_uint_callback; @@ -5971,7 +5989,7 @@ void menu_setting_free(rarch_setting_t *list) if (!list) return; - for (; setting->type != ST_NONE; setting++) + for (; menu_setting_get_type(setting) != ST_NONE; setting++) { if (setting->flags & SD_FLAG_IS_DRIVER) { @@ -5979,7 +5997,7 @@ void menu_setting_free(rarch_setting_t *list) free((void*)setting->values); } - if (setting->type == ST_BIND) + if (menu_setting_get_type(setting) == ST_BIND) { free((void*)setting->name); free((void*)setting->short_description); @@ -6220,7 +6238,7 @@ bool menu_setting_is_of_path_type(rarch_setting_t *setting) { if ( setting && - setting->type == ST_ACTION && + (menu_setting_get_type(setting) == ST_ACTION) && (setting->flags & SD_FLAG_BROWSER_ACTION) && (setting->action_right || setting->action_left || setting->action_select) && setting->change_handler) diff --git a/menu/menu_setting.h b/menu/menu_setting.h index 313ef53b18..83c766dfa6 100644 --- a/menu/menu_setting.h +++ b/menu/menu_setting.h @@ -282,6 +282,8 @@ bool menu_setting_is_of_path_type(rarch_setting_t *setting); int menu_action_handle_setting(rarch_setting_t *setting, unsigned type, unsigned action, bool wraparound); +enum setting_type menu_setting_get_type(rarch_setting_t *setting); + #ifdef __cplusplus } #endif