Add ClutterAnimator

ClutterAnimator is a class for managing the animation of multiple
properties of multiple actors over time with keyframing of values.

The Animator class is meant to be used to effectively describe
animations using the ClutterScript definition format, and to construct
complex implicit animations from the ground up.

Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
This commit is contained in:
Øyvind Kolås 2010-02-05 12:32:00 +00:00 committed by Emmanuele Bassi
parent f973b73208
commit 4cc269a468
11 changed files with 1793 additions and 1 deletions

1
.gitignore vendored
View File

@ -146,6 +146,7 @@ TAGS
/tests/interactive/test-flow-layout
/tests/interactive/test-box-layout
/tests/interactive/stamp-test-interactive
/tests/interactive/test-animator
/tests/conform/stamp-test-conformance
/tests/conform/test-anchors
/tests/conform/test-cogl-backface-culling

View File

@ -66,6 +66,7 @@ source_h = \
$(srcdir)/clutter-alpha.h \
$(srcdir)/clutter-animatable.h \
$(srcdir)/clutter-animation.h \
$(srcdir)/clutter-animator.h \
$(srcdir)/clutter-backend.h \
$(srcdir)/clutter-behaviour.h \
$(srcdir)/clutter-behaviour-depth.h \
@ -138,6 +139,7 @@ source_c = \
$(srcdir)/clutter-alpha.c \
$(srcdir)/clutter-animatable.c \
$(srcdir)/clutter-animation.c \
$(srcdir)/clutter-animator.c \
$(srcdir)/clutter-backend.c \
$(srcdir)/clutter-behaviour.c \
$(srcdir)/clutter-behaviour-depth.c \

1435
clutter/clutter-animator.c Normal file

File diff suppressed because it is too large Load Diff

166
clutter/clutter-animator.h Normal file
View File

@ -0,0 +1,166 @@
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Copyright (C) 2010 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 <http://www.gnu.org/licenses/>.
*
* Author:
* Øyvind Kolås <pippin@linux.intel.com>
*/
#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
#error "Only <clutter/clutter.h> can be included directly."
#endif
#ifndef __CLUTTER_ANIMATOR_H__
#define __CLUTTER_ANIMATOR_H__
#include <clutter/clutter-types.h>
#include <clutter/clutter-timeline.h>
G_BEGIN_DECLS
#define CLUTTER_TYPE_ANIMATOR (clutter_animator_get_type ())
#define CLUTTER_TYPE_ANIMATOR_KEY (clutter_animator_key_get_type ())
#define CLUTTER_ANIMATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_ANIMATOR, ClutterAnimator))
#define CLUTTER_ANIMATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_ANIMATOR, ClutterAnimatorClass))
#define CLUTTER_IS_ANIMATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_ANIMATOR))
#define CLUTTER_IS_ANIMATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_ANIMATOR))
#define CLUTTER_ANIMATOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_ANIMATOR, ClutterAnimatorClass))
/* ClutterAnimator is typedef in clutter-types.h */
typedef struct _ClutterAnimatorClass ClutterAnimatorClass;
typedef struct _ClutterAnimatorPrivate ClutterAnimatorPrivate;
/**
* ClutterAnimatorKey:
*
* A key frame inside a #ClutterAnimator
*
* Since: 1.2
*/
typedef struct _ClutterAnimatorKey ClutterAnimatorKey;
/**
* ClutterInterpolation:
* @CLUTTER_INTERPOLATION_LINEAR:
* @CLUTTER_INTERPOLATION_CUBIC:
*
* The mode of interpolation between key frames
*
* Since: 1.2
*/
typedef enum {
CLUTTER_INTERPOLATION_LINEAR,
CLUTTER_INTERPOLATION_CUBIC
} ClutterInterpolation;
/**
* ClutterAnimator:
*
* The #ClutterAnimator structure contains only private data and
* should be accessed using the provided API
*
* Since: 1.2
*/
struct _ClutterAnimator
{
/*< private >*/
GObject parent_instance;
ClutterAnimatorPrivate *priv;
};
/**
* ClutterAnimatorClass:
*
* The #ClutterAnimatorClass structure contains only private data
*
* Since: 1.2
*/
struct _ClutterAnimatorClass
{
/*< private >*/
GObjectClass parent_class;
/* padding for future expansion */
gpointer _padding_dummy[16];
};
GType clutter_animator_get_type (void) G_GNUC_CONST;
ClutterAnimator * clutter_animator_new (void);
ClutterAnimator * clutter_animator_set_key (ClutterAnimator *animator,
GObject *object,
const gchar *property_name,
guint mode,
gdouble progress,
const GValue *value);
void clutter_animator_set (ClutterAnimator *animator,
gpointer first_object,
const gchar *first_property_name,
guint first_mode,
gdouble first_progress,
...);
GList * clutter_animator_get_keys (ClutterAnimator *animator,
GObject *object,
const gchar *property_name,
gdouble progress);
void clutter_animator_remove_key (ClutterAnimator *animator,
GObject *object,
const gchar *property_name,
gdouble progress);
ClutterTimeline * clutter_animator_run (ClutterAnimator *animator);
ClutterTimeline * clutter_animator_get_timeline (ClutterAnimator *animator);
void clutter_animator_set_timeline (ClutterAnimator *animator,
ClutterTimeline *timeline);
guint clutter_animator_get_duration (ClutterAnimator *animator);
void clutter_animator_set_duration (ClutterAnimator *animator,
guint duration);
gboolean clutter_animator_property_get_ease_in (ClutterAnimator *animator,
GObject *object,
const gchar *property_name);
void clutter_animator_property_set_ease_in (ClutterAnimator *animator,
GObject *object,
const gchar *property_name,
gboolean ease_in);
ClutterInterpolation clutter_animator_property_get_interpolation (ClutterAnimator *animator,
GObject *object,
const gchar *property_name,
ClutterInterpolation interpolation);
void clutter_animator_property_set_interpolation (ClutterAnimator *animator,
GObject *object,
const gchar *property_name,
ClutterInterpolation interpolation);
GType clutter_animator_key_get_type (void) G_GNUC_CONST;
GObject * clutter_animator_key_get_object (ClutterAnimatorKey *animator_key);
G_CONST_RETURN gchar *clutter_animator_key_get_property_name (ClutterAnimatorKey *animator_key);
gulong clutter_animator_key_get_mode (ClutterAnimatorKey *animator_key);
gdouble clutter_animator_key_get_progress (ClutterAnimatorKey *animator_key);
void clutter_animator_key_get_value (ClutterAnimatorKey *animator_key,
GValue *value);
G_END_DECLS
#endif /* __CLUTTER_ANIMATOR_H__ */

