-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cbc1fa
commit b151080
Showing
4 changed files
with
197 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
/// <summary> | ||
/// Removes a control from the window. | ||
/// </summary> | ||
/// <param name="Control">The control to remove.</param> | ||
public void RemoveControl(Control Control) | ||
{ | ||
Control.Window = null; | ||
Controls.Remove(Control); | ||
Render(); | ||
} | ||
|
||
/// <summary> | ||
/// Adds a control to the window. | ||
/// </summary> | ||
/// <param name="Control">The control to add.</param> | ||
public void AddControl(Control Control) | ||
{ | ||
Control.Window = this; | ||
Controls.Add(Control); | ||
Render(); | ||
} | ||
|
||
/// <summary> | ||
/// Renders the window - Only use after changing something. | ||
/// </summary> | ||
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<Control> ShelfControls; | ||
private readonly List<Control> 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 | ||
} | ||
} |