From e75633064a1a17249baa40cb5ee954f11b144001 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 5 Jan 2017 04:52:04 +0100 Subject: [PATCH] Add 'Y button' callback function for input binds --- gfx/video_driver.c | 4 ++- input/input_config.c | 76 ++++++++++++++++++++++++++++++++++++++++ input/input_config.h | 2 ++ menu/cbs/menu_cbs_scan.c | 46 ++++++++++++++++++++++++ menu/menu_cbs.c | 2 +- tasks/task_image.c | 28 ++++++++++----- 6 files changed, 148 insertions(+), 10 deletions(-) diff --git a/gfx/video_driver.c b/gfx/video_driver.c index d1a0bf9a14..850da219cf 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -119,7 +119,9 @@ static video_pixel_scaler_t *video_driver_scaler_ptr = NULL; * TODO: Refactor this better. */ static struct retro_hw_render_callback hw_render; -static const struct retro_hw_render_context_negotiation_interface *hw_render_context_negotiation = NULL; +static const struct +retro_hw_render_context_negotiation_interface * +hw_render_context_negotiation = NULL; static bool video_driver_use_rgba = false; static bool video_driver_data_own = false; diff --git a/input/input_config.c b/input/input_config.c index 6aed461caf..c438700fd7 100644 --- a/input/input_config.c +++ b/input/input_config.c @@ -488,3 +488,79 @@ const struct retro_keybind *input_config_get_bind_auto(unsigned port, unsigned i return &settings->input.autoconf_binds[joy_idx][id]; return NULL; } + +unsigned input_config_label_to_key(const char *label) +{ + unsigned key = 0; + + if (string_is_equal(label, "toggle_fast_forward")) + key = RARCH_FAST_FORWARD_KEY; + else if (string_is_equal(label, "hold_fast_forward")) + key = RARCH_FAST_FORWARD_HOLD_KEY; + else if (string_is_equal(label, "load_state")) + key = RARCH_LOAD_STATE_KEY; + else if (string_is_equal(label, "save_state")) + key = RARCH_SAVE_STATE_KEY; + else if (string_is_equal(label, "toggle_fullscreen")) + key = RARCH_FULLSCREEN_TOGGLE_KEY; + else if (string_is_equal(label, "exit_emulator")) + key = RARCH_QUIT_KEY; + else if (string_is_equal(label, "state_slot_increase")) + key = RARCH_STATE_SLOT_PLUS; + else if (string_is_equal(label, "state_slot_decrease")) + key = RARCH_STATE_SLOT_MINUS; + else if (string_is_equal(label, "rewind")) + key = RARCH_REWIND; + else if (string_is_equal(label, "movie_record_toggle")) + key = RARCH_MOVIE_RECORD_TOGGLE; + else if (string_is_equal(label, "pause_toggle")) + key = RARCH_PAUSE_TOGGLE; + else if (string_is_equal(label, "frame_advance")) + key = RARCH_FRAMEADVANCE; + else if (string_is_equal(label, "reset")) + key = RARCH_RESET; + else if (string_is_equal(label, "shader_next")) + key = RARCH_SHADER_NEXT; + else if (string_is_equal(label, "shader_prev")) + key = RARCH_SHADER_PREV; + else if (string_is_equal(label, "cheat_index_plus")) + key = RARCH_CHEAT_INDEX_PLUS; + else if (string_is_equal(label, "cheat_index_minus")) + key = RARCH_CHEAT_INDEX_MINUS; + else if (string_is_equal(label, "cheat_toggle")) + key = RARCH_CHEAT_TOGGLE; + else if (string_is_equal(label, "screenshot")) + key = RARCH_SCREENSHOT; + else if (string_is_equal(label, "audio_mute")) + key = RARCH_MUTE; + else if (string_is_equal(label, "osk_toggle")) + key = RARCH_OSK; + else if (string_is_equal(label, "netplay_flip_players_1_2")) + key = RARCH_NETPLAY_FLIP; + else if (string_is_equal(label, "netplay_game_watch")) + key = RARCH_NETPLAY_GAME_WATCH; + else if (string_is_equal(label, "slowmotion")) + key = RARCH_SLOWMOTION; + else if (string_is_equal(label, "enable_hotkey")) + key = RARCH_ENABLE_HOTKEY; + else if (string_is_equal(label, "volume_up")) + key = RARCH_VOLUME_UP; + else if (string_is_equal(label, "volume_down")) + key = RARCH_VOLUME_DOWN; + else if (string_is_equal(label, "overlay_next")) + key = RARCH_OVERLAY_NEXT; + else if (string_is_equal(label, "disk_eject_toggle")) + key = RARCH_DISK_EJECT_TOGGLE; + else if (string_is_equal(label, "disk_next")) + key = RARCH_DISK_NEXT; + else if (string_is_equal(label, "disk_prev")) + key = RARCH_DISK_PREV; + else if (string_is_equal(label, "grab_mouse_toggle")) + key = RARCH_GRAB_MOUSE_TOGGLE; + else if (string_is_equal(label, "game_focus_toggle")) + key = RARCH_GAME_FOCUS_TOGGLE; + else if (string_is_equal(label, "menu_toggle")) + key = RARCH_MENU_TOGGLE; + + return key; +} diff --git a/input/input_config.h b/input/input_config.h index cdacb915a5..4314ec37eb 100644 --- a/input/input_config.h +++ b/input/input_config.h @@ -67,6 +67,8 @@ void input_config_parse_joy_button(void *data, const char *prefix, void input_config_parse_joy_axis(void *data, const char *prefix, const char *axis, struct retro_keybind *bind); +unsigned input_config_label_to_key(const char *label); + const struct retro_keybind *input_config_get_bind_auto(unsigned port, unsigned id); #endif diff --git a/menu/cbs/menu_cbs_scan.c b/menu/cbs/menu_cbs_scan.c index dc49656dac..18cc043887 100644 --- a/menu/cbs/menu_cbs_scan.c +++ b/menu/cbs/menu_cbs_scan.c @@ -15,6 +15,7 @@ #include #include +#include #ifdef HAVE_CONFIG_H #include "../../config.h" @@ -24,6 +25,8 @@ #include "../menu_cbs.h" #include "../menu_setting.h" +#include "../input/input_config.h" + #include "../../configuration.h" #include "../../tasks/tasks_internal.h" @@ -114,9 +117,43 @@ int action_switch_thumbnail(const char *path, return 0; } +static int action_scan_input_desc(const char *path, + const char *label, unsigned type, size_t idx) +{ + const char *menu_label = NULL; + settings_t *settings = config_get_ptr(); + unsigned key = 0; + unsigned inp_desc_user = 0; + struct retro_keybind *target = NULL; + + menu_entries_get_last_stack(NULL, &menu_label, NULL, NULL, NULL); + + if (string_is_equal(menu_label, "deferred_user_binds_list")) + { + unsigned char player_no_str = atoi(&label[1]); + + inp_desc_user = (unsigned)player_no_str - 1; + key = idx - 6; + } + else + key = input_config_label_to_key(label); + + target = (struct retro_keybind*)&settings->input.binds[inp_desc_user][key]; + + if (target) + { + target->key = RETROK_UNKNOWN; + target->joykey = NO_BTN; + target->joyaxis = AXIS_NONE; + } + + return 0; +} + static int menu_cbs_init_bind_scan_compare_type(menu_file_list_cbs_t *cbs, unsigned type) { + switch (type) { #ifdef HAVE_LIBRETRODB @@ -148,6 +185,15 @@ int menu_cbs_init_bind_scan(menu_file_list_cbs_t *cbs, BIND_ACTION_SCAN(cbs, NULL); + if (cbs->setting) + { + if (setting_get_type(cbs->setting) == ST_BIND) + { + BIND_ACTION_SCAN(cbs, action_scan_input_desc); + return 0; + } + } + menu_cbs_init_bind_scan_compare_type(cbs, type); return -1; diff --git a/menu/menu_cbs.c b/menu/menu_cbs.c index 1546145a43..17a2203f11 100644 --- a/menu/menu_cbs.c +++ b/menu/menu_cbs.c @@ -20,7 +20,7 @@ #include "menu_cbs.h" #include "../verbosity.h" -#if 0 +#if 1 #define DEBUG_LOG #endif diff --git a/tasks/task_image.c b/tasks/task_image.c index 710340465d..55c5cb1654 100644 --- a/tasks/task_image.c +++ b/tasks/task_image.c @@ -52,7 +52,7 @@ struct nbio_image_handle size_t size; unsigned processing_pos_increment; unsigned pos_increment; - int processing_final_state; + enum image_process_code processing_final_state; enum image_status_enum status; }; @@ -65,9 +65,14 @@ static int cb_image_menu_upload_generic(void *data, size_t len) if (!image) return -1; - if (image->processing_final_state == IMAGE_PROCESS_ERROR || - image->processing_final_state == IMAGE_PROCESS_ERROR_END) - return -1; + switch (image->processing_final_state) + { + case IMAGE_PROCESS_ERROR: + case IMAGE_PROCESS_ERROR_END: + return -1; + default: + break; + } image_texture_set_color_shifts(&r_shift, &g_shift, &b_shift, &a_shift, &image->ti); @@ -119,7 +124,7 @@ static int task_image_process( static int cb_image_menu_generic(nbio_handle_t *nbio) { - int retval; + enum image_process_code retval; unsigned width = 0, height = 0; struct nbio_image_handle *image = (struct nbio_image_handle*)nbio->data; @@ -127,8 +132,15 @@ static int cb_image_menu_generic(nbio_handle_t *nbio) return -1; retval = task_image_process(nbio, &width, &height); - if ((retval == IMAGE_PROCESS_ERROR) || (retval == IMAGE_PROCESS_ERROR_END)) - return -1; + + switch (retval) + { + case IMAGE_PROCESS_ERROR: + case IMAGE_PROCESS_ERROR_END: + return -1; + default: + break; + } image->is_blocking_on_processing = (retval != IMAGE_PROCESS_END); image->is_finished = (retval == IMAGE_PROCESS_END); @@ -151,7 +163,7 @@ static int cb_image_menu_thumbnail(void *data, size_t len) static int task_image_iterate_process_transfer(nbio_handle_t *nbio) { - int retval = 0; + enum image_process_code retval; unsigned i, width = 0, height = 0; struct nbio_image_handle *image = (struct nbio_image_handle*)nbio->data;