From e71486a9bfa0d03a62d4fdfcd72f232e70ad1690 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 12 Oct 2014 19:13:42 +0200 Subject: [PATCH] Start implementing toggle actions in menu_entries_cbs.c --- frontend/menu/backend/menu_backend.h | 1 + frontend/menu/backend/menu_common_backend.c | 25 +++++++++++---------- frontend/menu/menu_entries_cbs.c | 24 ++++++++++++++++---- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/frontend/menu/backend/menu_backend.h b/frontend/menu/backend/menu_backend.h index 90ea2a6b32..d5cb6cc38a 100644 --- a/frontend/menu/backend/menu_backend.h +++ b/frontend/menu/backend/menu_backend.h @@ -9,6 +9,7 @@ typedef struct menu_file_list_cbs { int (*action_ok)(const char *path, const char *label, unsigned type, size_t index); + int (*action_toggle)(unsigned type, const char *label, unsigned action); } menu_file_list_cbs_t; typedef struct menu_ctx_driver_backend diff --git a/frontend/menu/backend/menu_common_backend.c b/frontend/menu/backend/menu_common_backend.c index 23c76fc9b1..d02db75dc8 100644 --- a/frontend/menu/backend/menu_common_backend.c +++ b/frontend/menu/backend/menu_common_backend.c @@ -55,7 +55,7 @@ static int menu_message_toggle(unsigned action) return 0; } -static int menu_setting_ok_toggle(unsigned type, +static int menu_setting_ok_pressed(unsigned type, const char *path, const char *label, unsigned action) { @@ -214,7 +214,7 @@ static int menu_start_screen_iterate(unsigned action) return 0; } -static int menu_setting_start_toggle(unsigned type, +static int menu_setting_start_pressed(unsigned type, const char *dir, const char *label, unsigned action) { @@ -242,18 +242,19 @@ static int menu_setting_start_toggle(unsigned type, return -1; } -static int menu_setting_toggle(unsigned type, +static int menu_setting_toggle_pressed(unsigned type, const char *dir, const char *label, unsigned action) { struct retro_perf_counter **counters = NULL; + menu_file_list_cbs_t *cbs = (menu_file_list_cbs_t*) + file_list_get_actiondata_at_offset(driver.menu->selection_buf, + driver.menu->selection_ptr); - if ((menu_common_type_is(label, type) == MENU_SETTINGS_SHADER_OPTIONS) || - !strcmp(label, "video_shader_parameters") || - !strcmp(label, "video_shader_preset_parameters") - ) - return menu_shader_manager_setting_toggle(type, label, action); - else if ((type >= MENU_SETTINGS_CORE_OPTION_START)) + if (cbs && cbs->action_toggle) + return cbs->action_toggle(type, label, action); + + if ((type >= MENU_SETTINGS_CORE_OPTION_START)) return menu_common_core_setting_toggle(type, action); else if (type >= MENU_SETTINGS_PERF_COUNTERS_BEGIN && type <= MENU_SETTINGS_PERF_COUNTERS_END) @@ -316,17 +317,17 @@ static int menu_settings_iterate(unsigned action) 0, driver.menu->selection_ptr); break; case MENU_ACTION_OK: - if (menu_setting_ok_toggle(type, path, label, action) == 0) + if (menu_setting_ok_pressed(type, path, label, action) == 0) return 0; /* fall-through */ case MENU_ACTION_START: - if (menu_setting_start_toggle(type, path, label, action) == 0) + if (menu_setting_start_pressed(type, path, label, action) == 0) return 0; /* fall-through */ case MENU_ACTION_LEFT: case MENU_ACTION_RIGHT: { - int ret = menu_setting_toggle(type, path, label, action); + int ret = menu_setting_toggle_pressed(type, path, label, action); if (ret) return ret; diff --git a/frontend/menu/menu_entries_cbs.c b/frontend/menu/menu_entries_cbs.c index 01d6d5de47..b531fbebbe 100644 --- a/frontend/menu/menu_entries_cbs.c +++ b/frontend/menu/menu_entries_cbs.c @@ -589,7 +589,7 @@ static int action_ok_help(const char *path, /* Bind the OK callback function */ -static int menu_entries_cbs_init_bind_ok(menu_file_list_cbs_t *cbs, +static int menu_entries_cbs_init_bind_ok_first(menu_file_list_cbs_t *cbs, const char *path, const char *label, unsigned type, size_t index) { const char *menu_label = NULL; @@ -674,7 +674,7 @@ static int menu_entries_cbs_init_bind_ok(menu_file_list_cbs_t *cbs, return 0; } -static void menu_entries_cbs_init_bind_ok_toggle(menu_file_list_cbs_t *cbs, +static void menu_entries_cbs_init_bind_ok(menu_file_list_cbs_t *cbs, const char *path, const char *label, unsigned type, size_t index) { if (!cbs) @@ -682,7 +682,7 @@ static void menu_entries_cbs_init_bind_ok_toggle(menu_file_list_cbs_t *cbs, cbs->action_ok = NULL; - if (menu_entries_cbs_init_bind_ok(cbs, path, label, type, index) == 0) + if (menu_entries_cbs_init_bind_ok_first(cbs, path, label, type, index) == 0) return; else if (!strcmp(label, "help")) cbs->action_ok = action_ok_help; @@ -721,6 +721,21 @@ static void menu_entries_cbs_init_bind_ok_toggle(menu_file_list_cbs_t *cbs, cbs->action_ok = action_ok_configurations_list; } +static void menu_entries_cbs_init_bind_toggle(menu_file_list_cbs_t *cbs, + const char *path, const char *label, unsigned type, size_t index) +{ + if (!cbs) + return; + + cbs->action_toggle = NULL; + + if ((menu_common_type_is(label, type) == MENU_SETTINGS_SHADER_OPTIONS) || + !strcmp(label, "video_shader_parameters") || + !strcmp(label, "video_shader_preset_parameters") + ) + cbs->action_toggle = menu_shader_manager_setting_toggle; +} + void menu_entries_cbs_init(void *data, const char *path, const char *label, unsigned type, size_t index) @@ -735,6 +750,7 @@ void menu_entries_cbs_init(void *data, if (cbs) { - menu_entries_cbs_init_bind_ok_toggle(cbs, path, label, type, index); + menu_entries_cbs_init_bind_ok(cbs, path, label, type, index); + menu_entries_cbs_init_bind_toggle(cbs, path, label, type, index); } }