Diff of /trunk/src/map-tool.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 57 by harbaum, Sun Aug 16 19:29:01 2009 UTC revision 61 by harbaum, Tue Aug 18 14:32:45 2009 UTC
# Line 18  Line 18 
18   */   */
19    
20  #include "gpxview.h"  #include "gpxview.h"
21    #include "converter.h"
22  #include <math.h>    // for isnan  #include <math.h>    // for isnan
23    
24  #ifdef ENABLE_OSM_GPS_MAP  #ifdef ENABLE_OSM_GPS_MAP
# Line 27  Line 28 
28  #define MAP_SOURCE  OSM_GPS_MAP_SOURCE_OPENSTREETMAP  #define MAP_SOURCE  OSM_GPS_MAP_SOURCE_OPENSTREETMAP
29  #define GPS_DEFAULT_ZOOM 13  #define GPS_DEFAULT_ZOOM 13
30    
 /* equatorial radius in meters */  
 #define EQ_RADIUS     (6378137.0)  
   
 #define RAD2DEG(a)  (((a)*180.0)/M_PI)  
 #define DEG2RAD(a)  (((a)*M_PI)/180.0)  
   
31  #define PROXY_KEY  "/system/http_proxy/"  #define PROXY_KEY  "/system/http_proxy/"
32    
33  static const char *get_proxy_uri(appdata_t *appdata) {  static const char *get_proxy_uri(appdata_t *appdata) {
# Line 83  static void map_zoom(map_context_t *cont Line 78  static void map_zoom(map_context_t *cont
78    gtk_widget_set_sensitive(context->zoomout,    gtk_widget_set_sensitive(context->zoomout,
79             zoom > osm_gps_map_source_get_min_zoom(MAP_SOURCE));             zoom > osm_gps_map_source_get_min_zoom(MAP_SOURCE));
80    
   /* hmm ... this doesn't really work */  
   osm_gps_map_osd_speed(map, zoom);  
   
81    /* save new zoom */    /* save new zoom */
82    context->appdata->map.zoom = zoom;    context->appdata->map.zoom = zoom;
83  }  }
# Line 251  static cache_t *map_closest(map_context_ Line 243  static cache_t *map_closest(map_context_
243  /* translate between osm-gps-map positions and gpxview ones */  /* translate between osm-gps-map positions and gpxview ones */
244  pos_t coord2pos(coord_t coo) {  pos_t coord2pos(coord_t coo) {
245    pos_t pos;    pos_t pos;
246    pos.lat = RAD2DEG(coo.rlat);    pos.lat = rad2deg(coo.rlat);
247    pos.lon = RAD2DEG(coo.rlon);    pos.lon = rad2deg(coo.rlon);
248    return pos;    return pos;
249  }  }
250    
# Line 282  on_map_button_press_event(GtkWidget *wid Line 274  on_map_button_press_event(GtkWidget *wid
274    return FALSE;    return FALSE;
275  }  }
276    
277    static void
278    cairo_draw_pixbuf(cairo_t *cr, GdkPixbuf *buf, gint x, gint y) {
279      /* convert the pixbuf into something cairo can handle */
280    
281      // Create a new ImageSurface
282      cairo_surface_t *image_surface =
283        cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
284                                   gdk_pixbuf_get_width(buf),
285                                   gdk_pixbuf_get_height(buf));
286    
287      // Create the new Context for the ImageSurface
288      cairo_t *context = cairo_create(image_surface);
289    
290      // Draw the image on the new Context
291      gdk_cairo_set_source_pixbuf(context, buf, 0.0, 0.0);
292      cairo_paint(context);
293    
294      // now draw this onto the original context
295      cairo_set_source_surface(cr, image_surface, x, y);
296    
297      cairo_paint(cr);
298    }
299    
300    #define LINE_SKIP  7
301    
302    static void
303    balloon_draw_cb(cairo_t *cr, OsmGpsMapRect_t *rect, gpointer data) {
304      cache_t *cache = (cache_t*)data;
305    
306      //  printf("draw cb for \"%s\"\n", cache->name);
307    
308    #if 0
309      /* draw pink background to check clipping */
310      cairo_rectangle (cr, rect->x-20, rect->y-20, rect->w+40, rect->h+40);
311      cairo_set_source_rgba (cr, 1, 0, 0, 0.3);
312      cairo_fill_preserve (cr);
313      cairo_set_line_width (cr, 0);
314      cairo_stroke (cr);
315    #endif
316    
317      /* leave a little border top and left */
318      gint x = rect->x, y = rect->y;
319    
320      /* draw the cache type icon ... */
321      GdkPixbuf *icon = icon_get(ICON_CACHE_TYPE, cache->type);
322      cairo_draw_pixbuf(cr, icon, x, y);
323    
324      /* ... and right of it the waypoint id */
325      cairo_text_extents_t extents;
326    
327      if(cache->id) {
328        cairo_select_font_face (cr, "Sans",
329                                CAIRO_FONT_SLANT_NORMAL,
330                                CAIRO_FONT_WEIGHT_BOLD);
331    
332        cairo_set_font_size (cr, 20.0);
333        cairo_text_extents (cr, cache->id, &extents);
334    
335        /* display id right of icon vertically centered */
336        x += gdk_pixbuf_get_width(icon) + 5;
337        y += (gdk_pixbuf_get_height(icon) + extents.height)/2;
338        cairo_move_to (cr, x, y);
339        cairo_set_source_rgba (cr, 0, 0, 0, 1);
340        cairo_show_text (cr, cache->id);
341        cairo_stroke (cr);
342    
343        y += (gdk_pixbuf_get_height(icon) - extents.height)/2 + LINE_SKIP;
344      } else
345        y += gdk_pixbuf_get_height(icon);
346    
347      /* return to the left border and below icon/text */
348      x = rect->x;
349    
350      /* everything from here uses the same font */
351      cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL,
352                              CAIRO_FONT_WEIGHT_NORMAL);
353      cairo_set_font_size (cr, 14.0);
354    
355      if(cache->name) {
356        /* draw cache name */
357        cairo_text_extents (cr, cache->name, &extents);
358        y += extents.height;
359        cairo_move_to (cr, x, y);
360        cairo_set_source_rgba (cr, 0, 0, 0, 1);
361        cairo_show_text (cr, cache->name);
362        cairo_stroke (cr);
363    
364        /* return to the left border and below text */
365        y += LINE_SKIP;
366        x = rect->x;
367      }
368    
369      if(cache->terrain) {
370        /* draw cache rating */
371        const char *terrain = "Terrain:";
372        icon = icon_get(ICON_STARS, (int)(cache->terrain*2-2));
373        cairo_text_extents (cr, _(terrain), &extents);
374        y += (gdk_pixbuf_get_height(icon) + extents.height)/2;
375    
376        /* draw "Terrain:" string */
377        cairo_move_to (cr, x, y);
378        cairo_set_source_rgba (cr, 0, 0, 0, 1);
379        cairo_show_text (cr, _(terrain));
380        cairo_stroke (cr);
381        x += extents.width + 2;
382    
383        /* draw terrain stars */
384        cairo_draw_pixbuf(cr, icon, x, y -
385                          (gdk_pixbuf_get_height(icon) + extents.height)/2);
386    
387        x += gdk_pixbuf_get_width(icon) + LINE_SKIP;
388        y -= (gdk_pixbuf_get_height(icon) + extents.height)/2;
389      }
390    
391      if(cache->difficulty) {
392        const char *difficulty = "Difficulty:";
393        cairo_text_extents (cr, _(difficulty), &extents);
394        y += (gdk_pixbuf_get_height(icon) + extents.height)/2;
395    
396        /* draw "Difficulty:" string */
397        cairo_move_to (cr, x, y);
398        cairo_set_source_rgba (cr, 0, 0, 0, 1);
399        cairo_show_text (cr, _(difficulty));
400        cairo_stroke (cr);
401        x += extents.width + 2;
402    
403        icon = icon_get(ICON_STARS, (int)(cache->difficulty*2-2));
404        cairo_draw_pixbuf(cr, icon, x, y -
405                          (gdk_pixbuf_get_height(icon) + extents.height)/2);
406      }
407    }
408    
409  static gboolean  static gboolean
410  on_map_button_release_event(GtkWidget *widget,  on_map_button_release_event(GtkWidget *widget,
411                              GdkEventButton *event, map_context_t *context) {                              GdkEventButton *event, map_context_t *context) {
# Line 299  on_map_button_release_event(GtkWidget *w Line 423  on_map_button_release_event(GtkWidget *w
423        float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE);        float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE);
424        if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ) {        if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ) {
425    
426          osm_gps_map_draw_balloon(map, nearest->pos.lat, nearest->pos.lon);          osm_gps_map_draw_balloon(map, nearest->pos.lat, nearest->pos.lon,
427                                     balloon_draw_cb, nearest);
428        }        }
429      }      }
430      context->press_on = NULL;      context->press_on = NULL;

Legend:
Removed from v.57  
changed lines
  Added in v.61