From 7591aa1c159d4d94568c26e14b8f28ba45ce4419 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Tue, 6 May 2008 14:06:46 +0300 Subject: [PATCH] Map widget: - Give scale some cairo love - Use constant instead of magic number for the scale padding --- src/gtkmap.c | 63 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/src/gtkmap.c b/src/gtkmap.c index bfd93f9..14661da 100644 --- a/src/gtkmap.c +++ b/src/gtkmap.c @@ -748,6 +748,8 @@ priv->mark_rect.width = abs(priv->mark_x1 - priv->mark_x2) + (4 * priv->draw_wid priv->mark_rect.height = abs(priv->mark_y1 - priv->mark_y2) + (4 * priv->draw_width); } +#define SCALE_PADDING (4) + static void gtk_map_scale_draw(GtkWidget *widget, GdkEventExpose *event) { @@ -772,8 +774,8 @@ if (!gdk_rectangle_intersect(&event->area, &priv->scale_rect, NULL)) return; /* Now calculate and draw the distance. */ -unit2latlon(priv->center.unitx - pixel2unit(SCALE_WIDTH / 2 - 4), priv->center.unity, lat1, lon1); -unit2latlon(priv->center.unitx + pixel2unit(SCALE_WIDTH / 2 - 4), priv->center.unity, lat2, lon2); +unit2latlon(priv->center.unitx - pixel2unit(SCALE_WIDTH / 2 - SCALE_PADDING), priv->center.unity, lat1, lon1); +unit2latlon(priv->center.unitx + pixel2unit(SCALE_WIDTH / 2 - SCALE_PADDING), priv->center.unity, lat2, lon2); distance=calculate_distance(lat1, lon1, lat2, lon2) * priv->units_conv; if (distance < 1.f) @@ -787,10 +789,9 @@ g_debug("SCALE: %s", buffer); #ifdef WITH_CAIRO cairo_rectangle(priv->ct, priv->scale_rect.x, priv->scale_rect.y, priv->scale_rect.width, priv->scale_rect.height); -cairo_set_source_rgba(priv->ct, 1, 1, 1, 0.8); +cairo_set_source_rgba(priv->ct, 1, 1, 1, 0.65); cairo_fill_preserve(priv->ct); -cairo_set_source_rgb(priv->ct, 0, 0, 0); -cairo_stroke(priv->ct); +cairo_set_source_rgba(priv->ct, 0, 0, 0, 0.81); #else gdk_draw_rectangle(widget->window, widget->style->bg_gc[GTK_WIDGET_STATE(widget)], TRUE, priv->scale_rect.x, priv->scale_rect.y, priv->scale_rect.width, priv->scale_rect.height); @@ -801,33 +802,41 @@ gdk_draw_rectangle(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget) pango_layout_set_text(priv->scale_layout, buffer, -1); pango_layout_get_pixel_size(priv->scale_layout, &width, NULL); -/* Draw the layout itself. */ -gdk_draw_layout(widget->window, - widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - priv->scale_rect.x + (priv->scale_rect.width - width) / 2, - priv->scale_rect.y, priv->scale_layout); - /* Draw little hashes on the ends. */ +#ifdef WITH_CAIRO +cairo_set_source_rgb(priv->ct, 0, 0, 0); +cairo_move_to(priv->ct, priv->scale_rect.x + SCALE_PADDING, priv->scale_rect.y + priv->scale_rect.height / 2 - SCALE_PADDING); +cairo_line_to(priv->ct, priv->scale_rect.x + SCALE_PADDING, priv->scale_rect.y + priv->scale_rect.height / 2 + SCALE_PADDING); + +cairo_move_to(priv->ct, priv->scale_rect.x + SCALE_PADDING, priv->scale_rect.y + priv->scale_rect.height / 2); +cairo_line_to(priv->ct, priv->scale_rect.x + (priv->scale_rect.width - width) / 2 - SCALE_PADDING, priv->scale_rect.y + priv->scale_rect.height / 2); + +cairo_move_to(priv->ct, priv->scale_rect.x + priv->scale_rect.width - SCALE_PADDING, priv->scale_rect.y + priv->scale_rect.height / 2 - SCALE_PADDING); +cairo_line_to(priv->ct, priv->scale_rect.x + priv->scale_rect.width - SCALE_PADDING, priv->scale_rect.y + priv->scale_rect.height / 2 + SCALE_PADDING); + +cairo_move_to(priv->ct, priv->scale_rect.x + priv->scale_rect.width - SCALE_PADDING, priv->scale_rect.y + priv->scale_rect.height / 2); +cairo_line_to(priv->ct, priv->scale_rect.x + (priv->scale_rect.width + width) / 2 + SCALE_PADDING, priv->scale_rect.y + priv->scale_rect.height / 2); + +cairo_stroke(priv->ct); +#else gdk_draw_line(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - priv->scale_rect.x + 4, - priv->scale_rect.y + priv->scale_rect.height / 2 - 4, - priv->scale_rect.x + 4, - priv->scale_rect.y + priv->scale_rect.height / 2 + 4); + priv->scale_rect.x + SCALE_PADDING, priv->scale_rect.y + priv->scale_rect.height / 2 - SCALE_PADDING, + priv->scale_rect.x + SCALE_PADDING, priv->scale_rect.y + priv->scale_rect.height / 2 + SCALE_PADDING); gdk_draw_line(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - priv->scale_rect.x + 4, - priv->scale_rect.y + priv->scale_rect.height / 2, - priv->scale_rect.x + (priv->scale_rect.width - width) / 2 - 4, - priv->scale_rect.y + priv->scale_rect.height / 2); + priv->scale_rect.x + SCALE_PADDING, priv->scale_rect.y + priv->scale_rect.height / 2, + priv->scale_rect.x + (priv->scale_rect.width - width) / 2 - SCALE_PADDING, priv->scale_rect.y + priv->scale_rect.height / 2); gdk_draw_line(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - priv->scale_rect.x + priv->scale_rect.width - 4, - priv->scale_rect.y + priv->scale_rect.height / 2 - 4, - priv->scale_rect.x + priv->scale_rect.width - 4, - priv->scale_rect.y + priv->scale_rect.height / 2 + 4); + priv->scale_rect.x + priv->scale_rect.width - SCALE_PADDING, priv->scale_rect.y + priv->scale_rect.height / 2 - SCALE_PADDING, + priv->scale_rect.x + priv->scale_rect.width - SCALE_PADDING, priv->scale_rect.y + priv->scale_rect.height / 2 + SCALE_PADDING); gdk_draw_line(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], - priv->scale_rect.x + priv->scale_rect.width - 4, - priv->scale_rect.y + priv->scale_rect.height / 2, - priv->scale_rect.x + (priv->scale_rect.width + width) / 2 + 4, - priv->scale_rect.y + priv->scale_rect.height / 2); + priv->scale_rect.x + priv->scale_rect.width - SCALE_PADDING, priv->scale_rect.y + priv->scale_rect.height / 2, + priv->scale_rect.x + (priv->scale_rect.width + width) / 2 + SCALE_PADDING, priv->scale_rect.y + priv->scale_rect.height / 2); +#endif + +/* Draw the layout itself. */ +gdk_draw_layout(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], + priv->scale_rect.x + (priv->scale_rect.width - width) / 2, priv->scale_rect.y, priv->scale_layout); + } static void -- 2.39.5