diff --git a/PrismOS/Tests/GraphicsTests.cs b/PrismOS/Tests/GraphicsTests.cs
index 9a7183b6..c7748008 100644
--- a/PrismOS/Tests/GraphicsTests.cs
+++ b/PrismOS/Tests/GraphicsTests.cs
@@ -24,7 +24,7 @@ static GraphicsTests()
Engine = new(800, 600, 75);
Button1 = new(50, 50, 64, 16, 4, "Button1", () => { });
Engine.Objects.Add(Mesh.GetCube(200, 200, 200));
- Engine.Camera.Position.Z = 200;
+ Engine.Camera.Position.Z = -200;
MouseManager.ScreenHeight = Canvas.Height;
MouseManager.ScreenWidth = Canvas.Width;
}
diff --git a/PrismUI/Controls/Button.cs b/PrismUI/Controls/Button.cs
index 6f7b0131..bb3d620a 100644
--- a/PrismUI/Controls/Button.cs
+++ b/PrismUI/Controls/Button.cs
@@ -33,8 +33,12 @@ public override Graphics MainImage
{
get
{
+ // Get the offset values.
+ int OffsetX = Window == null ? 0 : Window.X;
+ int OffsetY = Window == null ? 0 : Window.Y;
+
// Check if the mouse is within the control.
- if (MouseEx.IsMouseWithin(X, Y, Width, Height))
+ if (MouseEx.IsMouseWithin(OffsetX + X, OffsetY + Y, Width, Height))
{
if (MouseEx.IsClickPressed())
{
@@ -101,6 +105,9 @@ public override void Render()
ButtonHovering.DrawString(Width / 2, Height / 2, Text, default, Color.Black, true);
ButtonClicked.DrawString(Width / 2, Height / 2, Text, default, Color.Black, true);
ButtonIdle.DrawString(Width / 2, Height / 2, Text, default, Color.Black, true);
+
+ // Re-render the parent window.
+ Window?.Render();
}
public void Dispose()
diff --git a/PrismUI/Controls/Control.cs b/PrismUI/Controls/Control.cs
index e620e76b..68042e37 100644
--- a/PrismUI/Controls/Control.cs
+++ b/PrismUI/Controls/Control.cs
@@ -27,6 +27,54 @@ public Control(int X, int Y, ushort Width, ushort Height, ushort Radius)
///
public abstract Graphics MainImage { get; }
+ ///
+ /// The control's border radius.
+ ///
+ public ushort Radius
+ {
+ get
+ {
+ return _Radius;
+ }
+ set
+ {
+ _Radius = value;
+ Render();
+ }
+ }
+
+ ///
+ /// The control's pixel height.
+ ///
+ public ushort Height
+ {
+ get
+ {
+ return _Height;
+ }
+ set
+ {
+ _Height = value;
+ Render();
+ }
+ }
+
+ ///
+ /// The control's pixel width.
+ ///
+ public ushort Width
+ {
+ get
+ {
+ return _Width;
+ }
+ set
+ {
+ _Width = value;
+ Render();
+ }
+ }
+
#endregion
#region Methods
@@ -40,10 +88,19 @@ public Control(int X, int Y, ushort Width, ushort Height, ushort Radius)
#region Fields
- public ushort Radius;
- public ushort Height;
- public ushort Width;
+ internal Window? Window;
+ private ushort _Radius;
+ private ushort _Height;
+ private ushort _Width;
+
+ ///
+ /// The control's X position.
+ ///
public int X;
+
+ ///
+ /// The control's Y position.
+ ///
public int Y;
#endregion
diff --git a/PrismUI/Window.cs b/PrismUI/Window.cs
new file mode 100644
index 00000000..591431f1
--- /dev/null
+++ b/PrismUI/Window.cs
@@ -0,0 +1,128 @@
+using PrismUI.Controls;
+using PrismGraphics;
+
+namespace PrismUI
+{
+ public class Window
+ {
+ public Window(int X, int Y, ushort Width, ushort Height)
+ {
+ // Initialize the control list.
+ ShelfControls = new();
+ Controls = new();
+
+ // Initialize the window's buffers.
+ MainImage = new(Width, Height);
+ TitleShelf = new(Width, 32);
+ WindowBody = new(Width, Height);
+
+ // Initialize the window fields.
+ this.Height = Height;
+ this.Width = Width;
+ this.X = X;
+ this.Y = Y;
+ }
+
+ #region Properties
+
+ public ushort Height
+ {
+ get
+ {
+ return _Height;
+ }
+ set
+ {
+ _Height = value;
+ Render();
+ }
+ }
+ public ushort Width
+ {
+ get
+ {
+ return _Width;
+ }
+ set
+ {
+ _Width = value;
+ Render();
+ }
+ }
+
+ #endregion
+
+ #region Methods
+
+ ///
+ /// Removes a control from the window.
+ ///
+ /// The control to remove.
+ public void RemoveControl(Control Control)
+ {
+ Control.Window = null;
+ Controls.Remove(Control);
+ Render();
+ }
+
+ ///
+ /// Adds a control to the window.
+ ///
+ /// The control to add.
+ public void AddControl(Control Control)
+ {
+ Control.Window = this;
+ Controls.Add(Control);
+ Render();
+ }
+
+ ///
+ /// Renders the window - Only use after changing something.
+ ///
+ public void Render()
+ {
+ // Resize if needed.
+ MainImage.Height = Height;
+ MainImage.Width = Width;
+ TitleShelf.Width = Width;
+ WindowBody.Height = Height;
+ WindowBody.Width = Width;
+
+ // Draw the window back panel.
+ TitleShelf.Clear(Color.DeepGray);
+ WindowBody.Clear(Color.White);
+
+ // Draw the cache of each control for the title shelf.
+ foreach (Control C in ShelfControls)
+ {
+ TitleShelf.DrawImage(C.X, C.Y, C.MainImage);
+ }
+
+ // Draw the cache of each control.
+ foreach (Control C in Controls)
+ {
+ WindowBody.DrawImage(C.X, C.Y, C.MainImage);
+ }
+
+ // Draw the window to the buffer.
+ MainImage.DrawImage(X, Y - 32, TitleShelf);
+ MainImage.DrawImage(X, Y, WindowBody);
+ }
+
+ #endregion
+
+ #region Fields
+
+ private readonly List ShelfControls;
+ private readonly List Controls;
+ private readonly Graphics TitleShelf;
+ private readonly Graphics WindowBody;
+ public readonly Graphics MainImage;
+ private ushort _Height;
+ private ushort _Width;
+ public int X;
+ public int Y;
+
+ #endregion
+ }
+}
\ No newline at end of file