aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java21
-rw-r--r--src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java12
2 files changed, 28 insertions, 5 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java
index 214bd16..89cc6f8 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigSwitch.java
@@ -14,19 +14,28 @@ import org.lwjgl.input.Mouse;
import java.lang.reflect.Field;
+import static org.lwjgl.nanovg.NanoVG.nvgResetScissor;
+import static org.lwjgl.nanovg.NanoVG.nvgScissor;
+
public class ConfigSwitch extends BasicOption {
private int color;
private float percentOn = 0f;
private boolean clicked = false;
- private boolean toggled = false;
+ private boolean toggled ;
public ConfigSwitch(Field field, String name, int size) {
super(field, name, size);
+ try {
+ toggled = (boolean) get();
+ } catch (IllegalAccessException e) {
+ System.err.println("failed to get config value: class=" + this + " fieldWatching=" + field);
+ }
}
@Override
public void draw(long vg, int x, int y) {
- boolean hovered = InputUtils.isAreaHovered(x, y, 480, 32);
+ nvgScissor(vg, x, y, size == 0 ? 480 : 992, 32);
+ boolean hovered = InputUtils.isAreaHovered(x, y, size == 0 ? 480 : 992, 32);
int x2 = x + 19 + (int) (percentOn * 18);
color = ColorUtils.smoothColor(color, OneConfigConfig.GRAY_400, OneConfigConfig.BLUE_500, toggled, 20f);
if(color == -15123643) {
@@ -36,17 +45,19 @@ public class ConfigSwitch extends BasicOption {
RenderManager.drawRoundedRect(vg, x2, y + 7, 18, 18, OneConfigConfig.WHITE, 9f);
RenderManager.drawString(vg, name, x + 66, y + 17, OneConfigConfig.WHITE, 18f, Fonts.INTER_MEDIUM);
- if (Mouse.isButtonDown(0) && !this.clicked && hovered)
+ if (InputUtils.isClicked(x, y, size == 0 ? 480 : 992, 32) && !this.clicked && hovered)
{
toggled = !toggled;
try {
set(toggled);
} catch (IllegalAccessException e) {
- throw new RuntimeException(e);
+ System.err.println("failed to write config value: class=" + this + " fieldWatching=" + field + " valueWrite=" + toggled);
+ e.printStackTrace();
}
}
- this.clicked = Mouse.isButtonDown(0) && hovered;
+ this.clicked = InputUtils.isClicked(x, y, size == 0 ? 480 : 992, 32) && hovered;
percentOn = MathUtils.clamp(MathUtils.easeOut(percentOn, toggled ? 1f : 0f, 10));
+ nvgResetScissor(vg);
diff --git a/src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java b/src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java
index 1ce1a30..e030c29 100644
--- a/src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java
+++ b/src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java
@@ -14,4 +14,16 @@ public class InputUtils {
int mouseY = Minecraft.getMinecraft().displayHeight - Math.abs(Mouse.getY());
return mouseX > x && mouseY > y && mouseX < x + width && mouseY < y + height; // TODO add scaling info
}
+
+ public static boolean isClicked(int x, int y, int width, int height) {
+ return isAreaHovered(x, y, width, height) && Mouse.isButtonDown(0); // TODO make actually do what its meant to do (only 1 event)
+ }
+
+ public static int mouseX() {
+ return Mouse.getX();
+ }
+
+ public static int mouseY() {
+ return Minecraft.getMinecraft().displayHeight - Math.abs(Mouse.getY());
+ }
}