From ea74e224c39a37385ce00abe76e673fa4d0a0c00 Mon Sep 17 00:00:00 2001 From: "Neil J. Patel" Date: Mon, 11 Jun 2007 16:04:37 +0000 Subject: [PATCH] 2007-06-11 Neil Jagdish Patel * examples/Makefile.am: * examples/gtk-clutter-events.c: (on_gtk_entry_changed), (on_x_changed), (on_y_changed), (on_z_changed), (on_opacity_changed), (create_colors), (main): Added another example whihc shows some interaction between gtk and the stage. * examples/gtk-clutter-test.c: (main): Updated to work with clutter-0.3 --- examples/Makefile.am | 9 +- examples/gtk-clutter-events.c | 193 +++++++++++++++++++++++++++++++++++++++++ examples/gtk-clutter-test.c | 2 +- 3 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 examples/gtk-clutter-events.c diff --git a/examples/Makefile.am b/examples/Makefile.am index 14140b3..7fbc388 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,4 +1,4 @@ -noinst_PROGRAMS = gtk-clutter-test +noinst_PROGRAMS = gtk-clutter-test gtk-clutter-events INCLUDES = \ -I$(srcdir) \ @@ -13,4 +13,11 @@ gtk_clutter_test_LDADD = \ $(CLUTTER_LIBS) \ $(GTK_LIBS) +gtk_clutter_events_DEPENDENCIES = $(top_srcdir)/clutter-gtk/libcluttergtk-1.0.la +gtk_clutter_events_SOURCES = gtk-clutter-events.c +gtk_clutter_events_LDADD = \ + $(top_srcdir)/clutter-gtk/libcluttergtk-1.0.la \ + $(CLUTTER_LIBS) \ + $(GTK_LIBS) + EXTRA_DIST = redhand.png diff --git a/examples/gtk-clutter-events.c b/examples/gtk-clutter-events.c new file mode 100644 index 0000000..ee327af --- /dev/null +++ b/examples/gtk-clutter-events.c @@ -0,0 +1,193 @@ +#include +#include + +#include + +typedef struct { + + GtkWidget *window; + GtkWidget *popup; + GtkWidget *gtk_entry; + + ClutterActor *stage; + ClutterActor *hand; + ClutterActor *clutter_entry; + +} EventApp; + +static void +on_gtk_entry_changed (GtkEditable *editable, EventApp *app) +{ + const gchar *text = gtk_entry_get_text (GTK_ENTRY (editable)); + + clutter_entry_set_text (CLUTTER_ENTRY (app->clutter_entry), text); +} + +static void +on_x_changed (GtkSpinButton *button, EventApp *app) +{ + clutter_actor_rotate_x (app->hand, + gtk_spin_button_get_value (button), + clutter_actor_get_height (app->hand), + 0); +} + +static void +on_y_changed (GtkSpinButton *button, EventApp *app) +{ + clutter_actor_rotate_y (app->hand, + gtk_spin_button_get_value (button), + clutter_actor_get_width (app->hand) /2, + 0); +} + +static void +on_z_changed (GtkSpinButton *button, EventApp *app) +{ + clutter_actor_rotate_z (app->hand, + gtk_spin_button_get_value (button), + clutter_actor_get_width (app->hand) /2, + clutter_actor_get_height (app->hand)/2); +} + +static void +on_opacity_changed (GtkSpinButton *button, EventApp *app) +{ + clutter_actor_set_opacity (app->hand, gtk_spin_button_get_value (button)); +} + +/* Set the clutter colors form the current gtk theme */ +static void +create_colors (EventApp *app, ClutterColor *stage, ClutterColor *text) +{ + GtkStyle *style = gtk_widget_get_style (app->window); + GdkColor color; + + /* Set the stage color to base[NORMAL] */ + color = style->bg[GTK_STATE_NORMAL]; + stage->red = (guint8) ((color.red/65535.0) * 255); + stage->green = (guint8) ((color.green/65535.0) * 255); + stage->blue = (guint8) ((color.blue/65535.0) * 255); + g_print ("%d %d %d\n", stage->red, stage->green, stage->blue); + + /* Now the text color */ + color = style->text[GTK_STATE_NORMAL]; + text->red =(guint8) ((color.red/65535.0) * 255); + text->green = (guint8) ((color.green/65535.0) * 255); + text->blue = (guint8) ((color.blue/65535.0) * 255); +} + +gint +main (gint argc, gchar **argv) +{ + EventApp *app = g_new0 (EventApp, 1); + GtkWidget *widget, *vbox, *hbox, *button, *label, *box; + ClutterActor *actor; + GdkPixbuf *pixbuf = NULL; + guint width, height; + ClutterColor stage_color = {255, 255, 255, 255}; + ClutterColor text_color = {0, 0, 0, 255}; + + clutter_init (&argc, &argv); + gtk_init (&argc, &argv); + + + /* Create the inital gtk window and widgets, just like normal */ + widget = gtk_window_new (GTK_WINDOW_TOPLEVEL); + app->window = widget; + gtk_window_set_title (GTK_WINDOW (widget), "Gtk-Clutter Interaction demo"); + gtk_window_set_default_size (GTK_WINDOW (widget), 800, 600); + gtk_window_set_resizable (GTK_WINDOW (widget), FALSE); + gtk_container_set_border_width (GTK_CONTAINER (widget), 12); + g_signal_connect (G_OBJECT (widget), "destroy-event", + G_CALLBACK (gtk_main_quit), NULL); + + /* Create our layout box */ + vbox = gtk_vbox_new (FALSE, 12); + gtk_container_add (GTK_CONTAINER (app->window), vbox); + + widget = gtk_entry_new (); + app->gtk_entry = widget; + gtk_entry_set_text (GTK_ENTRY (widget), "Enter some text"); + gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0); + g_signal_connect (G_OBJECT (box), "changed", + G_CALLBACK (on_gtk_entry_changed), app); + + hbox = gtk_hbox_new (FALSE, 12); + gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0); + + /* Set up clutter & create our stage */ + create_colors (app, &stage_color, &text_color); + widget = gtk_clutter_new (); + gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0); + app->stage = gtk_clutter_get_stage (GTK_CLUTTER (widget)); + clutter_stage_set_color (CLUTTER_STAGE (app->stage), &stage_color); + + /* Create the main texture that the spin buttons manipulate */ + pixbuf = gdk_pixbuf_new_from_file ("redhand.png", NULL); + if (pixbuf == NULL) + g_error ("Unable to load pixbuf\n"); + + actor = clutter_texture_new_from_pixbuf (pixbuf); + app->hand = actor; + clutter_group_add (CLUTTER_GROUP (app->stage), actor); + clutter_actor_get_size (actor, &width, &height); + clutter_actor_set_position (actor, + (CLUTTER_STAGE_WIDTH ()/2) - (width/2), + (CLUTTER_STAGE_HEIGHT ()/2) - (height/2)); + + /* Setup the clutter entry */ + actor = clutter_entry_new_full ("Sans 10", "", &text_color); + app->clutter_entry = actor; + clutter_group_add (CLUTTER_GROUP (app->stage), actor); + clutter_actor_set_position (actor, 0, 0); + clutter_actor_set_size (actor, 500, 20); + + /* Create our adjustment widgets */ + vbox = gtk_vbox_new (FALSE, 6); + gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0); + + box = gtk_hbox_new (TRUE, 6); + gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, TRUE, 0); + label = gtk_label_new ("Rotate x-axis"); + gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0); + button = gtk_spin_button_new_with_range (0, 360, 1); + gtk_box_pack_start (GTK_BOX (box), button, TRUE, TRUE, 0); + g_signal_connect (G_OBJECT (button), "value-changed", + G_CALLBACK (on_x_changed), app); + + box = gtk_hbox_new (TRUE, 6); + gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, TRUE, 0); + label = gtk_label_new ("Rotate y-axis"); + gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0); + button = gtk_spin_button_new_with_range (0, 360, 1); + gtk_box_pack_start (GTK_BOX (box), button, TRUE, TRUE, 0); + g_signal_connect (G_OBJECT (button), "value-changed", + G_CALLBACK (on_y_changed), app); + + box = gtk_hbox_new (TRUE, 6); + gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, TRUE, 0); + label = gtk_label_new ("Rotate z-axis"); + gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0); + button = gtk_spin_button_new_with_range (0, 360, 1); + gtk_box_pack_start (GTK_BOX (box), button, TRUE, TRUE, 0); + g_signal_connect (G_OBJECT (button), "value-changed", + G_CALLBACK (on_z_changed), app); + + box = gtk_hbox_new (TRUE, 6); + gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, TRUE, 0); + label = gtk_label_new ("Adjust opacity"); + gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0); + button = gtk_spin_button_new_with_range (0, 255, 1); + gtk_spin_button_set_value (GTK_SPIN_BUTTON (button), 255); + gtk_box_pack_start (GTK_BOX (box), button, TRUE, TRUE, 0); + g_signal_connect (G_OBJECT (button), "value-changed", + G_CALLBACK (on_opacity_changed), app); + + clutter_actor_show_all (app->stage); + gtk_widget_show_all (app->window); + + gtk_main (); + + return 0; +} diff --git a/examples/gtk-clutter-test.c b/examples/gtk-clutter-test.c index f1929bc..ff5de99 100644 --- a/examples/gtk-clutter-test.c +++ b/examples/gtk-clutter-test.c @@ -197,7 +197,7 @@ main (int argc, char *argv[]) clutter_group_add (CLUTTER_GROUP (stage), CLUTTER_ACTOR(oh->group)); /* Show everying ( and map window ) */ - clutter_group_show_all (oh->group); + clutter_actor_show_all (CLUTTER_ACTOR (oh->group)); g_signal_connect (stage, "button-press-event", G_CALLBACK (input_cb), -- 1.7.9.5