DEADSOFTWARE

Rewrite menu
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / menu / objects / Button.java
1 package ru.deadsoftware.cavedroid.menu.objects;
3 import com.badlogic.gdx.math.Rectangle;
5 public class Button {
7 public static final int WIDTH = 200;
8 public static final int HEIGHT = 20;
10 public static final int
11 DISABLED = 0,
12 NORMAL = 1,
13 SELECTED = 2;
15 private ButtonEventListener listener;
17 private final Rectangle rect;
18 private final String label;
19 private int type;
21 /**
22 * @param label Label to be shown on button
23 * @param type Type of button where 0 - disabled, 1 - normal, 2 - selected.
24 * You should use these constants
25 * {@link #DISABLED} {@link #NORMAL} {@link #SELECTED}
26 */
27 public Button(String label, int x, int y, int type, ButtonEventListener listener) {
28 this.label = label;
29 rect = new Rectangle(x, y, WIDTH, HEIGHT);
30 this.type = type;
31 this.listener = listener;
32 }
34 public Rectangle getRect() {
35 return rect;
36 }
38 public String getLabel() {
39 return label;
40 }
42 public float getX() {
43 return rect.x;
44 }
46 public float getY() {
47 return rect.y;
48 }
50 public float getWidth() {
51 return rect.width;
52 }
54 public float getHeight() {
55 return rect.height;
56 }
58 public int getType() {
59 return type;
60 }
62 public void setType(int type) {
63 this.type = type;
64 }
66 public void draw(ButtonDrawer drawer) {
67 drawer.draw(this);
68 }
70 public void clicked() {
71 listener.buttonClicked();
72 }
74 }