mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-26 13:08:24 +01:00
SOURCE DUMP v1
This commit is contained in:
parent
bd62d51ec9
commit
fb20299e9d
5 changed files with 768360 additions and 0 deletions
|
|
@ -0,0 +1,9 @@
|
|||
using Brutal.ImGuiApi.Internal;
|
||||
|
||||
namespace Brutal.ImGuiApi.Extensions;
|
||||
|
||||
public partial class ImGuiCompatibilityEx
|
||||
{
|
||||
[Obsolete("Use Brutal.ImGuiApi.Internal.ImGui.GetCurrentWindow()", error: false)]
|
||||
public static ImGuiWindowPtr GetCurrentWindow() => Internal.GetCurrentWindow();
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
namespace Brutal.ImGuiApi.Extensions;
|
||||
|
||||
public partial class ImGuiCompatibilityEx
|
||||
{
|
||||
[Obsolete("use ImGui.Text() instead.", error: false)]
|
||||
public static void TextUnformatted(ImString text) => ImGui.Text(text);
|
||||
|
||||
/// <inheritdoc cref="ImGui.Image"/>
|
||||
[Obsolete("use ImageWithBg(ImTextureRef, tintColor: color)", error: false)]
|
||||
public static void Image(ImTextureID user_texture_id, float2 image_size, float4? tint_col = default) =>
|
||||
ImGui.ImageWithBg(new ImTextureRef { _TexID = user_texture_id }, image_size, tintCol: tint_col);
|
||||
|
||||
/// <inheritdoc cref="ImGui.Image"/>
|
||||
[Obsolete("use ImTextureRef overload", error: false)]
|
||||
public static void Image(ImTextureID user_texture_id, float2 image_size, float2 uv0, float2 uv1) =>
|
||||
ImGui.Image(new ImTextureRef { _TexID = user_texture_id }, image_size, uv0, uv1);
|
||||
|
||||
/// <inheritdoc cref="ImGui.PushFont"/>
|
||||
[Obsolete(
|
||||
"PushFont() API now has a REQUIRED size parameter",
|
||||
error: false,
|
||||
UrlFormat = "https://github.com/ocornut/imgui/releases/tag/v1.92.0#:~:text=PushFont()%20API%20now%20has%20a%20REQUIRED%20size%20parameter"
|
||||
)]
|
||||
public static void PushFont(ImFontPtr font) => ImGui.PushFont(font, font.LegacySize);
|
||||
|
||||
[Obsolete(
|
||||
"Prefer using PushFont(null, style.FontSizeBase * factor) or use style.FontScaleMain to scale all windows.",
|
||||
error: false,
|
||||
UrlFormat = "https://github.com/ocornut/imgui/blob/v1.92.2-docking/imgui.h#L4233"
|
||||
)]
|
||||
public static void SetWindowFontScale(float scale) => throw new NotImplementedException();
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
namespace Brutal.ImGuiApi.Extensions;
|
||||
|
||||
public abstract partial class ImGuiCompatibilityEx : ImGui
|
||||
{
|
||||
#region overloads / permutations
|
||||
|
||||
/// <inheritdoc cref="ImGui.PInvoke.InputText"/>
|
||||
[Obsolete("InputText(ref string) is obsolete, use the ImInputString overload instead.", error: false)]
|
||||
public static bool InputText(
|
||||
ImString label,
|
||||
ref string input,
|
||||
uint maxLength,
|
||||
ImGuiInputTextFlags flags = ImGuiInputTextFlags.None,
|
||||
ImGuiInputTextCallback? callback = null,
|
||||
IntPtr userData = 0
|
||||
)
|
||||
{
|
||||
// HACK: this allocates, remove when conversion is done
|
||||
var tmpInput = new ImInputString((int)maxLength, input);
|
||||
var changed = ImGui.InputText(label, tmpInput, flags, callback, userData);
|
||||
if (changed)
|
||||
input = tmpInput.ToString();
|
||||
return changed;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="ImGui.PInvoke.MenuItem_0"/>
|
||||
[Obsolete("use the MenuItem(\"label\", selected: selected) syntax instead.", error: false)]
|
||||
public static bool MenuItem(ImString label, bool selected_obsolete) =>
|
||||
ImGui.MenuItem(label, selected: selected_obsolete);
|
||||
|
||||
/// <inheritdoc cref="ImGui.PInvoke.MenuItem_0"/>
|
||||
[Obsolete("use the MenuItem(\"label\", selected: selected, enabled: enabled) syntax instead.", error: false)]
|
||||
public static bool MenuItem(ImString label, bool selected_obsolete, bool enabled_obsolete) =>
|
||||
ImGui.MenuItem(label, selected: selected_obsolete, enabled: enabled_obsolete);
|
||||
|
||||
/// <inheritdoc cref="ImGui.PInvoke.BeginChild_0"/>
|
||||
[Obsolete("use the BeginChild(\"id\", childFlags: childFlags) syntax instead.", error: false)]
|
||||
public static bool BeginChild(ImString strId, ImGuiChildFlags childFlags_obsolete) =>
|
||||
ImGui.BeginChild(strId, childFlags: childFlags_obsolete);
|
||||
|
||||
/// <inheritdoc cref="ImGui.PInvoke.BeginChild_0"/>
|
||||
[Obsolete("use the BeginChild(\"id\", windowFlags: windowFlags) syntax instead.", error: false)]
|
||||
public static bool BeginChild(ImString strId, float2? size, ImGuiWindowFlags windowFlags_obsolete) =>
|
||||
ImGui.BeginChild(strId, size, windowFlags: windowFlags_obsolete);
|
||||
|
||||
#endregion
|
||||
}
|
||||
2
brutal.imgui/Brutal.ImGui.Extensions/GlobalUsings.cs
Normal file
2
brutal.imgui/Brutal.ImGui.Extensions/GlobalUsings.cs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
global using Brutal.Numerics;
|
||||
global using Brutal.Pointers;
|
||||
315
brutal.imgui/Brutal.ImGui.Extensions/ImGui.extensions.cs
Normal file
315
brutal.imgui/Brutal.ImGui.Extensions/ImGui.extensions.cs
Normal file
|
|
@ -0,0 +1,315 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
using Brutal.Strings;
|
||||
|
||||
namespace Brutal.ImGuiApi.Extensions;
|
||||
|
||||
using static ImGui;
|
||||
|
||||
public static partial class ImGuiEx
|
||||
{
|
||||
public static bool CheckboxFlags<T>(ImString label, ref T flags, T flagsValue)
|
||||
where T : Enum
|
||||
{
|
||||
CheckEnumIsIntSized<T>();
|
||||
return ImGui.CheckboxFlags(label, ref Unsafe.As<T, int>(ref flags), Unsafe.As<T, int>(ref flagsValue));
|
||||
}
|
||||
|
||||
public static bool Combo<T>(
|
||||
ImString label,
|
||||
ref T currentItem,
|
||||
ReadOnlySpan<Ptr<byte>> items,
|
||||
int popupMaxHeightInItems = -1
|
||||
)
|
||||
where T : Enum
|
||||
{
|
||||
CheckEnumIsIntSized<T>();
|
||||
return ImGui.Combo(label, ref Unsafe.As<T, int>(ref currentItem), items, popupMaxHeightInItems);
|
||||
}
|
||||
|
||||
public static bool Combo<T>(
|
||||
ImString label,
|
||||
ref T currentItem,
|
||||
scoped RefString8Array items,
|
||||
int popupMaxHeightInItems = -1
|
||||
)
|
||||
where T : Enum
|
||||
{
|
||||
CheckEnumIsIntSized<T>();
|
||||
return ImGui.Combo(label, ref Unsafe.As<T, int>(ref currentItem), items, popupMaxHeightInItems);
|
||||
}
|
||||
|
||||
public static bool Combo<T>(
|
||||
ImString label,
|
||||
ref T currentItem,
|
||||
ImString itemsSeparatedByZeros,
|
||||
int popupMaxHeightInItems = -1
|
||||
)
|
||||
where T : Enum
|
||||
{
|
||||
CheckEnumIsIntSized<T>();
|
||||
return ImGui.Combo(label, ref Unsafe.As<T, int>(ref currentItem), itemsSeparatedByZeros, popupMaxHeightInItems);
|
||||
}
|
||||
|
||||
public static bool Combo<T>(
|
||||
ImString label,
|
||||
ref T currentItem,
|
||||
ComboGetter getter,
|
||||
nint userData,
|
||||
int itemsCount,
|
||||
int popupMaxHeightInItems = -1
|
||||
)
|
||||
where T : Enum
|
||||
{
|
||||
CheckEnumIsIntSized<T>();
|
||||
return ImGui.Combo(
|
||||
label,
|
||||
ref Unsafe.As<T, int>(ref currentItem),
|
||||
getter,
|
||||
userData,
|
||||
itemsCount,
|
||||
popupMaxHeightInItems
|
||||
);
|
||||
}
|
||||
|
||||
public static bool RadioButton<T>(ImString label, ref T v, T vButton)
|
||||
where T : Enum
|
||||
{
|
||||
CheckEnumIsIntSized<T>();
|
||||
return ImGui.RadioButton(label, ref Unsafe.As<T, int>(ref v), Unsafe.As<T, int>(ref vButton));
|
||||
}
|
||||
|
||||
private static void CheckEnumIsIntSized<T>()
|
||||
where T : Enum
|
||||
{
|
||||
if (Unsafe.SizeOf<T>() != sizeof(int))
|
||||
throw new ArgumentException("Enum must be int sized to be used in this function");
|
||||
}
|
||||
|
||||
/// <remarks>
|
||||
/// Implementation automatically applies the NoAlpha flag, so col.A is ignored
|
||||
/// </remarks>
|
||||
public static bool ColorPicker3(ImString label, ref float4 col, ImGuiColorEditFlags flags = default)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (float4* col_fixed = &col)
|
||||
fixed (byte* label_fixed = label)
|
||||
{
|
||||
return PInvoke.ColorPicker3(label_fixed, (float3*)col_fixed, flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <remarks>
|
||||
/// Implementation automatically applies the NoAlpha flag, so col.A is ignored
|
||||
/// </remarks>
|
||||
public static bool ColorEdit3(ImString label, ref float4 col, ImGuiColorEditFlags flags = default)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (float4* col_fixed = &col)
|
||||
fixed (byte* label_fixed = label)
|
||||
{
|
||||
return PInvoke.ColorEdit3(label_fixed, (float3*)col_fixed, flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool DragScalar<T>(
|
||||
ImString label,
|
||||
ImGuiDataType dataType,
|
||||
ref T pData,
|
||||
float vSpeed = 1f,
|
||||
T? pMin = null,
|
||||
T? pMax = null,
|
||||
ImString format = default,
|
||||
ImGuiSliderFlags flags = default
|
||||
)
|
||||
where T : unmanaged
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
var pMin_ptr = pMin is { } min_value ? &min_value : null;
|
||||
var pMax_ptr = pMax is { } max_value ? &max_value : null;
|
||||
|
||||
fixed (T* pData_fixed = &pData)
|
||||
fixed (byte* format_fixed = format)
|
||||
fixed (byte* label_fixed = label)
|
||||
{
|
||||
return PInvoke.DragScalar(
|
||||
label_fixed,
|
||||
dataType,
|
||||
pData_fixed,
|
||||
vSpeed,
|
||||
pMin_ptr,
|
||||
pMax_ptr,
|
||||
format_fixed,
|
||||
flags
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool SliderScalar<T>(
|
||||
ImString label,
|
||||
ImGuiDataType dataType,
|
||||
ref T pData,
|
||||
T pMin,
|
||||
T pMax,
|
||||
ImString format = default,
|
||||
ImGuiSliderFlags flags = default
|
||||
)
|
||||
where T : unmanaged
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* format_fixed = format)
|
||||
fixed (T* pData_fixed = &pData)
|
||||
fixed (byte* label_fixed = label)
|
||||
{
|
||||
return PInvoke.SliderScalar(label_fixed, dataType, pData_fixed, &pMin, &pMax, format_fixed, flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool InputScalar<T>(
|
||||
ImString label,
|
||||
ImGuiDataType dataType,
|
||||
ref T pData,
|
||||
T? pStep = null,
|
||||
T? pStepFast = null,
|
||||
ImString format = default,
|
||||
ImGuiInputTextFlags flags = default
|
||||
)
|
||||
where T : unmanaged
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
var pStep_ptr = pStep is { } step_value ? &step_value : null;
|
||||
var pStepFast_ptr = pStepFast is { } stepFast_value ? &stepFast_value : null;
|
||||
|
||||
fixed (byte* format_fixed = format)
|
||||
fixed (T* pData_fixed = &pData)
|
||||
fixed (byte* label_fixed = label)
|
||||
{
|
||||
return PInvoke.InputScalar(
|
||||
label_fixed,
|
||||
dataType,
|
||||
pData_fixed,
|
||||
pStep_ptr,
|
||||
pStepFast_ptr,
|
||||
format_fixed,
|
||||
flags
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool DragScalarN<T>(
|
||||
ImString label,
|
||||
ImGuiDataType dataType,
|
||||
Span<T> pData,
|
||||
float vSpeed = 1f,
|
||||
T? pMin = null,
|
||||
T? pMax = null,
|
||||
ImString format = default,
|
||||
ImGuiSliderFlags flags = default
|
||||
)
|
||||
where T : unmanaged
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
var pMin_ptr = pMin is { } min_value ? &min_value : null;
|
||||
var pMax_ptr = pMax is { } max_value ? &max_value : null;
|
||||
|
||||
fixed (T* pData_fixed = pData)
|
||||
fixed (byte* format_fixed = format)
|
||||
fixed (byte* label_fixed = label)
|
||||
{
|
||||
return PInvoke.DragScalarN(
|
||||
label_fixed,
|
||||
dataType,
|
||||
pData_fixed,
|
||||
pData.Length,
|
||||
vSpeed,
|
||||
pMin_ptr,
|
||||
pMax_ptr,
|
||||
format_fixed,
|
||||
flags
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool SliderScalar<T>(
|
||||
ImString label,
|
||||
ImGuiDataType dataType,
|
||||
Span<T> pData,
|
||||
T pMin,
|
||||
T pMax,
|
||||
ImString format = default,
|
||||
ImGuiSliderFlags flags = default
|
||||
)
|
||||
where T : unmanaged
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* format_fixed = format)
|
||||
fixed (T* pData_fixed = pData)
|
||||
fixed (byte* label_fixed = label)
|
||||
{
|
||||
return PInvoke.SliderScalarN(
|
||||
label_fixed,
|
||||
dataType,
|
||||
pData_fixed,
|
||||
pData.Length,
|
||||
&pMin,
|
||||
&pMax,
|
||||
format_fixed,
|
||||
flags
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool InputScalar<T>(
|
||||
ImString label,
|
||||
ImGuiDataType dataType,
|
||||
Span<T> pData,
|
||||
T? pStep = null,
|
||||
T? pStepFast = null,
|
||||
ImString format = default,
|
||||
ImGuiInputTextFlags flags = default
|
||||
)
|
||||
where T : unmanaged
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
var pStep_ptr = pStep is { } step_value ? &step_value : null;
|
||||
var pStepFast_ptr = pStepFast is { } stepFast_value ? &stepFast_value : null;
|
||||
|
||||
fixed (byte* format_fixed = format)
|
||||
fixed (T* pData_fixed = pData)
|
||||
fixed (byte* label_fixed = label)
|
||||
{
|
||||
return PInvoke.InputScalarN(
|
||||
label_fixed,
|
||||
dataType,
|
||||
pData_fixed,
|
||||
pData.Length,
|
||||
pStep_ptr,
|
||||
pStepFast_ptr,
|
||||
format_fixed,
|
||||
flags
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static float4 ColorConvertHSVtoRGB(float4 hsv)
|
||||
{
|
||||
var rgba = new float4 { A = hsv.A };
|
||||
ImGui.ColorConvertHSVtoRGB(hsv.X, hsv.Y, hsv.Z, out rgba.X, out rgba.Y, out rgba.Z);
|
||||
return rgba;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue