Merge pull request #25 from jameson-ernst/master

Marshaling refinements and SDL_ShowMessageBox
This commit is contained in:
Ethan Lee 2013-07-14 22:15:51 -07:00
commit 7a4820d660
6 changed files with 258 additions and 106 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
bin/ bin/
obj/
*.userprefs *.userprefs

View file

@ -38,7 +38,7 @@ namespace SDL2
_leaveAllocatedInstance = new LPUtf8StrMarshaler(true), _leaveAllocatedInstance = new LPUtf8StrMarshaler(true),
_defaultInstance = new LPUtf8StrMarshaler(false); _defaultInstance = new LPUtf8StrMarshaler(false);
private static ICustomMarshaler GetInstance(string cookie) public static ICustomMarshaler GetInstance(string cookie)
{ {
switch (cookie) switch (cookie)
{ {

View file

@ -366,27 +366,149 @@ namespace SDL2
#endregion #endregion
#region SDL_messagebox.h #region SDL_messagebox.h
[Flags]
public enum SDL_MessageBoxFlags : uint public enum SDL_MessageBoxFlags : uint
{ {
SDL_MESSAGEBOX_ERROR = 0x00000010, SDL_MESSAGEBOX_ERROR = 0x00000010,
SDL_MESSAGEBOX_WARNING = 0x00000020, SDL_MESSAGEBOX_WARNING = 0x00000020,
SDL_MESSAGEBOX_INFORMATION = 0x00000040 SDL_MESSAGEBOX_INFORMATION = 0x00000040
} }
[Flags]
public enum SDL_MessageBoxButtonFlags : uint
{
SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT = 0x00000001,
SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT = 0x00000002
}
[StructLayout(LayoutKind.Sequential)]
private 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)]
private 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)]
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)
{
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;
}
/* window refers to an SDL_Window* */ /* window refers to an SDL_Window* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_ShowSimpleMessageBox( public static extern int SDL_ShowSimpleMessageBox(
UInt32 flags, SDL_MessageBoxFlags flags,
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))] [In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string title, string title,
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))] [In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string message, string message,
IntPtr window IntPtr window
); );
#endregion #endregion
#region SDL_version.h, SDL_revision.h #region SDL_version.h, SDL_revision.h
/* Similar to the headers, this is the version we're expecting to be /* Similar to the headers, this is the version we're expecting to be
@ -908,7 +1030,8 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_UpdateWindowSurfaceRects( public static extern int SDL_UpdateWindowSurfaceRects(
IntPtr window, IntPtr window,
SDL_Rect[] rects, [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Struct, SizeParamIndex = 2)]
SDL_Rect[] rects,
int numrects int numrects
); );
@ -1015,23 +1138,23 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_GetRenderDrawBlendMode( public static extern int SDL_GetRenderDrawBlendMode(
IntPtr renderer, IntPtr renderer,
ref SDL_BlendMode blendMode out SDL_BlendMode blendMode
); );
/* renderer refers to an SDL_Renderer* */ /* renderer refers to an SDL_Renderer* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_GetRenderDrawColor( public static extern int SDL_GetRenderDrawColor(
IntPtr renderer, IntPtr renderer,
ref byte r, out byte r,
ref byte g, out byte g,
ref byte b, out byte b,
ref byte a out byte a
); );
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_GetRenderDriverInfo( public static extern int SDL_GetRenderDriverInfo(
int index, int index,
ref SDL_RendererInfo info out SDL_RendererInfo info
); );
/* IntPtr refers to an SDL_Renderer*, window to an SDL_Window* */ /* IntPtr refers to an SDL_Renderer*, window to an SDL_Window* */
@ -1042,30 +1165,30 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_GetRendererInfo( public static extern int SDL_GetRendererInfo(
IntPtr renderer, IntPtr renderer,
ref SDL_RendererInfo info out SDL_RendererInfo info
); );
/* texture refers to an SDL_Texture* */ /* texture refers to an SDL_Texture* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_GetTextureAlphaMod( public static extern int SDL_GetTextureAlphaMod(
IntPtr texture, IntPtr texture,
ref byte alpha out byte alpha
); );
/* texture refers to an SDL_Texture* */ /* texture refers to an SDL_Texture* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_GetTextureBlendMode( public static extern int SDL_GetTextureBlendMode(
IntPtr texture, IntPtr texture,
ref SDL_BlendMode blendMode out SDL_BlendMode blendMode
); );
/* texture refers to an SDL_Texture* */ /* texture refers to an SDL_Texture* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_GetTextureColorMod( public static extern int SDL_GetTextureColorMod(
IntPtr texture, IntPtr texture,
ref byte r, out byte r,
ref byte g, out byte g,
ref byte b out byte b
); );
/* texture refers to an SDL_Texture*, pixels to a void* */ /* texture refers to an SDL_Texture*, pixels to a void* */
@ -1073,26 +1196,26 @@ namespace SDL2
public static extern int SDL_LockTexture( public static extern int SDL_LockTexture(
IntPtr texture, IntPtr texture,
ref SDL_Rect rect, ref SDL_Rect rect,
ref IntPtr pixels, out IntPtr pixels,
ref int pitch out int pitch
); );
/* texture refers to an SDL_Texture* */ /* texture refers to an SDL_Texture* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_QueryTexture( public static extern int SDL_QueryTexture(
IntPtr texture, IntPtr texture,
ref uint format, out uint format,
ref int access, out int access,
ref int w, out int w,
ref int h out int h
); );
/* texture refers to an SDL_Texture, pixels to a void* */ /* texture refers to an SDL_Texture, pixels to a void* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_QueryTexturePixels( public static extern int SDL_QueryTexturePixels(
IntPtr texture, IntPtr texture,
ref IntPtr pixels, out IntPtr pixels,
ref int pitch out int pitch
); );
/* renderer refers to an SDL_Renderer* */ /* renderer refers to an SDL_Renderer* */
@ -1134,7 +1257,8 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_RenderDrawLines( public static extern int SDL_RenderDrawLines(
IntPtr renderer, IntPtr renderer,
SDL_Point[] points, [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Struct, SizeParamIndex = 2)]
SDL_Point[] points,
int count int count
); );
@ -1150,7 +1274,8 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_RenderDrawPoints( public static extern int SDL_RenderDrawPoints(
IntPtr renderer, IntPtr renderer,
SDL_Point[] points, [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Struct, SizeParamIndex = 2)]
SDL_Point[] points,
int count int count
); );
@ -1165,7 +1290,8 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_RenderDrawRects( public static extern int SDL_RenderDrawRects(
IntPtr renderer, IntPtr renderer,
SDL_Rect[] rects, [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Struct, SizeParamIndex = 2)]
SDL_Rect[] rects,
int count int count
); );
@ -1180,7 +1306,8 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_RenderFillRects( public static extern int SDL_RenderFillRects(
IntPtr renderer, IntPtr renderer,
SDL_Rect[] rects, [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Struct, SizeParamIndex = 2)]
SDL_Rect[] rects,
int count int count
); );
@ -1188,7 +1315,7 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_RendererGetViewport( public static extern int SDL_RendererGetViewport(
IntPtr renderer, IntPtr renderer,
ref SDL_Rect rect out SDL_Rect rect
); );
/* renderer refers to an SDL_Renderer* */ /* renderer refers to an SDL_Renderer* */
@ -1669,7 +1796,7 @@ namespace SDL2
public struct SDL_Palette public struct SDL_Palette
{ {
public int ncolors; public int ncolors;
public SDL_Color[] colors; public IntPtr colors;
public int version; public int version;
public int refcount; public int refcount;
} }
@ -1708,7 +1835,8 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_CalculateGammaRamp( public static extern void SDL_CalculateGammaRamp(
float gamma, float gamma,
ref ushort ramp [Out()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U2, SizeConst = 256)]
ushort[] ramp
); );
/* format refers to an SDL_PixelFormat* */ /* format refers to an SDL_PixelFormat* */
@ -1730,9 +1858,9 @@ namespace SDL2
public static extern void SDL_GetRGB( public static extern void SDL_GetRGB(
uint pixel, uint pixel,
IntPtr format, IntPtr format,
ref byte r, out byte r,
ref byte g, out byte g,
ref byte b out byte b
); );
/* format refers to an SDL_PixelFormat* */ /* format refers to an SDL_PixelFormat* */
@ -1740,10 +1868,10 @@ namespace SDL2
public static extern void SDL_GetRGBA( public static extern void SDL_GetRGBA(
uint pixel, uint pixel,
IntPtr format, IntPtr format,
ref byte r, out byte r,
ref byte g, out byte g,
ref byte b, out byte b,
ref byte a out byte a
); );
/* format refers to an SDL_PixelFormat* */ /* format refers to an SDL_PixelFormat* */
@ -1777,18 +1905,19 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern SDL_bool SDL_PixelFormatEnumToMasks( public static extern SDL_bool SDL_PixelFormatEnumToMasks(
uint format, uint format,
ref int bpp, out int bpp,
ref uint Rmask, out uint Rmask,
ref uint Gmask, out uint Gmask,
ref uint Bmask, out uint Bmask,
ref uint Amask out uint Amask
); );
/* palette refers to an SDL_Palette* */ /* palette refers to an SDL_Palette* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_SetPaletteColors( public static extern int SDL_SetPaletteColors(
IntPtr palette, IntPtr palette,
SDL_Color[] colors, [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Struct)]
SDL_Color[] colors,
int firstcolor, int firstcolor,
int ncolors int ncolors
); );
@ -1822,10 +1951,11 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern SDL_bool SDL_EnclosePoints( public static extern SDL_bool SDL_EnclosePoints(
SDL_Point[] points, [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Struct, SizeParamIndex = 1)]
SDL_Point[] points,
int count, int count,
ref SDL_Rect clip, ref SDL_Rect clip,
ref SDL_Rect result out SDL_Rect result
); );
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -1838,7 +1968,7 @@ namespace SDL2
public static extern SDL_bool SDL_IntersectRect( public static extern SDL_bool SDL_IntersectRect(
ref SDL_Rect A, ref SDL_Rect A,
ref SDL_Rect B, ref SDL_Rect B,
ref SDL_Rect result out SDL_Rect result
); );
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -1863,7 +1993,7 @@ namespace SDL2
public static extern void SDL_UnionRect( public static extern void SDL_UnionRect(
ref SDL_Rect A, ref SDL_Rect A,
ref SDL_Rect B, ref SDL_Rect B,
ref SDL_Rect result out SDL_Rect result
); );
#endregion #endregion
@ -1983,7 +2113,8 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_FillRects( public static extern int SDL_FillRects(
IntPtr dst, IntPtr dst,
SDL_Rect[] rects, [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Struct, SizeParamIndex = 2)]
SDL_Rect[] rects,
int count, int count,
uint color uint color
); );
@ -1996,37 +2127,37 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_GetClipRect( public static extern void SDL_GetClipRect(
IntPtr surface, IntPtr surface,
ref SDL_Rect rect out SDL_Rect rect
); );
/* surface refers to an SDL_Surface* */ /* surface refers to an SDL_Surface* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_GetColorKey( public static extern int SDL_GetColorKey(
IntPtr surface, IntPtr surface,
ref uint key out uint key
); );
/* surface refers to an SDL_Surface* */ /* surface refers to an SDL_Surface* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_GetSurfaceAlphaMod( public static extern int SDL_GetSurfaceAlphaMod(
IntPtr surface, IntPtr surface,
ref byte alpha out byte alpha
); );
/* surface refers to an SDL_Surface* */ /* surface refers to an SDL_Surface* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_GetSurfaceBlendMode( public static extern int SDL_GetSurfaceBlendMode(
IntPtr surface, IntPtr surface,
ref SDL_BlendMode blendMode out SDL_BlendMode blendMode
); );
/* surface refers to an SDL_Surface* */ /* surface refers to an SDL_Surface* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_GetSurfaceColorMod( public static extern int SDL_GetSurfaceColorMod(
IntPtr surface, IntPtr surface,
ref byte r, out byte r,
ref byte g, out byte g,
ref byte b out byte b
); );
/* These are for SDL_LoadBMP, which is a macro in the SDL headers. */ /* These are for SDL_LoadBMP, which is a macro in the SDL headers. */
@ -2618,7 +2749,8 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_PeepEvents( public static extern int SDL_PeepEvents(
SDL_Event[] events, [Out()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Struct, SizeParamIndex = 1)]
SDL_Event[] events,
int numevents, int numevents,
SDL_eventaction action, SDL_eventaction action,
SDL_EventType minType, SDL_EventType minType,
@ -2672,8 +2804,8 @@ namespace SDL2
/* userdata refers to a void* */ /* userdata refers to a void* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern SDL_bool SDL_GetEventFilter( public static extern SDL_bool SDL_GetEventFilter(
ref SDL_EventFilter filter, out SDL_EventFilter filter,
ref IntPtr userdata out IntPtr userdata
); );
/* userdata refers to a void* */ /* userdata refers to a void* */
@ -3320,7 +3452,7 @@ namespace SDL2
/* Return value is a pointer to a UInt8 array */ /* Return value is a pointer to a UInt8 array */
/* Numkeys returns the size of the array if non-null */ /* Numkeys returns the size of the array if non-null */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [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. */ /* Get the current key modifier state for the keyboard. */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
@ -3542,8 +3674,8 @@ namespace SDL2
public static extern int SDL_JoystickGetBall( public static extern int SDL_JoystickGetBall(
IntPtr joystick, IntPtr joystick,
int ball, int ball,
ref int dx, out int dx,
ref int dy out int dy
); );
/* joystick refers to an SDL_Joystick* */ /* joystick refers to an SDL_Joystick* */
@ -4312,14 +4444,14 @@ namespace SDL2
IntPtr src, IntPtr src,
int freesrc, int freesrc,
ref SDL_AudioSpec spec, ref SDL_AudioSpec spec,
ref IntPtr audio_buf, out IntPtr audio_buf,
ref uint audio_len out uint audio_len
); );
public static SDL_AudioSpec SDL_LoadWAV( public static SDL_AudioSpec SDL_LoadWAV(
string file, string file,
ref SDL_AudioSpec spec, ref SDL_AudioSpec spec,
ref IntPtr audio_buf, out IntPtr audio_buf,
ref uint audio_len out uint audio_len
) { ) {
SDL_AudioSpec result; SDL_AudioSpec result;
IntPtr rwops = INTERNAL_SDL_RWFromFile(file, "rb"); IntPtr rwops = INTERNAL_SDL_RWFromFile(file, "rb");
@ -4327,8 +4459,8 @@ namespace SDL2
rwops, rwops,
1, 1,
ref spec, ref spec,
ref audio_buf, out audio_buf,
ref audio_len out audio_len
); );
result = (SDL_AudioSpec) Marshal.PtrToStructure( result = (SDL_AudioSpec) Marshal.PtrToStructure(
result_ptr, result_ptr,
@ -4346,8 +4478,10 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_MixAudio( public static extern void SDL_MixAudio(
byte[] dst, [Out()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 2)]
byte[] src, byte[] dst,
[In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 2)]
byte[] src,
uint len, uint len,
int volume int volume
); );
@ -4355,8 +4489,10 @@ namespace SDL2
/* format refers to an SDL_AudioFormat */ /* format refers to an SDL_AudioFormat */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern void SDL_MixAudioFormat( public static extern void SDL_MixAudioFormat(
byte[] dst, [Out()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 3)]
byte[] src, byte[] dst,
[In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 3)]
byte[] src,
ushort format, ushort format,
uint len, uint len,
int volume int volume
@ -4365,7 +4501,7 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int SDL_OpenAudio( public static extern int SDL_OpenAudio(
ref SDL_AudioSpec desired, ref SDL_AudioSpec desired,
ref SDL_AudioSpec obtained out SDL_AudioSpec obtained
); );
/* uint refers to an SDL_AudioDeviceID */ /* uint refers to an SDL_AudioDeviceID */
@ -4375,7 +4511,7 @@ namespace SDL2
string device, string device,
int iscapture, int iscapture,
ref SDL_AudioSpec desired, ref SDL_AudioSpec desired,
ref SDL_AudioSpec obtained, out SDL_AudioSpec obtained,
int allowed_changes int allowed_changes
); );

