aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/lwjgl
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/lwjgl')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/lwjgl/OneColor.java68
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/lwjgl/RenderManager.java46
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/lwjgl/image/Images.java1
3 files changed, 95 insertions, 20 deletions
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"),