summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2019-01-16 22:03:16 -0800
committerMichael Pavone <pavone@retrodev.com>2019-01-16 22:03:16 -0800
commit9396be2bc0410d221f9f848f562711f848c342d2 (patch)
treed6088b44c4a56f5cfcd5d72edc06a38b358027f5
parentccf42ac003a47af4ddd242e0afef7f26bddaf5b5 (diff)
Add code to handle controllers that have their d-pads mapped as buttons or axes
-rw-r--r--bindings.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/bindings.c b/bindings.c
index 8801ab8..da6eea8 100644
--- a/bindings.c
+++ b/bindings.c
@@ -957,14 +957,26 @@ void handle_joy_added(int joystick)
char numstr[2] = {dpad + '0', 0};
tern_node * pad_dpad = tern_find_node(dpad_node, numstr);
char * dirs[] = {"up", "down", "left", "right"};
- //TODO: Support controllers that have d-pads implemented as analog axes or buttons
+ char *render_dirs[] = {"dpup", "dpdown", "dpleft", "dpright"};
int dirnums[] = {RENDER_DPAD_UP, RENDER_DPAD_DOWN, RENDER_DPAD_LEFT, RENDER_DPAD_RIGHT};
for (int dir = 0; dir < sizeof(dirs)/sizeof(dirs[0]); dir++) {
char * target = tern_find_ptr(pad_dpad, dirs[dir]);
if (target) {
uint8_t subtype_a = 0, subtype_b = 0;
int bindtype = parse_binding_target(joystick, target, get_pad_buttons(), get_mouse_buttons(), &subtype_a, &subtype_b);
- bind_dpad(joystick, dpad, dirnums[dir], bindtype, subtype_a, subtype_b);
+ int32_t hostbutton = dpad >0 ? -1 : render_translate_input_name(joystick, render_dirs[dir], 0);
+ if (hostbutton < 0) {
+ //assume this is a raw dpad mapping
+ bind_dpad(joystick, dpad, dirnums[dir], bindtype, subtype_a, subtype_b);
+ } else if (hostbutton & RENDER_DPAD_BIT) {
+ bind_dpad(joystick, render_dpad_part(hostbutton), render_direction_part(hostbutton), bindtype, subtype_a, subtype_b);
+ } else if (hostbutton & RENDER_AXIS_BIT) {
+ //SDL2 knows internally whether this should be a positive or negative binding, but doesn't expose that externally
+ //for now I'll just assume that any controller with axes for a d-pad has these mapped the "sane" way
+ bind_axis(joystick, render_axis_part(hostbutton), dir == 1 || dir == 3 ? 1 : 0, bindtype, subtype_a, subtype_b);
+ } else {
+ bind_button(joystick, hostbutton, bindtype, subtype_a, subtype_b);
+ }
}
}
}