From f00f73c5ed259a0683dd180731767c2b01039299 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 23 Sep 2018 10:59:09 +0200 Subject: [PATCH] Add 'dropdown list' when pressing the OK/Confirm button on Video -> Aspect Ratio --- config.def.h | 2 + configuration.c | 2 +- intl/msg_hash_lbl.h | 2 + menu/cbs/menu_cbs_cancel.c | 11 +++-- menu/cbs/menu_cbs_deferred_push.c | 6 +++ menu/cbs/menu_cbs_get_value.c | 2 + menu/cbs/menu_cbs_left.c | 2 +- menu/cbs/menu_cbs_ok.c | 46 +++++++++++++++++++- menu/cbs/menu_cbs_right.c | 2 +- menu/cbs/menu_cbs_start.c | 2 +- menu/cbs/menu_cbs_title.c | 12 +++++- menu/menu_cbs.h | 7 ++++ menu/menu_displaylist.c | 70 +++++++++++++++++++++++++++++++ menu/menu_displaylist.h | 1 + menu/menu_driver.h | 2 + menu/menu_setting.c | 20 ++++++++- menu/menu_setting.h | 3 +- msg_hash.h | 1 + 18 files changed, 180 insertions(+), 13 deletions(-) diff --git a/config.def.h b/config.def.h index 198c2c3fbb..de9215a0a5 100644 --- a/config.def.h +++ b/config.def.h @@ -148,6 +148,8 @@ static const bool vsync = true; static const unsigned max_swapchain_images = 3; +static const bool adaptive_vsync = true; + /* Attempts to hard-synchronize CPU and GPU. * Can reduce latency at cost of performance. */ static const bool hard_sync = false; diff --git a/configuration.c b/configuration.c index 0914c19c03..524efd6180 100644 --- a/configuration.c +++ b/configuration.c @@ -1315,7 +1315,7 @@ static struct config_bool_setting *populate_settings_bool(settings_t *settings, SETTING_BOOL("video_fullscreen", &settings->bools.video_fullscreen, true, fullscreen, false); SETTING_BOOL("bundle_assets_extract_enable", &settings->bools.bundle_assets_extract_enable, true, bundle_assets_extract_enable, false); SETTING_BOOL("video_vsync", &settings->bools.video_vsync, true, vsync, false); - SETTING_BOOL("video_adaptive_vsync", &settings->bools.video_adaptive_vsync, true, false, false); + SETTING_BOOL("video_adaptive_vsync", &settings->bools.video_adaptive_vsync, true, adaptive_vsync, false); SETTING_BOOL("video_hard_sync", &settings->bools.video_hard_sync, true, hard_sync, false); SETTING_BOOL("video_black_frame_insertion", &settings->bools.video_black_frame_insertion, true, black_frame_insertion, false); SETTING_BOOL("video_disable_composition", &settings->bools.video_disable_composition, true, disable_composition, false); diff --git a/intl/msg_hash_lbl.h b/intl/msg_hash_lbl.h index f1cd250913..f2e17652d5 100644 --- a/intl/msg_hash_lbl.h +++ b/intl/msg_hash_lbl.h @@ -241,6 +241,8 @@ MSG_HASH(MENU_ENUM_LABEL_DATABASE_MANAGER, "database_manager") MSG_HASH(MENU_ENUM_LABEL_DATABASE_MANAGER_LIST, "database_manager_list") +MSG_HASH(MENU_ENUM_LABEL_DEFERRED_DROPDOWN_BOX_LIST, + "deferred_dropdown_box_list") MSG_HASH(MENU_ENUM_LABEL_DEFERRED_CONFIGURATIONS_LIST, "deferred_configurations_list") MSG_HASH(MENU_ENUM_LABEL_DEFERRED_PLAYLIST_LIST, diff --git a/menu/cbs/menu_cbs_cancel.c b/menu/cbs/menu_cbs_cancel.c index ddd6d09f1d..6d2ff230a8 100644 --- a/menu/cbs/menu_cbs_cancel.c +++ b/menu/cbs/menu_cbs_cancel.c @@ -30,12 +30,17 @@ #endif /* Clicks the back button */ -static int action_cancel_pop_default(const char *path, +int action_cancel_pop_default(const char *path, const char *label, unsigned type, size_t idx) { size_t new_selection_ptr; - const char *menu_label = NULL; - enum msg_hash_enums enum_idx = 0 ; + const char *menu_label = NULL; + enum msg_hash_enums enum_idx = 0; + + (void)path; + (void)label; + (void)type; + (void)idx; menu_entries_get_last_stack(NULL, &menu_label, NULL, &enum_idx, NULL); diff --git a/menu/cbs/menu_cbs_deferred_push.c b/menu/cbs/menu_cbs_deferred_push.c index 8415ec7010..e63b591f8a 100644 --- a/menu/cbs/menu_cbs_deferred_push.c +++ b/menu/cbs/menu_cbs_deferred_push.c @@ -602,6 +602,7 @@ generic_deferred_push_clear_general(deferred_playlist_list, PUSH_DEFAULT, DISPLA generic_deferred_push_clear_general(deferred_music_history_list, PUSH_DEFAULT, DISPLAYLIST_MUSIC_HISTORY) generic_deferred_push_clear_general(deferred_image_history_list, PUSH_DEFAULT, DISPLAYLIST_IMAGES_HISTORY) generic_deferred_push_clear_general(deferred_video_history_list, PUSH_DEFAULT, DISPLAYLIST_VIDEO_HISTORY) +generic_deferred_push_clear_general(deferred_push_dropdown_box_list, PUSH_DEFAULT, DISPLAYLIST_DROPDOWN_LIST) static int menu_cbs_init_bind_deferred_push_compare_label( menu_file_list_cbs_t *cbs, @@ -612,6 +613,11 @@ static int menu_cbs_init_bind_deferred_push_compare_label( BIND_ACTION_DEFERRED_PUSH(cbs, deferred_push_favorites_list); return 0; } + else if (string_is_equal(label, msg_hash_to_str(MENU_ENUM_LABEL_DEFERRED_DROPDOWN_BOX_LIST))) + { + BIND_ACTION_DEFERRED_PUSH(cbs, deferred_push_dropdown_box_list); + return 0; + } else if (string_is_equal(label, msg_hash_to_str(MENU_ENUM_LABEL_DEFERRED_BROWSE_URL_LIST))) { BIND_ACTION_DEFERRED_PUSH(cbs, deferred_push_browse_url_list); diff --git a/menu/cbs/menu_cbs_get_value.c b/menu/cbs/menu_cbs_get_value.c index efcd41013c..a087141bc7 100644 --- a/menu/cbs/menu_cbs_get_value.c +++ b/menu/cbs/menu_cbs_get_value.c @@ -2383,6 +2383,8 @@ static int menu_cbs_init_bind_get_string_representation_compare_type( case 26: /* URL entries */ BIND_ACTION_GET_VALUE(cbs, menu_action_setting_disp_set_label_entry_url); break; + case MENU_SETTING_DROPDOWN_SETTING_UINT_ITEM: + case MENU_SETTING_DROPDOWN_ITEM: case MENU_SETTING_NO_ITEM: BIND_ACTION_GET_VALUE(cbs, menu_action_setting_disp_set_label_no_items); break; diff --git a/menu/cbs/menu_cbs_left.c b/menu/cbs/menu_cbs_left.c index 29c6285c39..654742e10d 100644 --- a/menu/cbs/menu_cbs_left.c +++ b/menu/cbs/menu_cbs_left.c @@ -735,7 +735,7 @@ static int disk_options_disk_idx_left(unsigned type, const char *label, static int bind_left_generic(unsigned type, const char *label, bool wraparound) { - return menu_setting_set(type, label, MENU_ACTION_LEFT, wraparound); + return menu_setting_set(type, MENU_ACTION_LEFT, wraparound); } static int menu_cbs_init_bind_left_compare_label(menu_file_list_cbs_t *cbs, diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 059eacc894..1b63ea9a52 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -258,6 +258,8 @@ static enum msg_hash_enums action_ok_dl_to_enum(unsigned lbl) { switch (lbl) { + case ACTION_OK_DL_DROPDOWN_BOX_LIST: + return MENU_ENUM_LABEL_DEFERRED_DROPDOWN_BOX_LIST; case ACTION_OK_DL_MIXER_STREAM_SETTINGS_LIST: return MENU_ENUM_LABEL_DEFERRED_MIXER_STREAM_SETTINGS_LIST; case ACTION_OK_DL_ACCOUNTS_LIST: @@ -409,6 +411,15 @@ int generic_action_ok_displaylist_push(const char *path, info.enum_idx = MENU_ENUM_LABEL_DEFERRED_VIDEO_LIST; dl_type = DISPLAYLIST_GENERIC; break; + case ACTION_OK_DL_DROPDOWN_BOX_LIST: + info.type = type; + info.directory_ptr = idx; + info_path = path; + info_label = msg_hash_to_str( + MENU_ENUM_LABEL_DEFERRED_DROPDOWN_BOX_LIST); + info.enum_idx = MENU_ENUM_LABEL_DEFERRED_DROPDOWN_BOX_LIST; + dl_type = DISPLAYLIST_GENERIC; + break; case ACTION_OK_DL_USER_BINDS_LIST: info.type = type; info.directory_ptr = idx; @@ -1956,7 +1967,7 @@ static int action_ok_mixer_stream_action_stop(const char *path, static int action_ok_lookup_setting(const char *path, const char *label, unsigned type, size_t idx, size_t entry_idx) { - return menu_setting_set(type, label, MENU_ACTION_OK, false); + return menu_setting_set(type, MENU_ACTION_OK, false); } static int action_ok_audio_add_to_mixer(const char *path, @@ -4258,6 +4269,33 @@ int action_ok_push_filebrowser_list_file_select(const char *path, entry_idx, ACTION_OK_DL_FILE_BROWSER_SELECT_DIR); } +static int action_ok_push_dropdown_setting_uint_item(const char *path, + const char *label, unsigned type, size_t idx, size_t entry_idx) +{ + enum msg_hash_enums enum_idx = (enum msg_hash_enums)atoi(label); + rarch_setting_t *setting = menu_setting_find_enum(enum_idx); + + if (!setting) + return -1; + + *setting->value.target.unsigned_integer = idx; + return action_cancel_pop_default(NULL, NULL, 0, 0); +} + +static int action_ok_push_dropdown_item(const char *path, + const char *label, unsigned type, size_t idx, size_t entry_idx) +{ +#if 0 + RARCH_LOG("dropdown: \n"); + RARCH_LOG("path: %s \n", path); + RARCH_LOG("label: %s \n", label); + RARCH_LOG("type: %d \n", type); + RARCH_LOG("idx: %d \n", idx); + RARCH_LOG("entry_idx: %d \n", entry_idx); +#endif + return 0; +} + static int action_ok_push_default(const char *path, const char *label, unsigned type, size_t idx, size_t entry_idx) { @@ -5306,6 +5344,12 @@ static int menu_cbs_init_bind_ok_compare_type(menu_file_list_cbs_t *cbs, { switch (type) { + case MENU_SETTING_DROPDOWN_SETTING_UINT_ITEM: + BIND_ACTION_OK(cbs, action_ok_push_dropdown_setting_uint_item); + break; + case MENU_SETTING_DROPDOWN_ITEM: + BIND_ACTION_OK(cbs, action_ok_push_dropdown_item); + break; case MENU_SETTING_ACTION_CORE_DISK_OPTIONS: BIND_ACTION_OK(cbs, action_ok_push_default); break; diff --git a/menu/cbs/menu_cbs_right.c b/menu/cbs/menu_cbs_right.c index 1a2caabdc6..4bda401e98 100644 --- a/menu/cbs/menu_cbs_right.c +++ b/menu/cbs/menu_cbs_right.c @@ -513,7 +513,7 @@ static int disk_options_disk_idx_right(unsigned type, const char *label, int bind_right_generic(unsigned type, const char *label, bool wraparound) { - return menu_setting_set(type, label, MENU_ACTION_RIGHT, wraparound); + return menu_setting_set(type, MENU_ACTION_RIGHT, wraparound); } static int menu_cbs_init_bind_right_compare_type(menu_file_list_cbs_t *cbs, diff --git a/menu/cbs/menu_cbs_start.c b/menu/cbs/menu_cbs_start.c index 129a017be6..963b3c154f 100644 --- a/menu/cbs/menu_cbs_start.c +++ b/menu/cbs/menu_cbs_start.c @@ -283,7 +283,7 @@ static int action_start_video_resolution(unsigned type, const char *label) static int action_start_lookup_setting(unsigned type, const char *label) { - return menu_setting_set(type, label, MENU_ACTION_START, false); + return menu_setting_set(type, MENU_ACTION_START, false); } static int menu_cbs_init_bind_start_compare_label(menu_file_list_cbs_t *cbs) diff --git a/menu/cbs/menu_cbs_title.c b/menu/cbs/menu_cbs_title.c index d0404ab883..4d5eb60cdc 100644 --- a/menu/cbs/menu_cbs_title.c +++ b/menu/cbs/menu_cbs_title.c @@ -78,6 +78,11 @@ static int action_get_title_action_generic(const char *path, const char *label, return 0; \ } +static int action_get_title_dropdown_item(const char *path, const char *label, unsigned menu_type, char *s, size_t len) +{ + return 0; +} + static int action_get_title_mixer_stream_actions(const char *path, const char *label, unsigned menu_type, char *s, size_t len) { unsigned offset = (menu_type - MENU_SETTINGS_AUDIO_MIXER_STREAM_ACTIONS_BEGIN); @@ -1188,7 +1193,12 @@ int menu_cbs_init_bind_title(menu_file_list_cbs_t *cbs, BIND_ACTION_GET_TITLE(cbs, action_get_title_mixer_stream_actions); return 0; } - + if (string_is_equal(label, + msg_hash_to_str(MENU_ENUM_LABEL_DEFERRED_DROPDOWN_BOX_LIST))) + { + BIND_ACTION_GET_TITLE(cbs, action_get_title_dropdown_item); + return 0; + } if (string_is_equal(label, msg_hash_to_str(MENU_ENUM_LABEL_DEFERRED_RPL_ENTRY_ACTIONS))) { BIND_ACTION_GET_TITLE(cbs, action_get_quick_menu_views_settings_list); diff --git a/menu/menu_cbs.h b/menu/menu_cbs.h index 65b17fc2cc..8c75106c0c 100644 --- a/menu/menu_cbs.h +++ b/menu/menu_cbs.h @@ -43,6 +43,7 @@ typedef struct key_desc enum { ACTION_OK_DL_DEFAULT = 0, + ACTION_OK_DL_DROPDOWN_BOX_LIST, ACTION_OK_DL_OPEN_ARCHIVE, ACTION_OK_DL_OPEN_ARCHIVE_DETECT_CORE, ACTION_OK_DL_MUSIC, @@ -139,10 +140,16 @@ enum /* Function callbacks */ +int action_cancel_pop_default(const char *path, + const char *label, unsigned type, size_t idx); + int action_refresh_default(file_list_t *list, file_list_t *menu_list); int shader_action_parameter_right(unsigned type, const char *label, bool wraparound); +int action_cancel_pop_with_new_pos(const char *path, + const char *label, unsigned type, size_t idx, size_t new_idx); + int generic_action_ok_displaylist_push(const char *path, const char *new_path, const char *label, unsigned type, size_t idx, size_t entry_idx, unsigned action_type); diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 080e1206d9..dd618d38e4 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -7690,6 +7690,76 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data) menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, info->list); use_filebrowser = true; break; + case DISPLAYLIST_DROPDOWN_LIST: + { + enum msg_hash_enums enum_idx = (enum msg_hash_enums)atoi(info->path); + rarch_setting_t *setting = menu_setting_find_enum(enum_idx); + + menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, info->list); + + switch (setting->type) + { + case ST_UINT: + if (setting->enforce_minrange && setting->enforce_maxrange) + { + float i; + float step = setting->step; + double min = setting->min; + double max = setting->max; + + if (setting->get_string_representation) + { + unsigned orig_value = *setting->value.target.unsigned_integer; + for (i = 0.00; i < max; i += step) + { + char val_s[256], val_d[256]; + int val = (int)i; + + /* TODO/FIXME - + * get_string_representation for aspect ratio index + * uses setting->value.target.unsigned_integer, so + * create this hack */ + *setting->value.target.unsigned_integer = val; + + setting->get_string_representation(setting, + val_s, sizeof(val_s)); + snprintf(val_d, sizeof(val_d), "%d", setting->enum_idx); + menu_entries_append_enum(info->list, + val_s, + val_d, + MENU_ENUM_LABEL_NO_ITEMS, + MENU_SETTING_DROPDOWN_SETTING_UINT_ITEM, val, 0); + } + + *setting->value.target.unsigned_integer = orig_value; + } + else + { + for (i = 1.00; i < max; i += step) + { + char val_s[16], val_d[16]; + int val = (int)i; + + snprintf(val_s, sizeof(val_s), "%d", val); + snprintf(val_d, sizeof(val_d), "%d", setting->enum_idx); + + menu_entries_append_enum(info->list, + val_s, + val_d, + MENU_ENUM_LABEL_NO_ITEMS, + MENU_SETTING_DROPDOWN_SETTING_UINT_ITEM, val, 0); + } + } + } + break; + default: + break; + } + + info->need_refresh = true; + info->need_push = true; + } + break; case DISPLAYLIST_NONE: break; } diff --git a/menu/menu_displaylist.h b/menu/menu_displaylist.h index c22323d306..10a0ad40aa 100644 --- a/menu/menu_displaylist.h +++ b/menu/menu_displaylist.h @@ -54,6 +54,7 @@ enum menu_displaylist_parse_type enum menu_displaylist_ctl_state { DISPLAYLIST_NONE = 0, + DISPLAYLIST_DROPDOWN_LIST, DISPLAYLIST_INFO, DISPLAYLIST_HELP, DISPLAYLIST_HELP_SCREEN_LIST, diff --git a/menu/menu_driver.h b/menu/menu_driver.h index b5ee5999c9..fafb73b656 100644 --- a/menu/menu_driver.h +++ b/menu/menu_driver.h @@ -147,6 +147,8 @@ enum menu_settings_type MENU_NETPLAY_TAB, MENU_ADD_TAB, MENU_PLAYLISTS_TAB, + MENU_SETTING_DROPDOWN_ITEM, + MENU_SETTING_DROPDOWN_SETTING_UINT_ITEM, MENU_SETTING_NO_ITEM, MENU_SETTING_DRIVER, MENU_SETTING_ACTION, diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 84aa89ca7a..6cf2bef8a9 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -159,6 +159,22 @@ struct string_options_entry size_t len; }; +static int setting_action_ok_uint(void *data, bool wraparound) +{ + char enum_idx[16]; + rarch_setting_t *setting = (rarch_setting_t*)data; + if (!setting) + return -1; + + snprintf(enum_idx, sizeof(enum_idx), "%d", setting->enum_idx); + + generic_action_ok_displaylist_push( + enum_idx, /* we will pass the enumeration index of the string as a path */ + NULL, NULL, 0, 0, 0, + ACTION_OK_DL_DROPDOWN_BOX_LIST); + return 0; +} + #ifdef HAVE_CHEEVOS static void setting_get_string_representation_cheevos_password(void *data, char *s, size_t len) @@ -1054,8 +1070,7 @@ int menu_setting_set_flags(rarch_setting_t *setting) return 0; } -int menu_setting_set(unsigned type, const char *label, - unsigned action, bool wraparound) +int menu_setting_set(unsigned type, unsigned action, bool wraparound) { int ret = 0; file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0); @@ -4065,6 +4080,7 @@ static bool setting_append_list( true, true); settings_data_list_current_add_flags(list, list_info, SD_FLAG_CMD_APPLY_AUTO); + (*list)[list_info->index - 1].action_ok = &setting_action_ok_uint; (*list)[list_info->index - 1].get_string_representation = &setting_get_string_representation_uint_aspect_ratio_index; diff --git a/menu/menu_setting.h b/menu/menu_setting.h index 3b4b76d0d8..b3febd1600 100644 --- a/menu/menu_setting.h +++ b/menu/menu_setting.h @@ -76,8 +76,7 @@ int menu_setting_generic(rarch_setting_t *setting, bool wraparound); int menu_setting_set_flags(rarch_setting_t *setting); -int menu_setting_set(unsigned type, const char *label, - unsigned action, bool wraparound); +int menu_setting_set(unsigned type, unsigned action, bool wraparound); /** * menu_setting_find: diff --git a/msg_hash.h b/msg_hash.h index 39b6abfff4..954b91a4e9 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -982,6 +982,7 @@ enum msg_hash_enums MENU_LABEL(BROWSE_URL), MENU_LABEL(BROWSE_START), /* Deferred */ + MENU_ENUM_LABEL_DEFERRED_DROPDOWN_BOX_LIST, MENU_ENUM_LABEL_DEFERRED_MIXER_STREAM_SETTINGS_LIST, MENU_ENUM_LABEL_DEFERRED_CONFIGURATIONS_LIST, MENU_ENUM_LABEL_DEFERRED_FAVORITES_LIST,