@@ -39,6 +39,8 @@ __M_BEGIN_DECLS
39
39
#endif
40
40
#endif
41
41
42
+ #include <limits.h>
43
+
42
44
/* SDL1 backwards compatibility for SDL2 ************************************/
43
45
44
46
#if !SDL_VERSION_ATLEAST (2 ,0 ,0 )
@@ -242,8 +244,8 @@ typedef SDL_GameControllerButton SDL_GamepadButton;
242
244
#define SDL_GAMEPAD_BUTTON_BACK SDL_CONTROLLER_BUTTON_BACK
243
245
#define SDL_GAMEPAD_BUTTON_GUIDE SDL_CONTROLLER_BUTTON_GUIDE
244
246
#define SDL_GAMEPAD_BUTTON_START SDL_CONTROLLER_BUTTON_START
245
- #define SDL_GAMEPAD_BUTTON_LEFT_STICK SDL_CONTROLLER_BUTTON_LEFT_STICK
246
- #define SDL_GAMEPAD_BUTTON_RIGHT_STICK SDL_CONTROLLER_BUTTON_RIGHT_STICK
247
+ #define SDL_GAMEPAD_BUTTON_LEFT_STICK SDL_CONTROLLER_BUTTON_LEFTSTICK
248
+ #define SDL_GAMEPAD_BUTTON_RIGHT_STICK SDL_CONTROLLER_BUTTON_RIGHTSTICK
247
249
#define SDL_GAMEPAD_BUTTON_LEFT_SHOULDER SDL_CONTROLLER_BUTTON_LEFTSHOULDER
248
250
#define SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER SDL_CONTROLLER_BUTTON_RIGHTSHOULDER
249
251
#define SDL_GAMEPAD_BUTTON_DPAD_UP SDL_CONTROLLER_BUTTON_DPAD_UP
@@ -308,23 +310,70 @@ static inline void SDL_SetJoystickEventsEnabled(SDL_bool enabled)
308
310
#define SDL_DestroyPalette (p ) SDL_FreePalette(p)
309
311
#define SDL_CreatePixelFormat (f ) SDL_AllocFormat(f)
310
312
#define SDL_DestroyPixelFormat (pf ) SDL_FreeFormat(pf)
311
- #define SDL_GetMasksForPixelFormatEnum (f ,b ,r ,g ,b ,a ) SDL_PixelFormatEnumToMasks(f,b,r,g,b,a)
313
+ #define SDL_GetMasksForPixelFormatEnum (f ,b ,R ,G ,B ,A ) SDL_PixelFormatEnumToMasks(f,b,R,G,B,A)
314
+ #endif
315
+
316
+ /**
317
+ * SDL_rect.h
318
+ */
319
+ #if SDL_VERSION_ATLEAST (2 ,0 ,0 )
320
+ #if !SDL_VERSION_ATLEAST (2 ,0 ,10 )
321
+ struct SDL_FRect
322
+ {
323
+ float x ;
324
+ float y ;
325
+ float w ;
326
+ float h ;
327
+ };
328
+ #endif
329
+
330
+ #define SDL_F_TO_INT (f ) \
331
+ ((f) >= INT_MAX) ? INT_MAX : ((f) <= INT_MIN) ? INT_MIN : (int)(f)
332
+
333
+ /* SDL_RenderTexture support function--convert an SDL_FRect to SDL_Rect. */
334
+ static inline SDL_Rect sdl_frect_to_rect (const SDL_FRect * src )
335
+ {
336
+ SDL_Rect tmp =
337
+ {
338
+ SDL_F_TO_INT (src -> x ),
339
+ SDL_F_TO_INT (src -> y ),
340
+ SDL_F_TO_INT (src -> w ),
341
+ SDL_F_TO_INT (src -> h )
342
+ };
343
+ return tmp ;
344
+ }
312
345
#endif
313
346
314
- /* SDL_render.h */
347
+ /**
348
+ * SDL_render.h
349
+ */
315
350
#if !SDL_VERSION_ATLEAST (3 ,0 ,0 ) && SDL_VERSION_ATLEAST (2 ,0 ,0 )
316
351
typedef int SDL_RendererLogicalPresentation ;
317
352
#define SDL_LOGICAL_PRESENTATION_DISABLED 0
318
- #define SDL_SCALEMODE_BEST SDL_ScaleModeBest
319
- #define SDL_SCALEMODE_LINEAR SDL_ScaleModeLinear
320
- #define SDL_SCALEMODE_NEAREST SDL_ScaleModeNearest
321
- #define SDL_SetRenderClipRect (r , rect ) SDL_RenderSetClipRect(r, rect)
353
+ #define SDL_SCALEMODE_BEST SDL_ScaleModeBest
354
+ #define SDL_SCALEMODE_LINEAR SDL_ScaleModeLinear
355
+ #define SDL_SCALEMODE_NEAREST SDL_ScaleModeNearest
356
+ #define SDL_SetRenderClipRect (r , rect ) SDL_RenderSetClipRect(r, rect)
357
+ #define SDL_SetRenderLogicalSize (r , w , h ) SDL_RenderSetLogicalSize(r, w, h)
322
358
323
359
static inline int SDL_SetRenderLogicalPresentation (SDL_Renderer * render ,
324
- int w , int h , SDL_RendererLogicalPresentiation p , SDL_ScaleMode s )
360
+ int w , int h , SDL_RendererLogicalPresentation p , SDL_ScaleMode s )
325
361
{
326
362
return SDL_SetRenderLogicalSize (render , w , h );
327
363
}
364
+
365
+ static inline int SDL_RenderTexture (SDL_Renderer * renderer , SDL_Texture * texture ,
366
+ const SDL_FRect * src_frect , const SDL_FRect * dest_frect )
367
+ {
368
+ SDL_Rect src_rect = sdl_frect_to_rect (src_frect );
369
+
370
+ #if SDL_VERSION_ATLEAST (2 ,0 ,10 )
371
+ return SDL_RenderCopyF (renderer , texture , & src_rect , dest_frect );
372
+ #else
373
+ SDL_Rect dest_rect = sdl_frect_to_rect (dest_frect );
374
+ return SDL_RenderCopy (renderer , texture , & src_rect , & dest_rect );
375
+ #endif
376
+ }
328
377
#endif
329
378
330
379
/* SDL_surface.h */
0 commit comments