aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/polyfrost/oneconfig/utils
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-04-24 14:46:10 +0200
committerDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-04-24 14:46:10 +0200
commit087267b1e9a0562ca80604d583fc6c0790e0f733 (patch)
tree53019267804181b9e8ff42d90783d04c3119efa5 /src/main/java/io/polyfrost/oneconfig/utils
parent9a3d070d80d569bea3f1b6b162bb061a7d9446db (diff)
parent5417c7bd2d43c306863707bb91e7c88a651a696b (diff)
downloadOneConfig-087267b1e9a0562ca80604d583fc6c0790e0f733.tar.gz
OneConfig-087267b1e9a0562ca80604d583fc6c0790e0f733.tar.bz2
OneConfig-087267b1e9a0562ca80604d583fc6c0790e0f733.zip
Merge branch 'master' of github.com:Polyfrost/OneConfig
merge or smthing
Diffstat (limited to 'src/main/java/io/polyfrost/oneconfig/utils')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java25
-rw-r--r--src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java16
2 files changed, 39 insertions, 2 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java b/src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java
index b8d56bd..dd9a78e 100644
--- a/src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java
+++ b/src/main/java/io/polyfrost/oneconfig/utils/ColorUtils.java
@@ -1,6 +1,8 @@
package io.polyfrost.oneconfig.utils;
import io.polyfrost.oneconfig.config.OneConfigConfig;
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.annotations.NotNull;
import java.awt.*;
@@ -10,6 +12,8 @@ public class ColorUtils {
float[] color = splitColor(currentColor);
if(click) {
switch (colorPalette) {
+ case -2:
+ return new Color(0.9f,0.9f,0.9f,0.2f).getRGB();
case -1:
return OneConfigConfig.GRAY_500_80;
default:
@@ -21,11 +25,13 @@ 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);
case -1:
return getColorComponents(color, splitColor(OneConfigConfig.TRANSPARENT), splitColor(OneConfigConfig.GRAY_500), hover, 10f);
default:
case 0:
- return getColorComponents(color, splitColor(OneConfigConfig.GRAY_500), splitColor(OneConfigConfig.GRAY_400), hover, 130f);
+ return getColorComponents(color, splitColor(OneConfigConfig.GRAY_600), splitColor(OneConfigConfig.GRAY_300), hover, 25f);
case 1:
return getColorComponents(color, splitColor(OneConfigConfig.BLUE_600), splitColor(OneConfigConfig.BLUE_500), hover, 150f);
@@ -33,7 +39,22 @@ public class ColorUtils {
}
- private static float[] splitColor(int color) {
+ /**
+ * Smooths the transition of a color between two colors.
+ * @param currentColor the current color (also the one you want to change)
+ * @param direction false to move towards initColor, true to move towards finalColor
+ * @param speed speed of the transition
+ * @return currentColor but with the new color
+ */
+ public static int smoothColor(int currentColor, int initColor, int finalColor, boolean direction, float speed) {
+ float[] init = splitColor(initColor);
+ float[] finalC = splitColor(finalColor);
+ float[] current = splitColor(currentColor);
+ return getColorComponents(current, init, finalC, direction, speed);
+ }
+
+ @Contract(value = "_ -> new", pure = true)
+ private static float @NotNull [] splitColor(int color) {
return new float[] { (color >> 16 & 255) / 255f, (color >> 8 & 255) / 255f, (color & 255) / 255f, (color >> 24 & 255) /255f };
}
diff --git a/src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java b/src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java
new file mode 100644
index 0000000..d5ad44b
--- /dev/null
+++ b/src/main/java/io/polyfrost/oneconfig/utils/InputUtils.java
@@ -0,0 +1,16 @@
+package io.polyfrost.oneconfig.utils;
+
+import net.minecraft.client.Minecraft;
+import org.lwjgl.input.Mouse;
+
+public class InputUtils {
+ /**
+ * function to determine weather the mouse is currently over a specific region. Uses the current nvgScale to fix to any scale.
+ * @return true if mouse is over region, false if not.
+ */
+ public static boolean isAreaHovered(int x, int y, int width, int height) {
+ int mouseX = Mouse.getX();
+ int mouseY = Minecraft.getMinecraft().displayHeight - Math.abs(Mouse.getY());
+ return mouseX > x && mouseY > y && mouseX < x + width && mouseY < y + height; // TODO add scaling info
+ }
+}