Display current keybind in RGUI.

This commit is contained in:
Themaister 2013-09-30 18:27:35 +02:00
parent 02cd05550e
commit 7229142e57
3 changed files with 36 additions and 28 deletions

View File

@ -642,12 +642,27 @@ enum retro_key input_translate_keysym_to_rk(unsigned sym)
return RETROK_UNKNOWN;
}
const char *input_translate_rk_to_str(enum retro_key key)
void input_translate_rk_to_str(enum retro_key key, char *buf, size_t size)
{
for (unsigned i = 0; input_config_key_map[i].str; i++)
if (input_config_key_map[i].key == key)
return input_config_key_map[i].str;
return NULL;
rarch_assert(size >= 2);
*buf = '\0';
if (key >= RETROK_a && key <= RETROK_z)
{
buf[0] = (key - RETROK_a) + 'a';
buf[1] = '\0';
}
else
{
for (unsigned i = 0; input_config_key_map[i].str; i++)
{
if (input_config_key_map[i].key == key)
{
strlcpy(buf, input_config_key_map[i].str, size);
break;
}
}
}
}
unsigned input_translate_rk_to_keysym(enum retro_key key)
@ -804,6 +819,7 @@ const struct input_key_map input_config_key_map[] = {
void input_get_bind_string(char *buf, const struct retro_keybind *bind, size_t size)
{
*buf = '\0';
if (bind->joykey != NO_BTN)
{
if (GET_HAT_DIR(bind->joykey))
@ -817,10 +833,10 @@ void input_get_bind_string(char *buf, const struct retro_keybind *bind, size_t s
case HAT_RIGHT_MASK: dir = "right"; break;
default: dir = "?"; break;
}
snprintf(buf, size, "Hat #%u %s", (unsigned)GET_HAT(bind->joykey), dir);
snprintf(buf, size, "Hat #%u %s ", (unsigned)GET_HAT(bind->joykey), dir);
}
else
snprintf(buf, size, "%u (btn)", (unsigned)bind->joykey);
snprintf(buf, size, "%u (btn) ", (unsigned)bind->joykey);
}
else if (bind->joyaxis != AXIS_NONE)
{
@ -836,10 +852,17 @@ void input_get_bind_string(char *buf, const struct retro_keybind *bind, size_t s
dir = '+';
axis = AXIS_POS_GET(bind->joyaxis);
}
snprintf(buf, size, "%c%u (axis)", dir, axis);
snprintf(buf, size, "%c%u (axis) ", dir, axis);
}
else
strlcpy(buf, "<default>", size);
char key[64];
input_translate_rk_to_str(bind->key, key, sizeof(key));
if (!strcmp(key, "nul"))
*key = '\0';
char keybuf[64];
snprintf(keybuf, sizeof(keybuf), "(Key: %s)", key);
strlcat(buf, keybuf, size);
}
static enum retro_key find_sk_bind(const char *str)

View File

@ -143,7 +143,7 @@ struct input_key_map
enum retro_key key;
};
extern const struct input_key_map input_config_key_map[];
const char *input_translate_rk_to_str(enum retro_key key);
void input_translate_rk_to_str(enum retro_key key, char *buf, size_t size);
extern const char* const input_builtin_autoconfs[];

View File

@ -879,23 +879,8 @@ static void save_keybind_key(config_file_t *conf, const char *prefix, const char
char key[64];
snprintf(key, sizeof(key), "%s_%s", prefix, base);
char ascii[2] = {0};
const char *btn = ascii;
if (bind->key >= RETROK_a && bind->key <= RETROK_z)
ascii[0] = 'a' + (bind->key - RETROK_a);
else
{
for (unsigned i = 0; input_config_key_map[i].str; i++)
{
if (input_config_key_map[i].key == bind->key)
{
btn = input_config_key_map[i].str;
break;
}
}
}
char btn[64];
input_translate_rk_to_str(bind->key, btn, sizeof(btn));
config_set_string(conf, key, btn);
}