From: Pierre-Luc Beaudoin Date: Mon, 25 May 2009 02:10:15 +0000 (-0400) Subject: Draw the lines using Cairo X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0997ebec1ce628862c5390dc0df4baed994d3caf;p=libchamplain Draw the lines using Cairo The lines are drawn on a cairo surface, which is updated each time the view changes (zoom, center, scroll). --- diff --git a/champlain/champlain-line.c b/champlain/champlain-line.c index 2eeb5cb..e432dc3 100644 --- a/champlain/champlain-line.c +++ b/champlain/champlain-line.c @@ -32,6 +32,7 @@ #include "champlain-line.h" #include "champlain-defines.h" +#include "champlain-private.h" #include #include @@ -46,10 +47,6 @@ enum PROP_0 }; -struct _ChamplainLinePrivate { - GList *points; -}; - static void champlain_line_get_property (GObject *object, guint property_id, diff --git a/champlain/champlain-private.h b/champlain/champlain-private.h index d27e705..e837afa 100644 --- a/champlain/champlain-private.h +++ b/champlain/champlain-private.h @@ -37,6 +37,10 @@ struct _ChamplainBaseMarkerPrivate gdouble lat; }; +struct _ChamplainLinePrivate { + GList *points; +}; + typedef struct { gint x; diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c index 1406a1d..5c95b69 100644 --- a/champlain/champlain-view.c +++ b/champlain/champlain-view.c @@ -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); } diff --git a/demos/lines.c b/demos/lines.c index f47b66b..2bbfd98 100644 --- a/demos/lines.c +++ b/demos/lines.c @@ -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);