282 |
return FALSE; |
return FALSE; |
283 |
} |
} |
284 |
|
|
285 |
|
static void |
286 |
|
cairo_draw_pixbuf(cairo_t *cr, GdkPixbuf *buf, gint x, gint y) { |
287 |
|
/* convert the pixbuf into something cairo can handle */ |
288 |
|
|
289 |
|
// Create a new ImageSurface |
290 |
|
cairo_surface_t *image_surface = |
291 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
292 |
|
gdk_pixbuf_get_width(buf), |
293 |
|
gdk_pixbuf_get_height(buf)); |
294 |
|
|
295 |
|
// Create the new Context for the ImageSurface |
296 |
|
cairo_t *context = cairo_create(image_surface); |
297 |
|
|
298 |
|
// Draw the image on the new Context |
299 |
|
gdk_cairo_set_source_pixbuf(context, buf, 0.0, 0.0); |
300 |
|
cairo_paint(context); |
301 |
|
|
302 |
|
// now draw this onto the original context |
303 |
|
cairo_set_source_surface(cr, image_surface, x, y); |
304 |
|
|
305 |
|
cairo_paint(cr); |
306 |
|
} |
307 |
|
|
308 |
|
#define LINE_SKIP 7 |
309 |
|
|
310 |
|
static void |
311 |
|
balloon_draw_cb(cairo_t *cr, OsmGpsMapRect_t *rect, gpointer data) { |
312 |
|
cache_t *cache = (cache_t*)data; |
313 |
|
|
314 |
|
// printf("draw cb for \"%s\"\n", cache->name); |
315 |
|
|
316 |
|
#if 0 |
317 |
|
/* draw pink background to check clipping */ |
318 |
|
cairo_rectangle (cr, rect->x-20, rect->y-20, rect->w+40, rect->h+40); |
319 |
|
cairo_set_source_rgba (cr, 1, 0, 0, 0.3); |
320 |
|
cairo_fill_preserve (cr); |
321 |
|
cairo_set_line_width (cr, 0); |
322 |
|
cairo_stroke (cr); |
323 |
|
#endif |
324 |
|
|
325 |
|
/* leave a little border top and left */ |
326 |
|
gint x = rect->x, y = rect->y; |
327 |
|
|
328 |
|
/* draw the cache type icon ... */ |
329 |
|
GdkPixbuf *icon = icon_get(ICON_CACHE_TYPE, cache->type); |
330 |
|
cairo_draw_pixbuf(cr, icon, x, y); |
331 |
|
|
332 |
|
/* ... and right of it the waypoint id */ |
333 |
|
cairo_text_extents_t extents; |
334 |
|
|
335 |
|
if(cache->id) { |
336 |
|
cairo_select_font_face (cr, "Sans", |
337 |
|
CAIRO_FONT_SLANT_NORMAL, |
338 |
|
CAIRO_FONT_WEIGHT_BOLD); |
339 |
|
|
340 |
|
cairo_set_font_size (cr, 20.0); |
341 |
|
cairo_text_extents (cr, cache->id, &extents); |
342 |
|
|
343 |
|
/* display id right of icon vertically centered */ |
344 |
|
x += gdk_pixbuf_get_width(icon) + 5; |
345 |
|
y += (gdk_pixbuf_get_height(icon) + extents.height)/2; |
346 |
|
cairo_move_to (cr, x, y); |
347 |
|
cairo_set_source_rgba (cr, 0, 0, 0, 1); |
348 |
|
cairo_show_text (cr, cache->id); |
349 |
|
cairo_stroke (cr); |
350 |
|
|
351 |
|
y += (gdk_pixbuf_get_height(icon) - extents.height)/2 + LINE_SKIP; |
352 |
|
} else |
353 |
|
y += gdk_pixbuf_get_height(icon); |
354 |
|
|
355 |
|
/* return to the left border and below icon/text */ |
356 |
|
x = rect->x; |
357 |
|
|
358 |
|
/* everything from here uses the same font */ |
359 |
|
cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL, |
360 |
|
CAIRO_FONT_WEIGHT_NORMAL); |
361 |
|
cairo_set_font_size (cr, 14.0); |
362 |
|
|
363 |
|
if(cache->name) { |
364 |
|
/* draw cache name */ |
365 |
|
cairo_text_extents (cr, cache->name, &extents); |
366 |
|
y += extents.height; |
367 |
|
cairo_move_to (cr, x, y); |
368 |
|
cairo_set_source_rgba (cr, 0, 0, 0, 1); |
369 |
|
cairo_show_text (cr, cache->name); |
370 |
|
cairo_stroke (cr); |
371 |
|
|
372 |
|
/* return to the left border and below text */ |
373 |
|
y += LINE_SKIP; |
374 |
|
x = rect->x; |
375 |
|
} |
376 |
|
|
377 |
|
if(cache->terrain) { |
378 |
|
/* draw cache rating */ |
379 |
|
const char *terrain = "Terrain:"; |
380 |
|
icon = icon_get(ICON_STARS, (int)(cache->terrain*2-2)); |
381 |
|
cairo_text_extents (cr, _(terrain), &extents); |
382 |
|
y += (gdk_pixbuf_get_height(icon) + extents.height)/2; |
383 |
|
|
384 |
|
/* draw "Terrain:" string */ |
385 |
|
cairo_move_to (cr, x, y); |
386 |
|
cairo_set_source_rgba (cr, 0, 0, 0, 1); |
387 |
|
cairo_show_text (cr, _(terrain)); |
388 |
|
cairo_stroke (cr); |
389 |
|
x += extents.width + 2; |
390 |
|
|
391 |
|
/* draw terrain stars */ |
392 |
|
cairo_draw_pixbuf(cr, icon, x, y - |
393 |
|
(gdk_pixbuf_get_height(icon) + extents.height)/2); |
394 |
|
|
395 |
|
x += gdk_pixbuf_get_width(icon) + LINE_SKIP; |
396 |
|
y -= (gdk_pixbuf_get_height(icon) + extents.height)/2; |
397 |
|
} |
398 |
|
|
399 |
|
if(cache->difficulty) { |
400 |
|
const char *difficulty = "Difficulty:"; |
401 |
|
cairo_text_extents (cr, _(difficulty), &extents); |
402 |
|
y += (gdk_pixbuf_get_height(icon) + extents.height)/2; |
403 |
|
|
404 |
|
/* draw "Difficulty:" string */ |
405 |
|
cairo_move_to (cr, x, y); |
406 |
|
cairo_set_source_rgba (cr, 0, 0, 0, 1); |
407 |
|
cairo_show_text (cr, _(difficulty)); |
408 |
|
cairo_stroke (cr); |
409 |
|
x += extents.width + 2; |
410 |
|
|
411 |
|
icon = icon_get(ICON_STARS, (int)(cache->difficulty*2-2)); |
412 |
|
cairo_draw_pixbuf(cr, icon, x, y - |
413 |
|
(gdk_pixbuf_get_height(icon) + extents.height)/2); |
414 |
|
} |
415 |
|
} |
416 |
|
|
417 |
static gboolean |
static gboolean |
418 |
on_map_button_release_event(GtkWidget *widget, |
on_map_button_release_event(GtkWidget *widget, |
419 |
GdkEventButton *event, map_context_t *context) { |
GdkEventButton *event, map_context_t *context) { |
431 |
float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE); |
float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE); |
432 |
if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ) { |
if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ) { |
433 |
|
|
434 |
osm_gps_map_draw_balloon(map, nearest->pos.lat, nearest->pos.lon); |
osm_gps_map_draw_balloon(map, nearest->pos.lat, nearest->pos.lon, |
435 |
|
balloon_draw_cb, nearest); |
436 |
} |
} |
437 |
} |
} |
438 |
context->press_on = NULL; |
context->press_on = NULL; |