X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavedroid%2Fmenu%2Fobjects%2FButton.java;h=fa24eb7370797d757512691b5e2902fabd03d20d;hb=f894e0e20eb63a2b489ccfa2f5e64b98bf0c9a34;hp=f0da583f5c0e9c0127402e8eb067778b77211337;hpb=0a855ca3c1d0c84de41a928cc99fd8544a933015;p=cavedroid.git diff --git a/core/src/ru/deadsoftware/cavedroid/menu/objects/Button.java b/core/src/ru/deadsoftware/cavedroid/menu/objects/Button.java index f0da583..fa24eb7 100644 --- a/core/src/ru/deadsoftware/cavedroid/menu/objects/Button.java +++ b/core/src/ru/deadsoftware/cavedroid/menu/objects/Button.java @@ -4,26 +4,31 @@ import com.badlogic.gdx.math.Rectangle; public class Button { - private Rectangle rect; - private String label; - private int type; + public static final int WIDTH = 200; + public static final int HEIGHT = 20; - public Button(String label, float x, float y, float width, float heigth, int type) { - this.label = label; - rect = new Rectangle(x, y, width, heigth); - this.type = type; - } + public static final int + DISABLED = 0, + NORMAL = 1, + SELECTED = 2; - public Button(String label, float x, float y, float width, float heigth) { - this(label, x, y, width, heigth, 1); - } + private ButtonEventListener listener; - public Button(String label, float x, float y, int type) { - this(label, x, y, 200, 20, type); - } + private final Rectangle rect; + private final String label; + private int type; - public Button(String label, float x, float y) { - this(label, x, y, 200, 20, 1); + /** + * @param label Label to be shown on button + * @param type Type of button where 0 - disabled, 1 - normal, 2 - selected. + * You should use these constants + * {@link #DISABLED} {@link #NORMAL} {@link #SELECTED} + */ + public Button(String label, int x, int y, int type, ButtonEventListener listener) { + this.label = label; + rect = new Rectangle(x, y, WIDTH, HEIGHT); + this.type = type; + this.listener = listener; } public Rectangle getRect() { @@ -58,4 +63,12 @@ public class Button { this.type = type; } + public void draw(ButtonRenderer drawer) { + drawer.draw(this); + } + + public void clicked() { + listener.buttonClicked(); + } + }