From b5138b61229f597b646e72a3cac8998ead9e5a5a Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 12 Sep 2021 17:41:00 +0200 Subject: [PATCH] Move input_config_get_bind_string to input_driver.c --- input/input_driver.c | 108 +++++++++++++++++++++++++++++++++++ input/input_remapping.h | 3 +- menu/menu_displaylist.c | 4 +- menu/menu_driver.c | 2 +- menu/menu_setting.c | 3 +- retroarch.c | 107 ---------------------------------- ui/drivers/qt/qt_options.cpp | 2 +- 7 files changed, 116 insertions(+), 113 deletions(-) diff --git a/input/input_driver.c b/input/input_driver.c index 21e2a14aab..71cdf8d0a4 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -1827,6 +1827,114 @@ unsigned input_config_translate_str_to_bind_id(const char *str) return RARCH_BIND_LIST_END; } +void input_config_get_bind_string( + void *settings_data, + char *buf, + const struct retro_keybind *bind, + const struct retro_keybind *auto_bind, + size_t size) +{ + settings_t *settings = (settings_t*)settings_data; + int delim = 0; + bool input_descriptor_label_show = + settings->bools.input_descriptor_label_show; + + *buf = '\0'; + + if (bind && bind->joykey != NO_BTN) + input_config_get_bind_string_joykey( + input_descriptor_label_show, buf, "", bind, size); + else if (bind && bind->joyaxis != AXIS_NONE) + input_config_get_bind_string_joyaxis( + input_descriptor_label_show, + buf, "", bind, size); + else if (auto_bind && auto_bind->joykey != NO_BTN) + input_config_get_bind_string_joykey( + input_descriptor_label_show, buf, "Auto: ", auto_bind, size); + else if (auto_bind && auto_bind->joyaxis != AXIS_NONE) + input_config_get_bind_string_joyaxis( + input_descriptor_label_show, + buf, "Auto: ", auto_bind, size); + + if (*buf) + delim = 1; + +#ifndef RARCH_CONSOLE + { + char key[64]; + key[0] = '\0'; + + input_keymaps_translate_rk_to_str(bind->key, key, sizeof(key)); + if ( key[0] == 'n' + && key[1] == 'u' + && key[2] == 'l' + && key[3] == '\0' + ) + *key = '\0'; + /*empty?*/ + if (*key != '\0') + { + char keybuf[64]; + + keybuf[0] = '\0'; + + if (delim) + strlcat(buf, ", ", size); + snprintf(keybuf, sizeof(keybuf), + msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_KEY), key); + strlcat(buf, keybuf, size); + delim = 1; + } + } +#endif + + if (bind->mbutton != NO_BTN) + { + int tag = 0; + switch (bind->mbutton) + { + case RETRO_DEVICE_ID_MOUSE_LEFT: + tag = MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_LEFT; + break; + case RETRO_DEVICE_ID_MOUSE_RIGHT: + tag = MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_RIGHT; + break; + case RETRO_DEVICE_ID_MOUSE_MIDDLE: + tag = MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_MIDDLE; + break; + case RETRO_DEVICE_ID_MOUSE_BUTTON_4: + tag = MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_BUTTON4; + break; + case RETRO_DEVICE_ID_MOUSE_BUTTON_5: + tag = MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_BUTTON5; + break; + case RETRO_DEVICE_ID_MOUSE_WHEELUP: + tag = MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_WHEEL_UP; + break; + case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: + tag = MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_WHEEL_DOWN; + break; + case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP: + tag = MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_HORIZ_WHEEL_UP; + break; + case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN: + tag = MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_HORIZ_WHEEL_DOWN; + break; + } + + if (tag != 0) + { + if (delim) + strlcat(buf, ", ", size); + strlcat(buf, msg_hash_to_str((enum msg_hash_enums)tag), size); + } + } + + /*completely empty?*/ + if (*buf == '\0') + strlcat(buf, "---", size); +} + void input_config_get_bind_string_joykey( bool input_descriptor_label_show, char *buf, const char *prefix, diff --git a/input/input_remapping.h b/input/input_remapping.h index ab06073037..3a79f79371 100644 --- a/input/input_remapping.h +++ b/input/input_remapping.h @@ -144,7 +144,8 @@ uint8_t input_config_bind_map_get_retro_key(unsigned index); * @param auto_bind A default binding which will be used after `bind`. Can be NULL. * @param size The maximum length that will be written to `buf` */ -void input_config_get_bind_string(char *buf, const struct retro_keybind *bind, +void input_config_get_bind_string(void *settings_data, + char *buf, const struct retro_keybind *bind, const struct retro_keybind *auto_bind, size_t size); /** diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 7c9fc696f0..7512f89eb1 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -9969,7 +9969,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, (const struct retro_keybind*) input_config_get_bind_auto(port, retro_id); - input_config_get_bind_string(descriptor, + input_config_get_bind_string(settings, descriptor, keybind, auto_bind, sizeof(descriptor)); if (!strstr(descriptor, "Auto")) @@ -10020,7 +10020,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, (const struct retro_keybind*) input_config_get_bind_auto(port, retro_id); - input_config_get_bind_string(descriptor, + input_config_get_bind_string(settings, descriptor, keybind, auto_bind, sizeof(descriptor)); if (!strstr(descriptor, "Auto")) diff --git a/menu/menu_driver.c b/menu/menu_driver.c index 351481eb05..bbcc53fe96 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -1951,7 +1951,7 @@ int menu_dialog_iterate( (const struct retro_keybind*) input_config_get_bind_auto(0, binds[i]); - input_config_get_bind_string(desc[i], + input_config_get_bind_string(settings, desc[i], keybind, auto_bind, sizeof(desc[i])); } diff --git a/menu/menu_setting.c b/menu/menu_setting.c index bf93d80d82..f10eef8851 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -1303,6 +1303,7 @@ static void setting_get_string_representation_st_bind(rarch_setting_t *setting, unsigned index_offset = 0; const struct retro_keybind* keybind = NULL; const struct retro_keybind* auto_bind = NULL; + settings_t *settings = config_get_ptr(); if (!setting) return; @@ -1312,7 +1313,7 @@ static void setting_get_string_representation_st_bind(rarch_setting_t *setting, auto_bind = (const struct retro_keybind*) input_config_get_bind_auto(index_offset, keybind->id); - input_config_get_bind_string(s, keybind, auto_bind, len); + input_config_get_bind_string(settings, s, keybind, auto_bind, len); } static int setting_action_action_ok( diff --git a/retroarch.c b/retroarch.c index 2e6c39dc11..738afa85b3 100644 --- a/retroarch.c +++ b/retroarch.c @@ -20975,113 +20975,6 @@ void input_keyboard_event(bool down, unsigned code, } } -void input_config_get_bind_string(char *buf, - const struct retro_keybind *bind, - const struct retro_keybind *auto_bind, - size_t size) -{ - int delim = 0; - struct rarch_state *p_rarch = &rarch_st; - settings_t *settings = p_rarch->configuration_settings; - bool input_descriptor_label_show = - settings->bools.input_descriptor_label_show; - - *buf = '\0'; - - if (bind && bind->joykey != NO_BTN) - input_config_get_bind_string_joykey( - input_descriptor_label_show, buf, "", bind, size); - else if (bind && bind->joyaxis != AXIS_NONE) - input_config_get_bind_string_joyaxis( - input_descriptor_label_show, - buf, "", bind, size); - else if (auto_bind && auto_bind->joykey != NO_BTN) - input_config_get_bind_string_joykey( - input_descriptor_label_show, buf, "Auto: ", auto_bind, size); - else if (auto_bind && auto_bind->joyaxis != AXIS_NONE) - input_config_get_bind_string_joyaxis( - input_descriptor_label_show, - buf, "Auto: ", auto_bind, size); - - if (*buf) - delim = 1; - -#ifndef RARCH_CONSOLE - { - char key[64]; - key[0] = '\0'; - - input_keymaps_translate_rk_to_str(bind->key, key, sizeof(key)); - if ( key[0] == 'n' - && key[1] == 'u' - && key[2] == 'l' - && key[3] == '\0' - ) - *key = '\0'; - /*empty?*/ - if (*key != '\0') - { - char keybuf[64]; - - keybuf[0] = '\0'; - - if (delim) - strlcat(buf, ", ", size); - snprintf(keybuf, sizeof(keybuf), - msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_KEY), key); - strlcat(buf, keybuf, size); - delim = 1; - } - } -#endif - - if (bind->mbutton != NO_BTN) - { - int tag = 0; - switch (bind->mbutton) - { - case RETRO_DEVICE_ID_MOUSE_LEFT: - tag = MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_LEFT; - break; - case RETRO_DEVICE_ID_MOUSE_RIGHT: - tag = MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_RIGHT; - break; - case RETRO_DEVICE_ID_MOUSE_MIDDLE: - tag = MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_MIDDLE; - break; - case RETRO_DEVICE_ID_MOUSE_BUTTON_4: - tag = MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_BUTTON4; - break; - case RETRO_DEVICE_ID_MOUSE_BUTTON_5: - tag = MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_BUTTON5; - break; - case RETRO_DEVICE_ID_MOUSE_WHEELUP: - tag = MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_WHEEL_UP; - break; - case RETRO_DEVICE_ID_MOUSE_WHEELDOWN: - tag = MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_WHEEL_DOWN; - break; - case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP: - tag = MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_HORIZ_WHEEL_UP; - break; - case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN: - tag = MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_HORIZ_WHEEL_DOWN; - break; - } - - if (tag != 0) - { - if (delim) - strlcat(buf, ", ", size); - strlcat(buf, msg_hash_to_str((enum msg_hash_enums)tag), size); - } - } - - /*completely empty?*/ - if (*buf == '\0') - strlcat(buf, "---", size); -} - /* input_device_info wrappers START */ unsigned input_config_get_device_count(void) diff --git a/ui/drivers/qt/qt_options.cpp b/ui/drivers/qt/qt_options.cpp index 336c9e46e1..3f0a5da757 100644 --- a/ui/drivers/qt/qt_options.cpp +++ b/ui/drivers/qt/qt_options.cpp @@ -287,7 +287,7 @@ QWidget *UserBindsPage::widget() (const struct retro_keybind*) input_config_get_bind_auto(p, retro_id); - input_config_get_bind_string(descriptor, + input_config_get_bind_string(settings, descriptor, keybind, auto_bind, sizeof(descriptor)); const struct retro_keybind *keyptr =