From 99846d578ca8935ea75b8b1404a5acb6c68f03bc Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Wed, 25 Apr 2018 11:51:21 -0400 Subject: [PATCH] Fixes found by BRUTE --- src/SDL2.cs | 43 ++++++++++++++++++++++++++----------------- src/SDL2_image.cs | 11 ++++------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/SDL2.cs b/src/SDL2.cs index ee48b7a..83a347f 100644 --- a/src/SDL2.cs +++ b/src/SDL2.cs @@ -2966,8 +2966,15 @@ namespace SDL2 } /* Only available in 2.0.4 */ - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern SDL_bool SDL_PointInRect(ref SDL_Point p, ref SDL_Rect r); + public static SDL_bool SDL_PointInRect(ref SDL_Point p, ref SDL_Rect r) + { + return ( (p.x >= r.x) && + (p.x < (r.x + r.w)) && + (p.y >= r.y) && + (p.y < (r.y + r.h)) ) ? + SDL_bool.SDL_TRUE : + SDL_bool.SDL_FALSE; + } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_EnclosePoints( @@ -3000,14 +3007,24 @@ namespace SDL2 ref int Y2 ); - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern SDL_bool SDL_RectEmpty(ref SDL_Rect rect); + public static SDL_bool SDL_RectEmpty(ref SDL_Rect r) + { + return ((r.w <= 0) || (r.h <= 0)) ? + SDL_bool.SDL_TRUE : + SDL_bool.SDL_FALSE; + } - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern SDL_bool SDL_RectEquals( - ref SDL_Rect A, - ref SDL_Rect B - ); + public static SDL_bool SDL_RectEquals( + ref SDL_Rect a, + ref SDL_Rect b + ) { + return ( (a.x == b.x) && + (a.y == b.y) && + (a.w == b.w) && + (a.h == b.h) ) ? + SDL_bool.SDL_TRUE : + SDL_bool.SDL_FALSE; + } [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_UnionRect( @@ -5112,10 +5129,6 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr SDL_JoystickOpen(int device_index); - /* joystick refers to an SDL_Joystick* */ - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int SDL_JoystickOpened(int device_index); - /* joystick refers to an SDL_Joystick* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_JoystickUpdate(); @@ -6015,10 +6028,6 @@ namespace SDL2 int len ); - /* dev refers to an SDL_AudioDeviceID */ - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int SDL_AudioDeviceConnected(uint dev); - [DllImport(nativeLibName, EntryPoint = "SDL_AudioInit", CallingConvention = CallingConvention.Cdecl)] private static extern int INTERNAL_SDL_AudioInit( byte[] driver_name diff --git a/src/SDL2_image.cs b/src/SDL2_image.cs index a3423c9..86e0aae 100644 --- a/src/SDL2_image.cs +++ b/src/SDL2_image.cs @@ -68,12 +68,12 @@ namespace SDL2 X.patch = SDL_IMAGE_PATCHLEVEL; } - [DllImport(nativeLibName, EntryPoint = "IMG_LinkedVersion", CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr INTERNAL_IMG_LinkedVersion(); - public static SDL.SDL_version IMG_LinkedVersion() + [DllImport(nativeLibName, EntryPoint = "IMG_Linked_Version", CallingConvention = CallingConvention.Cdecl)] + private static extern IntPtr INTERNAL_IMG_Linked_Version(); + public static SDL.SDL_version IMG_Linked_Version() { SDL.SDL_version result; - IntPtr result_ptr = INTERNAL_IMG_LinkedVersion(); + IntPtr result_ptr = INTERNAL_IMG_Linked_Version(); result = (SDL.SDL_version) Marshal.PtrToStructure( result_ptr, typeof(SDL.SDL_version) @@ -179,9 +179,6 @@ namespace SDL2 ); } - [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern int IMG_InvertAlpha(int on); - /* IntPtr refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr IMG_ReadXPMFromArray(