aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/lwjgl
diff options
context:
space:
mode:
authornextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com>2022-05-22 14:57:45 +0100
committernextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com>2022-05-22 14:57:45 +0100
commitffcb16e4c7f0f4414c69541238178ce3a128bb74 (patch)
tree0806698ae4fecfba85146aa8e24f4cc0067ed4ef /src/main/java/cc/polyfrost/oneconfig/lwjgl
parent89af4c9fe007e0c4d8ed8edae541b9377e12d8d0 (diff)
downloadOneConfig-ffcb16e4c7f0f4414c69541238178ce3a128bb74.tar.gz
OneConfig-ffcb16e4c7f0f4414c69541238178ce3a128bb74.tar.bz2
OneConfig-ffcb16e4c7f0f4414c69541238178ce3a128bb74.zip
color selector and loads of stuffs
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/lwjgl')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java249
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java3
2 files changed, 2 insertions, 250 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java b/src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java
deleted file mode 100644
index 9c62d1a..0000000
--- a/src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java
+++ /dev/null
@@ -1,249 +0,0 @@
-package cc.polyfrost.oneconfig.lwjgl;
-
-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.
- * <p>
- * <code>
- * short[0] = hue (0-360)
- * short[1] = saturation (0-100)
- * short[2] = brightness (0-100)
- * short[3] = alpha (0-255)
- * </code>
- */
-@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);