diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2018-07-06 14:07:42 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2018-07-06 14:07:42 +0200 |
commit | cb3328fa808ddfb8d671a87f0747d7b1827f8074 (patch) | |
tree | fb3c932089d11ef1859da37505e0cb57f2e498d7 /core/src/ch/asynk/zproject/Hud.java | |
parent | 620077ed656885cb558e5644c75a262346d512aa (diff) | |
download | gdx-boardgame-cb3328fa808ddfb8d671a87f0747d7b1827f8074.zip gdx-boardgame-cb3328fa808ddfb8d671a87f0747d7b1827f8074.tar.gz |
Plugin a little demo with touch detiction
Diffstat (limited to 'core/src/ch/asynk/zproject/Hud.java')
-rw-r--r-- | core/src/ch/asynk/zproject/Hud.java | 121 |
1 files changed, 89 insertions, 32 deletions
diff --git a/core/src/ch/asynk/zproject/Hud.java b/core/src/ch/asynk/zproject/Hud.java index d013d7b..fd74ade 100644 --- a/core/src/ch/asynk/zproject/Hud.java +++ b/core/src/ch/asynk/zproject/Hud.java @@ -1,59 +1,116 @@ package ch.asynk.zproject; import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.graphics.g2d.BitmapFont; -import com.badlogic.gdx.graphics.g2d.GlyphLayout; import com.badlogic.gdx.graphics.g2d.Sprite; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.utils.Disposable; +import com.badlogic.gdx.math.Rectangle; + +import ch.asynk.zproject.engine.ui.Button; +import ch.asynk.zproject.engine.ui.Patch; +import ch.asynk.zproject.engine.ui.Alignment; +import ch.asynk.zproject.engine.ui.Root; +import ch.asynk.zproject.engine.Touchable; -public class Hud implements Disposable +public class Hud implements Disposable, Touchable { private final Rectangle rect; - private final Sprite hud; - private final GlyphLayout glyphLayout; - private final BitmapFont font20; - private final BitmapFont font25; + private final Sprite corner; + private final Root root; + private final Button hello; + private final Button next; public Hud(final Assets assets) { - this.rect = new Rectangle(0, 0, 0, 0); - this.hud = new Sprite(assets.getTexture(assets.CORNER)); - this.glyphLayout = new GlyphLayout(); - font20 = assets.getFont(assets.FONT_20); - font25 = assets.getFont(assets.FONT_25); + this.corner = new Sprite(assets.getTexture(assets.CORNER)); + this.rect = new Rectangle(0, 0, 0 ,0); + + this.root = new Root(2); + this.root.setPadding(30); + + this.hello = new Button(assets.getFont(assets.FONT_25), assets.getNinePatch(assets.PATCH, 23, 23, 23 ,23), 10, 15); + this.hello.write("Hello"); + this.root.add(this.hello); + + this.next = new Button(assets.getFont(assets.FONT_25), assets.getNinePatch(assets.PATCH, 23, 23, 23 ,23), 20, 0); + this.next.write("NEXT"); + this.next.setPosition(100, 100); + this.root.add(this.next); } @Override public void dispose() { - hud.getTexture().dispose(); + corner.getTexture().dispose(); + } + + @Override public boolean touch(float x, float y) + { + if (rect.contains(x, y)) { + if (root.touch(x, y)) { + ZProject.debug("Hud", String.format("touchDown : %f %f", x, y)); + return true; + } + } + return false; } public void resize(float width, float height) { rect.set(0, 0, width, height); + this.root.resize(width, height); } public void draw(Batch batch) { - float right = rect.x + rect.width - hud.getWidth(); - float top = rect.y + rect.height - hud.getHeight(); - hud.setRotation(0); - hud.setPosition(rect.x, top); - hud.draw(batch); - hud.setRotation(90); - hud.setPosition(rect.x, rect.y); - hud.draw(batch); - hud.setRotation(180); - hud.setPosition(right, rect.y); - hud.draw(batch); - hud.setPosition(right, top); - hud.setRotation(270); - hud.draw(batch); - glyphLayout.setText(font20, "Hello"); - font20.draw(batch, glyphLayout, 60, 30); - glyphLayout.setText(font25, "worlD"); - font25.draw(batch, glyphLayout, 120, 32); + drawButtons(batch); + drawCorners(batch); + } + + public void drawCorners(Batch batch) + { + float right = rect.x + rect.width - corner.getWidth(); + float top = rect.y + rect.height - corner.getHeight(); + corner.setRotation(0); + corner.setPosition(rect.x, top); + corner.draw(batch); + corner.setRotation(90); + corner.setPosition(rect.x, rect.y); + corner.draw(batch); + corner.setRotation(180); + corner.setPosition(right, rect.y); + corner.draw(batch); + corner.setPosition(right, top); + corner.setRotation(270); + corner.draw(batch); + } + + private void drawButtons(Batch batch) + { + hello.setAlignment(Alignment.TOP_LEFT); + hello.setLabelAlignment(Alignment.BOTTOM_CENTER); + hello.update(); + root.draw(batch); + drawHello(batch, Alignment.TOP_CENTER, Alignment.BOTTOM_RIGHT); + drawHello(batch, Alignment.TOP_RIGHT, Alignment.TOP_LEFT); + drawHello(batch, Alignment.MIDDLE_LEFT, Alignment.TOP_CENTER); + drawHello(batch, Alignment.MIDDLE_CENTER, Alignment.TOP_RIGHT); + drawHello(batch, Alignment.MIDDLE_RIGHT, Alignment.MIDDLE_LEFT); + drawHello(batch, Alignment.BOTTOM_LEFT, Alignment.MIDDLE_CENTER); + drawHello(batch, Alignment.BOTTOM_CENTER, Alignment.MIDDLE_RIGHT); + drawHello(batch, Alignment.BOTTOM_RIGHT, Alignment.BOTTOM_LEFT); + } + + private void drawHello(Batch batch, Alignment alignment1, Alignment alignment2) + { + hello.setAlignment(alignment1); + hello.setLabelAlignment(alignment2); + hello.update(); + hello.draw(batch); + } + + public void drawDebug(ShapeRenderer debugShapes) + { + root.drawDebug(debugShapes); } } |