Convert CanvasRenderSource static fields/methods to instance members

Reorganize RenderCommandType enum into grouped categories
This commit is contained in:
Stone_Red
2026-06-17 01:37:01 +02:00
parent 5cd1f6654b
commit 73617ec719
2 changed files with 39 additions and 28 deletions
+15 -15
View File
@@ -10,25 +10,25 @@ namespace RemSox.UI.GUI.Rendering;
public sealed class CanvasRenderSource : IRenderSource public sealed class CanvasRenderSource : IRenderSource
{ {
private static readonly Dictionary<int, Canvas> windowCanvases = []; private readonly Dictionary<int, Canvas> windowCanvases = [];
private static readonly Dictionary<int, Point> windowPositions = []; private readonly Dictionary<int, Point> windowPositions = [];
private static readonly Dictionary<int, int> windowZIndices = []; private readonly Dictionary<int, int> windowZIndices = [];
// Sorted list keeps windows in Z-order without re-sorting. // Sorted list keeps windows in Z-order without re-sorting.
// Key = (zIndex << 32 | windowId) so equal Z stays insertion-stable. // Key = (zIndex << 32 | windowId) so equal Z stays insertion-stable.
private static readonly SortedList<long, int> zOrderedWindows = []; private readonly SortedList<long, int> zOrderedWindows = [];
// Accumulated drawing primitives per window (in draw order). // Accumulated drawing primitives per window (in draw order).
private static readonly Dictionary<int, List<(int ElementId, RenderCommand Command)>> windowPrimitives = []; private readonly Dictionary<int, List<(int ElementId, RenderCommand Command)>> windowPrimitives = [];
private static readonly HashSet<int> dirtyWindows = []; private readonly HashSet<int> dirtyWindows = [];
private static bool isPositionDirty = true; private bool isPositionDirty = true;
private static Point lastPointerPosition = new(-1, -1); private Point lastPointerPosition = new(-1, -1);
private static Point cursorPosition; private Point cursorPosition;
private static int screenWidth, screenHeight; private int screenWidth, screenHeight;
private static readonly Lock renderLock = new(); private readonly Lock renderLock = new();
public void Render(IEnumerable<RenderCommand> commands) public void Render(IEnumerable<RenderCommand> commands)
{ {
@@ -156,7 +156,7 @@ public sealed class CanvasRenderSource : IRenderSource
// --- Accumulated state management --- // --- Accumulated state management ---
private static void CreateOrUpdateWindow(RenderCommand cmd) private void CreateOrUpdateWindow(RenderCommand cmd)
{ {
int id = cmd.WindowId; int id = cmd.WindowId;
Size size = Get(cmd.Properties, "Size", new Size(160, 120)); Size size = Get(cmd.Properties, "Size", new Size(160, 120));
@@ -187,7 +187,7 @@ public sealed class CanvasRenderSource : IRenderSource
isPositionDirty = true; isPositionDirty = true;
} }
private static void RemoveWindow(int windowId) private void RemoveWindow(int windowId)
{ {
_ = windowCanvases.Remove(windowId); _ = windowCanvases.Remove(windowId);
_ = windowPositions.Remove(windowId); _ = windowPositions.Remove(windowId);
@@ -202,7 +202,7 @@ public sealed class CanvasRenderSource : IRenderSource
isPositionDirty = true; 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)) 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); _ = 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)) if (!windowPrimitives.TryGetValue(windowId, out List<(int ElementId, RenderCommand Command)>? list))
{ {
+24 -13
View File
@@ -1,22 +1,33 @@
namespace RemSox.UI.GUI.Rendering; namespace RemSox.UI.GUI.Rendering;
/// <summary>
/// Render command opcodes, grouped by category:
/// 0x010x0F System/setup
/// 0x100x1F Window lifecycle
/// 0x200x2F Primitives lifecycle
/// 0x300x3F Primitives draw
/// 0x40+ Future expansion
/// </summary>
public enum RenderCommandType : byte public enum RenderCommandType : byte
{ {
CreateWindow = 0x01, // System / setup (0x010x0F)
DestroyWindow = 0x02, ScreenInfo = 0x01,
MoveWindow = 0x03, SetCursor = 0x02,
DrawFilledRect = 0x10, // Window lifecycle (0x100x1F)
DrawRectBorder = 0x11, CreateWindow = 0x10,
DrawFilledCircle = 0x12, DestroyWindow = 0x11,
DrawCircle = 0x13, MoveWindow = 0x12,
DrawText = 0x14,
DrawLine = 0x15,
DrawPoint = 0x16,
// Primitives lifecycle (0x200x2F)
RemovePrimitives = 0x20, RemovePrimitives = 0x20,
SetCursor = 0x30, // Primitives draw (0x300x3F)
DrawFilledRect = 0x30,
ScreenInfo = 0xF0, DrawRectBorder = 0x31,
DrawFilledCircle = 0x32,
DrawCircle = 0x33,
DrawText = 0x34,
DrawLine = 0x35,
DrawPoint = 0x36,
} }