1 #pragma once
2 // Backports for older versions of SDL 2.
3 
4 #include <SDL.h>
5 
6 #ifndef SDL_MAX_UINT32
7 #define SDL_MAX_UINT32 ((Uint32)0xFFFFFFFFu)
8 #endif
9 
10 #if !SDL_VERSION_ATLEAST(2, 0, 4)
SDL_PointInRect(const SDL_Point * p,const SDL_Rect * r)11 inline SDL_bool SDL_PointInRect(const SDL_Point *p, const SDL_Rect *r)
12 {
13     return ( (p->x >= r->x) && (p->x < (r->x + r->w)) &&
14              (p->y >= r->y) && (p->y < (r->y + r->h)) ) ? SDL_TRUE : SDL_FALSE;
15 }
16 #endif
17 
18 #if !SDL_VERSION_ATLEAST(2, 0, 5)
19 inline SDL_Surface *
SDL_CreateRGBSurfaceWithFormat(Uint32 flags,int width,int height,int depth,Uint32 format)20 SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth,
21     Uint32 format)
22 {
23 	int bpp;
24 	Uint32 rmask, gmask, bmask, amask;
25 	if (!SDL_PixelFormatEnumToMasks(format, &bpp, &rmask, &gmask, &bmask, &amask))
26 		return NULL;
27 	return SDL_CreateRGBSurface(flags, width, height, bpp, rmask, gmask, bmask, amask);
28 }
29 
30 // From SDL 2.0.9.
31 inline SDL_Surface *
SDL_CreateRGBSurfaceWithFormatFrom(void * pixels,int width,int height,int depth,int pitch,Uint32 format)32 SDL_CreateRGBSurfaceWithFormatFrom(void *pixels,
33     int width, int height, int depth, int pitch,
34     Uint32 format)
35 {
36 	SDL_Surface *surface;
37 
38 	surface = SDL_CreateRGBSurfaceWithFormat(0, 0, 0, depth, format);
39 	if (surface != NULL) {
40 		surface->flags |= SDL_PREALLOC;
41 		surface->pixels = pixels;
42 		surface->w = width;
43 		surface->h = height;
44 		surface->pitch = pitch;
45 		SDL_SetClipRect(surface, NULL);
46 	}
47 	return surface;
48 }
49 #endif
50