diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2015-07-19 13:20:33 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2015-07-19 13:20:33 +0200 |
commit | de0463bcf0f76ef8b07f2719679c9e0d72745c5d (patch) | |
tree | 9a33df947ceeea16a3e20b400585b1d3c304e77e /core/src/ch/asynk/rustanddust/ui/Label.java | |
parent | e66f9f2a61d3dab4545e996046486de0d44e2901 (diff) | |
download | RustAndDust-de0463bcf0f76ef8b07f2719679c9e0d72745c5d.zip RustAndDust-de0463bcf0f76ef8b07f2719679c9e0d72745c5d.tar.gz |
welcome RustAndDust
Diffstat (limited to 'core/src/ch/asynk/rustanddust/ui/Label.java')
-rw-r--r-- | core/src/ch/asynk/rustanddust/ui/Label.java | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/core/src/ch/asynk/rustanddust/ui/Label.java b/core/src/ch/asynk/rustanddust/ui/Label.java new file mode 100644 index 0000000..6a6d809 --- /dev/null +++ b/core/src/ch/asynk/rustanddust/ui/Label.java @@ -0,0 +1,72 @@ +package ch.asynk.rustanddust.ui; + +import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.GlyphLayout; + +public class Label extends Widget +{ + private BitmapFont font; + private GlyphLayout layout; + private float dx; + private float dy; + protected String text; + + public Label(BitmapFont font) + { + this(font, 0f); + } + + 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; + this.layout = new GlyphLayout(); + } + + @Override + public void dispose() + { + } + + @Override + public void translate(float dx, float dy) + { + setPosition((rect.x + dx), (rect.y + dy)); + } + + @Override + public void setPosition(float x, float y) + { + this.layout.setText(font, (text == null) ? "" : text); + setPosition(x, y, (layout.width + (2 * padding)), (layout.height + (2 * padding))); + this.dx = (x + padding); + this.dy = (y + padding + layout.height); + } + + public void write(String text) + { + this.text = text; + setPosition(position); + } + + public void write(String text, float x, float y) + { + this.text = text; + setPosition(x, y); + } + + @Override + public void draw(Batch batch) + { + if (!visible) return; + font.draw(batch, layout, dx, dy); + } +} |