Skip to content

Commit 660c851

Browse files
authored
Merge pull request #2838 from Starbuck5/more-simple-sdl3-patches
Simple SDL3 patches for freetype, surface, mouse
2 parents aa1363e + f0e59d7 commit 660c851

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

src_c/_freetype.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,10 +757,10 @@ _ftfont_init(pgFontObject *self, PyObject *args, PyObject *kwds)
757757
goto end;
758758
}
759759

760-
if (source->size(source) <= 0) {
760+
if (SDL_RWsize(source) <= 0) {
761761
PyErr_Format(PyExc_ValueError,
762762
"Font file object has an invalid file size: %lld",
763-
source->size(source));
763+
SDL_RWsize(source));
764764
goto end;
765765
}
766766

src_c/_pygame.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ PG_UnlockMutex(SDL_mutex *mutex)
9898
#define PG_FORMAT_BitsPerPixel(format) format->bits_per_pixel
9999
#define PG_FORMAT_BytesPerPixel(format) format->bytes_per_pixel
100100

101+
/* Mask to test if surface flags are in a fullscreen window. */
102+
#define PG_WINDOW_FULLSCREEN_INCLUSIVE SDL_WINDOW_FULLSCREEN
103+
101104
#else /* ~SDL_VERSION_ATLEAST(3, 0, 0)*/
102105
#define PG_ShowCursor() SDL_ShowCursor(SDL_ENABLE)
103106
#define PG_HideCursor() SDL_ShowCursor(SDL_DISABLE)
@@ -147,6 +150,11 @@ PG_UnlockMutex(SDL_mutex *mutex)
147150
#define PG_FORMAT_BitsPerPixel(format) format->BitsPerPixel
148151
#define PG_FORMAT_BytesPerPixel(format) format->BytesPerPixel
149152

153+
/* Mask to test if surface flags are in a fullscreen window.
154+
* SDL_WINDOW_FULLSCREEN_DESKTOP works here because it also contains
155+
* SDL_WINDOW_FULLSCREEN. */
156+
#define PG_WINDOW_FULLSCREEN_INCLUSIVE SDL_WINDOW_FULLSCREEN_DESKTOP
157+
150158
#if SDL_VERSION_ATLEAST(2, 0, 14)
151159
#define PG_SurfaceHasRLE SDL_HasSurfaceRLE
152160
#else

src_c/freetype/ft_render.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,11 @@ _PGFT_Render_Array(FreeTypeInstance *ft, pgFontObject *fontobj,
695695
/*
696696
* Setup target surface struct
697697
*/
698+
#if SDL_VERSION_ATLEAST(3, 0, 0)
699+
format.bytes_per_pixel = itemsize;
700+
#else
698701
format.BytesPerPixel = itemsize;
702+
#endif
699703
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
700704
format.Ashift = _is_swapped(view_p) ? (itemsize - 1) * 8 : 0;
701705
#else

src_c/mouse.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ mouse_set_visible(PyObject *self, PyObject *args)
183183
SDL_SetRelativeMouseMode(0);
184184
}
185185
window_flags = SDL_GetWindowFlags(win);
186-
if (!toggle && (window_flags & SDL_WINDOW_FULLSCREEN_DESKTOP ||
187-
window_flags & SDL_WINDOW_FULLSCREEN)) {
186+
if (!toggle && (window_flags & PG_WINDOW_FULLSCREEN_INCLUSIVE)) {
188187
SDL_SetHint(SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN, "0");
189188
}
190189
else {

src_c/surface.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,11 @@ surface_init(pgSurfaceObject *self, PyObject *args, PyObject *kwds)
640640
pix = pgSurface_AsSurface(pg_GetDefaultWindowSurface())->format;
641641
else {
642642
pix = &default_format;
643+
#if SDL_VERSION_ATLEAST(3, 0, 0)
644+
pix->bits_per_pixel = 32;
645+
#else
643646
pix->BitsPerPixel = 32;
647+
#endif
644648
pix->Amask = 0;
645649
pix->Rmask = 0xFF0000;
646650
pix->Gmask = 0xFF00;
@@ -1534,9 +1538,14 @@ surf_convert(pgSurfaceObject *self, PyObject *args)
15341538
PyExc_ValueError,
15351539
"invalid argument specifying new format to convert to");
15361540
}
1541+
#if SDL_VERSION_ATLEAST(3, 0, 0)
1542+
format.bits_per_pixel = (Uint8)bpp;
1543+
format.bytes_per_pixel = (bpp + 7) / 8;
1544+
#else
15371545
format.BitsPerPixel = (Uint8)bpp;
15381546
format.BytesPerPixel = (bpp + 7) / 8;
1539-
if (format.BitsPerPixel > 8)
1547+
#endif
1548+
if (PG_FORMAT_BitsPerPixel((&format)) > 8)
15401549
/* Allow a 8 bit source surface with an empty palette to be
15411550
* converted to a format without a palette (pygame-ce issue
15421551
* #146). If the target format has a non-NULL palette pointer
@@ -1545,8 +1554,8 @@ surf_convert(pgSurfaceObject *self, PyObject *args)
15451554
*/
15461555
format.palette = NULL;
15471556
if (SDL_ISPIXELFORMAT_INDEXED(SDL_MasksToPixelFormatEnum(
1548-
format.BitsPerPixel, format.Rmask, format.Gmask,
1549-
format.Bmask, format.Amask))) {
1557+
PG_FORMAT_BitsPerPixel((&format)), format.Rmask,
1558+
format.Gmask, format.Bmask, format.Amask))) {
15501559
if (SDL_ISPIXELFORMAT_INDEXED(surf->format->format)) {
15511560
SDL_SetPixelFormatPalette(&format, surf->format->palette);
15521561
}
@@ -2434,8 +2443,7 @@ surf_get_flags(PyObject *self, PyObject *_null)
24342443
if ((sdl_flags & SDL_RLEACCEL))
24352444
flags |= PGS_RLEACCEL;
24362445
if (is_window_surf) {
2437-
if (window_flags & SDL_WINDOW_FULLSCREEN_DESKTOP ||
2438-
window_flags & SDL_WINDOW_FULLSCREEN)
2446+
if (window_flags & PG_WINDOW_FULLSCREEN_INCLUSIVE)
24392447
flags |= PGS_FULLSCREEN;
24402448
if (window_flags & SDL_WINDOW_OPENGL)
24412449
flags |= PGS_OPENGL;

0 commit comments

Comments
 (0)