Skip to content

Commit

Permalink
Support multiple joystick buttons bound to the same gamepad button
Browse files Browse the repository at this point in the history
(cherry picked from commit ed94331)
(cherry picked from commit 74ff82f)
  • Loading branch information
slouken committed Nov 5, 2024
1 parent 9eca707 commit ad60292
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/joystick/SDL_gamecontroller.c
Original file line number Diff line number Diff line change
Expand Up @@ -2364,23 +2364,19 @@ Uint8 SDL_GameControllerGetButton(SDL_GameController *gamecontroller, SDL_GameCo
if (binding->input.axis.axis_min < binding->input.axis.axis_max) {
valid_input_range = (value >= binding->input.axis.axis_min && value <= binding->input.axis.axis_max);
if (valid_input_range) {
retval = (value >= threshold) ? SDL_PRESSED : SDL_RELEASED;
break;
retval |= (value >= threshold) ? SDL_PRESSED : SDL_RELEASED;
}
} else {
valid_input_range = (value >= binding->input.axis.axis_max && value <= binding->input.axis.axis_min);
if (valid_input_range) {
retval = (value <= threshold) ? SDL_PRESSED : SDL_RELEASED;
break;
retval |= (value <= threshold) ? SDL_PRESSED : SDL_RELEASED;
}
}
} else if (binding->inputType == SDL_CONTROLLER_BINDTYPE_BUTTON) {
retval = SDL_JoystickGetButton(gamecontroller->joystick, binding->input.button);
break;
retval |= SDL_JoystickGetButton(gamecontroller->joystick, binding->input.button);
} else if (binding->inputType == SDL_CONTROLLER_BINDTYPE_HAT) {
int hat_mask = SDL_JoystickGetHat(gamecontroller->joystick, binding->input.hat.hat);
retval = (hat_mask & binding->input.hat.hat_mask) ? SDL_PRESSED : SDL_RELEASED;
break;
retval |= (hat_mask & binding->input.hat.hat_mask) ? SDL_PRESSED : SDL_RELEASED;
}
}
}
Expand Down

0 comments on commit ad60292

Please sign in to comment.