From 13e3cd5614e74a327ca99d5e369d566cef9507dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 17 Dec 2014 16:08:13 +0100 Subject: Label: clean, add translate() --- core/src/ch/asynk/tankontank/game/hud/Label.java | 28 ++++++++++++++++-------- 1 file 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); } } -- cgit v1.1-2-g2b99