2006-06-22 Iain Holmes <iain@openedhand.com>

* 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!!!
This commit is contained in:
Iain Holmes 2006-06-21 22:29:28 +00:00
parent 1b7b2bc573
commit e34b2f77c6
4 changed files with 81 additions and 27 deletions

View File

@ -1,3 +1,10 @@
2006-06-22 Iain Holmes <iain@openedhand.com>
* 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 <ebassi@openedhand.com>
* examples/video-cube.c (main): Quit on key press.

View File

@ -18,6 +18,8 @@ typedef struct SuperOH
} SuperOH;
gboolean fade = FALSE;
/* input handler */
void
input_cb (ClutterStage *stage,
@ -86,7 +88,11 @@ 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),
@ -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",
@ -129,12 +137,20 @@ 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]);

View File

@ -25,9 +25,12 @@
#include "config.h"
#include <gtk/gtksocket.h>
#include <gdk/gdkx.h>
#include <gtk/gtkdrawingarea.h>
#include <gtk/gtkwidget.h>
#include <clutter/clutter-main.h>
#include <clutter/clutter-stage.h>
#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));
@ -115,12 +132,21 @@ gtk_clutter_init (GtkClutter *clutter)
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)
{

View File

@ -26,7 +26,7 @@
#ifndef _HAVE_GTK_CLUTTER_H
#define _HAVE_GTK_CLUTTER_H
#include <gtk/gtksocket.h>
#include <gtk/gtkdrawingarea.h>
#include <clutter/clutter-actor.h>
@ -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);