From a68e15e27404629ce8301332416a0a74d13574de Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Tue, 20 Nov 2018 20:30:48 +0100 Subject: [PATCH] tween: add ability to store a custom tweening function with the Tween object --- src/tween.c | 6 ++++++ src/tween.h | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/tween.c b/src/tween.c index c0b490e..241680b 100644 --- a/src/tween.c +++ b/src/tween.c @@ -256,6 +256,7 @@ SYMBOL_EXPORT struct Tween Tween(struct Game* game, double start, double stop, T .predelay = 0, .postdelay = 0, .callback = NULL, + .func = NULL, .data = NULL}; } @@ -340,11 +341,16 @@ SYMBOL_EXPORT double Interpolate(double pos, TWEEN_STYLE style) { return BounceEaseOut(pos); case TWEEN_STYLE_BOUNCE_IN_OUT: return BounceEaseInOut(pos); + default: + return pos; } return pos; } SYMBOL_EXPORT double GetTweenInterpolation(struct Tween* tween) { + if (tween->style == TWEEN_STYLE_CUSTOM && tween->func) { + return tween->func(GetTweenPosition(tween)); + } return Interpolate(GetTweenPosition(tween), tween->style); } diff --git a/src/tween.h b/src/tween.h index 83d2224..d0a85aa 100644 --- a/src/tween.h +++ b/src/tween.h @@ -65,7 +65,9 @@ typedef enum TWEEN_STYLE { // Exponentially-decaying bounce easing TWEEN_STYLE_BOUNCE_IN, TWEEN_STYLE_BOUNCE_OUT, - TWEEN_STYLE_BOUNCE_IN_OUT + TWEEN_STYLE_BOUNCE_IN_OUT, + // Custom callback + TWEEN_STYLE_CUSTOM } TWEEN_STYLE; // Cheet sheet at http://easings.net/ :) struct Tween { @@ -76,6 +78,7 @@ struct Tween { bool paused; bool done; struct Game* game; + double (*func)(double value); void (*callback)(struct Game* game, struct Tween* tween, void* data); void* data; };