2009-03-11 14:26:30 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <gmodule.h>
|
2010-11-06 11:54:21 -04:00
|
|
|
|
|
|
|
#undef CLUTTER_DISABLE_DEPRECATED
|
2009-03-11 14:26:30 -04:00
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
2009-06-06 10:57:29 -04:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
LOAD_SYNC,
|
|
|
|
LOAD_DATA_ASYNC,
|
|
|
|
LOAD_ASYNC
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_load_finished (ClutterTexture *texture,
|
|
|
|
const GError *error,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
gint load_type = GPOINTER_TO_INT (user_data);
|
|
|
|
const gchar *load_str = NULL;
|
|
|
|
|
|
|
|
switch (load_type)
|
|
|
|
{
|
|
|
|
case LOAD_SYNC:
|
|
|
|
load_str = "synchronous loading";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOAD_DATA_ASYNC:
|
|
|
|
load_str = "asynchronous data loading";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LOAD_ASYNC:
|
|
|
|
load_str = "asynchronous loading";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error != NULL)
|
|
|
|
g_print ("%s failed: %s\n", load_str, error->message);
|
|
|
|
else
|
|
|
|
g_print ("%s successful\n", load_str);
|
|
|
|
}
|
2009-03-12 06:14:40 -04:00
|
|
|
|
2009-11-05 12:30:33 -05:00
|
|
|
static void
|
|
|
|
size_change_cb (ClutterTexture *texture,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
gpointer user_data)
|
2009-03-12 06:14:40 -04:00
|
|
|
{
|
|
|
|
clutter_actor_set_size (user_data, width, height);
|
|
|
|
}
|
|
|
|
|
2009-11-05 12:30:33 -05:00
|
|
|
static
|
|
|
|
gboolean task (gpointer user_data)
|
2009-03-11 14:26:30 -04:00
|
|
|
{
|
|
|
|
ClutterTimeline *timeline;
|
|
|
|
ClutterAlpha *alpha;
|
|
|
|
ClutterBehaviour *depth_behavior;
|
|
|
|
ClutterActor *image[4];
|
2009-03-12 06:14:40 -04:00
|
|
|
ClutterActor *clone[4];
|
|
|
|
ClutterActor *stage;
|
2009-11-05 12:30:33 -05:00
|
|
|
gchar *path = user_data;
|
2009-03-11 14:26:30 -04:00
|
|
|
gint i;
|
|
|
|
|
|
|
|
stage = clutter_stage_get_default ();
|
2009-06-06 10:57:29 -04:00
|
|
|
|
|
|
|
image[0] = g_object_new (CLUTTER_TYPE_TEXTURE, NULL);
|
|
|
|
g_signal_connect (image[0], "load-finished",
|
|
|
|
G_CALLBACK (on_load_finished),
|
|
|
|
GINT_TO_POINTER (LOAD_SYNC));
|
|
|
|
|
2009-03-11 14:26:30 -04:00
|
|
|
image[1] = g_object_new (CLUTTER_TYPE_TEXTURE,
|
2009-03-12 06:38:39 -04:00
|
|
|
"load-data-async", TRUE,
|
2009-03-11 14:26:30 -04:00
|
|
|
NULL);
|
2009-06-06 10:57:29 -04:00
|
|
|
g_signal_connect (image[1], "load-finished",
|
|
|
|
G_CALLBACK (on_load_finished),
|
|
|
|
GINT_TO_POINTER (LOAD_DATA_ASYNC));
|
2009-03-11 14:26:30 -04:00
|
|
|
image[2] = g_object_new (CLUTTER_TYPE_TEXTURE,
|
2009-03-12 06:38:39 -04:00
|
|
|
"load-async", TRUE,
|
2009-03-11 14:26:30 -04:00
|
|
|
NULL);
|
2009-06-06 10:57:29 -04:00
|
|
|
g_signal_connect (image[2], "load-finished",
|
|
|
|
G_CALLBACK (on_load_finished),
|
|
|
|
GINT_TO_POINTER (LOAD_ASYNC));
|
|
|
|
|
2009-11-05 12:30:33 -05:00
|
|
|
for (i = 0; i < 3; i++)
|
2010-06-08 06:19:28 -04:00
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
clutter_texture_set_from_file (CLUTTER_TEXTURE (image[i]), path, &error);
|
|
|
|
if (error != NULL)
|
|
|
|
g_error ("Unable to load image at '%s': %s",
|
|
|
|
path != NULL ? path : "<unknown>",
|
|
|
|
error->message);
|
|
|
|
}
|
2009-06-06 10:57:29 -04:00
|
|
|
|
2009-11-05 12:30:33 -05:00
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
clutter_container_add (CLUTTER_CONTAINER (stage), image[i], NULL);
|
2009-06-06 10:57:29 -04:00
|
|
|
|
2009-11-05 12:30:33 -05:00
|
|
|
for (i = 0; i < 3; i++)
|
2009-03-12 06:14:40 -04:00
|
|
|
{
|
|
|
|
clutter_actor_set_position (image[i], 50+i*100, 0+i*50);
|
|
|
|
clone[i]=clutter_clone_new (image[i]);
|
2009-03-12 07:48:44 -04:00
|
|
|
g_signal_connect (image[i], "size-change",
|
|
|
|
G_CALLBACK (size_change_cb), clone[i]);
|
2009-03-12 06:14:40 -04:00
|
|
|
clutter_container_add (CLUTTER_CONTAINER (stage), clone[i], NULL);
|
|
|
|
clutter_actor_set_position (clone[i], 50+i*100, 150+i*50+100);
|
|
|
|
}
|
2009-03-11 14:26:30 -04:00
|
|
|
|
2009-11-05 12:30:33 -05:00
|
|
|
for (i = 0; i < 3; i++)
|
2009-03-11 14:26:30 -04:00
|
|
|
{
|
2009-06-04 08:05:12 -04:00
|
|
|
timeline = clutter_timeline_new (5000);
|
2009-03-11 14:26:30 -04:00
|
|
|
alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR);
|
|
|
|
depth_behavior = clutter_behaviour_depth_new (alpha, -2500, 0);
|
|
|
|
clutter_behaviour_apply (depth_behavior, image[i]);
|
|
|
|
clutter_timeline_start (timeline);
|
|
|
|
}
|
2009-11-05 12:30:33 -05:00
|
|
|
|
2009-03-12 06:14:40 -04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
G_MODULE_EXPORT gint
|
|
|
|
test_texture_async_main (int argc, char *argv[])
|
|
|
|
{
|
2009-11-05 12:30:33 -05:00
|
|
|
ClutterActor *stage;
|
|
|
|
ClutterColor stage_color = { 0x12, 0x34, 0x56, 0xff };
|
|
|
|
gchar *path;
|
2009-03-12 06:14:40 -04:00
|
|
|
|
|
|
|
clutter_init (&argc, &argv);
|
|
|
|
|
2009-03-12 07:48:44 -04:00
|
|
|
g_thread_init (NULL);
|
2009-03-12 06:14:40 -04:00
|
|
|
stage = clutter_stage_get_default ();
|
|
|
|
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
|
|
|
|
|
2009-03-11 14:26:30 -04:00
|
|
|
clutter_actor_show (stage);
|
2009-03-12 06:14:40 -04:00
|
|
|
g_signal_connect (stage,
|
|
|
|
"button-press-event", G_CALLBACK (clutter_main_quit),
|
|
|
|
NULL);
|
|
|
|
|
2010-06-08 06:19:28 -04:00
|
|
|
path = (argc > 1)
|
2009-11-05 12:30:33 -05:00
|
|
|
? g_strdup (argv[1])
|
|
|
|
: g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
|
2009-03-12 06:14:40 -04:00
|
|
|
|
2010-06-08 06:19:28 -04:00
|
|
|
clutter_threads_add_timeout (500, task, path);
|
2009-03-11 14:26:30 -04:00
|
|
|
|
|
|
|
clutter_main ();
|
|
|
|
|
2009-11-05 12:30:33 -05:00
|
|
|
g_free (path);
|
|
|
|
|
2009-03-11 14:26:30 -04:00
|
|
|
/*g_object_unref (depth_behavior);
|
|
|
|
g_object_unref (timeline);*/
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|