From 73617ec719daf99730e87e613f7ac16201e10c82 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Wed, 17 Jun 2026 01:37:01 +0200 Subject: [PATCH] Convert CanvasRenderSource static fields/methods to instance members Reorganize RenderCommandType enum into grouped categories --- UI/GUI/Rendering/CanvasRenderSource.cs | 30 ++++++++++----------- UI/GUI/Rendering/RenderCommandType.cs | 37 +++++++++++++++++--------- 2 files changed, 39 insertions(+), 28 deletions(-) diff --git a/UI/GUI/Rendering/CanvasRenderSource.cs b/UI/GUI/Rendering/CanvasRenderSource.cs index 04f96f7..783a126 100644 --- a/UI/GUI/Rendering/CanvasRenderSource.cs +++ b/UI/GUI/Rendering/CanvasRenderSource.cs @@ -10,25 +10,25 @@ namespace RemSox.UI.GUI.Rendering; public sealed class CanvasRenderSource : IRenderSource { - private static readonly Dictionary windowCanvases = []; - private static readonly Dictionary windowPositions = []; - private static readonly Dictionary windowZIndices = []; + private readonly Dictionary windowCanvases = []; + private readonly Dictionary windowPositions = []; + private readonly Dictionary windowZIndices = []; // Sorted list keeps windows in Z-order without re-sorting. // Key = (zIndex << 32 | windowId) so equal Z stays insertion-stable. - private static readonly SortedList zOrderedWindows = []; + private readonly SortedList zOrderedWindows = []; // Accumulated drawing primitives per window (in draw order). - private static readonly Dictionary> windowPrimitives = []; + private readonly Dictionary> windowPrimitives = []; - private static readonly HashSet dirtyWindows = []; - private static bool isPositionDirty = true; - private static Point lastPointerPosition = new(-1, -1); + private readonly HashSet dirtyWindows = []; + private bool isPositionDirty = true; + private Point lastPointerPosition = new(-1, -1); - private static Point cursorPosition; - private static int screenWidth, screenHeight; + private Point cursorPosition; + private int screenWidth, screenHeight; - private static readonly Lock renderLock = new(); + private readonly Lock renderLock = new(); public void Render(IEnumerable commands) { @@ -156,7 +156,7 @@ public sealed class CanvasRenderSource : IRenderSource // --- Accumulated state management --- - private static void CreateOrUpdateWindow(RenderCommand cmd) + private void CreateOrUpdateWindow(RenderCommand cmd) { int id = cmd.WindowId; Size size = Get(cmd.Properties, "Size", new Size(160, 120)); @@ -187,7 +187,7 @@ public sealed class CanvasRenderSource : IRenderSource isPositionDirty = true; } - private static void RemoveWindow(int windowId) + private void RemoveWindow(int windowId) { _ = windowCanvases.Remove(windowId); _ = windowPositions.Remove(windowId); @@ -202,7 +202,7 @@ public sealed class CanvasRenderSource : IRenderSource isPositionDirty = true; } - private static void UpsertPrimitive(RenderCommand cmd) + private void UpsertPrimitive(RenderCommand cmd) { if (!windowPrimitives.TryGetValue(cmd.WindowId, out List<(int ElementId, RenderCommand Command)>? list)) { @@ -223,7 +223,7 @@ public sealed class CanvasRenderSource : IRenderSource _ = dirtyWindows.Add(cmd.WindowId); } - private static void RemovePrimitives(int windowId, int baseElementId) + private void RemovePrimitives(int windowId, int baseElementId) { if (!windowPrimitives.TryGetValue(windowId, out List<(int ElementId, RenderCommand Command)>? list)) { diff --git a/UI/GUI/Rendering/RenderCommandType.cs b/UI/GUI/Rendering/RenderCommandType.cs index 83098e7..f147e92 100644 --- a/UI/GUI/Rendering/RenderCommandType.cs +++ b/UI/GUI/Rendering/RenderCommandType.cs @@ -1,22 +1,33 @@ namespace RemSox.UI.GUI.Rendering; +/// +/// Render command opcodes, grouped by category: +/// 0x01–0x0F System/setup +/// 0x10–0x1F Window lifecycle +/// 0x20–0x2F Primitives lifecycle +/// 0x30–0x3F Primitives draw +/// 0x40+ Future expansion +/// public enum RenderCommandType : byte { - CreateWindow = 0x01, - DestroyWindow = 0x02, - MoveWindow = 0x03, + // System / setup (0x01–0x0F) + ScreenInfo = 0x01, + SetCursor = 0x02, - DrawFilledRect = 0x10, - DrawRectBorder = 0x11, - DrawFilledCircle = 0x12, - DrawCircle = 0x13, - DrawText = 0x14, - DrawLine = 0x15, - DrawPoint = 0x16, + // Window lifecycle (0x10–0x1F) + CreateWindow = 0x10, + DestroyWindow = 0x11, + MoveWindow = 0x12, + // Primitives lifecycle (0x20–0x2F) RemovePrimitives = 0x20, - SetCursor = 0x30, - - ScreenInfo = 0xF0, + // Primitives draw (0x30–0x3F) + DrawFilledRect = 0x30, + DrawRectBorder = 0x31, + DrawFilledCircle = 0x32, + DrawCircle = 0x33, + DrawText = 0x34, + DrawLine = 0x35, + DrawPoint = 0x36, }