summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust/ui/Button.java
blob: be54d5bee7a12cc1412097e27868172d852b0573 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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);
    }
}