diff options
Diffstat (limited to 'source/ui/elements/Label.cs')
| -rw-r--r-- | source/ui/elements/Label.cs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/source/ui/elements/Label.cs b/source/ui/elements/Label.cs new file mode 100644 index 0000000..c875791 --- /dev/null +++ b/source/ui/elements/Label.cs @@ -0,0 +1,62 @@ +using Celesteia.UI.Properties; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace Celesteia.UI.Elements { + public class Label : Element { + private Texture2D _background; + private TextProperties _text; + + public Label(Rect rect) { + SetRect(rect); + } + + public Label SetNewRect(Rect rect) { + SetRect(rect); + return this; + } + + public Label SetPivotPoint(Vector2 pivot) { + SetPivot(pivot); + return this; + } + + public Label SetBackground(Texture2D background) { + SetTexture(background); + return this; + } + + public Label SetText(string text) { + _text.SetText(text); + return this; + } + + public Label SetColor(Color color) { + _text.SetColor(color); + return this; + } + + public Label SetTextProperties(TextProperties text) { + _text = text; + return this; + } + + public override void Draw(SpriteBatch spriteBatch) + { + // Draw the label's background, if present. + if (_background != null) spriteBatch.Draw(GetTexture(), GetRectangle(), null, Color.White); + + TextUtilities.DrawAlignedText(spriteBatch, GetRectangle(), _text); + } + + public Texture2D GetTexture() => _background; + public void SetTexture(Texture2D background) => _background = background; + + public Label Clone() { + return new Label(GetRect()) + .SetPivotPoint(GetPivot()) + .SetBackground(GetTexture()) + .SetTextProperties(_text); + } + } +}
\ No newline at end of file |
