mirror of
https://github.com/Stone-Red-Code/RemSox.git
synced 2026-09-07 23:41:47 +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)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using RemSox.UI.GUI.Rendering;
|
||||
|
||||
using System.Drawing;
|
||||
|
||||
namespace RemSox.UI.GUI.UIEelements.Controls;
|
||||
@@ -28,6 +30,74 @@ public class CheckBox() : Control("CheckBox")
|
||||
set => SetProperty(nameof(TextColor), ref field, value);
|
||||
} = Color.White;
|
||||
|
||||
public override IEnumerable<RenderCommand> ToPrimitives(int windowId)
|
||||
{
|
||||
int boxSize = Size.Height;
|
||||
|
||||
// Checkbox box background
|
||||
yield return new RenderCommand
|
||||
{
|
||||
WindowId = windowId,
|
||||
ElementId = PrimitiveId(0),
|
||||
Type = RenderCommandType.DrawFilledRect,
|
||||
Position = Position,
|
||||
Properties = new Dictionary<string, object?>
|
||||
{
|
||||
["Color"] = BackgroundColor,
|
||||
["Size"] = new Size(boxSize, boxSize),
|
||||
}
|
||||
};
|
||||
|
||||
// Checkbox box border
|
||||
yield return new RenderCommand
|
||||
{
|
||||
WindowId = windowId,
|
||||
ElementId = PrimitiveId(1),
|
||||
Type = RenderCommandType.DrawRectBorder,
|
||||
Position = Position,
|
||||
Properties = new Dictionary<string, object?>
|
||||
{
|
||||
["Color"] = Color.DarkGray,
|
||||
["Size"] = new Size(boxSize, boxSize),
|
||||
}
|
||||
};
|
||||
|
||||
// Check mark (filled inner rect)
|
||||
if (IsChecked)
|
||||
{
|
||||
yield return new RenderCommand
|
||||
{
|
||||
WindowId = windowId,
|
||||
ElementId = PrimitiveId(2),
|
||||
Type = RenderCommandType.DrawFilledRect,
|
||||
Position = new Point(Position.X + 3, Position.Y + 3),
|
||||
Properties = new Dictionary<string, object?>
|
||||
{
|
||||
["Color"] = Color.Black,
|
||||
["Size"] = new Size(boxSize - 6, boxSize - 6),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Label text
|
||||
if (!string.IsNullOrEmpty(Text))
|
||||
{
|
||||
yield return new RenderCommand
|
||||
{
|
||||
WindowId = windowId,
|
||||
ElementId = PrimitiveId(3),
|
||||
Type = RenderCommandType.DrawText,
|
||||
Position = new Point(Position.X + boxSize + 5, Position.Y - 2),
|
||||
Properties = new Dictionary<string, object?>
|
||||
{
|
||||
["Color"] = TextColor,
|
||||
["Content"] = Text,
|
||||
["FontSize"] = boxSize,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public override void HandleMouseEvent(MouseEvent mouseEvent)
|
||||
{
|
||||
if (mouseEvent.Type == MouseEventType.ButtonDown && mouseEvent.Button == MouseButton.Left)
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
using RemSox.UI.GUI.Rendering;
|
||||
|
||||
using System.Drawing;
|
||||
|
||||
namespace RemSox.UI.GUI.UIEelements.Shapes;
|
||||
|
||||
public class Circle() : Shape("Circle")
|
||||
@@ -7,4 +11,26 @@ public class Circle() : Shape("Circle")
|
||||
get;
|
||||
set => SetProperty(nameof(Radius), ref field, value);
|
||||
}
|
||||
|
||||
public bool IsFilled
|
||||
{
|
||||
get;
|
||||
set => SetProperty(nameof(IsFilled), ref field, value);
|
||||
} = true;
|
||||
|
||||
public override IEnumerable<RenderCommand> ToPrimitives(int windowId)
|
||||
{
|
||||
yield return new RenderCommand
|
||||
{
|
||||
WindowId = windowId,
|
||||
ElementId = PrimitiveId(0),
|
||||
Type = IsFilled ? RenderCommandType.DrawFilledCircle : RenderCommandType.DrawCircle,
|
||||
Position = Position,
|
||||
Properties = new Dictionary<string, object?>
|
||||
{
|
||||
["Color"] = Color,
|
||||
["Radius"] = Radius,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
using RemSox.UI.GUI.Rendering;
|
||||
|
||||
using System.Drawing;
|
||||
|
||||
namespace RemSox.UI.GUI.UIEelements.Shapes;
|
||||
@@ -9,4 +11,20 @@ public class Line() : Shape("Line")
|
||||
get;
|
||||
set => SetProperty(nameof(EndPosition), ref field, value);
|
||||
}
|
||||
|
||||
public override IEnumerable<RenderCommand> ToPrimitives(int windowId)
|
||||
{
|
||||
yield return new RenderCommand
|
||||
{
|
||||
WindowId = windowId,
|
||||
ElementId = PrimitiveId(0),
|
||||
Type = RenderCommandType.DrawLine,
|
||||
Position = Position,
|
||||
Properties = new Dictionary<string, object?>
|
||||
{
|
||||
["Color"] = Color,
|
||||
["EndPosition"] = EndPosition,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using RemSox.UI.GUI.Rendering;
|
||||
|
||||
using System.Drawing;
|
||||
|
||||
namespace RemSox.UI.GUI.UIEelements.Shapes;
|
||||
|
||||
public class Pixel() : Shape("Pixel")
|
||||
{
|
||||
public override IEnumerable<RenderCommand> ToPrimitives(int windowId)
|
||||
{
|
||||
yield return new RenderCommand
|
||||
{
|
||||
WindowId = windowId,
|
||||
ElementId = PrimitiveId(0),
|
||||
Type = RenderCommandType.DrawPoint,
|
||||
Position = Position,
|
||||
Properties = new Dictionary<string, object?>
|
||||
{
|
||||
["Color"] = Color,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
using RemSox.UI.GUI.Rendering;
|
||||
|
||||
using System.Drawing;
|
||||
|
||||
namespace RemSox.UI.GUI.UIEelements.Shapes;
|
||||
@@ -15,4 +17,20 @@ public class Rectangle() : Shape("Rectangle")
|
||||
get;
|
||||
set => SetProperty(nameof(IsFilled), ref field, value);
|
||||
} = true;
|
||||
|
||||
public override IEnumerable<RenderCommand> ToPrimitives(int windowId)
|
||||
{
|
||||
yield return new RenderCommand
|
||||
{
|
||||
WindowId = windowId,
|
||||
ElementId = PrimitiveId(0),
|
||||
Type = IsFilled ? RenderCommandType.DrawFilledRect : RenderCommandType.DrawRectBorder,
|
||||
Position = Position,
|
||||
Properties = new Dictionary<string, object?>
|
||||
{
|
||||
["Color"] = Color,
|
||||
["Size"] = Size,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using RemSox.UI.GUI.Rendering;
|
||||
|
||||
using System.Drawing;
|
||||
|
||||
namespace RemSox.UI.GUI.UIEelements.Shapes;
|
||||
@@ -21,4 +23,21 @@ public class Text() : UIElement("Text")
|
||||
get;
|
||||
set => SetProperty(nameof(FontSize), ref field, value);
|
||||
} = 12;
|
||||
|
||||
public override IEnumerable<RenderCommand> ToPrimitives(int windowId)
|
||||
{
|
||||
yield return new RenderCommand
|
||||
{
|
||||
WindowId = windowId,
|
||||
ElementId = PrimitiveId(0),
|
||||
Type = RenderCommandType.DrawText,
|
||||
Position = Position,
|
||||
Properties = new Dictionary<string, object?>
|
||||
{
|
||||
["Color"] = Color,
|
||||
["Content"] = Content,
|
||||
["FontSize"] = FontSize,
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using RemSox.UI.GUI.Rendering;
|
||||
using RemSox.Utils;
|
||||
|
||||
using System.Drawing;
|
||||
@@ -6,6 +7,8 @@ namespace RemSox.UI.GUI.UIEelements;
|
||||
|
||||
public abstract class UIElement(string type) : ChangedPropertiesTracker
|
||||
{
|
||||
public const int PrimitiveIdShift = 6;
|
||||
|
||||
public int Id { get; init; }
|
||||
|
||||
public string Type { get; set; } = type;
|
||||
@@ -15,4 +18,10 @@ public abstract class UIElement(string type) : ChangedPropertiesTracker
|
||||
get;
|
||||
set => SetProperty(nameof(Position), ref field, value);
|
||||
}
|
||||
|
||||
/// <summary> Expands this UI element into drawing primitives. </summary>
|
||||
public abstract IEnumerable<RenderCommand> ToPrimitives(int windowId);
|
||||
|
||||
/// <summary> Builds a stable primitive ID from element ID and sub-index. </summary>
|
||||
protected int PrimitiveId(int subIndex) => (Id << PrimitiveIdShift) | subIndex;
|
||||
}
|
||||
Reference in New Issue
Block a user