2007-10-08 11:03:22 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2009-10-21 11:15:18 -04:00
|
|
|
#include <math.h>
|
|
|
|
|
2007-10-08 11:03:22 -04:00
|
|
|
#include <glib.h>
|
2008-11-07 14:32:28 -05:00
|
|
|
#include <gmodule.h>
|
2007-10-08 11:03:22 -04:00
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
2007-10-18 08:31:07 -04:00
|
|
|
static ClutterScript *script = NULL;
|
|
|
|
static guint merge_id = 0;
|
|
|
|
|
2019-01-20 03:03:50 -05:00
|
|
|
int
|
|
|
|
test_script_main (int argc, char *argv[]);
|
|
|
|
|
2007-10-18 08:31:07 -04:00
|
|
|
static const gchar *test_unmerge =
|
2008-05-28 08:20:54 -04:00
|
|
|
"["
|
|
|
|
" {"
|
|
|
|
" \"id\" : \"main-stage\","
|
|
|
|
" \"type\" : \"ClutterStage\","
|
|
|
|
" \"children\" : [ \"blue-button\" ]"
|
|
|
|
" },"
|
|
|
|
" {"
|
|
|
|
" \"id\" : \"blue-button\","
|
|
|
|
" \"type\" : \"ClutterRectangle\","
|
|
|
|
" \"color\" : \"#0000ffff\","
|
|
|
|
" \"x\" : 350,"
|
|
|
|
" \"y\" : 50,"
|
|
|
|
" \"width\" : 100,"
|
|
|
|
" \"height\" : 100,"
|
|
|
|
" \"visible\" : true,"
|
|
|
|
" \"reactive\" : true"
|
|
|
|
" }"
|
|
|
|
"]";
|
2007-10-18 08:31:07 -04:00
|
|
|
|
2007-10-09 09:29:03 -04:00
|
|
|
static const gchar *test_behaviour =
|
2007-10-09 12:21:04 -04:00
|
|
|
"["
|
|
|
|
" {"
|
|
|
|
" \"id\" : \"main-timeline\","
|
|
|
|
" \"type\" : \"ClutterTimeline\","
|
2007-10-25 10:46:02 -04:00
|
|
|
" \"duration\" : 5000,"
|
2007-10-09 12:21:04 -04:00
|
|
|
" \"loop\" : true"
|
|
|
|
" },"
|
|
|
|
" {"
|
2009-10-21 11:15:18 -04:00
|
|
|
" \"id\" : \"sine-alpha\","
|
|
|
|
" \"type\" : \"ClutterAlpha\","
|
|
|
|
" \"function\" : \"sine_alpha\","
|
|
|
|
" \"timeline\" : \"main-timeline\""
|
|
|
|
" },"
|
|
|
|
" {"
|
2007-10-25 10:46:02 -04:00
|
|
|
" \"id\" : \"path-behaviour\","
|
|
|
|
" \"type\" : \"ClutterBehaviourPath\","
|
2008-12-05 08:13:37 -05:00
|
|
|
" \"path\" : \"M 50 50 L 100 100\","
|
2007-10-25 10:46:02 -04:00
|
|
|
" \"alpha\" : {"
|
|
|
|
" \"timeline\" : \"main-timeline\","
|
2009-10-21 11:15:18 -04:00
|
|
|
" \"function\" : \"double_ramp_alpha\""
|
2007-10-25 10:46:02 -04:00
|
|
|
" }"
|
|
|
|
" },"
|
|
|
|
" {"
|
2007-10-09 12:21:04 -04:00
|
|
|
" \"id\" : \"rotate-behaviour\","
|
|
|
|
" \"type\" : \"ClutterBehaviourRotate\","
|
2007-11-13 08:21:56 -05:00
|
|
|
" \"angle-start\" : 0.0,"
|
2007-10-09 12:21:04 -04:00
|
|
|
" \"angle-end\" : 360.0,"
|
2007-10-10 10:29:29 -04:00
|
|
|
" \"axis\" : \"y-axis\","
|
2009-10-21 11:15:18 -04:00
|
|
|
" \"alpha\" : \"sine-alpha\""
|
2007-10-09 12:21:04 -04:00
|
|
|
" },"
|
|
|
|
" {"
|
|
|
|
" \"id\" : \"fade-behaviour\","
|
|
|
|
" \"type\" : \"ClutterBehaviourOpacity\","
|
|
|
|
" \"opacity-start\" : 255,"
|
|
|
|
" \"opacity-end\" : 0,"
|
|
|
|
" \"alpha\" : {"
|
2009-10-21 11:15:18 -04:00
|
|
|
" \"id\" : \"fade-alpha\","
|
|
|
|
" \"type\" : \"ClutterAlpha\","
|
2007-10-09 12:21:04 -04:00
|
|
|
" \"timeline\" : \"main-timeline\","
|
2009-10-21 11:15:18 -04:00
|
|
|
" \"mode\" : \"linear\""
|
2007-10-09 12:21:04 -04:00
|
|
|
" }"
|
2007-10-09 09:29:03 -04:00
|
|
|
" }"
|
2007-10-09 12:21:04 -04:00
|
|
|
"]";
|
2007-10-09 09:29:03 -04:00
|
|
|
|
2007-10-18 08:31:07 -04:00
|
|
|
static gboolean
|
|
|
|
blue_button_press (ClutterActor *actor,
|
|
|
|
ClutterButtonEvent *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2009-03-17 10:12:01 -04:00
|
|
|
g_print ("[*] Pressed '%s'\n", clutter_get_script_id (G_OBJECT (actor)));
|
2007-10-25 10:46:02 -04:00
|
|
|
g_print ("[*] Unmerging objects with merge id: %d\n", merge_id);
|
|
|
|
|
2007-10-18 08:31:07 -04:00
|
|
|
clutter_script_unmerge_objects (script, merge_id);
|
2007-10-25 10:46:02 -04:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
red_button_press (ClutterActor *actor,
|
|
|
|
ClutterButtonEvent *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GObject *timeline;
|
|
|
|
|
2009-03-17 10:12:01 -04:00
|
|
|
g_print ("[*] Pressed '%s'\n", clutter_get_script_id (G_OBJECT (actor)));
|
2007-11-14 06:32:24 -05:00
|
|
|
|
2007-10-25 10:46:02 -04:00
|
|
|
timeline = clutter_script_get_object (script, "main-timeline");
|
|
|
|
g_assert (CLUTTER_IS_TIMELINE (timeline));
|
|
|
|
|
|
|
|
if (!clutter_timeline_is_playing (CLUTTER_TIMELINE (timeline)))
|
|
|
|
clutter_timeline_start (CLUTTER_TIMELINE (timeline));
|
|
|
|
else
|
|
|
|
clutter_timeline_pause (CLUTTER_TIMELINE (timeline));
|
|
|
|
|
|
|
|
return TRUE;
|
2007-10-18 08:31:07 -04:00
|
|
|
}
|
|
|
|
|
2008-11-07 14:32:28 -05:00
|
|
|
G_MODULE_EXPORT int
|
|
|
|
test_script_main (int argc, char *argv[])
|
2007-10-08 11:03:22 -04:00
|
|
|
{
|
2007-12-21 10:25:00 -05:00
|
|
|
GObject *stage, *blue_button, *red_button;
|
2007-10-09 09:29:03 -04:00
|
|
|
GError *error = NULL;
|
2009-11-05 12:30:33 -05:00
|
|
|
gchar *file;
|
2007-10-27 15:08:59 -04:00
|
|
|
gint res;
|
2007-10-08 11:03:22 -04:00
|
|
|
|
2011-02-21 19:19:35 -05:00
|
|
|
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
|
|
|
|
return 1;
|
2007-10-08 11:03:22 -04:00
|
|
|
|
|
|
|
script = clutter_script_new ();
|
2007-10-09 09:29:03 -04:00
|
|
|
g_assert (CLUTTER_IS_SCRIPT (script));
|
|
|
|
|
|
|
|
clutter_script_load_from_data (script, test_behaviour, -1, &error);
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
g_print ("*** Error:\n"
|
|
|
|
"*** %s\n", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
g_object_unref (script);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2009-11-05 12:30:33 -05:00
|
|
|
|
|
|
|
file = g_build_filename (TESTS_DATADIR, "test-script.json", NULL);
|
|
|
|
clutter_script_load_from_file (script, file, &error);
|
2007-10-08 11:03:22 -04:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
g_print ("*** Error:\n"
|
|
|
|
"*** %s\n", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
g_object_unref (script);
|
2009-11-05 12:30:33 -05:00
|
|
|
g_free (file);
|
2007-10-08 11:03:22 -04:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2009-11-05 12:30:33 -05:00
|
|
|
g_free (file);
|
|
|
|
|
2007-10-18 08:31:07 -04:00
|
|
|
merge_id = clutter_script_load_from_data (script, test_unmerge, -1, &error);
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
g_print ("*** Error:\n"
|
|
|
|
"*** %s\n", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
g_object_unref (script);
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2007-11-15 10:24:43 -05:00
|
|
|
clutter_script_connect_signals (script, NULL);
|
|
|
|
|
2007-10-27 15:08:59 -04:00
|
|
|
res = clutter_script_get_objects (script,
|
|
|
|
"main-stage", &stage,
|
|
|
|
"red-button", &red_button,
|
|
|
|
"blue-button", &blue_button,
|
|
|
|
NULL);
|
|
|
|
g_assert (res == 3);
|
|
|
|
|
2007-10-09 12:21:04 -04:00
|
|
|
clutter_actor_show (CLUTTER_ACTOR (stage));
|
2007-10-08 11:03:22 -04:00
|
|
|
|
2007-10-25 10:46:02 -04:00
|
|
|
g_signal_connect (red_button,
|
|
|
|
"button-press-event",
|
|
|
|
G_CALLBACK (red_button_press),
|
|
|
|
NULL);
|
|
|
|
|
2007-10-18 08:31:07 -04:00
|
|
|
g_signal_connect (blue_button,
|
|
|
|
"button-press-event",
|
|
|
|
G_CALLBACK (blue_button_press),
|
|
|
|
NULL);
|
|
|
|
|
2007-10-08 11:03:22 -04:00
|
|
|
clutter_main ();
|
|
|
|
|
|
|
|
g_object_unref (script);
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|