From a92d2b6ca2353d862c60086e77507a2e0a0955a7 Mon Sep 17 00:00:00 2001 From: Saas Date: Sat, 20 Dec 2025 16:58:35 +0100 Subject: [PATCH] add slight background grid --- Source/Editor/Surface/VisjectSurface.Draw.cs | 47 +++++++++++++++++--- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/Source/Editor/Surface/VisjectSurface.Draw.cs b/Source/Editor/Surface/VisjectSurface.Draw.cs index 0138bce8d..0b7f6eaae 100644 --- a/Source/Editor/Surface/VisjectSurface.Draw.cs +++ b/Source/Editor/Surface/VisjectSurface.Draw.cs @@ -66,6 +66,47 @@ namespace FlaxEditor.Surface protected virtual void DrawBackground() { DrawBackgroundSolidColor(Style.BackgroundColor, Width, Height); + DrawGridBackground(Width, Height); + } + + // TODO: Rename (and get rid of old texture based draw background?) + internal static void DrawBackgroundSolidColor(Color color, float width, float height) + { + Rectangle backgroundRect = new Rectangle(0f, 0f, width, height); + Render2D.FillRectangle(backgroundRect, color); + } + + internal void DrawGridBackground(float width, float height) + { + var viewRect = GetClientArea(); + var upperLeft = _rootControl.PointFromParent(viewRect.Location); + var bottomRight = _rootControl.PointFromParent(viewRect.Size); + var min = Float2.Min(upperLeft, bottomRight); + var max = Float2.Max(upperLeft, bottomRight); + var pixelRange = (max - min) * ViewScale * 2.75f; + Render2D.PushClip(ref viewRect); + DrawAxis(Float2.UnitX, viewRect, min.X, max.X, pixelRange.X); + DrawAxis(Float2.UnitY, viewRect, min.Y, max.Y, pixelRange.Y); + Render2D.PopClip(); + } + + private void DrawAxis(Float2 axis, Rectangle viewRect, float min, float max, float pixelRange) + { + var linesColor = Style.BackgroundColor.RGBMultiplied(1.2f); + float[] _gridTickStrengths = { 0f }; + Utilities.Utils.DrawCurveTicks((decimal tick, double step, float strength) => + { + var p = _rootControl.PointToParent(axis * (float)tick); ; + + // Draw line + var lineRect = new Rectangle + ( + viewRect.Location + (p - 0.5f) * axis, + Float2.Lerp(viewRect.Size, Float2.One, axis) + ); + Render2D.FillRectangle(lineRect, linesColor.AlphaMultiplied(strength)); + + }, Utilities.Utils.CurveTickSteps, ref _gridTickStrengths, min, max, pixelRange); } internal static void DrawBackgroundDefault(Texture background, float width, float height) @@ -95,12 +136,6 @@ namespace FlaxEditor.Surface } } - internal static void DrawBackgroundSolidColor(Color color, float width, float height) - { - Rectangle backgroundRect = new Rectangle(0f, 0f, width, height); - Render2D.FillRectangle(backgroundRect, color); - } - /// /// Draws the selection background. ///