From ae59c294bfd4b73f6e751a3103c2ee7501068492 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Fri, 20 Sep 2024 23:57:19 +0200 Subject: Start parsing effects --- src/effect.c | 90 +++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 49 insertions(+), 41 deletions(-) (limited to 'src/effect.c') diff --git a/src/effect.c b/src/effect.c index 705c42d..9266979 100644 --- a/src/effect.c +++ b/src/effect.c @@ -1,53 +1,61 @@ -#include +#include #include "layout.h" #include "effect.h" #include "any_log.h" -double cubic_bezier(double x, double a, double b, double c, double d) -{ - const double t = 1 - x; - return a * (t * t * t) + 3 * b * (t * t * x) + 3 * c * (t * x * x) + d * (x * x * x); -} - -static void effect_pulse_pre(effect_t *effect, layout_t *layout, cairo_t *cr) -{ - struct timespec now; - timespec_get(&now, TIME_UTC); - - // After half the duration we invert direction - struct timespec midpoint = timespec_div(effect->duration, 2); - struct timespec diff = timespec_diff(now, effect->start); - - double t = timespec_greater(midpoint, diff) - ? (double)timespec_to_ms(diff) / timespec_to_ms(midpoint) - : 1.0 - (double)timespec_to_ms(timespec_diff(diff, midpoint)) / timespec_to_ms(midpoint); - - // Make it customizable - double s = cubic_bezier(t, 0.19, 1.0, 0.22, 1.0); - - // Make it a parameter - const double amplitude = 0.12; - - // FIXME: The intent was to scale the animation for long blocks, but it needs more love - // - int x_max = amplitude * (layout->height + (layout->width / (double)layout->height) - 1); - int y_max = amplitude * layout->height; - - layout->x_padding = layout->block->x_padding + x_max * s; - layout->y_padding = layout->block->y_padding + y_max * s; -} -effect_t *effect_pulse(struct timespec duration) +//double cubic_bezier(double x, double a, double b, double c, double d) +//{ +// const double t = 1 - x; +// return a * (t * t * t) + 3 * b * (t * t * x) + 3 * c * (t * x * x) + d * (x * x * x); +//} +// +//static void effect_pulse_pre(effect_t *effect, layout_t *layout, cairo_t *cr) +//{ +// struct timespec now; +// timespec_get(&now, TIME_UTC); +// +// // After half the duration we invert direction +// struct timespec midpoint = timespec_div(effect->duration, 2); +// struct timespec diff = timespec_diff(now, effect->start); +// +// double t = timespec_greater(midpoint, diff) +// ? (double)timespec_to_ms(diff) / timespec_to_ms(midpoint) +// : 1.0 - (double)timespec_to_ms(timespec_diff(diff, midpoint)) / timespec_to_ms(midpoint); +// +// // Make it customizable +// double s = cubic_bezier(t, 0.19, 1.0, 0.22, 1.0); +// +// // Make it a parameter +// const double amplitude = 0.12; +// +// // FIXME: The intent was to scale the animation for long blocks, but it needs more love +// // +// int x_max = amplitude * (layout->height + (layout->width / (double)layout->height) - 1); +// int y_max = amplitude * layout->height; +// +// layout->x_padding = layout->block->x_padding + x_max * s; +// layout->y_padding = layout->block->y_padding + y_max * s; +//} +// +//effect_t *effect_pulse(struct timespec duration) +//{ +// effect_t *effect = calloc(1, sizeof(effect_t)); +// effect->type = EFFECT_PULSE; +// effect->duration = duration; +// effect->pre = effect_pulse_pre; +// return effect; +//} + +void effect_info_free(effect_info_t *info) { - effect_t *effect = calloc(1, sizeof(effect_t)); - effect->type = EFFECT_PULSE; - effect->duration = duration; - effect->pre = effect_pulse_pre; - return effect; + free(info->state); + free(info); } void effect_free(effect_t *effect) { - free(effect); + assert(effect->info->finalize != NULL); + effect->info->finalize(effect); } -- cgit v1.2.3