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"