#include <gtk/gtk.h>
#include "gtktimeline.h"
#include <math.h>

typedef struct {
	GtkTimeline *timeline;
	GtkWidget   *window;
	GtkWidget   *label;
} DemoData;

static void
on_timeline_frame (GtkTimeline *timeline,
		   gdouble      progress,
		   gpointer     user_data)
{
	DemoData *data = (DemoData *) user_data;
	gdouble angle;

	angle = progress * 360;
	gtk_label_set_angle (GTK_LABEL (data->label), angle);
	gtk_misc_set_alignment (GTK_MISC (data->label), (gfloat) progress, 0.5);
}

static gdouble
sinusoidal_progress (gdouble progress)
{
	return (sinf (progress * 2 * G_PI) / 2 ) + 0.5;
}

static DemoData *
create_demo_data (void)
{
	DemoData *data;

	data = g_slice_new0 (DemoData);

	data->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title (GTK_WINDOW (data->window), "An useless animation");

	g_signal_connect (data->window, "delete-event",
			  G_CALLBACK (gtk_main_quit), NULL);

	data->label = gtk_label_new ("An useless animation");
	gtk_container_add (GTK_CONTAINER (data->window), data->label);

	data->timeline = GTK_TIMELINE (gtk_timeline_new (120));
	gtk_timeline_set_loop (data->timeline, TRUE);
	gtk_timeline_set_progress_func (data->timeline, sinusoidal_progress);

	g_signal_connect (data->timeline, "frame",
			  G_CALLBACK (on_timeline_frame), data);

	gtk_timeline_start (data->timeline);

	return data;
}

int
main (int argc, gchar *argv[])
{
	DemoData *data;

	gtk_init (&argc, &argv);
	data = create_demo_data ();

	gtk_widget_show_all (data->window);
	gtk_main ();

	return 0;
}
