2006-11-29 Emmanuele Bassi <ebassi@openedhand.com>
authorEmmanuele Bassi <ebassi@openedhand.com>
Wed, 29 Nov 2006 22:39:46 +0000 (22:39 +0000)
committerEmmanuele Bassi <ebassi@openedhand.com>
Wed, 29 Nov 2006 22:39:46 +0000 (22:39 +0000)
* clutter-gtk/gtk-clutter.h: Add constructor; clean up.

* clutter-gtk/gtk-clutter.c:
(gtk_clutter_destroy), (gtk_clutter_class_init): Move
the stage unref to the GtkObject::destroy method.

(gtk_clutter_size_allocate): Oblige to the size allocation
request from the container of the GtkClutter widget by
resizing the ClutterStage.

(gtk_clutter_size_request): Require the size of the stage.

(gtk_clutter_destroy), (gtk_clutter_size_request),
(gtk_clutter_realize): Do not use the G_TYPE_INSTANCE_GET_PRIVATE()
macro, which does a type check and a function call; use the
priv pointer we conveniently keep around.

* examples/gtk-clutter-test.c: Use the given constructor;
now window resizing works.  The stage doesn't get refreshed
immediately (resize the window), though, and there's still
the X error when we close the window.

ChangeLog
clutter-gtk/gtk-clutter.c
clutter-gtk/gtk-clutter.h
examples/gtk-clutter-test.c

index 68acb0c..79538e1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
 2006-11-29  Emmanuele Bassi  <ebassi@openedhand.com>
 
+       * clutter-gtk/gtk-clutter.h: Add constructor; clean up.
+
+       * clutter-gtk/gtk-clutter.c:
+       (gtk_clutter_destroy), (gtk_clutter_class_init): Move
+       the stage unref to the GtkObject::destroy method.
+
+       (gtk_clutter_size_allocate): Oblige to the size allocation
+       request from the container of the GtkClutter widget by
+       resizing the ClutterStage.
+
+       (gtk_clutter_size_request): Require the size of the stage.
+
+       (gtk_clutter_destroy), (gtk_clutter_size_request),
+       (gtk_clutter_realize): Do not use the G_TYPE_INSTANCE_GET_PRIVATE()
+       macro, which does a type check and a function call; use the
+       priv pointer we conveniently keep around.
+
+       * examples/gtk-clutter-test.c: Use the given constructor;
+       now window resizing works.  The stage doesn't get refreshed
+       immediately (resize the window), though, and there's still
+       the X error when we close the window.
+
+2006-11-29  Emmanuele Bassi  <ebassi@openedhand.com>
+
        * *: Initial import out of the main tree.
index 05066b2..7e9d9fb 100644 (file)
  * #ClutterStage, allowing it to be used in a GTK+ based program like any 
  * normal GTK+ widget.
  */
+
+#ifdef HAVE_CONFIG_H
 #include "config.h"
+#endif
 
 #include <gdk/gdkx.h>
 
 #define GTK_CLUTTER_GET_PRIVATE(obj) \
 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_CLUTTER, GtkClutterPrivate))
 
-struct _GtkClutterPrivate {
+struct _GtkClutterPrivate
+{
   ClutterActor *stage;
 };
 
-static GtkDrawingAreaClass *parent_class;
+G_DEFINE_TYPE (GtkClutter, gtk_clutter, GTK_TYPE_DRAWING_AREA);
 
 static void
-dispose (GObject *object)
+gtk_clutter_destroy (GtkObject *object)
 {
-  GtkClutter *clutter;
   GtkClutterPrivate *priv;
 
-  clutter = GTK_CLUTTER (object);
-  priv = GTK_CLUTTER_GET_PRIVATE (clutter);
+  priv = GTK_CLUTTER (object)->priv;
 
-  if (priv->stage) {
-    g_object_unref (G_OBJECT (priv->stage));
-    priv->stage = NULL;
-  }
+  if (priv->stage)
+    {
+      g_object_unref (G_OBJECT (priv->stage));
+      priv->stage = NULL;
+    }
 
-  G_OBJECT_CLASS (parent_class)->dispose (object);
+  GTK_OBJECT_CLASS (gtk_clutter_parent_class)->destroy (object);
 }
 
 static void
-size_request (GtkWidget *widget,
-              GtkRequisition *req)
+gtk_clutter_size_allocate (GtkWidget     *widget,
+                           GtkAllocation *allocation)
+{
+  GtkClutterPrivate *priv = GTK_CLUTTER (widget)->priv;
+
+  clutter_actor_set_size (priv->stage,
+                          allocation->width,
+                          allocation->height);
+
+  clutter_actor_queue_redraw (priv->stage);
+}
+
+static void
+gtk_clutter_size_request (GtkWidget      *widget,
+                          GtkRequisition *req)
 {
-  GtkClutter *clutter;
   GtkClutterPrivate *priv;
 
-  clutter = GTK_CLUTTER (widget);
-  priv = GTK_CLUTTER_GET_PRIVATE (clutter);
+  priv = GTK_CLUTTER (widget)->priv;
 
-  req->width = 800;
-  req->height = 600;
+  req->width = clutter_actor_get_width (priv->stage);
+  req->height = clutter_actor_get_height (priv->stage);
 }
 
 static void
-realize (GtkWidget *widget)
+gtk_clutter_realize (GtkWidget *widget)
 {
-  GtkClutter *clutter;
   GtkClutterPrivate *priv;
   const XVisualInfo *xvinfo;
   GdkVisual *visual;
   GdkColormap *colormap;
 
-  clutter = GTK_CLUTTER (widget);
-  priv = GTK_CLUTTER_GET_PRIVATE (clutter);
+  priv = GTK_CLUTTER (widget)->priv;
 
   /* We need to use the colormap from the Clutter visual */
   xvinfo = clutter_stage_get_xvisual (CLUTTER_STAGE (priv->stage));
@@ -105,31 +117,33 @@ realize (GtkWidget *widget)
   /* 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);
+  GTK_WIDGET_CLASS (gtk_clutter_parent_class)->realize (widget);
 
   gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
 
-  clutter = GTK_CLUTTER (widget);
-  priv = GTK_CLUTTER_GET_PRIVATE (clutter);
+  priv = GTK_CLUTTER (widget)->priv;
 
   clutter_stage_set_xwindow_foreign (CLUTTER_STAGE (priv->stage), 
                                      GDK_WINDOW_XID (widget->window));
+  
+  /* force a realize */
+  clutter_actor_realize (priv->stage);
 }
 
 static void
 gtk_clutter_class_init (GtkClutterClass *klass)
 {
-  GObjectClass *gobject_class = (GObjectClass *) klass;
-  GtkWidgetClass *widget_class = (GtkWidgetClass *) klass;
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
-  gobject_class->dispose = dispose;
+  object_class->destroy = gtk_clutter_destroy;
 
-  widget_class->size_request = size_request;
-  widget_class->realize = realize;
+  widget_class->size_request = gtk_clutter_size_request;
+  widget_class->size_allocate = gtk_clutter_size_allocate;
+  widget_class->realize = gtk_clutter_realize;
 
   g_type_class_add_private (gobject_class, sizeof (GtkClutterPrivate));
-
-  parent_class = g_type_class_peek_parent (klass);
 }
 
 static void
@@ -144,8 +158,6 @@ gtk_clutter_init (GtkClutter *clutter)
   priv->stage = clutter_stage_get_default ();
 }
 
