--- trunk/src/map-tool.c 2009/08/16 19:29:01 57 +++ trunk/src/map-tool.c 2009/08/17 10:51:56 58 @@ -282,6 +282,72 @@ return FALSE; } +static void +cairo_draw_pixbuf(cairo_t *cr, GdkPixbuf *buf, gint x, gint y) { + /* convert the pixbuf into something cairo can handle */ + + // Create a new ImageSurface + cairo_surface_t *image_surface = + cairo_image_surface_create(CAIRO_FORMAT_ARGB32, + gdk_pixbuf_get_width(buf), + gdk_pixbuf_get_height(buf)); + + // Create the new Context for the ImageSurface + cairo_t *context = cairo_create(image_surface); + + // Draw the image on the new Context + gdk_cairo_set_source_pixbuf(context, buf, 0.0, 0.0); + cairo_paint(context); + + // now draw this onto the original context + cairo_set_source_surface(cr, image_surface, x, y); + cairo_paint(cr); +} + +static void +balloon_draw_cb(cairo_t *cr, OsmGpsMapRect_t *rect, gpointer data) { + cache_t *cache = (cache_t*)data; + + // printf("draw cb for \"%s\"\n", cache->name); + +#if 0 + /* draw pink background to check clipping */ + cairo_rectangle (cr, rect->x-20, rect->y-20, rect->w+40, rect->h+40); + cairo_set_source_rgba (cr, 1, 0, 0, 0.3); + cairo_fill_preserve (cr); + cairo_set_line_width (cr, 0); + cairo_stroke (cr); +#endif + + /* leave a little border top and left */ + gint x = rect->x, y = rect->y; + + /* draw the cache type icon ... */ + GdkPixbuf *icon = icon_get(ICON_CACHE_TYPE, cache->type); + cairo_draw_pixbuf(cr, icon, x, y); + + /* ... and right of it the waypoint id */ + cairo_text_extents_t extents; + + cairo_select_font_face (cr, "Sans", + CAIRO_FONT_SLANT_NORMAL, + CAIRO_FONT_WEIGHT_BOLD); + + cairo_set_font_size (cr, 20.0); + cairo_text_extents (cr, cache->id, &extents); + + /* draw right of icon vertically centered */ + x += gdk_pixbuf_get_width(icon) + 5; + y += (gdk_pixbuf_get_height(icon) + extents.height)/2; + + cairo_move_to (cr, x,y); + printf("trying to draw %s\n", cache->id); + cairo_set_source_rgba (cr, 0, 0, 0, 1); + cairo_show_text (cr, cache->id); + cairo_stroke (cr); + +} + static gboolean on_map_button_release_event(GtkWidget *widget, GdkEventButton *event, map_context_t *context) { @@ -299,7 +365,8 @@ float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE); if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ) { - osm_gps_map_draw_balloon(map, nearest->pos.lat, nearest->pos.lon); + osm_gps_map_draw_balloon(map, nearest->pos.lat, nearest->pos.lon, + balloon_draw_cb, nearest); } } context->press_on = NULL;