blob: c875791046ecb5f982537ff164a794be975f254f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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);
}
}
}
|