зеркало из https://github.com/stride3d/SDL2-CS.git
Internally we are just using a class, no more struct. This makes it faster by avoid too many struct copies whenever we access one of the buffers, and we avoided indirections by returning the IntPtr of the buffer. Added definition of a finalizer on the Utf8String class. Renamed UTF8String into Utf8String to avoid ReSharper warnings on namings.
This commit is contained in:
Родитель
4a1ea6fff8
Коммит
5293e8ecea
196
src/SDL2.cs
196
src/SDL2.cs
|
@ -89,9 +89,9 @@ namespace SDL2
|
|||
/// <returns>Returns a pointer to the SDL_RWops structure that is created, or NULL on failure; call SDL_GetError() for more information.</returns>
|
||||
public static IntPtr SDL_RWFromFile(string file, string mode)
|
||||
{
|
||||
var fileUTF8 = UTF8String.ReusableBuffer(file);
|
||||
var modeUTF8 = UTF8String.ReusableBufferBis(mode);
|
||||
return SDL_RWFromFileNative(fileUTF8.Handle, modeUTF8.Handle);
|
||||
var fileUTF8 = Utf8String.ReusableBufferPtr(file);
|
||||
var modeUTF8 = Utf8String.ReusableBufferPtrBis(mode);
|
||||
return SDL_RWFromFileNative(fileUTF8, modeUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_RWFromFile", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_RWFromFileNative(IntPtr fileUtf8Str, IntPtr modeUtf8Str);
|
||||
|
@ -205,7 +205,7 @@ namespace SDL2
|
|||
|
||||
public static string SDL_GetPlatform ()
|
||||
{
|
||||
return UTF8String.String(SDL_GetPlatformNative());
|
||||
return Utf8String.String(SDL_GetPlatformNative());
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GetPlatform", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GetPlatformNative();
|
||||
|
@ -329,8 +329,8 @@ namespace SDL2
|
|||
/// <returns>Returns the string value of a hint or NULL if the hint isn't set.</returns>
|
||||
public static string SDL_GetHint(string name)
|
||||
{
|
||||
var nameUTF8 = UTF8String.ReusableBuffer(name);
|
||||
return UTF8String.String(SDL_GetHintNative(nameUTF8.Handle));
|
||||
var nameUTF8 = Utf8String.ReusableBufferPtr(name);
|
||||
return Utf8String.String(SDL_GetHintNative(nameUTF8));
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GetHint", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GetHintNative(IntPtr name);
|
||||
|
@ -347,9 +347,9 @@ namespace SDL2
|
|||
/// override priority instead.</remarks>
|
||||
public static SDL_bool SDL_SetHint( string name, string value)
|
||||
{
|
||||
var nameUTF8 = UTF8String.ReusableBuffer(name);
|
||||
var valueUTF8 = UTF8String.ReusableBufferBis(value);
|
||||
return SDL_SetHintNative(nameUTF8.Handle, valueUTF8.Handle);
|
||||
var nameUTF8 = Utf8String.ReusableBufferPtr(name);
|
||||
var valueUTF8 = Utf8String.ReusableBufferPtrBis(value);
|
||||
return SDL_SetHintNative(nameUTF8, valueUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_SetHint", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern SDL_bool SDL_SetHintNative(IntPtr name, IntPtr value);
|
||||
|
@ -367,9 +367,9 @@ namespace SDL2
|
|||
/// considered to have override priority. </remarks>
|
||||
public static SDL_bool SDL_SetHintWithPriority( string name, string value, SDL_HintPriority priority)
|
||||
{
|
||||
var nameUTF8 = UTF8String.ReusableBuffer(name);
|
||||
var valueUTF8 = UTF8String.ReusableBufferBis(value);
|
||||
return SDL_SetHintWithPriorityNative(nameUTF8.Handle, valueUTF8.Handle, priority);
|
||||
var nameUTF8 = Utf8String.ReusableBufferPtr(name);
|
||||
var valueUTF8 = Utf8String.ReusableBufferPtrBis(value);
|
||||
return SDL_SetHintWithPriorityNative(nameUTF8, valueUTF8, priority);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_SetHintWithPriority", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern SDL_bool SDL_SetHintWithPriorityNative( IntPtr name, IntPtr value, SDL_HintPriority priority);
|
||||
|
@ -396,7 +396,7 @@ namespace SDL2
|
|||
/// <remarks>It is possible for multiple errors to occur before calling SDL_GetError(). Only the last error is returned. </remarks>
|
||||
public static string SDL_GetError()
|
||||
{
|
||||
return UTF8String.String(SDL_GetErrorNative());
|
||||
return Utf8String.String(SDL_GetErrorNative());
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GetError", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GetErrorNative();
|
||||
|
@ -411,8 +411,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/// <remarks>Calling this function will replace any previous error message that was set.</remarks>
|
||||
public static void SDL_SetError(string fmt, __arglist)
|
||||
{
|
||||
var fmtUTF8 = UTF8String.ReusableBuffer(fmt);
|
||||
SDL_SetErrorNative(fmtUTF8.Handle, __arglist);
|
||||
var fmtUTF8 = Utf8String.ReusableBufferPtr(fmt);
|
||||
SDL_SetErrorNative(fmtUTF8, __arglist);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_SetError", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void SDL_SetErrorNative(IntPtr fmt, __arglist);
|
||||
|
@ -495,8 +495,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/// <param name="...">additional parameters matching % tokens in the fmt string, if any</param>
|
||||
public static void SDL_Log( string fmt, __arglist)
|
||||
{
|
||||
var fmtUTF8 = UTF8String.ReusableBuffer(fmt);
|
||||
SDL_LogNative(fmtUTF8.Handle, __arglist);
|
||||
var fmtUTF8 = Utf8String.ReusableBufferPtr(fmt);
|
||||
SDL_LogNative(fmtUTF8, __arglist);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_Log", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void SDL_LogNative(IntPtr fmt, __arglist);
|
||||
|
@ -510,8 +510,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/// <remarks>The category can be one of SDL_LOG_CATEGORY*</remarks>
|
||||
public static void SDL_LogVerbose( int category, string fmt, __arglist)
|
||||
{
|
||||
var fmtUTF8 = UTF8String.ReusableBuffer(fmt);
|
||||
SDL_LogVerboseNative(category, fmtUTF8.Handle, __arglist);
|
||||
var fmtUTF8 = Utf8String.ReusableBufferPtr(fmt);
|
||||
SDL_LogVerboseNative(category, fmtUTF8, __arglist);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_LogVerbose", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void SDL_LogVerboseNative( int category, IntPtr fmt, __arglist);
|
||||
|
@ -525,8 +525,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/// <remarks>The category can be one of SDL_LOG_CATEGORY*</remarks>
|
||||
public static void SDL_LogDebug( int category, string fmt, __arglist)
|
||||
{
|
||||
var fmtUTF8 = UTF8String.ReusableBuffer(fmt);
|
||||
SDL_LogDebugNative(category, fmtUTF8.Handle, __arglist);
|
||||
var fmtUTF8 = Utf8String.ReusableBufferPtr(fmt);
|
||||
SDL_LogDebugNative(category, fmtUTF8, __arglist);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_LogDebug", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void SDL_LogDebugNative( int category, IntPtr fmt, __arglist);
|
||||
|
@ -540,8 +540,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/// <remarks>The category can be one of SDL_LOG_CATEGORY*</remarks>
|
||||
public static void SDL_LogInfo( int category, string fmt, __arglist)
|
||||
{
|
||||
var fmtUTF8 = UTF8String.ReusableBuffer(fmt);
|
||||
SDL_LogInfoNative(category, fmtUTF8.Handle, __arglist);
|
||||
var fmtUTF8 = Utf8String.ReusableBufferPtr(fmt);
|
||||
SDL_LogInfoNative(category, fmtUTF8, __arglist);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = " SDL_LogInfo", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void SDL_LogInfoNative( int category, IntPtr fmt, __arglist);
|
||||
|
@ -555,8 +555,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/// <remarks>The category can be one of SDL_LOG_CATEGORY*</remarks>
|
||||
public static void SDL_LogWarn( int category, string fmt, __arglist)
|
||||
{
|
||||
var fmtUTF8 = UTF8String.ReusableBuffer(fmt);
|
||||
SDL_LogWarnNative(category, fmtUTF8.Handle, __arglist);
|
||||
var fmtUTF8 = Utf8String.ReusableBufferPtr(fmt);
|
||||
SDL_LogWarnNative(category, fmtUTF8, __arglist);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_LogWarn", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void SDL_LogWarnNative( int category, IntPtr fmt, __arglist);
|
||||
|
@ -570,8 +570,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/// <remarks>The category can be one of SDL_LOG_CATEGORY*</remarks>
|
||||
public static void SDL_LogError( int category, string fmt, __arglist)
|
||||
{
|
||||
var fmtUTF8 = UTF8String.ReusableBuffer(fmt);
|
||||
SDL_LogErrorNative(category, fmtUTF8.Handle, __arglist);
|
||||
var fmtUTF8 = Utf8String.ReusableBufferPtr(fmt);
|
||||
SDL_LogErrorNative(category, fmtUTF8, __arglist);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_LogError", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void SDL_LogErrorNative( int category, IntPtr fmt, __arglist);
|
||||
|
@ -585,8 +585,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/// <remarks>The category can be one of SDL_LOG_CATEGORY*</remarks>
|
||||
public static void SDL_LogCritical( int category, string fmt, __arglist)
|
||||
{
|
||||
var fmtUTF8 = UTF8String.ReusableBuffer(fmt);
|
||||
SDL_LogCriticalNative(category, fmtUTF8.Handle, __arglist);
|
||||
var fmtUTF8 = Utf8String.ReusableBufferPtr(fmt);
|
||||
SDL_LogCriticalNative(category, fmtUTF8, __arglist);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_LogCritical", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void SDL_LogCriticalNative( int category, IntPtr fmt, __arglist);
|
||||
|
@ -602,8 +602,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/// <remarks>The priority can be one of SDL_LOG_PRIORITY*</remarks>
|
||||
public static void SDL_LogMessage( int category, SDL_LogPriority priority, string fmt, __arglist)
|
||||
{
|
||||
var fmtUTF8 = UTF8String.ReusableBuffer(fmt);
|
||||
SDL_LogMessageNative(category, priority, fmtUTF8.Handle, __arglist);
|
||||
var fmtUTF8 = Utf8String.ReusableBufferPtr(fmt);
|
||||
SDL_LogMessageNative(category, priority, fmtUTF8, __arglist);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_LogMessage", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void SDL_LogMessageNative( int category, SDL_LogPriority priority, IntPtr fmt, __arglist);
|
||||
|
@ -618,8 +618,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/// <param name="...">additional parameters matching % tokens in the fmt string, if any</param>
|
||||
public static void SDL_LogMessageV( int category, SDL_LogPriority priority, string fmt, __arglist)
|
||||
{
|
||||
var fmtUTF8 = UTF8String.ReusableBuffer(fmt);
|
||||
SDL_LogMessageVNative(category, priority, fmtUTF8.Handle, __arglist);
|
||||
var fmtUTF8 = Utf8String.ReusableBufferPtr(fmt);
|
||||
SDL_LogMessageVNative(category, priority, fmtUTF8, __arglist);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_LogMessageV", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void SDL_LogMessageVNative( int category, SDL_LogPriority priority, IntPtr fmt, __arglist);
|
||||
|
@ -696,8 +696,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
[Flags]
|
||||
public enum SDL_MessageBoxFlags : uint
|
||||
{
|
||||
SDL_MESSAGEBOX_ERROR = 0x00000010,
|
||||
SDL_MESSAGEBOX_WARNING = 0x00000020,
|
||||
SDL_MESSAGEBOX_ERROR = 0x00000010,
|
||||
SDL_MESSAGEBOX_WARNING = 0x00000020,
|
||||
SDL_MESSAGEBOX_INFORMATION = 0x00000040
|
||||
}
|
||||
|
||||
|
@ -788,8 +788,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/// <returns></returns>
|
||||
public static unsafe int SDL_ShowMessageBox([In()] ref SDL_MessageBoxData messageboxdata, out int buttonid)
|
||||
{
|
||||
UTF8StringCell titleUTF8 = new UTF8StringCell(messageboxdata.title);
|
||||
UTF8StringCell messageUTF8 = new UTF8StringCell(messageboxdata.message);
|
||||
Utf8String titleUTF8 = new Utf8String(messageboxdata.title);
|
||||
Utf8String messageUTF8 = new Utf8String(messageboxdata.message);
|
||||
var data = new INTERNAL_SDL_MessageBoxData()
|
||||
{
|
||||
flags = messageboxdata.flags,
|
||||
|
@ -800,10 +800,10 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
};
|
||||
|
||||
var buttons = new INTERNAL_SDL_MessageBoxButtonData[messageboxdata.numbuttons];
|
||||
var buttonTextUTF8 = new UTF8StringCell[messageboxdata.numbuttons];
|
||||
var buttonTextUTF8 = new Utf8String[messageboxdata.numbuttons];
|
||||
for (int i = 0; i < messageboxdata.numbuttons; i++)
|
||||
{
|
||||
buttonTextUTF8[i] = new UTF8StringCell(messageboxdata.buttons[i].text);
|
||||
buttonTextUTF8[i] = new Utf8String(messageboxdata.buttons[i].text);
|
||||
buttons[i] = new INTERNAL_SDL_MessageBoxButtonData()
|
||||
{
|
||||
flags = messageboxdata.buttons[i].flags,
|
||||
|
@ -846,9 +846,9 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/// <returns>0 on success or a negative error code on failure; call SDL_GetError() for more information. </returns>
|
||||
public static int SDL_ShowSimpleMessageBox( SDL_MessageBoxFlags flags, string title, string message, IntPtr window)
|
||||
{
|
||||
var titleUTF8 = UTF8String.ReusableBuffer(title);
|
||||
var messageUTF8 = UTF8String.ReusableBufferBis(message);
|
||||
return SDL_ShowSimpleMessageBoxNative (flags, titleUTF8.Handle, messageUTF8.Handle, window);
|
||||
var titleUTF8 = Utf8String.ReusableBufferPtr(title);
|
||||
var messageUTF8 = Utf8String.ReusableBufferPtrBis(message);
|
||||
return SDL_ShowSimpleMessageBoxNative (flags, titleUTF8, messageUTF8, window);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_ShowSimpleMessageBox", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int SDL_ShowSimpleMessageBoxNative( SDL_MessageBoxFlags flags, IntPtr title, IntPtr message, IntPtr window);
|
||||
|
@ -944,7 +944,7 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/// different from the code you are compiling with, which is found in the constant SDL_REVISION.</remarks>
|
||||
public static string SDL_GetRevision()
|
||||
{
|
||||
return UTF8String.String(SDL_GetRevisionNative());
|
||||
return Utf8String.String(SDL_GetRevisionNative());
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GetRevision", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GetRevisionNative();
|
||||
|
@ -1126,8 +1126,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/// for more information. (refers to an <see cref="SDL_Window"/>)</returns>
|
||||
public static IntPtr SDL_CreateWindow( string title, int x, int y, int w, int h, SDL_WindowFlags flags)
|
||||
{
|
||||
var titleUTF8 = UTF8String.ReusableBuffer(title);
|
||||
return SDL_CreateWindowNative(titleUTF8.Handle, x, y, w, h, flags);
|
||||
var titleUTF8 = Utf8String.ReusableBufferPtr(title);
|
||||
return SDL_CreateWindowNative(titleUTF8, x, y, w, h, flags);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_CreateWindow", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_CreateWindowNative( IntPtr title, int x, int y, int w, int h, SDL_WindowFlags flags);
|
||||
|
@ -1227,7 +1227,7 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/// previous native display mode, and not the current display mode. </remarks>
|
||||
public static string SDL_GetCurrentVideoDriver()
|
||||
{
|
||||
return UTF8String.String(SDL_GetCurrentVideoDriverNative());
|
||||
return Utf8String.String(SDL_GetCurrentVideoDriverNative());
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GetCurrentVideoDriver", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GetCurrentVideoDriverNative();
|
||||
|
@ -1316,7 +1316,7 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/// <remarks>The video drivers are presented in the order in which they are normally checked during initialization. </remarks>
|
||||
public static string SDL_GetVideoDriver( int index)
|
||||
{
|
||||
return UTF8String.String(SDL_GetVideoDriverNative(index));
|
||||
return Utf8String.String(SDL_GetVideoDriverNative(index));
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GetVideoDriver", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GetVideoDriverNative( int index);
|
||||
|
@ -1339,8 +1339,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/// <returns>Returns the value associated with name. (void*)</returns>
|
||||
public static IntPtr SDL_GetWindowData( IntPtr window, string name)
|
||||
{
|
||||
var nameUTF8 = UTF8String.ReusableBuffer(name);
|
||||
return SDL_GetWindowDataNative(window, nameUTF8.Handle);
|
||||
var nameUTF8 = Utf8String.ReusableBufferPtr(name);
|
||||
return SDL_GetWindowDataNative(window, nameUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GetWindowData", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GetWindowDataNative( IntPtr window, IntPtr name);
|
||||
|
@ -1452,7 +1452,7 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/* window refers to an SDL_Window* */
|
||||
public static string SDL_GetWindowTitle( IntPtr window)
|
||||
{
|
||||
return UTF8String.String(SDL_GetWindowTitleNative(window));
|
||||
return Utf8String.String(SDL_GetWindowTitleNative(window));
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GetWindowTitle", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GetWindowTitleNative( IntPtr window);
|
||||
|
@ -1476,16 +1476,16 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/* IntPtr refers to a function pointer */
|
||||
public static IntPtr SDL_GL_GetProcAddress( string proc)
|
||||
{
|
||||
var procUTF8 = UTF8String.ReusableBuffer(proc);
|
||||
return SDL_GL_GetProcAddressNative(procUTF8.Handle);
|
||||
var procUTF8 = Utf8String.ReusableBufferPtr(proc);
|
||||
return SDL_GL_GetProcAddressNative(procUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GL_GetProcAddress", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GL_GetProcAddressNative( IntPtr proc);
|
||||
|
||||
public static SDL_bool SDL_GL_ExtensionSupported( string extension)
|
||||
{
|
||||
var extensionUTF8 = UTF8String.ReusableBuffer(extension);
|
||||
return SDL_GL_ExtensionSupportedNative(extensionUTF8.Handle);
|
||||
var extensionUTF8 = Utf8String.ReusableBufferPtr(extension);
|
||||
return SDL_GL_ExtensionSupportedNative(extensionUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GL_ExtensionSupported", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern SDL_bool SDL_GL_ExtensionSupportedNative( IntPtr extension);
|
||||
|
@ -1576,8 +1576,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/* IntPtr and userdata are void*, window is an SDL_Window* */
|
||||
public static IntPtr SDL_SetWindowData( IntPtr window, string name, IntPtr userdata)
|
||||
{
|
||||
var nameUTF8 = UTF8String.ReusableBuffer(name);
|
||||
return SDL_SetWindowDataNative(window, nameUTF8.Handle, userdata);
|
||||
var nameUTF8 = Utf8String.ReusableBufferPtr(name);
|
||||
return SDL_SetWindowDataNative(window, nameUTF8, userdata);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_SetWindowData", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_SetWindowDataNative( IntPtr window, IntPtr name, IntPtr userdata);
|
||||
|
@ -1664,8 +1664,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/* window refers to an SDL_Window* */
|
||||
public static void SDL_SetWindowTitle( IntPtr window, string title)
|
||||
{
|
||||
var titleUTF8 = UTF8String.ReusableBuffer(title);
|
||||
SDL_SetWindowTitleNative(window, titleUTF8.Handle);
|
||||
var titleUTF8 = Utf8String.ReusableBufferPtr(title);
|
||||
SDL_SetWindowTitleNative(window, titleUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_SetWindowTitle", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void SDL_SetWindowTitleNative( IntPtr window, IntPtr title);
|
||||
|
@ -1689,8 +1689,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
|
||||
public static int SDL_VideoInit( string driver_name)
|
||||
{
|
||||
var driver_nameUTF8 = UTF8String.ReusableBuffer(driver_name);
|
||||
return SDL_VideoInitNative(driver_nameUTF8.Handle);
|
||||
var driver_nameUTF8 = Utf8String.ReusableBufferPtr(driver_name);
|
||||
return SDL_VideoInitNative(driver_nameUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_VideoInit", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int SDL_VideoInitNative( IntPtr driver_name);
|
||||
|
@ -2670,7 +2670,7 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
|
||||
public static string SDL_GetPixelFormatName( uint format)
|
||||
{
|
||||
return UTF8String.String(SDL_GetPixelFormatNameNative(format));
|
||||
return Utf8String.String(SDL_GetPixelFormatNameNative(format));
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GetPixelFormatName", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GetPixelFormatNameNative( uint format);
|
||||
|
@ -3209,15 +3209,15 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
|
||||
public static string SDL_GetClipboardText()
|
||||
{
|
||||
return UTF8String.String(SDL_GetClipboardTextNative());
|
||||
return Utf8String.String(SDL_GetClipboardTextNative());
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GetClipboardText", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GetClipboardTextNative();
|
||||
|
||||
public static int SDL_SetClipboardText( string text)
|
||||
{
|
||||
var textUTF8 = UTF8String.ReusableBuffer(text);
|
||||
return SDL_SetClipboardTextNative(textUTF8.Handle);
|
||||
var textUTF8 = Utf8String.ReusableBufferPtr(text);
|
||||
return SDL_SetClipboardTextNative(textUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_SetClipboardText", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int SDL_SetClipboardTextNative( IntPtr text);
|
||||
|
@ -4421,7 +4421,7 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/* Wrapper for SDL_GetScancodeName */
|
||||
public static string SDL_GetScancodeName(SDL_Scancode scancode)
|
||||
{
|
||||
return UTF8String.String(SDL_GetScancodeNameNative(scancode));
|
||||
return Utf8String.String(SDL_GetScancodeNameNative(scancode));
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GetScancodeName", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GetScancodeNameNative(SDL_Scancode scancode);
|
||||
|
@ -4429,8 +4429,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/* Get a scancode from a human-readable name */
|
||||
public static SDL_Scancode SDL_GetScancodeFromName( string name)
|
||||
{
|
||||
var nameUTF8 = UTF8String.ReusableBuffer(name);
|
||||
return SDL_GetScancodeFromNameNative(nameUTF8.Handle);
|
||||
var nameUTF8 = Utf8String.ReusableBufferPtr(name);
|
||||
return SDL_GetScancodeFromNameNative(nameUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GetScancodeFromName", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern SDL_Scancode SDL_GetScancodeFromNameNative( IntPtr name);
|
||||
|
@ -4438,7 +4438,7 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/* Wrapper for SDL_GetKeyName */
|
||||
public static string SDL_GetKeyName(SDL_Keycode key)
|
||||
{
|
||||
return UTF8String.String(SDL_GetKeyNameNative(key));
|
||||
return Utf8String.String(SDL_GetKeyNameNative(key));
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GetKeyName", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GetKeyNameNative(SDL_Keycode key);
|
||||
|
@ -4446,8 +4446,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/* Get a key code from a human-readable name */
|
||||
public static SDL_Keycode SDL_GetKeyFromName( string name)
|
||||
{
|
||||
var nameUTF8 = UTF8String.ReusableBuffer(name);
|
||||
return SDL_GetKeyFromNameNative(nameUTF8.Handle);
|
||||
var nameUTF8 = Utf8String.ReusableBufferPtr(name);
|
||||
return SDL_GetKeyFromNameNative(nameUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GetKeyFromName", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern SDL_Keycode SDL_GetKeyFromNameNative( IntPtr name);
|
||||
|
@ -4721,14 +4721,14 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/* joystick refers to an SDL_Joystick* */
|
||||
public static string SDL_JoystickName( IntPtr joystick)
|
||||
{
|
||||
return UTF8String.String(SDL_JoystickNameNative(joystick));
|
||||
return Utf8String.String(SDL_JoystickNameNative(joystick));
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_JoystickName", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_JoystickNameNative( IntPtr joystick);
|
||||
|
||||
public static string SDL_JoystickNameForIndex( int device_index)
|
||||
{
|
||||
return UTF8String.String(SDL_JoystickNameForIndexNative(device_index));
|
||||
return Utf8String.String(SDL_JoystickNameForIndexNative(device_index));
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_JoystickNameForIndex", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_JoystickNameForIndexNative( int device_index);
|
||||
|
@ -4785,8 +4785,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
|
||||
public static Guid SDL_JoystickGetGUIDFromString( string pchGUID)
|
||||
{
|
||||
var pchGUIDUTF8 = UTF8String.ReusableBuffer(pchGUID);
|
||||
return SDL_JoystickGetGUIDFromStringNative(pchGUIDUTF8.Handle);
|
||||
var pchGUIDUTF8 = Utf8String.ReusableBufferPtr(pchGUID);
|
||||
return SDL_JoystickGetGUIDFromStringNative(pchGUIDUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_JoystickGetGUIDFromString", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern Guid SDL_JoystickGetGUIDFromStringNative( IntPtr pchGUID);
|
||||
|
@ -4869,8 +4869,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
|
||||
public static int SDL_GameControllerAddMapping( string mappingString)
|
||||
{
|
||||
var mappingStringUTF8 = UTF8String.ReusableBuffer(mappingString);
|
||||
return SDL_GameControllerAddMappingNative(mappingStringUTF8.Handle);
|
||||
var mappingStringUTF8 = Utf8String.ReusableBufferPtr(mappingString);
|
||||
return SDL_GameControllerAddMappingNative(mappingStringUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GameControllerAddMapping", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int SDL_GameControllerAddMappingNative( IntPtr mappingString);
|
||||
|
@ -4889,7 +4889,7 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
|
||||
public static string SDL_GameControllerMappingForGUID( Guid guid)
|
||||
{
|
||||
return UTF8String.String(SDL_GameControllerMappingForGUIDNative(guid));
|
||||
return Utf8String.String(SDL_GameControllerMappingForGUIDNative(guid));
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GameControllerMappingForGUID", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GameControllerMappingForGUIDNative( Guid guid);
|
||||
|
@ -4897,7 +4897,7 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/* gamecontroller refers to an SDL_GameController* */
|
||||
public static string SDL_GameControllerMapping( IntPtr gamecontroller)
|
||||
{
|
||||
return UTF8String.String(SDL_GameControllerMappingNative(gamecontroller));
|
||||
return Utf8String.String(SDL_GameControllerMappingNative(gamecontroller));
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GameControllerMapping", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GameControllerMappingNative( IntPtr gamecontroller);
|
||||
|
@ -4907,7 +4907,7 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
|
||||
public static string SDL_GameControllerNameForIndex( int joystick_index)
|
||||
{
|
||||
return UTF8String.String(SDL_GameControllerNameForIndexNative(joystick_index));
|
||||
return Utf8String.String(SDL_GameControllerNameForIndexNative(joystick_index));
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GameControllerNameForIndex", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GameControllerNameForIndexNative( int joystick_index);
|
||||
|
@ -4919,7 +4919,7 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/* gamecontroller refers to an SDL_GameController* */
|
||||
public static string SDL_GameControllerName( IntPtr gamecontroller)
|
||||
{
|
||||
return UTF8String.String(SDL_GameControllerNameNative(gamecontroller));
|
||||
return Utf8String.String(SDL_GameControllerNameNative(gamecontroller));
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GameControllerName", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GameControllerNameNative( IntPtr gamecontroller);
|
||||
|
@ -4946,15 +4946,15 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
|
||||
public static SDL_GameControllerAxis SDL_GameControllerGetAxisFromString( string pchString)
|
||||
{
|
||||
var pchStringUTF8 = UTF8String.ReusableBuffer(pchString);
|
||||
return SDL_GameControllerGetAxisFromStringNative(pchStringUTF8.Handle);
|
||||
var pchStringUTF8 = Utf8String.ReusableBufferPtr(pchString);
|
||||
return SDL_GameControllerGetAxisFromStringNative(pchStringUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GameControllerGetAxisFromString", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern SDL_GameControllerAxis SDL_GameControllerGetAxisFromStringNative( IntPtr pchString);
|
||||
|
||||
public static string SDL_GameControllerGetStringForAxis( SDL_GameControllerAxis axis)
|
||||
{
|
||||
return UTF8String.String(SDL_GameControllerGetStringForAxisNative(axis));
|
||||
return Utf8String.String(SDL_GameControllerGetStringForAxisNative(axis));
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GameControllerGetStringForAxis", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GameControllerGetStringForAxisNative( SDL_GameControllerAxis axis);
|
||||
|
@ -4975,15 +4975,15 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
|
||||
public static SDL_GameControllerButton SDL_GameControllerGetButtonFromString( string pchString)
|
||||
{
|
||||
var pchStringUTF8 = UTF8String.ReusableBuffer(pchString);
|
||||
return SDL_GameControllerGetButtonFromStringNative(pchStringUTF8.Handle);
|
||||
var pchStringUTF8 = Utf8String.ReusableBufferPtr(pchString);
|
||||
return SDL_GameControllerGetButtonFromStringNative(pchStringUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GameControllerGetButtonFromString", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern SDL_GameControllerButton SDL_GameControllerGetButtonFromStringNative( IntPtr pchString);
|
||||
|
||||
public static string SDL_GameControllerGetStringForButton( SDL_GameControllerButton button)
|
||||
{
|
||||
return UTF8String.String(SDL_GameControllerGetStringForButtonNative(button));
|
||||
return Utf8String.String(SDL_GameControllerGetStringForButtonNative(button));
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GameControllerGetStringForButton", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GameControllerGetStringForButtonNative( SDL_GameControllerButton button);
|
||||
|
@ -5219,7 +5219,7 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/* haptic refers to an SDL_Haptic* */
|
||||
public static string SDL_HapticName( int device_index)
|
||||
{
|
||||
return UTF8String.String(SDL_HapticNameNative(device_index));
|
||||
return Utf8String.String(SDL_HapticNameNative(device_index));
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_HapticName", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_HapticNameNative( int device_index);
|
||||
|
@ -5456,8 +5456,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
|
||||
public static int SDL_AudioInit( string driver_name)
|
||||
{
|
||||
var driver_nameUTF8 = UTF8String.ReusableBuffer(driver_name);
|
||||
return SDL_AudioInitNative(driver_nameUTF8.Handle);
|
||||
var driver_nameUTF8 = Utf8String.ReusableBufferPtr(driver_name);
|
||||
return SDL_AudioInitNative(driver_nameUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_AudioInit", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int SDL_AudioInitNative( IntPtr driver_name);
|
||||
|
@ -5478,7 +5478,7 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
|
||||
public static string SDL_GetAudioDeviceName( int index, int iscapture)
|
||||
{
|
||||
return UTF8String.String(SDL_GetAudioDeviceNameNative(index, iscapture));
|
||||
return Utf8String.String(SDL_GetAudioDeviceNameNative(index, iscapture));
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GetAudioDeviceName", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GetAudioDeviceNameNative( int index, int iscapture);
|
||||
|
@ -5491,7 +5491,7 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
|
||||
public static string SDL_GetAudioDriver( int index)
|
||||
{
|
||||
return UTF8String.String(SDL_GetAudioDriverNative(index));
|
||||
return Utf8String.String(SDL_GetAudioDriverNative(index));
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GetAudioDriver", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GetAudioDriverNative( int index);
|
||||
|
@ -5501,7 +5501,7 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
|
||||
public static string SDL_GetCurrentAudioDriver()
|
||||
{
|
||||
return UTF8String.String(SDL_GetCurrentAudioDriverNative());
|
||||
return Utf8String.String(SDL_GetCurrentAudioDriverNative());
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GetCurrentAudioDriver", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GetCurrentAudioDriverNative();
|
||||
|
@ -5579,8 +5579,8 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/* uint refers to an SDL_AudioDeviceID */
|
||||
public static uint SDL_OpenAudioDevice( string device, int iscapture, ref SDL_AudioSpec desired, out SDL_AudioSpec obtained, int allowed_changes)
|
||||
{
|
||||
var deviceUTF8 = UTF8String.ReusableBuffer(device);
|
||||
return SDL_OpenAudioDeviceNative (deviceUTF8.Handle, iscapture, ref desired, out obtained, allowed_changes);
|
||||
var deviceUTF8 = Utf8String.ReusableBufferPtr(device);
|
||||
return SDL_OpenAudioDeviceNative (deviceUTF8, iscapture, ref desired, out obtained, allowed_changes);
|
||||
}
|
||||
[DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern uint SDL_OpenAudioDeviceNative ( IntPtr device, int iscapture, ref SDL_AudioSpec desired, out SDL_AudioSpec obtained, int allowed_changes);
|
||||
|
@ -5752,7 +5752,7 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/// This function is only available in SDL 2.0.1 and later.</remarks>
|
||||
public static string SDL_GetBasePath()
|
||||
{
|
||||
return UTF8String.String(SDL_GetBasePathNative());
|
||||
return Utf8String.String(SDL_GetBasePathNative());
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GetBasePath", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GetBasePathNative();
|
||||
|
@ -5781,9 +5781,9 @@ Commented while waiting for RuntimeArgumentHandle to be in CoreFX.
|
|||
/// This function is only available in SDL 2.0.1 and later.</remarks>
|
||||
public static string SDL_GetPrefPath( string org, string app)
|
||||
{
|
||||
var orgUTF8 = UTF8String.ReusableBuffer(org);
|
||||
var appUTF8 = UTF8String.ReusableBufferBis(app);
|
||||
return UTF8String.String(SDL_GetPrefPathNative(orgUTF8.Handle, appUTF8.Handle));
|
||||
var orgUTF8 = Utf8String.ReusableBufferPtr(org);
|
||||
var appUTF8 = Utf8String.ReusableBufferPtrBis(app);
|
||||
return Utf8String.String(SDL_GetPrefPathNative(orgUTF8, appUTF8));
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "SDL_GetPrefPath", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr SDL_GetPrefPathNative( IntPtr org, IntPtr app);
|
||||
|
|
|
@ -87,8 +87,8 @@ namespace SDL2
|
|||
/* IntPtr refers to an SDL_Surface* */
|
||||
public static IntPtr IMG_Load( string file)
|
||||
{
|
||||
var fileUTF8 = UTF8String.ReusableBuffer(file);
|
||||
return IMG_LoadNative(fileUTF8.Handle);
|
||||
var fileUTF8 = Utf8String.ReusableBufferPtr(file);
|
||||
return IMG_LoadNative(fileUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "IMG_LoadNative", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr IMG_LoadNative( IntPtr file);
|
||||
|
@ -105,8 +105,8 @@ namespace SDL2
|
|||
/* THIS IS A PUBLIC RWops FUNCTION! */
|
||||
public static IntPtr IMG_LoadTyped_RW(IntPtr src, int freesrc, string type)
|
||||
{
|
||||
var typeUTF8 = UTF8String.ReusableBuffer(type);
|
||||
return IMG_LoadTyped_RWNative(src, freesrc, typeUTF8.Handle);
|
||||
var typeUTF8 = Utf8String.ReusableBufferPtr(type);
|
||||
return IMG_LoadTyped_RWNative(src, freesrc, typeUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "IMG_LoadTypedRW", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr IMG_LoadTyped_RWNative( IntPtr src, int freesrc, IntPtr type );
|
||||
|
@ -114,8 +114,8 @@ namespace SDL2
|
|||
/* IntPtr refers to an SDL_Texture*, renderer to an SDL_Renderer* */
|
||||
public static IntPtr IMG_LoadTexture(IntPtr renderer, string file)
|
||||
{
|
||||
var fileUTF8 = UTF8String.ReusableBuffer(file);
|
||||
return IMG_LoadTextureNative(renderer, fileUTF8.Handle);
|
||||
var fileUTF8 = Utf8String.ReusableBufferPtr(file);
|
||||
return IMG_LoadTextureNative(renderer, fileUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "IMG_loadTexture", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr IMG_LoadTextureNative( IntPtr renderer, IntPtr file );
|
||||
|
@ -139,8 +139,8 @@ namespace SDL2
|
|||
/* THIS IS A PUBLIC RWops FUNCTION! */
|
||||
public static IntPtr IMG_LoadTextureTyped_RW(IntPtr renderer, IntPtr src, int freesrc, string type)
|
||||
{
|
||||
var typeUTF8 = UTF8String.ReusableBuffer(type);
|
||||
return IMG_LoadTextureTyped_RWNative(renderer, src, freesrc, typeUTF8.Handle);
|
||||
var typeUTF8 = Utf8String.ReusableBufferPtr(type);
|
||||
return IMG_LoadTextureTyped_RWNative(renderer, src, freesrc, typeUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "IMG_LoadTextureTyped_RW", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr IMG_LoadTextureTyped_RWNative( IntPtr renderer, IntPtr src, int freesrc, IntPtr type );
|
||||
|
@ -158,8 +158,8 @@ namespace SDL2
|
|||
/* surface refers to an SDL_Surface* */
|
||||
public static int IMG_SavePNG(IntPtr surface, string file)
|
||||
{
|
||||
var fileUTF8 = UTF8String.ReusableBuffer(file);
|
||||
return IMG_SavePNGNative(surface, fileUTF8.Handle);
|
||||
var fileUTF8 = Utf8String.ReusableBufferPtr(file);
|
||||
return IMG_SavePNGNative(surface, fileUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "IMG_SavePNG", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int IMG_SavePNGNative( IntPtr surface, IntPtr file );
|
||||
|
|
|
@ -141,7 +141,7 @@ namespace SDL2
|
|||
{
|
||||
SDL.SDL_version result;
|
||||
IntPtr result_ptr = INTERNAL_MIX_Linked_Version();
|
||||
result = (SDL.SDL_version) Marshal.PtrToStructure(result_ptr, typeof(SDL.SDL_version));
|
||||
result = (SDL.SDL_version) Marshal.PtrToStructure(result_ptr, typeof(SDL.SDL_version));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -188,8 +188,8 @@ namespace SDL2
|
|||
/* IntPtr refers to a Mix_Music* */
|
||||
public static IntPtr Mix_LoadMUS( string file)
|
||||
{
|
||||
var fileUTF8 = UTF8String.ReusableBuffer(file);
|
||||
return Mix_LoadMUSNative(fileUTF8.Handle);
|
||||
var fileUTF8 = Utf8String.ReusableBufferPtr(file);
|
||||
return Mix_LoadMUSNative(fileUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "Mix_LoadMUS", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr Mix_LoadMUSNative( IntPtr file);
|
||||
|
@ -222,7 +222,7 @@ namespace SDL2
|
|||
|
||||
public static string Mix_GetChunkDecoder( int index)
|
||||
{
|
||||
return UTF8String.String(Mix_GetChunkDecoderNative(index));
|
||||
return Utf8String.String(Mix_GetChunkDecoderNative(index));
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "Mix_GetChunkDecoder", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr Mix_GetChunkDecoderNative( int index);
|
||||
|
@ -232,7 +232,7 @@ namespace SDL2
|
|||
|
||||
public static string Mix_GetMusicDecoder( int index)
|
||||
{
|
||||
return UTF8String.String(Mix_GetMusicDecoderNative(index));
|
||||
return Utf8String.String(Mix_GetMusicDecoderNative(index));
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "Mix_GetMusicDecoder", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr Mix_GetMusicDecoderNative( int index);
|
||||
|
@ -456,8 +456,8 @@ namespace SDL2
|
|||
|
||||
public static int Mix_SetMusicCMD( string command)
|
||||
{
|
||||
var commandUTF8 = UTF8String.ReusableBuffer(command);
|
||||
return Mix_SetMusicCMDNative(commandUTF8.Handle);
|
||||
var commandUTF8 = Utf8String.ReusableBufferPtr(command);
|
||||
return Mix_SetMusicCMDNative(commandUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "Mix_SetMusicCMD", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_SetMusicCMDNative( IntPtr command);
|
||||
|
@ -470,15 +470,15 @@ namespace SDL2
|
|||
|
||||
public static int Mix_SetSoundFonts( string paths)
|
||||
{
|
||||
var pathsUTF8 = UTF8String.ReusableBuffer(paths);
|
||||
return Mix_SetSoundFontsNative(pathsUTF8.Handle);
|
||||
var pathsUTF8 = Utf8String.ReusableBufferPtr(paths);
|
||||
return Mix_SetSoundFontsNative(pathsUTF8);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "Mix_SetSoundFonts", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int Mix_SetSoundFontsNative( IntPtr paths);
|
||||
|
||||
public static string Mix_GetSoundFonts()
|
||||
{
|
||||
return UTF8String.String(Mix_GetSoundFontsNative());
|
||||
return Utf8String.String(Mix_GetSoundFontsNative());
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "Mix_GetSoundFonts", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr Mix_GetSoundFontsNative();
|
||||
|
|
|
@ -79,7 +79,7 @@ namespace SDL2
|
|||
{
|
||||
SDL.SDL_version result;
|
||||
IntPtr result_ptr = INTERNAL_TTF_LinkedVersion();
|
||||
result = (SDL.SDL_version) Marshal.PtrToStructure(result_ptr, typeof(SDL.SDL_version));
|
||||
result = (SDL.SDL_version) Marshal.PtrToStructure(result_ptr, typeof(SDL.SDL_version));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -92,8 +92,8 @@ namespace SDL2
|
|||
/* IntPtr refers to a TTF_Font */
|
||||
public static IntPtr TTF_OpenFont(string file, int ptsize)
|
||||
{
|
||||
var fileUTF8 = UTF8String.ReusableBuffer(file);
|
||||
return TTF_OpenFontNative(fileUTF8.Handle, ptsize);
|
||||
var fileUTF8 = Utf8String.ReusableBufferPtr(file);
|
||||
return TTF_OpenFontNative(fileUTF8, ptsize);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "TTF_OpenFont", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_OpenFontNative( IntPtr file, int ptsize );
|
||||
|
@ -110,8 +110,8 @@ namespace SDL2
|
|||
/* IntPtr refers to a TTF_Font* */
|
||||
public static IntPtr TTF_OpenFontIndex( string file, int ptsize, long index)
|
||||
{
|
||||
var fileUTF8 = UTF8String.ReusableBuffer(file);
|
||||
return TTF_OpenFontIndexNative(fileUTF8.Handle, ptsize, index);
|
||||
var fileUTF8 = Utf8String.ReusableBufferPtr(file);
|
||||
return TTF_OpenFontIndexNative(fileUTF8, ptsize, index);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "TTF_OpenFontIndex", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_OpenFontIndexNative( IntPtr file, int ptsize, long index);
|
||||
|
@ -185,7 +185,7 @@ namespace SDL2
|
|||
/* font refers to a TTF_Font* */
|
||||
public static string TTF_FontFaceFamilyName( IntPtr font)
|
||||
{
|
||||
return UTF8String.String(TTF_FontFaceFamilyNameNative(font));
|
||||
return Utf8String.String(TTF_FontFaceFamilyNameNative(font));
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "TTF_FontFaceFamilyName", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_FontFaceFamilyNameNative( IntPtr font);
|
||||
|
@ -193,7 +193,7 @@ namespace SDL2
|
|||
/* font refers to a TTF_Font* */
|
||||
public static string TTF_FontFaceStyleName( IntPtr font)
|
||||
{
|
||||
return UTF8String.String(TTF_FontFaceStyleNameNative(font));
|
||||
return Utf8String.String(TTF_FontFaceStyleNameNative(font));
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "TTF_FontFaceStyleName", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_FontFaceStyleNameNative( IntPtr font);
|
||||
|
@ -217,8 +217,8 @@ namespace SDL2
|
|||
/* font refers to a TTF_Font* */
|
||||
public static int TTF_SizeText( IntPtr font, string text, out int w, out int h)
|
||||
{
|
||||
var textUTF8 = UTF8String.ReusableBuffer(text);
|
||||
return TTF_SizeTextNative(font, textUTF8.Handle, out w, out h);
|
||||
var textUTF8 = Utf8String.ReusableBufferPtr(text);
|
||||
return TTF_SizeTextNative(font, textUTF8, out w, out h);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint="TTF_SizeText", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_SizeTextNative( IntPtr font, IntPtr text, out int w, out int h);
|
||||
|
@ -226,8 +226,8 @@ namespace SDL2
|
|||
/* font refers to a TTF_Font* */
|
||||
public static int TTF_SizeUTF8( IntPtr font, string text, out int w, out int h)
|
||||
{
|
||||
var textUTF8 = UTF8String.ReusableBuffer(text);
|
||||
return TTF_SizeUTF8Native(font, textUTF8.Handle, out w, out h);
|
||||
var textUTF8 = Utf8String.ReusableBufferPtr(text);
|
||||
return TTF_SizeUTF8Native(font, textUTF8, out w, out h);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint="TTF_SizeUTF8", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int TTF_SizeUTF8Native( IntPtr font, IntPtr text, out int w, out int h);
|
||||
|
@ -254,8 +254,8 @@ namespace SDL2
|
|||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
|
||||
public static IntPtr TTF_RenderUTF8_Solid( IntPtr font, string text, SDL.SDL_Color fg)
|
||||
{
|
||||
var textUTF8 = UTF8String.ReusableBuffer(text);
|
||||
return TTF_RenderUTF8_SolidNative(font, textUTF8.Handle, fg);
|
||||
var textUTF8 = Utf8String.ReusableBufferPtr(text);
|
||||
return TTF_RenderUTF8_SolidNative(font, textUTF8, fg);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint="CalTTF_RenderUTF8_Solid", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_RenderUTF8_SolidNative( IntPtr font, IntPtr text, SDL.SDL_Color fg);
|
||||
|
@ -290,8 +290,8 @@ namespace SDL2
|
|||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
|
||||
public static IntPtr TTF_RenderUTF8_Shaded( IntPtr font, string text, SDL.SDL_Color fg, SDL.SDL_Color bg)
|
||||
{
|
||||
var textUTF8 = UTF8String.ReusableBuffer(text);
|
||||
return TTF_RenderUTF8_ShadedNative(font, textUTF8.Handle, fg, bg);
|
||||
var textUTF8 = Utf8String.ReusableBufferPtr(text);
|
||||
return TTF_RenderUTF8_ShadedNative(font, textUTF8, fg, bg);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint="CalTTF_RenderUTF8_Shaded", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_RenderUTF8_ShadedNative( IntPtr font, IntPtr text, SDL.SDL_Color fg, SDL.SDL_Color bg);
|
||||
|
@ -327,8 +327,8 @@ namespace SDL2
|
|||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
|
||||
public static IntPtr TTF_RenderUTF8_Blended( IntPtr font, string text, SDL.SDL_Color fg, int toto)
|
||||
{
|
||||
var textUTF8 = UTF8String.ReusableBuffer(text);
|
||||
return TTF_RenderUTF8_BlendedNative(font, textUTF8.Handle, fg);
|
||||
var textUTF8 = Utf8String.ReusableBufferPtr(text);
|
||||
return TTF_RenderUTF8_BlendedNative(font, textUTF8, fg);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint="CalTTF_RenderUTF8_Blended", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_RenderUTF8_BlendedNative( IntPtr font, IntPtr text, SDL.SDL_Color fg);
|
||||
|
@ -355,8 +355,8 @@ namespace SDL2
|
|||
/* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */
|
||||
public static IntPtr TTF_RenderUTF8_Blended_Wrapped( IntPtr font, string text, SDL.SDL_Color fg, uint wrapped)
|
||||
{
|
||||
var textUTF8 = UTF8String.ReusableBuffer(text);
|
||||
return TTF_RenderUTF8_Blended_WrappedNative(font, textUTF8.Handle, fg, wrapped);
|
||||
var textUTF8 = Utf8String.ReusableBufferPtr(text);
|
||||
return TTF_RenderUTF8_Blended_WrappedNative(font, textUTF8, fg, wrapped);
|
||||
}
|
||||
[DllImport(nativeLibName, EntryPoint = "TTF_RenderUTF8_Blended_Wrapped", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern IntPtr TTF_RenderUTF8_Blended_WrappedNative( IntPtr font, IntPtr text, SDL.SDL_Color fg, uint wrapped);
|
||||
|
|
|
@ -29,99 +29,26 @@ using System.Diagnostics.Contracts;
|
|||
|
||||
namespace SDL2
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides a wrapper around the <see cref="UTF8String"/> struct that will automatically free the external memory when not referenced.
|
||||
/// Mostly used to provide reusable buffers of UTF8String.
|
||||
/// </summary>
|
||||
public class UTF8StringCell: IDisposable
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Initialize current with <paramref name="s"/>
|
||||
/// </summary>
|
||||
/// <param name="s">String to use for initializing current.</param>
|
||||
public UTF8StringCell(string s)
|
||||
{
|
||||
_item = new UTF8String(s);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Access to the underlying unmanaged memory.
|
||||
/// </summary>
|
||||
public IntPtr Handle
|
||||
{
|
||||
get { return _item.Handle; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// .NET string representation of current UTF-8 encoded string.
|
||||
/// </summary>
|
||||
public string String()
|
||||
{
|
||||
return _item.String();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set current with <paramref name="s"/>.
|
||||
/// </summary>
|
||||
/// <param name="s">String to convert into UTF-8.</param>
|
||||
public void SetString(string s)
|
||||
{
|
||||
_item.SetString(s);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Free external memory held by current.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (_item.Handle != IntPtr.Zero)
|
||||
{
|
||||
_item.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finalizer to free external memory held by current if not already done.
|
||||
/// </summary>
|
||||
~UTF8StringCell() {
|
||||
Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Explicit interface implementation of the Dispose pattern.
|
||||
/// </summary>
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
Dispose();
|
||||
// No need to have the finalizer running now.
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Content of cell.
|
||||
/// </summary>
|
||||
internal UTF8String _item;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// .NET representation of a UTF8 string. Mostly used for marshalling between .NET and UTF-8.
|
||||
/// </summary>
|
||||
public unsafe struct UTF8String : IDisposable
|
||||
public unsafe class Utf8String : IDisposable
|
||||
{
|
||||
#region Initialization
|
||||
/// <summary>
|
||||
/// Initialize instance with .NET string <see cref="s"/>
|
||||
/// </summary>
|
||||
/// <param name="s">.NET string to wrap into a UTF8 sequence of unmanaged bytes.</param>
|
||||
public UTF8String(string s)
|
||||
public Utf8String(string s)
|
||||
{
|
||||
Contract.Requires(s != null, "s is not null");
|
||||
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(s);
|
||||
int nb = bytes.Length;
|
||||
IntPtr lPtr = SDL.SDL_malloc((IntPtr)(nb + 1));
|
||||
if (lPtr == IntPtr.Zero)
|
||||
{
|
||||
throw new OutOfMemoryException("Cannot Allocate UTF8String");
|
||||
throw new OutOfMemoryException("Cannot Allocate Utf8String");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -136,7 +63,6 @@ namespace SDL2
|
|||
Contract.Ensures((_capacity >= s.Length + 1), "capacity_greater_than_input");
|
||||
Contract.Ensures(ReferenceEquals(s, String()) || (String().Equals(s)), "string_set");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Access
|
||||
|
@ -144,35 +70,49 @@ namespace SDL2
|
|||
/// Access to the underlying unmanaged memory.
|
||||
/// </summary>
|
||||
public IntPtr Handle { get { return _handle; } }
|
||||
#endregion
|
||||
|
||||
#region Statics
|
||||
/// <summary>
|
||||
/// Avoid allocating external memory by reusing an internal buffer for the UTF-8 encoded representation of <paramref name="s"/>
|
||||
/// and returns a pointer to that representation.
|
||||
/// </summary>
|
||||
public static UTF8String ReusableBuffer(string s)
|
||||
/// <remarks>Consecutive calls to this routine will invalidate any previous calls. Use <see cref="ReusableBufferPtrBis"/> when you need another handle.</remarks>
|
||||
/// <param name="s">String to encode.</param>
|
||||
public static IntPtr ReusableBufferPtr(string s)
|
||||
{
|
||||
if (_buffer1 == null)
|
||||
var buf = _buffer1;
|
||||
if (buf == null)
|
||||
{
|
||||
_buffer1 = new UTF8StringCell(s);
|
||||
buf = new Utf8String(s);
|
||||
_buffer1 = buf;
|
||||
}
|
||||
else
|
||||
{
|
||||
_buffer1.SetString(s);
|
||||
buf.SetString(s);
|
||||
}
|
||||
return _buffer1._item;
|
||||
return buf._handle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Avoid allocating external memory by reusing an internal buffer for the UTF-8 encoded representation of <paramref name="s"/>
|
||||
/// and returns a pointer to that representation.
|
||||
/// </summary>
|
||||
public static UTF8String ReusableBufferBis(string s)
|
||||
/// <remarks>Consecutive calls to this routine will invalidate any previous calls. Use <see cref="ReusableBufferPtr"/> when you need another handle.</remarks>
|
||||
/// <param name="s">String to encode.</param>
|
||||
public static IntPtr ReusableBufferPtrBis(string s)
|
||||
{
|
||||
if (_buffer2 == null)
|
||||
var buf = _buffer2;
|
||||
if (buf == null)
|
||||
{
|
||||
_buffer2 = new UTF8StringCell(s);
|
||||
buf = new Utf8String(s);
|
||||
_buffer2 = buf;
|
||||
}
|
||||
else
|
||||
{
|
||||
_buffer2.SetString(s);
|
||||
buf.SetString(s);
|
||||
}
|
||||
return _buffer2._item;
|
||||
return buf._handle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -194,7 +134,7 @@ namespace SDL2
|
|||
long nb = ptr - o;
|
||||
if (nb > int.MaxValue)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("UTF-8 string too large");
|
||||
throw new ArgumentOutOfRangeException("UTF-8 string `o' is too large");
|
||||
}
|
||||
#if !NET46
|
||||
byte[] bytes = new byte[nb];
|
||||
|
@ -211,7 +151,7 @@ namespace SDL2
|
|||
/// </summary>
|
||||
public static string String(IntPtr o)
|
||||
{
|
||||
return UTF8String.String((byte*)o);
|
||||
return String((byte*)o);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -223,7 +163,7 @@ namespace SDL2
|
|||
{
|
||||
#if !NET46
|
||||
byte[] bytes = new byte[n];
|
||||
Marshal.Copy((IntPtr)o, bytes, 0, (int)n);
|
||||
Marshal.Copy((IntPtr)o, bytes, 0, n);
|
||||
return Encoding.UTF8.GetString(bytes, 0, n);
|
||||
#else
|
||||
return Encoding.UTF8.GetString((byte*) o, n);
|
||||
|
@ -235,7 +175,7 @@ namespace SDL2
|
|||
/// </summary>
|
||||
public static string String(IntPtr o, int n)
|
||||
{
|
||||
return UTF8String.String((byte*)o, n);
|
||||
return String((byte*)o, n);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -244,7 +184,7 @@ namespace SDL2
|
|||
/// <returns></returns>
|
||||
public string String()
|
||||
{
|
||||
return UTF8String.String(_handle, _count);
|
||||
return String(_handle, _count);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -266,12 +206,12 @@ namespace SDL2
|
|||
if (nb >= _capacity)
|
||||
{
|
||||
// By default increase size by the max of 50% or new capacity nb.
|
||||
int newSize = System.Math.Max(_capacity + _capacity / 2, nb + 1);
|
||||
int newSize = Math.Max(_capacity + _capacity / 2, nb + 1);
|
||||
IntPtr lPtr = SDL.SDL_realloc(_handle, (IntPtr) newSize);
|
||||
if (lPtr == IntPtr.Zero)
|
||||
{
|
||||
Dispose();
|
||||
throw new OutOfMemoryException("Cannot reallocate UTF8String");
|
||||
throw new OutOfMemoryException("Cannot reallocate Utf8String");
|
||||
}
|
||||
_handle = lPtr;
|
||||
_capacity = newSize;
|
||||
|
@ -292,7 +232,7 @@ namespace SDL2
|
|||
|
||||
#region Dispose
|
||||
/// <summary>
|
||||
/// Free allocated memory.
|
||||
/// Free external memory held by current.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
|
@ -304,6 +244,25 @@ namespace SDL2
|
|||
_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finalizer to free external memory held by current if not already done.
|
||||
/// </summary>
|
||||
~Utf8String()
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Explicit interface implementation of the Dispose pattern.
|
||||
/// </summary>
|
||||
void IDisposable.Dispose()
|
||||
{
|
||||
Dispose();
|
||||
// No need to have the finalizer running now.
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementation: Accesss
|
||||
|
@ -322,8 +281,8 @@ namespace SDL2
|
|||
/// </summary>
|
||||
private IntPtr _handle;
|
||||
|
||||
[ThreadStatic] private static UTF8StringCell _buffer1;
|
||||
[ThreadStatic] private static UTF8StringCell _buffer2;
|
||||
[ThreadStatic] private static Utf8String _buffer1;
|
||||
[ThreadStatic] private static Utf8String _buffer2;
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче