diff options
Diffstat (limited to 'src')
11 files changed, 201 insertions, 57 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/OneConfig.java b/src/main/java/cc/polyfrost/oneconfig/OneConfig.java index 62bff81..25866e8 100644 --- a/src/main/java/cc/polyfrost/oneconfig/OneConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/OneConfig.java @@ -6,6 +6,7 @@ import cc.polyfrost.oneconfig.config.core.ConfigCore; import cc.polyfrost.oneconfig.config.data.Mod; import cc.polyfrost.oneconfig.config.data.ModType; import cc.polyfrost.oneconfig.lwjgl.BlurHandler; +import cc.polyfrost.oneconfig.lwjgl.OneColor; import cc.polyfrost.oneconfig.lwjgl.font.Fonts; import cc.polyfrost.oneconfig.hud.HudCore; import cc.polyfrost.oneconfig.lwjgl.RenderManager; diff --git a/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java b/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java index 0eb833f..2993e23 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java @@ -16,7 +16,8 @@ public class OneConfigConfig extends Config { public static String currentProfile = "Default Profile"; public static ArrayList<String> favoriteMods = new ArrayList<>(); - public static final int TRANSPARENT = new Color(0, 0, 0, 0).getRGB(); // Transparent // button sidebar normal + public static final int TRANSPARENT = new Color(0, 0, 0, 0).getRGB(); // Transparent + public static final int TRANSPARENT_25 = new Color(0, 0, 0, 25).getRGB(); // Transparent 25% (used because of NanoVG culling) public static final int BLACK = new Color(0,0,0,255).getRGB(); // Black public static final int GRAY_900 = new Color(13, 14, 15, 255).getRGB(); // Gray 900 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())); } } diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java index fbdf86b..377b532 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java @@ -3,22 +3,21 @@ package cc.polyfrost.oneconfig.lwjgl; import org.jetbrains.annotations.NotNull; import java.awt.*; -import java.util.Arrays; /** * OneColor is a class for storing Colors in HSBA format. This format is used to allow the color selectors to work correctly. * <p> * <code> - * byte[0] = hue (0-360) - * byte[1] = saturation (0-100) - * byte[2] = brightness (0-100) - * byte[3] = alpha (0-100) + * short[0] = hue (0-360) + * short[1] = saturation (0-100) + * short[2] = brightness (0-100) + * short[3] = alpha (0-100) * </code> */ @SuppressWarnings("unused") public class OneColor { transient private int rgba; - private final byte[] hsba; + private short[] hsba; private int chroma = -1; // rgb constructors @@ -59,7 +58,7 @@ public class OneColor { * Create a new OneColor from the given HSBA values. */ public OneColor(float hue, float saturation, float brightness, float alpha) { - this.hsba = new byte[]{(byte) hue, (byte) saturation, (byte) brightness, (byte) alpha}; + this.hsba = new short[]{(short) hue, (short) saturation, (short) brightness, (short) alpha}; this.rgba = HSBAtoRGBA(this.hsba[0], this.hsba[1], this.hsba[2], this.hsba[3]); } @@ -80,11 +79,11 @@ public class OneColor { // internal constructor public OneColor(int hue, int saturation, int brightness, int alpha, int chromaSpeed) { if (chromaSpeed == -1) { - this.hsba = new byte[]{(byte) hue, (byte) saturation, (byte) brightness, (byte) alpha}; + this.hsba = new short[]{(short) hue, (short) saturation, (short) brightness, (short) alpha}; this.rgba = HSBAtoRGBA(this.hsba[0], this.hsba[1], this.hsba[2], this.hsba[3]); } else { this.chroma = chromaSpeed; - this.hsba = new byte[]{(byte) hue, (byte) saturation, (byte) brightness, (byte) alpha}; + this.hsba = new short[]{(short) hue, (short) saturation, (short) brightness, (short) alpha}; } } @@ -102,15 +101,15 @@ public class OneColor { return rgba & 255; } - public float getHue() { + public int getHue() { return hsba[0]; } - public float getSaturation() { + public int getSaturation() { return hsba[1]; } - public float getBrightness() { + public int getBrightness() { return hsba[2]; } @@ -118,6 +117,14 @@ public class OneColor { return hsba[3]; } + public void setHSBA(int hue, int saturation, int brightness, int alpha) { + this.hsba[0] = (short) hue; + this.hsba[1] = (short) saturation; + this.hsba[2] = (short) brightness; + this.hsba[3] = (short) alpha; + this.rgba = HSBAtoRGBA(this.hsba[0], this.hsba[1], this.hsba[2], this.hsba[3]); + } + /** * Return the current color in RGBA format. This is the format used by LWJGL and Minecraft. * This method WILL return the color as a chroma, at the specified speed, if it is set. @@ -133,24 +140,45 @@ public class OneColor { } } + /** return the current color without its alpha. Internal method. */ + public int getRGBNoAlpha() { + return new Color(rgba, false).getRGB(); + } + + /** + * Return the color as if it had maximum saturation and brightness. Internal method. + */ + public int getRGBMax() { + return HSBAtoRGBA(hsba[0], 100, 100, 255); + } + /** * Get the RGBA color from the HSB color, and apply the alpha. */ - public int HSBAtoRGBA(float hue, float saturation, float brightness, float alpha) { + public int HSBAtoRGBA(float hue, float saturation, float brightness, int alpha) { int temp = Color.HSBtoRGB(hue / 360f, saturation / 100f, brightness / 100f); - return temp | (int) (alpha * 255) << 24; // trusting copilot on this + return ((temp & 0x00ffffff) | (alpha << 24)); } /** * Get the HSBA color from the RGBA color. */ - public byte[] RGBAtoHSBA(int rgba) { - byte[] hsb = new byte[4]; + public short[] RGBAtoHSBA(int rgba) { + short[] hsb = new short[4]; float[] hsbArray = Color.RGBtoHSB((rgba >> 16 & 255), (rgba >> 8 & 255), (rgba & 255), null); - hsb[0] = (byte) (hsbArray[0] * 360); - hsb[1] = (byte) (hsbArray[1] * 100); - hsb[2] = (byte) (hsbArray[2] * 100); - hsb[3] = (byte) (rgba >> 24 & 255); + hsb[0] = (short) (hsbArray[0] * 360); + hsb[1] = (short) (hsbArray[1] * 100); + hsb[2] = (short) (hsbArray[2] * 100); + hsb[3] = (short) (rgba >> 24 & 255); return hsb; } + + public String getHex() { + return Integer.toHexString(rgba).toUpperCase(); + } + + public void setColorFromHex(String hex) { + rgba = Integer.parseInt(hex, 16); + hsba = RGBAtoHSBA(rgba); + } } diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java index 5f18e5f..979acde 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java @@ -87,6 +87,34 @@ public final class RenderManager { nvgColor2.free(); } + public static void drawHSBBox(long vg, float x, float y, float width, float height, int colorTarget) { + + drawRoundedRect(vg, x, y, width, height, colorTarget, 8f); + + NVGPaint bg = NVGPaint.create(); + nvgBeginPath(vg); + nvgRoundedRect(vg, x, y, width, height, 8f); + NVGColor nvgColor = color(vg, OneConfigConfig.WHITE); + NVGColor nvgColor2 = color(vg, OneConfigConfig.TRANSPARENT_25); + nvgFillPaint(vg, nvgLinearGradient(vg, x, y, x + width, y, nvgColor, nvgColor2, bg)); + nvgFill(vg); + nvgColor.free(); + nvgColor2.free(); + + NVGPaint bg2 = NVGPaint.create(); + nvgBeginPath(vg); + nvgRoundedRect(vg, x, y, width, height, 8f); + NVGColor nvgColor3 = color(vg, OneConfigConfig.TRANSPARENT_25); + NVGColor nvgColor4 = color(vg, OneConfigConfig.BLACK); + nvgFillPaint(vg, nvgLinearGradient(vg, x, y, x, y + height, nvgColor3, nvgColor4, bg2)); + nvgFill(vg); + nvgColor3.free(); + nvgColor4.free(); + + //drawHollowRoundRect(vg, x - 0.5f, y - 0.5f, width, height, new Color(77,77,77,255).getRGB(), 8f, 1f); + + } + public static void drawGradientRect(long vg, float x, float y, float width, float height, int color, int color2) { NVGPaint bg = NVGPaint.create(); nvgBeginPath(vg); @@ -208,6 +236,24 @@ public final class RenderManager { } } + public static void drawRoundImage(long vg, String filePath, float x, float y, float width, float height, float radius) { + if (ImageLoader.INSTANCE.loadImage(vg, filePath)) { + NVGPaint imagePaint = NVGPaint.calloc(); + cc.polyfrost.oneconfig.lwjgl.image.Image image = ImageLoader.INSTANCE.getImage(filePath); + nvgBeginPath(vg); + nvgImagePattern(vg, x, y, width, height, 0, image.getReference(), 1, imagePaint); + nvgRoundedRect(vg, x, y, width, height, radius); + nvgFillPaint(vg, imagePaint); + nvgFill(vg); + imagePaint.free(); + } + + } + + public static void drawRoundImage(long vg, Images filePath, float x, float y, float width, float height, float radius) { + drawRoundImage(vg, filePath.filePath, x, y, width, height, radius); + } + public static void drawImage(long vg, Images filePath, float x, float y, float width, float height) { drawImage(vg, filePath.filePath, x, y, width, height); } diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/Images.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/Images.java index 5609434..6232855 100644 --- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/Images.java +++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/image/Images.java @@ -17,6 +17,7 @@ public enum Images { COLOR_BASE_LONG("/assets/oneconfig/textures/gui/general/color/color_base_long.png"), COLOR_BASE_LARGE("/assets/oneconfig/textures/gui/general/color/color_base_large.png"), COLOR_WHEEL("/assets/oneconfig/textures/gui/general/color/color_wheel.png"), + HUE_GRADIENT("/assets/oneconfig/textures/gui/general/color/huegradient.png"), INFO("/assets/oneconfig/textures/gui/icons/alert/info.png"), SUCCESS("/assets/oneconfig/textures/gui/icons/alert/success.png"), diff --git a/src/main/resources/assets/oneconfig/textures/gui/general/color/huegradient.png b/src/main/resources/assets/oneconfig/textures/gui/general/color/huegradient.png Binary files differnew file mode 100644 index 0000000..69c93fe --- /dev/null +++ b/src/main/resources/assets/oneconfig/textures/gui/general/color/huegradient.png |