From f22e559e83a912f8f9f750daf278dd264b381cc6 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Wed, 22 May 2024 20:45:37 -0500 Subject: [PATCH 1/8] Add slot spacing to uniform grid panel. --- .../Engine/UI/GUI/Panels/UniformGridPanel.cs | 56 ++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/Source/Engine/UI/GUI/Panels/UniformGridPanel.cs b/Source/Engine/UI/GUI/Panels/UniformGridPanel.cs index 6c112d9d5..2353a5d99 100644 --- a/Source/Engine/UI/GUI/Panels/UniformGridPanel.cs +++ b/Source/Engine/UI/GUI/Panels/UniformGridPanel.cs @@ -11,6 +11,7 @@ namespace FlaxEngine.GUI { private Margin _slotPadding; private int _slotsV, _slotsH; + private Float2 _slotSpacing; /// /// Gets or sets the padding given to each slot. @@ -62,11 +63,25 @@ namespace FlaxEngine.GUI } } + /// + /// Gets or sets grid slot spacing. + /// + [EditorOrder(30), Limit(0), Tooltip("The Grid slot spacing.")] + public Float2 SlotSpacing + { + get => _slotSpacing; + set + { + _slotSpacing = value; + PerformLayout(); + } + } + /// /// Initializes a new instance of the class. /// public UniformGridPanel() - : this(2) + : this(0) { } @@ -74,10 +89,11 @@ namespace FlaxEngine.GUI /// Initializes a new instance of the class. /// /// The slot padding. - public UniformGridPanel(float slotPadding = 2) + public UniformGridPanel(float slotPadding = 0) { AutoFocus = false; SlotPadding = new Margin(slotPadding); + SlotSpacing = new Float2(2); _slotsH = _slotsV = 5; } @@ -122,6 +138,42 @@ namespace FlaxEngine.GUI var slotBounds = new Rectangle(slotSize.X * x, slotSize.Y * y, slotSize.X, slotSize.Y); _slotPadding.ShrinkRectangle(ref slotBounds); + if (slotsV > 1) + { + if (y == 0) + { + slotBounds.Height -= _slotSpacing.Y * 0.5f * slotsV; + } + else if (y == slotsV - 1) + { + slotBounds.Height -= _slotSpacing.Y * 0.5f * slotsV; + slotBounds.Y += _slotSpacing.Y * 0.5f * slotsV; + } + else + { + slotBounds.Height -= _slotSpacing.Y * 0.5f * slotsV; + slotBounds.Y += _slotSpacing.Y * 0.5f; + } + } + + if (slotsH > 1) + { + if (x == 0) + { + slotBounds.Width -= _slotSpacing.X * 0.5f * slotsH; + } + else if (x == slotsH - 1) + { + slotBounds.Width -= _slotSpacing.X * 0.5f * slotsH; + slotBounds.X += _slotSpacing.X * 0.5f * slotsH; + } + else + { + slotBounds.Width -= _slotSpacing.X * 0.5f * slotsH; + slotBounds.X += _slotSpacing.X * 0.5f; + } + } + var c = _children[i++]; c.Bounds = slotBounds; } From 30c1068a13c18b704cb4966afe7575920933d919 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 30 May 2024 08:38:42 -0500 Subject: [PATCH 2/8] Fix wrong spacing calculation. --- Source/Engine/UI/GUI/Panels/UniformGridPanel.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/Engine/UI/GUI/Panels/UniformGridPanel.cs b/Source/Engine/UI/GUI/Panels/UniformGridPanel.cs index 2353a5d99..80d96f7c2 100644 --- a/Source/Engine/UI/GUI/Panels/UniformGridPanel.cs +++ b/Source/Engine/UI/GUI/Panels/UniformGridPanel.cs @@ -142,16 +142,16 @@ namespace FlaxEngine.GUI { if (y == 0) { - slotBounds.Height -= _slotSpacing.Y * 0.5f * slotsV; + slotBounds.Height -= _slotSpacing.Y * 0.5f; } else if (y == slotsV - 1) { - slotBounds.Height -= _slotSpacing.Y * 0.5f * slotsV; - slotBounds.Y += _slotSpacing.Y * 0.5f * slotsV; + slotBounds.Height -= _slotSpacing.Y * 0.5f; + slotBounds.Y += _slotSpacing.Y * 0.5f; } else { - slotBounds.Height -= _slotSpacing.Y * 0.5f * slotsV; + slotBounds.Height -= _slotSpacing.Y; slotBounds.Y += _slotSpacing.Y * 0.5f; } } @@ -160,16 +160,16 @@ namespace FlaxEngine.GUI { if (x == 0) { - slotBounds.Width -= _slotSpacing.X * 0.5f * slotsH; + slotBounds.Width -= _slotSpacing.X * 0.5f; } else if (x == slotsH - 1) { - slotBounds.Width -= _slotSpacing.X * 0.5f * slotsH; - slotBounds.X += _slotSpacing.X * 0.5f * slotsH; + slotBounds.Width -= _slotSpacing.X * 0.5f; + slotBounds.X += _slotSpacing.X * 0.5f; } else { - slotBounds.Width -= _slotSpacing.X * 0.5f * slotsH; + slotBounds.Width -= _slotSpacing.X; slotBounds.X += _slotSpacing.X * 0.5f; } } From f3210608aefa28243d39661f31228feed3b2ef67 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 30 May 2024 09:07:42 -0500 Subject: [PATCH 3/8] make color value box the same spacing as the others in the editor. --- Source/Editor/GUI/Input/ColorValueBox.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Editor/GUI/Input/ColorValueBox.cs b/Source/Editor/GUI/Input/ColorValueBox.cs index ec437ad5a..1531266e3 100644 --- a/Source/Editor/GUI/Input/ColorValueBox.cs +++ b/Source/Editor/GUI/Input/ColorValueBox.cs @@ -130,7 +130,7 @@ namespace FlaxEditor.GUI.Input base.Draw(); var style = Style.Current; - var r = new Rectangle(2, 2, Width - 4, Height - 4); + var r = new Rectangle(0, 0, Width, Height); Render2D.FillRectangle(r, _value); Render2D.DrawRectangle(r, IsMouseOver || IsNavFocused ? style.BackgroundSelected : Color.Black); From cdd53f09b92c5dddd143f8c44f27588cb21eff4a Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 30 May 2024 10:01:32 -0500 Subject: [PATCH 4/8] Add extra spacing for transform properties. --- .../Editors/ActorTransformEditor.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Source/Editor/CustomEditors/Editors/ActorTransformEditor.cs b/Source/Editor/CustomEditors/Editors/ActorTransformEditor.cs index 3794bffc8..e341d4d4f 100644 --- a/Source/Editor/CustomEditors/Editors/ActorTransformEditor.cs +++ b/Source/Editor/CustomEditors/Editors/ActorTransformEditor.cs @@ -41,6 +41,13 @@ namespace FlaxEditor.CustomEditors.Editors public override void Initialize(LayoutElementsContainer layout) { base.Initialize(layout); + + if (XElement.ValueBox.Parent is UniformGridPanel ug) + { + ug.Height += 2; + ug.SlotSpacing = new Float2(4); + ug.SlotPadding = new Margin(0, 0, 1, 1); + } // Override colors var back = FlaxEngine.GUI.Style.Current.TextBoxBackground; @@ -66,6 +73,13 @@ namespace FlaxEditor.CustomEditors.Editors public override void Initialize(LayoutElementsContainer layout) { base.Initialize(layout); + + if (XElement.ValueBox.Parent is UniformGridPanel ug) + { + ug.Height += 2; + ug.SlotSpacing = new Float2(4); + ug.SlotPadding = new Margin(0, 0, 1, 1); + } // Override colors var back = FlaxEngine.GUI.Style.Current.TextBoxBackground; @@ -122,6 +136,13 @@ namespace FlaxEditor.CustomEditors.Editors menu.AddButton("Link", ToggleLink).LinkTooltip("Links scale components for uniform scaling"); }; } + + if (XElement.ValueBox.Parent is UniformGridPanel ug) + { + ug.Height += 2; + ug.SlotSpacing = new Float2(4); + ug.SlotPadding = new Margin(0, 0, 1, 1); + } // Override colors var back = FlaxEngine.GUI.Style.Current.TextBoxBackground; From 07371ddfdfe67a6ddf1ed25f558d39dcd42caa64 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Sat, 8 Jun 2024 19:20:28 +0300 Subject: [PATCH 5/8] Fix crash when PhysicsMaterial asset is reloaded in editor --- Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp | 10 ++++++++++ Source/Engine/Physics/Physics.cpp | 2 +- Source/Engine/Physics/PhysicsBackend.h | 1 + Source/Engine/Physics/PhysicsBackendEmpty.cpp | 4 ++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp b/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp index 8824abdfa..80d264857 100644 --- a/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp +++ b/Source/Engine/Physics/PhysX/PhysicsBackendPhysX.cpp @@ -4474,6 +4474,16 @@ void PhysicsBackend::DestroyController(void* controller) controllerPhysX->release(); } +void PhysicsBackend::DestroyMaterial(void* material) +{ + ASSERT_LOW_LAYER(material); + auto materialPhysX = (PxMaterial*)material; + materialPhysX->userData = nullptr; + FlushLocker.Lock(); + DeleteObjects.Add(materialPhysX); + FlushLocker.Unlock(); +} + void PhysicsBackend::DestroyObject(void* object) { ASSERT_LOW_LAYER(object); diff --git a/Source/Engine/Physics/Physics.cpp b/Source/Engine/Physics/Physics.cpp index 4a16b4923..a1a5e8db2 100644 --- a/Source/Engine/Physics/Physics.cpp +++ b/Source/Engine/Physics/Physics.cpp @@ -81,7 +81,7 @@ void PhysicsSettings::Deserialize(DeserializeStream& stream, ISerializeModifier* PhysicalMaterial::~PhysicalMaterial() { if (_material) - PhysicsBackend::DestroyObject(_material); + PhysicsBackend::DestroyMaterial(_material); } bool PhysicsService::Init() diff --git a/Source/Engine/Physics/PhysicsBackend.h b/Source/Engine/Physics/PhysicsBackend.h index 8bd493267..f070a7bfb 100644 --- a/Source/Engine/Physics/PhysicsBackend.h +++ b/Source/Engine/Physics/PhysicsBackend.h @@ -314,6 +314,7 @@ public: static void DestroyShape(void* shape); static void DestroyJoint(void* joint); static void DestroyController(void* controller); + static void DestroyMaterial(void* material); static void DestroyObject(void* object); static void RemoveCollider(PhysicsColliderActor* collider); static void RemoveJoint(Joint* joint); diff --git a/Source/Engine/Physics/PhysicsBackendEmpty.cpp b/Source/Engine/Physics/PhysicsBackendEmpty.cpp index 941813b2e..566c40303 100644 --- a/Source/Engine/Physics/PhysicsBackendEmpty.cpp +++ b/Source/Engine/Physics/PhysicsBackendEmpty.cpp @@ -865,6 +865,10 @@ void PhysicsBackend::DestroyController(void* controller) { } +void PhysicsBackend::DestroyMaterial(void* material) +{ +} + void PhysicsBackend::DestroyObject(void* object) { } From 7614481d78d1116adebdd5157560ee46708b988f Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Sat, 8 Jun 2024 19:21:13 +0300 Subject: [PATCH 6/8] Fix PhysicsMaterial not updating in Colliders after asset reload --- Source/Engine/Physics/Colliders/Collider.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Engine/Physics/Colliders/Collider.cpp b/Source/Engine/Physics/Colliders/Collider.cpp index 6175c9058..793368abe 100644 --- a/Source/Engine/Physics/Colliders/Collider.cpp +++ b/Source/Engine/Physics/Colliders/Collider.cpp @@ -21,6 +21,8 @@ Collider::Collider(const SpawnParams& params) , _cachedScale(1.0f) , _contactOffset(2.0f) { + Material.Loaded.Bind(this); + Material.Unload.Bind(this); Material.Changed.Bind(this); } From 992436b47c2059706d3d01c9ca44be7e606591a8 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Fri, 7 Jun 2024 22:17:15 +0300 Subject: [PATCH 7/8] Fix error when previewing animation timeline values after reimport --- Source/Editor/GUI/Timeline/Tracks/MemberTrack.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/Editor/GUI/Timeline/Tracks/MemberTrack.cs b/Source/Editor/GUI/Timeline/Tracks/MemberTrack.cs index 0361ffe6f..b280c5758 100644 --- a/Source/Editor/GUI/Timeline/Tracks/MemberTrack.cs +++ b/Source/Editor/GUI/Timeline/Tracks/MemberTrack.cs @@ -363,6 +363,8 @@ namespace FlaxEditor.GUI.Timeline.Tracks /// public override void OnDestroy() { + if (_previewValue != null) + Timeline.ShowPreviewValuesChanged -= OnTimelineShowPreviewValuesChanged; _previewValue = null; _rightKey = null; _addKey = null; From 7ba97f3c3210342c7d33adcf98acc607385e0f03 Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Sat, 8 Jun 2024 21:16:43 +0300 Subject: [PATCH 8/8] Fix freeing managed Object references in marshalled arrays --- Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs index 341fb1f99..70b23502b 100644 --- a/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs +++ b/Source/Tools/Flax.Build/Bindings/BindingsGenerator.CSharp.cs @@ -1669,7 +1669,7 @@ namespace Flax.Build.Bindings toManagedContent.AppendLine($"unmanaged.{fieldInfo.Name} != IntPtr.Zero ? NativeInterop.ConvertArray((Unsafe.As(ManagedHandle.FromIntPtr(unmanaged.{fieldInfo.Name}).Target)).ToSpan<{internalElementType}>(), {originalElementTypeMarshaller}.ToManaged) : null;"); toNativeContent.AppendLine($"managed.{fieldInfo.Name}?.Length > 0 ? ManagedHandle.ToIntPtr(ManagedArray.WrapNewArray(NativeInterop.ConvertArray(managed.{fieldInfo.Name}, {originalElementTypeMarshaller}.ToNative)), GCHandleType.Weak) : IntPtr.Zero;"); freeContents.AppendLine($"if (unmanaged.{fieldInfo.Name} != IntPtr.Zero) {{ ManagedHandle handle = ManagedHandle.FromIntPtr(unmanaged.{fieldInfo.Name}); Span<{internalElementType}> values = (Unsafe.As(handle.Target)).ToSpan<{internalElementType}>(); foreach (var value in values) {{ {originalElementTypeMarshaller}.Free(value); }} (Unsafe.As(handle.Target)).Free(); handle.Free(); }}"); - freeContents2.AppendLine($"if (unmanaged.{fieldInfo.Name} != IntPtr.Zero) {{ ManagedHandle handle = ManagedHandle.FromIntPtr(unmanaged.{fieldInfo.Name}); Span<{internalElementType}> values = (Unsafe.As(handle.Target)).ToSpan<{internalElementType}>(); foreach (var value in values) {{ {originalElementTypeMarshaller}.Free(value); }} (Unsafe.As(handle.Target)).Free(); handle.Free(); }}"); + freeContents2.AppendLine($"if (unmanaged.{fieldInfo.Name} != IntPtr.Zero) {{ ManagedHandle handle = ManagedHandle.FromIntPtr(unmanaged.{fieldInfo.Name}); Span<{internalElementType}> values = (Unsafe.As(handle.Target)).ToSpan<{internalElementType}>(); foreach (var value in values) {{ {originalElementTypeMarshaller}.NativeToManaged.Free(value); }} (Unsafe.As(handle.Target)).Free(); handle.Free(); }}"); } else if (fieldInfo.Type.GenericArgs[0].IsObjectRef) { @@ -1720,7 +1720,7 @@ namespace Flax.Build.Bindings toManagedContent.AppendLine($"{internalTypeMarshaller}.ToManaged(unmanaged.{fieldInfo.Name});"); toNativeContent.AppendLine($"{internalTypeMarshaller}.ToNative(managed.{fieldInfo.Name});"); freeContents.AppendLine($"{internalTypeMarshaller}.Free(unmanaged.{fieldInfo.Name});"); - freeContents2.AppendLine($"{internalTypeMarshaller}.Free(unmanaged.{fieldInfo.Name});"); + freeContents2.AppendLine($"{internalTypeMarshaller}.NativeToManaged.Free(unmanaged.{fieldInfo.Name});"); } /*else if (originalType == "Guid") {