From 3a1162cbcffd4147f3022b3241101e3269a54169 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 19 May 2010 12:21:54 +0100 Subject: [PATCH] animatable: Add custom properties to Animatable Like ClutterScriptable, it would be good to have the Animatable interface allow defining custom properties that can be animated. --- clutter/clutter-animatable.c | 63 ++++++++++++++++++++++++++++++++++++ clutter/clutter-animatable.h | 51 +++++++++++++++++++++-------- 2 files changed, 100 insertions(+), 14 deletions(-) diff --git a/clutter/clutter-animatable.c b/clutter/clutter-animatable.c index e448a694f..d0dde8a64 100644 --- a/clutter/clutter-animatable.c +++ b/clutter/clutter-animatable.c @@ -124,3 +124,66 @@ clutter_animatable_animate_property (ClutterAnimatable *animatable, return res; } + +GParamSpec * +clutter_animatable_find_property (ClutterAnimatable *animatable, + ClutterAnimation *animation, + const gchar *property_name) +{ + ClutterAnimatableIface *iface; + + g_return_val_if_fail (CLUTTER_IS_ANIMATABLE (animatable), NULL); + g_return_val_if_fail (CLUTTER_IS_ANIMATION (animation), NULL); + g_return_val_if_fail (property_name != NULL, NULL); + + CLUTTER_NOTE (ANIMATION, "Looking for property '%s'", property_name); + + iface = CLUTTER_ANIMATABLE_GET_IFACE (animatable); + if (iface->find_property != NULL) + return iface->find_property (animatable, animation, property_name); + + return g_object_class_find_property (G_OBJECT_GET_CLASS (animatable), + property_name); +} + +void +clutter_animatable_get_initial_state (ClutterAnimatable *animatable, + ClutterAnimation *animation, + const gchar *property_name, + GValue *value) +{ + ClutterAnimatableIface *iface; + + g_return_if_fail (CLUTTER_IS_ANIMATABLE (animatable)); + g_return_if_fail (CLUTTER_IS_ANIMATION (animation)); + g_return_if_fail (property_name != NULL); + + CLUTTER_NOTE (ANIMATION, "Getting initial state of '%s'", property_name); + + iface = CLUTTER_ANIMATABLE_GET_IFACE (animatable); + if (iface->get_initial_state != NULL) + iface->get_initial_state (animatable, animation, property_name, value); + else + g_object_get_property (G_OBJECT (animatable), property_name, value); +} + +void +clutter_animatable_set_final_state (ClutterAnimatable *animatable, + ClutterAnimation *animation, + const gchar *property_name, + const GValue *value) +{ + ClutterAnimatableIface *iface; + + g_return_if_fail (CLUTTER_IS_ANIMATABLE (animatable)); + g_return_if_fail (CLUTTER_IS_ANIMATION (animation)); + g_return_if_fail (property_name != NULL); + + CLUTTER_NOTE (ANIMATION, "Setting state of property '%s'", property_name); + + iface = CLUTTER_ANIMATABLE_GET_IFACE (animatable); + if (iface->set_final_state != NULL) + iface->set_final_state (animatable, animation, property_name, value); + else + g_object_set_property (G_OBJECT (animatable), property_name, value); +} diff --git a/clutter/clutter-animatable.h b/clutter/clutter-animatable.h index a82d13a4b..04df1dc45 100644 --- a/clutter/clutter-animatable.h +++ b/clutter/clutter-animatable.h @@ -65,24 +65,47 @@ struct _ClutterAnimatableIface GTypeInterface parent_iface; /*< public >*/ - gboolean (* animate_property) (ClutterAnimatable *animatable, - ClutterAnimation *animation, - const gchar *property_name, - const GValue *initial_value, - const GValue *final_value, - gdouble progress, - GValue *value); + gboolean (* animate_property) (ClutterAnimatable *animatable, + ClutterAnimation *animation, + const gchar *property_name, + const GValue *initial_value, + const GValue *final_value, + gdouble progress, + GValue *value); + GParamSpec *(* find_property) (ClutterAnimatable *animatable, + ClutterAnimation *animation, + const gchar *property_name); + void (* get_initial_state) (ClutterAnimatable *animatable, + ClutterAnimation *animation, + const gchar *property_name, + GValue *value); + void (* set_final_state) (ClutterAnimatable *animatable, + ClutterAnimation *animation, + const gchar *property_name, + const GValue *value); }; GType clutter_animatable_get_type (void) G_GNUC_CONST; -gboolean clutter_animatable_animate_property (ClutterAnimatable *animatable, - ClutterAnimation *animation, - const gchar *property_name, - const GValue *initial_value, - const GValue *final_value, - gdouble progress, - GValue *value); +gboolean clutter_animatable_animate_property (ClutterAnimatable *animatable, + ClutterAnimation *animation, + const gchar *property_name, + const GValue *initial_value, + const GValue *final_value, + gdouble progress, + GValue *value); + +GParamSpec *clutter_animatable_find_property (ClutterAnimatable *animatable, + ClutterAnimation *animation, + const gchar *property_name); +void clutter_animatable_get_initial_state (ClutterAnimatable *animatable, + ClutterAnimation *animation, + const gchar *property_name, + GValue *initial); +void clutter_animatable_set_final_state (ClutterAnimatable *animatable, + ClutterAnimation *animation, + const gchar *property_name, + const GValue *final); G_END_DECLS