2006-06-06 14:19:11 -04:00
|
|
|
/*
|
|
|
|
* GTK-Clutter.
|
|
|
|
*
|
|
|
|
* GTK+ widget for Clutter.
|
|
|
|
*
|
|
|
|
* Authored By Iain Holmes <iain@openedhand.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 OpenedHand
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2006-06-21 19:19:59 -04:00
|
|
|
/**
|
|
|
|
* SECTION:gtk-clutter
|
|
|
|
* @short_description: GTK+ widget displaying a #ClutterStage.
|
|
|
|
*
|
|
|
|
* #GtkClutter is a GTK+ widget, derived from #GtkDrawingArea that contains a
|
|
|
|
* #ClutterStage, allowing it to be used in a GTK+ based program like any
|
|
|
|
* normal GTK+ widget.
|
|
|
|
*/
|
2006-06-06 14:19:11 -04:00
|
|
|
#include "config.h"
|
|
|
|
|
2006-06-21 18:29:28 -04:00
|
|
|
#include <gdk/gdkx.h>
|
|
|
|
|
|
|
|
#include <gtk/gtkdrawingarea.h>
|
2006-06-06 14:19:11 -04:00
|
|
|
#include <gtk/gtkwidget.h>
|
|
|
|
|
2006-06-21 18:29:28 -04:00
|
|
|
#include <clutter/clutter-main.h>
|
2006-06-06 14:19:11 -04:00
|
|
|
#include <clutter/clutter-stage.h>
|
|
|
|
|
|
|
|
#include "gtk-clutter.h"
|
|
|
|
|
|
|
|
#define GTK_CLUTTER_GET_PRIVATE(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_CLUTTER, GtkClutterPrivate))
|
|
|
|
|
|
|
|
struct _GtkClutterPrivate {
|
2006-06-13 09:17:45 -04:00
|
|
|
ClutterActor *stage;
|
2006-06-06 14:19:11 -04:00
|
|
|
};
|
|
|
|
|
2006-06-21 18:29:28 -04:00
|
|
|
static GtkDrawingAreaClass *parent_class;
|
2006-06-06 14:19:11 -04:00
|
|
|
|
|
|
|
static void
|
|
|
|
dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GtkClutter *clutter;
|
|
|
|
GtkClutterPrivate *priv;
|
|
|
|
|
|
|
|
clutter = GTK_CLUTTER (object);
|
|
|
|
priv = GTK_CLUTTER_GET_PRIVATE (clutter);
|
|
|
|
|
|
|
|
if (priv->stage) {
|
|
|
|
g_object_unref (G_OBJECT (priv->stage));
|
|
|
|
priv->stage = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2006-06-06 14:25:55 -04:00
|
|
|
static void
|
|
|
|
size_request (GtkWidget *widget,
|
|
|
|
GtkRequisition *req)
|
|
|
|
{
|
|
|
|
GtkClutter *clutter;
|
|
|
|
GtkClutterPrivate *priv;
|
|
|
|
|
|
|
|
clutter = GTK_CLUTTER (widget);
|
|
|
|
priv = GTK_CLUTTER_GET_PRIVATE (clutter);
|
|
|
|
|
2006-06-21 18:29:28 -04:00
|
|
|
req->width = 800;
|
|
|
|
req->height = 600;
|
2006-06-06 14:25:55 -04:00
|
|
|
}
|
|
|
|
|
2006-06-06 14:19:11 -04:00
|
|
|
static void
|
2006-06-21 18:29:28 -04:00
|
|
|
realize (GtkWidget *widget)
|
2006-06-06 14:19:11 -04:00
|
|
|
{
|
|
|
|
GtkClutter *clutter;
|
|
|
|
GtkClutterPrivate *priv;
|
2006-09-14 13:18:54 -04:00
|
|
|
const XVisualInfo *xvinfo;
|
2006-06-21 18:29:28 -04:00
|
|
|
GdkVisual *visual;
|
|
|
|
GdkColormap *colormap;
|
2006-06-06 14:19:11 -04:00
|
|
|
|
|
|
|
clutter = GTK_CLUTTER (widget);
|
|
|
|
priv = GTK_CLUTTER_GET_PRIVATE (clutter);
|
|
|
|
|
2006-06-21 18:29:28 -04:00
|
|
|
/* 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);
|
2006-06-06 14:19:11 -04:00
|
|
|
|
2006-06-21 18:29:28 -04:00
|
|
|
/* 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));
|
2006-06-06 14:19:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_clutter_class_init (GtkClutterClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
|
|
|
GtkWidgetClass *widget_class = (GtkWidgetClass *) klass;
|
|
|
|
|
|
|
|
gobject_class->dispose = dispose;
|
|
|
|
|
2006-06-06 14:25:55 -04:00
|
|
|
widget_class->size_request = size_request;
|
2006-06-21 18:29:28 -04:00
|
|
|
widget_class->realize = realize;
|
2006-06-06 14:19:11 -04:00
|
|
|
|
|
|
|
g_type_class_add_private (gobject_class, sizeof (GtkClutterPrivate));
|
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_clutter_init (GtkClutter *clutter)
|
|
|
|
{
|
|
|
|
GtkClutterPrivate *priv;
|
|
|
|
|
|
|
|
clutter->priv = priv = GTK_CLUTTER_GET_PRIVATE (clutter);
|
2006-06-21 18:29:28 -04:00
|
|
|
|
|
|
|
gtk_widget_set_double_buffered (GTK_WIDGET (clutter), FALSE);
|
|
|
|
|
2006-06-06 14:19:11 -04:00
|
|
|
priv->stage = clutter_stage_get_default ();
|
|
|
|
}
|
|
|
|
|
2006-06-21 18:29:28 -04:00
|
|
|
G_DEFINE_TYPE (GtkClutter, gtk_clutter, GTK_TYPE_DRAWING_AREA);
|
2006-06-06 14:19:11 -04:00
|
|
|
|
2006-06-21 18:29:28 -04:00
|
|
|
/**
|
|
|
|
* gtk_clutter_get_stage:
|
|
|
|
* @clutter: A #GtkClutter object.
|
|
|
|
*
|
|
|
|
* Obtains the #ClutterStage associated with this object.
|
|
|
|
*
|
|
|
|
* Return value: A #ClutterActor.
|
|
|
|
*/
|
2006-06-13 09:17:45 -04:00
|
|
|
ClutterActor *
|
2006-06-06 14:19:11 -04:00
|
|
|
gtk_clutter_get_stage (GtkClutter *clutter)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_CLUTTER (clutter), NULL);
|
|
|
|
|
|
|
|
return clutter->priv->stage;
|
|
|
|
}
|