diff --git a/GlitchyEditor/src/Assets/MaterialAssetLoader.bf b/GlitchyEditor/src/Assets/MaterialAssetLoader.bf index afec1cb..0e48d31 100644 --- a/GlitchyEditor/src/Assets/MaterialAssetLoader.bf +++ b/GlitchyEditor/src/Assets/MaterialAssetLoader.bf @@ -226,7 +226,7 @@ class MaterialAssetPropertiesEditor : AssetPropertiesEditor float2 minV = hasMin ? min.Get() : (float2)float.MinValue; float2 maxV = hasMax ? max.Get() : (float2)float.MaxValue; - if (ImGui.Editfloat2(displayName, ref value, .Zero, 0.1f, 100.0f, minV, maxV)) + if (ImGui.EditFloat2(displayName, ref value, .Zero, 0.1f, 100.0f, minV, maxV)) material.SetVariable(variable.Name, value); case 3: material.GetVariable(variable.Name, var value); @@ -234,7 +234,7 @@ class MaterialAssetPropertiesEditor : AssetPropertiesEditor float3 minV = hasMin ? min.Get() : (float3)float.MinValue; float3 maxV = hasMax ? max.Get() : (float3)float.MaxValue; - if (ImGui.Editfloat3(displayName, ref value, .Zero, 0.1f, 100.0f, minV, maxV)) + if (ImGui.EditFloat3(displayName, ref value, .Zero, 0.1f, 100.0f, minV, maxV)) material.SetVariable(variable.Name, value); case 4: material.GetVariable(variable.Name, var value); @@ -242,7 +242,7 @@ class MaterialAssetPropertiesEditor : AssetPropertiesEditor float4 minV = hasMin ? min.Get() : (float4)float.MinValue; float4 maxV = hasMax ? max.Get() : (float4)float.MaxValue; - if (ImGui.Editfloat4(displayName, ref value, .Zero, 0.1f, 100.0f, minV, maxV)) + if (ImGui.EditFloat4(displayName, ref value, .Zero, 0.1f, 100.0f, minV, maxV)) material.SetVariable(variable.Name, value); } } diff --git a/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf b/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf index d2d69c8..9d13288 100644 --- a/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf +++ b/GlitchyEditor/src/EditWindows/ComponentEditWindow.bf @@ -196,7 +196,7 @@ namespace GlitchyEditor.EditWindows textWidth += ImGui.GetStyle().FramePadding.x * 3.0f; float3 position = transform.Position; - if (ImGui.Editfloat3("Position", ref position, .Zero, 0.1f, textWidth)) + if (ImGui.EditFloat3("Position", ref position, .Zero, 0.1f, textWidth)) { transform.Position = position; @@ -217,7 +217,7 @@ namespace GlitchyEditor.EditWindows rotationEuler.XY = 0; } - if (ImGui.Editfloat3("Rotation", ref rotationEuler, .Zero, 0.1f, textWidth, componentEnabled: componentEditable)) + if (ImGui.EditFloat3("Rotation", ref rotationEuler, .Zero, 0.1f, textWidth, componentEnabled: componentEditable)) { transform.EditorRotationEuler = MathHelper.ToRadians(rotationEuler); @@ -229,7 +229,7 @@ namespace GlitchyEditor.EditWindows } float3 scale = transform.Scale; - if (ImGui.Editfloat3("Scale", ref scale, .One, 0.1f, textWidth)) + if (ImGui.EditFloat3("Scale", ref scale, .One, 0.1f, textWidth)) transform.Scale = scale; } @@ -436,11 +436,11 @@ namespace GlitchyEditor.EditWindows float2 offset = boxCollider.Offset; - if (ImGui.Editfloat2("Offset", ref offset, .Zero, 0.1f, textWidth)) + if (ImGui.EditFloat2("Offset", ref offset, .Zero, 0.1f, textWidth)) boxCollider.Offset = offset; float2 size = boxCollider.Size; - if (ImGui.Editfloat2("Size", ref size, .Zero, 0.1f, textWidth, float2(0.01f, 0.01f), float.PositiveInfinity.XX)) + if (ImGui.EditFloat2("Size", ref size, .Zero, 0.1f, textWidth, float2(0.01f, 0.01f), float.PositiveInfinity.XX)) boxCollider.Size = size; float density = boxCollider.Density; @@ -466,7 +466,7 @@ namespace GlitchyEditor.EditWindows textWidth += ImGui.GetStyle().FramePadding.x * 3.0f; float2 offset = circleCollider.Offset; - if (ImGui.Editfloat2("Offset", ref offset, .Zero, 0.1f, textWidth)) + if (ImGui.EditFloat2("Offset", ref offset, .Zero, 0.1f, textWidth)) circleCollider.Offset = offset; float radius = circleCollider.Radius; @@ -496,7 +496,7 @@ namespace GlitchyEditor.EditWindows textWidth += ImGui.GetStyle().FramePadding.x * 3.0f; float2 offset = polygonCollider.Offset; - if (ImGui.Editfloat2("Offset", ref offset, .Zero, 0.1f, textWidth)) + if (ImGui.EditFloat2("Offset", ref offset, .Zero, 0.1f, textWidth)) polygonCollider.Offset = offset; // TODO: Handles in editor, etc... @@ -504,7 +504,7 @@ namespace GlitchyEditor.EditWindows { for (int i < polygonCollider.VertexCount) { - ImGui.Editfloat2(scope $"{i}", ref polygonCollider.Vertices[i]); + ImGui.EditFloat2(scope $"{i}", ref polygonCollider.Vertices[i]); } } @@ -629,159 +629,108 @@ namespace GlitchyEditor.EditWindows if (scriptComponent.Instance?.IsInitialized == true) { - SharpClass sharpClass = scriptComponent.Instance.ScriptClass; - ScriptInstance scriptInstance = scriptComponent.Instance; + // SharpClass sharpClass = scriptComponent.Instance.ScriptClass; + // ScriptInstance scriptInstance = scriptComponent.Instance; - /*void DoFunnyStuff(void* instance, SharpType sharpType) - { - for (let (fieldName, scriptField) in sharpType.Fields) - { - var monoField = scriptField.[Friend]_monoField; - - switch (scriptField.FieldType) - { - case .Float: - var value = GetData(instance, scriptField); - if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .Float, &value)) - SetData(instance, scriptField, value); - - case .Struct: - { - var v = Mono.mono_field_get_value_object(ScriptEngine.[Friend]s_AppDomain, scriptField.[Friend]_monoField, (.)instance); - - void* dataPtr = Mono.mono_object_unbox(v); - - Span data = .((.)dataPtr, scriptField.SizeInBytes); - - if (ImGui.CollapsingHeader(fieldName.Ptr)) - { - DoFunnyStuff(dataPtr, scriptField.SharpType); - } - - SetData(instance, scriptField, v); - - //Mono.mono_field_set_value_object(ScriptEngine.[Friend]s_AppDomain, scriptField.[Friend]_monoField, (.)instance); - //uint8* data = ; - - /*uint8[] data = scope .[scriptField.SizeInBytes]; - - GetData(instance, scriptField, data.Ptr); - - if (ImGui.CollapsingHeader(fieldName.Ptr)) - { - DoFunnyStuff(data.Ptr, scriptField.SharpType); - } - - MonoObject* boxed = Mono.mono_value_box(ScriptEngine.[Friend]s_AppDomain, ((SharpClass)scriptField.SharpType).[Friend]_monoClass, data.Ptr); - - SetData(instance, scriptField, boxed);*/ - - //Mono.mono_field_get_value(instance, scriptField.[Friend]_monoField, data.Ptr); - - } - default: - //Log.EngineLogger.Error($"Unhandled field type {scriptField.FieldType}"); - } - } - } - - DoFunnyStuff(scriptInstance.[Friend]_instance, sharpClass);*/ - - for (let (fieldName, scriptField) in sharpClass.Fields) - { - var monoField = scriptField.[Friend]_monoField; + // for (let (fieldName, scriptField) in sharpClass.Fields) + // { + // var monoField = scriptField.[Friend]_monoField; - switch (scriptField.FieldType) - { - case .Bool: - var value = GetFieldValue(scriptInstance, scriptField); - if (ImGui.Checkbox(fieldName.ToScopeCStr!(), &value)) - SetFieldValue(scriptInstance, scriptField, value); + // switch (scriptField.FieldType) + // { + // case .Bool: + // var value = GetFieldValue(scriptInstance, scriptField); + // if (ImGui.Checkbox(fieldName.ToScopeCStr!(), &value)) + // SetFieldValue(scriptInstance, scriptField, value); - case .SByte: - var value = GetFieldValue(scriptInstance, scriptField); - if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .S8, &value)) - SetFieldValue(scriptInstance, scriptField, value); - case .Short: - var value = GetFieldValue(scriptInstance, scriptField); - if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .S16, &value)) - SetFieldValue(scriptInstance, scriptField, value); - case .Int: - var value = GetFieldValue(scriptInstance, scriptField); - if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .S32, &value)) - SetFieldValue(scriptInstance, scriptField, value); - case .Long: - var value = GetFieldValue(scriptInstance, scriptField); - if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .S64, &value)) - SetFieldValue(scriptInstance, scriptField, value); + // case .SByte: + // var value = GetFieldValue(scriptInstance, scriptField); + // if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .S8, &value)) + // SetFieldValue(scriptInstance, scriptField, value); + // case .Short: + // var value = GetFieldValue(scriptInstance, scriptField); + // if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .S16, &value)) + // SetFieldValue(scriptInstance, scriptField, value); + // case .Int: + // var value = GetFieldValue(scriptInstance, scriptField); + // if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .S32, &value)) + // SetFieldValue(scriptInstance, scriptField, value); + // case .Long: + // var value = GetFieldValue(scriptInstance, scriptField); + // if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .S64, &value)) + // SetFieldValue(scriptInstance, scriptField, value); - case .Byte: - var value = GetFieldValue(scriptInstance, scriptField); - if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .U8, &value)) - SetFieldValue(scriptInstance, scriptField, value); - case .UShort: - var value = GetFieldValue(scriptInstance, scriptField); - if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .U16, &value)) - SetFieldValue(scriptInstance, scriptField, value); - case .UInt: - var value = GetFieldValue(scriptInstance, scriptField); - if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .U32, &value)) - SetFieldValue(scriptInstance, scriptField, value); - case .ULong: - var value = GetFieldValue(scriptInstance, scriptField); - if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .U64, &value)) - SetFieldValue(scriptInstance, scriptField, value); + // case .Byte: + // var value = GetFieldValue(scriptInstance, scriptField); + // if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .U8, &value)) + // SetFieldValue(scriptInstance, scriptField, value); + // case .UShort: + // var value = GetFieldValue(scriptInstance, scriptField); + // if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .U16, &value)) + // SetFieldValue(scriptInstance, scriptField, value); + // case .UInt: + // var value = GetFieldValue(scriptInstance, scriptField); + // if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .U32, &value)) + // SetFieldValue(scriptInstance, scriptField, value); + // case .ULong: + // var value = GetFieldValue(scriptInstance, scriptField); + // if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .U64, &value)) + // SetFieldValue(scriptInstance, scriptField, value); - case .Float: - var value = GetFieldValue(scriptInstance, scriptField); - if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .Float, &value)) - SetFieldValue(scriptInstance, scriptField, value); + // case .Float: + // var value = GetFieldValue(scriptInstance, scriptField); + // if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .Float, &value)) + // SetFieldValue(scriptInstance, scriptField, value); - case .float2: - GetFieldValue(scriptInstance, scriptField, var value); - if (ImGui.Editfloat2(fieldName, ref value)) - SetFieldValue(scriptInstance, scriptField, value); - case .float3: - GetFieldValue(scriptInstance, scriptField, var value); - if (ImGui.Editfloat3(fieldName, ref value)) - SetFieldValue(scriptInstance, scriptField, value); - case .float4: - GetFieldValue(scriptInstance, scriptField, var value); - if (ImGui.Editfloat4(fieldName, ref value)) - SetFieldValue(scriptInstance, scriptField, value); + // case .float2: + // GetFieldValue(scriptInstance, scriptField, var value); + // if (ImGui.EditFloat2(fieldName, ref value)) + // SetFieldValue(scriptInstance, scriptField, value); + // case .float3: + // GetFieldValue(scriptInstance, scriptField, var value); + // if (ImGui.EditFloat3(fieldName, ref value)) + // SetFieldValue(scriptInstance, scriptField, value); + // case .float4: + // GetFieldValue(scriptInstance, scriptField, var value); + // if (ImGui.EditFloat4(fieldName, ref value)) + // SetFieldValue(scriptInstance, scriptField, value); - case .Double: - var value = GetFieldValue(scriptInstance, scriptField); - if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .Double, &value)) - SetFieldValue(scriptInstance, scriptField, value); + // case .Double: + // var value = GetFieldValue(scriptInstance, scriptField); + // if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .Double, &value)) + // SetFieldValue(scriptInstance, scriptField, value); - case .Entity: - // TODO! + // case .Entity: + // // TODO! - case .Enum: - // TODO! - case .Struct: - // TODO! - /*{ - uint8[] data = scope .[scriptField.SizeInBytes]; + // case .Enum: + // // TODO! + // case .Struct: + // // TODO! + // /*{ + // uint8[] data = scope .[scriptField.SizeInBytes]; - Mono.mono_field_get_value(scriptInstance.[Friend]_instance, scriptField.[Friend]_monoField, data.Ptr); + // Mono.mono_field_get_value(scriptInstance.[Friend]_instance, scriptField.[Friend]_monoField, data.Ptr); - //scriptField. + // //scriptField. - //scriptInstance.GetFieldValue(); + // //scriptInstance.GetFieldValue(); - //scriptInstance.ScriptClass.Fields[] - /* - var value = GetFieldValue(scriptInstance, scriptField); - if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .Double, &value)) - SetFieldValue(scriptInstance, scriptField, value); - */ - }*/ - default: - Log.EngineLogger.Error($"Unhandled field type {scriptField.FieldType}"); - } - } + // //scriptInstance.ScriptClass.Fields[] + // /* + // var value = GetFieldValue(scriptInstance, scriptField); + // if (ImGui.DragScalar(fieldName.ToScopeCStr!(), .Double, &value)) + // SetFieldValue(scriptInstance, scriptField, value); + // */ + // }*/ + // case .Class: + // { + // var value = GetFieldValue(scriptInstance, scriptField); + // } + // default: + // Log.EngineLogger.Error($"Unhandled field type {scriptField.FieldType}"); + // } + // } } else if (scriptClass != null) { @@ -847,15 +796,15 @@ namespace GlitchyEditor.EditWindows field.SetData(value); case .float2: var value = field.GetData(); - if (ImGui.Editfloat2(fieldName, ref value)) + if (ImGui.EditFloat2(fieldName, ref value)) field.SetData(value); case .float3: var value = field.GetData(); - if (ImGui.Editfloat3(fieldName, ref value)) + if (ImGui.EditFloat3(fieldName, ref value)) field.SetData(value); case .float4: var value = field.GetData(); - if (ImGui.Editfloat4(fieldName, ref value)) + if (ImGui.EditFloat4(fieldName, ref value)) field.SetData(value); case .Double: diff --git a/GlitchyEngine/src/ImGui/ImGuiExtension.bf b/GlitchyEngine/src/ImGui/ImGuiExtension.bf index ba32aa7..2440ad8 100644 --- a/GlitchyEngine/src/ImGui/ImGuiExtension.bf +++ b/GlitchyEngine/src/ImGui/ImGuiExtension.bf @@ -117,21 +117,27 @@ namespace ImGui /// 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) + 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) + 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) + 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); }