2010-08-12 16:39:59 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
|
|
|
static const ClutterColor stage_color = { 0x33, 0x33, 0x55, 0xff };
|
|
|
|
|
2010-08-16 15:16:07 +00:00
|
|
|
static gchar *source = NULL;
|
|
|
|
static gchar *target = NULL;
|
|
|
|
static guint duration = 1000;
|
|
|
|
|
|
|
|
static GOptionEntry entries[] = {
|
|
|
|
{
|
|
|
|
"source", 's',
|
|
|
|
0,
|
|
|
|
G_OPTION_ARG_FILENAME, &source,
|
|
|
|
"The source image of the cross-fade", "FILE"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"target", 't',
|
|
|
|
0,
|
|
|
|
G_OPTION_ARG_FILENAME, &target,
|
|
|
|
"The target image of the cross-fade", "FILE"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"duration", 'd',
|
|
|
|
0,
|
|
|
|
G_OPTION_ARG_INT, &duration,
|
|
|
|
"The duration of the cross-fade, in milliseconds", "MSECS"
|
|
|
|
},
|
|
|
|
|
|
|
|
{ NULL }
|
|
|
|
};
|
2010-08-12 16:39:59 +00:00
|
|
|
|
|
|
|
static gboolean
|
2010-08-16 15:16:07 +00:00
|
|
|
load_image (ClutterTexture *texture,
|
|
|
|
gchar *image_path)
|
2010-08-12 16:39:59 +00:00
|
|
|
{
|
|
|
|
GError *error = NULL;
|
2010-08-16 15:16:07 +00:00
|
|
|
|
|
|
|
gboolean success = clutter_texture_set_from_file (CLUTTER_TEXTURE (texture),
|
|
|
|
image_path,
|
|
|
|
&error);
|
2010-08-12 16:39:59 +00:00
|
|
|
|
|
|
|
if (error != NULL)
|
|
|
|
{
|
|
|
|
g_warning ("Error loading %s\n%s", image_path, error->message);
|
|
|
|
g_error_free (error);
|
2010-08-16 15:16:07 +00:00
|
|
|
exit (EXIT_FAILURE);
|
2010-08-12 16:39:59 +00:00
|
|
|
}
|
|
|
|
|
2010-08-16 15:16:07 +00:00
|
|
|
return success;
|
2010-08-12 16:39:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2010-08-16 15:16:07 +00:00
|
|
|
clutter_init_with_args (&argc, &argv,
|
|
|
|
" - cross-fade", entries,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (source == NULL || target == NULL)
|
2010-08-12 16:39:59 +00:00
|
|
|
{
|
2010-08-16 15:16:07 +00:00
|
|
|
g_print ("Usage: %s -s <source> -t <target> [-d <duration>]\n", argv[0]);
|
2010-08-12 16:39:59 +00:00
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
/* UI */
|
|
|
|
ClutterActor *stage;
|
|
|
|
ClutterLayoutManager *layout;
|
|
|
|
ClutterActor *box;
|
2010-08-16 15:16:07 +00:00
|
|
|
ClutterActor *front, *back;
|
|
|
|
ClutterState *transitions;
|
2010-08-12 16:39:59 +00:00
|
|
|
|
|
|
|
clutter_init (&argc, &argv);
|
|
|
|
|
|
|
|
stage = clutter_stage_get_default ();
|
|
|
|
clutter_stage_set_title (CLUTTER_STAGE (stage), "cross-fade");
|
2010-08-16 15:16:07 +00:00
|
|
|
clutter_actor_set_size (stage, 600, 600);
|
|
|
|
clutter_actor_show (stage);
|
|
|
|
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
|
2010-08-12 16:39:59 +00:00
|
|
|
|
|
|
|
layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
|
|
|
|
CLUTTER_BIN_ALIGNMENT_CENTER);
|
|
|
|
|
|
|
|
box = clutter_box_new (layout);
|
2010-08-16 15:16:07 +00:00
|
|
|
clutter_actor_set_size (box, 600, 600);
|
2010-08-12 16:39:59 +00:00
|
|
|
|
2010-08-16 15:16:07 +00:00
|
|
|
back = clutter_texture_new ();
|
|
|
|
clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (back), TRUE);
|
2010-08-12 16:39:59 +00:00
|
|
|
|
2010-08-16 15:16:07 +00:00
|
|
|
front = clutter_texture_new ();
|
|
|
|
clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (front), TRUE);
|
2010-08-12 16:39:59 +00:00
|
|
|
|
2010-08-16 15:16:07 +00:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (box), back);
|
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (box), front);
|
2010-08-12 16:39:59 +00:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), box);
|
|
|
|
|
|
|
|
/* animations */
|
2010-08-16 15:16:07 +00:00
|
|
|
transitions = clutter_state_new ();
|
|
|
|
clutter_state_set (transitions, NULL, "show-front",
|
|
|
|
front, "opacity", CLUTTER_EASE_IN_CUBIC, 255,
|
|
|
|
back, "opacity", CLUTTER_EASE_IN_CUBIC, 0,
|
2010-08-12 16:39:59 +00:00
|
|
|
NULL);
|
2010-08-16 15:16:07 +00:00
|
|
|
clutter_state_set (transitions, NULL, "show-back",
|
|
|
|
front, "opacity", CLUTTER_LINEAR, 0,
|
|
|
|
back, "opacity", CLUTTER_LINEAR, 255,
|
2010-08-12 16:39:59 +00:00
|
|
|
NULL);
|
2010-08-16 15:16:07 +00:00
|
|
|
clutter_state_set_duration (transitions, NULL, NULL, duration);
|
|
|
|
|
|
|
|
/* make the back opaque and front transparent */
|
|
|
|
clutter_state_warp_to_state (transitions, "show-back");
|
2010-08-12 16:39:59 +00:00
|
|
|
|
2010-08-16 15:16:07 +00:00
|
|
|
/* load the first image into the back */
|
|
|
|
load_image (CLUTTER_TEXTURE (back), source);
|
2010-08-12 16:39:59 +00:00
|
|
|
|
2010-08-16 15:16:07 +00:00
|
|
|
/* load the second image into the front */
|
|
|
|
load_image (CLUTTER_TEXTURE (front), target);
|
|
|
|
|
|
|
|
/* fade in the front texture and fade out the back texture */
|
|
|
|
clutter_state_set_state (transitions, "show-front");
|
2010-08-12 16:39:59 +00:00
|
|
|
|
|
|
|
clutter_actor_show (stage);
|
|
|
|
|
|
|
|
clutter_main ();
|
|
|
|
|
2010-08-16 15:16:07 +00:00
|
|
|
g_object_unref (transitions);
|
2010-08-12 16:39:59 +00:00
|
|
|
|
|
|
|
if (error != NULL)
|
|
|
|
g_error_free (error);
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|