Fixed centering the D-pad on some joysticks

Fixes https://github.com/libsdl-org/SDL/issues/6767
This commit is contained in:
Sam Lantinga 2022-12-05 13:36:51 -08:00
parent bcccbbd894
commit d1b4810542

View file

@ -1454,6 +1454,7 @@ static void RAWINPUT_HandleStatePacket(SDL_Joystick *joystick, Uint8 *data, int
for (i = 0; i < nhats; ++i) {
HIDP_DATA *item = GetData(ctx->hat_indices[i], ctx->data, data_length);
if (item) {
Uint8 hat = SDL_HAT_CENTERED;
const Uint8 hat_states[] = {
SDL_HAT_CENTERED,
SDL_HAT_UP,
@ -1464,6 +1465,7 @@ static void RAWINPUT_HandleStatePacket(SDL_Joystick *joystick, Uint8 *data, int
SDL_HAT_DOWN | SDL_HAT_LEFT,
SDL_HAT_LEFT,
SDL_HAT_UP | SDL_HAT_LEFT,
SDL_HAT_CENTERED,
};
ULONG state = item->RawValue;
@ -1471,8 +1473,9 @@ static void RAWINPUT_HandleStatePacket(SDL_Joystick *joystick, Uint8 *data, int
#ifdef SDL_JOYSTICK_RAWINPUT_MATCHING
match_state = (match_state & ~HAT_MASK) | hat_map[state];
#endif
SDL_PrivateJoystickHat(joystick, i, hat_states[state]);
hat = hat_states[state];
}
SDL_PrivateJoystickHat(joystick, i, hat);
}
}