From e7782ad8993730e1fa585415877224cf8c6d35d0 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Tue, 5 Aug 2008 17:18:09 +0300 Subject: [PATCH] MapWidget: Fixes to path drawing. Add cairo version. --- libs/libgtkmap/gtkmap.c | 102 ++++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 45 deletions(-) diff --git a/libs/libgtkmap/gtkmap.c b/libs/libgtkmap/gtkmap.c index f135fce..e0190b3 100644 --- a/libs/libgtkmap/gtkmap.c +++ b/libs/libgtkmap/gtkmap.c @@ -850,7 +850,7 @@ widget->window=gdk_window_new(gtk_widget_get_parent_window(widget), &attributes, gdk_window_set_user_data(widget->window, widget); gtk_widget_set_app_paintable(widget, TRUE); -gtk_widget_set_double_buffered(widget, FALSE); +gtk_widget_set_double_buffered(widget, TRUE); gtk_widget_set_extension_events(widget, GDK_EXTENSION_EVENTS_ALL); #if 0 @@ -1072,55 +1072,16 @@ gtk_map_render_waypoint(GtkWidget *widget, guint x, guint y) { GtkMap *map; GtkMapPriv *priv; -GdkGC *gc; g_return_if_fail(GTK_IS_MAP(widget)); map=GTK_MAP(widget); priv=GTK_MAP_GET_PRIVATE(map); -gc=priv->gc_waypoint; - if ((x > priv->buf_width_pixels) || (y > priv->buf_height_pixels)) return; -gdk_draw_arc(widget->window, gc, FALSE, x - priv->draw_width, y - priv->draw_width, 2 * priv->draw_width, 2 * priv->draw_width, 0, 360 * 64); -} - -/** - * gtk_map_render_path_segment: - * @widget - * @unitx1 - * @unity1 - * @unitx2 - * @unity2 - * - * Draw a path segment from unitx/y1 to unitx/y2 - */ -static void -gtk_map_render_path_segment(GtkWidget *widget, guint unitx1, guint unity1, guint unitx2, guint unity2) -{ -GtkMap *map; -GtkMapPriv *priv; -GdkGC *gc; -gint x1, y1, x2, y2; - -g_return_if_fail(GTK_IS_MAP(widget)); - -map=GTK_MAP(widget); -priv=GTK_MAP_GET_PRIVATE(map); - -x1=unit2bufx(unitx1); -y1=unit2bufy(unity1); -x2=unit2bufx(unitx2); -y2=unit2bufy(unity2); - -/* Make sure this line could possibly be visible. */ -if (!((x1 > priv->buf_width_pixels && x2 > priv->buf_width_pixels) || (x1 < 0 && x2 < 0) - || (y1 > priv->buf_height_pixels && y2 > priv->buf_height_pixels) || (y1 < 0 && y2 < 0))) { - gc=priv->gc_track; - gdk_draw_line(widget->window, gc, x1, y1, x2, y2); -} +gdk_draw_arc(widget->window, priv->gc_waypoint, FALSE, x - priv->draw_width, y - priv->draw_width, 2 * priv->draw_width, 2 * priv->draw_width, 0, 360 * 64); } /** @@ -1135,21 +1096,66 @@ gtk_map_render_path(GtkWidget *widget, Path *path, GdkEventExpose *event) { GtkMap *map; GtkMapPriv *priv; -Point *curr; +Point *curr, *prev; WayPoint *wcurr; +gint x1, y1, x2, y2; g_return_if_fail(path); +g_return_if_fail(path->head); if (path->head==path->tail) return; map=GTK_MAP(widget); priv=GTK_MAP_GET_PRIVATE(map); +prev=path->head; +x1=unit2x(path->head->unitx); +y1=unit2y(path->head->unity); + +#ifdef WITH_CAIRO +cairo_save(priv->ct); +switch (path->type) { + case PATH_TYPE_ROUTE: + cairo_set_source_rgb(priv->ct, 0.9, 0.2, 0.2); + break; + case PATH_TYPE_TRACK: + cairo_set_source_rgb(priv->ct, 0.2, 0.9, 0.2); + break; + default: + cairo_set_source_rgb(priv->ct, 0.2, 0.2, 0.9); + break; +} +cairo_set_line_width(priv->ct, priv->draw_width); +#if 0 +cairo_rectangle(priv->ct, event->area.x, event->area.y, event->area.width, event->area.height); +cairo_clip(priv->ct); +#endif +cairo_move_to(priv->ct, x1, y1); +if (priv->rotate_view) { + gtk_map_update_rotation_matrix(priv,unit2x(priv->center.unitx),unit2y(priv->center.unity) ); + cairo_set_matrix(priv->ct, &priv->matrix_rotate); +} +#endif + +for (curr=path->head, wcurr=path->whead; curr++!=path->tail;) { + x2=unit2x(curr->unitx); + y2=unit2y(curr->unity); -for (curr = path->head, wcurr = path->whead; curr++ != path->tail;) { + g_debug("Path: %d,%d - %d,%d", x1, y1, x2, y2); - /* Draw the line from (curr - 1) to (curr). */ - gtk_map_render_path_segment(widget, curr[-1].unitx, curr[-1].unity, curr->unitx, curr->unity); + if (x1!=x2 || y1!=y2) { + /* Make sure this line could possibly be visible. */ + if (!((x1 > priv->buf_width_pixels && x2 > priv->buf_width_pixels) || (x1 < 0 && x2 < 0) + || (y1 > priv->buf_height_pixels && y2 > priv->buf_height_pixels) || (y1 < 0 && y2 < 0))) { +#ifdef WITH_CAIRO + cairo_line_to(priv->ct, x2, y2); +#else + gdk_draw_line(widget->window, priv->gc_track, x1, y1, x2, y2); + x1=x2; + y1=y2; +#endif + } + } /* Now, check if curr is a waypoint. */ if (wcurr && wcurr <= path->wtail && wcurr->point == curr) { @@ -1162,11 +1168,17 @@ for (curr = path->head, wcurr = path->whead; curr++ != path->tail;) { gtk_map_render_waypoint(widget, wx, wy); wcurr++; } + prev=curr; } #if 0 if (path->type==PATH_TYPE_ROUTE) gtk_map_render_next_waypoint(widget, path); #endif +#ifdef WITH_CAIRO +cairo_stroke(priv->ct); +cairo_identity_matrix(priv->ct); +cairo_restore(priv->ct); +#endif } /** -- 2.39.5