Use SDL_bool where appropriate in SDL events

This involved changing button state from Uint8 to SDL_bool, and made SDL_PRESSED and SDL_RELEASED unnecessary.

Fixes https://github.com/libsdl-org/SDL/issues/10069
This commit is contained in:
Sam Lantinga
2024-09-09 09:18:02 -07:00
parent 7d1bbae6b2
commit 6fc6e3dc7e
89 changed files with 935 additions and 956 deletions

View File

@@ -52,25 +52,6 @@ extern "C" {
/* General keyboard/mouse/pen state definitions */
/**
* A value that signifies a button is no longer pressed.
*
* \since This macro is available since SDL 3.0.0.
*
* \sa SDL_PRESSED
*/
#define SDL_RELEASED 0
/**
* A value that signifies a button has been pressed down.
*
* \since This macro is available since SDL 3.0.0.
*
* \sa SDL_RELEASED
*/
#define SDL_PRESSED 1
/**
* The types of events that can be delivered.
*
@@ -346,8 +327,8 @@ typedef struct SDL_KeyboardEvent
SDL_Keycode key; /**< SDL virtual key code */
SDL_Keymod mod; /**< current key modifiers */
Uint16 raw; /**< The platform dependent scancode for this event */
Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */
Uint8 repeat; /**< Non-zero if this is a key repeat */
SDL_bool down; /**< SDL_TRUE if the key is pressed */
SDL_bool repeat; /**< SDL_TRUE if this is a key repeat */
} SDL_KeyboardEvent;
/**
@@ -455,7 +436,7 @@ typedef struct SDL_MouseButtonEvent
SDL_WindowID windowID; /**< The window with mouse focus, if any */
SDL_MouseID which; /**< The mouse instance id, SDL_TOUCH_MOUSEID */
Uint8 button; /**< The mouse button index */
Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */
SDL_bool down; /**< SDL_TRUE if the button is pressed */
Uint8 clicks; /**< 1 for single-click, 2 for double-click, etc. */
Uint8 padding;
float x; /**< X coordinate, relative to window */
@@ -554,7 +535,7 @@ typedef struct SDL_JoyButtonEvent
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
SDL_JoystickID which; /**< The joystick instance id */
Uint8 button; /**< The joystick button index */
Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */
SDL_bool down; /**< SDL_TRUE if the button is pressed */
Uint8 padding1;
Uint8 padding2;
} SDL_JoyButtonEvent;
@@ -619,7 +600,7 @@ typedef struct SDL_GamepadButtonEvent
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
SDL_JoystickID which; /**< The joystick instance id */
Uint8 button; /**< The gamepad button (SDL_GamepadButton) */
Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */
SDL_bool down; /**< SDL_TRUE if the button is pressed */
Uint8 padding1;
Uint8 padding2;
} SDL_GamepadButtonEvent;
@@ -683,7 +664,7 @@ typedef struct SDL_AudioDeviceEvent
Uint32 reserved;
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
SDL_AudioDeviceID which; /**< SDL_AudioDeviceID for the device being added or removed or changing */
Uint8 recording; /**< zero if a playback device, non-zero if a recording device. */
SDL_bool recording; /**< SDL_FALSE if a playback device, SDL_TRUE if a recording device. */
Uint8 padding1;
Uint8 padding2;
Uint8 padding3;
@@ -787,8 +768,8 @@ typedef struct SDL_PenTouchEvent
SDL_PenInputFlags pen_state; /**< Complete pen input state at time of event */
float x; /**< X position of pen on tablet */
float y; /**< Y position of pen on tablet */
Uint8 eraser; /**< Non-zero if eraser end is used (not all pens support this). */
Uint8 state; /**< SDL_PRESSED (pen is touching) or SDL_RELEASED (pen is lifted off) */
SDL_bool eraser; /**< SDL_TRUE if eraser end is used (not all pens support this). */
SDL_bool down; /**< SDL_TRUE if the pen is touching or SDL_FALSE if the pen is lifted off */
} SDL_PenTouchEvent;
/**
@@ -810,7 +791,7 @@ typedef struct SDL_PenButtonEvent
float x; /**< X position of pen on tablet */
float y; /**< Y position of pen on tablet */
Uint8 button; /**< The pen button index (first button is 1). */
Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */
SDL_bool down; /**< SDL_TRUE if the button is pressed */
} SDL_PenButtonEvent;
/**

View File

@@ -1184,15 +1184,14 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadHasButton(SDL_Gamepad *gamepad,
*
* \param gamepad a gamepad.
* \param button a button index (one of the SDL_GamepadButton values).
* \returns 1 for pressed state or 0 for not pressed state or failure; call
* SDL_GetError() for more information.
* \returns SDL_TRUE if the button is pressed, SDL_FALSE otherwise.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GamepadHasButton
* \sa SDL_GetGamepadAxis
*/
extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
/**
* Get the label of a button on a gamepad.
@@ -1253,12 +1252,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpadFingers(SDL_Gamepad *ga
* \param gamepad a gamepad.
* \param touchpad a touchpad.
* \param finger a finger.
* \param state filled with state.
* \param x filled with x position, normalized 0 to 1, with the origin in the
* upper left.
* \param y filled with y position, normalized 0 to 1, with the origin in the
* upper left.
* \param pressure filled with pressure value.
* \param down a pointer filled with SDL_TRUE if the finger is down, SDL_FALSE otherwise, may be NULL.
* \param x a pointer filled with the x position, normalized 0 to 1, with the origin in the
* upper left, may be NULL.
* \param y a pointer filled with the y position, normalized 0 to 1, with the origin in the
* upper left, may be NULL.
* \param pressure a pointer filled with pressure value, may be NULL.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
*
@@ -1266,7 +1265,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpadFingers(SDL_Gamepad *ga
*
* \sa SDL_GetNumGamepadTouchpadFingers
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure);
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, SDL_bool *down, float *x, float *y, float *pressure);
/**
* Return whether a gamepad has a particular sensor.

View File

@@ -558,13 +558,13 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualBall(SDL_Joystick *jo
*
* \param joystick the virtual joystick on which to set state.
* \param button the index of the button on the virtual joystick to update.
* \param value the new value for the specified button.
* \param down SDL_TRUE if the button is pressed, SDL_FALSE otherwise.
* \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
* for more information.
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, Uint8 value);
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, SDL_bool down);
/**
* Set the state of a hat on an opened virtual joystick.
@@ -598,7 +598,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualHat(SDL_Joystick *joy
* \param touchpad the index of the touchpad on the virtual joystick to
* update.
* \param finger the index of the finger on the touchpad to set.
* \param state `SDL_PRESSED` if the finger is pressed, `SDL_RELEASED` if the
* \param down SDL_TRUE if the finger is pressed, SDL_FALSE if the
* finger is released.
* \param x the x coordinate of the finger on the touchpad, normalized 0 to 1,
* with the origin in the upper left.
@@ -610,7 +610,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualHat(SDL_Joystick *joy
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualTouchpad(SDL_Joystick *joystick, int touchpad, int finger, Uint8 state, float x, float y, float pressure);
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualTouchpad(SDL_Joystick *joystick, int touchpad, int finger, SDL_bool down, float x, float y, float pressure);
/**
* Send a sensor update for an opened virtual joystick.
@@ -1065,13 +1065,13 @@ extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetJoystickHat(SDL_Joystick *joystick, int
* \param joystick an SDL_Joystick structure containing joystick information.
* \param button the button index to get the state from; indices start at
* index 0.
* \returns 1 if the specified button is pressed, 0 otherwise.
* \returns SDL_TRUE if the button is pressed, SDL_FALSE otherwise.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetNumJoystickButtons
*/
extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetJoystickButton(SDL_Joystick *joystick, int button);
extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetJoystickButton(SDL_Joystick *joystick, int button);
/**
* Start a rumble effect.

View File

@@ -119,8 +119,8 @@ extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_GetKeyboardFocus(void);
* valid for the whole lifetime of the application and should not be freed by
* the caller.
*
* A array element with a value of 1 means that the key is pressed and a value
* of 0 means that it is not. Indexes into this array are obtained by using
* A array element with a value of SDL_TRUE means that the key is pressed and a value
* of SDL_FALSE means that it is not. Indexes into this array are obtained by using
* SDL_Scancode values.
*
* Use SDL_PumpEvents() to update the state array.
@@ -141,7 +141,7 @@ extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_GetKeyboardFocus(void);
* \sa SDL_PumpEvents
* \sa SDL_ResetKeyboard
*/
extern SDL_DECLSPEC const Uint8 * SDLCALL SDL_GetKeyboardState(int *numkeys);
extern SDL_DECLSPEC const SDL_bool * SDLCALL SDL_GetKeyboardState(int *numkeys);
/**
* Clear the state of the keyboard.