2 #include <clutter/clutter.h>
4 #include <clutter-gtk/clutter-gtk.h>
14 ClutterActor *clutter_entry;
19 on_gtk_entry_changed (GtkEditable *editable, EventApp *app)
21 const gchar *text = gtk_entry_get_text (GTK_ENTRY (editable));
23 clutter_entry_set_text (CLUTTER_ENTRY (app->clutter_entry), text);
27 on_x_changed (GtkSpinButton *button, EventApp *app)
29 clutter_actor_rotate_x (app->hand,
30 gtk_spin_button_get_value (button),
31 clutter_actor_get_height (app->hand),
36 on_y_changed (GtkSpinButton *button, EventApp *app)
38 clutter_actor_rotate_y (app->hand,
39 gtk_spin_button_get_value (button),
40 clutter_actor_get_width (app->hand) /2,
45 on_z_changed (GtkSpinButton *button, EventApp *app)
47 clutter_actor_rotate_z (app->hand,
48 gtk_spin_button_get_value (button),
49 clutter_actor_get_width (app->hand) /2,
50 clutter_actor_get_height (app->hand)/2);
54 on_opacity_changed (GtkSpinButton *button, EventApp *app)
56 clutter_actor_set_opacity (app->hand, gtk_spin_button_get_value (button));
59 /* Set the clutter colors form the current gtk theme */
61 create_colors (EventApp *app, ClutterColor *stage, ClutterColor *text)
63 GtkStyle *style = gtk_widget_get_style (app->window);
66 /* Set the stage color to base[NORMAL] */
67 color = style->bg[GTK_STATE_NORMAL];
68 stage->red = (guint8) ((color.red/65535.0) * 255);
69 stage->green = (guint8) ((color.green/65535.0) * 255);
70 stage->blue = (guint8) ((color.blue/65535.0) * 255);
72 /* Now the text color */
73 color = style->text[GTK_STATE_NORMAL];
74 text->red =(guint8) ((color.red/65535.0) * 255);
75 text->green = (guint8) ((color.green/65535.0) * 255);
76 text->blue = (guint8) ((color.blue/65535.0) * 255);
80 main (gint argc, gchar **argv)
82 EventApp *app = g_new0 (EventApp, 1);
83 GtkWidget *widget, *vbox, *hbox, *button, *label, *box;
85 GdkPixbuf *pixbuf = NULL;
87 ClutterColor stage_color = {255, 255, 255, 255};
88 ClutterColor text_color = {0, 0, 0, 255};
90 clutter_init (&argc, &argv);
92 gtk_init (&argc, &argv);
94 /* Create the inital gtk window and widgets, just like normal */
95 widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
97 gtk_window_set_title (GTK_WINDOW (widget), "Gtk-Clutter Interaction demo");
98 gtk_window_set_default_size (GTK_WINDOW (widget), 800, 600);
99 gtk_window_set_resizable (GTK_WINDOW (widget), FALSE);
100 gtk_container_set_border_width (GTK_CONTAINER (widget), 12);
101 g_signal_connect (widget, "destroy", G_CALLBACK (gtk_main_quit), NULL);
103 /* Create our layout box */
104 vbox = gtk_vbox_new (FALSE, 12);
105 gtk_container_add (GTK_CONTAINER (app->window), vbox);
107 widget = gtk_entry_new ();
108 app->gtk_entry = widget;
109 gtk_entry_set_text (GTK_ENTRY (widget), "Enter some text");
110 gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
111 g_signal_connect (widget, "changed", G_CALLBACK (on_gtk_entry_changed), app);
113 hbox = gtk_hbox_new (FALSE, 12);
114 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
116 /* Set up clutter & create our stage */
117 create_colors (app, &stage_color, &text_color);
118 widget = gtk_clutter_new ();
119 gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
120 app->stage = gtk_clutter_get_stage (GTK_CLUTTER (widget));
121 clutter_stage_set_color (CLUTTER_STAGE (app->stage), &stage_color);
123 /* Create the main texture that the spin buttons manipulate */
124 pixbuf = gdk_pixbuf_new_from_file ("redhand.png", NULL);
126 g_error ("Unable to load pixbuf\n");
128 actor = clutter_texture_new_from_pixbuf (pixbuf);
130 clutter_group_add (CLUTTER_GROUP (app->stage), actor);
131 clutter_actor_get_size (actor, &width, &height);
132 clutter_actor_set_position (actor,
133 (CLUTTER_STAGE_WIDTH ()/2) - (width/2),
134 (CLUTTER_STAGE_HEIGHT ()/2) - (height/2));
136 /* Setup the clutter entry */
137 actor = clutter_entry_new_full ("Sans 10", "", &text_color);
138 app->clutter_entry = actor;
139 clutter_group_add (CLUTTER_GROUP (app->stage), actor);
140 clutter_actor_set_position (actor, 0, 0);
141 clutter_actor_set_size (actor, 500, 20);
143 /* Create our adjustment widgets */
144 vbox = gtk_vbox_new (FALSE, 6);
145 gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
147 box = gtk_hbox_new (TRUE, 6);
148 gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, TRUE, 0);
149 label = gtk_label_new ("Rotate x-axis");
150 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
151 button = gtk_spin_button_new_with_range (0, 360, 1);
152 gtk_box_pack_start (GTK_BOX (box), button, TRUE, TRUE, 0);
153 g_signal_connect (button, "value-changed", G_CALLBACK (on_x_changed), app);
155 box = gtk_hbox_new (TRUE, 6);
156 gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, TRUE, 0);
157 label = gtk_label_new ("Rotate y-axis");
158 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
159 button = gtk_spin_button_new_with_range (0, 360, 1);
160 gtk_box_pack_start (GTK_BOX (box), button, TRUE, TRUE, 0);
161 g_signal_connect (button, "value-changed", G_CALLBACK (on_y_changed), app);
163 box = gtk_hbox_new (TRUE, 6);
164 gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, TRUE, 0);
165 label = gtk_label_new ("Rotate z-axis");
166 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
167 button = gtk_spin_button_new_with_range (0, 360, 1);
168 gtk_box_pack_start (GTK_BOX (box), button, TRUE, TRUE, 0);
169 g_signal_connect (button, "value-changed", G_CALLBACK (on_z_changed), app);
171 box = gtk_hbox_new (TRUE, 6);
172 gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, TRUE, 0);
173 label = gtk_label_new ("Adjust opacity");
174 gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
175 button = gtk_spin_button_new_with_range (0, 255, 1);
176 gtk_spin_button_set_value (GTK_SPIN_BUTTON (button), 255);
177 gtk_box_pack_start (GTK_BOX (box), button, TRUE, TRUE, 0);
178 g_signal_connect (button, "value-changed", G_CALLBACK (on_opacity_changed), app);
180 clutter_actor_show_all (app->stage);
181 gtk_widget_show_all (app->window);