aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/gui/animations
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-06-03 18:13:50 +0200
committerDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-06-03 18:13:50 +0200
commit91da97c6843b76829a6b8cf1321f3d38f4e8893b (patch)
treedc7b3dda3ee8ef5ebb88d13c3511b51b7668e002 /src/main/java/cc/polyfrost/oneconfig/gui/animations
parent5771df1bb5d2bb18507badd68ed3e0718cbb9abc (diff)
downloadOneConfig-91da97c6843b76829a6b8cf1321f3d38f4e8893b.tar.gz
OneConfig-91da97c6843b76829a6b8cf1321f3d38f4e8893b.tar.bz2
OneConfig-91da97c6843b76829a6b8cf1321f3d38f4e8893b.zip
color anims start
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui/animations')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/animations/ColorAnimation.java49
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java2
2 files changed, 50 insertions, 1 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/ColorAnimation.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/ColorAnimation.java
new file mode 100644
index 0000000..420f1d0
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/ColorAnimation.java
@@ -0,0 +1,49 @@
+package cc.polyfrost.oneconfig.gui.animations;
+
+import cc.polyfrost.oneconfig.utils.color.ColorPalette;
+
+public class ColorAnimation {
+ private ColorPalette palette;
+ /**
+ * 0 = nothing
+ * 1 = hovered
+ * 2 = pressed
+ * 3 = color palette changed
+ */
+ private int prevState = 0;
+ private Animation redAnimation;
+ private Animation greenAnimation;
+ private Animation blueAnimation;
+ private Animation alphaAnimation;
+
+ public ColorAnimation(ColorPalette palette) {
+ this.palette = palette;
+ redAnimation = new DummyAnimation(palette.getNormalColorf()[0]);
+ greenAnimation = new DummyAnimation(palette.getNormalColorf()[1]);
+ blueAnimation = new DummyAnimation(palette.getNormalColorf()[2]);
+ alphaAnimation = new DummyAnimation(palette.getNormalColorf()[3]);
+ }
+
+ public int getColor(boolean hovered, boolean pressed) {
+ int state = pressed ? 2 : hovered ? 1 : 0;
+ if (state != prevState) {
+ float[] newColors = pressed ? palette.getPressedColorf() : hovered ? palette.getHoveredColorf() : palette.getNormalColorf();
+ redAnimation = new EaseInOutQuad(100, redAnimation.get(), newColors[0], false);
+ greenAnimation = new EaseInOutQuad(100, greenAnimation.get(), newColors[1], false);
+ blueAnimation = new EaseInOutQuad(100, blueAnimation.get(), newColors[2], false);
+ alphaAnimation = new EaseInOutQuad(100, alphaAnimation.get(), newColors[3], false);
+ prevState = state;
+ return ((int) (alphaAnimation.get(0) * 255) << 24) | ((int) (redAnimation.get(0) * 255) << 16) | ((int) (greenAnimation.get(0) * 255) << 8) | ((int) (blueAnimation.get(0) * 255));
+ }
+ return ((int) (alphaAnimation.get() * 255) << 24) | ((int) (redAnimation.get() * 255) << 16) | ((int) (greenAnimation.get() * 255) << 8) | ((int) (blueAnimation.get() * 255));
+ }
+
+ public ColorPalette getPalette() {
+ return palette;
+ }
+
+ public void setPalette(ColorPalette palette) {
+ this.palette = palette;
+ prevState = 3;
+ }
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java
index 6343123..bc97aca 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java
@@ -10,6 +10,6 @@ public class DummyAnimation extends Animation{
@Override
protected float animate(float timePassed, float duration, float start, float change) {
- return change;
+ return start;
}
}