mirror of
https://github.com/brl/mutter.git
synced 2024-11-23 16:40:41 -05:00
62844d5f04
Bug 1014 - Clutter Animation API Improvements * clutter/Makefile.am: * clutter/clutter.h: Update the build * clutter/clutter-types.h: Add AnimationMode, an enumeration for easing functions. * clutter/clutter-alpha.[ch]: Add the :mode property to control the function bound to an Alpha instance using an enumeration value. Also add six new alpha functions: - ease-in, ease-out, ease-in-out - sine-in, sine-out, sine-in-out * clutter/clutter-deprecated.h: Deprecate the #defines for the alpha functions. They will be replaced by entries in the ClutterAnimationMode. * clutter/clutter-interval.[ch]: Add ClutterInterval, an object for defining, validating and computing an interval between two values. * clutter/clutter-animation.[ch]: Add ClutterAnimation, an object responsible for animation the properties of a single actor along an interval of values. ClutterAnimation memory management is automatic. A simple wrapper method for ClutterActor is provided: clutter_actor_animate() which will create, or update, an animation for the passed actor. * clutter/clutter-debug.h: * clutter/clutter-main.c: Add a new 'animation' debug note. * clutter/clutter-script.c: Clean up the alpha functions whitelist, and add the new functions. * doc/reference/clutter/Makefile.am: * doc/reference/clutter/clutter-sections.txt: Update the API reference. * doc/reference/clutter/clutter-animation.xml: Renamed to doc/reference/clutter/clutter-animation-tutorial.xml to avoid clashes with the ClutterAnimation section. * doc/reference/clutter/clutter-docs.sgml: Renamed to doc/reference/clutter/clutter-docs.xml, as it was an XML file and not a SGML file. * tests/Makefile.am: * tests/interactive/Makefile.am: * tests/interactive/test-animation.c: * tests/interactive/test-easing.c: Add two tests for the new simple animation API and the easing functions. * tests/interactive/test-actors.c: * tests/interactive/test-behave.c: * tests/interactive/test-depth.c: * tests/interactive/test-effects.c: * tests/interactive/test-layout.c: * tests/interactive/test-multistage.c: * tests/interactive/test-paint-wrapper.c: * tests/interactive/test-rotate.c: * tests/interactive/test-scale.c: * tests/interactive/test-texture-quality.c: * tests/interactive/test-threads.c: * tests/interactive/test-viewport.c: Update interactive tests to the deprecations and new alpha API.
257 lines
6.1 KiB
C
257 lines
6.1 KiB
C
#include <clutter/clutter.h>
|
|
|
|
#if defined (_MSC_VER) && !defined (_USE_MATH_DEFINES)
|
|
#define _USE_MATH_DEFINES
|
|
#endif
|
|
|
|
#include <math.h>
|
|
#include <errno.h>
|
|
#include <stdlib.h>
|
|
#include <glib.h>
|
|
#include <gmodule.h>
|
|
|
|
#define TRAILS 0
|
|
#define NHANDS 6
|
|
#define RADIUS ((CLUTTER_STAGE_WIDTH()+CLUTTER_STAGE_HEIGHT())/NHANDS)
|
|
|
|
typedef struct SuperOH
|
|
{
|
|
ClutterActor **hand, *bgtex;
|
|
ClutterActor *group;
|
|
|
|
} SuperOH;
|
|
|
|
static gint n_hands = NHANDS;
|
|
|
|
static GOptionEntry super_oh_entries[] = {
|
|
{
|
|
"num-hands", 'n',
|
|
0,
|
|
G_OPTION_ARG_INT, &n_hands,
|
|
"Number of hands", "HANDS"
|
|
},
|
|
{ NULL }
|
|
};
|
|
|
|
/* input handler */
|
|
static gboolean
|
|
input_cb (ClutterActor *stage,
|
|
ClutterEvent *event,
|
|
gpointer data)
|
|
{
|
|
SuperOH *oh = data;
|
|
|
|
if (event->type == CLUTTER_BUTTON_PRESS)
|
|
{
|
|
ClutterButtonEvent *button_event;
|
|
ClutterActor *e;
|
|
gint x, y;
|
|
|
|
clutter_event_get_coords (event, &x, &y);
|
|
|
|
button_event = (ClutterButtonEvent *) event;
|
|
g_print ("*** button press event (button:%d) ***\n",
|
|
button_event->button);
|
|
|
|
e = clutter_stage_get_actor_at_pos (CLUTTER_STAGE (stage), x, y);
|
|
|
|
if (e && (CLUTTER_IS_TEXTURE (e) || CLUTTER_IS_CLONE_TEXTURE (e)))
|
|
{
|
|
clutter_actor_hide (e);
|
|
return TRUE;
|
|
}
|
|
}
|
|
else if (event->type == CLUTTER_KEY_RELEASE)
|
|
{
|
|
ClutterKeyEvent *kev = (ClutterKeyEvent *) event;
|
|
|
|
g_print ("*** key press event (key:%c) ***\n",
|
|
clutter_key_event_symbol (kev));
|
|
|
|
if (clutter_key_event_symbol (kev) == CLUTTER_q)
|
|
{
|
|
clutter_main_quit ();
|
|
return TRUE;
|
|
}
|
|
else if (clutter_key_event_symbol (kev) == CLUTTER_r)
|
|
{
|
|
gint i;
|
|
|
|
for (i = 0; i < n_hands; i++)
|
|
clutter_actor_show (oh->hand[i]);
|
|
|
|
return TRUE;
|
|
}
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
|
|
/* Timeline handler */
|
|
static void
|
|
frame_cb (ClutterTimeline *timeline,
|
|
gint frame_num,
|
|
gpointer data)
|
|
{
|
|
SuperOH *oh = data;
|
|
gint i;
|
|
|
|
/* Rotate everything clockwise about stage center*/
|
|
|
|
clutter_actor_set_rotation (CLUTTER_ACTOR (oh->group),
|
|
CLUTTER_Z_AXIS,
|
|
frame_num,
|
|
CLUTTER_STAGE_WIDTH () / 2,
|
|
CLUTTER_STAGE_HEIGHT () / 2,
|
|
0);
|
|
|
|
for (i = 0; i < n_hands; i++)
|
|
{
|
|
gdouble scale_x, scale_y;
|
|
|
|
clutter_actor_get_scale (oh->hand[i], &scale_x, &scale_y);
|
|
|
|
/* Rotate each hand around there centers - to get this we need
|
|
* to take into account any scaling.
|
|
*
|
|
* FIXME: scaling causes drift so disabled for now. Need rotation
|
|
* unit based functions to fix.
|
|
*/
|
|
clutter_actor_set_rotation (oh->hand[i], CLUTTER_Z_AXIS,
|
|
- 6.0 * frame_num, 0, 0, 0);
|
|
}
|
|
}
|
|
|
|
G_MODULE_EXPORT int
|
|
test_actors_main (int argc, char *argv[])
|
|
{
|
|
ClutterTimeline *timeline;
|
|
ClutterAlpha *alpha;
|
|
ClutterBehaviour *scaler_1, *scaler_2;
|
|
ClutterActor *stage;
|
|
ClutterColor stage_color = { 0x61, 0x64, 0x8c, 0xff };
|
|
SuperOH *oh;
|
|
gint i;
|
|
GError *error;
|
|
|
|
error = NULL;
|
|
|
|
clutter_init_with_args (&argc, &argv,
|
|
NULL,
|
|
super_oh_entries,
|
|
NULL,
|
|
&error);
|
|
if (error)
|
|
{
|
|
g_warning ("Unable to initialise Clutter:\n%s",
|
|
error->message);
|
|
g_error_free (error);
|
|
|
|
exit (1);
|
|
}
|
|
|
|
stage = clutter_stage_get_default ();
|
|
clutter_actor_set_size (stage, 800, 600);
|
|
|
|
clutter_stage_set_title (CLUTTER_STAGE (stage), "Actors Test");
|
|
clutter_stage_set_color (CLUTTER_STAGE (stage),
|
|
&stage_color);
|
|
|
|
oh = g_new(SuperOH, 1);
|
|
|
|
/* Create a timeline to manage animation */
|
|
timeline = clutter_timeline_new (360, 60); /* num frames, fps */
|
|
g_object_set (timeline, "loop", TRUE, NULL); /* have it loop */
|
|
|
|
/* fire a callback for frame change */
|
|
g_signal_connect (timeline, "new-frame", G_CALLBACK (frame_cb), oh);
|
|
|
|
/* Set up some behaviours to handle scaling */
|
|
alpha = clutter_alpha_new_full (timeline, clutter_sine_func, NULL, NULL);
|
|
|
|
scaler_1 = clutter_behaviour_scale_new (alpha,
|
|
0.5, 0.5,
|
|
1.0, 1.0);
|
|
|
|
scaler_2 = clutter_behaviour_scale_new (alpha,
|
|
1.0, 1.0,
|
|
0.5, 0.5);
|
|
|
|
/* create a new group to hold multiple actors in a group */
|
|
oh->group = clutter_group_new();
|
|
|
|
oh->hand = g_new (ClutterActor*, n_hands);
|
|
for (i = 0; i < n_hands; i++)
|
|
{
|
|
gint x, y, w, h;
|
|
|
|
/* Create a texture from file, then clone in to same resources */
|
|
if (i == 0)
|
|
{
|
|
if ((oh->hand[i] = clutter_texture_new_from_file ("redhand.png",
|
|
&error)) == NULL)
|
|
{
|
|
g_error ("image load failed: %s", error->message);
|
|
exit (1);
|
|
}
|
|
}
|
|
else
|
|
oh->hand[i] = clutter_clone_texture_new (CLUTTER_TEXTURE(oh->hand[0]));
|
|
|
|
/* Place around a circle */
|
|
w = clutter_actor_get_width (oh->hand[0]);
|
|
h = clutter_actor_get_height (oh->hand[0]);
|
|
|
|
x = CLUTTER_STAGE_WIDTH () / 2
|
|
+ RADIUS
|
|
* cos (i * M_PI / (n_hands / 2))
|
|
- w / 2;
|
|
|
|
y = CLUTTER_STAGE_HEIGHT () / 2
|
|
+ RADIUS
|
|
* sin (i * M_PI / (n_hands / 2))
|
|
- h / 2;
|
|
|
|
clutter_actor_set_position (oh->hand[i], x, y);
|
|
|
|
clutter_actor_move_anchor_point_from_gravity (oh->hand[i],
|
|
CLUTTER_GRAVITY_CENTER);
|
|
|
|
/* Add to our group group */
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (oh->group), oh->hand[i]);
|
|
|
|
#if 1 /* FIXME: disabled as causes drift? - see comment above */
|
|
if (i % 2)
|
|
clutter_behaviour_apply (scaler_1, oh->hand[i]);
|
|
else
|
|
clutter_behaviour_apply (scaler_2, oh->hand[i]);
|
|
#endif
|
|
}
|
|
|
|
/* Add the group to the stage */
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage),
|
|
CLUTTER_ACTOR (oh->group));
|
|
|
|
/* Show everying ( and map window ) */
|
|
clutter_actor_show (stage);
|
|
|
|
|
|
g_signal_connect (stage, "button-press-event",
|
|
G_CALLBACK (input_cb),
|
|
oh);
|
|
g_signal_connect (stage, "key-release-event",
|
|
G_CALLBACK (input_cb),
|
|
oh);
|
|
|
|
/* and start it */
|
|
clutter_timeline_start (timeline);
|
|
|
|
clutter_main ();
|
|
|
|
g_free (oh->hand);
|
|
g_free (oh);
|
|
|
|
return 0;
|
|
}
|