mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-29 06:28:25 +01:00
first
This commit is contained in:
parent
bd62d51ec9
commit
b578433e37
3 changed files with 784842 additions and 0 deletions
120
Brutal.ImGui/Manual/Functions/ImDrawList.cs
Normal file
120
Brutal.ImGui/Manual/Functions/ImDrawList.cs
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
namespace Brutal.ImGuiApi;
|
||||
|
||||
public static partial class ImDrawListExtensions
|
||||
{
|
||||
/// <remarks><code>
|
||||
/// Image primitives
|
||||
/// - Read FAQ to understand what ImTextureID/ImTextureRef are.
|
||||
/// - "p_min" and "p_max" represent the upper-left and lower-right corners of the rectangle.
|
||||
/// - "uv_min" and "uv_max" represent the normalized texture coordinates to use for those corners. Using (0,0)->(1,1) texture coordinates will generally display the entire texture.
|
||||
/// </code></remarks>
|
||||
/// <source href="https://github.com/ocornut/imgui/blob/v1.92.2-docking/imgui.h#L3407"><a href="https://github.com/ocornut/imgui/blob/v1.92.2-docking/imgui.h#L3407">imgui.h:3407</a></source>
|
||||
/// <br/>
|
||||
/// <declaration><c>void AddImage(ImTextureRef tex_ref, const ImVec2& p_min, const ImVec2& p_max, const ImVec2& uv_min = ImVec2(0, 0), const ImVec2& uv_max = ImVec2(1, 1), ImU32 col = IM_COL32_WHITE)</c></declaration>
|
||||
public static void AddImage(
|
||||
this ImDrawListPtr target,
|
||||
ImTextureRef texRef,
|
||||
in float2 pMin,
|
||||
in float2 pMax,
|
||||
in float2? uvMin = default,
|
||||
in float2? uvMax = default,
|
||||
ImColor8? col = default
|
||||
)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
var uvMin_default = uvMin ?? new float2(0f, 0f);
|
||||
var uvMax_default = uvMax ?? new float2(1f, 1f);
|
||||
var col_default = col ?? new byte4(255);
|
||||
fixed (float2* pMax_fixed = &pMax)
|
||||
fixed (float2* pMin_fixed = &pMin)
|
||||
{
|
||||
ImGui.PInvoke.ImDrawList_AddImage(
|
||||
target,
|
||||
texRef,
|
||||
pMin_fixed,
|
||||
pMax_fixed,
|
||||
&uvMin_default,
|
||||
&uvMax_default,
|
||||
col_default
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <remarks><code>
|
||||
/// Image primitives
|
||||
/// - Read FAQ to understand what ImTextureID/ImTextureRef are.
|
||||
/// - "p_min" and "p_max" represent the upper-left and lower-right corners of the rectangle.
|
||||
/// - "uv_min" and "uv_max" represent the normalized texture coordinates to use for those corners. Using (0,0)->(1,1) texture coordinates will generally display the entire texture.
|
||||
/// </code></remarks>
|
||||
/// <source href="https://github.com/ocornut/imgui/blob/v1.92.2-docking/imgui.h#L3408"><a href="https://github.com/ocornut/imgui/blob/v1.92.2-docking/imgui.h#L3408">imgui.h:3408</a></source>
|
||||
/// <br/>
|
||||
/// <declaration><c>void AddImageQuad(ImTextureRef tex_ref, const ImVec2& p1, const ImVec2& p2, const ImVec2& p3, const ImVec2& p4, const ImVec2& uv1 = ImVec2(0, 0), const ImVec2& uv2 = ImVec2(1, 0), const ImVec2& uv3 = ImVec2(1, 1), const ImVec2& uv4 = ImVec2(0, 1), ImU32 col = IM_COL32_WHITE)</c></declaration>
|
||||
public static void AddImageQuad(
|
||||
this ImDrawListPtr target,
|
||||
ImTextureRef texRef,
|
||||
in float2 p1,
|
||||
in float2 p2,
|
||||
in float2 p3,
|
||||
in float2 p4,
|
||||
in float2? uv1 = default,
|
||||
in float2? uv2 = default,
|
||||
in float2? uv3 = default,
|
||||
in float2? uv4 = default,
|
||||
ImColor8? col = default
|
||||
)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
var uv1_default = uv1 ?? new float2(0f, 0f);
|
||||
var uv2_default = uv2 ?? new float2(1f, 0f);
|
||||
var uv3_default = uv3 ?? new float2(1f, 1f);
|
||||
var uv4_default = uv4 ?? new float2(0f, 1f);
|
||||
var col_default = col ?? new byte4(255);
|
||||
fixed (float2* p4_fixed = &p4)
|
||||
fixed (float2* p3_fixed = &p3)
|
||||
fixed (float2* p2_fixed = &p2)
|
||||
fixed (float2* p1_fixed = &p1)
|
||||
{
|
||||
ImGui.PInvoke.ImDrawList_AddImageQuad(
|
||||
target,
|
||||
texRef,
|
||||
p1_fixed,
|
||||
p2_fixed,
|
||||
p3_fixed,
|
||||
p4_fixed,
|
||||
&uv1_default,
|
||||
&uv2_default,
|
||||
&uv3_default,
|
||||
&uv4_default,
|
||||
col_default
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <remarks><code>
|
||||
/// Advanced: Draw Callbacks
|
||||
/// - May be used to alter render state (change sampler, blending, current shader).
|
||||
/// - May be used to emit custom rendering commands (difficult to do correctly, but possible).
|
||||
/// - Use special ImDrawCallback_ResetRenderState callback to instruct backend to reset its render state to the default.
|
||||
/// - Your rendering loop must check for 'UserCallback' in ImDrawCmd and call the function instead of rendering triangles. (All standard backends are honoring this.)
|
||||
/// </code></remarks>
|
||||
/// <summary>
|
||||
/// User data is copied to a backing buffer by ImGui internals, and the callback points to the copy for user data
|
||||
/// </summary>
|
||||
public static unsafe void AddCallback<T>(this ImDrawListPtr target, ImDrawCallback callback, in T userData)
|
||||
where T : unmanaged
|
||||
{
|
||||
fixed (void* ptr = &userData)
|
||||
{
|
||||
PInvoke.ImDrawList_AddCallback(
|
||||
target,
|
||||
Marshal.GetFunctionPointerForDelegate(callback),
|
||||
ptr,
|
||||
(UIntPtr)ByteSize.Of<T>()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
45
Brutal.ImGui/Manual/Functions/ImGui.Text.cs
Normal file
45
Brutal.ImGui/Manual/Functions/ImGui.Text.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
namespace Brutal.ImGuiApi;
|
||||
|
||||
public partial class ImGui
|
||||
{
|
||||
// Manually wrap PInvoke.TextUnformatted() as Managed.Text(), as rules don't have renaming support.
|
||||
|
||||
/// <summary>
|
||||
/// <para>raw text without formatting. Roughly equivalent to Text("%s", text) but: A) doesn't require null terminated string if 'text_end' is specified, B) it's faster, no memory copy is done, no buffer size limits, recommended for long chunks of text.</para>
|
||||
/// <para>
|
||||
/// C++: <a href="https://github.com/ocornut/imgui/blob/v1.92.2-docking/imgui.h#L614">imgui.h:614</a>, <a href="https://github.com/ocornut/imgui/blob/v1.92.2-docking/imgui_widgets.cpp#L268">imgui_widgets.cpp:268</a>
|
||||
/// <br/>
|
||||
/// <c>void TextUnformatted(const char* text, const char* text_end = NULL)</c>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <remarks>Widgets: Text</remarks>
|
||||
public static void Text(ImString text)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* text_fixed = text)
|
||||
{
|
||||
PInvoke.TextUnformatted(text_fixed, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public partial class Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// C++: <a href="https://github.com/ocornut/imgui/blob/v1.92.2-docking/imgui.h#L616">imgui.h:616</a>, <a href="https://github.com/ocornut/imgui/blob/v1.92.2-docking/imgui_widgets.cpp#L281">imgui_widgets.cpp:281</a>
|
||||
/// <br/>
|
||||
/// <c>void TextV(const char* fmt, va_list args) IM_FMTLIST(1)</c>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <remarks>Uses C++/printf-style formatting: %d, %f etc.
|
||||
/// <br/>C# has better options, but this could be useful for compatibility, porting C++ code etc.</remarks>
|
||||
public static unsafe void TextFormatted(ImString fmt, params ReadOnlySpan<VariadicArgument> args)
|
||||
{
|
||||
fixed (byte* fmt_fixed = fmt)
|
||||
fixed (byte* vaList_fixed = VaList.Pack(stackalloc byte[VaList.GetSize(args)], args))
|
||||
PInvoke.TextV(fmt_fixed, vaList_fixed);
|
||||
}
|
||||
}
|
||||
}
|
||||
385
Brutal.ImGui/Manual/Functions/ImGui.cs
Normal file
385
Brutal.ImGui/Manual/Functions/ImGui.cs
Normal file
|
|
@ -0,0 +1,385 @@
|
|||
using System.Buffers;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Brutal.ImGuiApi;
|
||||
|
||||
/*
|
||||
* NOTE: we want ImGui non-static to allow extensions -> make it abstract instead
|
||||
* (static == abstract sealed, so we just don't seal it).
|
||||
*
|
||||
* If we want to roll back on that decision, this is the only place we should add `static`,
|
||||
* (ie not in the dozens of auto-generated files).
|
||||
*/
|
||||
public abstract partial class ImGui
|
||||
{
|
||||
/// <inheritdoc cref="PInvoke.LoadIniSettingsFromMemory"/>
|
||||
public static void LoadIniSettingsFromMemory(ImString iniData)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* iniData_fixed = iniData)
|
||||
{
|
||||
PInvoke.LoadIniSettingsFromMemory(iniData_fixed, (nuint)iniData.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="PInvoke.SaveIniSettingsToMemory"/>
|
||||
public static ImString SaveIniSettingsToMemory()
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
nuint outIniSize;
|
||||
var resultPtr = PInvoke.SaveIniSettingsToMemory(&outIniSize);
|
||||
return new ReadOnlySpan<byte>(resultPtr, (int)outIniSize);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="PInvoke.Combo_0"/>
|
||||
public static unsafe bool Combo(
|
||||
ImString label,
|
||||
ref int currentItem,
|
||||
ReadOnlySpan<Ptr<byte>> items,
|
||||
int popupMaxHeightInItems = -1
|
||||
)
|
||||
{
|
||||
fixed (Ptr<byte>* pointers = items)
|
||||
fixed (int* currentItem_fixed = ¤tItem)
|
||||
fixed (byte* label_fixed = label)
|
||||
{
|
||||
return PInvoke.Combo_0(
|
||||
label_fixed,
|
||||
currentItem_fixed,
|
||||
(byte**)pointers,
|
||||
items.Length,
|
||||
popupMaxHeightInItems
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="PInvoke.Combo_0"/>
|
||||
public static unsafe bool Combo(
|
||||
ImString label,
|
||||
ref int currentItem,
|
||||
scoped RefString8Array items,
|
||||
int popupMaxHeightInItems = -1
|
||||
)
|
||||
{
|
||||
try
|
||||
{
|
||||
fixed (byte* bytePtr = items)
|
||||
{
|
||||
fixed (int* currentItem_fixed = ¤tItem)
|
||||
fixed (byte* label_fixed = label)
|
||||
{
|
||||
return PInvoke.Combo_0(
|
||||
label_fixed,
|
||||
currentItem_fixed,
|
||||
items.CommitFixedRegion(bytePtr),
|
||||
items.Length,
|
||||
popupMaxHeightInItems
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
items.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="PInvoke.ListBox_0"/>
|
||||
public static unsafe bool ListBox(
|
||||
ImString label,
|
||||
ref int currentItem,
|
||||
ReadOnlySpan<Ptr<byte>> items,
|
||||
int heightInItems = -1
|
||||
)
|
||||
{
|
||||
fixed (Ptr<byte>* test = items)
|
||||
fixed (int* currentItem_fixed = ¤tItem)
|
||||
fixed (byte* label_fixed = label)
|
||||
{
|
||||
return PInvoke.ListBox_0(label_fixed, currentItem_fixed, (byte**)test, items.Length, heightInItems);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="PInvoke.ListBox_0"/>
|
||||
public static unsafe bool ListBox(
|
||||
ImString label,
|
||||
ref int currentItem,
|
||||
scoped RefString8Array items,
|
||||
int heightInItems = -1
|
||||
)
|
||||
{
|
||||
try
|
||||
{
|
||||
fixed (byte* bytePtr = items)
|
||||
{
|
||||
fixed (int* currentItem_fixed = ¤tItem)
|
||||
fixed (byte* label_fixed = label)
|
||||
{
|
||||
return PInvoke.ListBox_0(
|
||||
label_fixed,
|
||||
currentItem_fixed,
|
||||
items.CommitFixedRegion(bytePtr),
|
||||
items.Length,
|
||||
heightInItems
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
items.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="PInvoke.InputText"/>
|
||||
public static unsafe bool InputText(
|
||||
ImString label,
|
||||
ImInputString buffer,
|
||||
ImGuiInputTextFlags flags = default,
|
||||
ImGuiInputTextCallback? callback = null,
|
||||
nint userData = 0
|
||||
)
|
||||
{
|
||||
fixed (byte* buffer_fixed = buffer.Buffer)
|
||||
fixed (byte* label_fixed = label)
|
||||
{
|
||||
var result = PInvoke.InputText(
|
||||
label_fixed,
|
||||
buffer_fixed,
|
||||
(nuint)buffer.Capacity,
|
||||
flags,
|
||||
callback is null ? 0 : Marshal.GetFunctionPointerForDelegate(callback),
|
||||
(void*)userData
|
||||
);
|
||||
|
||||
if (result)
|
||||
buffer.EvaluateLength();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="PInvoke.InputTextMultiline"/>
|
||||
public static unsafe bool InputTextMultiline(
|
||||
ImString label,
|
||||
ImInputString buffer,
|
||||
in float2 size = default,
|
||||
ImGuiInputTextFlags flags = default,
|
||||
ImGuiInputTextCallback? callback = null,
|
||||
nint userData = 0
|
||||
)
|
||||
{
|
||||
fixed (byte* buffer_fixed = buffer.Buffer)
|
||||
fixed (float2* size_fixed = &size)
|
||||
fixed (byte* label_fixed = label)
|
||||
{
|
||||
var result = PInvoke.InputTextMultiline(
|
||||
label_fixed,
|
||||
buffer_fixed,
|
||||
(nuint)buffer.Capacity,
|
||||
size_fixed,
|
||||
flags,
|
||||
callback is null ? 0 : Marshal.GetFunctionPointerForDelegate(callback),
|
||||
(void*)userData
|
||||
);
|
||||
|
||||
if (result)
|
||||
buffer.EvaluateLength();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="PInvoke.InputTextWithHint"/>
|
||||
public static unsafe bool InputTextWithHint(
|
||||
ImString label,
|
||||
ImString hint,
|
||||
ImInputString buffer,
|
||||
ImGuiInputTextFlags flags = default,
|
||||
ImGuiInputTextCallback? callback = null,
|
||||
nint userData = 0
|
||||
)
|
||||
{
|
||||
fixed (byte* buffer_fixed = buffer.Buffer)
|
||||
fixed (byte* hint_fixed = hint)
|
||||
fixed (byte* label_fixed = label)
|
||||
{
|
||||
var result = PInvoke.InputTextWithHint(
|
||||
label_fixed,
|
||||
hint_fixed,
|
||||
buffer_fixed,
|
||||
(nuint)buffer.Capacity,
|
||||
flags,
|
||||
callback is null ? 0 : Marshal.GetFunctionPointerForDelegate(callback),
|
||||
(void*)userData
|
||||
);
|
||||
|
||||
if (result)
|
||||
buffer.EvaluateLength();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="PInvoke.GetAllocatorFunctions"/>
|
||||
public static unsafe void GetAllocatorFunctions(
|
||||
out ImGuiMemAllocFunc? pAllocFunc,
|
||||
out ImGuiMemFreeFunc? pFreeFunc,
|
||||
out nint pUserData
|
||||
)
|
||||
{
|
||||
nint pAllocFunc_value = 0;
|
||||
nint pFreeFunc_value = 0;
|
||||
|
||||
fixed (nint* pUserData_ptr = &pUserData)
|
||||
{
|
||||
PInvoke.GetAllocatorFunctions(&pAllocFunc_value, &pFreeFunc_value, (void**)pUserData_ptr);
|
||||
}
|
||||
|
||||
pAllocFunc = pAllocFunc_value is 0
|
||||
? null
|
||||
: Marshal.GetDelegateForFunctionPointer<ImGuiMemAllocFunc>(pAllocFunc_value);
|
||||
|
||||
pFreeFunc = pFreeFunc_value is 0
|
||||
? null
|
||||
: Marshal.GetDelegateForFunctionPointer<ImGuiMemFreeFunc>(pFreeFunc_value);
|
||||
}
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public unsafe delegate byte* ComboGetter(nint userData, int idx);
|
||||
|
||||
/// <inheritdoc cref="PInvoke.Combo_2" />
|
||||
public static bool Combo(
|
||||
ImString label,
|
||||
ref int currentItem,
|
||||
ComboGetter getter,
|
||||
nint userData,
|
||||
int itemsCount,
|
||||
int popupMaxHeightInItems = -1
|
||||
)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (int* currentItem_fixed = ¤tItem)
|
||||
fixed (byte* label_fixed = label)
|
||||
{
|
||||
return PInvoke.Combo_2(
|
||||
label_fixed,
|
||||
currentItem_fixed,
|
||||
Marshal.GetFunctionPointerForDelegate(getter),
|
||||
(void*)userData,
|
||||
itemsCount,
|
||||
popupMaxHeightInItems
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public unsafe delegate byte* ListBoxGetter(nint userData, int idx);
|
||||
|
||||
/// <inheritdoc cref="PInvoke.ListBox_1" />
|
||||
public static bool ListBox(
|
||||
ImString label,
|
||||
ref int currentItem,
|
||||
ListBoxGetter getter,
|
||||
nint userData,
|
||||
int itemsCount,
|
||||
int heightInItems = -1
|
||||
)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (int* currentItem_fixed = ¤tItem)
|
||||
fixed (byte* label_fixed = label)
|
||||
{
|
||||
return PInvoke.ListBox_1(
|
||||
label_fixed,
|
||||
currentItem_fixed,
|
||||
Marshal.GetFunctionPointerForDelegate(getter),
|
||||
(void*)userData,
|
||||
itemsCount,
|
||||
heightInItems
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate float PlotLinesValuesGetter(nint data, int idx);
|
||||
|
||||
/// <inheritdoc cref="PInvoke.PlotLines_1" />
|
||||
public static void PlotLines(
|
||||
ImString label,
|
||||
PlotLinesValuesGetter valuesGetter,
|
||||
nint data,
|
||||
int valuesCount,
|
||||
int valuesOffset = 0,
|
||||
ImString overlayText = default,
|
||||
float scaleMin = float.MaxValue,
|
||||
float scaleMax = float.MaxValue,
|
||||
float2? graphSize = default
|
||||
)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
var graphSize_default = graphSize ?? new float2(0f, 0f);
|
||||
fixed (byte* overlayText_fixed = overlayText)
|
||||
fixed (byte* label_fixed = label)
|
||||
{
|
||||
PInvoke.PlotLines_1(
|
||||
label_fixed,
|
||||
Marshal.GetFunctionPointerForDelegate(valuesGetter),
|
||||
(void*)data,
|
||||
valuesCount,
|
||||
valuesOffset,
|
||||
overlayText_fixed,
|
||||
scaleMin,
|
||||
scaleMax,
|
||||
graphSize_default
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate float PlotHistogramValuesGetter(nint data, int idx);
|
||||
|
||||
/// <inheritdoc cref="PInvoke.PlotHistogram_1" />
|
||||
public static void PlotHistogram(
|
||||
ImString label,
|
||||
PlotHistogramValuesGetter valuesGetter,
|
||||
nint data,
|
||||
int valuesCount,
|
||||
int valuesOffset = 0,
|
||||
ImString overlayText = default,
|
||||
float scaleMin = float.MaxValue,
|
||||
float scaleMax = float.MaxValue,
|
||||
float2? graphSize = default
|
||||
)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
var graphSize_default = graphSize ?? new float2(0f, 0f);
|
||||
fixed (byte* overlayText_fixed = overlayText)
|
||||
fixed (byte* label_fixed = label)
|
||||
{
|
||||
PInvoke.PlotHistogram_1(
|
||||
label_fixed,
|
||||
Marshal.GetFunctionPointerForDelegate(valuesGetter),
|
||||
(void*)data,
|
||||
valuesCount,
|
||||
valuesOffset,
|
||||
overlayText_fixed,
|
||||
scaleMin,
|
||||
scaleMax,
|
||||
graphSize_default
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue