From ffcb16e4c7f0f4414c69541238178ce3a128bb74 Mon Sep 17 00:00:00 2001 From: nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> Date: Sun, 22 May 2022 14:57:45 +0100 Subject: color selector and loads of stuffs --- .../oneconfig/config/OneConfigConfig.java | 2 +- .../polyfrost/oneconfig/config/core/OneColor.java | 262 +++++++++++++++++++++ .../cc/polyfrost/oneconfig/gui/OneConfigGui.java | 10 +- .../oneconfig/gui/elements/BasicElement.java | 7 +- .../oneconfig/gui/elements/ColorSelector.java | 193 ++++++++++----- .../polyfrost/oneconfig/gui/elements/Slider.java | 2 +- .../gui/elements/config/ConfigColorElement.java | 16 +- .../gui/elements/config/ConfigSlider.java | 2 +- .../polyfrost/oneconfig/gui/pages/CreditsPage.java | 12 + .../cc/polyfrost/oneconfig/gui/pages/HomePage.java | 23 +- .../java/cc/polyfrost/oneconfig/hud/BasicHud.java | 2 +- .../cc/polyfrost/oneconfig/lwjgl/OneColor.java | 249 -------------------- .../polyfrost/oneconfig/lwjgl/RenderManager.java | 3 +- .../cc/polyfrost/oneconfig/test/TestConfig.java | 2 +- .../cc/polyfrost/oneconfig/utils/ColorUtils.java | 15 +- .../java/cc/polyfrost/oneconfig/utils/IOUtils.java | 21 ++ 16 files changed, 479 insertions(+), 342 deletions(-) create mode 100644 src/main/java/cc/polyfrost/oneconfig/config/core/OneColor.java create mode 100644 src/main/java/cc/polyfrost/oneconfig/gui/pages/CreditsPage.java delete mode 100644 src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java (limited to 'src/main/java/cc/polyfrost/oneconfig') diff --git a/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java b/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java index d0697bd..9a50a77 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/OneConfigConfig.java @@ -1,7 +1,7 @@ package cc.polyfrost.oneconfig.config; import cc.polyfrost.oneconfig.config.interfaces.Config; -import cc.polyfrost.oneconfig.lwjgl.OneColor; +import cc.polyfrost.oneconfig.config.core.OneColor; import com.google.gson.JsonParser; import cc.polyfrost.oneconfig.config.data.Mod; diff --git a/src/main/java/cc/polyfrost/oneconfig/config/core/OneColor.java b/src/main/java/cc/polyfrost/oneconfig/config/core/OneColor.java new file mode 100644 index 0000000..0426090 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/config/core/OneColor.java @@ -0,0 +1,262 @@ +package cc.polyfrost.oneconfig.config.core; + +import org.jetbrains.annotations.NotNull; + +import java.awt.*; + +/** + * OneColor is a class for storing Colors in HSBA format. This format is used to allow the color selectors to work correctly. + *
+ *
- *
+ * short[0] = hue (0-360)
+ * short[1] = saturation (0-100)
+ * short[2] = brightness (0-100)
+ * short[3] = alpha (0-255)
+ *
+ */
+@SuppressWarnings("unused")
+public final class OneColor {
+ transient private Integer rgba = null;
+ private short[] hsba;
+ private int dataBit = -1;
+
+ // rgb constructors
+
+ /**
+ * Create a new OneColor, converting the RGBA color to HSBA.
+ */
+ public OneColor(int rgba) {
+ this.rgba = rgba;
+ this.hsba = RGBAtoHSBA(this.rgba);
+ }
+
+ /**
+ * Create a new OneColor from the given RGBA values.
+ */
+ public OneColor(int r, int g, int b, int a) {
+ this.rgba = ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | ((b & 0xFF));
+ this.hsba = RGBAtoHSBA(this.rgba);
+ }
+
+ /**
+ * Create a new OneColor, converting the RGB color to HSBA.
+ */
+ public OneColor(int r, int g, int b) {
+ this(r, g, b, 255);
+ }
+
+ /**
+ * Convert the java.awt.Color to an OneColor (HSBA format).
+ */
+ public OneColor(@NotNull Color c) {
+ this(c.getRGB());
+ }
+
+ // hsb constructors
+
+ /**
+ * Create a new OneColor from the given HSBA values.
+ */
+ public OneColor(float hue, float saturation, float brightness, float 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]);
+
+ }
+
+ /**
+ * Create a new OneColor from the given HSB values. (alpha is set to max)
+ */
+ public OneColor(float hue, float saturation, float brightness) {
+ this(hue, saturation, brightness, 1.0f);
+ }
+
+ // chroma constructors
+ /** Create a new Chroma OneColor. The speed should be a max of 30s and a min of 1s. */
+ public OneColor(int saturation, int brightness, int alpha, float chromaSpeed) {
+ this(System.currentTimeMillis() % (int) chromaSpeed / chromaSpeed, saturation, brightness, alpha);
+ if(chromaSpeed < 1) chromaSpeed = 1;
+ if(chromaSpeed > 30) chromaSpeed = 30;
+ this.dataBit = (int) chromaSpeed;
+ }
+
+ // internal constructor
+ public OneColor(int hue, int saturation, int brightness, int alpha, int chromaSpeed) {
+ if (chromaSpeed == -1) {
+ 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.dataBit = chromaSpeed;
+ this.hsba = new short[]{(short) hue, (short) saturation, (short) brightness, (short) alpha};
+ }
+ }
+
+
+ // accessors
+ /** Get the red value of the color (0-255). */
+ public int getRed() {
+ return rgba >> 16 & 255;
+ }
+
+ /** Get the green value of the color (0-255). */
+ public int getGreen() {
+ return rgba >> 8 & 255;
+ }
+
+ /** Get the blue value of the color (0-255). */
+ public int getBlue() {
+ return rgba & 255;
+ }
+
+ /** Get the hue value of the color (0-360). */
+ public int getHue() {
+ return hsba[0];
+ }
+
+ /** Get the saturation value of the color (0-100). */
+ public int getSaturation() {
+ return hsba[1];
+ }
+
+ /** Get the brightness value of the color (0-100). */
+ public int getBrightness() {
+ return hsba[2];
+ }
+
+ /** Get the alpha value of the color (0-255). */
+ public int getAlpha() {
+ return hsba[3];
+ }
+
+ /** Get the chroma speed of the color (1s-30s). */
+ public int getDataBit() {
+ return dataBit == -1 ? -1 : dataBit / 1000;
+ }
+
+ /** Set the current chroma speed of the color. -1 to disable. */
+ public void setChromaSpeed(int speed) {
+ if(speed == -1) {
+ this.dataBit = -1;
+ return;
+ }
+ if(speed < 1) speed = 1;
+ if(speed > 30) speed = 30;
+ this.dataBit = speed * 1000;
+ }
+
+ /** Set the HSBA values of the color. */
+ 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]);
+ }
+
+ public void setFromOneColor(OneColor color) {
+ setHSBA(color.hsba[0], color.hsba[1], color.hsba[2], color.hsba[3]);
+ }
+
+ /**
+ * Return the current color in ARGB 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.
+ * Otherwise, it will just return the current color.
+ *
+ * @return the current color in RGBA format (equivalent to getRGB of java.awt.Color)
+ */
+ public int getRGB() {
+ if (dataBit == 0) dataBit = -1;
+ if (dataBit == -1) {
+ // fix for when rgba is not set because of deserializing not calling constructor
+ if (rgba == null) rgba = HSBAtoRGBA(this.hsba[0], this.hsba[1], this.hsba[2], this.hsba[3]);
+ return rgba;
+ } else {
+ int temp = Color.HSBtoRGB(System.currentTimeMillis() % dataBit / (float) dataBit, hsba[1] / 100f, hsba[2] / 100f);
+ hsba[0] = (short) ((System.currentTimeMillis() % dataBit / (float) dataBit) * 360);
+ return ((temp & 0x00ffffff) | (hsba[3] << 24));
+ }
+ }
+
+ /**
+ * return the current color without its alpha. Internal method.
+ */
+ public int getRGBNoAlpha() {
+ return 0xff000000 | getRGB();
+ }
+
+ /**
+ * Return the color as if it had maximum saturation and brightness. Internal method.
+ */
+ public int getRGBMax(boolean maxBrightness) {
+ return HSBAtoRGBA(hsba[0], maxBrightness ? hsba[1] : 100, 100, 255);
+ }
+
+ /**
+ * Get the RGBA color from the HSB color, and apply the alpha.
+ */
+ public static int HSBAtoRGBA(float hue, float saturation, float brightness, int alpha) {
+ int temp = Color.HSBtoRGB(hue / 360f, saturation / 100f, brightness / 100f);
+ return ((temp & 0x00ffffff) | (alpha << 24));
+ }
+
+ /**
+ * Get the HSBA color from the RGBA color.
+ */
+ public static short[] RGBAtoHSBA(int rgba) {
+ short[] hsb = new short[4];
+ float[] hsbArray = Color.RGBtoHSB((rgba >> 16 & 255), (rgba >> 8 & 255), (rgba & 255), null);
+ 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(0xff000000 | getRGB()).toUpperCase().substring(2);
+ }
+
+ public void setColorFromHex(String hex) {
+ hex = hex.replace("#", "");
+ if(hex.length() > 6) {
+ hex = hex.substring(0, 6);
+ }
+ if(hex.length() == 3) {
+ hex = charsToString(hex.charAt(0), hex.charAt(0), hex.charAt(1), hex.charAt(1), hex.charAt(2), hex.charAt(2));
+ }
+ if(hex.length() == 1) {
+ hex = charsToString(hex.charAt(0), hex.charAt(0), hex.charAt(0), hex.charAt(0), hex.charAt(0), hex.charAt(0));
+ }
+ if(hex.length() == 2 && hex.charAt(1) == hex.charAt(0)) {
+ hex = charsToString(hex.charAt(0), hex.charAt(0), hex.charAt(0), hex.charAt(0), hex.charAt(0), hex.charAt(0));
+ }
+ StringBuilder hexBuilder = new StringBuilder(hex);
+ while (hexBuilder.length() < 6) {
+ hexBuilder.append("0");
+ }
+ hex = hexBuilder.toString();
+ //System.out.println(hex);
+ int r = Integer.valueOf(hex.substring( 0, 2 ), 16);
+ int g = Integer.valueOf( hex.substring( 2, 4 ), 16);
+ int b = Integer.valueOf( hex.substring( 4, 6 ), 16);
+ this.rgba = ((getAlpha() & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | ((b & 0xFF));
+ hsba = RGBAtoHSBA(rgba);
+ }
+
+ public void setAlpha(int alpha) {
+ this.hsba[3] = (short) alpha;
+ rgba = HSBAtoRGBA(this.hsba[0], this.hsba[1], this.hsba[2], this.hsba[3]);
+ }
+
+ private String charsToString(char... chars) {
+ StringBuilder sb = new StringBuilder();
+ for(char c : chars) {
+ sb.append(c);
+ }
+ return sb.toString();
+ }
+
+ @Override
+ public String toString() {
+ return "OneColor{rgba=[r=" + getRed() + ", g=" + getGreen() + ", b=" + getBlue() + ", a=" + getAlpha() + "], hsba=[h=" + getHue() + ", s=" + getSaturation() + ", b=" + getBrightness() + ", a=" + getAlpha() + "], hex=" + getHex() + "}";
+ }
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
index 7e12a74..3bfcc74 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/OneConfigGui.java
@@ -6,7 +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.config.core.OneColor;
import cc.polyfrost.oneconfig.lwjgl.RenderManager;
import cc.polyfrost.oneconfig.lwjgl.font.Fonts;
import cc.polyfrost.oneconfig.lwjgl.image.SVGs;
@@ -32,7 +32,7 @@ public class OneConfigGui extends UScreen {
private final BasicElement backArrow = new BasicElement(40, 40, -1, false);
private final BasicElement forwardArrow = new BasicElement(40, 40, -1, false);
private final ArrayListOneConfigGui.INSTANCE.initColorSelector(new ColorSelector(color, InputUtils.mouseX(), InputUtils.mouseY()));
*/
public void initColorSelector(ColorSelector colorSelector) {
+ InputUtils.blockClicks(true);
currentColorSelector = colorSelector;
}
@@ -242,6 +243,11 @@ public class OneConfigGui extends UScreen {
return color;
}
+ public OneColor getColor() {
+ if(currentColorSelector == null) return null;
+ return currentColorSelector.getColor();
+ }
+
public float getScaleFactor() {
return scale;
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java
index bcfebd3..887d8d2 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/BasicElement.java
@@ -16,6 +16,7 @@ public class BasicElement {
protected boolean disabled = false;
protected int currentColor;
protected final float radius;
+ private boolean block = false;
public BasicElement(int width, int height, int colorPalette, boolean hoverFx) {
this(width, height, colorPalette, hoverFx, 12f);
@@ -50,7 +51,7 @@ public class BasicElement {
return;
}
hovered = InputUtils.isAreaHovered(x - hitBoxX, y - hitBoxY, width + hitBoxX, height + hitBoxY);
- clicked = InputUtils.isClicked() && hovered;
+ clicked = InputUtils.isClicked(block) && hovered;
if (clicked) {
toggled = !toggled;
@@ -58,6 +59,10 @@ public class BasicElement {
}
}
+ public void ignoreBlockedTouches(boolean state) {
+ block = state;
+ }
+
public void onClick() {
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 f32abc3..a0c094a 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/ColorSelector.java
@@ -1,14 +1,15 @@
package cc.polyfrost.oneconfig.gui.elements;
import cc.polyfrost.oneconfig.config.OneConfigConfig;
+import cc.polyfrost.oneconfig.config.core.OneColor;
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.lwjgl.image.SVGs;
+import cc.polyfrost.oneconfig.utils.IOUtils;
import cc.polyfrost.oneconfig.utils.InputUtils;
import cc.polyfrost.oneconfig.utils.MathUtils;
import org.lwjgl.input.Mouse;
@@ -19,17 +20,19 @@ import java.awt.datatransfer.StringSelection;
import java.util.ArrayList;
public class ColorSelector {
- private final int x;
- private final int y;
+ private int x;
+ private int y;
private OneColor color;
private float percentMove = 0f;
private int mouseX, mouseY;
private final ArrayList
- * short[0] = hue (0-360)
- * short[1] = saturation (0-100)
- * short[2] = brightness (0-100)
- * short[3] = alpha (0-255)
- *
- */
-@SuppressWarnings("unused")
-public final class OneColor {
- transient private Integer rgba = null;
- private short[] hsba;
- private int chroma = -1;
-
- // rgb constructors
-
- /**
- * Create a new OneColor, converting the RGBA color to HSBA.
- */
- public OneColor(int rgba) {
- this.rgba = rgba;
- this.hsba = RGBAtoHSBA(this.rgba);
- }
-
- /**
- * Create a new OneColor from the given RGBA values.
- */
- public OneColor(int r, int g, int b, int a) {
- this.rgba = ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | ((b & 0xFF));
- this.hsba = RGBAtoHSBA(this.rgba);
- }
-
- /**
- * Create a new OneColor, converting the RGB color to HSBA.
- */
- public OneColor(int r, int g, int b) {
- this(r, g, b, 255);
- }
-
- /**
- * Convert the java.awt.Color to an OneColor (HSBA format).
- */
- public OneColor(@NotNull Color c) {
- this(c.getRGB());
- }
-
- // hsb constructors
-
- /**
- * Create a new OneColor from the given HSBA values.
- */
- public OneColor(float hue, float saturation, float brightness, float 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]);
-
- }
-
- /**
- * Create a new OneColor from the given HSB values. (alpha is set to max)
- */
- public OneColor(float hue, float saturation, float brightness) {
- this(hue, saturation, brightness, 1.0f);
- }
-
- // chroma constructors
- /** Create a new Chroma OneColor. The speed should be a max of 30s and a min of 1s. */
- public OneColor(int saturation, int brightness, int alpha, float chromaSpeed) {
- this(System.currentTimeMillis() % (int) chromaSpeed / chromaSpeed, saturation, brightness, alpha);
- if(chromaSpeed < 1) chromaSpeed = 1;
- if(chromaSpeed > 30) chromaSpeed = 30;
- this.chroma = (int) chromaSpeed;
- }
-
- // internal constructor
- public OneColor(int hue, int saturation, int brightness, int alpha, int chromaSpeed) {
- if (chromaSpeed == -1) {
- 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 short[]{(short) hue, (short) saturation, (short) brightness, (short) alpha};
- }
- }
-
-
- // accessors
- /** Get the red value of the color (0-255). */
- public int getRed() {
- return rgba >> 16 & 255;
- }
-
- /** Get the green value of the color (0-255). */
- public int getGreen() {
- return rgba >> 8 & 255;
- }
-
- /** Get the blue value of the color (0-255). */
- public int getBlue() {
- return rgba & 255;
- }
-
- /** Get the hue value of the color (0-360). */
- public int getHue() {
- return hsba[0];
- }
-
- /** Get the saturation value of the color (0-100). */
- public int getSaturation() {
- return hsba[1];
- }
-
- /** Get the brightness value of the color (0-100). */
- public int getBrightness() {
- return hsba[2];
- }
-
- /** Get the alpha value of the color (0-255). */
- public int getAlpha() {
- return hsba[3];
- }
-
- /** Get the chroma speed of the color (1s-30s). */
- public int getChroma() {
- return chroma == -1 ? -1 : chroma / 1000;
- }
-
- /** Set the current chroma speed of the color. -1 to disable. */
- public void setChromaSpeed(int speed) {
- if(speed == -1) {
- this.chroma = -1;
- return;
- }
- if(speed < 1) speed = 1;
- if(speed > 30) speed = 30;
- this.chroma = speed * 1000;
- }
-
- /** Set the HSBA values of the color. */
- 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]);
- }
-
- public void setFromOneColor(OneColor color) {
- setHSBA(color.hsba[0], color.hsba[1], color.hsba[2], color.hsba[3]);
- }
-
- /**
- * Return the current color in ARGB 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.
- * Otherwise, it will just return the current color.
- *
- * @return the current color in RGBA format (equivalent to getRGB of java.awt.Color)
- */
- public int getRGB() {
- if (chroma == -1) {
- // fix for when rgba is not set because of deserializing not calling constructor
- if (rgba == null) rgba = HSBAtoRGBA(this.hsba[0], this.hsba[1], this.hsba[2], this.hsba[3]);
- return rgba;
- } else {
- int temp = Color.HSBtoRGB(System.currentTimeMillis() % chroma / (float) chroma, hsba[1] / 100f, hsba[2] / 100f);
- hsba[0] = (short) ((System.currentTimeMillis() % chroma / (float) chroma) * 360);
- return ((temp & 0x00ffffff) | (hsba[3] << 24));
- }
- }
-
- /**
- * return the current color without its alpha. Internal method.
- */
- public int getRGBNoAlpha() {
- return 0xff000000 | getRGB();
- }
-
- /**
- * Return the color as if it had maximum saturation and brightness. Internal method.
- */
- public int getRGBMax(boolean maxBrightness) {
- return HSBAtoRGBA(hsba[0], maxBrightness ? hsba[1] : 100, 100, 255);
- }
-
- /**
- * Get the RGBA color from the HSB color, and apply the alpha.
- */
- public static int HSBAtoRGBA(float hue, float saturation, float brightness, int alpha) {
- int temp = Color.HSBtoRGB(hue / 360f, saturation / 100f, brightness / 100f);
- return ((temp & 0x00ffffff) | (alpha << 24));
- }
-
- /**
- * Get the HSBA color from the RGBA color.
- */
- public static short[] RGBAtoHSBA(int rgba) {
- short[] hsb = new short[4];
- float[] hsbArray = Color.RGBtoHSB((rgba >> 16 & 255), (rgba >> 8 & 255), (rgba & 255), null);
- 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(0xff000000 | getRGB()).toUpperCase().substring(2);
- }
-
- public void setColorFromHex(String hex) {
- hex = hex.replace("#", "");
- if(hex.length() == 3) {
- hex = charsToString(hex.charAt(0), hex.charAt(0), hex.charAt(1), hex.charAt(1), hex.charAt(2), hex.charAt(2));
- }
- if(hex.length() == 1) {
- hex = charsToString(hex.charAt(0), hex.charAt(0), hex.charAt(0), hex.charAt(0), hex.charAt(0), hex.charAt(0));
- }
- if(hex.length() == 2 && hex.charAt(1) == hex.charAt(0)) {
- hex = charsToString(hex.charAt(0), hex.charAt(0), hex.charAt(0), hex.charAt(0), hex.charAt(0), hex.charAt(0));
- }
- rgba = Integer.parseInt(hex, 16);
- hsba = RGBAtoHSBA(0xff000000 | rgba);
- }
-
- public void setAlpha(int alpha) {
- this.hsba[3] = (short) alpha;
- rgba = HSBAtoRGBA(this.hsba[0], this.hsba[1], this.hsba[2], this.hsba[3]);
- }
-
- private String charsToString(char... chars) {
- StringBuilder sb = new StringBuilder();
- for(char c : chars) {
- sb.append(c);
- }
- return sb.toString();
- }
-
- @Override
- public String toString() {
- return "OneColor{rgba=[r=" + getRed() + ", g=" + getGreen() + ", b=" + getBlue() + ", a=" + getAlpha() + "], hsba=[h=" + getHue() + ", s=" + getSaturation() + ", b=" + getBrightness() + ", a=" + getAlpha() + "], hex=" + getHex() + "}";
- }
-}
diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java
index 8f8fadf..a1c4d55 100644
--- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java
+++ b/src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java
@@ -49,6 +49,7 @@ public final class RenderManager {
fb.enableStencil();
}
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
+ GL11.glDisable(GL11.GL_ALPHA_TEST);
if (mcScaling) {
nvgBeginFrame(vg, (float) UResolution.getScaledWidth(), (float) UResolution.getScaledHeight(), (float) UResolution.getScaleFactor());
@@ -150,7 +151,7 @@ public final class RenderManager {
public static void drawHollowRoundRect(long vg, float x, float y, float width, float height, int color, float radius, float thickness) {
nvgBeginPath(vg);
nvgRoundedRect(vg, x + thickness, y + thickness, width - thickness, height - thickness, radius);
- nvgStrokeWidth(vg, thickness);
+ nvgStrokeWidth(vg, thickness + 0.5f);
nvgPathWinding(vg, NVG_HOLE);
color(vg, color);
NVGColor nvgColor = color(vg, color);
diff --git a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java
index b5410de..d65fea3 100644
--- a/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java
+++ b/src/main/java/cc/polyfrost/oneconfig/test/TestConfig.java
@@ -5,7 +5,7 @@ import cc.polyfrost.oneconfig.config.annotations.Option;
import cc.polyfrost.oneconfig.config.core.OneKeyBind;
import cc.polyfrost.oneconfig.config.data.*;
import cc.polyfrost.oneconfig.config.interfaces.Config;
-import cc.polyfrost.oneconfig.lwjgl.OneColor;
+import cc.polyfrost.oneconfig.config.core.OneColor;
import net.minecraftforge.fml.common.FMLCommonHandler;
public class TestConfig extends Config {
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java
index 400dc39..ae5753a 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/ColorUtils.java
@@ -25,18 +25,18 @@ public class ColorUtils {
switch (colorPalette) {
case -2:
- return getColorComponents(color, splitColor(OneConfigConfig.TRANSPARENT), new float[]{0.9f, 0.9f, 0.9f, 0.3f}, hover, 20f);
+ return getColorComponents(color, splitColor(OneConfigConfig.TRANSPARENT), new float[]{0.9f, 0.9f, 0.9f, 0.3f}, hover, 50f);
case -1:
- return getColorComponents(color, splitColor(OneConfigConfig.TRANSPARENT), splitColor(OneConfigConfig.GRAY_500), hover, 10f);
+ return getColorComponents(color, splitColor(OneConfigConfig.TRANSPARENT), splitColor(OneConfigConfig.GRAY_500), hover, 50f);
default:
case 0:
- return getColorComponents(color, splitColor(OneConfigConfig.GRAY_600), splitColor(OneConfigConfig.GRAY_300), hover, 25f);
+ return getColorComponents(color, splitColor(OneConfigConfig.GRAY_600), splitColor(OneConfigConfig.GRAY_300), hover, 50f);
case 1:
return getColorComponents(color, splitColor(OneConfigConfig.PRIMARY_600), splitColor(OneConfigConfig.PRIMARY_500), hover, 150f);
case 2:
return getColorComponents(color, splitColor(OneConfigConfig.GRAY_500), splitColor(OneConfigConfig.GRAY_300), hover, 50f);
case 3:
- return getColorComponents(color, splitColor(OneConfigConfig.GRAY_500), splitColor(OneConfigConfig.GRAY_300), hover, 25f);
+ return getColorComponents(color, splitColor(OneConfigConfig.GRAY_500), splitColor(OneConfigConfig.GRAY_300), hover, 150f);
}
}
@@ -52,7 +52,7 @@ public class ColorUtils {
float[] init = splitColor(initColor);
float[] finalC = splitColor(finalColor);
float[] current = splitColor(currentColor);
- return getColorComponents(current, init, finalC, direction, speed);
+ return getColorComponents(current, init, finalC, direction, speed + 100f);
}
private static float[] splitColor(int color) {
@@ -65,7 +65,10 @@ public class ColorUtils {
currentColor[2] = smooth(currentColor[2], initColor[2], finalColor[2], hover, speed);
currentColor[3] = smooth(currentColor[3], initColor[3], finalColor[3], hover, speed);
- return new Color(currentColor[0], currentColor[1], currentColor[2], currentColor[3]).getRGB();
+ return ((int) (currentColor[3] * 255) << 24) |
+ ((int) (currentColor[0] * 255) << 16) |
+ ((int) (currentColor[1] * 255) << 8) |
+ ((int) (currentColor[2] * 255));
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java b/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java
index 7263a19..73a8a13 100644
--- a/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java
+++ b/src/main/java/cc/polyfrost/oneconfig/utils/IOUtils.java
@@ -1,9 +1,11 @@
package cc.polyfrost.oneconfig.utils;
+import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URI;
import java.net.URL;
import java.nio.Buffer;
import java.nio.ByteBuffer;
@@ -52,4 +54,23 @@ public final class IOUtils {
}
}
+ public static void browseLink(String uri) {
+ try {
+ browseLink(new URI(uri));
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.err.println("Invalid URI: " + uri);
+ }
+ }
+ public static void browseLink(URI uri) {
+ if(Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
+ try {
+ Desktop.getDesktop().browse(uri);
+ } catch (IOException e) {
+ e.printStackTrace();
+ System.err.println("Failed to open URL in browser: " + uri);
+ }
+ }
+ }
+
}
\ No newline at end of file
--
cgit