package cc.polyfrost.oneconfig.utils; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.libs.universal.UResolution; import cc.polyfrost.oneconfig.platform.Platform; import cc.polyfrost.oneconfig.renderer.scissor.Scissor; import java.util.ArrayList; /** * Various utility methods for input. *
* All values returned from this class are not scaled to Minecraft's GUI scale. * For scaled values, see {@link cc.polyfrost.oneconfig.libs.universal.UMouse}. *
*/ public final class InputUtils { private static final ArrayList* All values returned from this class are not scaled to Minecraft's GUI scale. * For scaled values, see {@link cc.polyfrost.oneconfig.libs.universal.UMouse}. *
* * @return the current mouse X position */ public static int mouseX() { if (OneConfigGui.INSTANCE == null) return Platform.getMousePlatform().getMouseX(); return (int) (Platform.getMousePlatform().getMouseX() / OneConfigGui.INSTANCE.getScaleFactor()); } /** * Gets the current mouse Y position. ** All values returned from this class are not scaled to Minecraft's GUI scale. * For scaled values, see {@link cc.polyfrost.oneconfig.libs.universal.UMouse}. *
* * @return the current mouse Y position */ public static int mouseY() { if (OneConfigGui.INSTANCE == null) return UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY()); return (int) ((UResolution.getWindowHeight() - Math.abs(Platform.getMousePlatform().getMouseY())) / OneConfigGui.INSTANCE.getScaleFactor()); } /** * Block all clicks outside an area * * @param x X coordinate * @param y Y coordinate * @param width Width * @param height Height */ public static Scissor blockInputArea(int x, int y, int width, int height) { Scissor scissor = new Scissor(new Scissor(x, y, width, height)); blockScissors.add(scissor); return scissor; } /** * Should be used if there is something above other components and you don't want it clicking trough */ public static Scissor blockAllInput() { return blockInputArea(0, 0, 1920, 1080); } /** * Stop blocking an area from being interacted with * * @param scissor The scissor area */ public static void stopBlock(Scissor scissor) { blockScissors.remove(scissor); } /** * Clears all blocking areas */ public static void stopBlockingInput() { blockScissors.clear(); } /** * Whether clicks are blocked * * @return true if clicks are blocked, false if not */ public static boolean isBlockingInput() { return blockScissors.size() > 0; } private static boolean shouldBlock(int x, int y) { for (Scissor block : blockScissors) { if (block.isInScissor(x, y)) return true; } return false; } }