]> err.no Git - libchamplain/commitdiff
Draw the lines using Cairo
authorPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Mon, 25 May 2009 02:10:15 +0000 (22:10 -0400)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Wed, 10 Jun 2009 00:27:35 +0000 (20:27 -0400)
The lines are drawn on a cairo surface, which is updated
each time the view changes (zoom, center, scroll).

champlain/champlain-line.c
champlain/champlain-private.h
champlain/champlain-view.c
demos/lines.c

index 2eeb5cb15381f80480459cca1e7b8c337b87de41..e432dc3e529b0e33c58c95aed9a753ae8c06185f 100644 (file)
@@ -32,6 +32,7 @@
 #include "champlain-line.h"
 
 #include "champlain-defines.h"
+#include "champlain-private.h"
 
 #include <clutter/clutter.h>
 #include <glib.h>
@@ -46,10 +47,6 @@ enum
   PROP_0
 };
 
-struct _ChamplainLinePrivate {
-  GList *points;
-};
-
 static void
 champlain_line_get_property (GObject *object,
     guint property_id,
index d27e70515cc6eafc85f14a4b5e948a913c1f1e5a..e837afaf38f1144132444a91b4ad5479e7b19fc9 100644 (file)
@@ -37,6 +37,10 @@ struct _ChamplainBaseMarkerPrivate
   gdouble lat;
 };
 
+struct _ChamplainLinePrivate {
+  GList *points;
+};
+
 typedef struct
 {
   gint x;
index 1406a1df294b4abd428f7a3e46975d9f9d5662b5..5c95b69e412f37eb94ca182fe4114d19147321f8 100644 (file)
@@ -855,7 +855,7 @@ champlain_view_init (ChamplainView *view)
       priv->user_layers);
   clutter_actor_raise (priv->user_layers, priv->map_layer);
 
-  /* Setup user_layers */
+  /* Setup line layer */
   priv->line_layer = g_object_ref (clutter_cairo_new (800, 600));
   clutter_actor_show (priv->line_layer);
   clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport),
@@ -1094,6 +1094,7 @@ champlain_view_center_on (ChamplainView *view,
 
   view_load_visible_tiles (view);
   view_tiles_reposition (view);
+  view_update_lines (view);
   marker_reposition (view);
 }
 
@@ -2185,16 +2186,45 @@ champlain_view_add_line (ChamplainView *view,
 static void
 view_update_lines (ChamplainView *view)
 {
+  ChamplainViewPrivate *priv = view->priv;
+
+  if (priv->line == NULL)
+    return;
+
   cairo_t *cr;
-  cr = clutter_cairo_create (CLUTTER_CAIRO (view->priv->line_layer));
+  cr = clutter_cairo_create (CLUTTER_CAIRO (priv->line_layer));
+
+  /* Clear the drawing area */
+  cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
+  cairo_rectangle (cr, 0, 0, 800, 600);
+  cairo_fill (cr);
+
+  /* Draw the line */
+  cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+  GList *list = g_list_first (priv->line->priv->points);
+  while (list != NULL)
+    {
+      ChamplainPoint *point = (ChamplainPoint*) list->data;
+      gint x, y;
+
+      x = champlain_map_source_get_x (priv->map_source, priv->zoom_level,
+          point->lon);
+      y = champlain_map_source_get_y (priv->map_source, priv->zoom_level,
+          point->lat);
+
+      x -= priv->viewport_size.x + priv->anchor.x;
+      y -= priv->viewport_size.y + priv->anchor.y;
+
+      cairo_line_to (cr, x, y);
+      list = list->next;
+    }
+  gint x, y;
 
-  cairo_move_to (cr, 0, 0);
-  cairo_line_to (cr, 100, 0);
-  cairo_line_to (cr, 100, 200);
-  cairo_line_to (cr, 100, 100);
-  cairo_line_to (cr, 0, 100);
+  x = priv->viewport_size.x;
+  y = priv->viewport_size.y;
 
   cairo_stroke (cr);
   cairo_destroy (cr);
 
+  clutter_actor_set_position (priv->line_layer, x, y);
 }
index f47b66b4ff52239c3b40af768d995d73c7986f93..2bbfd987873a27dde9bc0a3ccc4791454d385363 100644 (file)
@@ -109,8 +109,8 @@ main (int argc,
 
   /* draw a line */
   line = champlain_line_new ();
-  champlain_line_add_point (line, -40, -70);
-  champlain_line_add_point (line, -45, -75);
+  champlain_line_add_point (line, 44, -74);
+  champlain_line_add_point (line, 45, -75);
   champlain_view_add_line (CHAMPLAIN_VIEW (actor), line);