-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement GUI capabilities for controls
- Loading branch information
1 parent
d4989be
commit 07a629d
Showing
17 changed files
with
451 additions
and
126 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
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,54 @@ | ||
using System; | ||
using System.Text; | ||
|
||
namespace IngameScript | ||
{ | ||
/// <summary> | ||
/// Represents a simple control that defines a rectangle with optional text content. | ||
/// </summary> | ||
abstract class Control : IControl | ||
{ | ||
public event Action<IControl> RedrawRequired; | ||
|
||
public bool Visible { get; set; } = true; | ||
|
||
/// <summary> | ||
/// Specifies how to apply the offset of the control. | ||
/// </summary> | ||
public Positioning Positioning { get; set; } | ||
|
||
/// <summary> | ||
/// Offsets the control from its position, depending on the positioning specified. | ||
/// </summary> | ||
public Vector2 Offset { get; set; } | ||
|
||
public float Width { get; set; } | ||
public SizeUnit WidthUnit { get; set; } | ||
public float Height { get; set; } | ||
public SizeUnit HeightUnit { get; set; } | ||
|
||
public Thickness Margin { get; set; } | ||
public SizeUnit MarginUnit { get; set; } | ||
public Thickness Padding { get; set; } | ||
public SizeUnit PaddingUnit { get; set; } | ||
|
||
public SizeUnit BorderUnit { get; set; } | ||
public Thickness Border { get; set; } | ||
public Color BorderColor { get; set; } = Color.Transparent; | ||
|
||
public string FontName { get; set; } = null; | ||
public float FontSize { get; set; } = 1f; | ||
|
||
public Color? TextColor { get; set; } | ||
public Color? BackgroundColor { get; set; } | ||
|
||
public TextAlignment TextAlignment { get; set; } = TextAlignment.LEFT; | ||
|
||
public abstract StringBuilder GetContent(bool FlushCache = false); | ||
|
||
protected virtual void OnRedrawRequired() | ||
{ | ||
RedrawRequired?.Invoke(this); | ||
} | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
src/GridOS/Core/DisplaySystem/DisplayControls/Helpers/Positioning.cs
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,15 @@ | ||
namespace IngameScript | ||
{ | ||
enum Positioning | ||
{ | ||
/// <summary> | ||
/// Positions an element relative to the preceding elements. | ||
/// </summary> | ||
Relative, | ||
|
||
/// <summary> | ||
/// Positions an element independently of other elements, from 0,0. | ||
/// </summary> | ||
Absolute | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/GridOS/Core/DisplaySystem/DisplayControls/Helpers/SizeUnit.cs
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,25 @@ | ||
namespace IngameScript | ||
{ | ||
public enum SizeUnit | ||
{ | ||
/// <summary> | ||
/// Relative to the font size of the control, where 1 is 100% of the font size. | ||
/// </summary> | ||
Em, | ||
|
||
/// <summary> | ||
/// Literal pixels, where 1 is 1 pixel on the screen. | ||
/// </summary> | ||
Px, | ||
|
||
/// <summary> | ||
/// Virtual, density-independent pixels, where values are scaled to the density of the display. | ||
/// </summary> | ||
Dip, | ||
|
||
/// <summary> | ||
/// Relative to the window size, where e.g. 50 is half of the size. | ||
/// </summary> | ||
Percent | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/GridOS/Core/DisplaySystem/DisplayControls/Helpers/Thickness.cs
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,79 @@ | ||
namespace IngameScript | ||
{ | ||
public struct Thickness | ||
{ | ||
public float Left { get; set; } | ||
public float Top { get; set; } | ||
public float Right { get; set; } | ||
public float Bottom { get; set; } | ||
|
||
public Thickness(float uniformThickness) | ||
{ | ||
Left = uniformThickness; | ||
Top = uniformThickness; | ||
Right = uniformThickness; | ||
Bottom = uniformThickness; | ||
} | ||
|
||
public Thickness(float left, float top, float right, float bottom) | ||
{ | ||
Left = left; | ||
Top = top; | ||
Right = right; | ||
Bottom = bottom; | ||
} | ||
|
||
public static Thickness operator *(Thickness a, float b) | ||
{ | ||
return new Thickness() | ||
{ | ||
Left = a.Left * b, | ||
Top = a.Top * b, | ||
Right = a.Right * b, | ||
Bottom = a.Bottom * b | ||
}; | ||
} | ||
|
||
public static Thickness operator /(Thickness a, float b) | ||
{ | ||
return new Thickness() | ||
{ | ||
Left = a.Left / b, | ||
Top = a.Top / b, | ||
Right = a.Right / b, | ||
Bottom = a.Bottom / b | ||
}; | ||
} | ||
|
||
public static Thickness operator +(Thickness a, float b) | ||
{ | ||
return new Thickness() | ||
{ | ||
Left = a.Left + b, | ||
Top = a.Top + b, | ||
Right = a.Right + b, | ||
Bottom = a.Bottom + b | ||
}; | ||
} | ||
|
||
public static Thickness operator -(Thickness a, float b) | ||
{ | ||
return new Thickness() | ||
{ | ||
Left = a.Left - b, | ||
Top = a.Top - b, | ||
Right = a.Right - b, | ||
Bottom = a.Bottom - b | ||
}; | ||
} | ||
|
||
public static Vector2 operator +(Thickness a, Vector2 b) | ||
{ | ||
return new Vector2() | ||
{ | ||
X = b.X + a.Left + a.Right, | ||
Y = b.Y + a.Top + a.Bottom | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.