Reorganize project structure

This commit is contained in:
Stone_Red
2026-06-19 00:56:46 +02:00
parent 6f58eefb66
commit 95d88f1a8d
84 changed files with 267 additions and 186 deletions
@@ -0,0 +1,29 @@
using RemSox.Shared.UI;
using Cosmos.Kernel.System.Keyboard;
using System.Drawing;
namespace RemSox.Kernel.UI.GUI.UIEelements;
public abstract class Control(string type) : UIElement(type)
{
public Color BackgroundColor
{
get;
set => SetProperty(nameof(BackgroundColor), ref field, value);
} = Color.LightGray;
public Size Size
{
get;
set => SetProperty(nameof(Size), ref field, value);
}
public virtual void HandleMouseEvent(MouseEvent mouseEvent)
{
}
public virtual void HandleKeyEvent(KeyEvent keyEvent)
{
}
}
@@ -0,0 +1,95 @@
using RemSox.Shared.UI;
using RemSox.Shared.UI.GUI.Rendering;
using System.Drawing;
namespace RemSox.Kernel.UI.GUI.UIEelements.Controls;
public class Button() : Control("Button")
{
public event EventHandler? OnClick;
public string Text
{
get;
set => SetProperty(nameof(Text), ref field, value);
} = string.Empty;
public Color TextColor
{
get;
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, falls back to left-aligned if too wide)
if (!string.IsNullOrEmpty(Text))
{
int fontSize = Size.Height - 8;
int charWidth = 8 * fontSize / 14;
int maxChars = Size.Width / charWidth;
string display = Text;
if (display.Length > maxChars && maxChars > 0)
{
display = Text[..maxChars];
}
int textWidth = display.Length * charWidth;
int tx = textWidth >= Size.Width
? Position.X
: Position.X + ((Size.Width - textWidth) / 2);
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,
["MaxWidth"] = Size.Width,
}
};
}
}
public override void HandleMouseEvent(MouseEvent mouseEvent)
{
if (mouseEvent.Type == MouseEventType.ButtonDown && mouseEvent.Button == MouseButton.Left)
{
OnClick?.Invoke(this, EventArgs.Empty);
}
}
}
@@ -0,0 +1,110 @@
using RemSox.Shared.UI;
using RemSox.Shared.UI.GUI.Rendering;
using System.Drawing;
namespace RemSox.Kernel.UI.GUI.UIEelements.Controls;
public class CheckBox() : Control("CheckBox")
{
public event EventHandler? OnCheckedChanged;
public bool IsChecked
{
get;
set
{
SetProperty(nameof(IsChecked), ref field, value);
OnCheckedChanged?.Invoke(this, EventArgs.Empty);
}
} = false;
public string Text
{
get;
set => SetProperty(nameof(Text), ref field, value);
} = string.Empty;
public Color TextColor
{
get;
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,
["MaxWidth"] = Size.Width - boxSize - 5,
}
};
}
}
public override void HandleMouseEvent(MouseEvent mouseEvent)
{
if (mouseEvent.Type == MouseEventType.ButtonDown && mouseEvent.Button == MouseButton.Left)
{
IsChecked = !IsChecked;
}
}
}
@@ -0,0 +1,22 @@
using RemSox.Shared.UI.GUI.Rendering;
namespace RemSox.Kernel.UI.GUI.UIEelements.Controls;
public class Panel() : Control("Panel")
{
public override IEnumerable<RenderCommand> ToPrimitives(int windowId)
{
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(0),
Type = RenderCommandType.DrawFilledRect,
Position = Position,
Properties = new Dictionary<string, object?>
{
["Color"] = BackgroundColor,
["Size"] = Size,
}
};
}
}
@@ -0,0 +1,70 @@
using RemSox.Shared.UI.GUI.Rendering;
using System.Drawing;
namespace RemSox.Kernel.UI.GUI.UIEelements.Controls;
public class ProgressBar() : Control("ProgressBar")
{
public int Value
{
get;
set => SetProperty(nameof(Value), ref field, value);
}
public Color FillColor
{
get;
set => SetProperty(nameof(FillColor), ref field, value);
} = Color.Green;
public override IEnumerable<RenderCommand> ToPrimitives(int windowId)
{
// Background
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(0),
Type = RenderCommandType.DrawFilledRect,
Position = Position,
Properties = new Dictionary<string, object?>
{
["Color"] = BackgroundColor,
["Size"] = Size,
}
};
// Fill
int fillWidth = Size.Width * Math.Clamp(Value, 0, 100) / 100;
if (fillWidth > 0)
{
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(1),
Type = RenderCommandType.DrawFilledRect,
Position = Position,
Properties = new Dictionary<string, object?>
{
["Color"] = FillColor,
["Size"] = new Size(fillWidth, Size.Height),
}
};
}
// Border
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(2),
Type = RenderCommandType.DrawRectBorder,
Position = Position,
Properties = new Dictionary<string, object?>
{
["Color"] = Color.DarkGray,
["Size"] = Size,
}
};
}
}
@@ -0,0 +1,105 @@
using RemSox.Shared.UI;
using RemSox.Shared.UI.GUI.Rendering;
using System.Drawing;
namespace RemSox.Kernel.UI.GUI.UIEelements.Controls;
public class RadioButton() : Control("RadioButton")
{
public event EventHandler? OnCheckedChanged;
public bool IsChecked
{
get;
set
{
SetProperty(nameof(IsChecked), ref field, value);
OnCheckedChanged?.Invoke(this, EventArgs.Empty);
}
}
public string Text
{
get;
set => SetProperty(nameof(Text), ref field, value);
} = string.Empty;
public Color TextColor
{
get;
set => SetProperty(nameof(TextColor), ref field, value);
} = Color.White;
public override IEnumerable<RenderCommand> ToPrimitives(int windowId)
{
int diameter = Size.Height;
int radius = diameter / 2;
Point center = new(Position.X + radius, Position.Y + radius);
// Outer circle
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(0),
Type = RenderCommandType.DrawCircle,
Position = new Point(center.X - radius, center.Y - radius),
Properties = new Dictionary<string, object?>
{
["Color"] = Color.DarkGray,
["Radius"] = radius,
}
};
// Inner fill when checked
if (IsChecked)
{
int innerRadius = radius - 3;
if (innerRadius > 0)
{
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(1),
Type = RenderCommandType.DrawFilledCircle,
Position = new Point(center.X - innerRadius, center.Y - innerRadius),
Properties = new Dictionary<string, object?>
{
["Color"] = Color.Black,
["Radius"] = innerRadius,
}
};
}
}
// Label text
if (!string.IsNullOrEmpty(Text))
{
int textX = Position.X + diameter + 5;
int textY = Position.Y + (Size.Height / 2) - 8;
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(2),
Type = RenderCommandType.DrawText,
Position = new Point(textX, textY),
Properties = new Dictionary<string, object?>
{
["Color"] = TextColor,
["Content"] = Text,
["FontSize"] = Size.Height,
["MaxWidth"] = Size.Width - Size.Height - 5,
}
};
}
}
public override void HandleMouseEvent(MouseEvent mouseEvent)
{
if (mouseEvent.Type == MouseEventType.ButtonDown && mouseEvent.Button == MouseButton.Left)
{
IsChecked = true;
}
}
}
@@ -0,0 +1,143 @@
using RemSox.Shared.UI;
using RemSox.Shared.UI.GUI.Rendering;
using System.Drawing;
namespace RemSox.Kernel.UI.GUI.UIEelements.Controls;
public class Slider() : Control("Slider")
{
public event EventHandler? OnValueChanged;
public int MinValue
{
get;
set => SetProperty(nameof(MinValue), ref field, value);
}
public int MaxValue
{
get;
set => SetProperty(nameof(MaxValue), ref field, value);
} = 100;
public int Value
{
get;
set
{
int clamped = Math.Clamp(value, MinValue, MaxValue);
SetProperty(nameof(Value), ref field, clamped);
if (Value == clamped)
{
OnValueChanged?.Invoke(this, EventArgs.Empty);
}
}
}
public Color ThumbColor
{
get;
set => SetProperty(nameof(ThumbColor), ref field, value);
} = Color.LightGray;
public override IEnumerable<RenderCommand> ToPrimitives(int windowId)
{
int trackHeight = 4;
int trackY = Position.Y + (Size.Height / 2) - (trackHeight / 2);
// Track background
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(0),
Type = RenderCommandType.DrawFilledRect,
Position = new Point(Position.X, trackY),
Properties = new Dictionary<string, object?>
{
["Color"] = Color.DimGray,
["Size"] = new Size(Size.Width, trackHeight),
}
};
// Filled portion
int range = MaxValue - MinValue;
int fillWidth = range > 0 ? Size.Width * (Value - MinValue) / range : 0;
if (fillWidth > 0)
{
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(1),
Type = RenderCommandType.DrawFilledRect,
Position = new Point(Position.X, trackY),
Properties = new Dictionary<string, object?>
{
["Color"] = BackgroundColor,
["Size"] = new Size(fillWidth, trackHeight),
}
};
}
// Thumb (centered at the fill edge)
int thumbSize = Size.Height;
int thumbX = fillWidth - (thumbSize / 2);
int thumbY = Position.Y;
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(2),
Type = RenderCommandType.DrawFilledCircle,
Position = new Point(Position.X + thumbX, thumbY),
Properties = new Dictionary<string, object?>
{
["Color"] = ThumbColor,
["Radius"] = thumbSize / 2,
}
};
// Thumb border
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(3),
Type = RenderCommandType.DrawCircle,
Position = new Point(Position.X + thumbX, thumbY),
Properties = new Dictionary<string, object?>
{
["Color"] = Color.DarkGray,
["Radius"] = thumbSize / 2,
}
};
}
private bool isDragging;
public override void HandleMouseEvent(MouseEvent mouseEvent)
{
if (mouseEvent.Type == MouseEventType.ButtonDown && mouseEvent.Button == MouseButton.Left)
{
isDragging = true;
SetValueFromX(mouseEvent.X);
}
else if (mouseEvent.Type == MouseEventType.Move && isDragging)
{
SetValueFromX(mouseEvent.X);
}
else if (mouseEvent.Type == MouseEventType.ButtonUp && mouseEvent.Button == MouseButton.Left)
{
isDragging = false;
}
}
private void SetValueFromX(int windowX)
{
int localX = windowX - Position.X;
int range = MaxValue - MinValue;
Value = range > 0
? MinValue + (localX * range / Size.Width)
: MinValue;
}
}
+12
View File
@@ -0,0 +1,12 @@
using System.Drawing;
namespace RemSox.Kernel.UI.GUI.UIEelements;
public abstract class Shape(string type) : UIElement(type)
{
public Color Color
{
get;
set => SetProperty(nameof(Color), ref field, value);
}
}
@@ -0,0 +1,34 @@
using RemSox.Shared.UI.GUI.Rendering;
namespace RemSox.Kernel.UI.GUI.UIEelements.Shapes;
public class Circle() : Shape("Circle")
{
public int Radius
{
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,
}
};
}
}
@@ -0,0 +1,30 @@
using RemSox.Shared.UI.GUI.Rendering;
using System.Drawing;
namespace RemSox.Kernel.UI.GUI.UIEelements.Shapes;
public class Line() : Shape("Line")
{
public Point EndPosition
{
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,21 @@
using RemSox.Shared.UI.GUI.Rendering;
namespace RemSox.Kernel.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,
}
};
}
}
@@ -0,0 +1,36 @@
using RemSox.Shared.UI.GUI.Rendering;
using System.Drawing;
namespace RemSox.Kernel.UI.GUI.UIEelements.Shapes;
public class Rectangle() : Shape("Rectangle")
{
public Size Size
{
get;
set => SetProperty(nameof(Size), 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.DrawFilledRect : RenderCommandType.DrawRectBorder,
Position = Position,
Properties = new Dictionary<string, object?>
{
["Color"] = Color,
["Size"] = Size,
}
};
}
}
@@ -0,0 +1,50 @@
using RemSox.Shared.UI.GUI.Rendering;
using System.Drawing;
namespace RemSox.Kernel.UI.GUI.UIEelements.Shapes;
public class Text() : UIElement("Text")
{
public string Content
{
get;
set => SetProperty(nameof(Content), ref field, value);
} = string.Empty;
public Color Color
{
get;
set => SetProperty(nameof(Color), ref field, value);
} = Color.White;
public int FontSize
{
get;
set => SetProperty(nameof(FontSize), ref field, value);
} = 12;
public int MaxWidth
{
get;
set => SetProperty(nameof(MaxWidth), ref field, value);
} = int.MaxValue;
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,
["MaxWidth"] = MaxWidth,
}
};
}
}
@@ -0,0 +1,30 @@
using RemSox.Shared.UI.GUI.Rendering;
using RemSox.Kernel.Utils;
using System.Drawing;
namespace RemSox.Kernel.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;
public Point Position
{
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)
{
return (Id << PrimitiveIdShift) | subIndex;
}
}