[libchamplain] Share the error tile drawing between all map sources



commit 29eb308ffd2c40a4811de70f2699fe0dd98e0119
Author: Simon Wenner <simon wenner ch>
Date:   Sat Jul 25 23:05:27 2009 +0200

    Share the error tile drawing between all map sources
    
    Moved to champlain-map-source.c

 champlain/champlain-map-source.c         |   54 ++++++++++++++++++++++++++++++
 champlain/champlain-memphis-map-source.c |   41 ----------------------
 champlain/champlain-network-map-source.c |   52 ----------------------------
 champlain/champlain-private.h            |    3 ++
 4 files changed, 57 insertions(+), 93 deletions(-)
---
diff --git a/champlain/champlain-map-source.c b/champlain/champlain-map-source.c
index d4de9e5..d14ea27 100644
--- a/champlain/champlain-map-source.c
+++ b/champlain/champlain-map-source.c
@@ -47,6 +47,7 @@
 #include <glib-object.h>
 #include <math.h>
 #include <string.h>
+#include <clutter-cairo.h>
 
 void champlain_map_source_real_fill_tile (ChamplainMapSource *map_source,
     ChamplainTile *tile);
@@ -778,3 +779,56 @@ champlain_map_source_get_meters_per_pixel (ChamplainMapSource *map_source,
   return 2 * M_PI * EARTH_RADIUS * sin (M_PI/2 - M_PI / 180 * latitude) /
     (priv->tile_size * champlain_map_source_get_row_count (map_source, zoom_level));
 }
+
+/* protected function */
+static ClutterActor *error_actor = NULL;
+
+void
+create_error_tile (ChamplainTile* tile)
+{
+  ClutterActor *clone;
+
+  if (!error_actor)
+    {
+      guint size;
+      ClutterActor *actor;
+      cairo_t *cr;
+      cairo_pattern_t *pat;
+      ClutterActor *stage;
+
+      size = champlain_tile_get_size (tile);
+      actor = clutter_cairo_texture_new (size, size);
+      cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (actor));
+      stage = clutter_stage_get_default ();
+
+      /* 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);
+
+      clutter_actor_show (actor);
+      clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor);
+      error_actor = actor;
+    }
+
+  clone = clutter_clone_new (error_actor);
+  champlain_tile_set_content (tile, clone, TRUE);
+  champlain_tile_set_state (tile, CHAMPLAIN_STATE_DONE);
+}
diff --git a/champlain/champlain-memphis-map-source.c b/champlain/champlain-memphis-map-source.c
index c12ed5d..4b2df63 100644
--- a/champlain/champlain-memphis-map-source.c
+++ b/champlain/champlain-memphis-map-source.c
@@ -183,47 +183,6 @@ map_data_changed_cb (ChamplainMapDataSource *map_data_source,
   champlain_memphis_map_source_delete_session_cache (map_source);
 }
 
-// TODO: share this function with ChamplainNetworkMapSource
-static void
-create_error_tile (ChamplainTile* tile)
-{
-  ClutterActor *actor;
-  cairo_t *cr;
-  cairo_pattern_t *pat;
-  guint size;
-
-  size = champlain_tile_get_size (tile);
-  actor = clutter_cairo_new (size, size);
-  cr = clutter_cairo_create (CLUTTER_CAIRO(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);
-
-  champlain_tile_set_content (tile, actor, TRUE);
-  clutter_actor_show (actor);
-
-  champlain_tile_set_state (tile, CHAMPLAIN_STATE_DONE);
-}
-
 static void
 fill_tile (ChamplainMapSource *map_source, ChamplainTile *tile)
 {
diff --git a/champlain/champlain-network-map-source.c b/champlain/champlain-network-map-source.c
index a2c1cfc..6055f16 100644
--- a/champlain/champlain-network-map-source.c
+++ b/champlain/champlain-network-map-source.c
@@ -385,58 +385,6 @@ get_filename (ChamplainNetworkMapSource *source,
              champlain_tile_get_x (tile), champlain_tile_get_y (tile));
 }
 
-static ClutterActor *error_actor = NULL;
-
-static void
-create_error_tile (ChamplainTile* tile)
-{
-  ClutterActor *clone;
-
-  if (!error_actor)
-    {
-      guint size;
-      ClutterActor *actor;
-      cairo_t *cr;
-      cairo_pattern_t *pat;
-      ClutterActor *stage;
-
-      size = champlain_tile_get_size (tile);
-      actor = clutter_cairo_texture_new (size, size);
-      cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (actor));
-      stage = clutter_stage_get_default ();
-
-      /* 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);
-
-      clutter_actor_show (actor);
-      clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor);
-      error_actor = actor;
-    }
-
-  clone = clutter_clone_new (error_actor);
-  champlain_tile_set_content (tile, clone, TRUE);
-  champlain_tile_set_state (tile, CHAMPLAIN_STATE_DONE);
-}
-
 static void
 file_loaded_cb (SoupSession *session,
     SoupMessage *msg,
diff --git a/champlain/champlain-private.h b/champlain/champlain-private.h
index 7455fe7..e42993e 100644
--- a/champlain/champlain-private.h
+++ b/champlain/champlain-private.h
@@ -21,6 +21,7 @@
 
 #include <glib.h>
 #include <clutter/clutter.h>
+#include "champlain-tile.h"
 
 typedef struct _Map Map;
 
@@ -59,4 +60,6 @@ typedef struct
   gint height;
 } ChamplainRectangle;
 
+void create_error_tile (ChamplainTile* tile);
+
 #endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]