View file

@ -61,7 +61,7 @@ namespace SDL2
IMG_INIT_WEBP = 0x00000008 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.major = SDL_IMAGE_MAJOR_VERSION;
X.minor = SDL_IMAGE_MINOR_VERSION; X.minor = SDL_IMAGE_MINOR_VERSION;
@ -107,7 +107,10 @@ namespace SDL2
/* IntPtr refers to an SDL_Surface* */ /* IntPtr refers to an SDL_Surface* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [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 #endregion
} }

View file

@ -137,7 +137,7 @@ namespace SDL2
IntPtr b // void* 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.major = SDL_MIXER_MAJOR_VERSION;
X.minor = SDL_MIXER_MINOR_VERSION; X.minor = SDL_MIXER_MINOR_VERSION;
@ -205,11 +205,18 @@ namespace SDL2
/* IntPtr refers to a Mix_Chunk* */ /* IntPtr refers to a Mix_Chunk* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [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* */ /* IntPtr refers to a Mix_Chunk* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [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* */ /* chunk refers to a Mix_Chunk* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]

View file

@ -66,7 +66,7 @@ namespace SDL2
public const int TTF_HINTING_MONO = 2; public const int TTF_HINTING_MONO = 2;
public const int TTF_HINTING_NONE = 3; 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.major = SDL_TTF_MAJOR_VERSION;
X.minor = SDL_TTF_MINOR_VERSION; X.minor = SDL_TTF_MINOR_VERSION;
@ -188,11 +188,11 @@ namespace SDL2
public static extern int TTF_GlyphMetrics( public static extern int TTF_GlyphMetrics(
IntPtr font, IntPtr font,
ushort ch, ushort ch,
ref int minx, out int minx,
ref int maxx, out int maxx,
ref int miny, out int miny,
ref int maxy, out int maxy,
ref int advance out int advance
); );
/* font refers to a TTF_Font* */ /* font refers to a TTF_Font* */
@ -201,8 +201,8 @@ namespace SDL2
IntPtr font, IntPtr font,
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))] [In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string text, string text,
ref int w, out int w,
ref int h out int h
); );
/* font refers to a TTF_Font* */ /* font refers to a TTF_Font* */
@ -211,24 +211,25 @@ namespace SDL2
IntPtr font, IntPtr font,
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))] [In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))]
string text, string text,
ref int w, out int w,
ref int h out int h
); );
/* font refers to a TTF_Font* */ /* font refers to a TTF_Font* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern int TTF_SizeUNICODE( public static extern int TTF_SizeUNICODE(
IntPtr font, IntPtr font,
ushort[] text, [In()] [MarshalAs(UnmanagedType.LPWStr)]
ref int w, string text,
ref int h out int w,
out int h
); );
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */ /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr TTF_RenderText_Solid( public static extern IntPtr TTF_RenderText_Solid(
IntPtr font, IntPtr font,
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))] [In()] [MarshalAs(UnmanagedType.LPStr)]
string text, string text,
SDL.SDL_Color fg SDL.SDL_Color fg
); );
@ -246,7 +247,8 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr TTF_RenderUNICODE_Solid( public static extern IntPtr TTF_RenderUNICODE_Solid(
IntPtr font, IntPtr font,
ushort[] text, [In()] [MarshalAs(UnmanagedType.LPWStr)]
string text,
SDL.SDL_Color fg SDL.SDL_Color fg
); );
@ -262,7 +264,7 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr TTF_RenderText_Shaded( public static extern IntPtr TTF_RenderText_Shaded(
IntPtr font, IntPtr font,
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))] [In()] [MarshalAs(UnmanagedType.LPStr)]
string text, string text,
SDL.SDL_Color fg, SDL.SDL_Color fg,
SDL.SDL_Color bg SDL.SDL_Color bg
@ -282,7 +284,8 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr TTF_RenderUNICODE_Shaded( public static extern IntPtr TTF_RenderUNICODE_Shaded(
IntPtr font, IntPtr font,
ushort[] text, [In()] [MarshalAs(UnmanagedType.LPWStr)]
string text,
SDL.SDL_Color fg, SDL.SDL_Color fg,
SDL.SDL_Color bg SDL.SDL_Color bg
); );
@ -300,7 +303,7 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr TTF_RenderText_Blended( public static extern IntPtr TTF_RenderText_Blended(
IntPtr font, IntPtr font,
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))] [In()] [MarshalAs(UnmanagedType.LPStr)]
string text, string text,
SDL.SDL_Color fg SDL.SDL_Color fg
); );
@ -318,7 +321,8 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr TTF_RenderUNICODE_Blended( public static extern IntPtr TTF_RenderUNICODE_Blended(
IntPtr font, IntPtr font,
ushort[] text, [In()] [MarshalAs(UnmanagedType.LPWStr)]
string text,
SDL.SDL_Color fg SDL.SDL_Color fg
); );
@ -326,7 +330,7 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr TTF_RenderText_Blended_Wrapped( public static extern IntPtr TTF_RenderText_Blended_Wrapped(
IntPtr font, IntPtr font,
[In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))] [In()] [MarshalAs(UnmanagedType.LPStr)]
string text, string text,
SDL.SDL_Color fg, SDL.SDL_Color fg,
uint wrapped uint wrapped
@ -346,7 +350,8 @@ namespace SDL2
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr TTF_RenderUNICODE_Blended_Wrapped( public static extern IntPtr TTF_RenderUNICODE_Blended_Wrapped(
IntPtr font, IntPtr font,
ushort[] text, [In()] [MarshalAs(UnmanagedType.LPWStr)]
string text,
SDL.SDL_Color fg, SDL.SDL_Color fg,
uint wrapped uint wrapped
); );