gnome-games r8166 - trunk/aisleriot
- From: jclinton svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-games r8166 - trunk/aisleriot
- Date: Tue, 21 Oct 2008 19:47:35 +0000 (UTC)
Author: jclinton
Date: Tue Oct 21 19:47:35 2008
New Revision: 8166
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8166&view=rev
Log:
Moved the animated cards to a ClutterGroup that is layered above the
slots so that the cards won't move behind the slots.
Modified:
trunk/aisleriot/board.c
trunk/aisleriot/slot-renderer.c
trunk/aisleriot/slot-renderer.h
Modified: trunk/aisleriot/board.c
==============================================================================
--- trunk/aisleriot/board.c (original)
+++ trunk/aisleriot/board.c Tue Oct 21 19:47:35 2008
@@ -28,6 +28,7 @@
#include <gdk/gdkkeysyms.h>
#include <clutter-gtk/gtk-clutter-embed.h>
+#include <clutter/clutter-group.h>
#include <libgames-support/games-card-images.h>
#include <libgames-support/games-files.h>
@@ -147,6 +148,9 @@
ClutterActor *moving_cards_group;
GByteArray *moving_cards;
+ /* A group to put animated cards above the slots */
+ ClutterActor *animation_layer;
+
/* The 'reveal card' action's slot and card link */
Slot *show_card_slot;
int show_card_id;
@@ -891,6 +895,8 @@
FALSE,
&anim.cardx,
&anim.cardy);
+ anim.cardx += slot->rect.x;
+ anim.cardy += slot->rect.y;
anim.face_down = old_card.attr.face_down;
g_array_append_val (animations, anim);
@@ -914,8 +920,8 @@
&& added_card.attr.rank == removed_card->card.attr.rank) {
AisleriotAnimStart anim;
- anim.cardx = removed_card->cardx - slot->rect.x;
- anim.cardy = removed_card->cardy - slot->rect.y;
+ anim.cardx = removed_card->cardx;
+ anim.cardy = removed_card->cardy;
anim.face_down = removed_card->card.attr.face_down;
g_array_append_val (animations, anim);
@@ -958,11 +964,17 @@
slot->slot_renderer = aisleriot_slot_renderer_new (priv->textures, slot);
g_object_ref_sink (slot->slot_renderer);
+ aisleriot_slot_renderer_set_animation_layer
+ (AISLERIOT_SLOT_RENDERER (slot->slot_renderer),
+ CLUTTER_CONTAINER (priv->animation_layer));
+
clutter_actor_set_position (slot->slot_renderer,
slot->rect.x, slot->rect.y);
clutter_container_add (CLUTTER_CONTAINER (stage),
slot->slot_renderer, NULL);
+
+ clutter_actor_raise_top (priv->animation_layer);
}
aisleriot_slot_renderer_set_animations
@@ -3072,6 +3084,7 @@
{
GtkWidget *widget = GTK_WIDGET (board);
AisleriotBoardPrivate *priv;
+ ClutterActor *stage;
priv = board->priv = AISLERIOT_BOARD_GET_PRIVATE (board);
@@ -3101,6 +3114,11 @@
#ifdef HAVE_MAEMO
gtk_widget_tap_and_hold_setup (widget, NULL, NULL, GTK_TAP_AND_HOLD_PASS_PRESS);
#endif
+
+ stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (board));
+ priv->animation_layer = g_object_ref_sink (clutter_group_new ());
+ clutter_container_add (CLUTTER_CONTAINER (stage),
+ priv->animation_layer, NULL);
}
static GObject *
@@ -3177,6 +3195,11 @@
priv->textures = NULL;
}
+ if (priv->animation_layer) {
+ g_object_unref (priv->animation_layer);
+ priv->animation_layer = NULL;
+ }
+
G_OBJECT_CLASS (aisleriot_board_parent_class)->dispose (object);
}
Modified: trunk/aisleriot/slot-renderer.c
==============================================================================
--- trunk/aisleriot/slot-renderer.c (original)
+++ trunk/aisleriot/slot-renderer.c Tue Oct 21 19:47:35 2008
@@ -19,8 +19,8 @@
#include <config.h>
#include <clutter/clutter-actor.h>
-#include <clutter/clutter-container.h>
#include <clutter/clutter-timeline.h>
+#include <clutter/clutter-container.h>
#include <clutter/clutter-behaviour-rotate.h>
#include <clutter/clutter-behaviour-depth.h>
#include <clutter/clutter-behaviour-path.h>
@@ -48,18 +48,10 @@
static void aisleriot_slot_renderer_set_cache (AisleriotSlotRenderer *srend,
AisleriotCardCache *cache);
-static void clutter_container_iface_init (ClutterContainerIface *iface);
-
-static void aisleriot_slot_renderer_allocate (ClutterActor *actor,
- const ClutterActorBox *box,
- gboolean origin_changed);
-
static void completed_cb (AisleriotSlotRenderer *srend);
-G_DEFINE_TYPE_WITH_CODE (AisleriotSlotRenderer, aisleriot_slot_renderer,
- CLUTTER_TYPE_ACTOR,
- G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTAINER,
- clutter_container_iface_init));
+G_DEFINE_TYPE (AisleriotSlotRenderer, aisleriot_slot_renderer,
+ CLUTTER_TYPE_ACTOR);
#define AISLERIOT_SLOT_RENDERER_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), AISLERIOT_TYPE_SLOT_RENDERER, \
@@ -79,6 +71,8 @@
ClutterTimeline *timeline;
guint completed_handler;
GArray *animations;
+
+ ClutterContainer *animation_layer;
};
struct _AnimationData
@@ -93,7 +87,8 @@
PROP_CACHE,
PROP_SLOT,
- PROP_HIGHLIGHT
+ PROP_HIGHLIGHT,
+ PROP_ANIMATION_LAYER
};
static void
@@ -110,7 +105,6 @@
gobject_class->get_property = aisleriot_slot_renderer_get_property;
actor_class->paint = aisleriot_slot_renderer_paint;
- actor_class->allocate = aisleriot_slot_renderer_allocate;
pspec = g_param_spec_object ("cache", NULL, NULL,
AISLERIOT_TYPE_CARD_CACHE,
@@ -139,6 +133,15 @@
G_PARAM_STATIC_BLURB);
g_object_class_install_property (gobject_class, PROP_HIGHLIGHT, pspec);
+ pspec = g_param_spec_object ("animation-layer", NULL, NULL,
+ CLUTTER_TYPE_CONTAINER,
+ G_PARAM_WRITABLE |
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB);
+ g_object_class_install_property (gobject_class, PROP_ANIMATION_LAYER, pspec);
+
g_type_class_add_private (klass, sizeof (AisleriotSlotRendererPrivate));
}
@@ -173,6 +176,8 @@
priv->timeline = NULL;
}
+ aisleriot_slot_renderer_set_animation_layer (self, NULL);
+
G_OBJECT_CLASS (aisleriot_slot_renderer_parent_class)->dispose (object);
}
@@ -236,6 +241,11 @@
g_value_get_int (value));
break;
+ case PROP_ANIMATION_LAYER:
+ aisleriot_slot_renderer_set_animation_layer (srend,
+ g_value_get_object (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -256,6 +266,11 @@
aisleriot_slot_renderer_get_highlight (srend));
break;
+ case PROP_ANIMATION_LAYER:
+ g_value_set_object (value,
+ aisleriot_slot_renderer_get_animation_layer (srend));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -331,14 +346,6 @@
0, 0, CFX_ONE, CFX_ONE);
}
}
-
- /* Paint the animated actors */
- for (i = 0; i < priv->animations->len; i++) {
- AnimationData *data = &g_array_index (priv->animations, AnimationData, i);
-
- if (CLUTTER_ACTOR_IS_VISIBLE (data->card_tex))
- clutter_actor_paint (data->card_tex);
- }
}
guint
@@ -353,14 +360,51 @@
aisleriot_slot_renderer_set_highlight (AisleriotSlotRenderer *srend,
gint highlight)
{
- AisleriotSlotRendererPrivate *priv = srend->priv;
+ AisleriotSlotRendererPrivate *priv;
g_return_if_fail (AISLERIOT_IS_SLOT_RENDERER (srend));
+ priv = srend->priv;
+
priv->highlight_start = highlight;
priv->show_highlight = priv->highlight_start != G_MAXINT;
clutter_actor_queue_redraw (CLUTTER_ACTOR (srend));
+
+ g_object_notify (G_OBJECT (srend), "highlight");
+}
+
+ClutterContainer *
+aisleriot_slot_renderer_get_animation_layer (AisleriotSlotRenderer *srend)
+{
+ AisleriotSlotRendererPrivate *priv;
+
+ g_return_val_if_fail (AISLERIOT_IS_SLOT_RENDERER (srend), NULL);
+
+ priv = srend->priv;
+
+ return priv->animation_layer;
+}
+
+void
+aisleriot_slot_renderer_set_animation_layer (AisleriotSlotRenderer *srend,
+ ClutterContainer *animation_layer)
+{
+ AisleriotSlotRendererPrivate *priv;
+
+ g_return_if_fail (AISLERIOT_IS_SLOT_RENDERER (srend));
+
+ priv = srend->priv;
+
+ if (animation_layer)
+ g_object_ref (animation_layer);
+
+ if (priv->animation_layer)
+ g_object_unref (priv->animation_layer);
+
+ priv->animation_layer = animation_layer;
+
+ g_object_notify (G_OBJECT (srend), "animation-layer");
}
void
@@ -411,7 +455,9 @@
anim_data.card_tex = aisleriot_card_new (priv->cache, card);
g_object_ref_sink (anim_data.card_tex);
- clutter_actor_set_parent (anim_data.card_tex, CLUTTER_ACTOR (srend));
+ if (priv->animation_layer)
+ clutter_container_add (priv->animation_layer,
+ CLUTTER_ACTOR (anim_data.card_tex), NULL);
cogl_tex = aisleriot_card_cache_get_card_texture (priv->cache, card, FALSE);
card_width = cogl_texture_get_width (cogl_tex);
@@ -422,8 +468,11 @@
knots[0].x = anims[i].cardx;
knots[0].y = anims[i].cardy;
- knots[1].x = priv->slot->pixeldx * card_num;
- knots[1].y = priv->slot->pixeldy * card_num;
+
+ aisleriot_game_get_card_offset (priv->slot, card_num, FALSE,
+ &knots[1].x, &knots[1].y);
+ knots[1].x += priv->slot->rect.x;
+ knots[1].y += priv->slot->rect.y;
alpha = clutter_alpha_new_full (priv->timeline, CLUTTER_ALPHA_RAMP_INC,
NULL, NULL);
@@ -481,93 +530,3 @@
renderer instead */
clutter_actor_queue_redraw (CLUTTER_ACTOR (srend));
}
-
-static void
-aisleriot_slot_renderer_real_add (ClutterContainer *container,
- ClutterActor *actor)
-{
- g_critical ("Do not add actors to an AisleriotSlotRenderer directly");
-}
-
-static void
-aisleriot_slot_renderer_real_remove (ClutterContainer *container,
- ClutterActor *actor)
-{
- g_object_ref (actor);
-
- clutter_actor_unparent (actor);
-
- clutter_actor_queue_relayout (CLUTTER_ACTOR (container));
-
- if (CLUTTER_ACTOR_IS_VISIBLE (CLUTTER_ACTOR (container)))
- clutter_actor_queue_redraw (CLUTTER_ACTOR (container));
-
- g_object_unref (actor);
-}
-
-static void
-aisleriot_slot_renderer_real_foreach (ClutterContainer *container,
- ClutterCallback callback,
- gpointer user_data)
-{
- AisleriotSlotRenderer *srend = AISLERIOT_SLOT_RENDERER (container);
- AisleriotSlotRendererPrivate *priv = srend->priv;
- guint i;
-
- for (i = 0; i < priv->animations->len; i++) {
- AnimationData *data = &g_array_index (priv->animations, AnimationData, i);
-
- (* callback) (data->card_tex, user_data);
- }
-}
-
-static void
-aisleriot_slot_renderer_real_raise (ClutterContainer *container,
- ClutterActor *actor,
- ClutterActor *sibling)
-{
-}
-
-static void
-aisleriot_slot_renderer_real_lower (ClutterContainer *container,
- ClutterActor *actor,
- ClutterActor *sibling)
-{
-}
-
-static void
-aisleriot_slot_renderer_real_sort_depth_order (ClutterContainer *container)
-{
-}
-
-static void
-clutter_container_iface_init (ClutterContainerIface *iface)
-{
- iface->add = aisleriot_slot_renderer_real_add;
- iface->remove = aisleriot_slot_renderer_real_remove;
- iface->foreach = aisleriot_slot_renderer_real_foreach;
- iface->raise = aisleriot_slot_renderer_real_raise;
- iface->lower = aisleriot_slot_renderer_real_lower;
- iface->sort_depth_order = aisleriot_slot_renderer_real_sort_depth_order;
-}
-
-static void
-aisleriot_slot_renderer_allocate (ClutterActor *actor,
- const ClutterActorBox *box,
- gboolean origin_changed)
-{
- AisleriotSlotRenderer *srend = (AisleriotSlotRenderer *) actor;
- AisleriotSlotRendererPrivate *priv = srend->priv;
- guint i;
-
- /* chain up to set actor->allocation */
- CLUTTER_ACTOR_CLASS (aisleriot_slot_renderer_parent_class)
- ->allocate (actor, box, origin_changed);
-
- for (i = 0; i < priv->animations->len; i++) {
- AnimationData *anim = &g_array_index (priv->animations, AnimationData, i);
-
- clutter_actor_allocate_preferred_size (anim->card_tex,
- origin_changed);
- }
-}
Modified: trunk/aisleriot/slot-renderer.h
==============================================================================
--- trunk/aisleriot/slot-renderer.h (original)
+++ trunk/aisleriot/slot-renderer.h Tue Oct 21 19:47:35 2008
@@ -20,6 +20,7 @@
#define __AISLERIOT_SLOT_RENDERER_H__
#include <clutter/clutter-actor.h>
+#include <clutter/clutter-container.h>
#include <libgames-support/games-card-images.h>
#include "card-cache.h"
#include "game.h"
@@ -79,6 +80,12 @@
gint hightlight_start);
guint aisleriot_slot_renderer_get_highlight (AisleriotSlotRenderer *srend);
+ClutterContainer *aisleriot_slot_renderer_get_animation_layer
+ (AisleriotSlotRenderer *srend);
+void aisleriot_slot_renderer_set_animation_layer
+ (AisleriotSlotRenderer *srend,
+ ClutterContainer *animation_layer);
+
void aisleriot_slot_renderer_set_animations (AisleriotSlotRenderer *srend,
guint n_anims,
const AisleriotAnimStart *anims);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]