From b877b08553e65e8b98fc33c9006d168e51b6319f Mon Sep 17 00:00:00 2001 From: Jameson Ernst Date: Sun, 14 Jul 2013 12:20:15 -0700 Subject: [PATCH 1/5] Added obj/ to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fa8a8a1..7ee19fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ bin/ +obj/ *.userprefs From 964f553e25f3044c28f7b50069e72e02db02d59b Mon Sep 17 00:00:00 2001 From: Jameson Ernst Date: Sun, 14 Jul 2013 14:33:14 -0700 Subject: [PATCH 2/5] Marshaling refinements --- src/SDL2.cs | 158 +++++++++++++++++++++++++++++----------------------- 1 file changed, 87 insertions(+), 71 deletions(-) diff --git a/src/SDL2.cs b/src/SDL2.cs index 8d879d1..4b86982 100644 --- a/src/SDL2.cs +++ b/src/SDL2.cs @@ -886,7 +886,8 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_UpdateWindowSurfaceRects( IntPtr window, - SDL_Rect[] rects, + [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Struct, SizeParamIndex = 2)] + SDL_Rect[] rects, int numrects ); @@ -993,23 +994,23 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetRenderDrawBlendMode( IntPtr renderer, - ref SDL_BlendMode blendMode + out SDL_BlendMode blendMode ); /* renderer refers to an SDL_Renderer* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetRenderDrawColor( IntPtr renderer, - ref byte r, - ref byte g, - ref byte b, - ref byte a + out byte r, + out byte g, + out byte b, + out byte a ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetRenderDriverInfo( int index, - ref SDL_RendererInfo info + out SDL_RendererInfo info ); /* IntPtr refers to an SDL_Renderer*, window to an SDL_Window* */ @@ -1020,30 +1021,30 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetRendererInfo( IntPtr renderer, - ref SDL_RendererInfo info + out SDL_RendererInfo info ); /* texture refers to an SDL_Texture* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetTextureAlphaMod( IntPtr texture, - ref byte alpha + out byte alpha ); /* texture refers to an SDL_Texture* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetTextureBlendMode( IntPtr texture, - ref SDL_BlendMode blendMode + out SDL_BlendMode blendMode ); /* texture refers to an SDL_Texture* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetTextureColorMod( IntPtr texture, - ref byte r, - ref byte g, - ref byte b + out byte r, + out byte g, + out byte b ); /* texture refers to an SDL_Texture*, pixels to a void* */ @@ -1051,26 +1052,26 @@ namespace SDL2 public static extern int SDL_LockTexture( IntPtr texture, ref SDL_Rect rect, - ref IntPtr pixels, - ref int pitch + out IntPtr pixels, + out int pitch ); /* texture refers to an SDL_Texture* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_QueryTexture( IntPtr texture, - ref uint format, - ref int access, - ref int w, - ref int h + out uint format, + out int access, + out int w, + out int h ); /* texture refers to an SDL_Texture, pixels to a void* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_QueryTexturePixels( IntPtr texture, - ref IntPtr pixels, - ref int pitch + out IntPtr pixels, + out int pitch ); /* renderer refers to an SDL_Renderer* */ @@ -1112,7 +1113,8 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderDrawLines( IntPtr renderer, - SDL_Point[] points, + [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Struct, SizeParamIndex = 2)] + SDL_Point[] points, int count ); @@ -1128,7 +1130,8 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderDrawPoints( IntPtr renderer, - SDL_Point[] points, + [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Struct, SizeParamIndex = 2)] + SDL_Point[] points, int count ); @@ -1143,7 +1146,8 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderDrawRects( IntPtr renderer, - SDL_Rect[] rects, + [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Struct, SizeParamIndex = 2)] + SDL_Rect[] rects, int count ); @@ -1158,7 +1162,8 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RenderFillRects( IntPtr renderer, - SDL_Rect[] rects, + [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Struct, SizeParamIndex = 2)] + SDL_Rect[] rects, int count ); @@ -1166,7 +1171,7 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_RendererGetViewport( IntPtr renderer, - ref SDL_Rect rect + out SDL_Rect rect ); /* renderer refers to an SDL_Renderer* */ @@ -1647,7 +1652,7 @@ namespace SDL2 public struct SDL_Palette { public int ncolors; - public SDL_Color[] colors; + public IntPtr colors; public int version; public int refcount; } @@ -1686,7 +1691,8 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_CalculateGammaRamp( float gamma, - ref ushort ramp + [Out()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeConst = 256)] + ushort[] ramp ); /* format refers to an SDL_PixelFormat* */ @@ -1708,9 +1714,9 @@ namespace SDL2 public static extern void SDL_GetRGB( uint pixel, IntPtr format, - ref byte r, - ref byte g, - ref byte b + out byte r, + out byte g, + out byte b ); /* format refers to an SDL_PixelFormat* */ @@ -1718,10 +1724,10 @@ namespace SDL2 public static extern void SDL_GetRGBA( uint pixel, IntPtr format, - ref byte r, - ref byte g, - ref byte b, - ref byte a + out byte r, + out byte g, + out byte b, + out byte a ); /* format refers to an SDL_PixelFormat* */ @@ -1755,18 +1761,19 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_PixelFormatEnumToMasks( uint format, - ref int bpp, - ref uint Rmask, - ref uint Gmask, - ref uint Bmask, - ref uint Amask + out int bpp, + out uint Rmask, + out uint Gmask, + out uint Bmask, + out uint Amask ); /* palette refers to an SDL_Palette* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_SetPaletteColors( IntPtr palette, - SDL_Color[] colors, + [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Struct)] + SDL_Color[] colors, int firstcolor, int ncolors ); @@ -1800,10 +1807,11 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_EnclosePoints( - SDL_Point[] points, + [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Struct, SizeParamIndex = 1)] + SDL_Point[] points, int count, ref SDL_Rect clip, - ref SDL_Rect result + out SDL_Rect result ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1816,7 +1824,7 @@ namespace SDL2 public static extern SDL_bool SDL_IntersectRect( ref SDL_Rect A, ref SDL_Rect B, - ref SDL_Rect result + out SDL_Rect result ); [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -1841,7 +1849,7 @@ namespace SDL2 public static extern void SDL_UnionRect( ref SDL_Rect A, ref SDL_Rect B, - ref SDL_Rect result + out SDL_Rect result ); #endregion @@ -1961,7 +1969,8 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_FillRects( IntPtr dst, - SDL_Rect[] rects, + [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Struct, SizeParamIndex = 2)] + SDL_Rect[] rects, int count, uint color ); @@ -1974,37 +1983,37 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_GetClipRect( IntPtr surface, - ref SDL_Rect rect + out SDL_Rect rect ); /* surface refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetColorKey( IntPtr surface, - ref uint key + out uint key ); /* surface refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetSurfaceAlphaMod( IntPtr surface, - ref byte alpha + out byte alpha ); /* surface refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetSurfaceBlendMode( IntPtr surface, - ref SDL_BlendMode blendMode + out SDL_BlendMode blendMode ); /* surface refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_GetSurfaceColorMod( IntPtr surface, - ref byte r, - ref byte g, - ref byte b + out byte r, + out byte g, + out byte b ); /* These are for SDL_LoadBMP, which is a macro in the SDL headers. */ @@ -2596,7 +2605,8 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_PeepEvents( - SDL_Event[] events, + [Out()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Struct, SizeParamIndex = 1)] + SDL_Event[] events, int numevents, SDL_eventaction action, SDL_EventType minType, @@ -2650,8 +2660,8 @@ namespace SDL2 /* userdata refers to a void* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern SDL_bool SDL_GetEventFilter( - ref SDL_EventFilter filter, - ref IntPtr userdata + out SDL_EventFilter filter, + out IntPtr userdata ); /* userdata refers to a void* */ @@ -3298,7 +3308,7 @@ namespace SDL2 /* Return value is a pointer to a UInt8 array */ /* Numkeys returns the size of the array if non-null */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr SDL_GetKeyboardState(ref int numkeys); + public static extern IntPtr SDL_GetKeyboardState(out int numkeys); /* Get the current key modifier state for the keyboard. */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] @@ -3520,8 +3530,8 @@ namespace SDL2 public static extern int SDL_JoystickGetBall( IntPtr joystick, int ball, - ref int dx, - ref int dy + out int dx, + out int dy ); /* joystick refers to an SDL_Joystick* */ @@ -4290,14 +4300,14 @@ namespace SDL2 IntPtr src, int freesrc, ref SDL_AudioSpec spec, - ref IntPtr audio_buf, - ref uint audio_len + out IntPtr audio_buf, + out uint audio_len ); public static SDL_AudioSpec SDL_LoadWAV( string file, ref SDL_AudioSpec spec, - ref IntPtr audio_buf, - ref uint audio_len + out IntPtr audio_buf, + out uint audio_len ) { SDL_AudioSpec result; IntPtr rwops = INTERNAL_SDL_RWFromFile(file, "rb"); @@ -4305,8 +4315,8 @@ namespace SDL2 rwops, 1, ref spec, - ref audio_buf, - ref audio_len + out audio_buf, + out audio_len ); result = (SDL_AudioSpec) Marshal.PtrToStructure( result_ptr, @@ -4324,8 +4334,10 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_MixAudio( - byte[] dst, - byte[] src, + [Out()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 2)] + byte[] dst, + [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 2)] + byte[] src, uint len, int volume ); @@ -4333,8 +4345,10 @@ namespace SDL2 /* format refers to an SDL_AudioFormat */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern void SDL_MixAudioFormat( - byte[] dst, - byte[] src, + [Out()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 3)] + byte[] dst, + [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 3)] + byte[] src, ushort format, uint len, int volume @@ -4343,7 +4357,7 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int SDL_OpenAudio( ref SDL_AudioSpec desired, - ref SDL_AudioSpec obtained + out SDL_AudioSpec obtained ); /* uint refers to an SDL_AudioDeviceID */ @@ -4353,7 +4367,7 @@ namespace SDL2 string device, int iscapture, ref SDL_AudioSpec desired, - ref SDL_AudioSpec obtained, + out SDL_AudioSpec obtained, int allowed_changes ); @@ -4375,6 +4389,8 @@ namespace SDL2 public static extern void SDL_UnlockAudioDevice(uint dev); #endregion + + } } From 92397d8a9855a3703e0bcd658e6359dba9f02cff Mon Sep 17 00:00:00 2001 From: Jameson Ernst Date: Sun, 14 Jul 2013 17:40:12 -0700 Subject: [PATCH 3/5] Added SDL_messagebox wrapper --- src/LPUtf8StrMarshaler.cs | 2 +- src/SDL2.cs | 141 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+), 1 deletion(-) diff --git a/src/LPUtf8StrMarshaler.cs b/src/LPUtf8StrMarshaler.cs index 3371ed0..df720c1 100644 --- a/src/LPUtf8StrMarshaler.cs +++ b/src/LPUtf8StrMarshaler.cs @@ -38,7 +38,7 @@ namespace SDL2 _leaveAllocatedInstance = new LPUtf8StrMarshaler(true), _defaultInstance = new LPUtf8StrMarshaler(false); - private static ICustomMarshaler GetInstance(string cookie) + public static ICustomMarshaler GetInstance(string cookie) { switch (cookie) { diff --git a/src/SDL2.cs b/src/SDL2.cs index 4b86982..1bdece3 100644 --- a/src/SDL2.cs +++ b/src/SDL2.cs @@ -4390,7 +4390,148 @@ namespace SDL2 #endregion + #region SDL_messagebox.h + [Flags] + public enum SDL_MessageBoxFlags + { + SDL_MESSAGEBOX_ERROR = 0x00000010, + SDL_MESSAGEBOX_WARNING = 0x00000020, + SDL_MESSAGEBOX_INFORMATION = 0x00000040 + } + + [Flags] + public enum SDL_MessageBoxButtonFlags + { + SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT = 0x00000001, + SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT = 0x00000002 + } + + [StructLayout(LayoutKind.Sequential)] + internal struct INTERNAL_SDL_MessageBoxButtonData + { + public SDL_MessageBoxButtonFlags flags; + public int buttonid; + public IntPtr text; /* The UTF-8 button text */ + } + + [StructLayout(LayoutKind.Sequential)] + public struct SDL_MessageBoxButtonData + { + public SDL_MessageBoxButtonFlags flags; + public int buttonid; + public string text; /* The UTF-8 button text */ + } + + [StructLayout(LayoutKind.Sequential)] + public struct SDL_MessageBoxColor + { + public byte r, g, b; + } + + public enum SDL_MessageBoxColorType + { + SDL_MESSAGEBOX_COLOR_BACKGROUND, + SDL_MESSAGEBOX_COLOR_TEXT, + SDL_MESSAGEBOX_COLOR_BUTTON_BORDER, + SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND, + SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED, + SDL_MESSAGEBOX_COLOR_MAX + } + + [StructLayout(LayoutKind.Sequential)] + public struct SDL_MessageBoxColorScheme + { + [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.Struct, SizeConst = (int)SDL_MessageBoxColorType.SDL_MESSAGEBOX_COLOR_MAX)] + public SDL_MessageBoxColor[] colors; + } + + [StructLayout(LayoutKind.Sequential)] + internal struct INTERNAL_SDL_MessageBoxData + { + public SDL_MessageBoxFlags flags; + public IntPtr window; /* Parent window, can be NULL */ + public IntPtr title; /* UTF-8 title */ + public IntPtr message; /* UTF-8 message text */ + public int numbuttons; + public IntPtr buttons; + public IntPtr colorScheme; /* Can be NULL to use system settings */ + } + + [StructLayout(LayoutKind.Sequential)] + public struct SDL_MessageBoxData + { + public SDL_MessageBoxFlags flags; + public IntPtr window; /* Parent window, can be NULL */ + public string title; /* UTF-8 title */ + public string message; /* UTF-8 message text */ + public int numbuttons; + public SDL_MessageBoxButtonData[] buttons; + public SDL_MessageBoxColorScheme? colorScheme; /* Can be NULL to use system settings */ + } + + [DllImport(nativeLibName, EntryPoint = "SDL_ShowMessageBox", CallingConvention = CallingConvention.Cdecl)] + internal static extern int INTERNAL_SDL_ShowMessageBox([In()] ref INTERNAL_SDL_MessageBoxData messageboxdata, out int buttonid); + + public static unsafe int SDL_ShowMessageBox([In()] ref SDL_MessageBoxData messageboxdata, out int buttonid) + { + var utf8 = LPUtf8StrMarshaler.GetInstance(null); + + var data = new INTERNAL_SDL_MessageBoxData() + { + flags = messageboxdata.flags, + window = messageboxdata.window, + title = utf8.MarshalManagedToNative(messageboxdata.title), + message = utf8.MarshalManagedToNative(messageboxdata.message), + numbuttons = messageboxdata.numbuttons, + }; + + var buttons = new INTERNAL_SDL_MessageBoxButtonData[messageboxdata.numbuttons]; + for (int i = 0; i < messageboxdata.numbuttons; i++) + { + buttons[i] = new INTERNAL_SDL_MessageBoxButtonData() + { + flags = messageboxdata.buttons[i].flags, + buttonid = messageboxdata.buttons[i].buttonid, + text = utf8.MarshalManagedToNative(messageboxdata.buttons[i].text), + }; + } + + if (messageboxdata.colorScheme != null) + { + data.colorScheme = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SDL_MessageBoxColorScheme))); + Marshal.StructureToPtr(messageboxdata.colorScheme.Value, data.colorScheme, false); + } + + int result; + fixed (INTERNAL_SDL_MessageBoxButtonData* buttonsPtr = &buttons[0]) + { + data.buttons = (IntPtr)buttonsPtr; + result = INTERNAL_SDL_ShowMessageBox(ref data, out buttonid); + } + + Marshal.FreeHGlobal(data.colorScheme); + for (int i = 0; i < messageboxdata.numbuttons; i++) + { + utf8.CleanUpNativeData(buttons[i].text); + } + utf8.CleanUpNativeData(data.message); + utf8.CleanUpNativeData(data.title); + + return result; + } + + [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] + public static extern int SDL_ShowSimpleMessageBox( + SDL_MessageBoxFlags flags, + [In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))] + string title, + [In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))] + string message, + IntPtr window + ); + + #endregion } } From 51e907c959ffece7c6c700e6b133fc5d382b9f6a Mon Sep 17 00:00:00 2001 From: Jameson Ernst Date: Sun, 14 Jul 2013 21:24:26 -0700 Subject: [PATCH 4/5] Marshaling refinements to supplementary libraries --- src/SDL2_image.cs | 7 +++++-- src/SDL2_mixer.cs | 13 ++++++++++--- src/SDL2_ttf.cs | 47 ++++++++++++++++++++++++++--------------------- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/SDL2_image.cs b/src/SDL2_image.cs index 6337211..e2a0641 100644 --- a/src/SDL2_image.cs +++ b/src/SDL2_image.cs @@ -61,7 +61,7 @@ namespace SDL2 IMG_INIT_WEBP = 0x00000008 } - public static void SDL_IMAGE_VERSION(ref SDL.SDL_version X) + public static void SDL_IMAGE_VERSION(out SDL.SDL_version X) { X.major = SDL_IMAGE_MAJOR_VERSION; X.minor = SDL_IMAGE_MINOR_VERSION; @@ -107,7 +107,10 @@ namespace SDL2 /* IntPtr refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr IMG_ReadXPMFromArray(ref char[] xpm); + public static extern IntPtr IMG_ReadXPMFromArray( + [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr)] + string[] xpm + ); #endregion } diff --git a/src/SDL2_mixer.cs b/src/SDL2_mixer.cs index 8d669df..00e0776 100644 --- a/src/SDL2_mixer.cs +++ b/src/SDL2_mixer.cs @@ -137,7 +137,7 @@ namespace SDL2 IntPtr b // void* ); - public static void SDL_MIXER_VERSION(ref SDL.SDL_version X) + public static void SDL_MIXER_VERSION(out SDL.SDL_version X) { X.major = SDL_MIXER_MAJOR_VERSION; X.minor = SDL_MIXER_MINOR_VERSION; @@ -205,11 +205,18 @@ namespace SDL2 /* IntPtr refers to a Mix_Chunk* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr Mix_QuickLoad_WAV(byte[] mem); + public static extern IntPtr Mix_QuickLoad_WAV( + [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1)] + byte[] mem + ); /* IntPtr refers to a Mix_Chunk* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Mix_Chunk Mix_QuickLoad_RAW(byte[] mem, uint len); + public static extern Mix_Chunk Mix_QuickLoad_RAW( + [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 1)] + byte[] mem, + uint len + ); /* chunk refers to a Mix_Chunk* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] diff --git a/src/SDL2_ttf.cs b/src/SDL2_ttf.cs index 4edea5c..430c5db 100644 --- a/src/SDL2_ttf.cs +++ b/src/SDL2_ttf.cs @@ -66,7 +66,7 @@ namespace SDL2 public const int TTF_HINTING_MONO = 2; public const int TTF_HINTING_NONE = 3; - public static void SDL_TTF_VERSION(ref SDL.SDL_version X) + public static void SDL_TTF_VERSION(out SDL.SDL_version X) { X.major = SDL_TTF_MAJOR_VERSION; X.minor = SDL_TTF_MINOR_VERSION; @@ -188,11 +188,11 @@ namespace SDL2 public static extern int TTF_GlyphMetrics( IntPtr font, ushort ch, - ref int minx, - ref int maxx, - ref int miny, - ref int maxy, - ref int advance + out int minx, + out int maxx, + out int miny, + out int maxy, + out int advance ); /* font refers to a TTF_Font* */ @@ -201,8 +201,8 @@ namespace SDL2 IntPtr font, [In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))] string text, - ref int w, - ref int h + out int w, + out int h ); /* font refers to a TTF_Font* */ @@ -211,24 +211,25 @@ namespace SDL2 IntPtr font, [In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))] string text, - ref int w, - ref int h + out int w, + out int h ); /* font refers to a TTF_Font* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int TTF_SizeUNICODE( IntPtr font, - ushort[] text, - ref int w, - ref int h + [In()] [MarshalAs(UnmanagedType.LPWStr)] + string text, + out int w, + out int h ); /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr TTF_RenderText_Solid( IntPtr font, - [In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))] + [In()] [MarshalAs(UnmanagedType.LPStr)] string text, SDL.SDL_Color fg ); @@ -246,7 +247,8 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr TTF_RenderUNICODE_Solid( IntPtr font, - ushort[] text, + [In()] [MarshalAs(UnmanagedType.LPWStr)] + string text, SDL.SDL_Color fg ); @@ -262,7 +264,7 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr TTF_RenderText_Shaded( IntPtr font, - [In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))] + [In()] [MarshalAs(UnmanagedType.LPStr)] string text, SDL.SDL_Color fg, SDL.SDL_Color bg @@ -282,7 +284,8 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr TTF_RenderUNICODE_Shaded( IntPtr font, - ushort[] text, + [In()] [MarshalAs(UnmanagedType.LPWStr)] + string text, SDL.SDL_Color fg, SDL.SDL_Color bg ); @@ -300,7 +303,7 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr TTF_RenderText_Blended( IntPtr font, - [In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))] + [In()] [MarshalAs(UnmanagedType.LPStr)] string text, SDL.SDL_Color fg ); @@ -318,7 +321,8 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr TTF_RenderUNICODE_Blended( IntPtr font, - ushort[] text, + [In()] [MarshalAs(UnmanagedType.LPWStr)] + string text, SDL.SDL_Color fg ); @@ -326,7 +330,7 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr TTF_RenderText_Blended_Wrapped( IntPtr font, - [In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))] + [In()] [MarshalAs(UnmanagedType.LPStr)] string text, SDL.SDL_Color fg, uint wrapped @@ -346,7 +350,8 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr TTF_RenderUNICODE_Blended_Wrapped( IntPtr font, - ushort[] text, + [In()] [MarshalAs(UnmanagedType.LPWStr)] + string text, SDL.SDL_Color fg, uint wrapped ); From 941209348aab780fab635185d00d62de009ab44f Mon Sep 17 00:00:00 2001 From: Jameson Ernst Date: Sun, 14 Jul 2013 22:12:54 -0700 Subject: [PATCH 5/5] Change messagebox enum base types to uint Change access level on messagebox internals to private --- src/SDL2.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/SDL2.cs b/src/SDL2.cs index e11ae03..274786e 100644 --- a/src/SDL2.cs +++ b/src/SDL2.cs @@ -368,7 +368,7 @@ namespace SDL2 #region SDL_messagebox.h [Flags] - public enum SDL_MessageBoxFlags + public enum SDL_MessageBoxFlags : uint { SDL_MESSAGEBOX_ERROR = 0x00000010, SDL_MESSAGEBOX_WARNING = 0x00000020, @@ -376,14 +376,14 @@ namespace SDL2 } [Flags] - public enum SDL_MessageBoxButtonFlags + public enum SDL_MessageBoxButtonFlags : uint { SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT = 0x00000001, SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT = 0x00000002 } [StructLayout(LayoutKind.Sequential)] - internal struct INTERNAL_SDL_MessageBoxButtonData + private struct INTERNAL_SDL_MessageBoxButtonData { public SDL_MessageBoxButtonFlags flags; public int buttonid; @@ -422,7 +422,7 @@ namespace SDL2 } [StructLayout(LayoutKind.Sequential)] - internal struct INTERNAL_SDL_MessageBoxData + private struct INTERNAL_SDL_MessageBoxData { public SDL_MessageBoxFlags flags; public IntPtr window; /* Parent window, can be NULL */ @@ -446,7 +446,7 @@ namespace SDL2 } [DllImport(nativeLibName, EntryPoint = "SDL_ShowMessageBox", CallingConvention = CallingConvention.Cdecl)] - internal static extern int INTERNAL_SDL_ShowMessageBox([In()] ref INTERNAL_SDL_MessageBoxData messageboxdata, out int buttonid); + private static extern int INTERNAL_SDL_ShowMessageBox([In()] ref INTERNAL_SDL_MessageBoxData messageboxdata, out int buttonid); public static unsafe int SDL_ShowMessageBox([In()] ref SDL_MessageBoxData messageboxdata, out int buttonid) {