[libchamplain] Add null tile source and error tile renderer
- From: Jiří Techet <jiritechet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libchamplain] Add null tile source and error tile renderer
- Date: Sun, 1 Aug 2010 23:16:24 +0000 (UTC)
commit 537d540c1d85e03d933aa06871b8c128b128ecbc
Author: JiÅ?Ã Techet <techet gmail com>
Date: Sat Jul 31 20:46:33 2010 +0200
Add null tile source and error tile renderer
Replace the error tile source with a null tile source
(a tile source with no data input) and error tile renderer
(always renders error tile, no mater what is on the input)
Signed-off-by: JiÅ?Ã Techet <techet gmail com>
champlain/Makefile.am | 9 +-
champlain/champlain-error-tile-renderer.c | 248 ++++++++++++++++++++++++
champlain/champlain-error-tile-renderer.h | 68 +++++++
champlain/champlain-error-tile-source.c | 166 ----------------
champlain/champlain-error-tile-source.h | 61 ------
champlain/champlain-file-tile-source.c | 2 +-
champlain/champlain-map-source-factory.c | 23 ++-
champlain/champlain-map-source-factory.h | 2 +
champlain/champlain-network-bbox-tile-source.c | 2 +-
champlain/champlain-network-tile-source.c | 2 +-
champlain/champlain-null-tile-source.c | 129 ++++++++++++
champlain/champlain-null-tile-source.h | 68 +++++++
champlain/champlain.h | 3 +-
demos/local-rendering.c | 2 +-
14 files changed, 547 insertions(+), 238 deletions(-)
---
diff --git a/champlain/Makefile.am b/champlain/Makefile.am
index c54b601..f4142a1 100644
--- a/champlain/Makefile.am
+++ b/champlain/Makefile.am
@@ -35,7 +35,6 @@ libchamplain_headers = \
champlain-tile-source.h \
champlain-tile-cache.h \
champlain-network-tile-source.h \
- champlain-error-tile-source.h \
champlain-file-cache.h \
champlain-map-source-factory.h \
champlain-map-source-desc.h \
@@ -44,7 +43,9 @@ libchamplain_headers = \
champlain-features.h \
champlain-renderer.h \
champlain-image-renderer.h \
+ champlain-error-tile-renderer.h \
champlain-file-tile-source.h \
+ champlain-null-tile-source.h \
champlain-network-bbox-tile-source.h \
champlain-bounding-box.h
@@ -70,7 +71,6 @@ libchamplain_ CHAMPLAIN_API_VERSION@_la_SOURCES = \
champlain-tile-source.c \
champlain-tile-cache.c \
champlain-network-tile-source.c \
- champlain-error-tile-source.c \
champlain-file-cache.c \
champlain-map-source-factory.c \
champlain-map-source-desc.c \
@@ -78,7 +78,9 @@ libchamplain_ CHAMPLAIN_API_VERSION@_la_SOURCES = \
champlain-polygon.c \
champlain-renderer.c \
champlain-image-renderer.c \
+ champlain-error-tile-renderer.c \
champlain-file-tile-source.c \
+ champlain-null-tile-source.c \
champlain-network-bbox-tile-source.c \
champlain-bounding-box.c
@@ -100,7 +102,6 @@ libchamplain_include_HEADERS = \
champlain-tile-source.h \
champlain-tile-cache.h \
champlain-network-tile-source.h \
- champlain-error-tile-source.h \
champlain-file-cache.h \
champlain-map-source-factory.h \
champlain-map-source-desc.h \
@@ -112,7 +113,9 @@ libchamplain_include_HEADERS = \
champlain-features.h \
champlain-renderer.h \
champlain-image-renderer.h \
+ champlain-error-tile-renderer.h \
champlain-file-tile-source.h \
+ champlain-null-tile-source.h \
champlain-network-bbox-tile-source.h \
champlain-bounding-box.h
diff --git a/champlain/champlain-error-tile-renderer.c b/champlain/champlain-error-tile-renderer.c
new file mode 100644
index 0000000..5e5639e
--- /dev/null
+++ b/champlain/champlain-error-tile-renderer.c
@@ -0,0 +1,248 @@
+/*
+ * Copyright (C) 2010 Jiri Techet <techet gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "champlain-error-tile-renderer.h"
+#include <gdk/gdk.h>
+
+G_DEFINE_TYPE (ChamplainErrorTileRenderer, champlain_error_tile_renderer, CHAMPLAIN_TYPE_RENDERER)
+
+#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CHAMPLAIN_TYPE_ERROR_TILE_RENDERER, ChamplainErrorTileRendererPrivate))
+
+struct _ChamplainErrorTileRendererPrivate
+{
+ CoglHandle error_tex;
+ guint tile_size;
+};
+
+enum
+{
+ PROP_0,
+ PROP_TILE_SIZE
+};
+
+
+static void set_data (ChamplainRenderer *renderer,
+ const gchar *data,
+ guint size);
+static void render (ChamplainRenderer *renderer,
+ ChamplainTile *tile);
+
+
+static void
+champlain_error_tile_renderer_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ ChamplainErrorTileRenderer *renderer = CHAMPLAIN_ERROR_TILE_RENDERER (object);
+
+ switch (property_id)
+ {
+ case PROP_TILE_SIZE:
+ g_value_set_uint (value, champlain_error_tile_renderer_get_tile_size (renderer));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+
+static void
+champlain_error_tile_renderer_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ ChamplainErrorTileRenderer *renderer = CHAMPLAIN_ERROR_TILE_RENDERER (object);
+
+ switch (property_id)
+ {
+ case PROP_TILE_SIZE:
+ champlain_error_tile_renderer_set_tile_size (renderer, g_value_get_uint (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+
+static void
+champlain_error_tile_renderer_dispose (GObject *object)
+{
+ ChamplainErrorTileRendererPrivate *priv = CHAMPLAIN_ERROR_TILE_RENDERER (object)->priv;
+
+ if (priv->error_tex)
+ {
+ cogl_handle_unref (priv->error_tex);
+ priv->error_tex = NULL;
+ }
+
+ G_OBJECT_CLASS (champlain_error_tile_renderer_parent_class)->dispose (object);
+}
+
+
+static void
+champlain_error_tile_renderer_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (champlain_error_tile_renderer_parent_class)->finalize (object);
+}
+
+
+static void
+champlain_error_tile_renderer_class_init (ChamplainErrorTileRendererClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ ChamplainRendererClass *renderer_class = CHAMPLAIN_RENDERER_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (ChamplainErrorTileRendererPrivate));
+
+ object_class->get_property = champlain_error_tile_renderer_get_property;
+ object_class->set_property = champlain_error_tile_renderer_set_property;
+ object_class->finalize = champlain_error_tile_renderer_finalize;
+ object_class->dispose = champlain_error_tile_renderer_dispose;
+
+ g_object_class_install_property (object_class,
+ PROP_TILE_SIZE,
+ g_param_spec_uint ("tile-size",
+ "Tile Size",
+ "The size of the rendered tile",
+ 0,
+ G_MAXINT,
+ 256,
+ G_PARAM_READWRITE));
+
+ renderer_class->set_data = set_data;
+ renderer_class->render = render;
+}
+
+
+static void
+champlain_error_tile_renderer_init (ChamplainErrorTileRenderer *self)
+{
+ ChamplainErrorTileRendererPrivate *priv = GET_PRIVATE (self);
+
+ self->priv = priv;
+
+ priv->error_tex = NULL;
+}
+
+
+ChamplainErrorTileRenderer *
+champlain_error_tile_renderer_new (guint tile_size)
+{
+ return g_object_new (CHAMPLAIN_TYPE_ERROR_TILE_RENDERER, "tile-size", tile_size, NULL);
+}
+
+
+static void
+set_data (ChamplainRenderer *renderer, const gchar *data, guint size)
+{
+}
+
+
+static void
+render (ChamplainRenderer *renderer, ChamplainTile *tile)
+{
+ g_return_if_fail (CHAMPLAIN_IS_ERROR_TILE_RENDERER (renderer));
+ g_return_if_fail (CHAMPLAIN_IS_TILE (tile));
+
+ ChamplainErrorTileRenderer *error_renderer = CHAMPLAIN_ERROR_TILE_RENDERER (renderer);
+ ChamplainErrorTileRendererPrivate *priv = error_renderer->priv;
+ ClutterActor *clone;
+ guint size;
+ ChamplainRenderCallbackData callback_data;
+
+ callback_data.data = NULL;
+ callback_data.size = 0;
+ callback_data.error = FALSE;
+
+ if (champlain_tile_get_state (tile) == CHAMPLAIN_STATE_LOADED)
+ {
+ /* cache is just validating tile - don't generate error tile in this case - instead use what we have */
+ g_signal_emit_by_name (tile, "render-complete", &callback_data);
+ return;
+ }
+
+ size = champlain_error_tile_renderer_get_tile_size (error_renderer);
+
+ if (!priv->error_tex)
+ {
+ cairo_t *cr;
+ cairo_pattern_t *pat;
+ ClutterActor *tmp_actor;
+
+ tmp_actor = clutter_cairo_texture_new (size, size);
+ cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (tmp_actor));
+
+ /* draw a linear gray to white pattern */
+ pat = cairo_pattern_create_linear (size / 2.0, 0.0, size, size / 2.0);
+ cairo_pattern_add_color_stop_rgb (pat, 0, 0.686, 0.686, 0.686);
+ cairo_pattern_add_color_stop_rgb (pat, 1, 0.925, 0.925, 0.925);
+ cairo_set_source (cr, pat);
+ cairo_rectangle (cr, 0, 0, size, size);
+ cairo_fill (cr);
+
+ cairo_pattern_destroy (pat);
+
+ /* draw the red cross */
+ cairo_set_source_rgb (cr, 0.424, 0.078, 0.078);
+ cairo_set_line_width (cr, 14.0);
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
+ cairo_move_to (cr, 24, 24);
+ cairo_line_to (cr, 50, 50);
+ cairo_move_to (cr, 50, 24);
+ cairo_line_to (cr, 24, 50);
+ cairo_stroke (cr);
+
+ cairo_destroy (cr);
+
+ priv->error_tex = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (tmp_actor));
+ cogl_handle_ref (priv->error_tex);
+
+ g_object_ref_sink (tmp_actor);
+ g_object_unref (tmp_actor);
+ }
+
+ clone = clutter_texture_new ();
+ clutter_texture_set_cogl_texture (CLUTTER_TEXTURE (clone), priv->error_tex);
+ champlain_tile_set_content (tile, clone);
+ g_signal_emit_by_name (tile, "render-complete", &callback_data);
+}
+
+
+void
+champlain_error_tile_renderer_set_tile_size (ChamplainErrorTileRenderer *renderer,
+ guint size)
+{
+ g_return_if_fail (CHAMPLAIN_IS_ERROR_TILE_RENDERER (renderer));
+
+ renderer->priv->tile_size = size;
+
+ g_object_notify (G_OBJECT (renderer), "tile-size");
+}
+
+
+guint
+champlain_error_tile_renderer_get_tile_size (ChamplainErrorTileRenderer *renderer)
+{
+ g_return_val_if_fail (CHAMPLAIN_IS_ERROR_TILE_RENDERER (renderer), 0);
+
+ return renderer->priv->tile_size;
+}
diff --git a/champlain/champlain-error-tile-renderer.h b/champlain/champlain-error-tile-renderer.h
new file mode 100644
index 0000000..92e6c5c
--- /dev/null
+++ b/champlain/champlain-error-tile-renderer.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2010 Jiri Techet <techet gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#if !defined (__CHAMPLAIN_CHAMPLAIN_H_INSIDE__) && !defined (CHAMPLAIN_COMPILATION)
+#error "Only <champlain/champlain.h> can be included directly."
+#endif
+
+#ifndef __CHAMPLAIN_ERROR_TILE_RENDERER_H__
+#define __CHAMPLAIN_ERROR_TILE_RENDERER_H__
+
+#include <champlain/champlain-tile.h>
+#include <champlain/champlain-renderer.h>
+
+G_BEGIN_DECLS
+
+#define CHAMPLAIN_TYPE_ERROR_TILE_RENDERER (champlain_error_tile_renderer_get_type ())
+#define CHAMPLAIN_ERROR_TILE_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CHAMPLAIN_TYPE_ERROR_TILE_RENDERER, ChamplainErrorTileRenderer))
+#define CHAMPLAIN_ERROR_TILE_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CHAMPLAIN_TYPE_ERROR_TILE_RENDERER, ChamplainErrorTileRendererClass))
+#define CHAMPLAIN_IS_ERROR_TILE_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CHAMPLAIN_TYPE_ERROR_TILE_RENDERER))
+#define CHAMPLAIN_IS_ERROR_TILE_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CHAMPLAIN_TYPE_ERROR_TILE_RENDERER))
+#define CHAMPLAIN_ERROR_TILE_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CHAMPLAIN_TYPE_ERROR_TILE_RENDERER, ChamplainErrorTileRendererClass))
+
+typedef struct _ChamplainErrorTileRendererPrivate ChamplainErrorTileRendererPrivate;
+
+typedef struct _ChamplainErrorTileRenderer ChamplainErrorTileRenderer;
+typedef struct _ChamplainErrorTileRendererClass ChamplainErrorTileRendererClass;
+
+struct _ChamplainErrorTileRenderer
+{
+ ChamplainRenderer parent;
+
+ ChamplainErrorTileRendererPrivate *priv;
+};
+
+struct _ChamplainErrorTileRendererClass
+{
+ ChamplainRendererClass parent_class;
+};
+
+
+GType champlain_error_tile_renderer_get_type (void);
+
+ChamplainErrorTileRenderer *champlain_error_tile_renderer_new (guint tile_size);
+
+void champlain_error_tile_renderer_set_tile_size (ChamplainErrorTileRenderer *renderer,
+ guint size);
+
+guint champlain_error_tile_renderer_get_tile_size (ChamplainErrorTileRenderer *renderer);
+
+
+G_END_DECLS
+
+#endif /* __CHAMPLAIN_ERROR_TILE_RENDERER_H__ */
diff --git a/champlain/champlain-file-tile-source.c b/champlain/champlain-file-tile-source.c
index a678f36..191ddc4 100644
--- a/champlain/champlain-file-tile-source.c
+++ b/champlain/champlain-file-tile-source.c
@@ -138,7 +138,7 @@ tile_rendered_cb (ChamplainTile *tile,
if (!data->error)
{
- if (tile_cache)
+ if (tile_cache && data->data)
champlain_tile_cache_store_tile (tile_cache, tile, data->data, data->size);
champlain_tile_set_fade_in (tile, TRUE);
diff --git a/champlain/champlain-map-source-factory.c b/champlain/champlain-map-source-factory.c
index 6c7630f..518b964 100644
--- a/champlain/champlain-map-source-factory.c
+++ b/champlain/champlain-map-source-factory.c
@@ -50,7 +50,7 @@
#include "champlain-private.h"
#include "champlain-network-tile-source.h"
#include "champlain-map-source-chain.h"
-#include "champlain-error-tile-source.h"
+#include "champlain-error-tile-renderer.h"
#include "champlain-image-renderer.h"
#include "champlain-file-tile-source.h"
@@ -400,7 +400,8 @@ champlain_map_source_factory_create (ChamplainMapSourceFactory *factory,
*
* Since: 0.6
*/
-ChamplainMapSource * champlain_map_source_factory_create_cached_source (ChamplainMapSourceFactory *factory,
+ChamplainMapSource *
+champlain_map_source_factory_create_cached_source (ChamplainMapSourceFactory *factory,
const gchar *id)
{
ChamplainMapSourceChain *source_chain;
@@ -412,7 +413,7 @@ ChamplainMapSource * champlain_map_source_factory_create_cached_source (Champlai
tile_source = champlain_map_source_factory_create (factory, id);
tile_size = champlain_map_source_get_tile_size (tile_source);
- error_source = CHAMPLAIN_MAP_SOURCE(champlain_error_tile_source_new_full (tile_size));
+ error_source = champlain_map_source_factory_create_error_source (factory, tile_size);
file_cache = CHAMPLAIN_MAP_SOURCE(champlain_file_cache_new ());
@@ -424,6 +425,22 @@ ChamplainMapSource * champlain_map_source_factory_create_cached_source (Champlai
return CHAMPLAIN_MAP_SOURCE(source_chain);
}
+
+ChamplainMapSource *
+champlain_map_source_factory_create_error_source (ChamplainMapSourceFactory *factory,
+ guint tile_size)
+{
+ ChamplainMapSource *null_source;
+ ChamplainRenderer *renderer;
+
+ null_source = CHAMPLAIN_MAP_SOURCE (champlain_null_tile_source_new ());
+ renderer = CHAMPLAIN_RENDERER (champlain_error_tile_renderer_new (tile_size));
+ champlain_map_source_set_renderer (null_source, renderer);
+
+ return null_source;
+}
+
+
/**
* champlain_map_source_factory_register:
* @factory: A #ChamplainMapSourceFactory
diff --git a/champlain/champlain-map-source-factory.h b/champlain/champlain-map-source-factory.h
index b5fcfc1..f932638 100644
--- a/champlain/champlain-map-source-factory.h
+++ b/champlain/champlain-map-source-factory.h
@@ -64,6 +64,8 @@ ChamplainMapSource * champlain_map_source_factory_create (ChamplainMapSourceFact
const gchar *id);
ChamplainMapSource * champlain_map_source_factory_create_cached_source (ChamplainMapSourceFactory *factory,
const gchar *id);
+ChamplainMapSource * champlain_map_source_factory_create_error_source (ChamplainMapSourceFactory *factory,
+ guint tile_size);
gboolean
champlain_map_source_factory_register (ChamplainMapSourceFactory *factory,
diff --git a/champlain/champlain-network-bbox-tile-source.c b/champlain/champlain-network-bbox-tile-source.c
index 7476f5c..977d5ec 100644
--- a/champlain/champlain-network-bbox-tile-source.c
+++ b/champlain/champlain-network-bbox-tile-source.c
@@ -342,7 +342,7 @@ tile_rendered_cb (ChamplainTile *tile,
if (!data->error)
{
- if (tile_cache)
+ if (tile_cache && data->data)
champlain_tile_cache_store_tile (tile_cache, tile, data->data, data->size);
champlain_tile_set_fade_in (tile, TRUE);
diff --git a/champlain/champlain-network-tile-source.c b/champlain/champlain-network-tile-source.c
index 229fa35..f877367 100644
--- a/champlain/champlain-network-tile-source.c
+++ b/champlain/champlain-network-tile-source.c
@@ -533,7 +533,7 @@ tile_rendered_cb (ChamplainTile *tile, ChamplainRenderCallbackData *data, TileRe
if (etag != NULL)
champlain_tile_set_etag (tile, etag);
- if (tile_cache)
+ if (tile_cache && data->data)
champlain_tile_cache_store_tile (tile_cache, tile, data->data, data->size);
champlain_tile_set_fade_in (tile, TRUE);
diff --git a/champlain/champlain-null-tile-source.c b/champlain/champlain-null-tile-source.c
new file mode 100644
index 0000000..ced41bc
--- /dev/null
+++ b/champlain/champlain-null-tile-source.c
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2010 Jiri Techet <techet gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "champlain-null-tile-source.h"
+
+#include "champlain-debug.h"
+#include "champlain-bounding-box.h"
+#include "champlain-enum-types.h"
+#include "champlain-tile.h"
+
+G_DEFINE_TYPE (ChamplainNullTileSource, champlain_null_tile_source, CHAMPLAIN_TYPE_TILE_SOURCE)
+
+static void fill_tile (ChamplainMapSource *map_source,
+ ChamplainTile *tile);
+
+
+static void
+champlain_null_tile_source_dispose (GObject *object)
+{
+ G_OBJECT_CLASS (champlain_null_tile_source_parent_class)->dispose (object);
+}
+
+
+static void
+champlain_null_tile_source_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (champlain_null_tile_source_parent_class)->finalize (object);
+}
+
+
+static void
+champlain_null_tile_source_class_init (ChamplainNullTileSourceClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ ChamplainMapSourceClass *map_source_class = CHAMPLAIN_MAP_SOURCE_CLASS (klass);
+
+ object_class->dispose = champlain_null_tile_source_dispose;
+ object_class->finalize = champlain_null_tile_source_finalize;
+
+ map_source_class->fill_tile = fill_tile;
+}
+
+
+static void
+champlain_null_tile_source_init (ChamplainNullTileSource *self)
+{
+ g_return_if_fail (CHAMPLAIN_IS_NULL_TILE_SOURCE (self));
+}
+
+
+/*
+ * champlain_null_tile_source_new:
+ *
+ * Creates a new instance of #ChamplainNullTileSource.
+ *
+ * Returns: a new #ChamplainNullTileSource.
+ *
+ * Since: 0.8
+ */
+ChamplainNullTileSource *
+champlain_null_tile_source_new (void)
+{
+ ChamplainNullTileSource *source;
+
+ source = g_object_new (CHAMPLAIN_TYPE_NULL_TILE_SOURCE, NULL);
+ return source;
+}
+
+
+static void
+tile_rendered_cb (ChamplainTile *tile,
+ ChamplainRenderCallbackData *data,
+ ChamplainMapSource *map_source)
+{
+ ChamplainTileSource *tile_source = CHAMPLAIN_TILE_SOURCE (map_source);
+ ChamplainTileCache *tile_cache = champlain_tile_source_get_cache (tile_source);
+ ChamplainMapSource *next_source = champlain_map_source_get_next_source (map_source);
+
+ if (!data->error)
+ {
+ if (tile_cache && data->data)
+ champlain_tile_cache_store_tile (tile_cache, tile, data->data, data->size);
+
+ champlain_tile_set_fade_in (tile, TRUE);
+ champlain_tile_set_state (tile, CHAMPLAIN_STATE_DONE);
+ champlain_tile_display_content (tile);
+ }
+ else if (next_source)
+ champlain_map_source_fill_tile (next_source, tile);
+
+ g_object_unref (map_source);
+ g_signal_handlers_disconnect_by_func (tile, tile_rendered_cb, data);
+}
+
+
+static void
+fill_tile (ChamplainMapSource *map_source,
+ ChamplainTile *tile)
+{
+ g_return_if_fail (CHAMPLAIN_IS_NULL_TILE_SOURCE (map_source));
+ g_return_if_fail (CHAMPLAIN_IS_TILE (tile));
+
+ ChamplainRenderer *renderer;
+
+ renderer = champlain_map_source_get_renderer (map_source);
+
+ g_return_if_fail (CHAMPLAIN_IS_RENDERER (renderer));
+
+ g_object_ref (map_source);
+
+ g_signal_connect (tile, "render-complete", G_CALLBACK (tile_rendered_cb), map_source);
+
+ champlain_renderer_render (renderer, tile);
+}
diff --git a/champlain/champlain-null-tile-source.h b/champlain/champlain-null-tile-source.h
new file mode 100644
index 0000000..8127464
--- /dev/null
+++ b/champlain/champlain-null-tile-source.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2010 Jiri Techet <techet gmail com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#if !defined (__CHAMPLAIN_CHAMPLAIN_H_INSIDE__) && !defined (CHAMPLAIN_COMPILATION)
+#error "Only <champlain/champlain.h> can be included directly."
+#endif
+
+#ifndef _CHAMPLAIN_NULL_TILE_SOURCE
+#define _CHAMPLAIN_NULL_TILE_SOURCE
+
+#include <glib-object.h>
+
+#include <champlain/champlain-tile-source.h>
+
+G_BEGIN_DECLS
+
+#define CHAMPLAIN_TYPE_NULL_TILE_SOURCE champlain_null_tile_source_get_type ()
+
+#define CHAMPLAIN_NULL_TILE_SOURCE(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), CHAMPLAIN_TYPE_NULL_TILE_SOURCE, ChamplainNullTileSource))
+
+#define CHAMPLAIN_NULL_TILE_SOURCE_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), CHAMPLAIN_TYPE_NULL_TILE_SOURCE, ChamplainNullTileSourceClass))
+
+#define CHAMPLAIN_IS_NULL_TILE_SOURCE(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CHAMPLAIN_TYPE_NULL_TILE_SOURCE))
+
+#define CHAMPLAIN_IS_NULL_TILE_SOURCE_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), CHAMPLAIN_TYPE_NULL_TILE_SOURCE))
+
+#define CHAMPLAIN_NULL_TILE_SOURCE_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), CHAMPLAIN_TYPE_NULL_TILE_SOURCE, ChamplainNullTileSourceClass))
+
+typedef struct _ChamplainNullTileSourcePrivate ChamplainNullTileSourcePrivate;
+
+typedef struct
+{
+ ChamplainTileSource parent;
+} ChamplainNullTileSource;
+
+typedef struct
+{
+ ChamplainTileSourceClass parent_class;
+} ChamplainNullTileSourceClass;
+
+GType champlain_null_tile_source_get_type (void);
+
+ChamplainNullTileSource *champlain_null_tile_source_new (void);
+
+
+G_END_DECLS
+
+#endif /* _CHAMPLAIN_NULL_TILE_SOURCE */
diff --git a/champlain/champlain.h b/champlain/champlain.h
index 95393a7..a183286 100644
--- a/champlain/champlain.h
+++ b/champlain/champlain.h
@@ -39,7 +39,7 @@
#include "champlain/champlain-tile-cache.h"
#include "champlain/champlain-network-tile-source.h"
#include "champlain/champlain-file-cache.h"
-#include "champlain/champlain-error-tile-source.h"
+#include "champlain/champlain-null-tile-source.h"
#include "champlain/champlain-map-source-factory.h"
#include "champlain/champlain-version.h"
#include "champlain/champlain-bounding-box.h"
@@ -47,6 +47,7 @@
#include "champlain/champlain-network-bbox-tile-source.h"
#include "champlain/champlain-renderer.h"
#include "champlain/champlain-image-renderer.h"
+#include "champlain/champlain-error-tile-renderer.h"
#undef __CHAMPLAIN_CHAMPLAIN_H_INSIDE__
diff --git a/demos/local-rendering.c b/demos/local-rendering.c
index 7361af6..694e547 100644
--- a/demos/local-rendering.c
+++ b/demos/local-rendering.c
@@ -439,7 +439,7 @@ map_source_changed (GtkWidget *widget, ChamplainView *view)
source_chain = champlain_map_source_chain_new ();
tile_size = champlain_map_source_get_tile_size (tile_source);
- src = CHAMPLAIN_MAP_SOURCE(champlain_error_tile_source_new_full (tile_size));
+ src = champlain_map_source_factory_create_error_source (factory, tile_size);
champlain_map_source_chain_push (source_chain, src);
champlain_map_source_chain_push (source_chain, tile_source);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]