From 9c9377198f7467b6fd30d080e5af84092eff4496 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 29 Nov 2006 22:09:13 +0000 Subject: [PATCH] add clutter-gtk --- clutter-gtk/Makefile.am | 19 ++++++ clutter-gtk/gtk-clutter.c | 163 +++++++++++++++++++++++++++++++++++++++++++++ clutter-gtk/gtk-clutter.h | 80 ++++++++++++++++++++++ 3 files changed, 262 insertions(+) create mode 100644 clutter-gtk/Makefile.am create mode 100644 clutter-gtk/gtk-clutter.c create mode 100644 clutter-gtk/gtk-clutter.h diff --git a/clutter-gtk/Makefile.am b/clutter-gtk/Makefile.am new file mode 100644 index 0000000..51e61d5 --- /dev/null +++ b/clutter-gtk/Makefile.am @@ -0,0 +1,19 @@ +INCLUDES = \ + -I$(srcdir) \ + -I$(top_srcdir) \ + -DG_LOG_DOMAIN=\"Clutter-Gtk\" \ + -DPREFIX=\""$(prefix)"\" \ + -DLIBDIR=\""$(libdir)"\" \ + $(CLUTTER_DEBUG_FLAGS) \ + $(GCC_FLAGS) \ + $(CLUTTER_CFLAGS) \ + $(GTK_CFLAGS) + +lib_LTLIBRARIES = libcluttergtk-1.0.la + +libcluttergtk_1_0_la_SOURCES = gtk-clutter.c +libcluttergtk_1_0_la_LIBADD = $(CLUTTER_LIBS) $(GTK_LIBS) +libcluttergtk_1_0_la_LDFLAGS = $(CLUTTER_LT_LDFLAGS) + +cluttergtkheadersdir = $(includedir)/clutter-0.1/clutter-gtk +cluttergtkheaders_HEADERS = gtk-clutter.h diff --git a/clutter-gtk/gtk-clutter.c b/clutter-gtk/gtk-clutter.c new file mode 100644 index 0000000..05066b2 --- /dev/null +++ b/clutter-gtk/gtk-clutter.c @@ -0,0 +1,163 @@ +/* + * GTK-Clutter. + * + * GTK+ widget for Clutter. + * + * Authored By Iain Holmes + * + * 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. + */ + +/** + * 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. + */ +#include "config.h" + +#include + +#include +#include + +#include +#include + +#include "gtk-clutter.h" + +#define GTK_CLUTTER_GET_PRIVATE(obj) \ +(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_CLUTTER, GtkClutterPrivate)) + +struct _GtkClutterPrivate { + ClutterActor *stage; +}; + +static GtkDrawingAreaClass *parent_class; + +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); +} + +static void +size_request (GtkWidget *widget, + GtkRequisition *req) +{ + GtkClutter *clutter; + GtkClutterPrivate *priv; + + clutter = GTK_CLUTTER (widget); + priv = GTK_CLUTTER_GET_PRIVATE (clutter); + + req->width = 800; + req->height = 600; +} + +static void +realize (GtkWidget *widget) +{ + GtkClutter *clutter; + GtkClutterPrivate *priv; + const XVisualInfo *xvinfo; + GdkVisual *visual; + GdkColormap *colormap; + + clutter = GTK_CLUTTER (widget); + priv = GTK_CLUTTER_GET_PRIVATE (clutter); + + /* 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); + + /* 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 +gtk_clutter_class_init (GtkClutterClass *klass) +{ + GObjectClass *gobject_class = (GObjectClass *) klass; + GtkWidgetClass *widget_class = (GtkWidgetClass *) klass; + + gobject_class->dispose = dispose; + + widget_class->size_request = size_request; + widget_class->realize = realize; + + 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); + + gtk_widget_set_double_buffered (GTK_WIDGET (clutter), FALSE); + + priv->stage = clutter_stage_get_default (); +} + +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) +{ + g_return_val_if_fail (GTK_IS_CLUTTER (clutter), NULL); + + return clutter->priv->stage; +} diff --git a/clutter-gtk/gtk-clutter.h b/clutter-gtk/gtk-clutter.h new file mode 100644 index 0000000..46ccb0e --- /dev/null +++ b/clutter-gtk/gtk-clutter.h @@ -0,0 +1,80 @@ +/* + * GTK-Clutter. + * + * GTK+ widget for Clutter. + * + * Authored By Iain Holmes + * + * 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. + */ + +#ifndef _HAVE_GTK_CLUTTER_H +#define _HAVE_GTK_CLUTTER_H + +#include + +#include + +G_BEGIN_DECLS + +#define GTK_TYPE_CLUTTER gtk_clutter_get_type () + +#define GTK_CLUTTER(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + GTK_TYPE_CLUTTER, GtkClutter)) + +#define GTK_CLUTTER_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CASE ((klass), \ + GTK_TYPE_CLUTTER, GtkClutterClass)) + +#define GTK_IS_CLUTTER(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + GTK_TYPE_CLUTTER)) + +#define GTK_IS_CLUTTER_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), \ + GTK_TYPE_CLUTTER)) + +#define GTK_CLUTTER_STAGE_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + GTK_TYPE_CLUTTER, GtkClutterClass)) + +typedef struct _GtkClutterPrivate GtkClutterPrivate; +typedef struct _GtkClutter GtkClutter; +typedef struct _GtkClutterClass GtkClutterClass; + +struct _GtkClutter +{ + GtkDrawingArea parent; + + /*< private >*/ + GtkClutterPrivate *priv; +}; + +struct _GtkClutterClass +{ + GtkDrawingAreaClass parent_class; +}; + +GType gtk_clutter_get_type (void); + +ClutterActor *gtk_clutter_get_stage (GtkClutter *clutter); + +G_END_DECLS + +#endif -- 1.7.9.5