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-01 20:06:36 +0200
committerDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-06-01 20:06:36 +0200
commitef98c272d57161ea1de222fe4ee04ee701877b4f (patch)
tree368d63b62b0cd04b179350d7477eacedf19917be /src/main/java/cc/polyfrost/oneconfig/gui/animations
parent18ddce4242a5a68bef111f9bce43b6c3f3a45ce6 (diff)
downloadOneConfig-ef98c272d57161ea1de222fe4ee04ee701877b4f.tar.gz
OneConfig-ef98c272d57161ea1de222fe4ee04ee701877b4f.tar.bz2
OneConfig-ef98c272d57161ea1de222fe4ee04ee701877b4f.zip
sidebar and animation stuff
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui/animations')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java16
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuad.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuart.java2
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInQuartReversed.java20
4 files changed, 29 insertions, 11 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java
index 834aeb1..d8d672d 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java
@@ -3,10 +3,10 @@ package cc.polyfrost.oneconfig.gui.animations;
import cc.polyfrost.oneconfig.gui.OneConfigGui;
public abstract class Animation {
- private final int duration;
+ private final float duration;
private final float start;
private final float change;
- private long timePassed = 0;
+ private float timePassed = 0;
/**
* @param duration The duration of the animation
@@ -14,7 +14,7 @@ public abstract class Animation {
* @param end The end of the animation
* @param reverse Reverse the animation
*/
- public Animation(int duration, float start, float end, boolean reverse) {
+ public Animation(float duration, float start, float end, boolean reverse) {
this.duration = duration;
this.start = start;
if (!reverse) this.change = end - start;
@@ -25,12 +25,10 @@ public abstract class Animation {
* @param deltaTime The time since the last frame
* @return The new value
*/
- public float get(long deltaTime) {
+ public float get(float deltaTime) {
timePassed += deltaTime;
- if (timePassed >= duration) return start + change;
- float value = animate(timePassed, duration, start, change);
- System.out.println(value);
- return value;
+ if (timePassed >= duration) timePassed = duration;
+ return animate(timePassed, duration, start, change);
}
/**
@@ -47,5 +45,5 @@ public abstract class Animation {
return timePassed >= duration;
}
- protected abstract float animate(long timePassed, int duration, float start, float change);
+ protected abstract float animate(float timePassed, float duration, float start, float change);
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuad.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuad.java
index 14e802f..9af6557 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuad.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuad.java
@@ -16,7 +16,7 @@ public class EaseInOutQuad extends Animation{
* Adapted from <a href="https://github.com/jesusgollonet/processing-penner-easing">https://github.com/jesusgollonet/processing-penner-easing</a>
*/
@Override
- protected float animate(long timePassed, int duration, float start, float change) {
+ protected float animate(float timePassed, float duration, float start, float change) {
if ((timePassed /= duration / 2) < 1) return change / 2 * timePassed * timePassed + start;;
return -change / 2 * ((--timePassed) * (timePassed - 2) - 1) + start;
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuart.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuart.java
index 55c1cad..a21aa73 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuart.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInOutQuart.java
@@ -16,7 +16,7 @@ public class EaseInOutQuart extends Animation{
* Adapted from <a href="https://github.com/jesusgollonet/processing-penner-easing">https://github.com/jesusgollonet/processing-penner-easing</a>
*/
@Override
- protected float animate(long timePassed, int duration, float start, float change) {
+ protected float animate(float timePassed, float duration, float start, float change) {
if ((timePassed /= duration / 2) < 1) return change / 2 * timePassed * timePassed * timePassed * timePassed + start;
return -change / 2 * ((timePassed -= 2) * timePassed * timePassed * timePassed - 2) + start;
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInQuartReversed.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInQuartReversed.java
new file mode 100644
index 0000000..9e77714
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseInQuartReversed.java
@@ -0,0 +1,20 @@
+package cc.polyfrost.oneconfig.gui.animations;
+
+public class EaseInQuartReversed extends Animation {
+ /**
+ * @param duration The duration of the animation
+ * @param start The start of the animation
+ * @param end The end of the animation
+ * @param reverse Reverse the animation
+ */
+ public EaseInQuartReversed(float duration, float start, float end, boolean reverse) {
+ super(duration, start, end, reverse);
+ }
+
+ @Override
+ protected float animate(float timePassed, float duration, float start, float change) {
+ float x = timePassed / duration;
+ if (x < 0.5f) return (float) (16 * Math.pow(x, 4) * change + start);
+ return (float) (Math.pow(2 * x - 2, 4) * change + start);
+ }
+}