[libchamplain] Insert tile content into parent only when state set to DONE
- From: Pierre-Luc Beaudoin <plbeaudoin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libchamplain] Insert tile content into parent only when state set to DONE
- Date: Tue, 23 Mar 2010 14:40:15 +0000 (UTC)
commit 3d4ca32f840d6dd1f26295ccbbc76f69cc7af100
Author: JiÅ?Ã Techet <techet gmail com>
Date: Fri Mar 12 00:15:19 2010 +0100
Insert tile content into parent only when state set to DONE
We call set_content() on tile also when we want to validate the tile only
and if the tile is not validated, the new contents is set again by
calling set_content(). This would cause redrawing the tile twice instead
of once. Also the tile is repositioned only after the state is set to
DONE so in between the tile is displayed at incorrect place.
Signed-off-by: JiÅ?Ã Techet <techet gmail com>
champlain/champlain-tile.c | 102 ++++++++++++++++++++------------------------
1 files changed, 46 insertions(+), 56 deletions(-)
---
diff --git a/champlain/champlain-tile.c b/champlain/champlain-tile.c
index c0e3775..c7b4ca5 100644
--- a/champlain/champlain-tile.c
+++ b/champlain/champlain-tile.c
@@ -59,6 +59,7 @@ struct _ChamplainTilePrivate {
ChamplainState state; /* The tile state: loading, validation, done */
ClutterActor *content_actor; /* The actual tile actor */
+ gboolean fade_in;
GTimeVal *modified_time; /* The last modified time of the cache */
gchar* etag; /* The HTTP ETag sent by the server */
@@ -140,8 +141,6 @@ champlain_tile_dispose (GObject *object)
G_OBJECT_CLASS (champlain_tile_parent_class)->dispose (object);
}
-
-
static void
champlain_tile_finalize (GObject *object)
{
@@ -296,6 +295,7 @@ champlain_tile_init (ChamplainTile *self)
priv->size = 0;
priv->modified_time = NULL;
priv->etag = NULL;
+ priv->fade_in = FALSE;
priv->content_actor = NULL;
}
@@ -473,6 +473,15 @@ champlain_tile_set_size (ChamplainTile *self,
g_object_notify (G_OBJECT (self), "size");
}
+static void
+fade_in_completed (ClutterAnimation *animation, ChamplainTile *self)
+{
+ if (clutter_group_get_n_children (CLUTTER_GROUP (self)) > 1)
+ clutter_actor_destroy (clutter_group_get_nth_child (CLUTTER_GROUP (self), 0));
+
+ g_object_unref (self);
+}
+
/**
* champlain_tile_set_state:
* @self: the #ChamplainTile
@@ -483,13 +492,41 @@ champlain_tile_set_size (ChamplainTile *self,
* Since: 0.4
*/
void
-champlain_tile_set_state (ChamplainTile *self,
- ChamplainState state)
+champlain_tile_set_state (ChamplainTile *self, ChamplainState state)
{
g_return_if_fail (CHAMPLAIN_TILE (self));
- GET_PRIVATE (self)->state = state;
+ ChamplainTilePrivate *priv = GET_PRIVATE (self);
+ if (state == priv->state)
+ return;
+
+ if (state == CHAMPLAIN_STATE_DONE && priv->content_actor &&
+ clutter_actor_get_parent (priv->content_actor) != CLUTTER_ACTOR (self))
+ {
+ if (!priv->fade_in)
+ clutter_group_remove_all (CLUTTER_GROUP (self));
+
+ clutter_container_add_actor (CLUTTER_CONTAINER (self), priv->content_actor);
+
+ if (priv->fade_in)
+ {
+ ClutterAnimation *animation;
+
+ clutter_actor_set_opacity (priv->content_actor, 0);
+
+ animation = clutter_actor_animate (priv->content_actor,
+ CLUTTER_EASE_IN_CUBIC,
+ 500,
+ "opacity", 255,
+ NULL);
+
+ g_object_ref (self);
+ g_signal_connect (animation, "completed", G_CALLBACK (fade_in_completed), self);
+ }
+ }
+
+ priv->state = state;
g_object_notify (G_OBJECT (self), "state");
}
@@ -616,25 +653,6 @@ champlain_tile_set_etag (ChamplainTile *self,
g_object_notify (G_OBJECT (self), "etag");
}
-typedef struct {
- ClutterActor *old_actor;
-} FadeInCompletedData;
-
-static void
-fade_in_completed (ClutterAnimation *animation,
- FadeInCompletedData *data)
-{
- ClutterActor *old_actor = data->old_actor;
-
- if (old_actor)
- {
- g_object_remove_weak_pointer (G_OBJECT (old_actor), (gpointer*)&data->old_actor);
- clutter_actor_destroy (old_actor);
- }
-
- g_free(data);
-}
-
/**
* champlain_tile_set_content:
* @self: the #ChamplainTile
@@ -655,39 +673,11 @@ champlain_tile_set_content (ChamplainTile *self,
ChamplainTilePrivate *priv = GET_PRIVATE (self);
- if (priv->content_actor)
- {
- /* it sometimes happen that the priv->content_actor has been destroyed,
- * this assert will help determine when with no impact on the user */
- g_assert (CLUTTER_IS_ACTOR (priv->content_actor));
-
- if (!fade_in)
- clutter_container_remove_actor (CLUTTER_CONTAINER (self), priv->content_actor);
- }
-
- clutter_container_add_actor (CLUTTER_CONTAINER (self), actor);
-
- if (fade_in)
- {
- FadeInCompletedData *data;
- ClutterAnimation *animation;
-
- clutter_actor_set_opacity (actor, 0);
+ priv->fade_in = fade_in;
- animation = clutter_actor_animate (actor,
- CLUTTER_EASE_IN_CUBIC,
- 500,
- "opacity", 255,
- NULL);
-
- data = g_new (FadeInCompletedData, 1);
- data->old_actor = priv->content_actor;
-
- if (data->old_actor)
- g_object_add_weak_pointer (G_OBJECT (data->old_actor), (gpointer*)&data->old_actor);
-
- g_signal_connect (animation, "completed", G_CALLBACK (fade_in_completed), data);
- }
+ if (priv->content_actor &&
+ clutter_actor_get_parent (priv->content_actor) != CLUTTER_ACTOR (self))
+ clutter_actor_destroy (priv->content_actor);
priv->content_actor = actor;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]