-G_DEFINE_TYPE (GtkClutter, gtk_clutter, GTK_TYPE_DRAWING_AREA);
-
 /**
  * gtk_clutter_get_stage:
  * @clutter: A #GtkClutter object.
@@ -161,3 +173,9 @@ gtk_clutter_get_stage (GtkClutter *clutter)
 
   return clutter->priv->stage;
 }
+
+GtkWidget *
+gtk_clutter_new (void)
+{
+  return g_object_new (GTK_TYPE_CLUTTER, NULL);
+}
index 46ccb0e..0cf7693 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
-#ifndef _HAVE_GTK_CLUTTER_H
-#define _HAVE_GTK_CLUTTER_H
+#ifndef __GTK_CLUTTER_H__
+#define __GTK_CLUTTER_H__
 
 #include <gtk/gtkdrawingarea.h>
-
 #include <clutter/clutter-actor.h>
 
 G_BEGIN_DECLS
 
-#define GTK_TYPE_CLUTTER gtk_clutter_get_type ()
+#define GTK_TYPE_CLUTTER (gtk_clutter_get_type ())
 
 #define GTK_CLUTTER(obj) \
   (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
@@ -54,9 +53,9 @@ G_BEGIN_DECLS
   (G_TYPE_INSTANCE_GET_CLASS ((obj), \
   GTK_TYPE_CLUTTER, GtkClutterClass))
 
-typedef struct _GtkClutterPrivate GtkClutterPrivate;
-typedef struct _GtkClutter GtkClutter;
-typedef struct _GtkClutterClass GtkClutterClass;
+typedef struct _GtkClutter              GtkClutter;
+typedef struct _GtkClutterClass         GtkClutterClass;
+typedef struct _GtkClutterPrivate       GtkClutterPrivate;
 
 struct _GtkClutter 
 {
@@ -69,12 +68,20 @@ struct _GtkClutter
 struct _GtkClutterClass
 {
   GtkDrawingAreaClass parent_class;
+
+  void (*_gtk_clutter_1) (void);
+  void (*_gtk_clutter_2) (void);
+  void (*_gtk_clutter_3) (void);
+  void (*_gtk_clutter_4) (void);
+  void (*_gtk_clutter_5) (void);
+  void (*_gtk_clutter_6) (void);
 };
 
-GType gtk_clutter_get_type (void);
+GType gtk_clutter_get_type (void) G_GNUC_CONST;
 
+GtkWidget    *gtk_clutter_new       (void);
 ClutterActor *gtk_clutter_get_stage (GtkClutter *clutter);
 
 G_END_DECLS
 
-#endif
+#endif /* __GTK_CLUTTER_H__ */
index 21f7f9b..646b232 100644 (file)
@@ -22,7 +22,7 @@ gboolean fade = FALSE;
 
 /* input handler */
 void 
-input_cb (ClutterStage *stage, 
+input_cb (ClutterStage *stage,
          ClutterEvent *event,
          gpointer      data)
 {
@@ -133,7 +133,7 @@ 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);
+  clutter = gtk_clutter_new ();
   stage = gtk_clutter_get_stage (GTK_CLUTTER (clutter));
   
   gtk_container_add (GTK_CONTAINER (vbox), clutter);