GtkClutterEmbedPrivate *priv = GTK_CLUTTER_EMBED (widget)->priv;
GdkWindowAttr attributes;
int attributes_mask;
-
- /* we must realize the stage to get it ready for embedding */
- clutter_actor_realize (priv->stage);
#ifdef HAVE_CLUTTER_GTK_X11
{
/* We need to use the colormap from the Clutter visual */
xvinfo = clutter_x11_get_stage_visual (CLUTTER_STAGE (priv->stage));
+ if (xvinfo == None)
+ {
+ g_critical ("Unable to retrieve the XVisualInfo from Clutter");
+ return;
+ }
+
visual = gdk_x11_screen_lookup_visual (gtk_widget_get_screen (widget),
xvinfo->visualid);
colormap = gdk_colormap_new (visual, FALSE);
GDK_WINDOW_HWND (widget->window));
#endif /* HAVE_CLUTTER_GTK_{X11,WIN32} */
+ clutter_actor_realize (priv->stage);
+
if (GTK_WIDGET_VISIBLE (widget))
clutter_actor_show (priv->stage);
- clutter_actor_queue_redraw (CLUTTER_ACTOR (priv->stage));
-
gtk_clutter_embed_send_configure (GTK_CLUTTER_EMBED (widget));
}
static void
+gtk_clutter_embed_unrealize (GtkWidget *widget)
+{
+ GtkClutterEmbedPrivate *priv = GTK_CLUTTER_EMBED (widget)->priv;
+
+ clutter_actor_hide (priv->stage);
+
+ GTK_WIDGET_CLASS (gtk_clutter_embed_parent_class)->unrealize (widget);
+}
+
+static void
gtk_clutter_embed_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GdkEventAny *event)
{
GtkClutterEmbedPrivate *priv = GTK_CLUTTER_EMBED (widget)->priv;
+ GtkWidgetClass *parent_class;
+ gboolean res = FALSE;
- /* The backend wont get the XEvent as we go strait to do_event().
- * So we have to make sure we set the event here.
- */
- CLUTTER_ACTOR_SET_FLAGS (priv->stage, CLUTTER_ACTOR_MAPPED);
+ parent_class = GTK_WIDGET_CLASS (gtk_clutter_embed_parent_class);
+ if (parent_class->map_event)
+ res = parent_class->map_event (widget, event);
- return FALSE;
+ clutter_actor_map (priv->stage);
+
+ return res;
+}
+
+static gboolean
+gtk_clutter_embed_unmap_event (GtkWidget *widget,
+ GdkEventAny *event)
+{
+ GtkClutterEmbedPrivate *priv = GTK_CLUTTER_EMBED (widget)->priv;
+ GtkWidgetClass *parent_class;
+ gboolean res = FALSE;
+
+ parent_class = GTK_WIDGET_CLASS (gtk_clutter_embed_parent_class);
+ if (parent_class->unmap_event)
+ res = parent_class->unmap_event (widget, event);
+
+ clutter_actor_unmap (priv->stage);
+
+ return res;
+}
+
+static void
+gtk_clutter_embed_unmap (GtkWidget *widget)
+{
+ GtkClutterEmbedPrivate *priv = GTK_CLUTTER_EMBED (widget)->priv;
+
+ clutter_actor_unmap (priv->stage);
+
+ GTK_WIDGET_CLASS (gtk_clutter_embed_parent_class)->unmap (widget);
}
static gboolean
-gtk_clutter_embed_focus_in (GtkWidget *widget,
+gtk_clutter_embed_focus_in (GtkWidget *widget,
GdkEventFocus *event)
{
GtkClutterEmbedPrivate *priv = GTK_CLUTTER_EMBED (widget)->priv;
widget_class->style_set = gtk_clutter_embed_style_set;
widget_class->size_allocate = gtk_clutter_embed_size_allocate;
widget_class->realize = gtk_clutter_embed_realize;
+ widget_class->unrealize = gtk_clutter_embed_unrealize;
widget_class->show = gtk_clutter_embed_show;
widget_class->hide = gtk_clutter_embed_hide;
+ widget_class->unmap = gtk_clutter_embed_unmap;
widget_class->expose_event = gtk_clutter_embed_expose_event;
widget_class->button_press_event = gtk_clutter_embed_button_event;
widget_class->button_release_event = gtk_clutter_embed_button_event;
widget_class->motion_notify_event = gtk_clutter_embed_motion_notify_event;
widget_class->expose_event = gtk_clutter_embed_expose_event;
widget_class->map_event = gtk_clutter_embed_map_event;
+ widget_class->unmap_event = gtk_clutter_embed_unmap_event;
widget_class->focus_in_event = gtk_clutter_embed_focus_in;
widget_class->focus_out_event = gtk_clutter_embed_focus_out;
widget_class->scroll_event = gtk_clutter_embed_scroll_event;
embed->priv = priv = GTK_CLUTTER_EMBED_GET_PRIVATE (embed);
GTK_WIDGET_SET_FLAGS (embed, GTK_CAN_FOCUS);
+ GTK_WIDGET_UNSET_FLAGS (embed, GTK_NO_WINDOW);
/* disable double-buffering: it's automatically provided
* by OpenGL
{
GtkAdjustment *h_adjust = priv->h_adjustment;
GtkAdjustment *v_adjust = priv->v_adjustment;
- ClutterUnit new_x, new_y;
+ gfloat new_x, new_y;
- new_x = CLUTTER_UNITS_FROM_FLOAT (gtk_adjustment_get_value (h_adjust));
- new_y = CLUTTER_UNITS_FROM_FLOAT (gtk_adjustment_get_value (v_adjust));
+ new_x = gtk_adjustment_get_value (h_adjust);
+ new_y = gtk_adjustment_get_value (v_adjust);
/* change the origin and queue a relayout */
if (new_x != priv->origin.x || new_y != priv->origin.y)
static gboolean
viewport_set_hadjustment_values (GtkClutterViewport *viewport,
- guint width)
+ gfloat width)
{
GtkClutterViewportPrivate *priv = viewport->priv;
GtkAdjustment *h_adjust = priv->h_adjustment;
if (priv->child && CLUTTER_ACTOR_IS_VISIBLE (priv->child))
{
- ClutterUnit natural_width;
+ gfloat natural_width;
clutter_actor_get_preferred_size (priv->child,
NULL, NULL,
&natural_width, NULL);
- gtk_adjustment_set_upper (h_adjust,
- MAX (CLUTTER_UNITS_TO_DEVICE (natural_width),
- width));
+ gtk_adjustment_set_upper (h_adjust, MAX (natural_width, width));
}
else
gtk_adjustment_set_upper (h_adjust, width);
static gboolean
viewport_set_vadjustment_values (GtkClutterViewport *viewport,
- guint height)
+ gfloat height)
{
GtkClutterViewportPrivate *priv = viewport->priv;
GtkAdjustment *v_adjust = priv->v_adjustment;
if (priv->child && CLUTTER_ACTOR_IS_VISIBLE (priv->child))
{
- ClutterUnit natural_height;
+ gfloat natural_height;
clutter_actor_get_preferred_size (priv->child,
NULL, NULL,
NULL, &natural_height);
- gtk_adjustment_set_upper (v_adjust,
- MAX (CLUTTER_UNITS_TO_DEVICE (natural_height),
- height));
+ gtk_adjustment_set_upper (v_adjust, MAX (natural_height, height));
}
else
gtk_adjustment_set_upper (v_adjust, height);
GtkClutterViewportPrivate *priv = viewport->priv;
GtkAdjustment **adj_p;
gboolean value_changed = FALSE;
- guint width, height;
+ gfloat width, height;
adj_p = (orientation == GTK_ORIENTATION_HORIZONTAL) ? &priv->h_adjustment
: &priv->v_adjustment;
static void
gtk_clutter_viewport_get_preferred_width (ClutterActor *actor,
- ClutterUnit for_height,
- ClutterUnit *min_width_p,
- ClutterUnit *natural_width_p)
+ gfloat for_height,
+ gfloat *min_width_p,
+ gfloat *natural_width_p)
{
GtkClutterViewportPrivate *priv = GTK_CLUTTER_VIEWPORT (actor)->priv;
static void
gtk_clutter_viewport_get_preferred_height (ClutterActor *actor,
- ClutterUnit for_width,
- ClutterUnit *min_height_p,
- ClutterUnit *natural_height_p)
+ gfloat for_width,
+ gfloat *min_height_p,
+ gfloat *natural_height_p)
{
GtkClutterViewportPrivate *priv = GTK_CLUTTER_VIEWPORT (actor)->priv;
}
static void
-gtk_clutter_viewport_allocate (ClutterActor *actor,
- const ClutterActorBox *box,
- gboolean origin_changed)
+gtk_clutter_viewport_allocate (ClutterActor *actor,
+ const ClutterActorBox *box,
+ ClutterAllocationFlags flags)
{
GtkClutterViewport *viewport = GTK_CLUTTER_VIEWPORT (actor);
GtkClutterViewportPrivate *priv = viewport->priv;
ClutterActorClass *parent_class;
gboolean h_adjustment_value_changed, v_adjustment_value_changed;
- guint width, height;
+ gfloat width, height;
parent_class = CLUTTER_ACTOR_CLASS (gtk_clutter_viewport_parent_class);
- parent_class->allocate (actor, box, origin_changed);
+ parent_class->allocate (actor, box, flags);
- width = CLUTTER_UNITS_TO_DEVICE (box->x2 - box->x1);
- height = CLUTTER_UNITS_TO_DEVICE (box->y2 - box->y1);
+ width = box->x2 - box->x1;
+ height = box->y2 - box->y1;
h_adjustment_value_changed =
viewport_set_hadjustment_values (viewport, width);
if (priv->child && CLUTTER_ACTOR_IS_VISIBLE (priv->child))
{
ClutterActorBox child_allocation = { 0, };
- ClutterUnit alloc_width, alloc_height;
+ gfloat alloc_width, alloc_height;
/* a viewport is a boundless actor which can contain a child
* without constraints; hence, we give any child exactly the
NULL, NULL,
&alloc_width, &alloc_height);
- child_allocation.x1 = clutter_actor_get_xu (priv->child);
- child_allocation.y1 = clutter_actor_get_yu (priv->child);
+ child_allocation.x1 = clutter_actor_get_x (priv->child);
+ child_allocation.y1 = clutter_actor_get_y (priv->child);
child_allocation.x2 = child_allocation.x1 + alloc_width;
child_allocation.y2 = child_allocation.y1 + alloc_height;
- clutter_actor_allocate (priv->child, &child_allocation, origin_changed);
+ clutter_actor_allocate (priv->child, &child_allocation, flags);
}
gtk_adjustment_changed (priv->h_adjustment);
/* translate the paint environment by the same amount
* defined by the origin value
*/
- cogl_translate (CLUTTER_UNITS_TO_FLOAT (priv->origin.x) * -1,
- CLUTTER_UNITS_TO_FLOAT (priv->origin.y) * -1,
- CLUTTER_UNITS_TO_FLOAT (priv->origin.z) * -1);
+ cogl_translate (priv->origin.x * -1,
+ priv->origin.y * -1,
+ priv->origin.z * -1);
/* the child will be painted in the new frame of reference */
if (priv->child && CLUTTER_ACTOR_IS_VISIBLE (priv->child))
priv = viewport->priv;
if (x)
- *x = CLUTTER_UNITS_TO_FLOAT (priv->origin.x);
+ *x = priv->origin.x;
if (y)
- *y = CLUTTER_UNITS_TO_FLOAT (priv->origin.y);
+ *y = priv->origin.y;
if (z)
- *z = CLUTTER_UNITS_TO_FLOAT (priv->origin.z);
+ *z = priv->origin.z;
}
{
if (event->type == CLUTTER_BUTTON_RELEASE)
{
- gint x, y;
+ gfloat x, y;
clutter_event_get_coords (event, &x, &y);
- g_print ("Event captured at (%d, %d)\n", x, y);
+ g_print ("Event captured at (%.2f, %.2f)\n", x, y);
}
return FALSE;
GtkWidget *widget, *vbox, *hbox, *button, *label, *box;
ClutterActor *actor;
GdkPixbuf *pixbuf = NULL;
- guint width, height;
+ gfloat width, height;
ClutterColor stage_color = {255, 255, 255, 255};
ClutterColor text_color = {0, 0, 0, 255};
#include <clutter-gtk/clutter-gtk.h>
static void
-on_stage2_allocation (GObject *gobject,
- GParamSpec *pspec,
- ClutterActor *texture)
+on_stage2_allocation_changed (ClutterActor *stage_2,
+ const ClutterActorBox *allocation,
+ ClutterAllocationFlags flags,
+ ClutterActor *texture_2)
{
- gint width = clutter_actor_get_width (CLUTTER_ACTOR (gobject));
- gint height = clutter_actor_get_height (CLUTTER_ACTOR (gobject));
-
- clutter_actor_set_position (texture, width / 2, height / 2);
+ clutter_actor_set_position (texture_2,
+ (allocation->x2 - allocation->x1) / 2,
+ (allocation->y2 - allocation->y1) / 2);
}
int
clutter_actor_set_position (tex2, 160, 60);
clutter_stage_add (stage2, tex2);
- g_signal_connect (stage2, "notify::allocation",
- G_CALLBACK (on_stage2_allocation),
- tex2);
-
gtk_container_add (GTK_CONTAINER (vbox), clutter2);
+ g_signal_connect (stage2, "allocation-changed",
+ G_CALLBACK (on_stage2_allocation_changed),
+ tex2);
+
gtk_widget_show_all (window);
clutter_actor_show_all (stage1);
clutter_actor_show_all (stage2);
if (event->type == CLUTTER_BUTTON_PRESS)
{
ClutterActor *a;
- gint x, y;
+ gfloat x, y;
clutter_event_get_coords (event, &x, &y);
- a = clutter_stage_get_actor_at_pos (stage, x, y);
+ a = clutter_stage_get_actor_at_pos (stage, CLUTTER_PICK_ALL, x, y);
if (a && (CLUTTER_IS_TEXTURE (a) || CLUTTER_IS_CLONE (a)))
clutter_actor_hide (a);
}
/* Timeline handler */
void
frame_cb (ClutterTimeline *timeline,
- gint frame_num,
+ gint msecs,
gpointer data)
{
SuperOH *oh = (SuperOH *)data;
gint i;
+ guint rotation = clutter_timeline_get_progress (timeline) * 360.0f;
#if TRAILS
oh->bgpixb = clutter_stage_snapshot (CLUTTER_STAGE (stage),
/* Rotate everything clockwise about stage center*/
clutter_actor_set_rotation (CLUTTER_ACTOR (oh->group),
CLUTTER_Z_AXIS,
- frame_num,
+ rotation,
WINWIDTH / 2, WINHEIGHT / 2, 0);
for (i = 0; i < NHANDS; i++)
/* rotate each hand around there centers */
clutter_actor_set_rotation (oh->hand[i],
CLUTTER_Z_AXIS,
- - 6.0 * frame_num,
+ - 6.0 * rotation,
clutter_actor_get_width (oh->hand[i]) / 2,
clutter_actor_get_height (oh->hand[i]) / 2,
0);
if (fade == TRUE)
- clutter_actor_set_opacity (oh->hand[i], (255 - (frame_num % 255)));
+ clutter_actor_set_opacity (oh->hand[i], (255 - (rotation % 255)));
}
/*
clutter_actor_show_all (CLUTTER_ACTOR (oh->group));
/* Create a timeline to manage animation */
- timeline = clutter_timeline_new (360, 60); /* num frames, fps */
+ timeline = clutter_timeline_new (6000);
g_object_set(timeline, "loop", TRUE, NULL); /* have it loop */
/* fire a callback for frame change */
G_STRLOC,
g_timer_elapsed (timer, NULL));
- g_print ("%s: tex.size = %d, %d\n",
+ g_print ("%s: tex.size = %.2f, %.2f\n",
G_STRLOC,
clutter_actor_get_width (tex),
clutter_actor_get_height (tex));