2007-06-16 21:15:31 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
2008-11-07 19:32:28 +00:00
|
|
|
#include <gmodule.h>
|
2007-06-16 21:15:31 +00:00
|
|
|
|
2010-11-06 15:54:21 +00:00
|
|
|
#undef CLUTTER_DISABLE_DEPRECATED
|
2006-08-15 20:28:41 +00:00
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
2007-10-08 14:51:14 +00:00
|
|
|
static gboolean
|
2007-03-22 18:21:59 +00:00
|
|
|
button_press_cb (ClutterStage *stage,
|
|
|
|
ClutterButtonEvent *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
const gchar *click_type;
|
|
|
|
|
2007-10-03 09:28:16 +00:00
|
|
|
switch (event->click_count)
|
2007-03-22 18:21:59 +00:00
|
|
|
{
|
2007-10-03 09:28:16 +00:00
|
|
|
case 2:
|
2007-03-22 18:21:59 +00:00
|
|
|
click_type = "double";
|
|
|
|
break;
|
2007-10-03 09:28:16 +00:00
|
|
|
case 3:
|
2007-03-22 18:21:59 +00:00
|
|
|
click_type = "triple";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
click_type = "single";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_print ("%s button press event\n", click_type);
|
2007-10-08 14:51:14 +00:00
|
|
|
|
|
|
|
return FALSE;
|
2007-03-22 18:21:59 +00:00
|
|
|
}
|
|
|
|
|
2007-10-08 14:51:14 +00:00
|
|
|
static gboolean
|
2007-03-22 18:21:59 +00:00
|
|
|
scroll_event_cb (ClutterStage *stage,
|
|
|
|
ClutterScrollEvent *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
g_print ("scroll direction: %s\n",
|
|
|
|
event->direction == CLUTTER_SCROLL_UP ? "up"
|
|
|
|
: "down");
|
2007-10-08 14:51:14 +00:00
|
|
|
|
|
|
|
return FALSE;
|
2007-03-22 18:21:59 +00:00
|
|
|
}
|
|
|
|
|
2007-04-30 08:39:31 +00:00
|
|
|
typedef enum {
|
|
|
|
PATH_POLY,
|
|
|
|
PATH_ELLIPSE,
|
|
|
|
PATH_BSPLINE
|
|
|
|
} path_t;
|
|
|
|
|
2008-11-07 19:32:28 +00:00
|
|
|
G_MODULE_EXPORT int
|
|
|
|
test_behave_main (int argc, char *argv[])
|
2006-08-15 20:28:41 +00:00
|
|
|
{
|
|
|
|
ClutterTimeline *timeline;
|
2006-08-28 17:11:15 +00:00
|
|
|
ClutterAlpha *alpha;
|
2006-12-04 16:26:35 +00:00
|
|
|
ClutterBehaviour *o_behave, *p_behave;
|
2006-11-20 22:20:48 +00:00
|
|
|
ClutterActor *stage;
|
|
|
|
ClutterActor *group, *rect, *hand;
|
2009-11-05 17:30:33 +00:00
|
|
|
gchar *file;
|
2007-04-30 08:39:31 +00:00
|
|
|
int i;
|
|
|
|
path_t path_type = PATH_POLY;
|
2008-12-05 13:13:37 +00:00
|
|
|
|
|
|
|
const char *knots_poly = ("M 0, 0 L 0, 300 L 300, 300 "
|
|
|
|
"L 300, 0 L 0, 0");
|
|
|
|
|
|
|
|
/* A spiral created with inkscake */
|
|
|
|
const char *knots_bspline =
|
|
|
|
"M 34.285713,35.219326 "
|
|
|
|
"C 44.026891,43.384723 28.084874,52.378758 20.714286,51.409804 "
|
|
|
|
"C 0.7404474,48.783999 -4.6171866,23.967448 1.904757,8.0764719 "
|
|
|
|
"C 13.570984,-20.348756 49.798303,-26.746504 74.999994,-13.352108 "
|
|
|
|
"C 111.98449,6.3047056 119.56591,55.259271 99.047626,89.505034 "
|
|
|
|
"C 71.699974,135.14925 9.6251774,143.91924 -33.571422,116.17172 "
|
|
|
|
"C -87.929934,81.254291 -97.88804,5.8941057 -62.857155,-46.209236 "
|
|
|
|
"C -20.430061,-109.31336 68.300385,-120.45954 129.2857,-78.114021 "
|
|
|
|
"C 201.15479,-28.21129 213.48932,73.938876 163.80954,143.79074 "
|
|
|
|
"C 106.45226,224.43749 -9.1490153,237.96076 -87.85713,180.93363 "
|
|
|
|
"C -177.29029,116.13577 -192.00272,-12.937817 -127.61907,-100.49494 "
|
|
|
|
"C -55.390344,-198.72081 87.170553,-214.62275 183.57141,-142.87593 "
|
|
|
|
"C 290.59464,-63.223369 307.68641,92.835839 228.57145,198.07645";
|
2007-04-30 08:39:31 +00:00
|
|
|
|
|
|
|
for (i = 0; i < argc; ++i)
|
|
|
|
{
|
|
|
|
if (!strncmp (argv[i], "--path", 6))
|
|
|
|
{
|
|
|
|
if (!strncmp (argv[i] + 7, "poly", 4))
|
|
|
|
path_type = PATH_POLY;
|
|
|
|
else if (!strncmp (argv[i] + 7, "bspline", 7))
|
|
|
|
path_type = PATH_BSPLINE;
|
|
|
|
else if (!strncmp (argv[i] + 7, "ellipse", 7))
|
|
|
|
path_type = PATH_ELLIPSE;
|
|
|
|
}
|
|
|
|
else if (!strncmp (argv[i], "--help", 6))
|
|
|
|
{
|
|
|
|
printf ("behave [--path=poly|ellipse|bspline]\n");
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-15 20:28:41 +00:00
|
|
|
clutter_init (&argc, &argv);
|
|
|
|
|
2010-10-11 16:45:30 +00:00
|
|
|
stage = clutter_stage_new ();
|
|
|
|
clutter_stage_set_title (CLUTTER_STAGE (stage), "Behaviours");
|
|
|
|
clutter_stage_set_color (CLUTTER_STAGE (stage), CLUTTER_COLOR_Aluminium2);
|
2007-03-22 18:21:59 +00:00
|
|
|
clutter_stage_hide_cursor (CLUTTER_STAGE (stage));
|
2010-10-11 16:45:30 +00:00
|
|
|
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
|
2007-03-22 18:21:59 +00:00
|
|
|
g_signal_connect (stage, "button-press-event",
|
|
|
|
G_CALLBACK (button_press_cb),
|
|
|
|
NULL);
|
|
|
|
g_signal_connect (stage, "scroll-event",
|
|
|
|
G_CALLBACK (scroll_event_cb),
|
|
|
|
NULL);
|
2006-11-20 22:20:48 +00:00
|
|
|
g_signal_connect (stage, "key-press-event",
|
|
|
|
G_CALLBACK (clutter_main_quit),
|
|
|
|
NULL);
|
2006-08-15 20:28:41 +00:00
|
|
|
|
|
|
|
/* Make a hand */
|
2006-11-20 22:20:48 +00:00
|
|
|
group = clutter_group_new ();
|
2007-06-07 14:41:35 +00:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), group);
|
2006-11-20 22:20:48 +00:00
|
|
|
clutter_actor_show (group);
|
2009-11-05 17:30:33 +00:00
|
|
|
|
|
|
|
file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
|
|
|
|
hand = clutter_texture_new_from_file (file, NULL);
|
2008-04-25 13:37:36 +00:00
|
|
|
if (hand == NULL)
|
2009-11-05 17:30:33 +00:00
|
|
|
g_error("Unable to load '%s'", file);
|
|
|
|
|
|
|
|
g_free (file);
|
|
|
|
|
2008-04-25 13:37:36 +00:00
|
|
|
clutter_actor_set_position (hand, 0, 0);
|
|
|
|
clutter_actor_show (hand);
|
|
|
|
|
2006-11-20 22:20:48 +00:00
|
|
|
rect = clutter_rectangle_new ();
|
|
|
|
clutter_actor_set_position (rect, 0, 0);
|
|
|
|
clutter_actor_set_size (rect,
|
2008-04-25 13:37:36 +00:00
|
|
|
clutter_actor_get_width (hand),
|
|
|
|
clutter_actor_get_height (hand));
|
2010-10-11 16:45:30 +00:00
|
|
|
clutter_rectangle_set_color (CLUTTER_RECTANGLE (rect), CLUTTER_COLOR_Transparent);
|
2006-11-20 22:20:48 +00:00
|
|
|
clutter_rectangle_set_border_width (CLUTTER_RECTANGLE (rect), 10);
|
|
|
|
clutter_rectangle_set_border_color (CLUTTER_RECTANGLE (rect),
|
2010-10-11 16:45:30 +00:00
|
|
|
CLUTTER_COLOR_Chameleon);
|
2006-11-20 22:20:48 +00:00
|
|
|
clutter_actor_show (rect);
|
2006-12-12 20:20:04 +00:00
|
|
|
|
2007-06-07 14:41:35 +00:00
|
|
|
clutter_container_add (CLUTTER_CONTAINER (group), rect, hand, NULL);
|
2006-12-12 20:20:04 +00:00
|
|
|
|
2006-08-15 20:28:41 +00:00
|
|
|
/* Make a timeline */
|
2010-11-17 15:27:42 +00:00
|
|
|
timeline = clutter_timeline_new (4000);
|
2007-11-23 11:23:19 +00:00
|
|
|
clutter_timeline_set_loop (timeline, TRUE);
|
2010-11-17 15:27:42 +00:00
|
|
|
clutter_timeline_set_reverse (timeline, TRUE);
|
2006-08-15 20:28:41 +00:00
|
|
|
|
2008-11-17 Emmanuele Bassi <ebassi@linux.intel.com>
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.
2008-11-18 09:50:03 +00:00
|
|
|
/* Set an alpha func to power behaviour - ramp is constant rise */
|
2009-01-16 13:42:06 +00:00
|
|
|
alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR);
|
2006-08-15 20:28:41 +00:00
|
|
|
|
2006-10-22 23:33:14 +00:00
|
|
|
/* Create a behaviour for that alpha */
|
2006-12-04 16:26:35 +00:00
|
|
|
o_behave = clutter_behaviour_opacity_new (alpha, 0X33, 0xff);
|
2006-08-15 20:28:41 +00:00
|
|
|
|
|
|
|
/* Apply it to our actor */
|
2006-12-04 16:26:35 +00:00
|
|
|
clutter_behaviour_apply (o_behave, group);
|
2006-08-15 20:28:41 +00:00
|
|
|
|
2006-10-22 23:33:14 +00:00
|
|
|
/* Make a path behaviour and apply that too */
|
2007-04-30 08:39:31 +00:00
|
|
|
switch (path_type)
|
|
|
|
{
|
|
|
|
case PATH_POLY:
|
2008-12-05 13:13:37 +00:00
|
|
|
{
|
|
|
|
ClutterPath *path = clutter_path_new ();
|
|
|
|
clutter_path_set_description (path, knots_poly);
|
|
|
|
p_behave = clutter_behaviour_path_new (alpha, path);
|
|
|
|
}
|
2007-04-30 08:39:31 +00:00
|
|
|
break;
|
|
|
|
case PATH_ELLIPSE:
|
|
|
|
p_behave =
|
2007-05-25 12:07:24 +00:00
|
|
|
clutter_behaviour_ellipse_new (alpha, 200, 200, 400, 300,
|
2007-08-03 09:52:52 +00:00
|
|
|
CLUTTER_ROTATE_CW,
|
2007-07-26 13:48:44 +00:00
|
|
|
0.0, 360.0);
|
2007-07-26 13:48:50 +00:00
|
|
|
|
2007-07-27 13:44:42 +00:00
|
|
|
clutter_behaviour_ellipse_set_angle_tilt (CLUTTER_BEHAVIOUR_ELLIPSE (p_behave),
|
2007-08-03 09:52:52 +00:00
|
|
|
CLUTTER_X_AXIS,
|
|
|
|
45.0);
|
2007-07-27 13:44:42 +00:00
|
|
|
clutter_behaviour_ellipse_set_angle_tilt (CLUTTER_BEHAVIOUR_ELLIPSE (p_behave),
|
2007-08-03 09:52:52 +00:00
|
|
|
CLUTTER_Z_AXIS,
|
|
|
|
45.0);
|
2007-04-30 08:39:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PATH_BSPLINE:
|
2008-12-05 13:13:37 +00:00
|
|
|
{
|
|
|
|
ClutterPath *path = clutter_path_new ();
|
|
|
|
clutter_path_set_description (path, knots_bspline);
|
|
|
|
p_behave = clutter_behaviour_path_new (alpha, path);
|
|
|
|
}
|
2007-04-30 08:39:31 +00:00
|
|
|
break;
|
2010-02-12 14:45:49 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
break;
|
2007-04-30 08:39:31 +00:00
|
|
|
}
|
|
|
|
|
2006-12-04 16:26:35 +00:00
|
|
|
clutter_behaviour_apply (p_behave, group);
|
2006-10-22 23:33:14 +00:00
|
|
|
|
|
|
|
/* start the timeline and thus the animations */
|
2006-08-15 20:28:41 +00:00
|
|
|
clutter_timeline_start (timeline);
|
|
|
|
|
2006-12-12 20:20:04 +00:00
|
|
|
clutter_actor_show_all (stage);
|
2006-08-15 20:28:41 +00:00
|
|
|
|
|
|
|
clutter_main();
|
|
|
|
|
2006-12-04 16:26:35 +00:00
|
|
|
g_object_unref (o_behave);
|
|
|
|
g_object_unref (p_behave);
|
|
|
|
|
2006-08-15 20:28:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|