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

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

revision 112 by harbaum, Tue Sep 15 13:52:04 2009 UTC revision 120 by harbaum, Sat Sep 19 19:19:42 2009 UTC
# Line 175  static gboolean on_map_configure(GtkWidg Line 175  static gboolean on_map_configure(GtkWidg
175    return FALSE;    return FALSE;
176  }  }
177    
178  static void map_draw_cachelist(GtkWidget *map, cache_t *cache) {  static void map_draw_cache(GtkWidget *map, cache_t *cache) {
179    while(cache) {    GdkPixbuf *icon = icon_get(ICON_CACHE_TYPE, cache->type);
     GdkPixbuf *icon = icon_get(ICON_CACHE_TYPE, cache->type);  
180    
181      /* check if there's also an overwritten coordinate */
182      if(cache->notes && cache->notes->override) {
183        GdkPixbuf *over = icon_get(ICON_MISC, 1);
184    
185        osm_gps_map_add_image(OSM_GPS_MAP(map),
186              cache->notes->pos.lat, cache->notes->pos.lon, icon);
187    
188        osm_gps_map_add_image(OSM_GPS_MAP(map),
189              cache->notes->pos.lat, cache->notes->pos.lon, over);
190      } else
191      osm_gps_map_add_image(OSM_GPS_MAP(map),      osm_gps_map_add_image(OSM_GPS_MAP(map),
192                            cache->pos.lat, cache->pos.lon, icon);                            cache->pos.lat, cache->pos.lon, icon);
193    
194    }
195    
196    static void map_draw_gpx(appdata_t *appdata, GtkWidget *map, gpx_t *gpx) {
197      if(!gpx->notes_loaded) {
198        notes_load_all(appdata, gpx);
199        gpx->notes_loaded = TRUE;
200      }
201    
202      cache_t *cache = gpx->cache;
203      while(cache) {
204        map_draw_cache(map, cache);
205      cache = cache->next;      cache = cache->next;
206    }    }
207  }  }
# Line 190  static void Line 210  static void
210  map_cachelist_nearest(cache_t *cache, pos_t *pos,  map_cachelist_nearest(cache_t *cache, pos_t *pos,
211                        cache_t **result, float *distance) {                        cache_t **result, float *distance) {
212    while(cache) {    while(cache) {
213        pos_t cpos = gpx_cache_pos(cache);
214    
215      float dist =      float dist =
216        pow(cache->pos.lat - pos->lat, 2) +        pow(cpos.lat - pos->lat, 2) +
217        pow(cache->pos.lon - pos->lon, 2);        pow(cpos.lon - pos->lon, 2);
218    
219      if(!(dist > *distance)) {      if(!(dist > *distance)) {
220        *result = cache;        *result = cache;
# Line 208  static cache_t *map_closest(map_context_ Line 230  static cache_t *map_closest(map_context_
230    float distance = NAN;    float distance = NAN;
231    
232  #ifdef USE_MAEMO  #ifdef USE_MAEMO
233    if(!context->appdata->cur_gpx) {    if(!context->appdata->cur_gpx && !context->appdata->cur_cache) {
234  #endif  #endif
235      /* search all geocaches */      /* search all geocaches */
236      gpx_t *gpx = context->appdata->gpx;      gpx_t *gpx = context->appdata->gpx;
# Line 217  static cache_t *map_closest(map_context_ Line 239  static cache_t *map_closest(map_context_
239        gpx = gpx->next;        gpx = gpx->next;
240      }      }
241  #ifdef USE_MAEMO  #ifdef USE_MAEMO
242    } else {    } else if(context->appdata->cur_gpx) {
243      map_cachelist_nearest(context->appdata->cur_gpx->cache,      map_cachelist_nearest(context->appdata->cur_gpx->cache,
244                            pos, &result, &distance);                            pos, &result, &distance);
245    }    } else
246        result = context->appdata->cur_gpx->cache;
247  #endif  #endif
248    
249    return result;    return result;
# Line 256  on_map_button_press_event(GtkWidget *wid Line 279  on_map_button_press_event(GtkWidget *wid
279    
280    cache_t *nearest = map_closest(context, &pos);    cache_t *nearest = map_closest(context, &pos);
281    if(nearest) {    if(nearest) {
282      float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE);      pos_t cpos = gpx_cache_pos(nearest);
283      if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ)  
284        float dist = gpx_pos_get_distance(pos, cpos, FALSE);
285        if(dist2pixel(context, dist, cpos.lat) < CLICK_FUZZ)
286        context->press_on = nearest;        context->press_on = nearest;
287    }    }
288    
# Line 313  balloon_draw_cb(cairo_t *cr, OsmGpsMapRe Line 338  balloon_draw_cb(cairo_t *cr, OsmGpsMapRe
338    GdkPixbuf *icon = icon_get(ICON_CACHE_TYPE, cache->type);    GdkPixbuf *icon = icon_get(ICON_CACHE_TYPE, cache->type);
339    cairo_draw_pixbuf(cr, icon, x, y);    cairo_draw_pixbuf(cr, icon, x, y);
340    
341      if(cache->notes && cache->notes->override) {
342        GdkPixbuf *over = icon_get(ICON_MISC, 1);
343        cairo_draw_pixbuf(cr, over, x, y);
344      }
345    
346    /* ... and right of it the waypoint id */    /* ... and right of it the waypoint id */
347    cairo_text_extents_t extents;    cairo_text_extents_t extents;
348    
# Line 421  on_map_button_release_event(GtkWidget *w Line 451  on_map_button_release_event(GtkWidget *w
451    
452      cache_t *nearest = map_closest(context, &pos);      cache_t *nearest = map_closest(context, &pos);
453      if(nearest && nearest == context->press_on) {      if(nearest && nearest == context->press_on) {
454        float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE);        pos_t cpos = gpx_cache_pos(nearest);
455        if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ) {  
456          float dist = gpx_pos_get_distance(pos, cpos, FALSE);
457          if(dist2pixel(context, dist, cpos.lat) < CLICK_FUZZ) {
458    
459          osm_gps_map_osd_draw_balloon(map, nearest->pos.lat, nearest->pos.lon,          osm_gps_map_osd_draw_balloon(map, cpos.lat, cpos.lon,
460                                       balloon_draw_cb, nearest);                                       balloon_draw_cb, nearest);
461        }        }
462      }      }
# Line 547  void map(appdata_t *appdata) { Line 579  void map(appdata_t *appdata) {
579    
580    char *name = NULL;    char *name = NULL;
581  #ifdef USE_MAEMO  #ifdef USE_MAEMO
582    if(!appdata->cur_gpx) {    if(!appdata->cur_gpx && !appdata->cur_cache) {
583  #endif  #endif
584      /* draw all geocaches */      /* draw all geocaches */
585      gpx_t *gpx = appdata->gpx;      gpx_t *gpx = appdata->gpx;
586      while(gpx) {      while(gpx) {
587        map_draw_cachelist(context->widget, gpx->cache);        map_draw_gpx(appdata, context->widget, gpx);
588        gpx = gpx->next;        gpx = gpx->next;
589      }      }
590      name = g_strdup(_("all geocaches"));      name = g_strdup(_("all"));
591  #ifdef USE_MAEMO  #ifdef USE_MAEMO
592    } else {    } else if(!appdata->cur_cache) {
593      map_draw_cachelist(context->widget, appdata->cur_gpx->cache);      map_draw_gpx(appdata, context->widget, appdata->cur_gpx);
594      name = g_strdup(appdata->cur_gpx->name);      name = g_strdup(appdata->cur_gpx->name);
595      } else {
596        map_draw_cache(context->widget, appdata->cur_cache);
597        name = g_strdup(appdata->cur_cache->name);
598    }    }
599  #endif  #endif
600    

Legend:
Removed from v.112  
changed lines
  Added in v.120