diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-06-02 19:14:51 +0200 |
---|---|---|
committer | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-06-02 19:14:51 +0200 |
commit | 0ad0457dc608ade2cd8ff7e325c009c2847fb711 (patch) | |
tree | a8761d2aef3684de9c10c5345f7e11a3cde245da /src/main/java/cc/polyfrost/oneconfig/gui/animations | |
parent | 4945b1bf585a0a53917917b29f3450002d4e3553 (diff) | |
download | OneConfig-0ad0457dc608ade2cd8ff7e325c009c2847fb711.tar.gz OneConfig-0ad0457dc608ade2cd8ff7e325c009c2847fb711.tar.bz2 OneConfig-0ad0457dc608ade2cd8ff7e325c009c2847fb711.zip |
animations
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/gui/animations')
3 files changed, 46 insertions, 0 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 ebb9145..9e2c238 100644 --- a/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/Animation.java @@ -7,6 +7,7 @@ public abstract class Animation { private final float start; private final float change; private float timePassed = 0; + protected final boolean reverse; /** * @param duration The duration of the animation @@ -23,6 +24,7 @@ public abstract class Animation { } this.start = start; this.change = end - start; + this.reverse = reverse; } /** @@ -49,5 +51,12 @@ public abstract class Animation { return timePassed >= duration; } + /** + * @return If the animation is reversed + */ + public boolean isReversed() { + return reverse; + } + protected abstract float animate(float timePassed, float duration, float start, float change); } diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java new file mode 100644 index 0000000..6343123 --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/DummyAnimation.java @@ -0,0 +1,15 @@ +package cc.polyfrost.oneconfig.gui.animations; + +public class DummyAnimation extends Animation{ + /** + * @param value The value that is returned + */ + public DummyAnimation(float value) { + super(value, value, value, false); + } + + @Override + protected float animate(float timePassed, float duration, float start, float change) { + return change; + } +} diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseOutQuad.java b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseOutQuad.java new file mode 100644 index 0000000..6cc97bf --- /dev/null +++ b/src/main/java/cc/polyfrost/oneconfig/gui/animations/EaseOutQuad.java @@ -0,0 +1,22 @@ +package cc.polyfrost.oneconfig.gui.animations; + +public class EaseOutQuad 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 EaseOutQuad(int duration, float start, float end, boolean reverse) { + super(duration, start, end, reverse); + } + + /** + * Adapted from <a href="https://github.com/jesusgollonet/processing-penner-easing">https://github.com/jesusgollonet/processing-penner-easing</a> + */ + @Override + protected float animate(float timePassed, float duration, float start, float change) { + return -change * (timePassed /= duration) * (timePassed - 2) + start; + } +} |