Start implementing toggle actions in menu_entries_cbs.c

This commit is contained in:
twinaphex 2014-10-12 19:13:42 +02:00
parent 1196e3b4eb
commit e71486a9bf
3 changed files with 34 additions and 16 deletions

View File

@ -9,6 +9,7 @@ typedef struct menu_file_list_cbs
{ {
int (*action_ok)(const char *path, const char *label, unsigned type, int (*action_ok)(const char *path, const char *label, unsigned type,
size_t index); size_t index);
int (*action_toggle)(unsigned type, const char *label, unsigned action);
} menu_file_list_cbs_t; } menu_file_list_cbs_t;
typedef struct menu_ctx_driver_backend typedef struct menu_ctx_driver_backend

View File

@ -55,7 +55,7 @@ static int menu_message_toggle(unsigned action)
return 0; return 0;
} }
static int menu_setting_ok_toggle(unsigned type, static int menu_setting_ok_pressed(unsigned type,
const char *path, const char *label, const char *path, const char *label,
unsigned action) unsigned action)
{ {
@ -214,7 +214,7 @@ static int menu_start_screen_iterate(unsigned action)
return 0; return 0;
} }
static int menu_setting_start_toggle(unsigned type, static int menu_setting_start_pressed(unsigned type,
const char *dir, const char *label, const char *dir, const char *label,
unsigned action) unsigned action)
{ {
@ -242,18 +242,19 @@ static int menu_setting_start_toggle(unsigned type,
return -1; return -1;
} }
static int menu_setting_toggle(unsigned type, static int menu_setting_toggle_pressed(unsigned type,
const char *dir, const char *label, const char *dir, const char *label,
unsigned action) unsigned action)
{ {
struct retro_perf_counter **counters = NULL; 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) || if (cbs && cbs->action_toggle)
!strcmp(label, "video_shader_parameters") || return cbs->action_toggle(type, label, action);
!strcmp(label, "video_shader_preset_parameters")
) if ((type >= MENU_SETTINGS_CORE_OPTION_START))
return menu_shader_manager_setting_toggle(type, label, action);
else if ((type >= MENU_SETTINGS_CORE_OPTION_START))
return menu_common_core_setting_toggle(type, action); return menu_common_core_setting_toggle(type, action);
else if (type >= MENU_SETTINGS_PERF_COUNTERS_BEGIN && else if (type >= MENU_SETTINGS_PERF_COUNTERS_BEGIN &&
type <= MENU_SETTINGS_PERF_COUNTERS_END) type <= MENU_SETTINGS_PERF_COUNTERS_END)
@ -316,17 +317,17 @@ static int menu_settings_iterate(unsigned action)
0, driver.menu->selection_ptr); 0, driver.menu->selection_ptr);
break; break;
case MENU_ACTION_OK: 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; return 0;
/* fall-through */ /* fall-through */
case MENU_ACTION_START: 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; return 0;
/* fall-through */ /* fall-through */
case MENU_ACTION_LEFT: case MENU_ACTION_LEFT:
case MENU_ACTION_RIGHT: 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) if (ret)
return ret; return ret;

View File

@ -589,7 +589,7 @@ static int action_ok_help(const char *path,
/* Bind the OK callback function */ /* 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 *path, const char *label, unsigned type, size_t index)
{ {
const char *menu_label = NULL; 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; 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) const char *path, const char *label, unsigned type, size_t index)
{ {
if (!cbs) 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; 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; return;
else if (!strcmp(label, "help")) else if (!strcmp(label, "help"))
cbs->action_ok = action_ok_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; 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, void menu_entries_cbs_init(void *data,
const char *path, const char *label, const char *path, const char *label,
unsigned type, size_t index) unsigned type, size_t index)
@ -735,6 +750,7 @@ void menu_entries_cbs_init(void *data,
if (cbs) 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);
} }
} }