X-Git-Url: https://deadsoftware.ru/gitweb?p=cavedroid.git;a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavedroid%2Fmenu%2Fobjects%2FButton.java;h=88dc5b3030747caf2c399514b27a4132921e39e9;hp=123b9b55f8ac646f41a15ea31dca430e8b2021fb;hb=0ed259db50b9cab761cd5dca5cb229e69886854b;hpb=107d9b29535be2cad37c8c5a48769c68689e6b33 diff --git a/core/src/ru/deadsoftware/cavedroid/menu/objects/Button.java b/core/src/ru/deadsoftware/cavedroid/menu/objects/Button.java index 123b9b5..88dc5b3 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 { + public static final int WIDTH = 200; + public static final int HEIGHT = 20; + + public static final int + DISABLED = 0, + NORMAL = 1, + SELECTED = 2; + + private ButtonEventListener listener; + private final Rectangle rect; private final String label; private int type; - public Button(String label, float x, float y, float width, float height, int type) { + /** + * @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); + rect = new Rectangle(x, y, WIDTH, HEIGHT); this.type = type; - } - - public Button(String label, float x, float y, float width, float height) { - this(label, x, y, width, height, 1); - } - - public Button(String label, float x, float y, int type) { - this(label, x, y, 200, 20, type); - } - - public Button(String label, float x, float y) { - this(label, x, y, 200, 20, 1); + this.listener = listener; } public Rectangle getRect() { @@ -58,4 +63,12 @@ public class Button { this.type = type; } + public void draw(ButtonDrawer drawer) { + drawer.draw(this); + } + + public void clicked() { + listener.buttonClicked(); + } + }