From e34b2f77c6c93da5f1ff8c5add77b35c7d899da9 Mon Sep 17 00:00:00 2001 From: Iain Holmes Date: Wed, 21 Jun 2006 22:29:28 +0000 Subject: [PATCH] 2006-06-22 Iain Holmes * gtk/gtk-clutter.[ch]: Rewrite to use clutter_stage_set_xwindow_foreign rather than GtkSocket. * gtk/gtk-clutter-test.c: Add fading!1!!!!11! OMGWTFBBQ!!! --- ChangeLog | 7 +++++ gtk/gtk-clutter-test.c | 35 +++++++++++++++++++----- gtk/gtk-clutter.c | 60 ++++++++++++++++++++++++++++++------------ gtk/gtk-clutter.h | 6 ++--- 4 files changed, 81 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index f8bfff86d..12b09115b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-06-22 Iain Holmes + + * gtk/gtk-clutter.[ch]: Rewrite to use + clutter_stage_set_xwindow_foreign rather than GtkSocket. + + * gtk/gtk-clutter-test.c: Add fading!1!!!!11! OMGWTFBBQ!!! + 2006-06-21 Emmanuele Bassi * examples/video-cube.c (main): Quit on key press. diff --git a/gtk/gtk-clutter-test.c b/gtk/gtk-clutter-test.c index c7119e6dd..323262472 100644 --- a/gtk/gtk-clutter-test.c +++ b/gtk/gtk-clutter-test.c @@ -18,6 +18,8 @@ typedef struct SuperOH } SuperOH; +gboolean fade = FALSE; + /* input handler */ void input_cb (ClutterStage *stage, @@ -86,8 +88,12 @@ frame_cb (ClutterTimeline *timeline, - 6.0 * frame_num, clutter_actor_get_width (oh->hand[i])/2, clutter_actor_get_height (oh->hand[i])/2); + if (fade == TRUE) { + clutter_actor_set_opacity (oh->hand[i], (255 - (frame_num % 255))); + } } + /* clutter_actor_rotate_x (CLUTTER_ACTOR(oh->group), 75.0, @@ -95,13 +101,20 @@ frame_cb (ClutterTimeline *timeline, */ } +static void +clickity (GtkButton *button, + gpointer ud) +{ + fade = !fade; +} + int main (int argc, char *argv[]) { ClutterTimeline *timeline; ClutterActor *stage; ClutterColor stage_color = { 0x61, 0x64, 0x8c, 0xff }; - GtkWidget *window, *plug, *clutter; + GtkWidget *window, *clutter; GtkWidget *label, *button, *vbox; GdkPixbuf *pixbuf; SuperOH *oh; @@ -116,11 +129,6 @@ main (int argc, char *argv[]) if (!pixbuf) g_error("pixbuf load failed"); - clutter = g_object_new (GTK_TYPE_CLUTTER, NULL); - stage = gtk_clutter_get_stage (GTK_CLUTTER (clutter)); - - /* Set our stage size */ - clutter_actor_set_size (stage, WINWIDTH, WINHEIGHT); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (window, "destroy", @@ -128,13 +136,21 @@ main (int argc, char *argv[]) vbox = gtk_vbox_new (FALSE, 6); gtk_container_add (GTK_CONTAINER (window), vbox); + + clutter = g_object_new (GTK_TYPE_CLUTTER, NULL); + stage = gtk_clutter_get_stage (GTK_CLUTTER (clutter)); gtk_container_add (GTK_CONTAINER (vbox), clutter); + /* Set our stage size */ +/* clutter_actor_set_size (stage, WINWIDTH, WINHEIGHT); */ + label = gtk_label_new ("This is a label"); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); button = gtk_button_new_with_label ("This is a button...clicky"); + g_signal_connect (button, "clicked", + G_CALLBACK (clickity), NULL); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); /* and its background color */ @@ -157,13 +173,18 @@ main (int argc, char *argv[]) for (i = 0; i < NHANDS; i++) { gint x, y, w, h; - + ClutterColor colour = { 255, 0, 0, 255 }; +#if 1 /* Create a texture from pixbuf, then clone in to same resources */ if (i == 0) oh->hand[i] = clutter_texture_new_from_pixbuf (pixbuf); else oh->hand[i] = clutter_clone_texture_new (CLUTTER_TEXTURE(oh->hand[0])); +#else + oh->hand[i] = clutter_rectangle_new_with_color (&colour); + clutter_actor_set_size (oh->hand[i], 50, 50); +#endif /* Place around a circle */ w = clutter_actor_get_width (oh->hand[0]); h = clutter_actor_get_height (oh->hand[0]); diff --git a/gtk/gtk-clutter.c b/gtk/gtk-clutter.c index e901ffc68..d1f5fd914 100644 --- a/gtk/gtk-clutter.c +++ b/gtk/gtk-clutter.c @@ -25,9 +25,12 @@ #include "config.h" -#include +#include + +#include #include +#include #include #include "gtk-clutter.h" @@ -37,10 +40,9 @@ struct _GtkClutterPrivate { ClutterActor *stage; - gboolean anchored; }; -static GtkSocketClass *parent_class; +static GtkDrawingAreaClass *parent_class; static void dispose (GObject *object) @@ -69,27 +71,42 @@ size_request (GtkWidget *widget, clutter = GTK_CLUTTER (widget); priv = GTK_CLUTTER_GET_PRIVATE (clutter); - req->width = clutter_actor_get_width (priv->stage); - req->height = clutter_actor_get_height (priv->stage); + req->width = 800; + req->height = 600; } static void -hierarchy_changed (GtkWidget *widget, - GtkWidget *parent) +realize (GtkWidget *widget) { GtkClutter *clutter; GtkClutterPrivate *priv; + XVisualInfo *xvinfo; + GdkVisual *visual; + GdkColormap *colormap; + gboolean foreign_success; clutter = GTK_CLUTTER (widget); priv = GTK_CLUTTER_GET_PRIVATE (clutter); - if (!priv->anchored) { - /* Now we can add our stage to the socket */ - gtk_socket_add_id - (GTK_SOCKET (clutter), (GdkNativeWindow) clutter_stage_get_xwindow (CLUTTER_STAGE (priv->stage))); + /* We need to use the colormap from the Clutter visual */ + xvinfo = clutter_stage_get_xvisual (CLUTTER_STAGE (priv->stage)); + visual = gdk_x11_screen_lookup_visual (gdk_screen_get_default (), + xvinfo->visualid); + colormap = gdk_colormap_new (visual, FALSE); + gtk_widget_set_colormap (widget, colormap); - priv->anchored = TRUE; - } + /* And turn off double buffering, cos GL doesn't like it */ + gtk_widget_set_double_buffered (widget, FALSE); + + GTK_WIDGET_CLASS (parent_class)->realize (widget); + + gdk_window_set_back_pixmap (widget->window, NULL, FALSE); + + clutter = GTK_CLUTTER (widget); + priv = GTK_CLUTTER_GET_PRIVATE (clutter); + + clutter_stage_set_xwindow_foreign (CLUTTER_STAGE (priv->stage), + GDK_WINDOW_XID (widget->window)); } static void @@ -101,7 +118,7 @@ gtk_clutter_class_init (GtkClutterClass *klass) gobject_class->dispose = dispose; widget_class->size_request = size_request; - widget_class->hierarchy_changed = hierarchy_changed; + widget_class->realize = realize; g_type_class_add_private (gobject_class, sizeof (GtkClutterPrivate)); @@ -114,13 +131,22 @@ gtk_clutter_init (GtkClutter *clutter) GtkClutterPrivate *priv; clutter->priv = priv = GTK_CLUTTER_GET_PRIVATE (clutter); - + + gtk_widget_set_double_buffered (GTK_WIDGET (clutter), FALSE); + priv->stage = clutter_stage_get_default (); - priv->anchored = FALSE; } -G_DEFINE_TYPE (GtkClutter, gtk_clutter, GTK_TYPE_SOCKET); +G_DEFINE_TYPE (GtkClutter, gtk_clutter, GTK_TYPE_DRAWING_AREA); +/** + * gtk_clutter_get_stage: + * @clutter: A #GtkClutter object. + * + * Obtains the #ClutterStage associated with this object. + * + * Return value: A #ClutterActor. + */ ClutterActor * gtk_clutter_get_stage (GtkClutter *clutter) { diff --git a/gtk/gtk-clutter.h b/gtk/gtk-clutter.h index b60bf7ff9..46ccb0e58 100644 --- a/gtk/gtk-clutter.h +++ b/gtk/gtk-clutter.h @@ -26,7 +26,7 @@ #ifndef _HAVE_GTK_CLUTTER_H #define _HAVE_GTK_CLUTTER_H -#include +#include #include @@ -60,7 +60,7 @@ typedef struct _GtkClutterClass GtkClutterClass; struct _GtkClutter { - GtkSocket parent; + GtkDrawingArea parent; /*< private >*/ GtkClutterPrivate *priv; @@ -68,7 +68,7 @@ struct _GtkClutter struct _GtkClutterClass { - GtkSocketClass parent_class; + GtkDrawingAreaClass parent_class; }; GType gtk_clutter_get_type (void);