From: Pierre-Luc Beaudoin Date: Fri, 1 May 2009 20:02:36 +0000 (-0400) Subject: Finally get totally rid of tile_ready and friends X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f396042cbc287c7b522b52d2f7f18da0a7bdcb5;p=libchamplain Finally get totally rid of tile_ready and friends Tile are now updated on their state change! (as it should always have been) --- diff --git a/champlain/champlain-cache.c b/champlain/champlain-cache.c index 3a8b4c1..34732b4 100644 --- a/champlain/champlain-cache.c +++ b/champlain/champlain-cache.c @@ -1,5 +1,5 @@ /* -* Copyright (C) 2008 Pierre-Luc Beaudoin +* Copyright (C) 2009 Pierre-Luc Beaudoin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -242,7 +242,7 @@ champlain_cache_fill_tile (ChamplainCache *self, /* Load the cached version */ actor = clutter_texture_new_from_file (filename, &error); - champlain_tile_set_actor (tile, actor); + champlain_tile_set_content (tile, actor, FALSE); g_object_unref (file); g_object_unref (info); diff --git a/champlain/champlain-map.c b/champlain/champlain-map.c index 8dacd1a..6c01938 100644 --- a/champlain/champlain-map.c +++ b/champlain/champlain-map.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Pierre-Luc Beaudoin + * Copyright (C) 2008-2009 Pierre-Luc Beaudoin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/champlain/champlain-network-map-source.c b/champlain/champlain-network-map-source.c index 3c55adf..4e17e8d 100644 --- a/champlain/champlain-network-map-source.c +++ b/champlain/champlain-network-map-source.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, 2009 Pierre-Luc Beaudoin + * Copyright (C) 2008-2009 Pierre-Luc Beaudoin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -395,7 +395,7 @@ create_error_tile (ChamplainTile* tile) cairo_destroy (cr); - champlain_tile_set_actor (tile, actor); + champlain_tile_set_content (tile, actor, TRUE); clutter_actor_show (actor); champlain_tile_set_state (tile, CHAMPLAIN_STATE_DONE); @@ -411,7 +411,7 @@ file_loaded_cb (SoupSession *session, GError *error = NULL; gchar* path = NULL; const gchar *filename = NULL; - ClutterActor *actor, *previous_actor = NULL; + ClutterActor *actor; GFile *file; GFileInfo *info; ChamplainCache *cache = champlain_cache_get_default (); @@ -439,7 +439,6 @@ file_loaded_cb (SoupSession *session, g_free (now); champlain_tile_set_state (ctx->tile, CHAMPLAIN_STATE_DONE); - champlain_view_tile_uptodate (ctx->view, ctx->zoom_level, ctx->tile); g_object_unref (ctx->tile); g_object_unref (ctx->zoom_level); g_free (ctx); @@ -532,11 +531,7 @@ file_loaded_cb (SoupSession *session, } } - previous_actor = champlain_tile_get_actor (ctx->tile); - if (previous_actor) - g_object_ref (previous_actor); /* to be unrefed by the view */ - - champlain_tile_set_actor (ctx->tile, actor); + champlain_tile_set_content (ctx->tile, actor, TRUE); DEBUG ("Tile loaded from network"); cleanup: @@ -544,7 +539,6 @@ cleanup: g_free (path); finish: champlain_tile_set_state (ctx->tile, CHAMPLAIN_STATE_DONE); - champlain_view_tile_updated (ctx->view, ctx->zoom_level, ctx->tile, previous_actor); g_object_unref (ctx->tile); g_object_unref (ctx->zoom_level); g_free (ctx); @@ -581,7 +575,6 @@ champlain_network_map_source_get_tile (ChamplainMapSource *map_source, champlain_tile_set_state (tile, CHAMPLAIN_STATE_DONE); DEBUG ("Tile loaded from cache"); - champlain_view_tile_ready (view, zoom_level, tile); } diff --git a/champlain/champlain-private.h b/champlain/champlain-private.h index 0b33464..9af67e0 100644 --- a/champlain/champlain-private.h +++ b/champlain/champlain-private.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Pierre-Luc Beaudoin + * Copyright (C) 2008-2009 Pierre-Luc Beaudoin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -45,15 +45,4 @@ typedef struct gint height; } ChamplainRectangle; -void champlain_view_tile_ready (ChamplainView *view, - ChamplainZoomLevel *level, - ChamplainTile *tile); -void champlain_view_tile_updated (ChamplainView *view, - ChamplainZoomLevel *level, - ChamplainTile *tile, - ClutterActor *actor); -void champlain_view_tile_uptodate (ChamplainView *view, - ChamplainZoomLevel *level, - ChamplainTile *tile); - #endif diff --git a/champlain/champlain-tile.c b/champlain/champlain-tile.c index bdde921..f8ba6f7 100644 --- a/champlain/champlain-tile.c +++ b/champlain/champlain-tile.c @@ -1,5 +1,5 @@ /* -* Copyright (C) 2008 Pierre-Luc Beaudoin + * Copyright (C) 2008-2009 Pierre-Luc Beaudoin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -27,6 +27,7 @@ #include #include #include +#include G_DEFINE_TYPE (ChamplainTile, champlain_tile, G_TYPE_OBJECT) @@ -44,6 +45,7 @@ enum PROP_FILENAME, PROP_STATE, PROP_ACTOR, + PROP_CONTENT, PROP_ETAG }; @@ -60,6 +62,7 @@ struct _ChamplainTilePrivate { ChamplainState state; gchar *filename; ClutterActor *actor; + ClutterActor *content_actor; GTimeVal *modified_time; gchar* etag; @@ -98,6 +101,9 @@ champlain_tile_get_property (GObject *object, case PROP_ACTOR: g_value_set_object (value, champlain_tile_get_actor (self)); break; + case PROP_CONTENT: + g_value_set_object (value, champlain_tile_get_content (self)); + break; case PROP_ETAG: g_value_set_string (value, champlain_tile_get_etag (self)); break; @@ -139,6 +145,9 @@ champlain_tile_set_property (GObject *object, case PROP_ACTOR: champlain_tile_set_actor (self, g_value_get_object (value)); break; + case PROP_CONTENT: + champlain_tile_set_content (self, g_value_get_object (value), FALSE); + break; case PROP_ETAG: champlain_tile_set_etag (self, g_value_get_string (value)); break; @@ -159,6 +168,7 @@ champlain_tile_dispose (GObject *object) g_object_unref (G_OBJECT (priv->actor)); priv->actor = NULL; } + g_object_unref (priv->content_actor); G_OBJECT_CLASS (champlain_tile_parent_class)->dispose (object); } @@ -255,6 +265,14 @@ champlain_tile_class_init (ChamplainTileClass *klass) CLUTTER_TYPE_ACTOR, G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_CONTENT, + g_param_spec_object ("content", + "Content", + "The tile's content", + CLUTTER_TYPE_ACTOR, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, PROP_ETAG, g_param_spec_string ("etag", @@ -279,8 +297,8 @@ champlain_tile_init (ChamplainTile *self) priv->filename = g_strdup (""); priv->etag = NULL; - /* Can't call champlain_tile_set_actor (self, NULL); because the assertion will fail */ - priv->actor = NULL; + priv->actor = g_object_ref (clutter_group_new ()); + priv->content_actor = NULL; } ChamplainTile* @@ -533,3 +551,81 @@ champlain_tile_set_etag (ChamplainTile *self, priv->etag = g_strdup (etag); g_object_notify (G_OBJECT (self), "etag"); } + +typedef struct { + ChamplainTile *tile; + ClutterEffectTemplate *etemplate; + ClutterTimeline *timeline; + ClutterActor *old_actor; +} AnimationContext; + +static void +fade_in_completed (ClutterTimeline *timeline, + gpointer data) +{ + AnimationContext* ctx = (AnimationContext*) data; + ChamplainTilePrivate *priv = GET_PRIVATE (ctx->tile); + + if (ctx->old_actor != NULL) + { + g_object_unref (ctx->old_actor); + clutter_container_remove (CLUTTER_CONTAINER (priv->actor), ctx->old_actor, NULL); + } + + g_object_unref (ctx->tile); + g_object_unref (ctx->timeline); + g_object_unref (ctx->etemplate); + g_free (ctx); + +} + + +void +champlain_tile_set_content (ChamplainTile *self, ClutterActor *actor, gboolean fade_in) +{ + g_return_if_fail(CHAMPLAIN_TILE(self)); + g_return_if_fail(actor != NULL); + + ChamplainTilePrivate *priv = GET_PRIVATE (self); + ClutterActor *old_actor = NULL; + + if (priv->content_actor != NULL) + { + if (fade_in == TRUE) + old_actor = g_object_ref (priv->content_actor); + else + clutter_container_remove (CLUTTER_CONTAINER (priv->actor), priv->content_actor, NULL); + g_object_unref (priv->content_actor); + } + + clutter_container_add (CLUTTER_CONTAINER (priv->actor), actor, NULL); + + /* fixme: etemplate are leaked here */ + if (fade_in == TRUE) + { + AnimationContext *ctx = g_new0 (AnimationContext, 1); + ctx->tile = g_object_ref (self); + ctx->timeline = clutter_timeline_new_for_duration (750); + ctx->etemplate = clutter_effect_template_new (ctx->timeline, CLUTTER_ALPHA_SINE_INC); + ctx->old_actor = old_actor; + + g_signal_connect (ctx->timeline, "completed", G_CALLBACK (fade_in_completed), ctx); + + clutter_actor_set_opacity (actor, 0); + clutter_effect_fade (ctx->etemplate, actor, 255, NULL, NULL); + } + + priv->content_actor = g_object_ref (actor); + g_object_notify (G_OBJECT (self), "content"); +} + +ClutterActor * +champlain_tile_get_content (ChamplainTile *self) +{ + g_return_val_if_fail(CHAMPLAIN_TILE(self), NULL); + + ChamplainTilePrivate *priv = GET_PRIVATE (self); + + return priv->content_actor; +} + diff --git a/champlain/champlain-tile.h b/champlain/champlain-tile.h index 63bb639..01f8be8 100644 --- a/champlain/champlain-tile.h +++ b/champlain/champlain-tile.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Pierre-Luc Beaudoin + * Copyright (C) 2008-2009 Pierre-Luc Beaudoin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -64,6 +64,7 @@ ChamplainState champlain_tile_get_state (ChamplainTile *self); G_CONST_RETURN gchar * champlain_tile_get_uri (ChamplainTile *self); G_CONST_RETURN gchar * champlain_tile_get_filename (ChamplainTile *self); ClutterActor * champlain_tile_get_actor (ChamplainTile *self); +ClutterActor * champlain_tile_get_content (ChamplainTile *self); const GTimeVal * champlain_tile_get_modified_time (ChamplainTile *self); char * champlain_tile_get_modified_time_string (ChamplainTile *self); const char * champlain_tile_get_etag (ChamplainTile *self); @@ -76,6 +77,7 @@ void champlain_tile_set_state (ChamplainTile *self, ChamplainState state); void champlain_tile_set_uri (ChamplainTile *self, const gchar *uri); void champlain_tile_set_filename (ChamplainTile *self, const gchar *filename); void champlain_tile_set_actor (ChamplainTile *self, ClutterActor* actor); +void champlain_tile_set_content (ChamplainTile *self, ClutterActor* actor, gboolean fade_in); void champlain_tile_set_etag (ChamplainTile *self, const gchar *etag); void champlain_tile_set_modified_time (ChamplainTile *self, GTimeVal *time); diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c index 9d40b48..0c84840 100644 --- a/champlain/champlain-view.c +++ b/champlain/champlain-view.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, 2009 Pierre-Luc Beaudoin + * Copyright (C) 2008-2009 Pierre-Luc Beaudoin * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -1509,6 +1509,8 @@ view_load_visible_tiles (ChamplainView *view) g_object_set (G_OBJECT (tile), "x", i, "y", j, NULL); g_signal_connect (tile, "notify::state", G_CALLBACK (tile_state_notify), view); + clutter_container_add (CLUTTER_CONTAINER (champlain_zoom_level_get_actor (level)), + champlain_tile_get_actor (tile), NULL); champlain_zoom_level_add_tile (level, tile); champlain_map_source_get_tile (priv->map_source, view, level, tile); @@ -1555,62 +1557,13 @@ view_tiles_reposition (ChamplainView* view) } } -void -champlain_view_tile_ready (ChamplainView *view, - ChamplainZoomLevel *level, - ChamplainTile *tile) -{ - ClutterActor *actor; - - actor = champlain_tile_get_actor (tile); - - clutter_container_add (CLUTTER_CONTAINER (champlain_zoom_level_get_actor (level)), actor, NULL); - clutter_actor_show (actor); - view_position_tile (view, tile); -} - -void -champlain_view_tile_uptodate (ChamplainView *view, - ChamplainZoomLevel *level, - ChamplainTile *tile) -{ -} - -void -champlain_view_tile_updated (ChamplainView *view, - ChamplainZoomLevel *level, - ChamplainTile *tile, - ClutterActor *previous_actor) -{ - ClutterActor *actor; - ClutterEffectTemplate *etemplate; - - actor = champlain_tile_get_actor (tile); - if (previous_actor != NULL) - { - /* TODO: Don't remove until the fade in the of new time is over */ - clutter_container_remove_actor (CLUTTER_CONTAINER (champlain_zoom_level_get_actor (level)), - previous_actor); - g_object_unref (previous_actor); - } - - /* FIXME: etemplate are leaked here */ - etemplate = clutter_effect_template_new_for_duration (750, CLUTTER_ALPHA_SINE_INC); - clutter_actor_set_opacity(actor, 0); - clutter_effect_fade (etemplate, actor, 255, NULL, NULL); - - clutter_container_add (CLUTTER_CONTAINER (champlain_zoom_level_get_actor (level)), actor, NULL); - clutter_actor_show (actor); - - view_position_tile (view, tile); -} - static void tile_state_notify (GObject *gobject, GParamSpec *pspec, gpointer data) { - view_update_state (CHAMPLAIN_VIEW(data)); + view_position_tile (CHAMPLAIN_VIEW (data), CHAMPLAIN_TILE (gobject)); + view_update_state (CHAMPLAIN_VIEW (data)); } static void