blob: 6129547d2d18a0be36cfe46cd178ab2d453619ef (
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
63
64
65
66
|
package ch.asynk.gdx.boardgame.ui;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.math.Rectangle;
public class Label extends Element
{
private BitmapFont font;
private GlyphLayout layout;
private String text;
public Label(BitmapFont font)
{
this(font, 0);
}
public Label(BitmapFont font, float padding)
{
this(font, padding, Alignment.RELATIVE);
}
public Label(BitmapFont font, float padding, Alignment alignment)
{
super();
this.font = font;
this.padding = padding;
this.alignment = alignment;
this.layout = new GlyphLayout();
}
public String getText()
{
return text;
}
public void setFont(BitmapFont font)
{
this.font = font;
write();
}
public void write(String text)
{
this.text = text;
write();
}
public void write()
{
this.layout.setText(font, (text == null) ? "" : text);
taint();
}
@Override public void computeDimensions()
{
this.rect.width = (layout.width + (2 * padding));
this.rect.height = (layout.height + (2 * padding));
}
@Override public void drawReal(Batch batch)
{
font.draw(batch, layout, getInnerX(), getInnerY() + layout.height);
}
}
|