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; 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++) rarch_assert(size >= 2);
if (input_config_key_map[i].key == key) *buf = '\0';
return input_config_key_map[i].str;
return NULL; 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) 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) void input_get_bind_string(char *buf, const struct retro_keybind *bind, size_t size)
{ {
*buf = '\0';
if (bind->joykey != NO_BTN) if (bind->joykey != NO_BTN)
{ {
if (GET_HAT_DIR(bind->joykey)) 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; case HAT_RIGHT_MASK: dir = "right"; break;
default: dir = "?"; 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 else
snprintf(buf, size, "%u (btn)", (unsigned)bind->joykey); snprintf(buf, size, "%u (btn) ", (unsigned)bind->joykey);
} }
else if (bind->joyaxis != AXIS_NONE) 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 = '+'; dir = '+';
axis = AXIS_POS_GET(bind->joyaxis); 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) static enum retro_key find_sk_bind(const char *str)

View File

@ -143,7 +143,7 @@ struct input_key_map
enum retro_key key; enum retro_key key;
}; };
extern const struct input_key_map input_config_key_map[]; 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[]; 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]; char key[64];
snprintf(key, sizeof(key), "%s_%s", prefix, base); snprintf(key, sizeof(key), "%s_%s", prefix, base);
char ascii[2] = {0}; char btn[64];
const char *btn = ascii; input_translate_rk_to_str(bind->key, btn, sizeof(btn));
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;
}
}
}
config_set_string(conf, key, btn); config_set_string(conf, key, btn);
} }