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.
This commit is contained in:
Emmanuele Bassi 2009-01-06 12:53:30 +00:00
parent ff73fe3e1f
commit 854cf5d499
2 changed files with 32 additions and 6 deletions

View File

@ -57,9 +57,10 @@
#include <glib-object.h> #include <glib-object.h>
#include <gobject/gvaluecollector.h> #include <gobject/gvaluecollector.h>
#include "clutter-color.h"
#include "clutter-fixed.h"
#include "clutter-interval.h" #include "clutter-interval.h"
#include "clutter-units.h" #include "clutter-units.h"
#include "clutter-fixed.h"
enum enum
{ {
@ -249,6 +250,24 @@ clutter_interval_real_compute_value (ClutterInterval *interval,
g_value_set_boolean (value, FALSE); g_value_set_boolean (value, FALSE);
break; 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: default:
break; break;
} }

View File

@ -23,13 +23,12 @@ on_button_press (ClutterActor *actor,
ClutterAnimation *animation; ClutterAnimation *animation;
gint old_x, old_y, new_x, new_y; gint old_x, old_y, new_x, new_y;
guint old_width, old_height, new_width, new_height; guint old_width, old_height, new_width, new_height;
guint8 old_op, new_op;
gdouble new_angle; gdouble new_angle;
ClutterVertex vertex = { 0, }; ClutterVertex vertex = { 0, };
ClutterColor new_color = { 0, };
clutter_actor_get_position (actor, &old_x, &old_y); clutter_actor_get_position (actor, &old_x, &old_y);
clutter_actor_get_size (actor, &old_width, &old_height); 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 /* determine the final state of the animation depending on
* the state of the actor * the state of the actor
@ -40,8 +39,12 @@ on_button_press (ClutterActor *actor,
new_y = old_y - 100; new_y = old_y - 100;
new_width = old_width + 200; new_width = old_width + 200;
new_height = old_height + 200; new_height = old_height + 200;
new_op = 255;
new_angle = 360.0; new_angle = 360.0;
new_color.red = 0xdd;
new_color.green = 0x44;
new_color.blue = 0xdd;
new_color.alpha = 0xff;
} }
else else
{ {
@ -49,8 +52,12 @@ on_button_press (ClutterActor *actor,
new_y = old_y + 100; new_y = old_y + 100;
new_width = old_width - 200; new_width = old_width - 200;
new_height = old_height - 200; new_height = old_height - 200;
new_op = 128;
new_angle = 0.0; 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); vertex.x = CLUTTER_UNITS_FROM_FLOAT ((float) new_width / 2);
@ -62,7 +69,7 @@ on_button_press (ClutterActor *actor,
"y", new_y, "y", new_y,
"width", new_width, "width", new_width,
"height", new_height, "height", new_height,
"opacity", new_op, "color", &new_color,
"rotation-angle-z", new_angle, "rotation-angle-z", new_angle,
"fixed::rotation-center-z", &vertex, "fixed::rotation-center-z", &vertex,
"fixed::reactive", FALSE, "fixed::reactive", FALSE,