From: Kaj-Michael Lang Date: Fri, 28 Dec 2007 16:02:11 +0000 (+0200) Subject: Add generic information printer. Convert speed display to use it. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d138d4b782d7af83698ef23c4d04e03540fc03f;p=mapper Add generic information printer. Convert speed display to use it. Remove old code. --- diff --git a/src/map.c b/src/map.c index 9488a88..8ba4f47 100644 --- a/src/map.c +++ b/src/map.c @@ -110,12 +110,6 @@ static gboolean map_data_needs_refresh=FALSE; static osm_location map_loc = {NULL, NULL, NULL, FALSE, FALSE, 0, 0, 0.0, 0.0, 0 }; -typedef struct _map_tile_rdata map_tile_rdata; -struct _map_tile_rdata { - guint tilex, tiley, zoom; - guint destx, desty; -}; - /* Tile max age, 1 week */ #define TILE_MAX_AGE (604800) @@ -174,7 +168,7 @@ gdk_gc_set_rgb_fg_color(speed_gc2, &color); speed_context=gtk_widget_get_pango_context(map_widget); speed_layout=pango_layout_new(speed_context); speed_fontdesc=pango_font_description_new(); -pango_font_description_set_size(speed_fontdesc, 64 * PANGO_SCALE); +pango_font_description_set_size(speed_fontdesc, 48 * PANGO_SCALE); pango_layout_set_font_description(speed_layout, speed_fontdesc); pango_layout_set_alignment(speed_layout, PANGO_ALIGN_CENTER); @@ -399,16 +393,6 @@ if (pixbuf) { gdk_draw_rectangle(_map_pixmap, _map_widget->style->black_gc, TRUE, destx, desty, TILE_SIZE_PIXELS, TILE_SIZE_PIXELS); } -gboolean -map_render_tile_idle(map_tile_rdata *mtr) -{ -map_render_tile(mtr->tilex, mtr->tiley, mtr->destx, mtr->desty, FALSE); -gtk_widget_queue_draw_area(_map_widget, mtr->destx, mtr->desty, TILE_SIZE_PIXELS, TILE_SIZE_PIXELS); - -g_slice_free(map_tile_rdata, mtr); -return FALSE; -} - void map_render_data(void) { @@ -504,10 +488,8 @@ BOUND(new_center_unity, _min_center.unity, _max_center.unity); _center.unitx = new_center_unitx; _center.unity = new_center_unity; -new_base_tilex = grid2tile((gint) pixel2grid((gint)unit2pixel((gint) _center.unitx)) - - (gint)_screen_grids_halfwidth); -new_base_tiley = grid2tile(pixel2grid(unit2pixel(_center.unity)) - - _screen_grids_halfheight); +new_base_tilex = grid2tile((gint) pixel2grid((gint)unit2pixel((gint) _center.unitx)) - (gint)_screen_grids_halfwidth); +new_base_tiley = grid2tile(pixel2grid(unit2pixel(_center.unity)) - _screen_grids_halfheight); /* Same zoom level, so it's likely that we can reuse some of the old * buffer's pixels. */ @@ -544,11 +526,9 @@ if (new_base_tilex != _base_tilex || new_base_tiley != _base_tiley) { new_x = base_new_x; old_x = base_old_x; /* Iterate over the x tile values. */ - for (k = 0; k < BUF_WIDTH_TILES; - ++k, new_x += iox, old_x += iox) { + for (k = 0; k < BUF_WIDTH_TILES; ++k, new_x += iox, old_x += iox) { /* Can we get this grid block from the old buffer?. */ - if (old_x >= 0 && old_x < BUF_WIDTH_TILES - && old_y >= 0 && old_y < BUF_HEIGHT_TILES) { + if (old_x >= 0 && old_x < BUF_WIDTH_TILES && old_y >= 0 && old_y < BUF_HEIGHT_TILES) { /* Copy from old buffer to new buffer. */ gdk_draw_drawable(_map_pixmap, _gc[COLORABLE_MARK], @@ -895,33 +875,29 @@ if (_key_zoom_new < _zoom) { return TRUE; } +static void +map_information_text(guint x, guint y, GdkGC *gc, gchar *msg) +{ +guint width, height; + +pango_layout_set_text(speed_layout, msg, -1); +pango_layout_get_pixel_size(speed_layout, &width, &height); +gtk_widget_queue_draw_area(_map_widget, x - 5, y - 5, width * 3 + 15, height + 5); +gdk_window_process_all_updates(); +gdk_draw_layout(_map_widget->window, gc, x, y, speed_layout); +} + static void map_speed_draw(void) { GdkGC *gc; gfloat cur_speed; gchar *buffer; -static guint x = 0, y = 0, width = 0, height = 0; cur_speed = _gps.speed * UNITS_CONVERT[_units]; - -if (cur_speed > _speed_limit) { - gc = speed_gc1; -} else { - gc = speed_gc2; -} - +gc=(cur_speed > _speed_limit) ? speed_gc1 : speed_gc2; buffer = g_strdup_printf("%0.0f", cur_speed); -pango_layout_set_text(speed_layout, buffer, -1); -pango_layout_get_pixel_size(speed_layout, &width, &height); - -gtk_widget_queue_draw_area(_map_widget, x - 5, y - 5, width * 3 + 15, height + 5); -gdk_window_process_all_updates(); - -x = 10; -y = 10; - -gdk_draw_layout(_map_widget->window, gc, x, y, speed_layout); +map_information_text(10, 10, gc, buffer); g_free(buffer); }