4 * GTK+ widget for Clutter.
6 * Authored By Iain Holmes <iain@openedhand.com>
8 * Copyright (C) 2006 OpenedHand
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 02111-1307, USA.
28 * @short_description: GTK+ widget displaying a #ClutterStage.
30 * #GtkClutter is a GTK+ widget, derived from #GtkDrawingArea that contains a
31 * #ClutterStage, allowing it to be used in a GTK+ based program like any
38 #include <gtk/gtkdrawingarea.h>
39 #include <gtk/gtkwidget.h>
41 #include <clutter/clutter-main.h>
42 #include <clutter/clutter-stage.h>
44 #include "gtk-clutter.h"
46 #define GTK_CLUTTER_GET_PRIVATE(obj) \
47 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_CLUTTER, GtkClutterPrivate))
49 struct _GtkClutterPrivate {
53 static GtkDrawingAreaClass *parent_class;
56 dispose (GObject *object)
59 GtkClutterPrivate *priv;
61 clutter = GTK_CLUTTER (object);
62 priv = GTK_CLUTTER_GET_PRIVATE (clutter);
65 g_object_unref (G_OBJECT (priv->stage));
69 G_OBJECT_CLASS (parent_class)->dispose (object);
73 size_request (GtkWidget *widget,
77 GtkClutterPrivate *priv;
79 clutter = GTK_CLUTTER (widget);
80 priv = GTK_CLUTTER_GET_PRIVATE (clutter);
87 realize (GtkWidget *widget)
90 GtkClutterPrivate *priv;
91 const XVisualInfo *xvinfo;
93 GdkColormap *colormap;
95 clutter = GTK_CLUTTER (widget);
96 priv = GTK_CLUTTER_GET_PRIVATE (clutter);
98 /* We need to use the colormap from the Clutter visual */
99 xvinfo = clutter_stage_get_xvisual (CLUTTER_STAGE (priv->stage));
100 visual = gdk_x11_screen_lookup_visual (gdk_screen_get_default (),
102 colormap = gdk_colormap_new (visual, FALSE);
103 gtk_widget_set_colormap (widget, colormap);
105 /* And turn off double buffering, cos GL doesn't like it */
106 gtk_widget_set_double_buffered (widget, FALSE);
108 GTK_WIDGET_CLASS (parent_class)->realize (widget);
110 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
112 clutter = GTK_CLUTTER (widget);
113 priv = GTK_CLUTTER_GET_PRIVATE (clutter);
115 clutter_stage_set_xwindow_foreign (CLUTTER_STAGE (priv->stage),
116 GDK_WINDOW_XID (widget->window));
120 gtk_clutter_class_init (GtkClutterClass *klass)
122 GObjectClass *gobject_class = (GObjectClass *) klass;
123 GtkWidgetClass *widget_class = (GtkWidgetClass *) klass;
125 gobject_class->dispose = dispose;
127 widget_class->size_request = size_request;
128 widget_class->realize = realize;
130 g_type_class_add_private (gobject_class, sizeof (GtkClutterPrivate));
132 parent_class = g_type_class_peek_parent (klass);
136 gtk_clutter_init (GtkClutter *clutter)
138 GtkClutterPrivate *priv;
140 clutter->priv = priv = GTK_CLUTTER_GET_PRIVATE (clutter);
142 gtk_widget_set_double_buffered (GTK_WIDGET (clutter), FALSE);
144 priv->stage = clutter_stage_get_default ();
147 G_DEFINE_TYPE (GtkClutter, gtk_clutter, GTK_TYPE_DRAWING_AREA);
150 * gtk_clutter_get_stage:
151 * @clutter: A #GtkClutter object.
153 * Obtains the #ClutterStage associated with this object.
155 * Return value: A #ClutterActor.
158 gtk_clutter_get_stage (GtkClutter *clutter)
160 g_return_val_if_fail (GTK_IS_CLUTTER (clutter), NULL);
162 return clutter->priv->stage;