diff options
-rw-r--r-- | bindings.c | 2 | ||||
-rw-r--r-- | nuklear_ui/blastem_nuklear.c | 13 | ||||
-rw-r--r-- | render.h | 1 | ||||
-rwxr-xr-x | render_sdl.c | 7 |
4 files changed, 19 insertions, 4 deletions
@@ -825,7 +825,7 @@ void process_pad_button(char *key, tern_val val, uint8_t valtype, void *data) bind_dpad(hostpadnum, render_dpad_part(hostbutton), render_direction_part(hostbutton), bindtype, subtype_a, subtype_b); return; } else if (hostbutton & RENDER_AXIS_BIT) { - bind_axis(hostpadnum, render_axis_part(hostbutton), 1, bindtype, subtype_a, subtype_b); + bind_axis(hostpadnum, render_axis_part(hostbutton), hostbutton & RENDER_AXIS_POS, bindtype, subtype_a, subtype_b); return; } } diff --git a/nuklear_ui/blastem_nuklear.c b/nuklear_ui/blastem_nuklear.c index 25b5a85..dbd4ffb 100644 --- a/nuklear_ui/blastem_nuklear.c +++ b/nuklear_ui/blastem_nuklear.c @@ -1128,7 +1128,7 @@ static int current_button; static int current_axis; static int button_pressed, last_button; static int hat_moved, hat_value, last_hat, last_hat_value; -static int axis_moved, axis_value, last_axis; +static int axis_moved, axis_value, last_axis, last_axis_value; static char *mapping_string; static size_t mapping_pos; @@ -1206,7 +1206,11 @@ static void view_controller_mappings(struct nk_context *context) last_hat = hat_moved; last_hat_value = hat_value; - } else if (axis_moved >= 0 && abs(axis_value) > 1000 && axis_moved != last_axis) { + } else if (axis_moved >= 0 && abs(axis_value) > 1000 && ( + axis_moved != last_axis || ( + axis_value/abs(axis_value) != last_axis_value/abs(axis_value) && current_button >= SDL_CONTROLLER_BUTTON_DPAD_UP + ) + )) { if (current_button <= SDL_CONTROLLER_BUTTON_B || axis_moved != button_a_axis) { start_mapping(); mapping_string[mapping_pos++] = 'a'; @@ -1214,7 +1218,11 @@ static void view_controller_mappings(struct nk_context *context) mapping_string[mapping_pos++] = '0' + axis_moved / 10; } mapping_string[mapping_pos++] = '0' + axis_moved % 10; + if (current_button >= SDL_CONTROLLER_BUTTON_DPAD_UP) { + mapping_string[mapping_pos++] = axis_value >= 0 ? '+' : '-'; + } last_axis = axis_moved; + last_axis_value = axis_value; } added_mapping = 1; } @@ -1295,6 +1303,7 @@ static void view_controller_variant(struct nk_context *context) last_hat = -1; axis_moved = -1; last_axis = -1; + last_axis_value = 0; SDL_Joystick *joy = render_get_joystick(selected_controller); const char *name = SDL_JoystickName(joy); size_t namesz = strlen(name); @@ -86,6 +86,7 @@ typedef enum { #define RENDER_DPAD_BIT 0x40000000 #define RENDER_AXIS_BIT 0x20000000 +#define RENDER_AXIS_POS 0x10000000 #define RENDER_INVALID_NAME -1 #define RENDER_NOT_MAPPED -2 #define RENDER_NOT_PLUGGED_IN -3 diff --git a/render_sdl.c b/render_sdl.c index f162260..a77d049 100755 --- a/render_sdl.c +++ b/render_sdl.c @@ -1864,6 +1864,7 @@ int32_t render_translate_input_name(int32_t controller, char *name, uint8_t is_a } SDL_GameControllerButtonBind cbind; + int32_t is_positive = RENDER_AXIS_POS; if (is_axis) { int sdl_axis = render_lookup_axis(name); @@ -1878,6 +1879,10 @@ int32_t render_translate_input_name(int32_t controller, char *name, uint8_t is_a SDL_GameControllerClose(control); return RENDER_INVALID_NAME; } + if (sdl_button == SDL_CONTROLLER_BUTTON_DPAD_UP || sdl_button == SDL_CONTROLLER_BUTTON_DPAD_LEFT) { + //assume these will be negative if they are an axis + is_positive = 0; + } cbind = SDL_GameControllerGetBindForButton(control, sdl_button); } SDL_GameControllerClose(control); @@ -1886,7 +1891,7 @@ int32_t render_translate_input_name(int32_t controller, char *name, uint8_t is_a case SDL_CONTROLLER_BINDTYPE_BUTTON: return cbind.value.button; case SDL_CONTROLLER_BINDTYPE_AXIS: - return RENDER_AXIS_BIT | cbind.value.axis; + return RENDER_AXIS_BIT | cbind.value.axis | is_positive; case SDL_CONTROLLER_BINDTYPE_HAT: return RENDER_DPAD_BIT | (cbind.value.hat.hat << 4) | cbind.value.hat.hat_mask; } |