Implement z-index for windows and ensure correct stacking order on interaction

This commit is contained in:
Stone_Red
2026-06-08 13:31:27 +02:00
parent 3be75c60f2
commit 4561e1f997
4 changed files with 50 additions and 29 deletions
+14 -4
View File
@@ -1,6 +1,7 @@
using System;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using Cosmos.Kernel.System.Graphics;
namespace RemSox.UI.GUI.Rendering;
@@ -9,11 +10,20 @@ public sealed class CanvasRenderSource : IRenderSource
{
private static readonly Dictionary<int, Canvas> windowCanvases = new();
private static readonly Dictionary<int, Point> windowPositions = new();
private static readonly Dictionary<int, int> windowZIndices = new();
public void Render(IEnumerable<RenderCommand> commands)
{
foreach (RenderCommand command in commands)
{
if (command.ElementType == "Window" || command.ElementType == "WindowMove")
{
if (command.Properties.TryGetValue("ZIndex", out object? rawZIndex) && rawZIndex is int z)
{
windowZIndices[command.WindowId] = z;
}
}
if (command.ElementType == "Window")
{
Size size = command.Properties.TryGetValue("Size", out object? rawSize) && rawSize is Size windowSize
@@ -59,11 +69,11 @@ public sealed class CanvasRenderSource : IRenderSource
{
screenCanvas.Clear(Color.Black);
foreach (var kvp in windowPositions)
var orderedWindows = windowPositions.Keys.OrderBy(id => windowZIndices.TryGetValue(id, out int z) ? z : 0);
foreach (var windowId in orderedWindows)
{
int windowId = kvp.Key;
Point position = kvp.Value;
if (windowCanvases.TryGetValue(windowId, out Canvas? windowCanvas))
if (windowPositions.TryGetValue(windowId, out Point position) && windowCanvases.TryGetValue(windowId, out Canvas? windowCanvas))
{
screenCanvas.DrawCanvas(windowCanvas, position.X, position.Y);
}