Skip to content

Commit

Permalink
add left/right callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
andres-asm committed Sep 11, 2017
1 parent b93417f commit c8752ec
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 216 deletions.
2 changes: 1 addition & 1 deletion input/input_mapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void input_mapper_poll(input_mapper_t *handle)
{
if(i < RETROK_LAST)
{
if (input_state(0, RETRO_DEVICE_JOYPAD, handle->port, i))
if (input_state(handle->port, RETRO_DEVICE_JOYPAD, 0, i))
{
MAPPER_SET_KEY (handle, settings->uints.input_keymapper_ids[i]);
input_keyboard_event(true, settings->uints.input_keymapper_ids[i], 0, 0, RETRO_DEVICE_KEYBOARD);
Expand Down
74 changes: 11 additions & 63 deletions menu/cbs/menu_cbs_get_value.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
cbs->action_get_value_ident = #name;
#endif

extern struct key_desc key_descriptors[192];
extern struct key_desc key_descriptors[MENU_SETTINGS_INPUT_DESC_KBD_END];

static void menu_action_setting_disp_set_label_cheat_num_passes(
file_list_t* list,
Expand Down Expand Up @@ -497,74 +497,22 @@ static void menu_action_setting_disp_set_label_input_desc_kbd(
const char *path,
char *s2, size_t len2)
{
RARCH_LOG("%d %s\n", key_descriptors[10].id, key_descriptors[10].desc);
char descriptor[255];
const struct retro_keybind *auto_bind = NULL;
const struct retro_keybind *keybind = NULL;
settings_t *settings = config_get_ptr();
unsigned inp_desc_index_offset =
type - MENU_SETTINGS_INPUT_DESC_BEGIN;
unsigned inp_desc_user = inp_desc_index_offset /
(RARCH_FIRST_CUSTOM_BIND + 4);
unsigned inp_desc_button_index_offset = inp_desc_index_offset -
(inp_desc_user * (RARCH_FIRST_CUSTOM_BIND + 4));
unsigned remap_id = 0;
settings_t *settings = config_get_ptr();
unsigned key_id;
unsigned remap_id =
settings->uints.input_keymapper_ids[type - MENU_SETTINGS_INPUT_DESC_KBD_BEGIN];
char desc[PATH_MAX_LENGTH];

if (!settings)
return;

descriptor[0] = '\0';

remap_id = settings->uints.input_remap_ids
[inp_desc_user][inp_desc_button_index_offset];

keybind = &input_config_binds[inp_desc_user][remap_id];
auto_bind = (const struct retro_keybind*)
input_config_get_bind_auto(inp_desc_user, remap_id);

input_config_get_bind_string(descriptor,
keybind, auto_bind, sizeof(descriptor));

if (inp_desc_button_index_offset < RARCH_FIRST_CUSTOM_BIND)
for (key_id = 0; key_id < MENU_SETTINGS_INPUT_DESC_KBD_END - 1; key_id++)
{
if(strstr(descriptor, "Auto") && !strstr(descriptor,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE)))
strlcpy(s,
descriptor,
len);
else
{
const struct retro_keybind *keyptr = &input_config_binds[inp_desc_user]
[remap_id];

strlcpy(s, msg_hash_to_str(keyptr->enum_idx), len);
}
}



else
{
const char *str = NULL;
switch (remap_id)
{
case 0:
str = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_ANALOG_LEFT_X);
break;
case 1:
str = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_ANALOG_LEFT_Y);
break;
case 2:
str = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_ANALOG_RIGHT_X);
break;
case 3:
str = msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_ANALOG_RIGHT_Y);
break;
}

if (!string_is_empty(str))
strlcpy(s, str, len);
if(remap_id == key_descriptors[key_id].key)
break;
}
snprintf(desc, sizeof(desc), "Keyboard %s", key_descriptors[key_id].desc);
strlcpy(s, desc, len);

*w = 19;
strlcpy(s2, path, len2);
Expand Down
36 changes: 36 additions & 0 deletions menu/cbs/menu_cbs_left.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
} while(0)
#endif

extern struct key_desc key_descriptors[MENU_SETTINGS_INPUT_DESC_KBD_END];

