aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/gui/elements/text
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-08-17 17:43:23 +0200
committerGitHub <noreply@github.com>2022-08-17 17:43:23 +0200
commit97f788ecd4be15b1556ee1f3d8bd057bdf06bf5f (patch)
tree2bccc96007025fbccf1758ac66d4665a97d6c315 /src/main/java/cc/polyfrost/oneconfig/gui/elements/text
parente18629af6aee276b0be6cec473e4099cca9100f1 (diff)
downloadOneConfig-97f788ecd4be15b1556ee1f3d8bd057bdf06bf5f.tar.gz
OneConfig-97f788ecd4be15b1556ee1f3d8bd057bdf06bf5f.tar.bz2
OneConfig-97f788ecd4be15b1556ee1f3d8bd057bdf06bf5f.zip
Input revamp (#93)
* hud fix * api * things * stuff
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui/elements/text')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java15
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java26
2 files changed, 21 insertions, 20 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java
index 50a792f..930a81f 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/NumberInputField.java
@@ -31,6 +31,7 @@ import cc.polyfrost.oneconfig.gui.animations.ColorAnimation;
import cc.polyfrost.oneconfig.gui.elements.BasicElement;
import cc.polyfrost.oneconfig.renderer.RenderManager;
import cc.polyfrost.oneconfig.internal.assets.SVGs;
+import cc.polyfrost.oneconfig.utils.InputHandler;
import cc.polyfrost.oneconfig.utils.color.ColorPalette;
public class NumberInputField extends TextInputField {
@@ -53,14 +54,14 @@ public class NumberInputField extends TextInputField {
}
@Override
- public void draw(long vg, float x, float y) {
+ public void draw(long vg, float x, float y, InputHandler inputHandler) {
super.errored = false;
- if(disabled) RenderManager.setAlpha(vg, 0.5f);
+ if (disabled) RenderManager.setAlpha(vg, 0.5f);
RenderManager.drawRoundedRect(vg, x + width + 4, y, 12, 28, Colors.GRAY_500, 6f);
upArrow.disable(disabled);
downArrow.disable(disabled);
- upArrow.update(x + width + 4, y);
- downArrow.update(x + width + 4, y + 14);
+ upArrow.update(x + width + 4, y, inputHandler);
+ downArrow.update(x + width + 4, y + 14, inputHandler);
try {
current = Float.parseFloat(input);
} catch (NumberFormatException e) {
@@ -98,16 +99,16 @@ public class NumberInputField extends TextInputField {
}
RenderManager.drawRoundedRectVaried(vg, x + width + 4, y + 14, 12, 14, colorBottom.getColor(downArrow.isHovered(), downArrow.isPressed()), 0f, 0f, 6f, 6f);
RenderManager.drawSvg(vg, SVGs.CHEVRON_DOWN, x + width + 5, y + 15, 10, 10);
- if(!disabled) RenderManager.setAlpha(vg, 1f);
+ if (!disabled) RenderManager.setAlpha(vg, 1f);
try {
- super.draw(vg, x, y - 2);
+ super.draw(vg, x, y - 2, inputHandler);
} catch (Exception e) {
setCurrentValue(current);
super.caretPos = 0;
super.prevCaret = 0;
}
- if(disabled) RenderManager.setAlpha(vg, 1f);
+ if (disabled) RenderManager.setAlpha(vg, 1f);
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java
index 90a101c..9d470e4 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/text/TextInputField.java
@@ -36,7 +36,7 @@ import cc.polyfrost.oneconfig.renderer.font.Fonts;
import cc.polyfrost.oneconfig.renderer.scissor.Scissor;
import cc.polyfrost.oneconfig.renderer.scissor.ScissorManager;
import cc.polyfrost.oneconfig.utils.IOUtils;
-import cc.polyfrost.oneconfig.utils.InputUtils;
+import cc.polyfrost.oneconfig.utils.InputHandler;
import cc.polyfrost.oneconfig.utils.MathUtils;
import cc.polyfrost.oneconfig.utils.TextUtils;
import org.jetbrains.annotations.NotNull;
@@ -121,7 +121,7 @@ public class TextInputField extends BasicElement {
}
@Override
- public void draw(long vg, float x, float y) {
+ public void draw(long vg, float x, float y, InputHandler inputHandler) {
this.x = x;
this.y = y;
this.vg = vg;
@@ -136,8 +136,8 @@ public class TextInputField extends BasicElement {
RenderManager.drawHollowRoundRect(vg, x, y, width - 0.5f, height - 0.5f, errored ? Colors.ERROR_600 : Colors.PRIMARY_600, 12f, 2f);
}
Scissor scissor = ScissorManager.scissor(vg, x, y, width, height);
- super.update(x, y);
- if (Platform.getMousePlatform().isButtonDown(0) && !InputUtils.isAreaHovered(x - 40, y - 20, width + 90, height + 20)) {
+ super.update(x, y, inputHandler);
+ if (Platform.getMousePlatform().isButtonDown(0) && !inputHandler.isAreaHovered(x - 40, y - 20, width + 90, height + 20)) {
onClose();
toggled = false;
}
@@ -172,11 +172,11 @@ public class TextInputField extends BasicElement {
int state = Platform.getMousePlatform().getButtonState(0); //todo does this work
if (state == 1) {
if (multiLine) {
- int caretLine = Math.max(0, Math.min(wrappedText.size() - 1, (int) Math.floor((InputUtils.mouseY() - y - 10) / 24f)));
- caretPos = calculatePos(InputUtils.mouseX(), wrappedText.get(caretLine));
- } else prevCaret = calculatePos(InputUtils.mouseX(), input);
+ int caretLine = Math.max(0, Math.min(wrappedText.size() - 1, (int) Math.floor((inputHandler.mouseY() - y - 10) / 24f)));
+ caretPos = calculatePos(inputHandler.mouseX(), wrappedText.get(caretLine));
+ } else prevCaret = calculatePos(inputHandler.mouseX(), input);
if (System.currentTimeMillis() - clickTimeD1 < 300) {
- onDoubleClick();
+ onDoubleClick(inputHandler);
isDoubleClick = true;
}
clickTimeD1 = System.currentTimeMillis();
@@ -209,10 +209,10 @@ public class TextInputField extends BasicElement {
if (hovered) {
if (Platform.getMousePlatform().isButtonDown(0) && !isDoubleClick) {
if (multiLine) {
- int caretLine = Math.max(0, Math.min(wrappedText.size() - 1, (int) Math.floor((InputUtils.mouseY() - y - 10) / 24f)));
- caretPos = calculatePos(InputUtils.mouseX(), wrappedText.get(caretLine));
+ int caretLine = Math.max(0, Math.min(wrappedText.size() - 1, (int) Math.floor((inputHandler.mouseY() - y - 10) / 24f)));
+ caretPos = calculatePos(inputHandler.mouseX(), wrappedText.get(caretLine));
for (int i = 0; i < caretLine; i++) caretPos += wrappedText.get(i).length();
- } else caretPos = calculatePos(InputUtils.mouseX(), input);
+ } else caretPos = calculatePos(inputHandler.mouseX(), input);
if (caretPos > prevCaret) {
if (!centered) start = x + 12 + this.getTextWidth(vg, input.substring(0, prevCaret));
else
@@ -462,13 +462,13 @@ public class TextInputField extends BasicElement {
toggled = true;
}
- private void onDoubleClick() {
+ private void onDoubleClick(InputHandler inputHandler) {
prevCaret = input.substring(0, caretPos).lastIndexOf(' ') + 1;
caretPos = input.indexOf(' ', caretPos);
if (caretPos == -1) caretPos = input.length();
selectedText = input.substring(prevCaret, caretPos);
if (multiLine) {
- int caretLine = Math.max(0, Math.min(wrappedText.size() - 1, (int) Math.floor((InputUtils.mouseY() - y - 10) / 24f)));
+ int caretLine = Math.max(0, Math.min(wrappedText.size() - 1, (int) Math.floor((inputHandler.mouseY() - y - 10) / 24f)));
startLine = caretLine;
endLine = caretLine;
start = x + 12 + this.getTextWidth(vg, wrappedText.get(caretLine).substring(0, getLineCaret(prevCaret, startLine)));