From 24808e20b3c190ef79a88f958e4ff2617b7c155f Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 8 Jan 2009 12:56:46 +0000 Subject: [PATCH 1/4] [animation] Add ClutterAnimatable The ClutterAnimatable interface is meant to be used by GObject classes to override the value computation for an animatable property within the boundaries of an interval. It is composed of a single virtual function, animate_property(); its implementation will receive the ClutterAnimation used to animate the object; the property name; the initial and final interval values; and the progress factor as retrieved by the Alpha object bound to the Animation instance. --- clutter/Makefile.am | 2 + clutter/clutter-animatable.c | 93 ++++++++++++++++++++++++++++++++++++ clutter/clutter-animatable.h | 56 ++++++++++++++++++++++ clutter/clutter.h | 1 + 4 files changed, 152 insertions(+) create mode 100644 clutter/clutter-animatable.c create mode 100644 clutter/clutter-animatable.h diff --git a/clutter/Makefile.am b/clutter/Makefile.am index 4db7c9fe2..ca54bfae2 100644 --- a/clutter/Makefile.am +++ b/clutter/Makefile.am @@ -47,6 +47,7 @@ BUILT_SOURCES = $(MARSHALFILES) $(ENUMFILES) source_h = \ $(srcdir)/clutter-actor.h \ $(srcdir)/clutter-alpha.h \ + $(srcdir)/clutter-animatable.h \ $(srcdir)/clutter-animation.h \ $(srcdir)/clutter-backend.h \ $(srcdir)/clutter-behaviour.h \ @@ -138,6 +139,7 @@ CLEANFILES = $(STAMPFILES) source_c = \ clutter-actor.c \ clutter-alpha.c \ + clutter-animatable.c \ clutter-animation.c \ clutter-backend.c \ clutter-behaviour.c \ diff --git a/clutter/clutter-animatable.c b/clutter/clutter-animatable.c new file mode 100644 index 000000000..e7876e2a6 --- /dev/null +++ b/clutter/clutter-animatable.c @@ -0,0 +1,93 @@ +/** + * SECTION:clutter-animatable + * @short_description: Interface for animatable classes + * + * #ClutterAnimatable is an interface that allows a #GObject class + * to control how a #ClutterAnimation will animate a property. + * + * Each #ClutterAnimatable should implement the animate_property() + * virtual function of the interface to compute the animation state + * between two values of an interval depending on a progress factor, + * expressed as a floating point value. + * + * If a #ClutterAnimatable is animated by a #ClutterAnimation + * instance, the #ClutterAnimation will call + * clutter_animatable_animate_property() passing the name of the + * currently animated property; the initial and final values of + * the animation interval; the progress factor. The #ClutterAnimatable + * implementation should return the computed value for the animated + * property. + * + * #ClutterAnimatable is available since Clutter 1.0 + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "clutter-animatable.h" +#include "clutter-debug.h" +#include "clutter-private.h" + +GType +clutter_animatable_get_type (void) +{ + static GType a_type = 0; + + if (G_UNLIKELY (a_type == 0)) + a_type = g_type_register_static_simple (G_TYPE_INTERFACE, + I_("ClutterAnimatable"), + sizeof (ClutterAnimatableIface), + NULL, 0, NULL, 0); + + return a_type; +} + +/** + * clutter_animatable_animate_property: + * @animatable: a #ClutterAnimatable + * @animation: a #ClutterAnimation + * @property_name: the name of the animated property + * @initial_value: the initial value of the animation interval + * @final_value: the final value of the animation interval + * @progress: the progress factor + * @value: return location for the animation value + * + * Calls the animate_property() virtual function for @animatable. + * + * The @initial_value and @final_value #GValues must contain + * the same type; @value must have been initialized to the same + * type of @initial_value and @final_value. + * + * All implementation of the #ClutterAnimatable interface must + * implement this function. + * + * Since: 1.0 + */ +void +clutter_animatable_animate_property (ClutterAnimatable *animatable, + ClutterAnimation *animation, + const gchar *property_name, + const GValue *initial_value, + const GValue *final_value, + gdouble progress, + GValue *value) +{ + g_return_if_fail (CLUTTER_IS_ANIMATABLE (animatable)); + g_return_if_fail (CLUTTER_IS_ANIMATION (animation)); + g_return_if_fail (property_name != NULL); + g_return_if_fail (initial_value != NULL && final_value != NULL); + g_return_if_fail (G_VALUE_TYPE (initial_value) != G_TYPE_INVALID); + g_return_if_fail (G_VALUE_TYPE (final_value) != G_TYPE_INVALID); + g_return_if_fail (value != NULL); + g_return_if_fail (G_VALUE_TYPE (value) == G_VALUE_TYPE (initial_value) && + G_VALUE_TYPE (value) == G_VALUE_TYPE (final_value)); + + CLUTTER_ANIMATABLE_GET_IFACE (animatable)->animate_property (animatable, + animation, + property_name, + initial_value, + final_value, + progress, + value); +} diff --git a/clutter/clutter-animatable.h b/clutter/clutter-animatable.h new file mode 100644 index 000000000..073ec3f66 --- /dev/null +++ b/clutter/clutter-animatable.h @@ -0,0 +1,56 @@ +#ifndef __CLUTTER_ANIMATABLE_H__ +#define __CLUTTER_ANIMATABLE_H__ + +#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION) +#error "Only can be included directly." +#endif + +#include + +G_BEGIN_DECLS + +#define CLUTTER_TYPE_ANIMATABLE (clutter_animatable_get_type ()) +#define CLUTTER_ANIMATABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_ANIMATABLE, ClutterAnimatable)) +#define CLUTTER_IS_ANIMATABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_ANIMATABLE)) +#define CLUTTER_ANIMATABLE_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), CLUTTER_TYPE_ANIMATABLE, ClutterAnimatableIface)) + +typedef struct _ClutterAnimatable ClutterAnimatable; /* dummy typedef */ +typedef struct _ClutterAnimatableIface ClutterAnimatableIface; + +/** + * ClutterAnimatableIface: + * @animate_property: virtual function for animating a property + * + * Base interface for #GObjects that can be animated by a + * a #ClutterAnimation. + * + * Since: 1.0 + */ +struct _ClutterAnimatableIface +{ + /*< private >*/ + GTypeInterface parent_iface; + + /*< public >*/ + void (* animate_property) (ClutterAnimatable *animatable, + ClutterAnimation *animation, + const gchar *property_name, + const GValue *initial_value, + const GValue *final_value, + gdouble progress, + GValue *value); +}; + +GType clutter_animatable_get_type (void) G_GNUC_CONST; + +void clutter_animatable_animate_property (ClutterAnimatable *animatable, + ClutterAnimation *animation, + const gchar *property_name, + const GValue *initial_value, + const GValue *final_value, + gdouble progress, + GValue *value); + +G_END_DECLS + +#endif /* __CLUTTER_ANIMATABLE_H__ */ diff --git a/clutter/clutter.h b/clutter/clutter.h index 15208ce17..e7a8c5b3f 100644 --- a/clutter/clutter.h +++ b/clutter/clutter.h @@ -30,6 +30,7 @@ #include "clutter-actor.h" #include "clutter-alpha.h" +#include "clutter-animatable.h" #include "clutter-animation.h" #include "clutter-backend.h" #include "clutter-behaviour-depth.h" From 60cfa5edb241a4115e36d4d67374f3e87a4bb688 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 8 Jan 2009 12:59:16 +0000 Subject: [PATCH 2/4] [animation] Use ClutterAnimatable inside Animation ClutterAnimation should check if the object is implementing the Animatable interface, and if so delegate to it the computation of the value along the interval initial and final value, depending on the progress. --- clutter/clutter-animation.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/clutter/clutter-animation.c b/clutter/clutter-animation.c index f27d9da3e..9cff31d07 100644 --- a/clutter/clutter-animation.c +++ b/clutter/clutter-animation.c @@ -50,6 +50,7 @@ #include #include "clutter-alpha.h" +#include "clutter-animatable.h" #include "clutter-animation.h" #include "clutter-debug.h" #include "clutter-enum-types.h" @@ -664,9 +665,17 @@ on_alpha_notify (GObject *gobject, ClutterAnimationPrivate *priv = animation->priv; GList *properties, *p; guint32 alpha_value; + gboolean is_animatable = FALSE; + ClutterAnimatable *animatable = NULL; alpha_value = clutter_alpha_get_alpha (CLUTTER_ALPHA (gobject)); + if (CLUTTER_IS_ANIMATABLE (priv->actor)) + { + animatable = CLUTTER_ANIMATABLE (priv->actor); + is_animatable = TRUE; + } + g_object_freeze_notify (G_OBJECT (priv->actor)); properties = g_hash_table_get_keys (priv->properties); @@ -684,8 +693,29 @@ on_alpha_notify (GObject *gobject, factor = (gdouble) alpha_value / CLUTTER_ALPHA_MAX_ALPHA; - if (clutter_interval_compute_value (interval, factor, &value)) - g_object_set_property (G_OBJECT (priv->actor), p_name, &value); + if (is_animatable) + { + const GValue *initial, *final; + + initial = clutter_interval_peek_initial_value (interval); + final = clutter_interval_peek_final_value (interval); + + CLUTTER_NOTE (ANIMATION, "Animatable property `%s'", p_name); + clutter_animatable_animate_property (animatable, animation, + p_name, + initial, final, + factor, + &value); + + g_object_set_property (G_OBJECT (priv->actor), p_name, &value); + } + else + { + CLUTTER_NOTE (ANIMATION, "Standard property `%s'", p_name); + + if (clutter_interval_compute_value (interval, factor, &value)) + g_object_set_property (G_OBJECT (priv->actor), p_name, &value); + } g_value_unset (&value); } From d340de8e00b5de125ed94b2b26b9bcaa08a19675 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 8 Jan 2009 13:18:00 +0000 Subject: [PATCH 3/4] Add license notice to ClutterAnimation files --- clutter/clutter-animatable.c | 24 ++++++++++++++++++++++++ clutter/clutter-animatable.h | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/clutter/clutter-animatable.c b/clutter/clutter-animatable.c index e7876e2a6..fb2b88b19 100644 --- a/clutter/clutter-animatable.c +++ b/clutter/clutter-animatable.c @@ -1,3 +1,27 @@ +/* + * Clutter. + * + * An OpenGL based 'interactive canvas' library. + * + * Copyright (C) 2009 Intel Corporation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Author: + * Emmanuele Bassi + */ + /** * SECTION:clutter-animatable * @short_description: Interface for animatable classes diff --git a/clutter/clutter-animatable.h b/clutter/clutter-animatable.h index 073ec3f66..aee717ac4 100644 --- a/clutter/clutter-animatable.h +++ b/clutter/clutter-animatable.h @@ -1,3 +1,27 @@ +/* + * Clutter. + * + * An OpenGL based 'interactive canvas' library. + * + * Copyright (C) 2009 Intel Corporation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Author: + * Emmanuele Bassi + */ + #ifndef __CLUTTER_ANIMATABLE_H__ #define __CLUTTER_ANIMATABLE_H__ From 628ccaf4a855dc2477a5bb579bf49c414a80249e Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 8 Jan 2009 13:31:27 +0000 Subject: [PATCH 4/4] [docs] Add ClutterAnimatable to the API reference --- doc/reference/clutter/clutter-docs.xml | 1 + doc/reference/clutter/clutter-sections.txt | 79 ++++++++++++++-------- doc/reference/clutter/clutter.types | 1 + 3 files changed, 52 insertions(+), 29 deletions(-) diff --git a/doc/reference/clutter/clutter-docs.xml b/doc/reference/clutter/clutter-docs.xml index ffd06a561..3c7011827 100644 --- a/doc/reference/clutter/clutter-docs.xml +++ b/doc/reference/clutter/clutter-docs.xml @@ -106,6 +106,7 @@ + diff --git a/doc/reference/clutter/clutter-sections.txt b/doc/reference/clutter/clutter-sections.txt index 5948dd14a..771f86ba7 100644 --- a/doc/reference/clutter/clutter-sections.txt +++ b/doc/reference/clutter/clutter-sections.txt @@ -210,6 +210,35 @@ ClutterCloneTexturePrivate clutter_clone_texture_get_type +
+clutter-cairo-texture +ClutterCairoTexture +ClutterCairoTexture +ClutterCairoTextureClass +clutter_cairo_texture_new +clutter_cairo_texture_set_surface_size +clutter_cairo_texture_get_surface_size + + +clutter_cairo_texture_create +clutter_cairo_texture_create_region + + +clutter_cairo_set_source_color + + +CLUTTER_TYPE_CAIRO_TEXTURE +CLUTTER_CAIRO_TEXTURE +CLUTTER_IS_CAIRO_TEXTURE +CLUTTER_CAIRO_TEXTURE_CLASS +CLUTTER_IS_CAIRO_TEXTURE_CLASS +CLUTTER_CAIRO_TEXTURE_GET_CLASS + + +ClutterCairoTexturePrivate +clutter_cairo_texture_get_type +
+
clutter-group ClutterGroup @@ -1641,6 +1670,10 @@ clutter_interval_get_interval clutter_interval_validate clutter_interval_compute_value + +ClutterProgressFunc +clutter_interval_register_progress_func + CLUTTER_TYPE_INTERVAL CLUTTER_INTERVAL @@ -1654,6 +1687,23 @@ ClutterIntervalPrivate clutter_interval_get_type
+
+clutter-animatable +ClutterAnimatable +ClutterAnimatable +ClutterAnimatableIface +clutter_animatable_animate_property + + +CLUTTER_TYPE_ANIMATABLE +CLUTTER_ANIMATABLE +CLUTTER_IS_ANIMATABLE +CLUTTER_ANIMATABLE_GET_IFACE + + +clutter_animatable_get_type +
+
Key Bindings clutter-binding-pool @@ -1677,32 +1727,3 @@ clutter_binding_pool_unblock_action clutter_binding_pool_activate
- -
-ClutterCairoTexture -clutter-cairo-texture -ClutterCairoTexture -ClutterCairoTextureClass -clutter_cairo_texture_new -clutter_cairo_texture_set_surface_size -clutter_cairo_texture_get_surface_size - - -clutter_cairo_texture_create -clutter_cairo_texture_create_region - - -clutter_cairo_set_source_color - - -CLUTTER_TYPE_CAIRO_TEXTURE -CLUTTER_CAIRO_TEXTURE -CLUTTER_IS_CAIRO_TEXTURE -CLUTTER_CAIRO_TEXTURE_CLASS -CLUTTER_IS_CAIRO_TEXTURE_CLASS -CLUTTER_CAIRO_TEXTURE_GET_CLASS - - -ClutterCairoTexturePrivate -clutter_cairo_texture_get_type -
diff --git a/doc/reference/clutter/clutter.types b/doc/reference/clutter/clutter.types index 2bac85c6e..ac7d68ccc 100644 --- a/doc/reference/clutter/clutter.types +++ b/doc/reference/clutter/clutter.types @@ -29,3 +29,4 @@ clutter_score_get_type clutter_shader_get_type clutter_child_meta_get_type clutter_cairo_texture_get_type +clutter_animatable_get_type