From 854cf5d49916c8b4eb7218c340db2f95dca81d24 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Tue, 6 Jan 2009 12:53:30 +0000 Subject: [PATCH] Animate ClutterColor properties We can animate a ClutterColor-based property between an interval of two colors by simply applying the factor to each color component. --- clutter/clutter-interval.c | 21 ++++++++++++++++++++- tests/interactive/test-animation.c | 17 ++++++++++++----- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/clutter/clutter-interval.c b/clutter/clutter-interval.c index 5f2924d09..a3be68c71 100644 --- a/clutter/clutter-interval.c +++ b/clutter/clutter-interval.c @@ -57,9 +57,10 @@ #include #include +#include "clutter-color.h" +#include "clutter-fixed.h" #include "clutter-interval.h" #include "clutter-units.h" -#include "clutter-fixed.h" enum { @@ -249,6 +250,24 @@ clutter_interval_real_compute_value (ClutterInterval *interval, g_value_set_boolean (value, FALSE); break; + case G_TYPE_BOXED: + if (value_type == CLUTTER_TYPE_COLOR) + { + const ClutterColor *ia, *ib; + ClutterColor res = { 0, }; + + ia = clutter_value_get_color (initial); + ib = clutter_value_get_color (final); + + res.red = (factor * (ib->red - (gdouble) ia->red)) + ia->red; + res.green = (factor * (ib->green - (gdouble) ia->green)) + ia->green; + res.blue = (factor * (ib->blue - (gdouble) ia->blue)) + ia->blue; + res.alpha = (factor * (ib->alpha - (gdouble) ia->alpha)) + ia->alpha; + + clutter_value_set_color (value, &res); + } + break; + default: break; } diff --git a/tests/interactive/test-animation.c b/tests/interactive/test-animation.c index 000e02bd8..ee0ff7337 100644 --- a/tests/interactive/test-animation.c +++ b/tests/interactive/test-animation.c @@ -23,13 +23,12 @@ on_button_press (ClutterActor *actor, ClutterAnimation *animation; gint old_x, old_y, new_x, new_y; guint old_width, old_height, new_width, new_height; - guint8 old_op, new_op; gdouble new_angle; ClutterVertex vertex = { 0, }; + ClutterColor new_color = { 0, }; clutter_actor_get_position (actor, &old_x, &old_y); clutter_actor_get_size (actor, &old_width, &old_height); - old_op = clutter_actor_get_opacity (actor); /* determine the final state of the animation depending on * the state of the actor @@ -40,8 +39,12 @@ on_button_press (ClutterActor *actor, new_y = old_y - 100; new_width = old_width + 200; new_height = old_height + 200; - new_op = 255; new_angle = 360.0; + + new_color.red = 0xdd; + new_color.green = 0x44; + new_color.blue = 0xdd; + new_color.alpha = 0xff; } else { @@ -49,8 +52,12 @@ on_button_press (ClutterActor *actor, new_y = old_y + 100; new_width = old_width - 200; new_height = old_height - 200; - new_op = 128; new_angle = 0.0; + + new_color.red = 0x44; + new_color.green = 0xdd; + new_color.blue = 0x44; + new_color.alpha = 0x88; } vertex.x = CLUTTER_UNITS_FROM_FLOAT ((float) new_width / 2); @@ -62,7 +69,7 @@ on_button_press (ClutterActor *actor, "y", new_y, "width", new_width, "height", new_height, - "opacity", new_op, + "color", &new_color, "rotation-angle-z", new_angle, "fixed::rotation-center-z", &vertex, "fixed::reactive", FALSE,