Split controller axes into positive and negative sides so each can be bound independently.

Using this a D-Pad can be mapped to a thumbstick and vice versa.
Also added support for inverted axes, improving trigger binding support
This commit is contained in:
Sam Lantinga 2016-12-27 01:39:07 -08:00
parent 8f0a0028e6
commit c6e0424049
7 changed files with 609 additions and 340 deletions

View file

@ -53,12 +53,12 @@ static const struct { int x; int y; } button_positions[] = {
/* This is indexed by SDL_GameControllerAxis. */
static const struct { int x; int y; double angle; } axis_positions[] = {
{75, 154, 0.0}, /* LEFTX */
{75, 154, 90.0}, /* LEFTY */
{305, 230, 0.0}, /* RIGHTX */
{305, 230, 90.0}, /* RIGHTY */
{91, 0, 90.0}, /* TRIGGERLEFT */
{375, 0, 90.0}, /* TRIGGERRIGHT */
{74, 153, 270.0}, /* LEFTX */
{74, 153, 0.0}, /* LEFTY */
{306, 231, 270.0}, /* RIGHTX */
{306, 231, 0.0}, /* RIGHTY */
{91, -20, 0.0}, /* TRIGGERLEFT */
{375, -20, 0.0}, /* TRIGGERRIGHT */
};
SDL_Renderer *screen = NULL;
@ -80,10 +80,6 @@ LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
if (transparent) {
if (temp->format->BytesPerPixel == 1) {
SDL_SetColorKey(temp, SDL_TRUE, *(Uint8 *)temp->pixels);
} else {
SDL_assert(!temp->format->palette);
SDL_assert(temp->format->BitsPerPixel == 24);
SDL_SetColorKey(temp, SDL_TRUE, (*(Uint32 *)temp->pixels) & 0x00FFFFFF);
}
}
@ -112,6 +108,13 @@ loop(void *arg)
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_CONTROLLERAXISMOTION:
SDL_Log("Controller axis %s changed to %d\n", SDL_GameControllerGetStringForAxis(event.caxis.axis), event.caxis.value);
break;
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
SDL_Log("Controller button %s %s\n", SDL_GameControllerGetStringForButton(event.cbutton.button), event.cbutton.state ? "pressed" : "released");
break;
case SDL_KEYDOWN:
if (event.key.keysym.sym != SDLK_ESCAPE) {
break;