diff --git a/Source/Editor/Surface/SurfaceComment.cs b/Source/Editor/Surface/SurfaceComment.cs index 86b68da4e..54c438fe3 100644 --- a/Source/Editor/Surface/SurfaceComment.cs +++ b/Source/Editor/Surface/SurfaceComment.cs @@ -1,7 +1,6 @@ // Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. using System; -using FlaxEditor.GUI; using FlaxEditor.GUI.ContextMenu; using FlaxEditor.GUI.Input; using FlaxEngine; @@ -86,7 +85,10 @@ namespace FlaxEditor.Surface // Read node data Title = TitleValue; Color = ColorValue; - Size = SizeValue; + var size = SizeValue; + if (Surface.GridSnappingEnabled) + size = Surface.SnapToGrid(size, true); + Size = size; // Order // Backwards compatibility - When opening with an older version send the old comments to the back @@ -299,7 +301,10 @@ namespace FlaxEditor.Surface if (_isResizing) { // Update size - Size = Float2.Max(location, new Float2(140.0f, _headerRect.Bottom)); + var size = Float2.Max(location, new Float2(140.0f, _headerRect.Bottom)); + if (Surface.GridSnappingEnabled) + size = Surface.SnapToGrid(size, true); + Size = size; } else { diff --git a/Source/Editor/Surface/SurfaceControl.cs b/Source/Editor/Surface/SurfaceControl.cs index 9774d76ba..29d7c1768 100644 --- a/Source/Editor/Surface/SurfaceControl.cs +++ b/Source/Editor/Surface/SurfaceControl.cs @@ -131,6 +131,15 @@ namespace FlaxEditor.Surface /// public virtual void OnSurfaceLoaded(SurfaceNodeActions action) { + // Snap bounds (with ceil) when using grid snapping + if (Surface.GridSnappingEnabled) + { + var bounds = Bounds; + bounds.Location = Surface.SnapToGrid(bounds.Location, false); + bounds.Size = Surface.SnapToGrid(bounds.Size, true); + Bounds = bounds; + } + UpdateRectangles(); } diff --git a/Source/Editor/Surface/SurfaceNode.cs b/Source/Editor/Surface/SurfaceNode.cs index 936b68f04..c5c011db0 100644 --- a/Source/Editor/Surface/SurfaceNode.cs +++ b/Source/Editor/Surface/SurfaceNode.cs @@ -167,6 +167,15 @@ namespace FlaxEditor.Surface if (Surface == null) return; + // Snap bounds (with ceil) when using grid snapping + if (Surface.GridSnappingEnabled) + { + var size = Surface.SnapToGrid(new Float2(width, height), true); + width = size.X; + height = size.Y; + } + + // Arrange output boxes on the right edge for (int i = 0; i < Elements.Count; i++) { if (Elements[i] is OutputBox box) @@ -175,6 +184,7 @@ namespace FlaxEditor.Surface } } + // Resize Size = CalculateNodeSize(width, height); }