diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-09 00:38:42 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-09 00:38:42 +0100 |
commit | 025855819d8052410bc8bbc2c62016211a3c99d2 (patch) | |
tree | e759937440b3665e6235b23249bd6ec11f61f834 /core/src/ch/asynk/tankontank/game/hud | |
parent | c81eabd7eb21ff656c98a814ee729c61896173d4 (diff) | |
download | RustAndDust-025855819d8052410bc8bbc2c62016211a3c99d2.zip RustAndDust-025855819d8052410bc8bbc2c62016211a3c99d2.tar.gz |
Label: extends Widget, has a padding
Diffstat (limited to 'core/src/ch/asynk/tankontank/game/hud')
-rw-r--r-- | core/src/ch/asynk/tankontank/game/hud/Label.java | 61 |
1 files changed, 19 insertions, 42 deletions
diff --git a/core/src/ch/asynk/tankontank/game/hud/Label.java b/core/src/ch/asynk/tankontank/game/hud/Label.java index e3f753f..0b6001e 100644 --- a/core/src/ch/asynk/tankontank/game/hud/Label.java +++ b/core/src/ch/asynk/tankontank/game/hud/Label.java @@ -1,63 +1,48 @@ package ch.asynk.tankontank.game.hud; -import com.badlogic.gdx.utils.Disposable; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds; -import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import ch.asynk.tankontank.engine.gfx.Drawable; -public class Label implements Drawable, Disposable +public class Label extends Widget { - public boolean visible; - public float x; - public float y; - private float ry; - private String text; private BitmapFont font; + private float padding; + private float rx; + private float ry; + protected String text; - public Label(BitmapFont font, String text) - { - this.font = font; - this.text = text; - this.visible = true; - } - - @Override - public void dispose() + public Label(BitmapFont font) { - font.dispose(); + this(font, 0f); } - public float getWidth() + public Label(BitmapFont font, float padding) { - TextBounds b = getBounds(); - return b.width; + this.font = font; + this.padding = padding; } - public float getHeight() + @Override + public void dispose() { - TextBounds b = getBounds(); - return b.height; } + @Override public void setPosition(float x, float y) { - TextBounds b = getBounds(); - this.x = x; - this.y = y; - this.ry = (y + b.height); - } - - public TextBounds getBounds() - { - return font.getMultiLineBounds(text); + TextBounds b = font.getMultiLineBounds((text == null) ? "" : text); + set(x, y, (b.width + (2 * padding)), (b.height + (2 * padding))); + this.rx = x + (padding); + this.ry = (y + padding + b.height); } public void write(String text) { this.text = text; + setPosition(rect.x, rect.y); } public void write(String text, float x, float y) @@ -70,14 +55,6 @@ public class Label implements Drawable, Disposable public void draw(Batch batch) { if (!visible) return; - font.drawMultiLine(batch, text, x, ry); - } - - @Override - public void drawDebug(ShapeRenderer shapes) - { - if (!visible) return; - TextBounds b = getBounds(); - shapes.rect(x, y, b.width, b.height); + font.drawMultiLine(batch, text, rx, ry); } } |