comparison bindings.c @ 1679:deaf31803b11

Add code to handle controllers that have their d-pads mapped as buttons or axes
author Michael Pavone <pavone@retrodev.com>
date Wed, 16 Jan 2019 22:03:16 -0800
parents 12d0c7c4ad80
children 326d1a601fb9
comparison
equal deleted inserted replaced
1678:d377d6037dd9 1679:deaf31803b11
955 for (int dpad = 0; dpad < 10; dpad++) 955 for (int dpad = 0; dpad < 10; dpad++)
956 { 956 {
957 char numstr[2] = {dpad + '0', 0}; 957 char numstr[2] = {dpad + '0', 0};
958 tern_node * pad_dpad = tern_find_node(dpad_node, numstr); 958 tern_node * pad_dpad = tern_find_node(dpad_node, numstr);
959 char * dirs[] = {"up", "down", "left", "right"}; 959 char * dirs[] = {"up", "down", "left", "right"};
960 //TODO: Support controllers that have d-pads implemented as analog axes or buttons 960 char *render_dirs[] = {"dpup", "dpdown", "dpleft", "dpright"};
961 int dirnums[] = {RENDER_DPAD_UP, RENDER_DPAD_DOWN, RENDER_DPAD_LEFT, RENDER_DPAD_RIGHT}; 961 int dirnums[] = {RENDER_DPAD_UP, RENDER_DPAD_DOWN, RENDER_DPAD_LEFT, RENDER_DPAD_RIGHT};
962 for (int dir = 0; dir < sizeof(dirs)/sizeof(dirs[0]); dir++) { 962 for (int dir = 0; dir < sizeof(dirs)/sizeof(dirs[0]); dir++) {
963 char * target = tern_find_ptr(pad_dpad, dirs[dir]); 963 char * target = tern_find_ptr(pad_dpad, dirs[dir]);
964 if (target) { 964 if (target) {
965 uint8_t subtype_a = 0, subtype_b = 0; 965 uint8_t subtype_a = 0, subtype_b = 0;
966 int bindtype = parse_binding_target(joystick, target, get_pad_buttons(), get_mouse_buttons(), &subtype_a, &subtype_b); 966 int bindtype = parse_binding_target(joystick, target, get_pad_buttons(), get_mouse_buttons(), &subtype_a, &subtype_b);
967 bind_dpad(joystick, dpad, dirnums[dir], bindtype, subtype_a, subtype_b); 967 int32_t hostbutton = dpad >0 ? -1 : render_translate_input_name(joystick, render_dirs[dir], 0);
968 if (hostbutton < 0) {
969 //assume this is a raw dpad mapping
970 bind_dpad(joystick, dpad, dirnums[dir], bindtype, subtype_a, subtype_b);
971 } else if (hostbutton & RENDER_DPAD_BIT) {
972 bind_dpad(joystick, render_dpad_part(hostbutton), render_direction_part(hostbutton), bindtype, subtype_a, subtype_b);
973 } else if (hostbutton & RENDER_AXIS_BIT) {
974 //SDL2 knows internally whether this should be a positive or negative binding, but doesn't expose that externally
975 //for now I'll just assume that any controller with axes for a d-pad has these mapped the "sane" way
976 bind_axis(joystick, render_axis_part(hostbutton), dir == 1 || dir == 3 ? 1 : 0, bindtype, subtype_a, subtype_b);
977 } else {
978 bind_button(joystick, hostbutton, bindtype, subtype_a, subtype_b);
979 }
968 } 980 }
969 } 981 }
970 } 982 }
971 } 983 }
972 tern_node *button_node = tern_find_node(pad, "buttons"); 984 tern_node *button_node = tern_find_node(pad, "buttons");