diff options
Diffstat (limited to 'src')
5 files changed, 74 insertions, 8 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java index 1b6123e..3377f19 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/OneConfigGui.java @@ -7,6 +7,8 @@ import io.polyfrost.oneconfig.gui.elements.TextInputField; import io.polyfrost.oneconfig.gui.pages.HomePage; import io.polyfrost.oneconfig.gui.pages.Page; import io.polyfrost.oneconfig.lwjgl.RenderManager; +import io.polyfrost.oneconfig.lwjgl.Scissor; +import io.polyfrost.oneconfig.lwjgl.ScissorManager; import io.polyfrost.oneconfig.lwjgl.font.Fonts; import io.polyfrost.oneconfig.lwjgl.image.Images; import io.polyfrost.oneconfig.utils.InputUtils; @@ -115,7 +117,7 @@ public class OneConfigGui extends GuiScreen { } } - nvgScissor(vg, x + 224, y + 72, 1056, 728); + Scissor scissor = ScissorManager.scissor(vg, x + 224, y + 72, 1056, 728); if (prevPage != null) { pageProgress = MathUtils.easeInOutCirc(50, pageProgress, 832 - pageProgress, 220); prevPage.draw(vg, (int) (x - pageProgress), y + 72); @@ -128,7 +130,7 @@ public class OneConfigGui extends GuiScreen { } else { currentPage.draw(vg, (int) (x - pageProgress), y + 72); } - nvgResetScissor(vg); + ScissorManager.resetScissor(vg, scissor); if (currentColorSelector != null) { currentColorSelector.draw(vg); } diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/TextInputField.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/TextInputField.java index 04e5676..1e33008 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/TextInputField.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/TextInputField.java @@ -2,6 +2,8 @@ package io.polyfrost.oneconfig.gui.elements; import io.polyfrost.oneconfig.config.OneConfigConfig; import io.polyfrost.oneconfig.lwjgl.RenderManager; +import io.polyfrost.oneconfig.lwjgl.Scissor; +import io.polyfrost.oneconfig.lwjgl.ScissorManager; import io.polyfrost.oneconfig.lwjgl.font.Fonts; import io.polyfrost.oneconfig.utils.InputUtils; import net.minecraft.client.gui.GuiScreen; @@ -84,6 +86,7 @@ public class TextInputField extends BasicElement { this.y = y; this.vg = vg; try { + Scissor scissor = ScissorManager.scissor(vg, x, y, width, height); int colorOutline = errored ? OneConfigConfig.ERROR_700 : OneConfigConfig.GRAY_700; RenderManager.drawHollowRoundRect(vg, x, y, width, height, colorOutline, 12f, 2f); super.update(x, y); @@ -179,6 +182,7 @@ public class TextInputField extends BasicElement { } else { RenderManager.drawString(vg, s.toString(), x + 12, y + height / 2f + 1, color, 14f, Fonts.INTER_REGULAR); } + ScissorManager.resetScissor(vg, scissor); } catch (Exception e) { e.printStackTrace(); } @@ -334,9 +338,6 @@ public class TextInputField extends BasicElement { if (!Character.isDefined(c)) return; if (GuiScreen.isCtrlKeyDown()) return; if (ChatAllowedCharacters.isAllowedCharacter(c)) { - if (getTextWidth(vg, input) + 22 > width) { // over typing is banned - return; - } if (selectedText != null) { if (caretPos > prevCaret) { input = input.substring(0, prevCaret) + input.substring(prevCaret, caretPos); diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java index 9e3a4a4..ff7616e 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/config/ConfigUniSelector.java @@ -3,6 +3,8 @@ package io.polyfrost.oneconfig.gui.elements.config; import io.polyfrost.oneconfig.config.OneConfigConfig; import io.polyfrost.oneconfig.config.interfaces.BasicOption; import io.polyfrost.oneconfig.lwjgl.RenderManager; +import io.polyfrost.oneconfig.lwjgl.Scissor; +import io.polyfrost.oneconfig.lwjgl.ScissorManager; import io.polyfrost.oneconfig.lwjgl.font.Fonts; import io.polyfrost.oneconfig.lwjgl.image.Images; import io.polyfrost.oneconfig.utils.InputUtils; @@ -36,16 +38,15 @@ public class ConfigUniSelector extends BasicOption { String option = options[selected] + " " + (selected + 1) + "/" + options.length; RenderManager.drawString(vg, name, x, y + 16, OneConfigConfig.WHITE_90, 14f, Fonts.INTER_MEDIUM); + Scissor scissor = ScissorManager.scissor(vg, x + 256, y, 192, 32); if (previous == -1) { RenderManager.drawString(vg, option, x + 352 - RenderManager.getTextWidth(vg, option, 12f, Fonts.INTER_MEDIUM) / 2f, y + 15, OneConfigConfig.WHITE_90, 12f, Fonts.INTER_MEDIUM); } else { String prevOption = options[previous] + " " + (previous + 1) + "/" + options.length; - NanoVG.nvgScissor(vg, x + 256, y, 192, 32); RenderManager.drawString(vg, selected < previous ? prevOption : option, x + 352 - RenderManager.getTextWidth(vg, selected < previous ? prevOption : option, 12f, Fonts.INTER_MEDIUM) / 2f + 192 * percentMove, y + 15, OneConfigConfig.WHITE_90, 12f, Fonts.INTER_MEDIUM); RenderManager.drawString(vg, selected < previous ? option : prevOption, x + 352 - RenderManager.getTextWidth(vg, selected < previous ? option : prevOption, 12f, Fonts.INTER_MEDIUM) / 2f - 192 * (1 - percentMove), y + 15, OneConfigConfig.WHITE_90, 12f, Fonts.INTER_MEDIUM); - - NanoVG.nvgResetScissor(vg); } + ScissorManager.resetScissor(vg, scissor); // actual coordinates: 240, 7 NanoVG.nvgTranslate(vg, x + 248, y + 21); diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/Scissor.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/Scissor.java new file mode 100644 index 0000000..dcd570a --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/Scissor.java @@ -0,0 +1,22 @@ +package io.polyfrost.oneconfig.lwjgl; + +public class Scissor { + public int x; + public int y; + public int width; + public int height; + + public Scissor(int x, int y, int width, int height) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + + public Scissor(Scissor scissor) { + this.x = scissor.x; + this.y = scissor.y; + this.width = scissor.width; + this.height = scissor.height; + } +} diff --git a/src/main/java/io/polyfrost/oneconfig/lwjgl/ScissorManager.java b/src/main/java/io/polyfrost/oneconfig/lwjgl/ScissorManager.java new file mode 100644 index 0000000..46d84b6 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/lwjgl/ScissorManager.java @@ -0,0 +1,40 @@ +package io.polyfrost.oneconfig.lwjgl; + +import org.lwjgl.nanovg.NanoVG; + +import java.util.ArrayList; + +public class ScissorManager { + private static final ArrayList<Scissor> scissors = new ArrayList<>(); + + public static Scissor scissor(long vg, int x, int y, int width, int height) { + Scissor scissor = new Scissor(x, y, width, height); + if (scissors.contains(scissor)) return scissor; + scissors.add(scissor); + applyScissors(vg); + return scissor; + } + + public static void resetScissor(long vg, Scissor scissor) { + if (scissors.contains(scissor)) { + scissors.remove(scissor); + applyScissors(vg); + } + } + + private static void applyScissors(long vg) { + NanoVG.nvgResetScissor(vg); + if (scissors.size() <= 0) return; + Scissor finalScissor = new Scissor(scissors.get(0)); + for (int i = 1; i < scissors.size(); i++) { + Scissor scissor = scissors.get(i); + int rightX = Math.min(scissor.x + scissor.width, finalScissor.x + finalScissor.width); + int rightY = Math.min(scissor.y + scissor.height, finalScissor.y + finalScissor.height); + finalScissor.x = Math.max(finalScissor.x, scissor.x); + finalScissor.y = Math.max(finalScissor.y, scissor.y); + finalScissor.width = rightX - finalScissor.x; + finalScissor.height = rightY - finalScissor.y; + } + NanoVG.nvgScissor(vg, finalScissor.x, finalScissor.y, finalScissor.width, finalScissor.height); + } +} |