From 30df910cf3b2f5b0683ce01e391c35829d8a5850 Mon Sep 17 00:00:00 2001 From: nextdaydelivery <79922345+nxtdaydelivery@users.noreply.github.com> Date: Wed, 20 Apr 2022 13:46:50 +0100 Subject: hella gui stuff --- .../io/polyfrost/oneconfig/utils/ColorUtils.java | 58 ++++++++++++++++++++++ .../io/polyfrost/oneconfig/utils/MathUtils.java | 4 +- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java (limited to 'src/main/java/io/polyfrost/oneconfig/utils') diff --git a/src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java b/src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java new file mode 100644 index 0000000..f45f9a5 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java @@ -0,0 +1,58 @@ +package io.polyfrost.oneconfig.utils; + +import io.polyfrost.oneconfig.config.OneConfigConfig; + +import java.awt.*; + +public class ColorUtils { + + public static int getColor(int currentColor, int colorPalette, boolean hover, boolean click) { + float[] color = splitColor(currentColor); + if(click) { + switch (colorPalette) { + case -1: + return OneConfigConfig.GRAY_500_80; + default: + case 0: + return OneConfigConfig.GRAY_400_80; + } + } + + switch (colorPalette) { + case -1: + return getColorComponents(color, splitColor(OneConfigConfig.TRANSPARENT), splitColor(OneConfigConfig.GRAY_500), hover); + default: + case 0: + return getColorComponents(color, splitColor(OneConfigConfig.GRAY_500), splitColor(OneConfigConfig.GRAY_400), hover); // OK hopefully this works + + } + + } + + private static float[] splitColor(int color) { + Color c = new Color(color, true); + return new float[] {c.getRed() / 255f, c.getGreen() / 255f, c.getBlue() / 255f, c.getAlpha() / 255f}; + } + + private static int getColorComponents(float[] currentColor, float[] initColor, float[] finalColor, boolean hover) { + currentColor[0] = smooth(currentColor[0], initColor[0], finalColor[0], hover); + currentColor[1] = smooth(currentColor[1], initColor[1], finalColor[1], hover); + currentColor[2] = smooth(currentColor[2], initColor[2], finalColor[2], hover); + currentColor[3] = smooth(currentColor[3], initColor[3], finalColor[3], hover); + + return new Color(currentColor[0], currentColor[1], currentColor[2], currentColor[3]).getRGB(); + + } + + private static float smooth(float current, float min, float max, boolean moveToFinal) { + current = MathUtils.easeOut(current, moveToFinal ? 1f : 0f); + if(current <= min) { + current = min; + } + + if(current >= max) { + current = max; + } + return current; + } +} diff --git a/src/main/java/io/polyfrost/oneconfig/utils/MathUtils.java b/src/main/java/io/polyfrost/oneconfig/utils/MathUtils.java index e2e5184..7d64170 100644 --- a/src/main/java/io/polyfrost/oneconfig/utils/MathUtils.java +++ b/src/main/java/io/polyfrost/oneconfig/utils/MathUtils.java @@ -7,9 +7,11 @@ public class MathUtils { public static float easeOut(float current, float goal) { if (Math.floor(Math.abs(goal - current) / (float) 0.01) > 0) { - return current + (goal - current) / (float) 20.0; + return current + (goal - current) / (float) 100.0; // this number here controls the speed uh oh } else { return goal; } } + + } -- cgit