aboutsummaryrefslogtreecommitdiff
path: root/src/Java/binnie/craftgui/controls/button
diff options
context:
space:
mode:
authorDraknyte1 <Draknyte1@hotmail.com>2016-01-20 14:24:34 +1000
committerDraknyte1 <Draknyte1@hotmail.com>2016-01-20 14:24:34 +1000
commit869c206c4fcc8001bd2e1d66f704290331813835 (patch)
tree96735ce8fe4665e2759c3374221d6f06f4527df2 /src/Java/binnie/craftgui/controls/button
parentec2c72827f01dd4bb2174137f1ab162f9ddaab62 (diff)
downloadGT5-Unofficial-869c206c4fcc8001bd2e1d66f704290331813835.tar.gz
GT5-Unofficial-869c206c4fcc8001bd2e1d66f704290331813835.tar.bz2
GT5-Unofficial-869c206c4fcc8001bd2e1d66f704290331813835.zip
Initial Commit
Diffstat (limited to 'src/Java/binnie/craftgui/controls/button')
-rw-r--r--src/Java/binnie/craftgui/controls/button/ControlButton.java70
-rw-r--r--src/Java/binnie/craftgui/controls/button/ControlEnumButton.java61
-rw-r--r--src/Java/binnie/craftgui/controls/button/ControlToggleButton.java21
3 files changed, 152 insertions, 0 deletions
diff --git a/src/Java/binnie/craftgui/controls/button/ControlButton.java b/src/Java/binnie/craftgui/controls/button/ControlButton.java
new file mode 100644
index 0000000000..b41cb65116
--- /dev/null
+++ b/src/Java/binnie/craftgui/controls/button/ControlButton.java
@@ -0,0 +1,70 @@
+package binnie.craftgui.controls.button;
+
+import binnie.craftgui.controls.ControlText;
+import binnie.craftgui.controls.core.Control;
+import binnie.craftgui.core.Attribute;
+import binnie.craftgui.core.CraftGUI;
+import binnie.craftgui.core.IWidget;
+import binnie.craftgui.core.geometry.TextJustification;
+import binnie.craftgui.core.renderer.Renderer;
+import binnie.craftgui.events.EventButtonClicked;
+import binnie.craftgui.events.EventHandler.Origin;
+import binnie.craftgui.events.EventMouse.Down;
+import binnie.craftgui.events.EventMouse.Down.Handler;
+import binnie.craftgui.resource.minecraft.CraftGUITexture;
+
+public class ControlButton
+ extends Control
+{
+ private ControlText textWidget;
+ private String text;
+
+ public ControlButton(IWidget parent, float x, float y, float width, float height)
+ {
+ super(parent, x, y, width, height);
+
+ addAttribute(Attribute.MouseOver);
+
+ addEventHandler(new EventMouse.Down.Handler()
+ {
+ public void onEvent(EventMouse.Down event)
+ {
+ ControlButton.this.callEvent(new EventButtonClicked(ControlButton.this.getWidget()));
+ ControlButton.this.onMouseClick(event);
+ }
+ }.setOrigin(EventHandler.Origin.Self, this));
+ }
+
+ protected void onMouseClick(EventMouse.Down event) {}
+
+ public ControlButton(IWidget parent, float x, float y, float width, float height, String text)
+ {
+ this(parent, x, y, width, height);
+
+ this.text = text;
+ this.textWidget = new ControlText(this, getArea(), text, TextJustification.MiddleCenter);
+ }
+
+ public void onUpdateClient()
+ {
+ if (this.textWidget != null) {
+ this.textWidget.setValue(getText());
+ }
+ }
+
+ public String getText()
+ {
+ return this.text;
+ }
+
+ public void onRenderBackground()
+ {
+ Object texture = CraftGUITexture.ButtonDisabled;
+ if (isMouseOver()) {
+ texture = CraftGUITexture.ButtonHighlighted;
+ } else if (isEnabled()) {
+ texture = CraftGUITexture.Button;
+ }
+ CraftGUI.Render.texture(texture, getArea());
+ }
+}
diff --git a/src/Java/binnie/craftgui/controls/button/ControlEnumButton.java b/src/Java/binnie/craftgui/controls/button/ControlEnumButton.java
new file mode 100644
index 0000000000..924bd8c110
--- /dev/null
+++ b/src/Java/binnie/craftgui/controls/button/ControlEnumButton.java
@@ -0,0 +1,61 @@
+package binnie.craftgui.controls.button;
+
+import binnie.craftgui.controls.core.IControlValue;
+import binnie.craftgui.core.IWidget;
+import binnie.craftgui.events.EventMouse.Down;
+import binnie.craftgui.events.EventValueChanged;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ControlEnumButton<T>
+ extends ControlButton
+ implements IControlValue<T>
+{
+ public static final String eventEnumChanged = "eventEnumButtonChanged";
+ private T currentSelection;
+
+ public String getText()
+ {
+ return this.currentSelection.toString();
+ }
+
+ public void onMouseClick(EventMouse.Down event)
+ {
+ int index = this.enumConstants.indexOf(this.currentSelection);
+ if (index < this.enumConstants.size() - 1) {
+ index++;
+ } else {
+ index = 0;
+ }
+ T newEnum = this.enumConstants.get(index);
+
+ setValue(newEnum);
+ }
+
+ public void setValue(T selection)
+ {
+ if (this.currentSelection != selection)
+ {
+ this.currentSelection = selection;
+ callEvent(new EventValueChanged(this, getValue()));
+ }
+ }
+
+ private List<T> enumConstants = new ArrayList();
+
+ public ControlEnumButton(IWidget parent, float x, float y, float width, float height, T[] values)
+ {
+ super(parent, x, y, width, height, "");
+ for (T value : values) {
+ this.enumConstants.add(value);
+ }
+ if (values.length > 0) {
+ this.currentSelection = values[0];
+ }
+ }
+
+ public T getValue()
+ {
+ return this.currentSelection;
+ }
+}
diff --git a/src/Java/binnie/craftgui/controls/button/ControlToggleButton.java b/src/Java/binnie/craftgui/controls/button/ControlToggleButton.java
new file mode 100644
index 0000000000..1a06801fbd
--- /dev/null
+++ b/src/Java/binnie/craftgui/controls/button/ControlToggleButton.java
@@ -0,0 +1,21 @@
+package binnie.craftgui.controls.button;
+
+import binnie.craftgui.core.IWidget;
+import binnie.craftgui.events.EventMouse.Down;
+import binnie.craftgui.events.EventToggleButtonClicked;
+
+public class ControlToggleButton
+ extends ControlButton
+{
+ boolean toggled;
+
+ public void onMouseClick(EventMouse.Down event)
+ {
+ callEvent(new EventToggleButtonClicked(this, this.toggled));
+ }
+
+ public ControlToggleButton(IWidget parent, int x, int y, int width, int height)
+ {
+ super(parent, x, y, width, height);
+ }
+}