#ifdef HAVE_SHADER_MANAGER
static int generic_shader_action_parameter_left(
struct video_shader_parameter *param,
Expand Down Expand Up @@ -111,6 +113,35 @@ static int action_left_input_desc(unsigned type, const char *label,
return 0;
}

static int action_left_input_desc_kbd(unsigned type, const char *label,
bool wraparound)
{
settings_t *settings = config_get_ptr();
unsigned key_id;
unsigned offset = type - MENU_SETTINGS_INPUT_DESC_KBD_BEGIN;
unsigned remap_id =
settings->uints.input_keymapper_ids[offset];
char desc[PATH_MAX_LENGTH];

if (!settings)
return 0;

for (key_id = 0; key_id < MENU_SETTINGS_INPUT_DESC_KBD_END - 1; key_id++)
{
if(remap_id == key_descriptors[key_id].key)
break;
}

if (key_id > 1)
key_id--;
else
key_id = MENU_SETTINGS_INPUT_DESC_KBD_END - 1;

settings->uints.input_keymapper_ids[offset] = key_descriptors[key_id].key;

return 0;
}

static int action_left_scroll(unsigned type, const char *label,
bool wraparound)
{
Expand Down Expand Up @@ -538,6 +569,11 @@ static int menu_cbs_init_bind_left_compare_type(menu_file_list_cbs_t *cbs,
{
BIND_ACTION_LEFT(cbs, action_left_input_desc);
}
else if (type >= MENU_SETTINGS_INPUT_DESC_KBD_BEGIN
&& type <= MENU_SETTINGS_INPUT_DESC_KBD_END)
{
BIND_ACTION_LEFT(cbs, action_left_input_desc_kbd);
}
else if ((type >= MENU_SETTINGS_PLAYLIST_ASSOCIATION_START))
{
BIND_ACTION_LEFT(cbs, playlist_association_left);
Expand Down
59 changes: 48 additions & 11 deletions menu/cbs/menu_cbs_right.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "../../managers/cheat_manager.h"
#include "../../file_path_special.h"
#include "../../retroarch.h"
#include "../../verbosity.h"
#include "../../ui/ui_companion_driver.h"

#ifndef BIND_ACTION_RIGHT
Expand All @@ -47,6 +48,8 @@
} while(0)
#endif

extern struct key_desc key_descriptors[MENU_SETTINGS_INPUT_DESC_KBD_END];

#ifdef HAVE_SHADER_MANAGER
static int generic_shader_action_parameter_right(struct video_shader_parameter *param,
unsigned type, const char *label, bool wraparound)
Expand Down Expand Up @@ -99,28 +102,57 @@ int action_right_cheat(unsigned type, const char *label,
wraparound);
}

int action_right_input_desc(unsigned type, const char *label,
int action_right_input_desc_kbd(unsigned type, const char *label,
bool wraparound)
{
unsigned inp_desc_index_offset = type - MENU_SETTINGS_INPUT_DESC_BEGIN;
unsigned inp_desc_user = inp_desc_index_offset / (RARCH_FIRST_CUSTOM_BIND + 4);
unsigned inp_desc_button_index_offset = inp_desc_index_offset - (inp_desc_user * (RARCH_FIRST_CUSTOM_BIND + 4));
settings_t *settings = config_get_ptr();
unsigned key_id;
unsigned offset = type - MENU_SETTINGS_INPUT_DESC_KBD_BEGIN;
unsigned remap_id =
settings->uints.input_keymapper_ids[offset];
char desc[PATH_MAX_LENGTH];

if (inp_desc_button_index_offset < RARCH_FIRST_CUSTOM_BIND)
if (!settings)
return 0;

for (key_id = 0; key_id < MENU_SETTINGS_INPUT_DESC_KBD_END - 1; key_id++)
{
if (settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset] < RARCH_FIRST_CUSTOM_BIND - 1)
settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset]++;
if(remap_id == key_descriptors[key_id].key)
break;
}

if (key_id < MENU_SETTINGS_INPUT_DESC_KBD_END - 1)
key_id++;
else
{
if (settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset] < 4 - 1)
settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset]++;
}
key_id = 0;

settings->uints.input_keymapper_ids[offset] = key_descriptors[key_id].key;

return 0;
}

int action_right_input_desc(unsigned type, const char *label,
bool wraparound)
{
unsigned inp_desc_index_offset = type - MENU_SETTINGS_INPUT_DESC_BEGIN;
unsigned inp_desc_user = inp_desc_index_offset / (RARCH_FIRST_CUSTOM_BIND + 4);
unsigned inp_desc_button_index_offset = inp_desc_index_offset - (inp_desc_user * (RARCH_FIRST_CUSTOM_BIND + 4));
settings_t *settings = config_get_ptr();

if (inp_desc_button_index_offset < RARCH_FIRST_CUSTOM_BIND)
{
if (settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset] < RARCH_FIRST_CUSTOM_BIND - 1)
settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset]++;
}
else
{
if (settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset] < 4 - 1)
settings->uints.input_remap_ids[inp_desc_user][inp_desc_button_index_offset]++;
}

return 0;
}

static int action_right_scroll(unsigned type, const char *label,
bool wraparound)
{
Expand Down Expand Up @@ -406,6 +438,11 @@ static int menu_cbs_init_bind_right_compare_type(menu_file_list_cbs_t *cbs,
{
BIND_ACTION_RIGHT(cbs, action_right_input_desc);
}
else if (type >= MENU_SETTINGS_INPUT_DESC_KBD_BEGIN
&& type <= MENU_SETTINGS_INPUT_DESC_KBD_END)
{
BIND_ACTION_RIGHT(cbs, action_right_input_desc_kbd);
}
else if ((type >= MENU_SETTINGS_PLAYLIST_ASSOCIATION_START))
{
BIND_ACTION_RIGHT(cbs, playlist_association_right);
Expand Down
Loading

0 comments on commit c8752ec

Please sign in to comment.