From 3981a621e9fb53700a3a0220d44aa924b57e8412 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 18 May 2015 03:37:07 +0200 Subject: [PATCH] Simplify menu_input_bind_iterate --- menu/menu_entries_cbs_iterate.c | 30 +++-------- menu/menu_input.c | 93 +++++++++++++++++---------------- menu/menu_input.h | 2 - 3 files changed, 55 insertions(+), 70 deletions(-) diff --git a/menu/menu_entries_cbs_iterate.c b/menu/menu_entries_cbs_iterate.c index 8504417a5d..cb2c477dc0 100644 --- a/menu/menu_entries_cbs_iterate.c +++ b/menu/menu_entries_cbs_iterate.c @@ -455,26 +455,6 @@ static int action_iterate_menu_viewport(const char *label, unsigned action) return 0; } -static int action_iterate_custom_bind(const char *label, unsigned action) -{ - menu_list_t *menu_list = menu_list_get_ptr(); - if (!menu_list) - return -1; - if (menu_input_bind_iterate()) - menu_list_pop_stack(menu_list); - return 0; -} - -static int action_iterate_custom_bind_keyboard(const char *label, unsigned action) -{ - menu_list_t *menu_list = menu_list_get_ptr(); - if (!menu_list) - return -1; - if (menu_input_bind_iterate_keyboard()) - menu_list_pop_stack(menu_list); - return 0; -} - static int action_iterate_message(const char *label, unsigned action) { menu_handle_t *menu = menu_driver_get_ptr(); @@ -526,10 +506,12 @@ static int action_iterate_main(const char *label, unsigned action) !strcmp(label, "custom_bind_defaults") ) { - if (global->menu.bind_mode_keyboard) - return action_iterate_custom_bind_keyboard(label, action); - else - return action_iterate_custom_bind(label, action); + menu_list_t *menu_list = menu_list_get_ptr(); + if (!menu_list) + return -1; + if (menu_input_bind_iterate()) + menu_list_pop_stack(menu_list); + return 0; } ret = action_iterate_switch(action); diff --git a/menu/menu_input.c b/menu/menu_input.c index 3a2fee5cbd..336f24a4bc 100644 --- a/menu/menu_input.c +++ b/menu/menu_input.c @@ -454,50 +454,7 @@ int menu_input_set_input_device_bind_mode(void *data, return 0; } -int menu_input_bind_iterate(void) -{ - char msg[PATH_MAX_LENGTH]; - struct menu_bind_state binds; - menu_handle_t *menu = menu_driver_get_ptr(); - driver_t *driver = driver_get_ptr(); - - if (!menu) - return 1; - - binds = menu->binds; - - menu_driver_render(); - - snprintf(msg, sizeof(msg), "[%s]\npress joypad\n(RETURN to skip)", - input_config_bind_map[ - menu->binds.begin - MENU_SETTINGS_BIND_BEGIN].desc); - - menu_driver_render_messagebox(msg); - - driver->block_input = true; - menu_input_poll_bind_state(&binds); - - if ((binds.skip && !menu->binds.skip) || - menu_input_poll_find_trigger(&menu->binds, &binds)) - { - driver->block_input = false; - - /* Avoid new binds triggering things right away. */ - driver->flushing_input = true; - - binds.begin++; - - if (binds.begin > binds.last) - return 1; - - binds.target++; - } - menu->binds = binds; - - return 0; -} - -int menu_input_bind_iterate_keyboard(void) +static int menu_input_bind_iterate_keyboard(void) { char msg[PATH_MAX_LENGTH]; int64_t current; @@ -548,6 +505,54 @@ int menu_input_bind_iterate_keyboard(void) return 0; } +int menu_input_bind_iterate(void) +{ + char msg[PATH_MAX_LENGTH]; + struct menu_bind_state binds; + menu_handle_t *menu = menu_driver_get_ptr(); + driver_t *driver = driver_get_ptr(); + global_t *global = global_get_ptr(); + + if (!menu) + return 1; + + if (global && global->menu.bind_mode_keyboard) + return menu_input_bind_iterate_keyboard(); + + binds = menu->binds; + + menu_driver_render(); + + snprintf(msg, sizeof(msg), "[%s]\npress joypad\n(RETURN to skip)", + input_config_bind_map[ + menu->binds.begin - MENU_SETTINGS_BIND_BEGIN].desc); + + menu_driver_render_messagebox(msg); + + driver->block_input = true; + menu_input_poll_bind_state(&binds); + + if ((binds.skip && !menu->binds.skip) || + menu_input_poll_find_trigger(&menu->binds, &binds)) + { + driver->block_input = false; + + /* Avoid new binds triggering things right away. */ + driver->flushing_input = true; + + binds.begin++; + + if (binds.begin > binds.last) + return 1; + + binds.target++; + } + menu->binds = binds; + + return 0; +} + + static int menu_input_mouse(unsigned *action) { const struct retro_keybind *binds[MAX_USERS]; diff --git a/menu/menu_input.h b/menu/menu_input.h index fa25a71f5c..18d530a9b5 100644 --- a/menu/menu_input.h +++ b/menu/menu_input.h @@ -82,8 +82,6 @@ bool menu_input_poll_find_trigger(struct menu_bind_state *state, int menu_input_bind_iterate(void); -int menu_input_bind_iterate_keyboard(void); - unsigned menu_input_frame(retro_input_t input, retro_input_t trigger_state); void menu_input_post_iterate(int *ret, unsigned action);