Mercurial > repos > blastem
comparison nuklear_ui/blastem_nuklear.c @ 1804:34370330eaf3
Support controllers that have their dpad mapped to an axis
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 26 Mar 2019 23:26:08 -0700 |
parents | 5278b6e44fc1 |
children | 396369ab481a |
comparison
equal
deleted
inserted
replaced
1803:a851d36e24bb | 1804:34370330eaf3 |
---|---|
1126 | 1126 |
1127 static int current_button; | 1127 static int current_button; |
1128 static int current_axis; | 1128 static int current_axis; |
1129 static int button_pressed, last_button; | 1129 static int button_pressed, last_button; |
1130 static int hat_moved, hat_value, last_hat, last_hat_value; | 1130 static int hat_moved, hat_value, last_hat, last_hat_value; |
1131 static int axis_moved, axis_value, last_axis; | 1131 static int axis_moved, axis_value, last_axis, last_axis_value; |
1132 static char *mapping_string; | 1132 static char *mapping_string; |
1133 static size_t mapping_pos; | 1133 static size_t mapping_pos; |
1134 | 1134 |
1135 static void start_mapping(void) | 1135 static void start_mapping(void) |
1136 { | 1136 { |
1204 mapping_string[mapping_pos++] = '0' + hat_value; | 1204 mapping_string[mapping_pos++] = '0' + hat_value; |
1205 added_mapping = 1; | 1205 added_mapping = 1; |
1206 | 1206 |
1207 last_hat = hat_moved; | 1207 last_hat = hat_moved; |
1208 last_hat_value = hat_value; | 1208 last_hat_value = hat_value; |
1209 } else if (axis_moved >= 0 && abs(axis_value) > 1000 && axis_moved != last_axis) { | 1209 } else if (axis_moved >= 0 && abs(axis_value) > 1000 && ( |
1210 axis_moved != last_axis || ( | |
1211 axis_value/abs(axis_value) != last_axis_value/abs(axis_value) && current_button >= SDL_CONTROLLER_BUTTON_DPAD_UP | |
1212 ) | |
1213 )) { | |
1210 if (current_button <= SDL_CONTROLLER_BUTTON_B || axis_moved != button_a_axis) { | 1214 if (current_button <= SDL_CONTROLLER_BUTTON_B || axis_moved != button_a_axis) { |
1211 start_mapping(); | 1215 start_mapping(); |
1212 mapping_string[mapping_pos++] = 'a'; | 1216 mapping_string[mapping_pos++] = 'a'; |
1213 if (axis_moved > 9) { | 1217 if (axis_moved > 9) { |
1214 mapping_string[mapping_pos++] = '0' + axis_moved / 10; | 1218 mapping_string[mapping_pos++] = '0' + axis_moved / 10; |
1215 } | 1219 } |
1216 mapping_string[mapping_pos++] = '0' + axis_moved % 10; | 1220 mapping_string[mapping_pos++] = '0' + axis_moved % 10; |
1221 if (current_button >= SDL_CONTROLLER_BUTTON_DPAD_UP) { | |
1222 mapping_string[mapping_pos++] = axis_value >= 0 ? '+' : '-'; | |
1223 } | |
1217 last_axis = axis_moved; | 1224 last_axis = axis_moved; |
1225 last_axis_value = axis_value; | |
1218 } | 1226 } |
1219 added_mapping = 1; | 1227 added_mapping = 1; |
1220 } | 1228 } |
1221 } | 1229 } |
1222 | 1230 |
1293 button_pressed = -1; | 1301 button_pressed = -1; |
1294 last_button = -1; | 1302 last_button = -1; |
1295 last_hat = -1; | 1303 last_hat = -1; |
1296 axis_moved = -1; | 1304 axis_moved = -1; |
1297 last_axis = -1; | 1305 last_axis = -1; |
1306 last_axis_value = 0; | |
1298 SDL_Joystick *joy = render_get_joystick(selected_controller); | 1307 SDL_Joystick *joy = render_get_joystick(selected_controller); |
1299 const char *name = SDL_JoystickName(joy); | 1308 const char *name = SDL_JoystickName(joy); |
1300 size_t namesz = strlen(name); | 1309 size_t namesz = strlen(name); |
1301 mapping_string = malloc(512 + namesz); | 1310 mapping_string = malloc(512 + namesz); |
1302 for (mapping_pos = 0; mapping_pos < namesz; mapping_pos++) | 1311 for (mapping_pos = 0; mapping_pos < namesz; mapping_pos++) |