diff options
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/utils')
-rw-r--r-- | src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java index ee0bafd..6053a99 100644 --- a/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/utils/InputUtils.java @@ -5,6 +5,8 @@ import gg.essential.universal.UResolution; import org.lwjgl.input.Mouse; public class InputUtils { + private static boolean blockClicks = false; + /** * function to determine weather the mouse is currently over a specific region. Uses the current nvgScale to fix to any scale. * @@ -13,15 +15,23 @@ public class InputUtils { public static boolean isAreaHovered(int x, int y, int width, int height) { int mouseX = mouseX(); int mouseY = mouseY(); - return mouseX > x && mouseY > y && mouseX < x + width && mouseY < y + height; // TODO add scaling info + return mouseX > x && mouseY > y && mouseX < x + width && mouseY < y + height; + } + + public static boolean isAreaClicked(int x, int y, int width, int height, boolean ignoreBlock) { + return isAreaHovered(x, y, width, height) && isClicked(ignoreBlock); } public static boolean isAreaClicked(int x, int y, int width, int height) { - return isAreaHovered(x, y, width, height) && isClicked(); + return isAreaClicked(x, y, width, height, false); + } + + public static boolean isClicked(boolean ignoreBlock) { + return OneConfigGui.INSTANCE != null && OneConfigGui.INSTANCE.mouseDown && !Mouse.isButtonDown(0) && (!blockClicks || ignoreBlock); } public static boolean isClicked() { - return OneConfigGui.INSTANCE != null && OneConfigGui.INSTANCE.mouseDown && !Mouse.isButtonDown(0); + return isClicked(false); } public static int mouseX() { @@ -33,4 +43,15 @@ public class InputUtils { if (OneConfigGui.INSTANCE == null) return UResolution.getWindowHeight() - Math.abs(Mouse.getY()); return (int) ((UResolution.getWindowHeight() - Math.abs(Mouse.getY())) / OneConfigGui.INSTANCE.getScaleFactor()); } + + /** + * Should be used if there is something above other components and you don't want it clicking trough + */ + public static void blockClicks(boolean value) { + blockClicks = value; + } + + public static boolean isBlockingClicks() { + return blockClicks; + } } |