Skip to content

Commit

Permalink
Updated structure and field names for consistency
Browse files Browse the repository at this point in the history
Type names are camel case and field names are snake case except for fields ending in id, which are capitalized.

Fixes libsdl-org#6955
  • Loading branch information
slouken committed Feb 11, 2024
1 parent 6f87973 commit cacac6c
Show file tree
Hide file tree
Showing 74 changed files with 489 additions and 356 deletions.
119 changes: 109 additions & 10 deletions build-scripts/SDL_migration.cocci
Original file line number Diff line number Diff line change
Expand Up @@ -2413,50 +2413,90 @@ SDL_Event e1;
- e1.caxis
+ e1.gaxis
@@
SDL_Event *e1;
@@
- e1->caxis
+ e1->gaxis
@@
SDL_Event e1;
@@
- e1.cbutton
+ e1.gbutton
@@
SDL_Event *e1;
@@
- e1->cbutton
+ e1->gbutton
@@
SDL_Event e1;
@@
- e1.cdevice
+ e1.gdevice
@@
SDL_Event *e1;
@@
- e1->cdevice
+ e1->gdevice
@@
SDL_Event e1;
@@
- e1.ctouchpad
+ e1.gtouchpad
@@
SDL_Event *e1;
@@
- e1->ctouchpad
+ e1->gtouchpad
@@
SDL_Event e1;
@@
- e1.csensor
+ e1.gsensor
@@
SDL_Event *e1;
@@
- e1->caxis
+ e1->gaxis
- e1->csensor
+ e1->gsensor
@@
SDL_Event e1;
@@
- e1.wheel.mouseX
+ e1.wheel.mouse_x
@@
SDL_Event *e1;
@@
- e1->cbutton
+ e1->gbutton
- e1->wheel.mouseX
+ e1->wheel.mouse_x
@@
SDL_Event e1;
@@
- e1.wheel.mouseY
+ e1.wheel.mouse_y
@@
SDL_Event *e1;
@@
- e1->cdevice
+ e1->gdevice
- e1->wheel.mouseY
+ e1->wheel.mouse_y
@@
SDL_Event e1;
@@
- e1.tfinger.touchId
+ e1.tfinger.touchID
@@
SDL_Event *e1;
@@
- e1->ctouchpad
+ e1->gtouchpad
- e1->tfinger.touchId
+ e1->tfinger.touchID
@@
SDL_Event e1;
@@
- e1.tfinger.fingerId
+ e1.tfinger.fingerID
@@
SDL_Event *e1;
@@
- e1->csensor
+ e1->gsensor
- e1->tfinger.fingerId
+ e1->tfinger.fingerID
@@
expression e1, e2, e3, e4;
@@
Expand Down Expand Up @@ -2909,3 +2949,62 @@ expression e1, e2, e3, e4;
- SDL_HasWindowSurface
+ SDL_WindowHasSurface
(...)
@@
SDL_PixelFormat e1;
@@
- e1.BitsPerPixel
+ e1.bits_per_pixel
@@
SDL_PixelFormat *e1;
@@
- e1->BitsPerPixel
+ e1->bits_per_pixel
@@
SDL_PixelFormat e1;
@@
- e1.BytesPerPixel
+ e1.bytes_per_pixel
@@
SDL_PixelFormat *e1;
@@
- e1->BytesPerPixel
+ e1->bytes_per_pixel
@@
SDL_MessageBoxButtonData e1;
@@
- e1.buttonid
+ e1.buttonID
@@
SDL_MessageBoxButtonData *e1;
@@
- e1->buttonid
+ e1->buttonID
@@
SDL_GamepadBinding e1;
@@
- e1.inputType
+ e1.input_type
@@
SDL_GamepadBinding *e1;
@@
- e1->inputType
+ e1->input_type
@@
SDL_GamepadBinding e1;
@@
- e1.outputType
+ e1.output_type
@@
SDL_GamepadBinding *e1;
@@
- e1->outputType
+ e1->output_type
@@
@@
- SDL_version
+ SDL_Version
@@
typedef SDL_version, SDL_Version;
@@
- SDL_version
+ SDL_Version
15 changes: 15 additions & 0 deletions docs/README-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ The SDL_EVENT_WINDOW_SIZE_CHANGED event has been removed, and you can use SDL_EV
The gamepad event structures caxis, cbutton, cdevice, ctouchpad, and csensor have been renamed gaxis, gbutton, gdevice, gtouchpad, and gsensor.
The mouseX and mouseY fields of SDL_MouseWheelEvent have been renamed mouse_x and mouse_y.
The touchId and fingerId fields of SDL_TouchFingerEvent have been renamed touchID and fingerID.
SDL_QUERY, SDL_IGNORE, SDL_ENABLE, and SDL_DISABLE have been removed. You can use the functions SDL_SetEventEnabled() and SDL_EventEnabled() to set and query event processing state.
SDL_AddEventWatch() now returns -1 if it fails because it ran out of memory and couldn't add the event watch callback.
Expand Down Expand Up @@ -504,6 +508,8 @@ SDL_bool SDL_IsJoystickNVIDIASHIELDController(Uint16 vendor_id, Uint16 product_i
}
```
The inputType and outputType fields of SDL_GamepadBinding have been renamed input_type and output_type.
The following enums have been renamed:
* SDL_GameControllerAxis => SDL_GamepadAxis
* SDL_GameControllerBindType => SDL_GamepadBindingType
Expand Down Expand Up @@ -871,6 +877,10 @@ Several platform-specific entry point functions have been removed as unnecessary
#define SDL_GDKRunApp(MAIN_FUNC, RESERVED) SDL_RunApp(0, NULL, MAIN_FUNC, RESERVED)
```
## SDL_messagebox.h
The buttonid field of SDL_MessageBoxButtonData has been renamed buttonID.
## SDL_metal.h
SDL_Metal_GetDrawableSize() has been removed. SDL_GetWindowSizeInPixels() can be used in its place.
Expand Down Expand Up @@ -912,6 +922,8 @@ The following symbols have been renamed:
SDL_CalculateGammaRamp has been removed, because SDL_SetWindowGammaRamp has been removed as well due to poor support in modern operating systems (see [SDL_video.h](#sdl_videoh)).
The BitsPerPixel and BytesPerPixel fields of SDL_PixelFormat have been renamed bits_per_pixel and bytes_per_pixel.
The following functions have been renamed:
* SDL_AllocFormat() => SDL_CreatePixelFormat()
* SDL_AllocPalette() => SDL_CreatePalette()
Expand Down Expand Up @@ -1528,6 +1540,9 @@ The following functions have been removed:
SDL_GetRevisionNumber() has been removed from the API, it always returned 0 in SDL 2.0.
The following structures have been renamed:
* SDL_version => SDL_Version
## SDL_video.h
Several video backends have had their names lower-cased ("kmsdrm", "rpi", "android", "psp", "ps2", "vita"). SDL already does a case-insensitive compare for SDL_HINT_VIDEO_DRIVER tests, but if your app is calling SDL_GetVideoDriver() or SDL_GetCurrentVideoDriver() and doing case-sensitive compares on those strings, please update your code.
Expand Down
8 changes: 4 additions & 4 deletions include/SDL3/SDL_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ typedef struct SDL_MouseWheelEvent
float x; /**< The amount scrolled horizontally, positive to the right and negative to the left */
float y; /**< The amount scrolled vertically, positive away from the user and negative toward the user */
Uint32 direction; /**< Set to one of the SDL_MOUSEWHEEL_* defines. When FLIPPED the values in X and Y will be opposite. Multiply by -1 to change them back */
float mouseX; /**< X coordinate, relative to window */
float mouseY; /**< Y coordinate, relative to window */
float mouse_x; /**< X coordinate, relative to window */
float mouse_y; /**< Y coordinate, relative to window */
} SDL_MouseWheelEvent;

/**
Expand Down Expand Up @@ -535,8 +535,8 @@ typedef struct SDL_TouchFingerEvent
Uint32 type; /**< ::SDL_EVENT_FINGER_MOTION or ::SDL_EVENT_FINGER_DOWN or ::SDL_EVENT_FINGER_UP */
Uint32 reserved;
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
SDL_TouchID touchId; /**< The touch device id */
SDL_FingerID fingerId;
SDL_TouchID touchID; /**< The touch device id */
SDL_FingerID fingerID;
float x; /**< Normalized in the range 0...1 */
float y; /**< Normalized in the range 0...1 */
float dx; /**< Normalized in the range -1...1 */
Expand Down
6 changes: 3 additions & 3 deletions include/SDL3/SDL_gamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ typedef enum
SDL_GAMEPAD_BINDTYPE_HAT
} SDL_GamepadBindingType;

