2010-08-12 12:39:59 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
2010-08-16 11:16:07 -04: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 12:39:59 -04:00
|
|
|
|
2010-08-17 10:46:48 -04:00
|
|
|
static gboolean
|
|
|
|
start_animation (ClutterActor *actor,
|
|
|
|
ClutterEvent *event,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
ClutterState *transitions = CLUTTER_STATE (user_data);
|
|
|
|
clutter_state_set_state (transitions, "show-top");
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-08-12 12:39:59 -04:00
|
|
|
static gboolean
|
2010-08-16 11:16:07 -04:00
|
|
|
load_image (ClutterTexture *texture,
|
|
|
|
gchar *image_path)
|
2010-08-12 12:39:59 -04:00
|
|
|
{
|
|
|
|
GError *error = NULL;
|
2010-08-16 11:16:07 -04:00
|
|
|
|
|
|
|
gboolean success = clutter_texture_set_from_file (CLUTTER_TEXTURE (texture),
|
|
|
|
image_path,
|
|
|
|
&error);
|
2010-08-12 12:39:59 -04:00
|
|
|
|
|
|
|
if (error != NULL)
|
|
|
|
{
|
|
|
|
g_warning ("Error loading %s\n%s", image_path, error->message);
|
|
|
|
g_error_free (error);
|
2010-08-16 11:16:07 -04:00
|
|
|
exit (EXIT_FAILURE);
|
2010-08-12 12:39:59 -04:00
|
|
|
}
|
|
|
|
|
2010-08-16 11:16:07 -04:00
|
|
|
return success;
|
2010-08-12 12:39:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2010-11-12 04:32:04 -05:00
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
/* UI */
|
|
|
|
ClutterActor *stage;
|
|
|
|
ClutterLayoutManager *layout;
|
|
|
|
ClutterActor *box;
|
|
|
|
ClutterActor *top, *bottom;
|
|
|
|
ClutterState *transitions;
|
|
|
|
|
2011-02-21 19:44:55 -05:00
|
|
|
if (clutter_init_with_args (&argc, &argv,
|
|
|
|
" - cross-fade", entries,
|
|
|
|
NULL,
|
|
|
|
NULL) != CLUTTER_INIT_SUCCESS)
|
|
|
|
return 1;
|
2010-08-16 11:16:07 -04:00
|
|
|
|
|
|
|
if (source == NULL || target == NULL)
|
2010-08-12 12:39:59 -04:00
|
|
|
{
|
2010-08-16 11:16:07 -04:00
|
|
|
g_print ("Usage: %s -s <source> -t <target> [-d <duration>]\n", argv[0]);
|
2010-08-12 12:39:59 -04:00
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2011-02-21 19:44:55 -05:00
|
|
|
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
|
|
|
|
return 1;
|
2010-08-12 12:39:59 -04:00
|
|
|
|
2011-11-09 12:49:25 -05:00
|
|
|
stage = clutter_stage_new ();
|
2010-08-12 12:39:59 -04:00
|
|
|
clutter_stage_set_title (CLUTTER_STAGE (stage), "cross-fade");
|
2010-08-17 10:46:48 -04:00
|
|
|
clutter_actor_set_size (stage, 400, 300);
|
2010-08-16 11:16:07 -04:00
|
|
|
clutter_actor_show (stage);
|
|
|
|
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
|
2010-08-12 12:39:59 -04:00
|
|
|
|
|
|
|
layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
|
|
|
|
CLUTTER_BIN_ALIGNMENT_CENTER);
|
|
|
|
|
|
|
|
box = clutter_box_new (layout);
|
2010-08-17 10:46:48 -04:00
|
|
|
clutter_actor_set_size (box, 400, 300);
|
2010-08-12 12:39:59 -04:00
|
|
|
|
2010-08-17 06:51:33 -04:00
|
|
|
bottom = clutter_texture_new ();
|
|
|
|
top = clutter_texture_new ();
|
2010-08-12 12:39:59 -04:00
|
|
|
|
2010-08-17 06:51:33 -04:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (box), bottom);
|
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (box), top);
|
2010-08-12 12:39:59 -04:00
|
|
|
clutter_container_add_actor (CLUTTER_CONTAINER (stage), box);
|
|
|
|
|
2010-08-17 06:51:33 -04:00
|
|
|
/* load the first image into the bottom */
|
|
|
|
load_image (CLUTTER_TEXTURE (bottom), source);
|
2010-08-17 05:56:06 -04:00
|
|
|
|
2010-08-17 06:51:33 -04:00
|
|
|
/* load the second image into the top */
|
|
|
|
load_image (CLUTTER_TEXTURE (top), target);
|
2010-08-17 05:56:06 -04:00
|
|
|
|
2010-08-12 12:39:59 -04:00
|
|
|
/* animations */
|
2010-08-16 11:16:07 -04:00
|
|
|
transitions = clutter_state_new ();
|
2010-08-17 06:51:33 -04:00
|
|
|
clutter_state_set (transitions, NULL, "show-bottom",
|
|
|
|
top, "opacity", CLUTTER_LINEAR, 0,
|
|
|
|
bottom, "opacity", CLUTTER_LINEAR, 255,
|
2010-08-12 12:39:59 -04:00
|
|
|
NULL);
|
2010-08-17 06:51:33 -04:00
|
|
|
clutter_state_set (transitions, NULL, "show-top",
|
|
|
|
top, "opacity", CLUTTER_EASE_IN_CUBIC, 255,
|
|
|
|
bottom, "opacity", CLUTTER_EASE_IN_CUBIC, 0,
|
2010-08-17 05:56:06 -04:00
|
|
|
NULL);
|
2010-08-16 11:16:07 -04:00
|
|
|
clutter_state_set_duration (transitions, NULL, NULL, duration);
|
|
|
|
|
2010-08-17 06:51:33 -04:00
|
|
|
/* make the bottom opaque and top transparent */
|
|
|
|
clutter_state_warp_to_state (transitions, "show-bottom");
|
2010-08-12 12:39:59 -04:00
|
|
|
|
2010-08-17 10:46:48 -04:00
|
|
|
/* on key press, fade in the top texture and fade out the bottom texture */
|
|
|
|
g_signal_connect (stage,
|
|
|
|
"key-press-event",
|
|
|
|
G_CALLBACK (start_animation),
|
|
|
|
transitions);
|
2010-08-12 12:39:59 -04:00
|
|
|
|
|
|
|
clutter_actor_show (stage);
|
|
|
|
|
|
|
|
clutter_main ();
|
|
|
|
|
2010-08-16 11:16:07 -04:00
|
|
|
g_object_unref (transitions);
|
2010-08-12 12:39:59 -04:00
|
|
|
|
|
|
|
if (error != NULL)
|
|
|
|
g_error_free (error);
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|