Skip to content

Commit 881a962

Browse files
committed
Port SDL_FillRect SDL3
1 parent ac09c5b commit 881a962

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src_c/_pygame.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ PG_GetSurfaceFormat(SDL_Surface *surf)
136136
#define PG_GetSurfaceBlendMode SDL_GetSurfaceBlendMode
137137
#define PG_GetSurfaceAlphaMod SDL_GetSurfaceAlphaMod
138138
#define PG_SetSurfaceAlphaMod SDL_SetSurfaceAlphaMod
139+
#define PG_FillSurfaceRect SDL_FillSurfaceRect
139140

140141
#define PG_GetRGBA SDL_GetRGBA
141142
#define PG_GetRGB SDL_GetRGB
@@ -269,6 +270,12 @@ PG_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha)
269270
return SDL_SetSurfaceAlphaMod(surface, alpha) == 0;
270271
}
271272

273+
static inline bool
274+
PG_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color)
275+
{
276+
return SDL_FillRect(dst, rect, color) == 0;
277+
}
278+
272279
// NOTE:
273280
// palette is part of the format in SDL2, so these functions below have it
274281
// as a separate parameter to be consistent with the SDL3 signature.

src_c/draw.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,6 @@ rect(PyObject *self, PyObject *args, PyObject *kwargs)
11781178
int top_left_radius = -1, top_right_radius = -1, bottom_left_radius = -1,
11791179
bottom_right_radius = -1;
11801180
SDL_Rect sdlrect;
1181-
int result;
11821181
SDL_Rect clipped;
11831182
int drawn_area[4] = {INT_MAX, INT_MAX, INT_MIN,
11841183
INT_MIN}; /* Used to store bounding box values */
@@ -1248,10 +1247,10 @@ rect(PyObject *self, PyObject *args, PyObject *kwargs)
12481247
else {
12491248
pgSurface_Prep(surfobj);
12501249
pgSurface_Lock(surfobj);
1251-
result = SDL_FillRect(surf, &clipped, color);
1250+
bool success = PG_FillSurfaceRect(surf, &clipped, color);
12521251
pgSurface_Unlock(surfobj);
12531252
pgSurface_Unprep(surfobj);
1254-
if (result != 0) {
1253+
if (!success) {
12551254
return RAISE(pgExc_SDLError, SDL_GetError());
12561255
}
12571256
}

src_c/surface.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,7 +2198,7 @@ surf_fill(pgSurfaceObject *self, PyObject *args, PyObject *keywds)
21982198
else {
21992199
pgSurface_Prep(self);
22002200
pgSurface_Lock((pgSurfaceObject *)self);
2201-
result = SDL_FillRect(surf, &sdlrect, color);
2201+
result = PG_FillSurfaceRect(surf, &sdlrect, color) - 1;
22022202
pgSurface_Unlock((pgSurfaceObject *)self);
22032203
pgSurface_Unprep(self);
22042204
}
@@ -2938,7 +2938,7 @@ surf_scroll(PyObject *self, PyObject *args, PyObject *keywds)
29382938
if (!repeat) {
29392939
if (dx >= w || dx <= -w || dy >= h || dy <= -h) {
29402940
if (erase) {
2941-
if (SDL_FillRect(surf, NULL, 0) == -1) {
2941+
if (!PG_FillSurfaceRect(surf, NULL, 0)) {
29422942
PyErr_SetString(pgExc_SDLError, SDL_GetError());
29432943
return NULL;
29442944
}

0 commit comments

Comments
 (0)