typedef struct
typedef struct SDL_GamepadBinding
{
SDL_GamepadBindingType inputType;
SDL_GamepadBindingType input_type;
union
{
int button;
Expand All @@ -200,7 +200,7 @@ typedef struct

} input;

SDL_GamepadBindingType outputType;
SDL_GamepadBindingType output_type;
union
{
SDL_GamepadButton button;
Expand Down
4 changes: 2 additions & 2 deletions include/SDL3/SDL_messagebox.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ typedef enum
typedef struct
{
Uint32 flags; /**< ::SDL_MessageBoxButtonFlags */
int buttonid; /**< User defined button id (value returned via SDL_ShowMessageBox) */
const char * text; /**< The UTF-8 button text */
int buttonID; /**< User defined button id (value returned via SDL_ShowMessageBox) */
const char *text; /**< The UTF-8 button text */
} SDL_MessageBoxButtonData;

/**
Expand Down
6 changes: 6 additions & 0 deletions include/SDL3/SDL_oldnames.h
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,9 @@
/* ##SDL_timer.h */
#define SDL_GetTicks64 SDL_GetTicks

/* ##SDL_version.h */
#define SDL_version SDL_Version

/* ##SDL_video.h */
#define SDL_GetClosestDisplayMode SDL_GetClosestFullscreenDisplayMode
#define SDL_GetDisplayOrientation SDL_GetCurrentDisplayOrientation
Expand Down Expand Up @@ -961,6 +964,9 @@
/* ##SDL_timer.h */
#define SDL_GetTicks64 SDL_GetTicks64_renamed_SDL_GetTicks

/* ##SDL_version.h */
#define SDL_version SDL_version_renamed_SDL_Version

/* ##SDL_video.h */
#define SDL_GetClosestDisplayMode SDL_GetClosestDisplayMode_renamed_SDL_GetClosestFullscreenDisplayMode
#define SDL_GetDisplayOrientation SDL_GetDisplayOrientation_renamed_SDL_GetCurrentDisplayOrientation
Expand Down
4 changes: 2 additions & 2 deletions include/SDL3/SDL_pixels.h
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,8 @@ typedef struct SDL_PixelFormat
{
Uint32 format;
SDL_Palette *palette;
Uint8 BitsPerPixel;
Uint8 BytesPerPixel;
Uint8 bits_per_pixel;
Uint8 bytes_per_pixel;
Uint8 padding[2];
Uint32 Rmask;
Uint32 Gmask;
Expand Down
14 changes: 7 additions & 7 deletions include/SDL3/SDL_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ extern "C" {
* \sa SDL_VERSION
* \sa SDL_GetVersion
*/
typedef struct SDL_version
typedef struct SDL_Version
{
Uint8 major; /**< major version */
Uint8 minor; /**< minor version */
Uint8 patch; /**< update version */
} SDL_version;
} SDL_Version;

/* Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
*/
Expand All @@ -64,16 +64,16 @@ typedef struct SDL_version
/**
* Macro to determine SDL version program was compiled against.
*
* This macro fills in a SDL_version structure with the version of the
* This macro fills in an SDL_Version structure with the version of the
* library you compiled against. This is determined by what header the
* compiler uses. Note that if you dynamically linked the library, you might
* have a slightly newer or older version at runtime. That version can be
* determined with SDL_GetVersion(), which, unlike SDL_VERSION(),
* is not a macro.
*
* \param x A pointer to a SDL_version struct to initialize.
* \param x A pointer to an SDL_Version struct to initialize.
*
* \sa SDL_version
* \sa SDL_Version
* \sa SDL_GetVersion
*/
#define SDL_VERSION(x) \
Expand Down Expand Up @@ -114,15 +114,15 @@ typedef struct SDL_version
*
* This function may be called safely at any time, even before SDL_Init().
*
* \param ver the SDL_version structure that contains the version information
* \param ver the SDL_Version structure that contains the version information
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetRevision
*/
extern DECLSPEC int SDLCALL SDL_GetVersion(SDL_version * ver);
extern DECLSPEC int SDLCALL SDL_GetVersion(SDL_Version * ver);

/**
* Get the code revision of SDL that is linked against your program.
Expand Down
6 changes: 3 additions & 3 deletions src/SDL.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ SDL_COMPILE_TIME_ASSERT(SDL_BUILD_MICRO_VERSION,
#endif

SDL_COMPILE_TIME_ASSERT(SDL_MAJOR_VERSION_min, SDL_MAJOR_VERSION >= 0);
/* Limited only by the need to fit in SDL_version */
/* Limited only by the need to fit in SDL_Version */
SDL_COMPILE_TIME_ASSERT(SDL_MAJOR_VERSION_max, SDL_MAJOR_VERSION <= 255);

SDL_COMPILE_TIME_ASSERT(SDL_MINOR_VERSION_min, SDL_MINOR_VERSION >= 0);
/* Limited only by the need to fit in SDL_version */
/* Limited only by the need to fit in SDL_Version */
SDL_COMPILE_TIME_ASSERT(SDL_MINOR_VERSION_max, SDL_MINOR_VERSION <= 255);

SDL_COMPILE_TIME_ASSERT(SDL_PATCHLEVEL_min, SDL_PATCHLEVEL >= 0);
Expand Down Expand Up @@ -534,7 +534,7 @@ Uint32 SDL_GetNextObjectID(void)
}

/* Get the library version number */
int SDL_GetVersion(SDL_version *ver)
int SDL_GetVersion(SDL_Version *ver)
{
static SDL_bool check_hint = SDL_TRUE;
static SDL_bool legacy_version = SDL_FALSE;
Expand Down
4 changes: 2 additions & 2 deletions src/SDL_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@
#endif

/* Optimized functions from 'SDL_blit_0.c'
- blit with source BitsPerPixel < 8, palette */
- blit with source bits_per_pixel < 8, palette */
#ifndef SDL_HAVE_BLIT_0
#define SDL_HAVE_BLIT_0 !SDL_LEAN_AND_MEAN
#endif

/* Optimized functions from 'SDL_blit_1.c'
- blit with source BytesPerPixel == 1, palette */
- blit with source bytes_per_pixel == 1, palette */
#ifndef SDL_HAVE_BLIT_1
#define SDL_HAVE_BLIT_1 !SDL_LEAN_AND_MEAN
#endif
Expand Down
Loading

0 comments on commit cacac6c

Please sign in to comment.