mirror of
https://github.com/Stone-Red-Code/RemSox.git
synced 2026-09-07 07:46:28 +02:00
Replace string element render types with RenderCommandType enum, decompose UI elements (Button, CheckBox, chrome) into drawing primitives via ToPrimitives(), emit per-element commands on flush, and move composite into IRenderSource.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using RemSox.UI.GUI.Rendering;
|
||||
|
||||
using System.Drawing;
|
||||
|
||||
namespace RemSox.UI.GUI.UIEelements.Controls;
|
||||
@@ -18,6 +20,58 @@ public class Button() : Control("Button")
|
||||
set => SetProperty(nameof(TextColor), ref field, value);
|
||||
} = Color.Black;
|
||||
|
||||
public override IEnumerable<RenderCommand> ToPrimitives(int windowId)
|
||||
{
|
||||
// Background fill
|
||||
yield return new RenderCommand
|
||||
{
|
||||
WindowId = windowId,
|
||||
ElementId = PrimitiveId(0),
|
||||
Type = RenderCommandType.DrawFilledRect,
|
||||
Position = Position,
|
||||
Properties = new Dictionary<string, object?>
|
||||
{
|
||||
["Color"] = BackgroundColor,
|
||||
["Size"] = Size,
|
||||
}
|
||||
};
|
||||
|
||||
// Border
|
||||
yield return new RenderCommand
|
||||
{
|
||||
WindowId = windowId,
|
||||
ElementId = PrimitiveId(1),
|
||||
Type = RenderCommandType.DrawRectBorder,
|
||||
Position = Position,
|
||||
Properties = new Dictionary<string, object?>
|
||||
{
|
||||
["Color"] = Color.DarkGray,
|
||||
["Size"] = Size,
|
||||
}
|
||||
};
|
||||
|
||||
// Text (centered)
|
||||
if (!string.IsNullOrEmpty(Text))
|
||||
{
|
||||
int tx = Position.X + (Size.Width / 2) - (Text.Length * 4);
|
||||
int ty = Position.Y + (Size.Height / 2) - 8;
|
||||
|
||||
yield return new RenderCommand
|
||||
{
|
||||
WindowId = windowId,
|
||||
ElementId = PrimitiveId(2),
|
||||
Type = RenderCommandType.DrawText,
|
||||
Position = new Point(tx, ty),
|
||||
Properties = new Dictionary<string, object?>
|
||||
{
|
||||
["Color"] = TextColor,
|
||||
["Content"] = Text,
|
||||
["FontSize"] = Size.Height - 8,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public override void HandleMouseEvent(MouseEvent mouseEvent)
|
||||
{
|
||||
if (mouseEvent.Type == MouseEventType.ButtonDown && mouseEvent.Button == MouseButton.Left)
|
||||
|
||||
Reference in New Issue
Block a user