From 6e7bd820c63306d321f0c67fed4f027b192932a5 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Wed, 9 Apr 2008 12:29:11 +0300 Subject: [PATCH] Draw destination icon. --- src/map.c | 65 +++++++++++++++++++++++++++++++++++-------------------- src/map.h | 2 +- 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/src/map.c b/src/map.c index 455ca24..f919d7e 100644 --- a/src/map.c +++ b/src/map.c @@ -482,12 +482,15 @@ map_render_data(void) if (map_drag_id>0) return; -if (_home.valid) - map_draw_position_icon(&_home); - if(_show_poi) map_render_all_pois(buf_width_pixels, buf_height_pixels); +if (_home.valid) + map_draw_position_icon(&_home, "home"); + +if (_dest.valid) + map_draw_position_icon(&_dest, "destination"); + if(_show_tracks>0) map_render_paths(); } @@ -746,15 +749,11 @@ map_update_location(lat, lon, TRUE); return FALSE; } -/** - * Draw given pixbuf on map, centered on x,y - */ void -map_draw_pixbuf(guint unitx, guint unity, GdkPixbuf *p) +map_draw_pixbuf_on_buffer(gint x, gint y, GdkPixbuf *p) { -gint x,y; -x = unit2bufx(unitx); -y = unit2bufy(unity); +if ((x < 0) || (y < 0)) + return; if ((x > buf_width_pixels) || (y > buf_height_pixels)) return; @@ -767,29 +766,47 @@ gdk_draw_pixbuf(map_pixmap, _gc[COLORABLE_POI], } /** - * Draw an icon on given Position. - * - * XXX: don't hardcode as home.png ! + * Draw given pixbuf on map, centered on x,y */ void -map_draw_position_icon(Position *pos) +map_draw_pixbuf(guint unitx, guint unity, GdkPixbuf *p) { -guint x,y, x1,y1; +gint x,y; +x=unit2bufx(unitx); +y=unit2bufy(unity); + +map_draw_pixbuf_on_buffer(x, y, p); +} + +/** + * Draw an icon at given Position. + * + */ +static void +map_draw_position_icon(Position *pos, const gchar *icon) +{ +gint x, y; +guint ux, uy; +gchar buffer[128]; GdkPixbuf *p; -latlon2unit(pos->lat, pos->lon, x, y); -x1=unit2bufx(x); -y1=unit2bufy(y); +latlon2unit(pos->lat, pos->lon, ux, uy); +x=unit2bufx(ux); +y=unit2bufy(uy); -if ((x1 > buf_width_pixels) || (y1 > buf_height_pixels)) +if ((x < 0) || (y < 0)) return; -p=gdk_pixbuf_new_from_file(DATADIR "/pixmaps/mapper/home.png", NULL); -if (p) { - map_draw_pixbuf(x,y,p); - g_object_unref(p); -} +if ((x > buf_width_pixels) || (y > buf_height_pixels)) + return; + +g_snprintf(buffer, sizeof(buffer), "%s/pixmaps/mapper/%s.png", DATADIR, icon); +p=gdk_pixbuf_new_from_file(buffer, NULL); +if (!p) + return; +map_draw_pixbuf_on_buffer(x, y, p); +g_object_unref(p); } /** diff --git a/src/map.h b/src/map.h index 7d9ec10..5105a48 100644 --- a/src/map.h +++ b/src/map.h @@ -206,7 +206,7 @@ gboolean map_render_tile(guint tilex, guint tiley, guint destx, guint desty, gbo void map_render_waypoint(guint x1, guint y1, GdkGC *gc); void map_render_paths(void); void map_force_redraw(void); -void map_draw_position_icon(Position *pos); +void map_draw_position_icon(Position *pos, const gchar *icon); GdkPixmap *map_pixmap_get(void); void map_center_unit(guint new_center_unitx, guint new_center_unity); -- 2.39.5