From 44ccbe0122a22b28507250f3a6b7879251021bb2 Mon Sep 17 00:00:00 2001 From: twinaphex <autechre1024@hotmail.com> Date: Thu, 14 Mar 2013 18:02:19 +0100 Subject: [PATCH] Implement KEYBINDS_ACTION_GET_BIND_LABEL - will be used through set_keybinds --- driver.h | 3 ++- gx/gx_input.c | 26 +++++++++++++++++++++----- ps3/ps3_input.c | 26 +++++++++++++++++++++----- xdk/xdk_xinput_input.c | 26 +++++++++++++++++++++----- 4 files changed, 65 insertions(+), 16 deletions(-) diff --git a/driver.h b/driver.h index 9de37075d2..20e02ae87e 100644 --- a/driver.h +++ b/driver.h @@ -135,7 +135,7 @@ struct retro_keybind struct platform_bind { uint64_t joykey; - const char *desc; + char *desc; }; enum rarch_shader_type @@ -223,6 +223,7 @@ enum keybind_set_id KEYBINDS_ACTION_SET_ANALOG_DPAD_NONE, KEYBINDS_ACTION_SET_ANALOG_DPAD_LSTICK, KEYBINDS_ACTION_SET_ANALOG_DPAD_RSTICK, + KEYBINDS_ACTION_GET_BIND_LABEL, KEYBINDS_ACTION_LAST }; diff --git a/gx/gx_input.c b/gx/gx_input.c index ae9dadb725..008d8bf434 100644 --- a/gx/gx_input.c +++ b/gx/gx_input.c @@ -168,14 +168,12 @@ static void gx_input_set_keybinds(void *data, unsigned device, unsigned port, { uint64_t *key = &g_settings.input.binds[port][id].joykey; uint64_t joykey = *key; - size_t arr_size; + size_t arr_size = platform_keys_size / sizeof(platform_keys[0]); (void)device; if (keybind_action & (1ULL << KEYBINDS_ACTION_DECREMENT_BIND)) { - arr_size = platform_keys_size / sizeof(platform_keys[0]); - if (joykey == NO_BTN) *key = platform_keys[arr_size - 1].joykey; else if (platform_keys[0].joykey == joykey) @@ -196,8 +194,6 @@ static void gx_input_set_keybinds(void *data, unsigned device, unsigned port, if (keybind_action & (1ULL << KEYBINDS_ACTION_INCREMENT_BIND)) { - arr_size = platform_keys_size / sizeof(platform_keys[0]); - if (joykey == NO_BTN) *key = platform_keys[0].joykey; else if (platform_keys[arr_size - 1].joykey == joykey) @@ -412,6 +408,26 @@ static void gx_input_set_keybinds(void *data, unsigned device, unsigned port, break; } } + + if (keybind_action & (1ULL << KEYBINDS_ACTION_GET_BIND_LABEL)) + { + struct platform_bind *ret = (struct platform_bind*)data; + + if (ret->joykey == NO_BTN) + strlcpy(ret->desc, "No button", sizeof(ret->desc)); + else + { + for (size_t i = 0; i < arr_size; i++) + { + if (platform_keys[i].joykey == joykey) + { + strlcpy(ret->desc, platform_keys[i].desc, sizeof(ret->desc)); + return; + } + } + strlcpy(ret->desc, "Unknown", sizeof(ret->desc)); + } + } } static void *gx_input_init(void) diff --git a/ps3/ps3_input.c b/ps3/ps3_input.c index 4afaba8d8d..e411b03c40 100644 --- a/ps3/ps3_input.c +++ b/ps3/ps3_input.c @@ -402,14 +402,12 @@ static void ps3_input_set_keybinds(void *data, unsigned device, { uint64_t *key = &g_settings.input.binds[port][id].joykey; uint64_t joykey = *key; - size_t arr_size; + size_t arr_size = platform_keys_size / sizeof(platform_keys[0]); (void)device; if (keybind_action & (1ULL << KEYBINDS_ACTION_DECREMENT_BIND)) { - arr_size = platform_keys_size / sizeof(platform_keys[0]); - if (joykey == NO_BTN) *key = platform_keys[arr_size - 1].joykey; else if (platform_keys[0].joykey == joykey) @@ -430,8 +428,6 @@ static void ps3_input_set_keybinds(void *data, unsigned device, if (keybind_action & (1ULL << KEYBINDS_ACTION_INCREMENT_BIND)) { - arr_size = platform_keys_size / sizeof(platform_keys[0]); - if (joykey == NO_BTN) *key = platform_keys[0].joykey; else if (platform_keys[arr_size - 1].joykey == joykey) @@ -490,6 +486,26 @@ static void ps3_input_set_keybinds(void *data, unsigned device, g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_LEFT].joykey = platform_keys[RARCH_ANALOG_RIGHT_X_DPAD_LEFT].joykey; g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_RIGHT].joykey = platform_keys[RARCH_ANALOG_RIGHT_X_DPAD_RIGHT].joykey; } + + if (keybind_action & (1ULL << KEYBINDS_ACTION_GET_BIND_LABEL)) + { + struct platform_bind *ret = (struct platform_bind*)data; + + if (ret->joykey == NO_BTN) + strlcpy(ret->desc, "No button", sizeof(ret->desc)); + else + { + for (size_t i = 0; i < arr_size; i++) + { + if (platform_keys[i].joykey == joykey) + { + strlcpy(ret->desc, platform_keys[i].desc, sizeof(ret->desc)); + return; + } + } + strlcpy(ret->desc, "Unknown", sizeof(ret->desc)); + } + } } static void* ps3_input_init(void) diff --git a/xdk/xdk_xinput_input.c b/xdk/xdk_xinput_input.c index e8d5d7638f..780c7ce585 100644 --- a/xdk/xdk_xinput_input.c +++ b/xdk/xdk_xinput_input.c @@ -274,14 +274,12 @@ static void xdk_input_set_keybinds(void *data, unsigned device, { uint64_t *key = &g_settings.input.binds[port][id].joykey; uint64_t joykey = *key; - size_t arr_size; + size_t arr_size = platform_keys_size / sizeof(platform_keys[0]); (void)device; if (keybind_action & (1ULL << KEYBINDS_ACTION_DECREMENT_BIND)) { - arr_size = platform_keys_size / sizeof(platform_keys[0]); - if (joykey == NO_BTN) *key = platform_keys[arr_size - 1].joykey; else if (platform_keys[0].joykey == joykey) @@ -302,8 +300,6 @@ static void xdk_input_set_keybinds(void *data, unsigned device, if (keybind_action & (1ULL << KEYBINDS_ACTION_INCREMENT_BIND)) { - arr_size = platform_keys_size / sizeof(platform_keys[0]); - if (joykey == NO_BTN) *key = platform_keys[0].joykey; else if (platform_keys[arr_size - 1].joykey == joykey) @@ -363,6 +359,26 @@ static void xdk_input_set_keybinds(void *data, unsigned device, g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_LEFT].joykey = platform_keys[RARCH_ANALOG_RIGHT_X_DPAD_LEFT].joykey; g_settings.input.binds[port][RETRO_DEVICE_ID_JOYPAD_RIGHT].joykey = platform_keys[RARCH_ANALOG_RIGHT_X_DPAD_RIGHT].joykey; } + + if (keybind_action & (1ULL << KEYBINDS_ACTION_GET_BIND_LABEL)) + { + struct platform_bind *ret = (struct platform_bind*)data; + + if (ret->joykey == NO_BTN) + strlcpy(ret->desc, "No button", sizeof(ret->desc)); + else + { + for (size_t i = 0; i < arr_size; i++) + { + if (platform_keys[i].joykey == joykey) + { + strlcpy(ret->desc, platform_keys[i].desc, sizeof(ret->desc)); + return; + } + } + strlcpy(ret->desc, "Unknown", sizeof(ret->desc)); + } + } } static void *xdk_input_init(void)