mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Almost entirely moved ImGui dependency (and settings) from Engine to Editor
This commit is contained in:
@@ -11,10 +11,6 @@ DirectX = "*"
|
||||
FreeType = "*"
|
||||
cgltf-beef = "*"
|
||||
msdfgen-beef = "*"
|
||||
ImGui = "*"
|
||||
ImGuiImplDX11 = "*"
|
||||
ImGuiImplWin32 = "*"
|
||||
ImGuizmo = "*"
|
||||
Beefy2D = "*"
|
||||
LodePng = "*"
|
||||
GlitchyEngineHelper = "*"
|
||||
@@ -22,6 +18,7 @@ bon = "*"
|
||||
box2d-beef = "*"
|
||||
"Beef.Linq" = "*"
|
||||
NetHostBeef = "*"
|
||||
ImGuiImplWin32 = "*"
|
||||
|
||||
[Configs.Paranoid.Win32]
|
||||
PreprocessorMacros = ["DEBUG", "PARANOID", "GE_WINDOWS"]
|
||||
@@ -33,7 +30,7 @@ PreprocessorMacros = ["DEBUG", "PARANOID", "GE_WINDOWS"]
|
||||
PreprocessorMacros = ["RELEASE", "GE_WINDOWS"]
|
||||
|
||||
[Configs.Release.Win64]
|
||||
PreprocessorMacros = ["IMGUI", "RELEASE", "GE_PROFILE"]
|
||||
PreprocessorMacros = ["RELEASE", "GE_PROFILE", "GE_PROFILE_RENDERER", "GE_PROFILE_RESOURCES", "GE_RESOURCE_DEBUG_NAMES"]
|
||||
|
||||
[Configs.Test.Win32]
|
||||
PreprocessorMacros = ["TEST", "GE_WINDOWS"]
|
||||
@@ -42,4 +39,4 @@ PreprocessorMacros = ["TEST", "GE_WINDOWS"]
|
||||
PreprocessorMacros = ["TEST", "GE_PROFILE", "GE_PROFILE_RENDERER", "GE_PROFILE_RESOURCES", "IMGUI", "GE_RESOURCE_DEBUG_NAMES"]
|
||||
|
||||
[Configs.Debug.Win64]
|
||||
PreprocessorMacros = ["DEBUG", "GE_PROFILE", "GE_PROFILE_RENDERER", "GE_PROFILE_RESOURCES", "IMGUI", "GE_RESOURCE_DEBUG_NAMES"]
|
||||
PreprocessorMacros = ["DEBUG", "GE_PROFILE", "GE_PROFILE_RENDERER", "GE_PROFILE_RESOURCES", "GE_RESOURCE_DEBUG_NAMES"]
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using GlitchyEngine.Events;
|
||||
using GlitchyEngine.ImGui;
|
||||
using GlitchyEngine.Renderer;
|
||||
using GlitchyEngine.Debug;
|
||||
using GlitchyEngine.Content;
|
||||
@@ -22,9 +21,6 @@ namespace GlitchyEngine
|
||||
|
||||
private append LayerStack _layerStack = .();
|
||||
|
||||
#if IMGUI
|
||||
private ImGuiLayer _imGuiLayer;
|
||||
#endif
|
||||
|
||||
private append GameTime _gameTime = .();
|
||||
|
||||
@@ -47,8 +43,6 @@ namespace GlitchyEngine
|
||||
|
||||
public static Application Instance => s_Instance;
|
||||
|
||||
public Settings Settings {get; private set;} = new .() ~ delete _;
|
||||
|
||||
public this()
|
||||
{
|
||||
Profiler.ProfileFunction!();
|
||||
@@ -77,17 +71,6 @@ namespace GlitchyEngine
|
||||
|
||||
Renderer.Init();
|
||||
ScriptEngine.Init();
|
||||
|
||||
#if IMGUI
|
||||
_imGuiLayer = new ImGuiLayer();
|
||||
PushOverlay(_imGuiLayer);
|
||||
#endif
|
||||
|
||||
GlitchyEngine.Settings.Load();
|
||||
Settings.OnApplySettings.Add(new (s, e) => {
|
||||
OnEvent(scope SettingsAppliedEvent());
|
||||
});
|
||||
Settings.Apply();
|
||||
}
|
||||
|
||||
/// Initializes the content manager.
|
||||
@@ -184,7 +167,7 @@ namespace GlitchyEngine
|
||||
if(allowFrame)
|
||||
{
|
||||
#if IMGUI
|
||||
_imGuiLayer.ImGuiRender();
|
||||
//_imGuiLayer.ImGuiRender();
|
||||
#endif
|
||||
|
||||
_window.Context.SwapChain.Present();
|
||||
@@ -214,6 +197,20 @@ namespace GlitchyEngine
|
||||
ownOverlay.OnAttach();
|
||||
}
|
||||
|
||||
public void PopLayer(Layer layer)
|
||||
{
|
||||
Profiler.ProfileFunction!();
|
||||
|
||||
_layerStack.PopLayer(layer);
|
||||
}
|
||||
|
||||
public void PopOverlay(Layer layer)
|
||||
{
|
||||
Profiler.ProfileFunction!();
|
||||
|
||||
_layerStack.PopOverlay(layer);
|
||||
}
|
||||
|
||||
public bool OnWindowClose(WindowCloseEvent e)
|
||||
{
|
||||
_running = false;
|
||||
|
||||
@@ -1,760 +0,0 @@
|
||||
using GlitchyEngine.Math;
|
||||
using GlitchyEngine.Renderer;
|
||||
using System;
|
||||
using GlitchyEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace GlitchyEngine.Math
|
||||
{
|
||||
extension ColorRGBA
|
||||
{
|
||||
internal uint32 ImGuiU32 => ImGui.ImGui.ColorConvertFloat4ToU32((.)(float4)this);
|
||||
}
|
||||
}
|
||||
|
||||
namespace ImGui
|
||||
{
|
||||
using internal GlitchyEngine.Math;
|
||||
|
||||
struct Payload<T> where T : struct
|
||||
{
|
||||
public ImGui.Payload* Payload;
|
||||
|
||||
public T Data => *(T*)Payload.Data;
|
||||
|
||||
public static ImGui.Payload* operator ->(Payload<T> self) => self.Payload;
|
||||
}
|
||||
|
||||
extension ImGui
|
||||
{
|
||||
extension Vec2
|
||||
{
|
||||
public static explicit operator float2(Vec2 v) => .(v.x, v.y);
|
||||
public static explicit operator Vec2(float2 v) => .(v.X, v.Y);
|
||||
}
|
||||
|
||||
extension Vec4
|
||||
{
|
||||
public static explicit operator float4(Vec4 v) => .(v.x, v.y, v.z, v.w);
|
||||
public static explicit operator Vec4(float4 v) => .(v.X, v.Y, v.Z, v.W);
|
||||
}
|
||||
|
||||
extension Color
|
||||
{
|
||||
public static explicit operator ColorRGBA(Color c) => .(c.Value.x, c.Value.y, c.Value.z, c.Value.w);
|
||||
public static explicit operator Color(ColorRGBA c) => .(c.R, c.G, c.B, c.A);
|
||||
}
|
||||
|
||||
enum RectangleSelectionFlags
|
||||
{
|
||||
None,
|
||||
NoRender
|
||||
}
|
||||
|
||||
public struct RectangleSelectionData
|
||||
{
|
||||
public float4 SelectionRectangle;
|
||||
public float2 StartPosition;
|
||||
public bool IsSelecting;
|
||||
}
|
||||
|
||||
|
||||
public static bool BeginRectangleSelection(ref RectangleSelectionData selectionData, bool isMouseDown, RectangleSelectionFlags flags = .None)
|
||||
{
|
||||
float2 minRegion = (.)ImGui.GetWindowPos();
|
||||
float2 maxRegion = (.)ImGui.GetCursorPos() + minRegion + (float2)ImGui.GetContentRegionAvail();
|
||||
|
||||
// ImGui.DrawRect((.)minRegion, (.)maxRegion, ImGui.Color(0,1f,0));
|
||||
|
||||
if (isMouseDown)
|
||||
{
|
||||
if (!selectionData.IsSelecting && IsWindowHovered() && !IsAnyItemHovered())
|
||||
{
|
||||
selectionData.StartPosition = (float2)ImGui.GetMousePos() - (float2)ImGui.GetCursorScreenPos();
|
||||
selectionData.IsSelecting = true;
|
||||
}
|
||||
|
||||
selectionData.SelectionRectangle.ZW = (float2)ImGui.GetMousePos();
|
||||
}
|
||||
else
|
||||
{
|
||||
selectionData.IsSelecting = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
selectionData.SelectionRectangle.XY = (float2)selectionData.StartPosition + (float2)ImGui.GetCursorScreenPos();
|
||||
|
||||
selectionData.SelectionRectangle.ZW = clamp(selectionData.SelectionRectangle.ZW, minRegion, maxRegion);
|
||||
|
||||
|
||||
if (!flags.HasFlag(.NoRender) && selectionData.IsSelecting)
|
||||
{
|
||||
let drawList = ImGui.GetForegroundDrawList();
|
||||
|
||||
float2 clampedStartPoint = clamp(selectionData.SelectionRectangle.XY, minRegion, maxRegion);
|
||||
|
||||
drawList.AddRect((.)clampedStartPoint.XY, (.)selectionData.SelectionRectangle.ZW, ImGui.GetColorU32(ImGui.Color(0, 130, 216, 255).Value));
|
||||
drawList.AddRectFilled((.)clampedStartPoint.XY, (.)selectionData.SelectionRectangle.ZW, ImGui.GetColorU32(ImGui.Color(0, 130, 216, 50).Value));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Returns true if the user is currently doing a rectangle selection
|
||||
public static bool IsRectangleSelecting(ref RectangleSelectionData selectionData)
|
||||
{
|
||||
return selectionData.IsSelecting;
|
||||
}
|
||||
|
||||
/// Returns true if the current item is intersecting the selection rectangle
|
||||
public static bool IsInRectangleSelection(ref RectangleSelectionData selectionData)
|
||||
{
|
||||
if (!selectionData.IsSelecting)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// ImGui.DebugDrawItemRect();
|
||||
|
||||
float2 minRect = (.)ImGui.GetItemRectMin();
|
||||
float2 maxRect = (.)ImGui.GetItemRectMax();
|
||||
|
||||
float2 topLeft = min(minRect, maxRect);
|
||||
float2 bottomRight = max(minRect, maxRect);
|
||||
|
||||
Rectangle itemRectangle = .(topLeft, 0);
|
||||
itemRectangle.BottomRight = bottomRight;
|
||||
|
||||
float2 selectionTopLeft = min(selectionData.SelectionRectangle.XY, selectionData.SelectionRectangle.ZW);
|
||||
float2 selectionTottomRight = max(selectionData.SelectionRectangle.XY, selectionData.SelectionRectangle.ZW);
|
||||
|
||||
Rectangle rect = .(selectionTopLeft, 0);
|
||||
rect.BottomRight = selectionTottomRight;
|
||||
|
||||
return rect.Intersects(itemRectangle);
|
||||
}
|
||||
|
||||
public static Payload<T>? AcceptDragDropPayload<T>(char8* type, DragDropFlags flags = .None) where T : struct
|
||||
{
|
||||
ImGui.Payload* payload = ImGui.AcceptDragDropPayload(type, flags);
|
||||
|
||||
if (payload == null)
|
||||
return null;
|
||||
|
||||
Log.ClientLogger.AssertDebug(payload.DataSize >= sizeof(T));
|
||||
|
||||
var typedPayload = Payload<T>();
|
||||
typedPayload.Payload = payload;
|
||||
|
||||
return typedPayload;
|
||||
}
|
||||
|
||||
/*public static bool IsItemJustDeactivated()
|
||||
{
|
||||
return IsItemDeactivatedAfterEdit();
|
||||
}
|
||||
|
||||
public static bool IsItemActiveLastFrame()
|
||||
{
|
||||
Context* g = GetCurrentContext();
|
||||
if (g.ActiveIdPreviousFrame != 0)
|
||||
return g.ActiveIdPreviousFrame == g.CurrentWindow.DC.LastItemId;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsItemJustActivated()
|
||||
{
|
||||
return IsItemActive() && !IsItemActiveLastFrame();
|
||||
}
|
||||
|
||||
public static bool IsItemEditing()
|
||||
{
|
||||
return IsItemActive();
|
||||
}*/
|
||||
|
||||
public static void PushStyleVar(StyleVar styleVar, float2 value) => PushStyleVar(styleVar, (Vec2)value);
|
||||
|
||||
// TODO: Color-functions
|
||||
public static bool ColorEdit3(char* label, ref ColorRGB col, ColorEditFlags flags = (ColorEditFlags) 0) => ColorEdit3Impl(label, *(float[3]*)&col, flags);
|
||||
public static bool ColorEdit3(char* label, ref ColorRGBA col, ColorEditFlags flags = (ColorEditFlags) 0) => ColorEdit3Impl(label, *(float[3]*)&col, flags);
|
||||
|
||||
public static bool ColorEdit4(char* label, ref ColorRGBA col, ColorEditFlags flags = (ColorEditFlags) 0) => ColorEdit4Impl(label, *(float[4]*)&col, flags);
|
||||
|
||||
public static bool ColorPicker3(char* label, ref ColorRGB col, ColorEditFlags flags = (ColorEditFlags) 0) => ColorPicker3Impl(label, *(float[3]*)&col, flags);
|
||||
public static bool ColorPicker3(char* label, ref ColorRGBA col, ColorEditFlags flags = (ColorEditFlags) 0) => ColorPicker3Impl(label, *(float[3]*)&col, flags);
|
||||
|
||||
public static bool ColorPicker4(char* label, ref ColorRGBA col, ColorEditFlags flags = (ColorEditFlags) 0, float* ref_col = null) => ColorPicker4Impl(label, *(float[4]*)&col, flags, ref_col);
|
||||
|
||||
public static void Image(Texture2D texture, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 tint_col = Vec4.Ones, Vec4 border_col = Vec4.Zero)
|
||||
{
|
||||
Image(texture.GetViewBinding(), size, uv0, uv1, tint_col, border_col);
|
||||
}
|
||||
|
||||
public static void Image(SubTexture2D subTexture, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 tint_col = Vec4.Ones, Vec4 border_col = Vec4.Zero)
|
||||
{
|
||||
if (uv0 != .Zero || uv1 != .Ones)
|
||||
Runtime.NotImplemented();
|
||||
|
||||
float2 v = (.)subTexture.TexCoords.XY + subTexture.TexCoords.ZW;
|
||||
|
||||
Image(subTexture.Texture.GetViewBinding(), size, (.)subTexture.TexCoords.XY, (.)v, tint_col, border_col);
|
||||
}
|
||||
|
||||
public static void Image(RenderTarget2D texture, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 tint_col = Vec4.Ones, Vec4 border_col = Vec4.Zero)
|
||||
{
|
||||
Image(texture.GetViewBinding(), size, uv0, uv1, tint_col, border_col);
|
||||
}
|
||||
|
||||
public static extern void Image(TextureViewBinding textureViewBinding, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 tint_col = Vec4.Ones, Vec4 border_col = Vec4.Zero);
|
||||
|
||||
public static bool ImageButton(char8* id, SubTexture2D subTexture, Vec2 imageSize, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 bg_col = Vec4.Zero, Vec4 tint_col = Vec4.Ones)
|
||||
{
|
||||
if (uv0 != .Zero || uv1 != .Ones)
|
||||
Runtime.NotImplemented();
|
||||
|
||||
float2 v = (.)subTexture.TexCoords.XY + subTexture.TexCoords.ZW;
|
||||
|
||||
return ImageButton(id, subTexture.Texture.GetViewBinding(), imageSize, (.)subTexture.TexCoords.XY, (.)v, bg_col, tint_col);
|
||||
}
|
||||
|
||||
public static extern bool ImageButton(char8* id, TextureViewBinding textureViewBinding, Vec2 imageSize, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 bg_col = Vec4.Zero, Vec4 tint_col = Vec4.Ones);
|
||||
|
||||
public static bool ImageButtonEx(uint32 id, SubTexture2D subTexture, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 bg_col = Vec4.Zero, Vec4 tint_col = Vec4.Ones)
|
||||
{
|
||||
if (uv0 != .Zero || uv1 != .Ones)
|
||||
Runtime.NotImplemented();
|
||||
|
||||
float2 v = (.)subTexture.TexCoords.XY + subTexture.TexCoords.ZW;
|
||||
|
||||
return ImageButtonEx(id, subTexture.Texture.GetViewBinding(), size, (.)subTexture.TexCoords.XY, (.)v, bg_col, tint_col);
|
||||
}
|
||||
|
||||
public static extern bool ImageButtonEx(uint32 id, TextureViewBinding textureViewBinding, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 bg_col = Vec4.Zero, Vec4 tint_col = Vec4.Ones);
|
||||
|
||||
public static void TextUnformatted(StringView text) => TextUnformattedImpl(text.Ptr, text.Ptr + text.Length);
|
||||
|
||||
public static void PushID(StringView id) => PushID(id.Ptr, id.Ptr + id.Length);
|
||||
|
||||
public static void PushID(int id) => PushID((void*)id);
|
||||
|
||||
/// Releases references that accumulated calls like ImGui::Image
|
||||
protected internal static extern void CleanupFrame();
|
||||
|
||||
[Export, LinkName(.C)]
|
||||
private static bool ImGui_EditFloat2(char8* label, ref float2 value, float2 resetValues = .Zero, float dragSpeed = 0.1f, float columnWidth = 100f, float2 minValue = .Zero, float2 maxValue = .Zero, bool2 componentEnabled = true)
|
||||
{
|
||||
return EditFloat2(StringView(label), ref value, resetValues, dragSpeed, columnWidth, minValue, maxValue, componentEnabled);
|
||||
}
|
||||
|
||||
/// Control to edit a vector 2 with drag functionality and reset buttons
|
||||
public static bool EditFloat2(StringView label, ref float2 value, float2 resetValues = .Zero, float dragSpeed = 0.1f, float columnWidth = 100f, float2 minValue = .Zero, float2 maxValue = .Zero, bool2 componentEnabled = true)
|
||||
{
|
||||
return EditVector<2>(label, ref *(float[2]*)&value, (float[2])resetValues, dragSpeed, columnWidth, (float[2])minValue, (float[2])maxValue, (bool[2])componentEnabled);
|
||||
}
|
||||
|
||||
/// Control to edit a vector 3 with drag functionality and reset buttons
|
||||
public static bool EditFloat3(StringView label, ref float3 value, float3 resetValues = .Zero, float dragSpeed = 0.1f, float columnWidth = 100f, float3 minValue = .Zero, float3 maxValue = .Zero, bool3 componentEnabled = true)
|
||||
{
|
||||
return EditVector<3>(label, ref *(float[3]*)&value, (float[3])resetValues, dragSpeed, columnWidth, (float[3])minValue, (float[3])maxValue, (bool[3])componentEnabled);
|
||||
}
|
||||
|
||||
/// Control to edit a vector 4 with drag functionality and reset buttons
|
||||
public static bool EditFloat4(StringView label, ref float4 value, float4 resetValues = .Zero, float dragSpeed = 0.1f, float columnWidth = 100f, float4 minValue = .Zero, float4 maxValue = .Zero, bool4 componentEnabled = true)
|
||||
{
|
||||
return EditVector<4>(label, ref *(float[4]*)&value, (float[4])resetValues, dragSpeed, columnWidth, (float[4])minValue, (float[4])maxValue, (bool[4])componentEnabled);
|
||||
}
|
||||
|
||||
static (ColorRGBA Default, ColorRGBA Hovered, ColorRGBA Active)[?] VectorButtonColors = .(
|
||||
(.(230, 25, 45), .(150, 25, 45), .(230, 90, 90)),
|
||||
(.(50, 190, 15), .(50, 120, 15), .(116, 190, 99)),
|
||||
(.(55, 55, 230), .(55, 55, 150), .(90, 90, 230)),
|
||||
(.(230, 25, 45), .(230, 25, 45), .(230, 25, 45)));
|
||||
|
||||
public static bool EditVector<NumComponents>(StringView label, ref float[NumComponents] value, float[NumComponents] resetValues = .(), float dragSpeed = 0.1f, float columnWidth = 100f, float[NumComponents] minValue = .(), float[NumComponents] maxValue = .(), bool[NumComponents] componentEnabled = .(true, )) where NumComponents : const int32
|
||||
{
|
||||
const String[?] componentNames = .("X", "Y", "Z", "W");
|
||||
const String[?] componentIds = .("##X", "##Y", "##Z", "##W");
|
||||
|
||||
static int mouseLockId = 0;
|
||||
|
||||
bool changed = false;
|
||||
bool deactivated = false;
|
||||
|
||||
if (!label.IsEmpty)
|
||||
{
|
||||
PushID(label);
|
||||
defer:: PopID();
|
||||
|
||||
Columns(2);
|
||||
defer:: Columns(1);
|
||||
SetColumnWidth(0, columnWidth);
|
||||
|
||||
//int currentId = ImGui.GetID("");
|
||||
|
||||
TextUnformatted(label);
|
||||
|
||||
NextColumn();
|
||||
}
|
||||
|
||||
float lineHeight = GetFont().FontSize + GetStyle().FramePadding.y * 2.0f;
|
||||
ImGui.Vec2 buttonSize = .(lineHeight + 3.0f, lineHeight);
|
||||
|
||||
float itemWidth = CalcItemWidth();
|
||||
|
||||
float itemWidthNoButton = itemWidth - buttonSize.y * NumComponents;
|
||||
|
||||
bool hideButtons = (itemWidthNoButton / NumComponents) < ImGui.CalcTextSize("0.000").x;
|
||||
|
||||
PushMultiItemsWidths(NumComponents, hideButtons ? itemWidth : itemWidthNoButton);
|
||||
|
||||
PushStyleVar(.ItemSpacing, Vec2.Zero);
|
||||
|
||||
for (int i < NumComponents)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
SameLine();
|
||||
}
|
||||
|
||||
PushStyleColor(.Button, VectorButtonColors[i].Default.ImGuiU32);
|
||||
PushStyleColor(.ButtonHovered, VectorButtonColors[i].Hovered.ImGuiU32);
|
||||
PushStyleColor(.ButtonActive, VectorButtonColors[i].Active.ImGuiU32);
|
||||
|
||||
ImGui.BeginDisabled(!componentEnabled[i]);
|
||||
|
||||
if (!hideButtons)
|
||||
{
|
||||
if (Button(componentNames[i], buttonSize))
|
||||
{
|
||||
value[i] = resetValues[i];
|
||||
changed = true;
|
||||
}
|
||||
|
||||
SameLine();
|
||||
}
|
||||
|
||||
if (DragFloat(componentIds[i], &value[i], dragSpeed, minValue[i], maxValue[i]))
|
||||
{
|
||||
changed = true;
|
||||
|
||||
/*if (mouseLockId != currentId)
|
||||
{
|
||||
mouseLockId = currentId;
|
||||
|
||||
Mouse.LockCurrentPosition(mouseLockId);
|
||||
}*/
|
||||
}
|
||||
|
||||
ImGui.EndDisabled();
|
||||
/*if (IsItemDeactivatedAfterEdit())
|
||||
{
|
||||
deactivated = true;
|
||||
}*/
|
||||
|
||||
PopItemWidth();
|
||||
PopStyleColor(3);
|
||||
}
|
||||
|
||||
PopStyleVar();
|
||||
|
||||
/*if (mouseLockId == currentId && deactivated)
|
||||
{
|
||||
Mouse.UnlockPosition(mouseLockId);
|
||||
mouseLockId = 0;
|
||||
}*/
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
/// Control to edit a vector 2 with drag functionality and reset buttons
|
||||
public static bool Float2Editor(StringView label, ref float2 value, float2 resetValues = .Zero, float dragSpeed = 0.1f, float2 minValue = .Zero, float2 maxValue = .Zero, bool2 componentEnabled = true, StringView[2] format = .())
|
||||
{
|
||||
return VectorEditor<2>(label, ref *(float[2]*)&value, (float[2])resetValues, dragSpeed, (float[2])minValue, (float[2])maxValue, (bool[2])componentEnabled, format);
|
||||
}
|
||||
|
||||
/// Control to edit a vector 3 with drag functionality and reset buttons
|
||||
public static bool Float3Editor(StringView label, ref float3 value, float3 resetValues = .Zero, float dragSpeed = 0.1f, float3 minValue = .Zero, float3 maxValue = .Zero, bool3 componentEnabled = true, StringView[3] format = .())
|
||||
{
|
||||
return VectorEditor<3>(label, ref *(float[3]*)&value, (float[3])resetValues, dragSpeed, (float[3])minValue, (float[3])maxValue, (bool[3])componentEnabled, format);
|
||||
}
|
||||
|
||||
/// Control to edit a vector 4 with drag functionality and reset buttons
|
||||
public static bool Float4Editor(StringView label, ref float4 value, float4 resetValues = .Zero, float dragSpeed = 0.1f, float4 minValue = .Zero, float4 maxValue = .Zero, bool4 componentEnabled = true, StringView[4] format = .())
|
||||
{
|
||||
return VectorEditor<4>(label, ref *(float[4]*)&value, (float[4])resetValues, dragSpeed, (float[4])minValue, (float[4])maxValue, (bool[4])componentEnabled, format);
|
||||
}
|
||||
|
||||
public static bool VectorEditor<NumComponents>(StringView label, ref float[NumComponents] value, float[NumComponents] resetValues = .(), float dragSpeed = 0.1f, float[NumComponents] minValue = .(), float[NumComponents] maxValue = .(), bool[NumComponents] componentEnabled = .(true, ), StringView[NumComponents] numberFormat = .()) where NumComponents : const int32
|
||||
{
|
||||
const String[?] componentNames = .("X", "Y", "Z", "W");
|
||||
const String[?] componentIds = .("##X", "##Y", "##Z", "##W");
|
||||
|
||||
bool changed = false;
|
||||
|
||||
PushID(label);
|
||||
defer PopID();
|
||||
|
||||
//PushMultiItemsWidths(NumComponents, CalcItemWidth());
|
||||
|
||||
float totalWidth = CalcItemWidth();
|
||||
|
||||
float componentWidth = totalWidth / NumComponents;
|
||||
|
||||
float lineHeight = GetFont().FontSize + GetStyle().FramePadding.y * 2.0f;
|
||||
ImGui.Vec2 buttonSize = .(lineHeight + 3.0f, lineHeight);
|
||||
|
||||
float dragFloatWidth = componentWidth - buttonSize.x;
|
||||
|
||||
bool showButtons = dragFloatWidth > CalcTextSize("0.000").x;
|
||||
|
||||
if (!showButtons)
|
||||
{
|
||||
dragFloatWidth = componentWidth;
|
||||
}
|
||||
|
||||
dragFloatWidth -= GetStyle().FramePadding.x * 2;
|
||||
|
||||
componentLoop: for (int i < NumComponents)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
SameLine();
|
||||
}
|
||||
|
||||
PushStyleColor(.Button, VectorButtonColors[i].Default.ImGuiU32);
|
||||
PushStyleColor(.ButtonHovered, VectorButtonColors[i].Hovered.ImGuiU32);
|
||||
PushStyleColor(.ButtonActive, VectorButtonColors[i].Active.ImGuiU32);
|
||||
|
||||
BeginDisabled(!componentEnabled[i]);
|
||||
|
||||
//PushItemWidth(buttonSize.x);
|
||||
|
||||
if (showButtons)
|
||||
{
|
||||
if (Button(componentNames[i], buttonSize))
|
||||
{
|
||||
value[i] = resetValues[i];
|
||||
changed = true;
|
||||
}
|
||||
|
||||
PushStyleVar(.ItemSpacing, Vec2.Zero);
|
||||
|
||||
SameLine();
|
||||
}
|
||||
|
||||
StringView format = "0.#####";
|
||||
|
||||
if (!numberFormat[i].IsWhiteSpace)
|
||||
{
|
||||
// Look if we have a format for the specific index
|
||||
format = numberFormat[i];
|
||||
}
|
||||
else if (!numberFormat[0].IsWhiteSpace)
|
||||
{
|
||||
// Try to take the first number format
|
||||
format = numberFormat[0];
|
||||
}
|
||||
|
||||
if (!format.StartsWith("%"))
|
||||
{
|
||||
String str = scope:componentLoop .();
|
||||
|
||||
value[i].ToString(str, scope .(format), null);
|
||||
|
||||
format = str;
|
||||
}
|
||||
|
||||
PushItemWidth(dragFloatWidth);
|
||||
|
||||
if (DragFloat(componentIds[i], &value[i], dragSpeed, minValue[i], maxValue[i],
|
||||
format.ToScopeCStr!:componentLoop(), flags: .NoRoundToFormat))
|
||||
{
|
||||
changed = true;
|
||||
}
|
||||
|
||||
PopItemWidth();
|
||||
|
||||
if (showButtons)
|
||||
PopStyleVar();
|
||||
|
||||
EndDisabled();
|
||||
|
||||
PopStyleColor(3);
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
/// Draws a rectangle with the given color.
|
||||
public static void DrawRect(Vec2 min, Vec2 max, Color color)
|
||||
{
|
||||
ImGui.GetForegroundDrawList().AddRect(min, max, ImGui.GetColorU32(color.Value));
|
||||
}
|
||||
|
||||
/// Provides a combo Box to select an enum value.
|
||||
public static bool EnumCombo<T>(StringView label, ref T selectedValue) where T : enum
|
||||
{
|
||||
String selectedValueString = scope .();
|
||||
selectedValue.ToString(selectedValueString);
|
||||
// TODO: make selectedValue human readable
|
||||
|
||||
bool changed = false;
|
||||
|
||||
if (ImGui.BeginCombo(label.ToScopeCStr!(), selectedValueString))
|
||||
{
|
||||
for (let (name, value) in Enum.GetEnumerator<T>())
|
||||
{
|
||||
ImGui.PushID(name);
|
||||
|
||||
if (ImGui.Selectable(name.ToScopeCStr!(), selectedValue == value))
|
||||
{
|
||||
selectedValue = value;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
ImGui.PopID();
|
||||
}
|
||||
|
||||
ImGui.EndCombo();
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
/// Provides a tooltip that will be show when the previously defined Widget is hovered.
|
||||
public static void AttachTooltip(StringView tooltip)
|
||||
{
|
||||
if (!ImGui.IsItemHovered())
|
||||
return;
|
||||
|
||||
ImGui.BeginTooltip();
|
||||
|
||||
ImGui.TextUnformatted(tooltip);
|
||||
|
||||
ImGui.EndTooltip();
|
||||
}
|
||||
|
||||
[Comptime]
|
||||
private static DataType GetDataType<T>()
|
||||
{
|
||||
DataType dataType = .COUNT;
|
||||
|
||||
switch (typeof(T))
|
||||
{
|
||||
case typeof(int8):
|
||||
dataType = .S8;
|
||||
case typeof(int16):
|
||||
dataType = .S16;
|
||||
case typeof(int32):
|
||||
dataType = .S32;
|
||||
case typeof(int64):
|
||||
dataType = .S64;
|
||||
case typeof(int):
|
||||
if (sizeof(int) == 8)
|
||||
dataType = .S64;
|
||||
else if (sizeof(int) == 4)
|
||||
dataType = .S32;
|
||||
|
||||
case typeof(uint8):
|
||||
dataType = .U8;
|
||||
case typeof(uint16):
|
||||
dataType = .U16;
|
||||
case typeof(uint32):
|
||||
dataType = .U32;
|
||||
case typeof(uint64):
|
||||
dataType = .U64;
|
||||
case typeof(uint):
|
||||
if (sizeof(uint) == 8)
|
||||
dataType = .U64;
|
||||
else if (sizeof(uint) == 4)
|
||||
dataType = .U32;
|
||||
//default:
|
||||
// Runtime.Assert(dataType != .COUNT);
|
||||
//Log.EngineLogger.Assert(dataType != .COUNT, "Unknown data type.");
|
||||
}
|
||||
|
||||
return dataType;
|
||||
}
|
||||
|
||||
// TODO: Add support for floats
|
||||
public static bool DragScalar<T>(char8* label, ref T value, float dragSpeed = (float) 1.0f, T minValue = typeof(T).MinValue, T maxValue = typeof(T).MaxValue, char8* format = null, SliderFlags sliderFlags = .None) where T : IInteger
|
||||
{
|
||||
DataType dataType = GetDataType<T>();
|
||||
|
||||
#unwarn
|
||||
return DragScalar(label, dataType, &value, dragSpeed, &minValue, &maxValue, format, sliderFlags);
|
||||
}
|
||||
|
||||
// TODO: Add support for floats
|
||||
public static bool SliderScalar<T>(char8* label, ref T value, T minValue = typeof(T).MinValue, T maxValue = typeof(T).MaxValue, char8* format = null, SliderFlags sliderFlags = .None) where T : IInteger
|
||||
{
|
||||
DataType dataType = GetDataType<T>();
|
||||
|
||||
#unwarn
|
||||
return SliderScalar(label, dataType, &value, &minValue, &maxValue, format, sliderFlags);
|
||||
}
|
||||
|
||||
public static void ListElementGrabber()
|
||||
{
|
||||
Window* window = GetCurrentWindow();
|
||||
if (window.SkipItems)
|
||||
return;
|
||||
|
||||
Context* g = GetCurrentContext();
|
||||
ref Style style = ref g.Style;
|
||||
|
||||
Vec2 cursorPos = ImGui.GetCursorScreenPos();
|
||||
|
||||
float line_height = max(min(window.DC.CurrLineSize.y, g.FontSize + style.FramePadding.y * 2), g.FontSize);
|
||||
Rect bb = .(cursorPos, Vec2(cursorPos.x + g.FontSize, cursorPos.y + line_height));
|
||||
ItemSize(bb);
|
||||
if (!ItemAdd(bb, 0))
|
||||
{
|
||||
SameLine(0, style.FramePadding.x * 2);
|
||||
return;
|
||||
}
|
||||
|
||||
// Render and stay on same line
|
||||
U32 text_col = GetColorU32(Col.Text);
|
||||
|
||||
float bar_height = line_height / 4.0f;
|
||||
|
||||
Rect topBb = .(cursorPos, (Vec2)((float2)cursorPos + float2(g.FontSize, bar_height)));
|
||||
RenderFrame(topBb.Min, topBb.Max, text_col, true, 4);
|
||||
|
||||
Rect middleBb = topBb;
|
||||
middleBb.Min.y = cursorPos.y + line_height / 2.0f - bar_height / 2.0f;
|
||||
middleBb.Max.y = middleBb.Min.y + bar_height;
|
||||
RenderFrame(middleBb.Min, middleBb.Max, text_col, true, 4);
|
||||
|
||||
Rect bottomBb = middleBb;
|
||||
bottomBb.Max.y = cursorPos.y + line_height;
|
||||
bottomBb.Min.y = bottomBb.Max.y - bar_height;
|
||||
RenderFrame(bottomBb.Min, bottomBb.Max, text_col, true, 4);
|
||||
|
||||
SameLine(0, style.FramePadding.x * 2.0f);
|
||||
}
|
||||
|
||||
[AllowDuplicates, CRepr]
|
||||
public enum TypedStyleVar
|
||||
{
|
||||
case Alpha(float Value);
|
||||
case DisabledAlpha(float Value);
|
||||
case WindowPadding(float2 Value);
|
||||
case WindowRounding(float Value);
|
||||
case WindowBorderSize(float Value);
|
||||
case WindowMinSize(float2 Value);
|
||||
case WindowTitleAlign(float2 Value);
|
||||
case ChildRounding(float Value);
|
||||
case ChildBorderSize(float Value);
|
||||
case PopupRounding(float Value);
|
||||
case PopupBorderSize (float Value);
|
||||
case FramePadding (float2 Value);
|
||||
case FrameRounding (float Value);
|
||||
case FrameBorderSize (float Value);
|
||||
case ItemSpacing (float2 Value);
|
||||
case ItemInnerSpacing (float2 Value);
|
||||
case IndentSpacing (float Value);
|
||||
case CellPadding (float2 Value);
|
||||
case ScrollbarSize (float Value);
|
||||
case ScrollbarRounding (float Value);
|
||||
case GrabMinSize (float Value);
|
||||
case GrabRounding (float Value);
|
||||
case TabRounding (float Value);
|
||||
case TabBarBorderSize (float Value);
|
||||
case ButtonTextAlign (float2 Value);
|
||||
case SelectableTextAlign (float2 Value);
|
||||
case SeparatorTextBorderSize (float Value);
|
||||
case SeparatorTextAlign (float2 Value);
|
||||
case SeparatorTextPadding (float2 Value);
|
||||
case DockingSeparatorSize (float Value);
|
||||
}
|
||||
|
||||
public static mixin PushScopedStyleVar(TypedStyleVar value)
|
||||
{
|
||||
PushStyleVar(value);
|
||||
defer:mixin PopStyleVar();
|
||||
}
|
||||
|
||||
public static void PushStyleVar(TypedStyleVar value)
|
||||
{
|
||||
switch (value)
|
||||
{
|
||||
case .Alpha(let Value):
|
||||
PushStyleVar(.Alpha, Value);
|
||||
case .DisabledAlpha(let Value):
|
||||
PushStyleVar(.DisabledAlpha, Value);
|
||||
case .WindowPadding(let Value):
|
||||
PushStyleVar(.WindowPadding, Value);
|
||||
case .WindowRounding(let Value):
|
||||
PushStyleVar(.WindowRounding, Value);
|
||||
case .WindowBorderSize(let Value):
|
||||
PushStyleVar(.WindowBorderSize, Value);
|
||||
case .WindowMinSize(let Value):
|
||||
PushStyleVar(.WindowMinSize, Value);
|
||||
case .WindowTitleAlign(let Value):
|
||||
PushStyleVar(.WindowTitleAlign, Value);
|
||||
case .ChildRounding(let Value):
|
||||
PushStyleVar(.ChildRounding, Value);
|
||||
case .ChildBorderSize(let Value):
|
||||
PushStyleVar(.ChildBorderSize, Value);
|
||||
case .PopupRounding(let Value):
|
||||
PushStyleVar(.PopupRounding, Value);
|
||||
case .PopupBorderSize(let Value):
|
||||
PushStyleVar(.PopupBorderSize, Value);
|
||||
case .FramePadding(let Value):
|
||||
PushStyleVar(.FramePadding, Value);
|
||||
case .FrameRounding(let Value):
|
||||
PushStyleVar(.FrameRounding, Value);
|
||||
case .FrameBorderSize(let Value):
|
||||
PushStyleVar(.FrameBorderSize, Value);
|
||||
case .ItemSpacing(let Value):
|
||||
PushStyleVar(.ItemSpacing, Value);
|
||||
case .ItemInnerSpacing(let Value):
|
||||
PushStyleVar(.ItemInnerSpacing, Value);
|
||||
case .IndentSpacing(let Value):
|
||||
PushStyleVar(.IndentSpacing, Value);
|
||||
case .CellPadding(let Value):
|
||||
PushStyleVar(.CellPadding, Value);
|
||||
case .ScrollbarSize(let Value):
|
||||
PushStyleVar(.ScrollbarSize, Value);
|
||||
case .ScrollbarRounding(let Value):
|
||||
PushStyleVar(.ScrollbarRounding, Value);
|
||||
case .GrabMinSize(let Value):
|
||||
PushStyleVar(.GrabMinSize, Value);
|
||||
case .GrabRounding(let Value):
|
||||
PushStyleVar(.GrabRounding, Value);
|
||||
case .TabRounding(let Value):
|
||||
PushStyleVar(.TabRounding, Value);
|
||||
case .TabBarBorderSize(let Value):
|
||||
PushStyleVar(.TabBarBorderSize, Value);
|
||||
case .ButtonTextAlign(let Value):
|
||||
PushStyleVar(.ButtonTextAlign, Value);
|
||||
case .SelectableTextAlign(let Value):
|
||||
PushStyleVar(.SelectableTextAlign, Value);
|
||||
case .SeparatorTextBorderSize(let Value):
|
||||
PushStyleVar(.SeparatorTextBorderSize, Value);
|
||||
case .SeparatorTextAlign(let Value):
|
||||
PushStyleVar(.SeparatorTextAlign, Value);
|
||||
case .SeparatorTextPadding(let Value):
|
||||
PushStyleVar(.SeparatorTextPadding, Value);
|
||||
case .DockingSeparatorSize(let Value):
|
||||
PushStyleVar(.DockingSeparatorSize, Value);
|
||||
}
|
||||
}
|
||||
|
||||
public struct DisabledScope : IDisposable
|
||||
{
|
||||
public this(bool disabled = true)
|
||||
{
|
||||
ImGui.BeginDisabled(disabled);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
ImGui.EndDisabled();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,262 +0,0 @@
|
||||
#if IMGUI
|
||||
|
||||
using System;
|
||||
using ImGui;
|
||||
using GlitchyEngine.Events;
|
||||
using ImGuizmo;
|
||||
using GlitchyEngine.Renderer;
|
||||
using System.IO;
|
||||
|
||||
using internal ImGui;
|
||||
|
||||
#if GE_GRAPHICS_DX11
|
||||
|
||||
using GlitchyEngine.Platform.DX11;
|
||||
using GlitchyEngine.Math;
|
||||
using internal GlitchyEngine.Platform.DX11;
|
||||
|
||||
#endif
|
||||
|
||||
namespace GlitchyEngine.ImGui
|
||||
{
|
||||
public class ImGuiLayer : Layer
|
||||
{
|
||||
ImGui.IO* _io;
|
||||
|
||||
public bool SettingsInvalid;
|
||||
|
||||
public this() : base("ImGuiLayer") { }
|
||||
|
||||
public override void OnAttach()
|
||||
{
|
||||
Debug.Profiler.ProfileFunction!();
|
||||
|
||||
//ImGuiImplWin32.EnableDpiAwareness();
|
||||
Log.EngineLogger.Trace("Initializing ImGui...");
|
||||
|
||||
ImGui.CHECKVERSION();
|
||||
ImGui.CreateContext();
|
||||
ImGui.StyleColorsDark();
|
||||
|
||||
_io = ImGui.GetIO();
|
||||
_io.ConfigFlags |= .NavEnableKeyboard;
|
||||
_io.ConfigFlags |= .DockingEnable;
|
||||
_io.ConfigFlags |= .ViewportsEnable;
|
||||
|
||||
// Todo: currently broken in ImGui
|
||||
//io.ConfigFlags |= .DpiEnableScaleFonts;
|
||||
//io.ConfigFlags |= .DpiEnableScaleViewports;
|
||||
|
||||
// When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones.
|
||||
ImGui.Style* style = ImGui.GetStyle();
|
||||
if(_io.ConfigFlags.HasFlag(.ViewportsEnable))
|
||||
{
|
||||
style.WindowRounding = 0.0f;
|
||||
style.Colors[(int)ImGui.Col.WindowBg].w = 1.0f;
|
||||
}
|
||||
|
||||
#if BF_PLATFORM_WINDOWS
|
||||
ImGuiImplWin32.Init(Application.Get().Window.NativeWindow);
|
||||
#endif
|
||||
|
||||
#if GE_GRAPHICS_DX11
|
||||
ImGuiImplDX11.Init(NativeDevice, NativeContext);
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void OnDetach()
|
||||
{
|
||||
Debug.Profiler.ProfileFunction!();
|
||||
|
||||
#if GE_GRAPHICS_DX11
|
||||
ImGuiImplDX11.Shutdown();
|
||||
#endif
|
||||
|
||||
#if BF_PLATFORM_WINDOWS
|
||||
ImGuiImplWin32.Shutdown();
|
||||
#endif
|
||||
|
||||
ImGui.DestroyContext();
|
||||
}
|
||||
|
||||
public void Begin()
|
||||
{
|
||||
Debug.Profiler.ProfileFunction!();
|
||||
|
||||
ImGuiImplDX11.NewFrame();
|
||||
ImGuiImplWin32.NewFrame();
|
||||
ImGui.NewFrame();
|
||||
ImGuizmo.BeginFrame();
|
||||
}
|
||||
|
||||
private void LoadFont()
|
||||
{
|
||||
var settings = Application.Instance.Settings.ImGuiSettings;
|
||||
|
||||
ImGui.GetIO().Fonts.Clear();
|
||||
|
||||
Stream fontFile = Application.Instance.ContentManager.GetStream(settings.FontName);
|
||||
|
||||
if (fontFile != null)
|
||||
{
|
||||
// We need to use ImGuis memory allocator because ImGui takes ownership
|
||||
uint8* fontData = (uint8*)ImGui.MemAlloc((uint64)fontFile.Length);
|
||||
var result = fontFile.TryRead(Span<uint8>(fontData, fontFile.Length));
|
||||
|
||||
if (result case .Err)
|
||||
Log.EngineLogger.Error($"Failed to load font \"{settings.FontName}\" from stream.");
|
||||
|
||||
ImGui.GetIO().Fonts.AddFontFromMemoryTTF(fontData, (int32)fontFile.Length, settings.FontSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui.GetIO().Fonts.AddFontDefault();
|
||||
}
|
||||
|
||||
ApplyDefaultStyle();
|
||||
|
||||
ImGui.GetIO().Fonts.AddFontDefault();
|
||||
|
||||
delete fontFile;
|
||||
}
|
||||
|
||||
private void ApplyDefaultStyle(ImGui.Style* dst = null)
|
||||
{
|
||||
ImGui.Style* style = dst ?? ImGui.GetStyle();
|
||||
ImGui.Vec4* colors = &style.Colors;
|
||||
|
||||
style.FrameRounding = 4;
|
||||
style.TabRounding = 8;
|
||||
style.ScrollbarSize = 20;
|
||||
style.ScrollbarRounding = 3;
|
||||
|
||||
style.WindowMinSize = ImGui.Vec2(100, 100);
|
||||
|
||||
style.SeparatorTextAlign = ImGui.Vec2(0.5f, 0.5f);
|
||||
|
||||
colors[(.)ImGui.Col.WindowBg] = ImGui.Vec4(0.118f, 0.118f, 0.118f, 1.00f);
|
||||
colors[(.)ImGui.Col.FrameBg] = ImGui.Vec4(0.289f, 0.387f, 0.533f, 1.00f);
|
||||
colors[(.)ImGui.Col.MenuBarBg] = ImGui.Vec4(0.21f, 0.21f, 0.21f, 1.00f);
|
||||
colors[(.)ImGui.Col.Header] = ImGui.Vec4(0.267f, 0.295f, 0.329f, 1.00f);
|
||||
colors[(.)ImGui.Col.Tab] = ImGui.Vec4(0.473f, 0.519f, 0.580f, 1.00f);
|
||||
colors[(.)ImGui.Col.TabUnfocused] = ImGui.Vec4(0.255f, 0.255f, 0.255f, 1.00f);
|
||||
colors[(.)ImGui.Col.CheckMark] = ImGui.Vec4(0.851f, 0.863f, 0.900f, 1.00f);
|
||||
colors[(.)ImGui.Col.TitleBg] = ImGui.Vec4(0.406f, 0.401f, 0.390f, 1.000f);
|
||||
colors[(.)ImGui.Col.TitleBgActive] = ImGui.Vec4(0.196f, 0.192f, 0.182f, 1.000f);
|
||||
|
||||
/*colors[(.)ImGui.Col.Text] = ImGui.Vec4(0.00f, 0.00f, 0.00f, 1.00f);
|
||||
colors[(.)ImGui.Col.TextDisabled] = ImGui.Vec4(0.60f, 0.60f, 0.60f, 1.00f);
|
||||
colors[(.)ImGui.Col.WindowBg] = ImGui.Vec4(0.94f, 0.94f, 0.94f, 1.00f);
|
||||
colors[(.)ImGui.Col.ChildBg] = ImGui.Vec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
colors[(.)ImGui.Col.PopupBg] = ImGui.Vec4(1.00f, 1.00f, 1.00f, 0.98f);
|
||||
colors[(.)ImGui.Col.Border] = ImGui.Vec4(0.00f, 0.00f, 0.00f, 0.30f);
|
||||
colors[(.)ImGui.Col.BorderShadow] = ImGui.Vec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
colors[(.)ImGui.Col.FrameBg] = ImGui.Vec4(1.00f, 1.00f, 1.00f, 1.00f);
|
||||
colors[(.)ImGui.Col.FrameBgHovered] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 0.40f);
|
||||
colors[(.)ImGui.Col.FrameBgActive] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 0.67f);
|
||||
colors[(.)ImGui.Col.TitleBg] = ImGui.Vec4(0.96f, 0.96f, 0.96f, 1.00f);
|
||||
colors[(.)ImGui.Col.TitleBgActive] = ImGui.Vec4(0.82f, 0.82f, 0.82f, 1.00f);
|
||||
colors[(.)ImGui.Col.TitleBgCollapsed] = ImGui.Vec4(1.00f, 1.00f, 1.00f, 0.51f);
|
||||
colors[(.)ImGui.Col.MenuBarBg] = ImGui.Vec4(0.86f, 0.86f, 0.86f, 1.00f);
|
||||
colors[(.)ImGui.Col.ScrollbarBg] = ImGui.Vec4(0.98f, 0.98f, 0.98f, 0.53f);
|
||||
colors[(.)ImGui.Col.ScrollbarGrab] = ImGui.Vec4(0.69f, 0.69f, 0.69f, 0.80f);
|
||||
colors[(.)ImGui.Col.ScrollbarGrabHovered] = ImGui.Vec4(0.49f, 0.49f, 0.49f, 0.80f);
|
||||
colors[(.)ImGui.Col.ScrollbarGrabActive] = ImGui.Vec4(0.49f, 0.49f, 0.49f, 1.00f);
|
||||
colors[(.)ImGui.Col.CheckMark] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 1.00f);
|
||||
colors[(.)ImGui.Col.SliderGrab] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 0.78f);
|
||||
colors[(.)ImGui.Col.SliderGrabActive] = ImGui.Vec4(0.46f, 0.54f, 0.80f, 0.60f);
|
||||
colors[(.)ImGui.Col.Button] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 0.40f);
|
||||
colors[(.)ImGui.Col.ButtonHovered] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 1.00f);
|
||||
colors[(.)ImGui.Col.ButtonActive] = ImGui.Vec4(0.06f, 0.53f, 0.98f, 1.00f);
|
||||
colors[(.)ImGui.Col.Header] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 0.31f);
|
||||
colors[(.)ImGui.Col.HeaderHovered] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 0.80f);
|
||||
colors[(.)ImGui.Col.HeaderActive] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 1.00f);
|
||||
colors[(.)ImGui.Col.Separator] = ImGui.Vec4(0.39f, 0.39f, 0.39f, 0.62f);
|
||||
colors[(.)ImGui.Col.SeparatorHovered] = ImGui.Vec4(0.14f, 0.44f, 0.80f, 0.78f);
|
||||
colors[(.)ImGui.Col.SeparatorActive] = ImGui.Vec4(0.14f, 0.44f, 0.80f, 1.00f);
|
||||
colors[(.)ImGui.Col.ResizeGrip] = ImGui.Vec4(0.35f, 0.35f, 0.35f, 0.17f);
|
||||
colors[(.)ImGui.Col.ResizeGripHovered] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 0.67f);
|
||||
colors[(.)ImGui.Col.ResizeGripActive] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 0.95f);
|
||||
colors[(.)ImGui.Col.Tab] = ImGui.Vec4(0.96f, 0.8f, 0.52f, 1.0f);//ImGui.ImLerp(colors[(.)ImGui.Col.Header], colors[(.)ImGui.Col.TitleBgActive], 0.90f);
|
||||
colors[(.)ImGui.Col.TabHovered] = ImGui.Vec4(0.73f, 0.78f, 0.95f, 1.0f);
|
||||
colors[(.)ImGui.Col.TabActive] = ImGui.ImLerp(colors[(.)ImGui.Col.HeaderActive], colors[(.)ImGui.Col.TitleBgActive], 0.60f);
|
||||
colors[(.)ImGui.Col.TabUnfocused] = ImGui.ImLerp(colors[(.)ImGui.Col.Tab], colors[(.)ImGui.Col.TitleBg], 0.80f);
|
||||
colors[(.)ImGui.Col.TabUnfocusedActive] = ImGui.ImLerp(colors[(.)ImGui.Col.TabActive], colors[(.)ImGui.Col.TitleBg], 0.40f);
|
||||
colors[(.)ImGui.Col.DockingPreview] = (.)((float4)colors[(.)ImGui.Col.Header] * (float4)ImGui.Vec4(1.0f, 1.0f, 1.0f, 0.7f));
|
||||
colors[(.)ImGui.Col.DockingEmptyBg] = ImGui.Vec4(0.20f, 0.20f, 0.20f, 1.00f);
|
||||
colors[(.)ImGui.Col.PlotLines] = ImGui.Vec4(0.39f, 0.39f, 0.39f, 1.00f);
|
||||
colors[(.)ImGui.Col.PlotLinesHovered] = ImGui.Vec4(1.00f, 0.43f, 0.35f, 1.00f);
|
||||
colors[(.)ImGui.Col.PlotHistogram] = ImGui.Vec4(0.90f, 0.70f, 0.00f, 1.00f);
|
||||
colors[(.)ImGui.Col.PlotHistogramHovered] = ImGui.Vec4(1.00f, 0.45f, 0.00f, 1.00f);
|
||||
colors[(.)ImGui.Col.TableHeaderBg] = ImGui.Vec4(0.78f, 0.87f, 0.98f, 1.00f);
|
||||
colors[(.)ImGui.Col.TableBorderStrong] = ImGui.Vec4(0.57f, 0.57f, 0.64f, 1.00f); // Prefer using Alpha=1.0 here
|
||||
colors[(.)ImGui.Col.TableBorderLight] = ImGui.Vec4(0.68f, 0.68f, 0.74f, 1.00f); // Prefer using Alpha=1.0 here
|
||||
colors[(.)ImGui.Col.TableRowBg] = ImGui.Vec4(0.00f, 0.00f, 0.00f, 0.00f);
|
||||
colors[(.)ImGui.Col.TableRowBgAlt] = ImGui.Vec4(0.30f, 0.30f, 0.30f, 0.09f);
|
||||
colors[(.)ImGui.Col.TextSelectedBg] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 0.35f);
|
||||
colors[(.)ImGui.Col.DragDropTarget] = ImGui.Vec4(0.26f, 0.59f, 0.98f, 0.95f);
|
||||
colors[(.)ImGui.Col.NavHighlight] = colors[(.)ImGui.Col.HeaderHovered];
|
||||
colors[(.)ImGui.Col.NavWindowingHighlight] = ImGui.Vec4(0.70f, 0.70f, 0.70f, 0.70f);
|
||||
colors[(.)ImGui.Col.NavWindowingDimBg] = ImGui.Vec4(0.20f, 0.20f, 0.20f, 0.20f);
|
||||
colors[(.)ImGui.Col.ModalWindowDimBg] = ImGui.Vec4(0.20f, 0.20f, 0.20f, 0.35f);*/
|
||||
}
|
||||
|
||||
public void ImGuiRender()
|
||||
{
|
||||
Debug.Profiler.ProfileFunction!();
|
||||
|
||||
if (SettingsInvalid)
|
||||
{
|
||||
LoadFont();
|
||||
|
||||
#if GE_GRAPHICS_DX11
|
||||
ImGuiImplDX11.CreateDeviceObjects();
|
||||
#endif
|
||||
|
||||
SettingsInvalid = false;
|
||||
}
|
||||
|
||||
Begin();
|
||||
|
||||
{
|
||||
Debug.Profiler.ProfileScope!("ImGuiRenderEvent");
|
||||
|
||||
var event = scope ImGuiRenderEvent();
|
||||
Application.Instance.OnEvent(event);
|
||||
}
|
||||
|
||||
End();
|
||||
}
|
||||
|
||||
public void End()
|
||||
{
|
||||
Debug.Profiler.ProfileFunction!();
|
||||
|
||||
ImGui.Render();
|
||||
|
||||
RenderCommand.SetDepthStencilTarget(null);
|
||||
// TODO: This is dirty
|
||||
RenderCommand.UnbindRenderTargets();
|
||||
RenderCommand.SetRenderTarget(null);
|
||||
RenderCommand.BindRenderTargets();
|
||||
|
||||
#if GE_GRAPHICS_DX11
|
||||
|
||||
using (ContextMonitor.Enter())
|
||||
{
|
||||
ImGuiImplDX11.RenderDrawData(ImGui.GetDrawData());
|
||||
}
|
||||
#endif
|
||||
|
||||
ImGui.CleanupFrame();
|
||||
|
||||
if(_io.ConfigFlags.HasFlag(.ViewportsEnable))
|
||||
{
|
||||
ImGui.UpdatePlatformWindows();
|
||||
ImGui.RenderPlatformWindowsDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,23 +0,0 @@
|
||||
using GlitchyEngine.Events;
|
||||
|
||||
namespace GlitchyEngine.Events
|
||||
{
|
||||
extension EventType
|
||||
{
|
||||
case ImGuiRender;
|
||||
}
|
||||
}
|
||||
|
||||
namespace GlitchyEngine.ImGui
|
||||
{
|
||||
public class ImGuiRenderEvent : Event, IEvent
|
||||
{
|
||||
public override EventType EventType => .ImGuiRender;
|
||||
|
||||
public override EventCategory Category => .Application;
|
||||
|
||||
public override System.StringView Name => "ImGuiRender";
|
||||
|
||||
public static EventType StaticType => .ImGuiRender;
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@ namespace GlitchyEngine
|
||||
public static extern void Impl_NewFrame();
|
||||
public static extern void Impl_EndFrame();
|
||||
|
||||
public static void ImGuiDebugDraw()
|
||||
/*public static void ImGuiDebugDraw()
|
||||
{
|
||||
if (ImGui.Begin("Input"))
|
||||
{
|
||||
@@ -116,7 +116,7 @@ namespace GlitchyEngine
|
||||
}
|
||||
|
||||
ImGui.End();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public static class Mouse
|
||||
|
||||
@@ -58,6 +58,7 @@ namespace GlitchyEngine
|
||||
{
|
||||
_insertIndex--;
|
||||
layer.OnDetach();
|
||||
delete layer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +71,7 @@ namespace GlitchyEngine
|
||||
if(_layers.Remove(overlay))
|
||||
{
|
||||
overlay.OnDetach();
|
||||
delete overlay;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
#if GE_GRAPHICS_DX11
|
||||
|
||||
using GlitchyEngine.Renderer;
|
||||
using System.Collections;
|
||||
using DirectX.D3D11;
|
||||
|
||||
namespace ImGui
|
||||
{
|
||||
using internal GlitchyEngine.Renderer;
|
||||
|
||||
extension ImGui
|
||||
{
|
||||
static List<ID3D11ShaderResourceView*> _resourceViews = new .() ~ delete _;
|
||||
|
||||
public static override void Image(TextureViewBinding textureViewBinding, Vec2 size, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 tint_col = Vec4.Ones, Vec4 border_col = Vec4.Zero)
|
||||
{
|
||||
var view = textureViewBinding._nativeShaderResourceView..AddRef();
|
||||
_resourceViews.Add(view);
|
||||
|
||||
ImGui.Image(view, size, uv0, uv1, tint_col, border_col);
|
||||
|
||||
textureViewBinding.ReleaseRef();
|
||||
}
|
||||
|
||||
public static override bool ImageButton(char8* id, TextureViewBinding textureViewBinding, Vec2 imageSize, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 bg_col = Vec4.Zero, Vec4 tint_col = Vec4.Ones)
|
||||
{
|
||||
var view = textureViewBinding._nativeShaderResourceView..AddRef();
|
||||
_resourceViews.Add(view);
|
||||
|
||||
bool pressed = ImGui.ImageButton(id, view, imageSize, uv0, uv1, bg_col, tint_col);
|
||||
|
||||
textureViewBinding.ReleaseRef();
|
||||
|
||||
return pressed;
|
||||
}
|
||||
|
||||
public static override bool ImageButtonEx(uint32 id, TextureViewBinding textureViewBinding, Vec2 imageSize, Vec2 uv0 = Vec2.Zero, Vec2 uv1 = Vec2.Ones, Vec4 bg_col = Vec4.Zero, Vec4 tint_col = Vec4.Ones)
|
||||
{
|
||||
var view = textureViewBinding._nativeShaderResourceView..AddRef();
|
||||
_resourceViews.Add(view);
|
||||
|
||||
bool pressed = ImGui.ImageButtonEx(id, view, imageSize, uv0, uv1, bg_col, tint_col);
|
||||
|
||||
textureViewBinding.ReleaseRef();
|
||||
|
||||
return pressed;
|
||||
}
|
||||
|
||||
protected internal static override void CleanupFrame()
|
||||
{
|
||||
for(var view in _resourceViews)
|
||||
{
|
||||
view.Release();
|
||||
}
|
||||
|
||||
_resourceViews.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -275,7 +275,10 @@ namespace GlitchyEngine
|
||||
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
// TODO: This line is the reason why GlitchyEngine depends on ImGui...
|
||||
#if IMGUI
|
||||
ImGui.ImGuiImplWin32.WndProcHandler(hwnd, uMsg, wParam, lParam);
|
||||
#endif
|
||||
|
||||
switch (uMsg)
|
||||
{
|
||||
|
||||
@@ -1,145 +0,0 @@
|
||||
using System;
|
||||
using ImGui;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using Bon;
|
||||
|
||||
namespace GlitchyEngine
|
||||
{
|
||||
interface ISettings
|
||||
{
|
||||
void Apply();
|
||||
}
|
||||
|
||||
/// Fields with this Attribute will be scanned for Settings.
|
||||
[AttributeUsage(.Field, .ReflectAttribute)]
|
||||
struct SettingContainerAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
enum SettingEditor
|
||||
{
|
||||
case Default;
|
||||
case Path;//(bool MultiSelect, bool OpenFolderDialog, StringView Filter);
|
||||
}
|
||||
|
||||
/// Fields with this Attribute will be exposed as settings.
|
||||
[AttributeUsage(.Field, .ReflectAttribute)]
|
||||
struct SettingAttribute : Attribute
|
||||
{
|
||||
public String Category;
|
||||
public String Name;
|
||||
public String Tooltip;
|
||||
public SettingEditor EditorMode;
|
||||
|
||||
public this(String category, String name, String tooltip = "", SettingEditor editorMode = .Default)
|
||||
{
|
||||
Category = category;
|
||||
Name = name;
|
||||
Tooltip = tooltip;
|
||||
EditorMode = editorMode;
|
||||
}
|
||||
}
|
||||
|
||||
[Reflect, BonTarget]
|
||||
class Settings
|
||||
{
|
||||
#if IMGUI
|
||||
[SettingContainer, BonInclude]
|
||||
public readonly ImGuiSettings ImGuiSettings = new .() ~ delete _;
|
||||
#endif
|
||||
[BonIgnore]
|
||||
public Event<EventHandler> OnApplySettings = .() ~ _.Dispose();
|
||||
|
||||
/*
|
||||
[BonInclude]
|
||||
private List<ISettings> _userSettings ~ ClearAndDeleteItems!(_);
|
||||
*/
|
||||
|
||||
public this()
|
||||
{
|
||||
/*List<ISettings> userSettings = append .();
|
||||
_userSettings = userSettings;*/
|
||||
RegisterEventListeners();
|
||||
}
|
||||
|
||||
protected virtual void RegisterEventListeners()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Apply()
|
||||
{
|
||||
#if IMGUI
|
||||
ImGuiSettings.Apply();
|
||||
#endif
|
||||
|
||||
OnApplySettings.Invoke(this, .Empty);
|
||||
|
||||
/*for (let settings in _userSettings)
|
||||
{
|
||||
settings.Apply();
|
||||
}*/
|
||||
}
|
||||
|
||||
public static void Load()
|
||||
{
|
||||
Settings settings = Application.Get().Settings;
|
||||
|
||||
if (!File.Exists("./settings.bon"))
|
||||
{
|
||||
settings.Save();
|
||||
}
|
||||
|
||||
var result = Bon.DeserializeFromFile(ref settings, "./settings.bon");
|
||||
|
||||
if (result case .Err)
|
||||
Log.EngineLogger.Error("Failed to deserialze settings.");
|
||||
|
||||
Application.Get().Settings.Apply();
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
gBonEnv.serializeFlags |= .Verbose;
|
||||
Bon.SerializeIntoFile(this, "./settings.bon");
|
||||
}
|
||||
|
||||
/*
|
||||
/// Registers a instance of a settings interface. Note: Takes ownership of the instance.
|
||||
public void RegisterUserSettings(ISettings settings)
|
||||
{
|
||||
_userSettings.Add(settings);
|
||||
}
|
||||
|
||||
public T GetUserSettings<T>() where T : ISettings, class
|
||||
{
|
||||
for (let v in _userSettings)
|
||||
{
|
||||
if (v is T)
|
||||
{
|
||||
return (T)v;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}*/
|
||||
}
|
||||
|
||||
#if IMGUI
|
||||
[Reflect]
|
||||
class ImGuiSettings
|
||||
{
|
||||
[Setting("UI", "Font Size"), BonInclude]
|
||||
public int32 FontSize = 14;
|
||||
|
||||
[Setting("UI", "Font name"), BonInclude]
|
||||
public readonly String FontName = new .("Fonts/CascadiaCode.ttf") ~ delete _;
|
||||
|
||||
public void Apply()
|
||||
{
|
||||
Application.Instance.[Friend]_imGuiLayer.SettingsInvalid = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user