mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
Use LibraryImport for custom ImGuiNative functinos
This commit is contained in:
parent
1a15600a8f
commit
334a02e69a
4 changed files with 72 additions and 41 deletions
|
|
@ -1,6 +1,6 @@
|
|||
namespace Dalamud.Bindings.ImGui;
|
||||
|
||||
public enum ImDrawCallbackEnum
|
||||
public enum ImDrawCallbackEnum : long
|
||||
{
|
||||
Empty,
|
||||
|
||||
|
|
@ -11,5 +11,5 @@ public enum ImDrawCallbackEnum
|
|||
/// state, and you want it to be restored. It is not done by default because they are many perfectly useful way of
|
||||
/// altering render state for imgui contents (e.g. changing shader/blending settings before an Image call).
|
||||
/// </summary>
|
||||
ResetRenderState = -1,
|
||||
ResetRenderState = ImGui.ImDrawCallbackResetRenderState,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
|
|
@ -160,17 +161,15 @@ public unsafe partial class ImGui
|
|||
{
|
||||
var dataBuffer = PointerTuple.Create(&callback);
|
||||
#pragma warning restore CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type
|
||||
var r =
|
||||
((delegate* unmanaged[Cdecl]<byte*, byte*, byte*, int, Vector2, ImGuiInputTextFlags, delegate* unmanaged
|
||||
<ImGuiInputTextCallbackData*, int>, void*, byte>)ImGui.funcTable[1277])(
|
||||
labelPtr,
|
||||
hintPtr,
|
||||
bufPtr,
|
||||
buf.Length,
|
||||
sizeArg,
|
||||
flags,
|
||||
callback == null ? null : &InputTextCallbackStatic,
|
||||
callback == null ? null : &dataBuffer) != 0;
|
||||
var r = ImGuiNative.InputTextEx(
|
||||
labelPtr,
|
||||
hintPtr,
|
||||
bufPtr,
|
||||
buf.Length,
|
||||
sizeArg,
|
||||
flags,
|
||||
callback == null ? null : &InputTextCallbackStatic,
|
||||
callback == null ? null : &dataBuffer) != 0;
|
||||
label.Dispose();
|
||||
hint.Dispose();
|
||||
return r;
|
||||
|
|
@ -189,17 +188,15 @@ public unsafe partial class ImGui
|
|||
{
|
||||
var dataBuffer = PointerTuple.Create(&callback, contextPtr);
|
||||
#pragma warning restore CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type
|
||||
var r =
|
||||
((delegate* unmanaged[Cdecl]<byte*, byte*, byte*, int, Vector2, ImGuiInputTextFlags, delegate* unmanaged
|
||||
<ImGuiInputTextCallbackData*, int>, void*, byte>)ImGui.funcTable[1277])(
|
||||
labelPtr,
|
||||
hintPtr,
|
||||
bufPtr,
|
||||
buf.Length,
|
||||
sizeArg,
|
||||
flags,
|
||||
&InputTextCallbackRefContextStatic,
|
||||
&dataBuffer) != 0;
|
||||
var r = ImGuiNative.InputTextEx(
|
||||
labelPtr,
|
||||
hintPtr,
|
||||
bufPtr,
|
||||
buf.Length,
|
||||
sizeArg,
|
||||
flags,
|
||||
&InputTextCallbackRefContextStatic,
|
||||
&dataBuffer) != 0;
|
||||
label.Dispose();
|
||||
hint.Dispose();
|
||||
return r;
|
||||
|
|
@ -218,17 +215,15 @@ public unsafe partial class ImGui
|
|||
{
|
||||
var dataBuffer = PointerTuple.Create(&callback, contextPtr);
|
||||
#pragma warning restore CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type
|
||||
var r =
|
||||
((delegate* unmanaged[Cdecl]<byte*, byte*, byte*, int, Vector2, ImGuiInputTextFlags, delegate* unmanaged
|
||||
<ImGuiInputTextCallbackData*, int>, void*, byte>)ImGui.funcTable[1277])(
|
||||
labelPtr,
|
||||
hintPtr,
|
||||
bufPtr,
|
||||
buf.Length,
|
||||
sizeArg,
|
||||
flags,
|
||||
&InputTextCallbackInContextStatic,
|
||||
&dataBuffer) != 0;
|
||||
var r = ImGuiNative.InputTextEx(
|
||||
labelPtr,
|
||||
hintPtr,
|
||||
bufPtr,
|
||||
buf.Length,
|
||||
sizeArg,
|
||||
flags,
|
||||
&InputTextCallbackInContextStatic,
|
||||
&dataBuffer) != 0;
|
||||
label.Dispose();
|
||||
hint.Dispose();
|
||||
return r;
|
||||
|
|
@ -445,21 +440,21 @@ public unsafe partial class ImGui
|
|||
return r;
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])]
|
||||
private static int InputTextCallbackStatic(ImGuiInputTextCallbackData* data)
|
||||
{
|
||||
ref var dvps = ref PointerTuple.From<ImGuiInputTextCallbackDelegate>(data->UserData);
|
||||
return dvps.Item1.Invoke(ref *data);
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])]
|
||||
private static int InputTextCallbackRefContextStatic(ImGuiInputTextCallbackData* data)
|
||||
{
|
||||
ref var dvps = ref PointerTuple.From<ImGuiInputTextCallbackRefContextDelegate<object>, object>(data->UserData);
|
||||
return dvps.Item1.Invoke(ref *data, ref dvps.Item2);
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly]
|
||||
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])]
|
||||
private static int InputTextCallbackInContextStatic(ImGuiInputTextCallbackData* data)
|
||||
{
|
||||
ref var dvps = ref PointerTuple.From<ImGuiInputTextCallbackInContextDelegate<object>, object>(data->UserData);
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@ public static unsafe partial class ImGui
|
|||
{
|
||||
public static void AddCallback(
|
||||
ImDrawListPtr self, delegate*<ImDrawList*, ImDrawCmd*, void> callback, void* callbackData = null) =>
|
||||
((delegate* unmanaged[Cdecl]<ImDrawList*, delegate*<ImDrawList*, ImDrawCmd*, void>, void*, void>)funcTable
|
||||
[540])(self, callback, callbackData);
|
||||
ImGuiNative.AddCallback(self, callback, callbackData);
|
||||
|
||||
public static void AddCallback(
|
||||
ImDrawListPtr self, delegate*<ImDrawListPtr, ImDrawCmdPtr, void> callback, void* callbackData = null) =>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,40 @@
|
|||
using System.Numerics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Dalamud.Bindings.ImGui;
|
||||
|
||||
public static partial class ImGuiNative;
|
||||
public static unsafe partial class ImGuiNative
|
||||
{
|
||||
private const string LibraryName = "cimgui";
|
||||
|
||||
static ImGuiNative()
|
||||
{
|
||||
if (LibraryName != ImGui.GetLibraryName())
|
||||
{
|
||||
throw new(
|
||||
$"{nameof(LibraryName)}(={LibraryName})" +
|
||||
$" does not match " +
|
||||
$"{nameof(ImGui)}.{nameof(ImGui.GetLibraryName)}(={ImGui.GetLibraryName()})");
|
||||
}
|
||||
}
|
||||
|
||||
[LibraryImport($"{LibraryName}.dll", EntryPoint = "ImDrawList_AddCallback")]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
public static partial void AddCallback(
|
||||
ImDrawList* self,
|
||||
delegate*<ImDrawList*, ImDrawCmd*, void> callback,
|
||||
void* callbackData = null);
|
||||
|
||||
[LibraryImport($"{LibraryName}.dll", EntryPoint = "igInputTextEx")]
|
||||
[UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
|
||||
public static partial int InputTextEx(
|
||||
byte* label,
|
||||
byte* hint,
|
||||
byte* buf,
|
||||
int bufSize,
|
||||
Vector2 sizeArg,
|
||||
ImGuiInputTextFlags flags = ImGuiInputTextFlags.None,
|
||||
delegate* unmanaged[Cdecl]<ImGuiInputTextCallbackData*, int> callback = null,
|
||||
void* userData = null);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue