Report autoconfigured binds in RGUI.

This commit is contained in:
Themaister 2014-06-09 19:23:06 +02:00
parent 82422946d6
commit 9bf32df360
3 changed files with 74 additions and 45 deletions

View File

@ -522,6 +522,8 @@ static int menu_info_screen_iterate(unsigned action)
if (driver.video_data && driver.menu_ctx && driver.menu_ctx->render)
driver.menu_ctx->render();
// FIXME: This is unused code, why was it even here?
#if 0
static const unsigned binds[] = {
RETRO_DEVICE_ID_JOYPAD_UP,
RETRO_DEVICE_ID_JOYPAD_DOWN,
@ -545,9 +547,11 @@ static int menu_info_screen_iterate(unsigned action)
else
{
const struct retro_keybind *bind = &g_settings.input.binds[0][binds[i]];
input_get_bind_string(desc[i], bind, sizeof(desc[i]));
const struct retro_keybind *auto_bind = input_get_auto_bind(0, binds[i]);
input_get_bind_string(desc[i], bind, auto_bind, sizeof(desc[i]));
}
}
#endif
switch (driver.menu->info_selection)
{
@ -1484,7 +1488,8 @@ static int menu_start_screen_iterate(unsigned action)
else
{
const struct retro_keybind *bind = &g_settings.input.binds[0][binds[i]];
input_get_bind_string(desc[i], bind, sizeof(desc[i]));
const struct retro_keybind *auto_bind = input_get_auto_bind(0, binds[i]);
input_get_bind_string(desc[i], bind, auto_bind, sizeof(desc[i]));
}
}
@ -4997,7 +5002,10 @@ static void menu_common_setting_set_label(char *type_str, size_t type_str_size,
menu_common_setting_set_label_perf(type_str, type_str_size, w, type, perf_counters_libretro,
type - RGUI_SETTINGS_LIBRETRO_PERF_COUNTERS_BEGIN);
else if (type >= RGUI_SETTINGS_BIND_BEGIN && type <= RGUI_SETTINGS_BIND_ALL_LAST)
input_get_bind_string(type_str, &g_settings.input.binds[driver.menu->current_pad][type - RGUI_SETTINGS_BIND_BEGIN], type_str_size);
{
const struct retro_keybind *auto_bind = input_get_auto_bind(driver.menu->current_pad, type - RGUI_SETTINGS_BIND_BEGIN);
input_get_bind_string(type_str, &g_settings.input.binds[driver.menu->current_pad][type - RGUI_SETTINGS_BIND_BEGIN], auto_bind, type_str_size);
}
else
{
switch (type)

View File

@ -1225,51 +1225,70 @@ void input_config_autoconfigure_joypad(unsigned index, const char *name, const c
}
}
void input_get_bind_string(char *buf, const struct retro_keybind *bind, size_t size)
const struct retro_keybind *input_get_auto_bind(unsigned port, unsigned id)
{
int joy_index = g_settings.input.joypad_map[port];
if (joy_index < 0)
return NULL;
return &g_settings.input.autoconf_binds[joy_index][id];
}
static void input_get_bind_string_joykey(char *buf, const char *prefix, const struct retro_keybind *bind, size_t size)
{
if (driver.input->set_keybinds)
{
struct platform_bind key_label;
strlcpy(key_label.desc, "Unknown", sizeof(key_label.desc));
key_label.joykey = bind->joykey;
driver.input->set_keybinds(&key_label, 0, 0, 0, (1ULL << KEYBINDS_ACTION_GET_BIND_LABEL));
snprintf(buf, size, "%s%s (btn) ", prefix, key_label.desc);
}
else if (GET_HAT_DIR(bind->joykey))
{
const char *dir;
switch (GET_HAT_DIR(bind->joykey))
{
case HAT_UP_MASK: dir = "up"; break;
case HAT_DOWN_MASK: dir = "down"; break;
case HAT_LEFT_MASK: dir = "left"; break;
case HAT_RIGHT_MASK: dir = "right"; break;
default: dir = "?"; break;
}
snprintf(buf, size, "%sHat #%u %s ", prefix, (unsigned)GET_HAT(bind->joykey), dir);
}
else
snprintf(buf, size, "%s%u (btn) ", prefix, (unsigned)bind->joykey);
}
static void input_get_bind_string_joyaxis(char *buf, const char *prefix, const struct retro_keybind *bind, size_t size)
{
unsigned axis = 0;
char dir = '\0';
if (AXIS_NEG_GET(bind->joyaxis) != AXIS_DIR_NONE)
{
dir = '-';
axis = AXIS_NEG_GET(bind->joyaxis);
}
else if (AXIS_POS_GET(bind->joyaxis) != AXIS_DIR_NONE)
{
dir = '+';
axis = AXIS_POS_GET(bind->joyaxis);
}
snprintf(buf, size, "%s%c%u (axis) ", prefix, dir, axis);
}
void input_get_bind_string(char *buf, const struct retro_keybind *bind,
const struct retro_keybind *auto_bind, size_t size)
{
*buf = '\0';
if (bind->joykey != NO_BTN)
{
if (driver.input->set_keybinds)
{
struct platform_bind key_label;
strlcpy(key_label.desc, "Unknown", sizeof(key_label.desc));
key_label.joykey = bind->joykey;
driver.input->set_keybinds(&key_label, 0, 0, 0, (1ULL << KEYBINDS_ACTION_GET_BIND_LABEL));
snprintf(buf, size, "%s (btn) ", key_label.desc);
}
else if (GET_HAT_DIR(bind->joykey))
{
const char *dir;
switch (GET_HAT_DIR(bind->joykey))
{
case HAT_UP_MASK: dir = "up"; break;
case HAT_DOWN_MASK: dir = "down"; break;
case HAT_LEFT_MASK: dir = "left"; break;
case HAT_RIGHT_MASK: dir = "right"; break;
default: dir = "?"; break;
}
snprintf(buf, size, "Hat #%u %s ", (unsigned)GET_HAT(bind->joykey), dir);
}
else
snprintf(buf, size, "%u (btn) ", (unsigned)bind->joykey);
}
input_get_bind_string_joykey(buf, "", bind, size);
else if (bind->joyaxis != AXIS_NONE)
{
unsigned axis = 0;
char dir = '\0';
if (AXIS_NEG_GET(bind->joyaxis) != AXIS_DIR_NONE)
{
dir = '-';
axis = AXIS_NEG_GET(bind->joyaxis);
}
else if (AXIS_POS_GET(bind->joyaxis) != AXIS_DIR_NONE)
{
dir = '+';
axis = AXIS_POS_GET(bind->joyaxis);
}
snprintf(buf, size, "%c%u (axis) ", dir, axis);
}
input_get_bind_string_joyaxis(buf, "", bind, size);
else if (auto_bind && auto_bind->joykey != NO_BTN)
input_get_bind_string_joykey(buf, "Auto: ", auto_bind, size);
else if (auto_bind && auto_bind->joyaxis != AXIS_NONE)
input_get_bind_string_joyaxis(buf, "Auto: ", auto_bind, size);
#ifndef RARCH_CONSOLE
char key[64];

View File

@ -143,7 +143,9 @@ struct input_bind_map
extern const struct input_bind_map input_config_bind_map[];
void input_get_bind_string(char *buf, const struct retro_keybind *bind, size_t size);
const struct retro_keybind *input_get_auto_bind(unsigned port, unsigned id);
// auto_bind can be NULL.
void input_get_bind_string(char *buf, const struct retro_keybind *bind, const struct retro_keybind *auto_bind, size_t size);
struct input_key_map
{