From ee9f8c3bdf9672e0d79598eed8f73569190888dc Mon Sep 17 00:00:00 2001 From: Damien Lespiau Date: Mon, 12 Oct 2009 16:28:10 +0100 Subject: [PATCH] Add ClutterInterval integration To be able to animate CLUTTER_TYPE_UNITS properties we need to register the GType and its progress function against the ClutterInterval code. The two ClutterUnits defining the interval can use different units, the resulting unit will always be in pixels, so calculating a progress between 10px and 4cm is valid. http://bugzilla.openedhand.com/show_bug.cgi?id=1844 --- clutter/clutter-units.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/clutter/clutter-units.c b/clutter/clutter-units.c index 4831fd17d..1a314f3ab 100644 --- a/clutter/clutter-units.c +++ b/clutter/clutter-units.c @@ -71,6 +71,7 @@ #include "clutter-units.h" #include "clutter-private.h" +#include "clutter-interval.h" #define DPI_FALLBACK (96.0) @@ -646,6 +647,31 @@ clutter_units_to_string (const ClutterUnits *units) return g_strconcat (buf, " ", unit_name, NULL); } +/* + * ClutterInterval integration + */ + +static gboolean +clutter_units_progress (const GValue *a, + const GValue *b, + gdouble progress, + GValue *retval) +{ + ClutterUnits *a_units = (ClutterUnits *) clutter_value_get_units (a); + ClutterUnits *b_units = (ClutterUnits *) clutter_value_get_units (b); + ClutterUnits res; + gfloat a_px, b_px, value; + + a_px = clutter_units_to_pixels (a_units); + b_px = clutter_units_to_pixels (b_units); + value = progress * (b_px - a_px) + a_px; + + clutter_units_from_pixels (&res, value); + clutter_value_set_units (retval, &res); + + return TRUE; +} + /* * GValue and GParamSpec integration */ @@ -731,6 +757,9 @@ clutter_units_get_type (void) g_value_register_transform_func (G_TYPE_STRING, clutter_units_type, clutter_value_transform_string_units); + clutter_interval_register_progress_func (clutter_units_type, + clutter_units_progress); + g_once_init_leave (&clutter_units_type__volatile, clutter_units_type); }