summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDanielle Madeley <danielle.madeley@collabora.co.uk>2009-08-24 13:45:28 +1000
committerDanielle Madeley <danielle.madeley@collabora.co.uk>2009-11-18 12:17:15 +1100
commiteefbf3f9dc1a2f520788c3420081b1242a3f6db9 (patch)
tree8b0a2f154615c5fc7b3f424408314dc5ecebafe8 /examples
parent984a6546e04e20918f0f8730901c9190e9e92fd5 (diff)
downloadclutter-gtk-eefbf3f9dc1a2f520788c3420081b1242a3f6db9.tar.gz
Add some optional animation to the reparenting test
Diffstat (limited to 'examples')
-rw-r--r--examples/reparenting-test.c47
1 files changed, 46 insertions, 1 deletions
diff --git a/examples/reparenting-test.c b/examples/reparenting-test.c
index 1263ede..06a3e18 100644
--- a/examples/reparenting-test.c
+++ b/examples/reparenting-test.c
@@ -9,6 +9,10 @@
#include <clutter/clutter.h>
#include <clutter-gtk/clutter-gtk.h>
+#include <math.h>
+
+static gulong CLUTTER_COS_SQUARED = CLUTTER_ANIMATION_LAST;
+
static GtkWidget *contents = NULL;
static GtkWidget *bin1 = NULL;
static GtkWidget *bin2 = NULL;
@@ -40,13 +44,38 @@ reparent_cb (GtkButton *button, gpointer user_data)
gtk_widget_reparent (contents, newparent);
}
+static gdouble
+clutter_cos_squared (ClutterAlpha *alpha, gpointer user_data)
+{
+ ClutterTimeline *timeline = clutter_alpha_get_timeline (alpha);
+ gdouble p = clutter_timeline_get_progress (timeline);
+
+ return pow (cos (M_PI * p), 2);
+}
+
+static void
+animate_cb (GtkToggleButton *toggle, ClutterTimeline *timeline)
+{
+ if (gtk_toggle_button_get_active (toggle))
+ {
+ clutter_timeline_start (timeline);
+ }
+ else
+ {
+ clutter_timeline_pause (timeline);
+ }
+}
+
int
main (int argc, char **argv)
{
gtk_clutter_init (&argc, &argv);
+ /* register the alpha func */
+ CLUTTER_COS_SQUARED = clutter_alpha_register_func (clutter_cos_squared, NULL);
+
GtkWidget *window = gtk_clutter_window_new ();
- GtkWidget *table = gtk_table_new (2, 2, FALSE);
+ GtkWidget *table = gtk_table_new (2, 3, FALSE);
gtk_container_add (GTK_CONTAINER (window), table);
@@ -61,19 +90,35 @@ main (int argc, char **argv)
GtkWidget *button = gtk_button_new_with_label ("Reparent");
gtk_table_attach_defaults (GTK_TABLE (table), button, 0, 2, 1, 2);
+ GtkWidget *toggle = gtk_toggle_button_new_with_label ("Animate RHS");
+ gtk_table_attach_defaults (GTK_TABLE (table), toggle, 0, 2, 2, 3);
+
contents = gtk_image_new_from_file ("redhand.png");
gtk_container_add (GTK_CONTAINER (bin1), contents);
+ /* put both sides of the table into a sizegroup to avoid resizing */
GtkSizeGroup *sizegroup = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
gtk_size_group_add_widget (sizegroup, bin1);
gtk_size_group_add_widget (sizegroup, standin);
+ /* add an optional animation to the actor */
+ ClutterAnimation *animation = clutter_actor_animate (actor,
+ CLUTTER_COS_SQUARED, 1200,
+ "opacity", 0x0,
+ NULL);
+ ClutterTimeline *timeline = clutter_animation_get_timeline (animation);
+ clutter_timeline_set_loop (timeline, TRUE);
+ clutter_timeline_stop (timeline);
+
g_signal_connect_swapped (window, "destroy",
G_CALLBACK (gtk_main_quit), NULL);
g_signal_connect (button, "clicked",
G_CALLBACK (reparent_cb), NULL);
+ g_signal_connect (toggle, "toggled",
+ G_CALLBACK (animate_cb), timeline);
+
gtk_widget_show_all (window);
gtk_main ();
}