1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
#include <gtk/gtk.h>
#include <clutter/clutter.h>
#include <clutter-gtk/gtk-clutter-embed.h>
#include <clutter-gtk/gtk-clutter-util.h>
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_set_rotation (app->hand, CLUTTER_X_AXIS,
gtk_spin_button_get_value (button),
0,
clutter_actor_get_height (app->hand) / 2,
0);
}
static void
on_y_changed (GtkSpinButton *button, EventApp *app)
{
clutter_actor_set_rotation (app->hand, CLUTTER_Y_AXIS,
gtk_spin_button_get_value (button),
clutter_actor_get_width (app->hand) / 2,
0,
0);
}
static void
on_z_changed (GtkSpinButton *button, EventApp *app)
{
clutter_actor_set_rotation (app->hand, CLUTTER_Z_AXIS,
gtk_spin_button_get_value (button),
clutter_actor_get_width (app->hand) / 2,
clutter_actor_get_height (app->hand) / 2,
0);
}
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)
{
gtk_clutter_get_bg_color (app->window, GTK_STATE_NORMAL, stage);
gtk_clutter_get_text_color (app->window, GTK_STATE_NORMAL, text);
}
static gboolean
on_stage_capture (ClutterActor *actor,
ClutterEvent *event,
gpointer dummy)
{
if (event->type == CLUTTER_BUTTON_RELEASE)
{
gint x, y;
clutter_event_get_coords (event, &x, &y);
g_print ("Event captured at (%d, %d)\n", x, y);
}
return FALSE;
}
static gboolean
on_hand_button_press (ClutterActor *actor,
ClutterButtonEvent *event,
gpointer dummy)
{
g_print ("Button press on hand ('%s')\n",
g_type_name (G_OBJECT_TYPE (actor)));
return FALSE;
}
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};
if (gtk_clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
g_error ("Unable to initialize GtkClutter");
/* 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 (widget, "destroy", 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 (widget, "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_embed_new ();
gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0);
app->stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (widget));
clutter_stage_set_color (CLUTTER_STAGE (app->stage), &stage_color);
gtk_widget_set_size_request (widget, 640, 480);
g_signal_connect (app->stage, "captured-event",
G_CALLBACK (on_stage_capture),
NULL);
/* 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 = gtk_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));
clutter_actor_set_reactive (actor, TRUE);
g_signal_connect (actor, "button-press-event",
G_CALLBACK (on_hand_button_press),
NULL);
/* 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 (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 (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 (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 (button, "value-changed", G_CALLBACK (on_opacity_changed), app);
gtk_widget_show_all (app->window);
/* Only show/show_all the stage after parent show. widget_show will call
* show on the stage.
*/
clutter_actor_show_all (app->stage);
gtk_main ();
return 0;
}
|