/*
-* Copyright (C) 2008 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
+* Copyright (C) 2009 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/* 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);
/*
- * Copyright (C) 2008 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
+ * Copyright (C) 2008-2009 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
/*
- * Copyright (C) 2008, 2009 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
+ * Copyright (C) 2008-2009 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
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);
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 ();
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);
}
}
- 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:
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);
champlain_tile_set_state (tile, CHAMPLAIN_STATE_DONE);
DEBUG ("Tile loaded from cache");
- champlain_view_tile_ready (view, zoom_level, tile);
}
/*
- * Copyright (C) 2008 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
+ * Copyright (C) 2008-2009 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
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
/*
-* Copyright (C) 2008 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
+ * Copyright (C) 2008-2009 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
#include <gdk/gdk.h>
#include <libsoup/soup.h>
#include <gio/gio.h>
+#include <clutter/clutter.h>
G_DEFINE_TYPE (ChamplainTile, champlain_tile, G_TYPE_OBJECT)
PROP_FILENAME,
PROP_STATE,
PROP_ACTOR,
+ PROP_CONTENT,
PROP_ETAG
};
ChamplainState state;
gchar *filename;
ClutterActor *actor;
+ ClutterActor *content_actor;
GTimeVal *modified_time;
gchar* etag;
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;
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;
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);
}
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",
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*
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;
+}
+
/*
- * Copyright (C) 2008 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
+ * Copyright (C) 2008-2009 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
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);
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);
/*
- * Copyright (C) 2008, 2009 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
+ * Copyright (C) 2008-2009 Pierre-Luc Beaudoin <pierre-luc@pierlux.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
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);
}
}
-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