From 4adf13571e9ddc119adea434cfdc514d0d80a9c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sat, 20 Feb 2016 21:36:47 +0100 Subject: add ui/Button --- core/src/ch/asynk/rustanddust/ui/Button.java | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 core/src/ch/asynk/rustanddust/ui/Button.java diff --git a/core/src/ch/asynk/rustanddust/ui/Button.java b/core/src/ch/asynk/rustanddust/ui/Button.java new file mode 100644 index 0000000..be54d5b --- /dev/null +++ b/core/src/ch/asynk/rustanddust/ui/Button.java @@ -0,0 +1,49 @@ +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.NinePatch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; + +public class Button extends Patch +{ + private Label label; + + public Button(String text, BitmapFont font, NinePatch patch, float padding) + { + super(patch); + label = new Label(font, padding); + label.write(text); + setPosition(label.getX(), label.getY(), label.getWidth(), label.getHeight()); + } + + @Override + public void setPosition(float x, float y, float w, float h) + { + rect.set(x, y, w, h); + if (label != null) label.setPosition(x, y); + } + + @Override + public void dispose() + { + super.dispose(); + label.dispose(); + } + + @Override + public void draw(Batch batch) + { + if (!visible) return; + super.draw(batch); + label.draw(batch); + } + + @Override + public void drawDebug(ShapeRenderer shapes) + { + if (!visible) return; + super.drawDebug(shapes); + label.drawDebug(shapes); + } +} -- cgit v1.1-2-g2b99