diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-12-17 16:08:13 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-12-17 16:08:13 +0100 |
commit | 13e3cd5614e74a327ca99d5e369d566cef9507dc (patch) | |
tree | d1bbc8fead0f2b440b69b71fcb13a4da70c58477 /core/src | |
parent | b0fa4f8f26545d959762a6b41f35ed10c17cf5dc (diff) | |
download | RustAndDust-13e3cd5614e74a327ca99d5e369d566cef9507dc.zip RustAndDust-13e3cd5614e74a327ca99d5e369d566cef9507dc.tar.gz |
Label: clean, add translate()
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/ch/asynk/tankontank/game/hud/Label.java | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/core/src/ch/asynk/tankontank/game/hud/Label.java b/core/src/ch/asynk/tankontank/game/hud/Label.java index 2c603c6..a2cbbf4 100644 --- a/core/src/ch/asynk/tankontank/game/hud/Label.java +++ b/core/src/ch/asynk/tankontank/game/hud/Label.java @@ -4,14 +4,11 @@ import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds; -import ch.asynk.tankontank.engine.gfx.Drawable; - public class Label extends Widget { private BitmapFont font; - private float padding; - private float rx; - private float ry; + private float dx; + private float dy; protected String text; public Label(BitmapFont font) @@ -21,8 +18,15 @@ public class Label extends Widget public Label(BitmapFont font, float padding) { + this(font, padding, Position.MIDDLE_CENTER); + } + + public Label(BitmapFont font, float padding, Position position) + { + super(); this.font = font; this.padding = padding; + this.position = position; } @Override @@ -31,18 +35,24 @@ public class Label extends Widget } @Override + public void translate(float dx, float dy) + { + setPosition((rect.x + dx), (rect.y + dy)); + } + + @Override public void setPosition(float x, float y) { TextBounds b = font.getMultiLineBounds((text == null) ? "" : text); setPosition(x, y, (b.width + (2 * padding)), (b.height + (2 * padding))); - this.rx = x + (padding); - this.ry = (y + padding + b.height); + this.dx = (x + padding); + this.dy = (y + padding + b.height); } public void write(String text) { this.text = text; - setPosition(rect.x, rect.y); + setPosition(position); } public void write(String text, float x, float y) @@ -55,6 +65,6 @@ public class Label extends Widget public void draw(Batch batch) { if (!visible) return; - font.drawMultiLine(batch, text, rx, ry); + font.drawMultiLine(batch, text, dx, dy); } } |