--- trunk/src/map-tool.c 2009/11/02 10:53:01 152 +++ trunk/src/map-tool.c 2009/11/03 08:38:23 155 @@ -173,7 +173,7 @@ } } -static void map_draw_gpx(appdata_t *appdata, +static void map_draw_gpx(appdata_t *appdata, cache_display_t *caches, GtkWidget *map, gpx_t *gpx, cache_t *nav, gboolean semi) { if(!gpx->notes_loaded) { @@ -183,9 +183,18 @@ cache_t *cache = gpx->cache; while(cache) { - /* if nav is given draw all other caches semitransparent. */ - /* if nav is not given do what semi sais */ - map_draw_cache(map, cache, nav?(cache != nav):semi); + /* search if we have that cache already in our list/displayed */ + int i=0; + while(caches[i].id && (strcmp(caches[i].id, cache->id) != 0)) + i++; + + if(!caches[i].id) { + /* if nav is given draw all other caches semitransparent. */ + /* if nav is not given do what semi sais */ + map_draw_cache(map, cache, nav?(cache != nav):semi); + caches[i].id = cache->id; + } + cache = cache->next; } } @@ -197,15 +206,17 @@ int cache_num = gpx_total_caches_global(context->appdata->gpx); if(context->caches_displayed && (cache_num != context->cache_list_len)) { + // printf("re-alloc because %p %d/%d\n", context->caches_displayed, + // cache_num, context->cache_list_len); g_free(context->caches_displayed); context->caches_displayed = NULL; context->cache_list_len = 0; } /* allocate buffer */ - if(cache_num) { + if(cache_num && !context->caches_displayed) { context->cache_list_len = cache_num; - context->caches_displayed = g_new0(cache_display_t, cache_num); + context->caches_displayed = g_new0(cache_display_t, cache_num+1); printf("allocated space to handle %d map icons\n", cache_num); } @@ -220,13 +231,23 @@ /* clear all existing cache images */ osm_gps_map_clear_images (OSM_GPS_MAP(context->widget)); + memset(context->caches_displayed, 0, + (cache_num+1) * sizeof(cache_display_t)); /* draw all geocaches and none is semi-transparent */ gpx_t *gpx = context->appdata->gpx; while(gpx) { - map_draw_gpx(context->appdata, context->widget, gpx, NULL, FALSE); + map_draw_gpx(context->appdata, context->caches_displayed, + context->widget, gpx, NULL, FALSE); gpx = gpx->next; } + + { + int i=0; + while(context->caches_displayed[i].id) i++; + printf("number of caches actually displayed: %d\n", i); + } + name = g_strdup(_("all")); context->state = MAP_ALL; } @@ -241,12 +262,19 @@ /* clear all existing ccahe images */ osm_gps_map_clear_images (OSM_GPS_MAP(context->widget)); + memset(context->caches_displayed, 0, + (cache_num+1) * sizeof(cache_display_t)); /* draw all geocaches and all other gpx files are semi-transparent */ + map_draw_gpx(context->appdata, context->caches_displayed, + context->widget, context->appdata->cur_gpx, NULL, FALSE); + gpx_t *gpx = context->appdata->gpx; while(gpx) { - map_draw_gpx(context->appdata, context->widget, gpx, NULL, - gpx != context->appdata->cur_gpx); + if(gpx != context->appdata->cur_gpx) + map_draw_gpx(context->appdata, context->caches_displayed, + context->widget, gpx, NULL, TRUE); + gpx = gpx->next; } @@ -256,7 +284,7 @@ } else { cache_t *cache = context->appdata->cur_cache; - printf("map_setp(CACHE)\n"); + printf("map_setup(CACHE)\n"); /* no balloons in this mode */ context->balloon = NULL; @@ -264,11 +292,14 @@ /* clear all existing ccahe images */ osm_gps_map_clear_images (OSM_GPS_MAP(context->widget)); + memset(context->caches_displayed, 0, + (cache_num+1) * sizeof(cache_display_t)); /* draw all geocaches and all but selected one are semi-transparent */ gpx_t *gpx = context->appdata->gpx; while(gpx) { - map_draw_gpx(context->appdata, context->widget, gpx, cache, FALSE); + map_draw_gpx(context->appdata, context->caches_displayed, + context->widget, gpx, cache, FALSE); gpx = gpx->next; }