mirror of
https://github.com/libretro/RetroArch
synced 2025-01-30 12:32:52 +00:00
Refactor set_bind functions
This commit is contained in:
parent
62a5d5338a
commit
baaed5a241
@ -368,13 +368,52 @@ static bool menu_input_custom_bind_keyboard_cb(void *data, unsigned code)
|
|||||||
return (menu->binds.begin <= menu->binds.last);
|
return (menu->binds.begin <= menu->binds.last);
|
||||||
}
|
}
|
||||||
|
|
||||||
int menu_input_set_keyboard_bind_mode(void)
|
int menu_input_set_keyboard_bind_mode(void *data,
|
||||||
|
enum menu_input_bind_mode type)
|
||||||
{
|
{
|
||||||
menu_handle_t *menu = menu_driver_get_ptr();
|
struct retro_keybind *keybind = NULL;
|
||||||
|
rarch_setting_t *setting = (rarch_setting_t*)data;
|
||||||
|
settings_t *settings = config_get_ptr();
|
||||||
|
menu_handle_t *menu = menu_driver_get_ptr();
|
||||||
|
|
||||||
if (!menu)
|
if (!menu || !setting)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case MENU_INPUT_BIND_NONE:
|
||||||
|
return -1;
|
||||||
|
break;
|
||||||
|
case MENU_INPUT_BIND_SINGLE:
|
||||||
|
keybind = (struct retro_keybind*)setting->value.keybind;
|
||||||
|
|
||||||
|
if (!keybind)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
menu->binds.begin = setting->bind_type;
|
||||||
|
menu->binds.last = setting->bind_type;
|
||||||
|
menu->binds.target = keybind;
|
||||||
|
menu->binds.user = setting->index_offset;
|
||||||
|
menu_list_push_stack( menu->menu_list,
|
||||||
|
"",
|
||||||
|
"custom_bind",
|
||||||
|
MENU_SETTINGS_CUSTOM_BIND_KEYBOARD,
|
||||||
|
menu->navigation.selection_ptr);
|
||||||
|
break;
|
||||||
|
case MENU_INPUT_BIND_ALL:
|
||||||
|
menu->binds.target = &settings->input.binds
|
||||||
|
[setting->index_offset][0];
|
||||||
|
menu->binds.begin = MENU_SETTINGS_BIND_BEGIN;
|
||||||
|
menu->binds.last = MENU_SETTINGS_BIND_LAST;
|
||||||
|
menu_list_push_stack( menu->menu_list,
|
||||||
|
"",
|
||||||
|
"custom_bind_all",
|
||||||
|
MENU_SETTINGS_CUSTOM_BIND_KEYBOARD,
|
||||||
|
menu->navigation.selection_ptr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
menu->binds.timeout_end =
|
menu->binds.timeout_end =
|
||||||
rarch_get_time_usec() +
|
rarch_get_time_usec() +
|
||||||
MENU_KEYBOARD_BIND_TIMEOUT_SECONDS * 1000000;
|
MENU_KEYBOARD_BIND_TIMEOUT_SECONDS * 1000000;
|
||||||
@ -384,13 +423,50 @@ int menu_input_set_keyboard_bind_mode(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int menu_input_set_input_device_bind_mode(void)
|
int menu_input_set_input_device_bind_mode(void *data,
|
||||||
|
enum menu_input_bind_mode type)
|
||||||
{
|
{
|
||||||
menu_handle_t *menu = menu_driver_get_ptr();
|
struct retro_keybind *keybind = NULL;
|
||||||
|
rarch_setting_t *setting = (rarch_setting_t*)data;
|
||||||
|
settings_t *settings = config_get_ptr();
|
||||||
|
menu_handle_t *menu = menu_driver_get_ptr();
|
||||||
|
|
||||||
if (!menu)
|
if (!menu || !setting)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case MENU_INPUT_BIND_NONE:
|
||||||
|
return -1;
|
||||||
|
break;
|
||||||
|
case MENU_INPUT_BIND_SINGLE:
|
||||||
|
keybind = (struct retro_keybind*)setting->value.keybind;
|
||||||
|
|
||||||
|
if (!keybind)
|
||||||
|
return -1;
|
||||||
|
menu->binds.begin = setting->bind_type;
|
||||||
|
menu->binds.last = setting->bind_type;
|
||||||
|
menu->binds.target = keybind;
|
||||||
|
menu->binds.user = setting->index_offset;
|
||||||
|
menu_list_push_stack( menu->menu_list,
|
||||||
|
"",
|
||||||
|
"custom_bind",
|
||||||
|
MENU_SETTINGS_CUSTOM_BIND,
|
||||||
|
menu->navigation.selection_ptr);
|
||||||
|
break;
|
||||||
|
case MENU_INPUT_BIND_ALL:
|
||||||
|
menu->binds.target = &settings->input.binds
|
||||||
|
[setting->index_offset][0];
|
||||||
|
menu->binds.begin = MENU_SETTINGS_BIND_BEGIN;
|
||||||
|
menu->binds.last = MENU_SETTINGS_BIND_LAST;
|
||||||
|
menu_list_push_stack( menu->menu_list,
|
||||||
|
"",
|
||||||
|
"custom_bind_all",
|
||||||
|
MENU_SETTINGS_CUSTOM_BIND,
|
||||||
|
menu->navigation.selection_ptr);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
menu_input_poll_bind_get_rested_axes(&menu->binds);
|
menu_input_poll_bind_get_rested_axes(&menu->binds);
|
||||||
menu_input_poll_bind_state(&menu->binds);
|
menu_input_poll_bind_state(&menu->binds);
|
||||||
|
|
||||||
|
@ -44,6 +44,13 @@ typedef enum
|
|||||||
MENU_ACTION_NOOP
|
MENU_ACTION_NOOP
|
||||||
} menu_action_t;
|
} menu_action_t;
|
||||||
|
|
||||||
|
enum menu_input_bind_mode
|
||||||
|
{
|
||||||
|
MENU_INPUT_BIND_NONE,
|
||||||
|
MENU_INPUT_BIND_SINGLE,
|
||||||
|
MENU_INPUT_BIND_ALL,
|
||||||
|
};
|
||||||
|
|
||||||
void menu_input_key_event(bool down, unsigned keycode, uint32_t character,
|
void menu_input_key_event(bool down, unsigned keycode, uint32_t character,
|
||||||
uint16_t key_modifiers);
|
uint16_t key_modifiers);
|
||||||
|
|
||||||
@ -72,9 +79,9 @@ void menu_input_post_iterate(int *ret, menu_file_list_cbs_t *cbs, const char *pa
|
|||||||
|
|
||||||
void menu_input_search_start(void);
|
void menu_input_search_start(void);
|
||||||
|
|
||||||
int menu_input_set_keyboard_bind_mode(void);
|
int menu_input_set_keyboard_bind_mode(void *data, enum menu_input_bind_mode type);
|
||||||
|
|
||||||
int menu_input_set_input_device_bind_mode(void);
|
int menu_input_set_input_device_bind_mode(void *data, enum menu_input_bind_mode type);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
53
settings.c
53
settings.c
@ -853,32 +853,15 @@ static int load_content_action_toggle(void *data, unsigned action,
|
|||||||
|
|
||||||
static int setting_action_ok_bind_all(void *data, unsigned action)
|
static int setting_action_ok_bind_all(void *data, unsigned action)
|
||||||
{
|
{
|
||||||
rarch_setting_t *setting = (rarch_setting_t*)data;
|
|
||||||
menu_handle_t *menu = menu_driver_get_ptr();
|
|
||||||
settings_t *settings = config_get_ptr();
|
|
||||||
global_t *global = global_get_ptr();
|
global_t *global = global_get_ptr();
|
||||||
|
|
||||||
if (!setting || !menu)
|
if (!global)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
menu->binds.target = &settings->input.binds
|
|
||||||
[setting->index_offset][0];
|
|
||||||
menu->binds.begin = MENU_SETTINGS_BIND_BEGIN;
|
|
||||||
menu->binds.last = MENU_SETTINGS_BIND_LAST;
|
|
||||||
|
|
||||||
menu_list_push_stack(
|
|
||||||
menu->menu_list,
|
|
||||||
"",
|
|
||||||
"custom_bind_all",
|
|
||||||
global->menu.bind_mode_keyboard ?
|
|
||||||
MENU_SETTINGS_CUSTOM_BIND_KEYBOARD :
|
|
||||||
MENU_SETTINGS_CUSTOM_BIND,
|
|
||||||
menu->navigation.selection_ptr);
|
|
||||||
|
|
||||||
if (global->menu.bind_mode_keyboard)
|
if (global->menu.bind_mode_keyboard)
|
||||||
menu_input_set_keyboard_bind_mode();
|
menu_input_set_keyboard_bind_mode(data, MENU_INPUT_BIND_ALL);
|
||||||
else
|
else
|
||||||
menu_input_set_input_device_bind_mode();
|
menu_input_set_input_device_bind_mode(data, MENU_INPUT_BIND_ALL);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1052,38 +1035,12 @@ static int setting_action_action_ok(void *data, unsigned action)
|
|||||||
|
|
||||||
static int setting_bind_action_ok(void *data, unsigned action)
|
static int setting_bind_action_ok(void *data, unsigned action)
|
||||||
{
|
{
|
||||||
struct retro_keybind *keybind = NULL;
|
|
||||||
rarch_setting_t *setting = (rarch_setting_t*)data;
|
|
||||||
menu_handle_t *menu = menu_driver_get_ptr();
|
|
||||||
global_t *global = global_get_ptr();
|
global_t *global = global_get_ptr();
|
||||||
|
|
||||||
if (!setting)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (!menu || !menu->menu_list)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
keybind = (struct retro_keybind*)setting->value.keybind;
|
|
||||||
|
|
||||||
if (!keybind)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
menu->binds.begin = setting->bind_type;
|
|
||||||
menu->binds.last = setting->bind_type;
|
|
||||||
menu->binds.target = keybind;
|
|
||||||
menu->binds.user = setting->index_offset;
|
|
||||||
menu_list_push_stack(
|
|
||||||
menu->menu_list,
|
|
||||||
"",
|
|
||||||
"custom_bind",
|
|
||||||
global->menu.bind_mode_keyboard ?
|
|
||||||
MENU_SETTINGS_CUSTOM_BIND_KEYBOARD : MENU_SETTINGS_CUSTOM_BIND,
|
|
||||||
menu->navigation.selection_ptr);
|
|
||||||
|
|
||||||
if (global->menu.bind_mode_keyboard)
|
if (global->menu.bind_mode_keyboard)
|
||||||
menu_input_set_keyboard_bind_mode();
|
menu_input_set_keyboard_bind_mode(data, MENU_INPUT_BIND_SINGLE);
|
||||||
else
|
else
|
||||||
menu_input_set_input_device_bind_mode();
|
menu_input_set_input_device_bind_mode(data, MENU_INPUT_BIND_SINGLE);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user