mirror of
https://github.com/Stone-Red-Code/RemSox.git
synced 2026-09-08 15:56:29 +02:00
Initial commit
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using Cosmos.Kernel.System.Graphics;
|
||||
|
||||
namespace RemSox.UI.GUI.Rendering;
|
||||
|
||||
public sealed class CanvasRenderSource : IRenderSource
|
||||
{
|
||||
public void Render(IEnumerable<RenderCommand> commands)
|
||||
{
|
||||
Canvas canvas = FullScreenCanvas.GetFullScreenCanvas();
|
||||
|
||||
foreach (RenderCommand command in commands)
|
||||
{
|
||||
if (command.ElementType == "Window")
|
||||
{
|
||||
RenderWindow(canvas, command);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (command.ElementType == "Circle")
|
||||
{
|
||||
RenderCircle(canvas, command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void RenderWindow(Canvas canvas, RenderCommand command)
|
||||
{
|
||||
int x = command.Position.X;
|
||||
int y = command.Position.Y;
|
||||
|
||||
Size size = command.Properties.TryGetValue(nameof(Size), out object? rawSize) && rawSize is Size windowSize
|
||||
? windowSize
|
||||
: new Size(160, 120);
|
||||
|
||||
bool isFocused = command.Properties.TryGetValue(nameof(Windows.Window.IsFocused), out object? rawFocused) && rawFocused is bool focused && focused;
|
||||
|
||||
Color borderColor = isFocused ? Color.White : Color.DarkGray;
|
||||
Color bodyColor = Color.FromArgb(32, 32, 32);
|
||||
Color titleColor = isFocused ? Color.FromArgb(0, 120, 215) : Color.FromArgb(80, 80, 80);
|
||||
|
||||
canvas.DrawFilledRectangle(bodyColor, x, y, size.Width, size.Height);
|
||||
canvas.DrawFilledRectangle(titleColor, x, y, size.Width, 18);
|
||||
canvas.DrawRectangle(borderColor, x, y, size.Width, size.Height);
|
||||
}
|
||||
|
||||
private static void RenderCircle(Canvas canvas, RenderCommand command)
|
||||
{
|
||||
Color color = command.Properties.TryGetValue(nameof(Color), out object? rawColor) && rawColor is Color circleColor
|
||||
? circleColor
|
||||
: Color.White;
|
||||
|
||||
int radius = command.Properties.TryGetValue(nameof(Radius), out object? rawRadius) && rawRadius is int circleRadius
|
||||
? circleRadius
|
||||
: 10;
|
||||
|
||||
int centerX = command.Position.X + radius;
|
||||
int centerY = command.Position.Y + radius;
|
||||
|
||||
canvas.DrawFilledCircle(color, centerX, centerY, radius);
|
||||
}
|
||||
|
||||
private static string Radius => nameof(Radius);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace RemSox.UI.GUI.Rendering;
|
||||
|
||||
public interface IRenderSource
|
||||
{
|
||||
public void Render(IEnumerable<RenderCommand> commands);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace RemSox.UI.GUI.Rendering;
|
||||
|
||||
public class RenderCommand
|
||||
{
|
||||
public required int ElementId { get; set; }
|
||||
public required string ElementType { get; set; }
|
||||
public required Point Position { get; set; }
|
||||
public required IReadOnlyDictionary<string, object?> Properties { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user