diff options
author | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-05-08 12:34:48 +0100 |
---|---|---|
committer | nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> | 2022-05-08 12:34:48 +0100 |
commit | e609d6a09c71ef88be32efd8aae832f813abd64b (patch) | |
tree | 2aed7aaff323ccc8eea1d5eabe7b8cd7c7cfc3cc /src/main/java/cc/polyfrost/oneconfig/gui | |
parent | 9cbb009f815923218b2b9ab7d246d0e904f63710 (diff) | |
download | OneConfig-e609d6a09c71ef88be32efd8aae832f813abd64b.tar.gz OneConfig-e609d6a09c71ef88be32efd8aae832f813abd64b.tar.bz2 OneConfig-e609d6a09c71ef88be32efd8aae832f813abd64b.zip |
color selector stuff
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui')
5 files changed, 103 insertions, 36 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java index 7fe7a35..8897ec5 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java @@ -6,6 +6,7 @@ import cc.polyfrost.oneconfig.gui.elements.ColorSelector; import cc.polyfrost.oneconfig.gui.elements.text.TextInputField; import cc.polyfrost.oneconfig.gui.pages.HomePage; import cc.polyfrost.oneconfig.gui.pages.Page; +import cc.polyfrost.oneconfig.lwjgl.OneColor; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.scissor.Scissor; import cc.polyfrost.oneconfig.lwjgl.scissor.ScissorManager; @@ -217,8 +218,8 @@ public class OneConfigGui extends GuiScreen { /** * Close the current color selector and return the color it had when it closed. */ - public Color closeColorSelector() { - Color color = currentColorSelector.getColor(); + public OneColor closeColorSelector() { + OneColor color = currentColorSelector.getColor(); currentColorSelector = null; return color; } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java index 25987db..a57226f 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java @@ -4,18 +4,24 @@ import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.elements.text.NumberInputField; import cc.polyfrost.oneconfig.gui.elements.text.TextInputField; +import cc.polyfrost.oneconfig.lwjgl.OneColor; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.Images; +import cc.polyfrost.oneconfig.utils.InputUtils; import cc.polyfrost.oneconfig.utils.MathUtils; +import org.lwjgl.input.Mouse; import java.awt.*; +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.StringSelection; public class ColorSelector { private final int x; private final int y; - private Color color; + private OneColor color; private float percentMove = 0f; + private int mouseX, mouseY; private final BasicElement hsbBtn = new BasicElement(124, 28, 2, true); private final BasicElement rgbBtn = new BasicElement(124, 28, 2, true); private final BasicElement chromaBtn = new BasicElement(124, 28, 2, true); @@ -25,18 +31,18 @@ public class ColorSelector { private final BasicElement pasteBtn = new BasicElement(32, 32, 2, true); private final BasicButton guideBtn = new BasicButton(112, 32, "Guide", null, null, 0, BasicButton.ALIGNMENT_CENTER); - private final NumberInputField hueInput = new NumberInputField(90, 32, 0, 0, 255, 1); - private final NumberInputField saturationInput = new NumberInputField(90, 32, 0, 0, 255, 1); - private final NumberInputField brightnessInput = new NumberInputField(90, 32, 0, 0, 100, 1); - private final NumberInputField alphaInput = new NumberInputField(90, 32, 0, 0, 100, 1); + private final NumberInputField hueInput = new NumberInputField(90, 32, 0, 0, 360, 1); + private final NumberInputField saturationInput = new NumberInputField(90, 32, 100, 0, 100, 1); + private final NumberInputField brightnessInput = new NumberInputField(90, 32, 100, 0, 100, 1); + private final NumberInputField alphaInput = new NumberInputField(90, 32, 0, 100, 100, 1); private final TextInputField hexInput = new TextInputField(88, 32, true, ""); - private final ColorSlider topSlider = new ColorSlider(384, 0, 255, 127); - private final ColorSlider bottomSlider = new ColorSlider(384, 0, 255, 127); + private final ColorSlider topSlider = new ColorSlider(384, 0, 360, 127); + private final ColorSlider bottomSlider = new ColorSlider(384, 0, 100, 100); private final Slider speedSlider = new Slider(384, 1, 60, 20); - public ColorSelector(Color color, int mouseX, int mouseY) { + public ColorSelector(OneColor color, int mouseX, int mouseY) { this.color = color; this.x = mouseX - 208; this.y = mouseY - 776; @@ -45,7 +51,7 @@ public class ColorSelector { public void draw(long vg) { int width = 416; int height = 768; - int mode = 1; + int mode = 0; RenderManager.drawHollowRoundRect(vg, x - 3, y - 3, width + 4, height + 4, new Color(204, 204, 204, 77).getRGB(), 20f, 2f); RenderManager.drawRoundedRect(vg, x, y, width, height, OneConfigConfig.GRAY_800, 20f); @@ -72,7 +78,7 @@ public class ColorSelector { brightnessInput.draw(vg, x + 104, y + 584); RenderManager.drawString(vg, "Alpha (%)", x + 224, y + 599, OneConfigConfig.WHITE_80, 12f, Fonts.MEDIUM); alphaInput.draw(vg, x + 312, y + 584); - RenderManager.drawString(vg, "Hex (RGBA)", x + 16, y + 641, OneConfigConfig.WHITE_80, 12f, Fonts.MEDIUM); + RenderManager.drawString(vg, "Hex (ARGB)", x + 16, y + 641, OneConfigConfig.WHITE_80, 12f, Fonts.MEDIUM); hexInput.draw(vg, x + 104, y + 624); copyBtn.draw(vg, x + 204, y + 624); @@ -84,9 +90,35 @@ public class ColorSelector { RenderManager.drawImage(vg, Images.HELP, x + 301, y + 631, 18, 18); RenderManager.drawImage(vg, Images.LAUNCH, x + 369, y + 631, 18, 18); + + switch (mode) { default: case 0: + if(mouseX < x + 16 || mouseY < y + 120){ + mouseX = x + 16; + mouseY = y + 120; + } + boolean drag = Mouse.isButtonDown(0) && InputUtils.isAreaHovered(x + 16, y + 120, 384, 288); + if(drag) { + mouseX = InputUtils.mouseX(); + mouseY = InputUtils.mouseY(); + } + float progressX = (mouseX - x - 16f) / 384f; + float progressY = Math.abs((mouseY - y - 120f) / 288f - 1f); + RenderManager.drawHSBBox(vg, x + 16, y + 120, 384, 288, color.getRGBMax()); + RenderManager.drawRoundedRect(vg, mouseX - 6, mouseY - 6, 12, 12, OneConfigConfig.BLUE_600, 12f); + + topSlider.setImage(Images.HUE_GRADIENT); + color.setHSBA((int) topSlider.getValue(), Math.round(progressX * 100), Math.round(progressY * 100), (int) ((bottomSlider.getValue() / 100f) * 255)); + + topSlider.draw(vg, x + 16, y + 424); + + RenderManager.drawString(vg, "Hue", x + 16, y + 560, OneConfigConfig.WHITE_80, 12f, Fonts.MEDIUM); + hueInput.draw(vg, x + 104, y + 544); + bottomSlider.setGradient(OneConfigConfig.TRANSPARENT_25, color.getRGBNoAlpha()); + RenderManager.drawImage(vg, Images.COLOR_BASE_LONG, x + 16, y + 456, 384, 16); + bottomSlider.draw(vg, x + 16, y + 456); break; case 1: RenderManager.drawRoundedRect(vg, x + 64, y + 120, 288, 288, OneConfigConfig.WHITE, 144f); @@ -94,14 +126,7 @@ public class ColorSelector { RenderManager.drawString(vg, "Hue", x + 16, y + 560, OneConfigConfig.WHITE_80, 12f, Fonts.MEDIUM); hueInput.draw(vg, x + 104, y + 544); - Color colorMax = new Color(color.getRed(), color.getGreen(), color.getBlue(), 255); - float[] hsbColor = new float[3]; - Color.RGBtoHSB(colorMax.getRed(), colorMax.getGreen(), colorMax.getBlue(), hsbColor); - hsbColor[2] = topSlider.getValue() / 255f; - color = new Color(Color.HSBtoRGB(hsbColor[0], hsbColor[1], hsbColor[2]), true); - bottomSlider.setGradient(new Color(color.getRed(), color.getGreen(), color.getBlue(), 25), colorMax); - topSlider.setGradient(Color.BLACK, colorMax); - color = new Color(color.getRed(), color.getGreen(), color.getBlue(), (int) bottomSlider.getValue()); + //RenderManager.drawRoundedRect(vg, bottomSlider.currentDragPoint - 8, y + 456, 16, 16, color.getRGB(), 16f); @@ -113,20 +138,45 @@ public class ColorSelector { break; } - float[] hsbColor = new float[3]; - Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsbColor); - hueInput.setInput(String.format("%.01f", hsbColor[0] * 360f)); - saturationInput.setInput(String.format("%.01f", hsbColor[1] * 100f)); - brightnessInput.setInput(String.format("%.01f", hsbColor[2] * 100f)); - alphaInput.setInput(String.format("%.01f", color.getAlpha() / 255f * 100f)); + if(hueInput.isToggled() || saturationInput.isToggled() || brightnessInput.isToggled() || alphaInput.isToggled() || hueInput.arrowsClicked() || saturationInput.arrowsClicked() || brightnessInput.arrowsClicked() || alphaInput.arrowsClicked()) { + color.setHSBA((int) hueInput.getCurrentValue(), (int) saturationInput.getCurrentValue(), (int) brightnessInput.getCurrentValue(), (int) ((alphaInput.getCurrentValue() / 100f) * 255f)); + topSlider.setValue(color.getHue()); + bottomSlider.setValue(color.getAlpha() / 255f * 100f); + } + else if(OneConfigGui.INSTANCE.mouseDown) { + hueInput.setInput(String.valueOf(color.getHue())); + saturationInput.setInput(String.valueOf(color.getSaturation())); + brightnessInput.setInput(String.valueOf(color.getBrightness())); + alphaInput.setInput(String.format("%.01f", color.getAlpha() / 255f * 100f)); + hexInput.setInput(color.getHex()); + } RenderManager.drawHollowRoundRect(vg, x + 15, y + 487, 384, 40, OneConfigConfig.GRAY_300, 12f, 2f); RenderManager.drawImage(vg, Images.COLOR_BASE_LARGE, x + 20, y + 492, 376, 32); RenderManager.drawRoundedRect(vg, x + 20, y + 492, 376, 32, color.getRGB(), 8f); + + hexInput.setErrored(false); + if(hexInput.isToggled()) { + try { + color.setColorFromHex(hexInput.getInput()); + } catch (Exception e) { + hexInput.setErrored(true); + } + } + + if(copyBtn.isClicked()) { + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(color.getHex()), null); + } + if(pasteBtn.isClicked()) { + try { + color.setColorFromHex(Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null).getTransferData(DataFlavor.stringFlavor).toString()); + } catch (Exception ignored) { + } + } } - public Color getColor() { + public OneColor getColor() { return color; } @@ -140,7 +190,8 @@ public class ColorSelector { private static class ColorSlider extends Slider { - protected Color gradColorStart, gradColorEnd; + protected int gradColorStart, gradColorEnd; + protected Images image; public ColorSlider(int length, float min, float max, float startValue) { super(length, min, max, startValue); @@ -150,15 +201,25 @@ public class ColorSelector { @Override public void draw(long vg, int x, int y) { update(x, y); + + if(image != null) { + RenderManager.drawRoundImage(vg, image, x, y, width, height, 8f); + } else { + RenderManager.drawGradientRoundedRect(vg, x, y, width, height, gradColorStart, gradColorEnd, 8f); + } + RenderManager.drawHollowRoundRect(vg, x - 1.5f, y - 1.5f, width + 2, height + 2, new Color(204, 204, 204, 77).getRGB(), 8f, 1f); - RenderManager.drawGradientRoundedRect(vg, x, y, width, height, gradColorStart.getRGB(), gradColorEnd.getRGB(), 8f); RenderManager.drawHollowRoundRect(vg, currentDragPoint - 9, y - 2, 18, 18, OneConfigConfig.WHITE, 7f, 1f); } - public void setGradient(Color start, Color end) { + public void setGradient(int start, int end) { gradColorStart = start; gradColorEnd = end; } + + public void setImage(Images image) { + this.image = image; + } } } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java index 627c0cc..ba533da 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigColorElement.java @@ -6,6 +6,7 @@ import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.elements.BasicElement; import cc.polyfrost.oneconfig.gui.elements.ColorSelector; import cc.polyfrost.oneconfig.gui.elements.text.TextInputField; +import cc.polyfrost.oneconfig.lwjgl.OneColor; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.Images; @@ -16,7 +17,7 @@ import java.lang.reflect.Field; public class ConfigColorElement extends BasicOption { private float alpha; - private Color color = Color.BLUE; + private OneColor color = new OneColor(Color.BLUE); private String hex; private final TextInputField hexField = new TextInputField(104, 32, "", false, false); @@ -79,7 +80,7 @@ public class ConfigColorElement extends BasicOption { RenderManager.drawRoundedRect(vg, x + 432, y, 64, 32, OneConfigConfig.GRAY_300, 12f); RenderManager.drawImage(vg, Images.COLOR_BASE, x + 948, y + 4, 56, 24, color.getRGB()); if (element.isClicked() && !element.isToggled()) { - OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(color, InputUtils.mouseX(), InputUtils.mouseY())); + OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(new OneColor(40, 30, 20), InputUtils.mouseX(), InputUtils.mouseY())); } if (element.isToggled() && element.isClicked()) { color = OneConfigGui.INSTANCE.closeColorSelector(); @@ -91,16 +92,16 @@ public class ConfigColorElement extends BasicOption { } // thanks stack overflow - public static Color HexToColor(String hex) throws NumberFormatException { + public static OneColor HexToColor(String hex) throws NumberFormatException { hex = hex.replace("#", ""); switch (hex.length()) { case 6: - return new Color( + return new OneColor( Integer.valueOf(hex.substring(0, 2), 16), Integer.valueOf(hex.substring(2, 4), 16), Integer.valueOf(hex.substring(4, 6), 16)); case 8: - return new Color( + return new OneColor( Integer.valueOf(hex.substring(0, 2), 16), Integer.valueOf(hex.substring(2, 4), 16), Integer.valueOf(hex.substring(4, 6), 16), 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 1199283..dbca002 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 @@ -97,6 +97,9 @@ public class TextInputField extends BasicElement { int color = toggled ? OneConfigConfig.WHITE : OneConfigConfig.WHITE_60; if (!toggled) caretPos = input.length(); if (caretPos > input.length()) caretPos = input.length(); + if (prevCaret > input.length()) prevCaret = input.length(); + if (caretPos < 0) caretPos = 0; + if (prevCaret < 0) prevCaret = 0; float width; StringBuilder s = new StringBuilder(); if (!password) { diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java b/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java index 85ebb9d..70a3917 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/pages/HomePage.java @@ -4,6 +4,7 @@ import cc.polyfrost.oneconfig.config.OneConfigConfig; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.elements.BasicButton; import cc.polyfrost.oneconfig.gui.elements.ColorSelector; +import cc.polyfrost.oneconfig.lwjgl.OneColor; import cc.polyfrost.oneconfig.lwjgl.RenderManager; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.lwjgl.image.Images; @@ -27,7 +28,7 @@ public class HomePage extends Page { //RenderManager.drawRoundedRect(vg); btn.draw(vg, x + 432, y + 658); if(btn.isClicked()) { - OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(new Color(255, 228, 155), InputUtils.mouseX(), InputUtils.mouseY())); + OneConfigGui.INSTANCE.initColorSelector(new ColorSelector(new OneColor(255, 228, 155), InputUtils.mouseX(), InputUtils.mouseY())); } } |