View File

@ -44,6 +44,7 @@ typedef struct _ClutterStage ClutterStage;
typedef struct _ClutterContainer ClutterContainer; /* dummy */
typedef struct _ClutterChildMeta ClutterChildMeta;
typedef struct _ClutterLayoutMeta ClutterLayoutMeta;
typedef struct _ClutterAnimator ClutterAnimator;
/**
* ClutterGravity:

View File

@ -34,6 +34,7 @@
#include "clutter-alpha.h"
#include "clutter-animatable.h"
#include "clutter-animation.h"
#include "clutter-animator.h"
#include "clutter-backend.h"
#include "clutter-behaviour-depth.h"
#include "clutter-behaviour-ellipse.h"

View File

@ -15,7 +15,7 @@
</copyright>
<copyright>
<year>2009</year>
<year>2009, 2010</year>
<holder>Intel Corporation</holder>
</copyright>
@ -123,6 +123,8 @@
<xi:include href="xml/clutter-interval.xml"/>
<xi:include href="xml/clutter-animation.xml"/>
<xi:include href="xml/clutter-animatable.xml"/>
<xi:include href="xml/clutter-animator.xml"/>
</chapter>
</part>

View File

@ -2012,3 +2012,51 @@ CLUTTER_BOX_LAYOUT_GET_CLASS
ClutterBoxLayoutPrivate
clutter_box_layout_get_type
</SECTION>
<SECTION>
<FILE>clutter-animator</FILE>
<TITLE>ClutterAnimator</TITLE>
ClutterAnimator
ClutterAnimatorClass
clutter_animator_new
clutter_animator_set
clutter_animator_set_key
clutter_animator_remove_key
clutter_animator_get_keys
clutter_animator_run
<SUBSECTION>
clutter_animator_set_timeline
clutter_animator_get_timeline
clutter_animator_set_duration
clutter_animator_get_duration
<SUBSECTION>
clutter_animator_property_set_ease_in
clutter_animator_property_get_ease_in
ClutterInterpolation
clutter_animator_property_set_interpolation
clutter_animator_property_get_interpolation
<SUBSECTION>
ClutterAnimatorKey
clutter_animator_key_get_object
clutter_animator_key_get_property_name
clutter_animator_key_get_mode
clutter_animator_key_get_progress
clutter_animator_key_get_value
<SUBSECTION Standard>
CLUTTER_TYPE_ANIMATOR
CLUTTER_TYPE_ANIMATOR_KEY
CLUTTER_ANIMATOR
CLUTTER_ANIMATOR_CLASS
CLUTTER_IS_ANIMATOR
CLUTTER_IS_ANIMATOR_CLASS
CLUTTER_ANIMATOR_GET_CLASS
<SUBSECTION Private>
clutter_animator_get_type
clutter_animator_key_get_type
ClutterAnimatorPrivate
</SECTION>

View File

@ -42,3 +42,4 @@ clutter_flow_layout_get_type
clutter_box_layout_get_type
clutter_input_device_get_type
clutter_device_manager_get_type
clutter_animator_get_type

View File

@ -19,6 +19,7 @@ UNIT_TESTS = \
test-grab.c \
test-fullscreen.c \
test-shader.c \
test-animator.c \
test-unproject.c \
test-viewport.c \
test-fbo.c \

View File

@ -0,0 +1,134 @@
#include <stdlib.h>
#include <math.h>
#include <gmodule.h>
#include <clutter/clutter.h>
static ClutterAnimator *animator;
static ClutterActor *new_rect (gint r,
gint g,
gint b,
gint a)
{
GError *error = NULL;
ClutterColor *color = clutter_color_new (r, g, b, a);
ClutterActor *rectangle = clutter_rectangle_new_with_color (color);
gchar *file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
rectangle = clutter_texture_new_from_file (file, &error);
if (rectangle == NULL)
g_error ("image load failed: %s", error->message);
g_free (file);
clutter_actor_set_size (rectangle, 128, 128);
clutter_color_free (color);
return rectangle;
}
static gboolean nuke_one (gpointer actor)
{
clutter_actor_destroy (actor);
return FALSE;
}
#define COUNT 4
static void reverse_timeline (ClutterTimeline *timeline,
gpointer data)
{
ClutterTimelineDirection direction = clutter_timeline_get_direction (timeline);
if (direction == CLUTTER_TIMELINE_FORWARD)
clutter_timeline_set_direction (timeline, CLUTTER_TIMELINE_BACKWARD);
else
clutter_timeline_set_direction (timeline, CLUTTER_TIMELINE_FORWARD);
clutter_timeline_start (timeline);
}
G_MODULE_EXPORT gint
test_animator_main (gint argc,
gchar **argv)
{
ClutterActor *stage;
ClutterActor *rects[COUNT];
gint i;
clutter_init (&argc, &argv);
stage = clutter_stage_get_default ();
for (i=0; i<COUNT; i++)
{
rects[i]=new_rect (255 *(i * 1.0/COUNT), 50, 160, 255);
clutter_container_add_actor (CLUTTER_CONTAINER (stage), rects[i]);
clutter_actor_set_anchor_point (rects[i], 64, 64);
clutter_actor_set_position (rects[i], 320.0, 240.0);
clutter_actor_set_opacity (rects[i], 0x70);
}
g_timeout_add (10000, nuke_one, rects[2]);
animator = clutter_animator_new ();
/* Note: when both animations are active for the same actor at the same
* time there is a race, such races should be handled by avoiding
* controlling the same properties from multiple animations. This is
* an intentional design flaw of this test for testing the corner case.
*/
clutter_animator_set (animator,
rects[0], "x", 1, 0.0, 180.0,
rects[0], "x", CLUTTER_LINEAR, 0.25, 450.0,
rects[0], "x", CLUTTER_LINEAR, 0.5, 450.0,
rects[0], "x", CLUTTER_LINEAR, 0.75, 180.0,
rects[0], "x", CLUTTER_LINEAR, 1.0, 180.0,
rects[0], "y", -1, 0.0, 100.0,
rects[0], "y", CLUTTER_LINEAR, 0.25, 100.0,
rects[0], "y", CLUTTER_LINEAR, 0.5, 380.0,
rects[0], "y", CLUTTER_LINEAR, 0.75, 380.0,
rects[0], "y", CLUTTER_LINEAR, 1.0, 100.0,
rects[3], "x", 0, 0.0, 180.0,
rects[3], "x", CLUTTER_LINEAR, 0.25, 180.0,
rects[3], "x", CLUTTER_LINEAR, 0.5, 450.0,
rects[3], "x", CLUTTER_LINEAR, 0.75, 450.0,
rects[3], "x", CLUTTER_LINEAR, 1.0, 180.0,
rects[3], "y", 0, 0.0, 100.0,
rects[3], "y", CLUTTER_LINEAR, 0.25, 380.0,
rects[3], "y", CLUTTER_LINEAR, 0.5, 380.0,
rects[3], "y", CLUTTER_LINEAR, 0.75, 100.0,
rects[3], "y", CLUTTER_LINEAR, 1.0, 100.0,
rects[2], "rotation-angle-y", 0, 0.0, 0.0,
rects[2], "rotation-angle-y", CLUTTER_LINEAR, 1.0, 360.0,
rects[1], "scale-x", 0, 0.0, 1.0,
rects[1], "scale-x", CLUTTER_LINEAR, 1.0, 2.0,
rects[1], "scale-y", 0, 0.0, 1.0,
rects[1], "scale-y", CLUTTER_LINEAR, 1.0, 2.0,
NULL);
clutter_actor_set_scale (rects[0], 1.4, 1.4);
clutter_animator_property_set_ease_in (animator, G_OBJECT (rects[0]), "x",
TRUE);
clutter_animator_property_set_ease_in (animator, G_OBJECT (rects[0]), "y",
TRUE);
clutter_animator_property_set_interpolation (animator, G_OBJECT (rects[0]),
"x", CLUTTER_INTERPOLATION_CUBIC);
clutter_animator_property_set_interpolation (animator, G_OBJECT (rects[0]),
"y", CLUTTER_INTERPOLATION_CUBIC);
clutter_actor_show (stage);
clutter_animator_set_duration (animator, 5000);
g_signal_connect (clutter_animator_run (animator),
"completed", G_CALLBACK (reverse_timeline), NULL);
clutter_main ();
g_object_unref (animator);
return EXIT_SUCCESS;
}