From 7e6aa11c5becf2bf14d4e026816ea1c21b41b9e5 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 6 Sep 2014 01:34:05 +0200 Subject: [PATCH] (Menu) Fix Shader Preset Save As option --- frontend/menu/backend/menu_common_backend.c | 21 +++++++++++++++---- .../menu/backend/menu_common_shader_backend.c | 11 ++++++---- frontend/menu/disp/rgui.c | 2 +- frontend/menu/disp/rmenu.c | 2 +- frontend/menu/disp/rmenu_xui.cpp | 2 +- frontend/menu/menu_common.h | 1 + frontend/menu/menu_entries.c | 2 +- frontend/menu/menu_input_line_cb.c | 17 ++++----------- frontend/menu/menu_input_line_cb.h | 2 -- 9 files changed, 33 insertions(+), 27 deletions(-) diff --git a/frontend/menu/backend/menu_common_backend.c b/frontend/menu/backend/menu_common_backend.c index f4f9c926bb..311d789a0a 100644 --- a/frontend/menu/backend/menu_common_backend.c +++ b/frontend/menu/backend/menu_common_backend.c @@ -612,6 +612,19 @@ static void menu_common_setting_set_current_string_path( setting->change_handler(setting); } +void menu_common_set_current_string_based_on_label( + const char *label, const char *str) +{ + if (!strcmp(label, "video_shader_preset_save_as")) + { +#ifdef HAVE_SHADER_MANAGER + if (driver.menu_ctx && driver.menu_ctx->backend + && driver.menu_ctx->backend->shader_manager_save_preset) + driver.menu_ctx->backend->shader_manager_save_preset(str, false); +#endif + } +} + void menu_common_setting_set_current_string( rarch_setting_t *setting, const char *str) { @@ -659,7 +672,7 @@ static void handle_setting(rarch_setting_t *setting, setting->default_value.string, setting->name, id, action); else if (setting->type == ST_STRING) { - if (id == MENU_FILE_LINEFEED) + if (id == MENU_FILE_LINEFEED || id == MENU_FILE_LINEFEED_SWITCH) { if (action == MENU_ACTION_OK) menu_key_start_line(driver.menu, setting->short_description, @@ -1028,9 +1041,9 @@ static int menu_setting_ok_toggle(unsigned type, #ifdef HAVE_SHADER_MANAGER else if (!strcmp(label, "video_shader_preset_save_as")) { - menu_key_start_line(driver.menu, "Preset Filename: ", - "shader_preset_save", preset_filename_callback); - return 0; + if (action == MENU_ACTION_OK) + menu_key_start_line(driver.menu, "Preset Filename", + label, st_string_callback); } else if (!strcmp(label, "shader_apply_changes")) { diff --git a/frontend/menu/backend/menu_common_shader_backend.c b/frontend/menu/backend/menu_common_shader_backend.c index fe147977a5..f8b2c6219c 100644 --- a/frontend/menu/backend/menu_common_shader_backend.c +++ b/frontend/menu/backend/menu_common_shader_backend.c @@ -193,7 +193,6 @@ static void menu_common_shader_manager_save_preset( char buffer[PATH_MAX], config_directory[PATH_MAX], cgp_path[PATH_MAX]; unsigned d, type = RARCH_SHADER_NONE; config_file_t *conf = NULL; - const char *conf_path = NULL; bool ret = false; if (!driver.menu) @@ -210,8 +209,6 @@ static void menu_common_shader_manager_save_preset( if (type == RARCH_SHADER_NONE) return; - conf_path = (type == RARCH_SHADER_GLSL) ? - driver.menu->default_glslp : driver.menu->default_cgp; *config_directory = '\0'; if (basename) @@ -227,6 +224,12 @@ static void menu_common_shader_manager_save_preset( strlcat(buffer, ".cgp", sizeof(buffer)); } } + else + { + const char *conf_path = (type == RARCH_SHADER_GLSL) ? + driver.menu->default_glslp : driver.menu->default_cgp; + strlcpy(buffer, conf_path, sizeof(buffer)); + } if (*g_extern.config_path) fill_pathname_basedir(config_directory, @@ -247,7 +250,7 @@ static void menu_common_shader_manager_save_preset( if (!*dirs[d]) continue; - fill_pathname_join(cgp_path, dirs[d], conf_path, sizeof(cgp_path)); + fill_pathname_join(cgp_path, dirs[d], buffer, sizeof(cgp_path)); if (config_file_write(conf, cgp_path)) { RARCH_LOG("Saved shader preset to %s.\n", cgp_path); diff --git a/frontend/menu/disp/rgui.c b/frontend/menu/disp/rgui.c index 4cefc7bba9..e4b6d816fe 100644 --- a/frontend/menu/disp/rgui.c +++ b/frontend/menu/disp/rgui.c @@ -386,7 +386,7 @@ static void rgui_render(void) core_option_get_val(g_extern.system.core_options, type - MENU_SETTINGS_CORE_OPTION_START), sizeof(type_str)); - else if (type == MENU_FILE_SWITCH) + else if (type == MENU_FILE_SWITCH || type == MENU_FILE_LINEFEED_SWITCH) strlcpy(type_str, "...", sizeof(type_str)); else if (driver.menu_ctx && driver.menu_ctx->backend && driver.menu_ctx->backend->setting_set_label) diff --git a/frontend/menu/disp/rmenu.c b/frontend/menu/disp/rmenu.c index d120c1158c..f39e51c0b9 100644 --- a/frontend/menu/disp/rmenu.c +++ b/frontend/menu/disp/rmenu.c @@ -254,7 +254,7 @@ static void rmenu_render(void) core_option_get_val(g_extern.system.core_options, type - MENU_SETTINGS_CORE_OPTION_START), sizeof(type_str)); - else if (type == MENU_FILE_SWITCH) + else if (type == MENU_FILE_SWITCH || type == MENU_FILE_LINEFEED_SWITCH) strlcpy(type_str, "...", sizeof(type_str)); else if (driver.menu_ctx && driver.menu_ctx->backend && driver.menu_ctx->backend->setting_set_label) diff --git a/frontend/menu/disp/rmenu_xui.cpp b/frontend/menu/disp/rmenu_xui.cpp index af07ba9e6c..7d61577295 100644 --- a/frontend/menu/disp/rmenu_xui.cpp +++ b/frontend/menu/disp/rmenu_xui.cpp @@ -466,7 +466,7 @@ static void rmenu_xui_render(void) core_option_get_val(g_extern.system.core_options, type - MENU_SETTINGS_CORE_OPTION_START), sizeof(type_str)); - else if (type == MENU_FILE_SWITCH) + else if (type == MENU_FILE_SWITCH || type == MENU_FILE_LINEFEED_SWITCH) strlcpy(type_str, "...", sizeof(type_str)); else if (driver.menu_ctx && driver.menu_ctx->backend && driver.menu_ctx->backend->setting_set_label) diff --git a/frontend/menu/menu_common.h b/frontend/menu/menu_common.h index bd994b69e0..a440eb702e 100644 --- a/frontend/menu/menu_common.h +++ b/frontend/menu/menu_common.h @@ -61,6 +61,7 @@ typedef enum MENU_FILE_DIRECTORY, MENU_FILE_DEVICE, MENU_FILE_LINEFEED, + MENU_FILE_LINEFEED_SWITCH, MENU_FILE_CORE, MENU_FILE_PLAYLIST_ENTRY, MENU_FILE_USE_DIRECTORY, diff --git a/frontend/menu/menu_entries.c b/frontend/menu/menu_entries.c index b40f50f56a..a8934304f6 100644 --- a/frontend/menu/menu_entries.c +++ b/frontend/menu/menu_entries.c @@ -495,7 +495,7 @@ int menu_entries_push_list(menu_handle_t *menu, file_list_push(list, "Load Shader Preset", "video_shader_preset", MENU_FILE_SWITCH, 0); file_list_push(list, "Shader Preset Save As", - "video_shader_preset_save_as", MENU_FILE_SWITCH, 0); + "video_shader_preset_save_as", MENU_FILE_LINEFEED_SWITCH, 0); file_list_push(list, "Parameters (Current)", "video_shader_parameters", MENU_FILE_SWITCH, 0); file_list_push(list, "Parameters (Menu)", diff --git a/frontend/menu/menu_input_line_cb.c b/frontend/menu/menu_input_line_cb.c index afee06cb72..77ceb43a20 100644 --- a/frontend/menu/menu_input_line_cb.c +++ b/frontend/menu/menu_input_line_cb.c @@ -32,6 +32,8 @@ /* forward decls */ void menu_common_setting_set_current_string(rarch_setting_t *setting, const char *str); +void menu_common_set_current_string_based_on_label( + const char *label, const char *str); void menu_key_start_line(void *data, const char *label, const char *label_setting, input_keyboard_line_complete_t cb) @@ -99,23 +101,12 @@ void st_string_callback(void *userdata, const char *str) setting_data_find_setting( setting_data, menu->keyboard.label_setting))) menu_common_setting_set_current_string(current_setting, str); + else + menu_common_set_current_string_based_on_label(menu->keyboard.label_setting, str); } menu_key_end_line(menu); } -#ifdef HAVE_SHADER_MANAGER -void preset_filename_callback(void *userdata, const char *str) -{ - menu_handle_t *menu = (menu_handle_t*)userdata; - - if (driver.menu_ctx && driver.menu_ctx->backend - && driver.menu_ctx->backend->shader_manager_save_preset) - driver.menu_ctx->backend->shader_manager_save_preset( - str && *str ? str : NULL, false); - menu_key_end_line(menu); -} -#endif - void menu_key_event(bool down, unsigned keycode, uint32_t character, uint16_t mod) { if (!driver.menu) diff --git a/frontend/menu/menu_input_line_cb.h b/frontend/menu/menu_input_line_cb.h index 77b8ffc6b5..3145e1657e 100644 --- a/frontend/menu/menu_input_line_cb.h +++ b/frontend/menu/menu_input_line_cb.h @@ -29,8 +29,6 @@ void st_uint_callback(void *userdata, const char *str); void st_string_callback(void *userdata, const char *str); -void preset_filename_callback(void *userdata, const char *str); - void menu_poll_bind_get_rested_axes(struct menu_bind_state *state); void menu_poll_bind_state(struct menu_bind_state *state);