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

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

revision 151 by harbaum, Fri Oct 30 20:09:13 2009 UTC revision 155 by harbaum, Tue Nov 3 08:38:23 2009 UTC
# Line 173  static void map_draw_cache(GtkWidget *ma Line 173  static void map_draw_cache(GtkWidget *ma
173    }    }
174  }  }
175    
176  static void map_draw_gpx(appdata_t *appdata,  static void map_draw_gpx(appdata_t *appdata, cache_display_t *caches,
177                           GtkWidget *map, gpx_t *gpx,                           GtkWidget *map, gpx_t *gpx,
178                           cache_t *nav, gboolean semi) {                           cache_t *nav, gboolean semi) {
179    if(!gpx->notes_loaded) {    if(!gpx->notes_loaded) {
# Line 183  static void map_draw_gpx(appdata_t *appd Line 183  static void map_draw_gpx(appdata_t *appd
183    
184    cache_t *cache = gpx->cache;    cache_t *cache = gpx->cache;
185    while(cache) {    while(cache) {
186      /* if nav is given draw all other caches semitransparent. */      /* search if we have that cache already in our list/displayed */
187      /* if nav is not given do what semi sais */      int i=0;
188      map_draw_cache(map, cache, nav?(cache != nav):semi);      while(caches[i].id && (strcmp(caches[i].id, cache->id) != 0))
189          i++;
190    
191        if(!caches[i].id) {
192          /* if nav is given draw all other caches semitransparent. */
193          /* if nav is not given do what semi sais */
194          map_draw_cache(map, cache, nav?(cache != nav):semi);
195          caches[i].id = cache->id;
196        }
197    
198      cache = cache->next;      cache = cache->next;
199    }    }
200  }  }
# Line 194  static void map_draw_gpx(appdata_t *appd Line 203  static void map_draw_gpx(appdata_t *appd
203  static void map_setup(map_context_t *context) {  static void map_setup(map_context_t *context) {
204    char *name = NULL;    char *name = NULL;
205    
206      int cache_num = gpx_total_caches_global(context->appdata->gpx);
207    
208      if(context->caches_displayed && (cache_num != context->cache_list_len)) {
209        //    printf("re-alloc because %p %d/%d\n", context->caches_displayed,
210        //     cache_num, context->cache_list_len);
211        g_free(context->caches_displayed);
212        context->caches_displayed = NULL;
213        context->cache_list_len = 0;
214      }
215    
216      /* allocate buffer */
217      if(cache_num && !context->caches_displayed) {
218        context->cache_list_len = cache_num;
219        context->caches_displayed = g_new0(cache_display_t, cache_num+1);
220        printf("allocated space to handle %d map icons\n", cache_num);
221      }
222    
223    if(!context->appdata->cur_gpx && !context->appdata->cur_cache) {    if(!context->appdata->cur_gpx && !context->appdata->cur_cache) {
224      if(context->state != MAP_ALL) {      if(context->state != MAP_ALL) {
225        printf("map_setup(ALL)\n");        printf("map_setup(ALL)\n");
# Line 205  static void map_setup(map_context_t *con Line 231  static void map_setup(map_context_t *con
231    
232        /* clear all existing cache images */        /* clear all existing cache images */
233        osm_gps_map_clear_images (OSM_GPS_MAP(context->widget));        osm_gps_map_clear_images (OSM_GPS_MAP(context->widget));
234          memset(context->caches_displayed, 0,
235                 (cache_num+1) * sizeof(cache_display_t));
236    
237        /* draw all geocaches and none is semi-transparent */        /* draw all geocaches and none is semi-transparent */
238        gpx_t *gpx = context->appdata->gpx;        gpx_t *gpx = context->appdata->gpx;
239        while(gpx) {        while(gpx) {
240          map_draw_gpx(context->appdata, context->widget, gpx, NULL, FALSE);          map_draw_gpx(context->appdata, context->caches_displayed,
241                         context->widget, gpx, NULL, FALSE);
242          gpx = gpx->next;          gpx = gpx->next;
243        }        }
244    
245          {
246            int i=0;
247            while(context->caches_displayed[i].id) i++;
248            printf("number of caches actually displayed: %d\n", i);
249          }
250    
251        name = g_strdup(_("all"));        name = g_strdup(_("all"));
252        context->state = MAP_ALL;        context->state = MAP_ALL;
253      }      }
# Line 226  static void map_setup(map_context_t *con Line 262  static void map_setup(map_context_t *con
262    
263        /* clear all existing ccahe images */        /* clear all existing ccahe images */
264        osm_gps_map_clear_images (OSM_GPS_MAP(context->widget));        osm_gps_map_clear_images (OSM_GPS_MAP(context->widget));
265          memset(context->caches_displayed, 0,
266                 (cache_num+1) * sizeof(cache_display_t));
267    
268        /* draw all geocaches and all other gpx files are semi-transparent */        /* draw all geocaches and all other gpx files are semi-transparent */
269          map_draw_gpx(context->appdata, context->caches_displayed,
270                       context->widget, context->appdata->cur_gpx, NULL, FALSE);
271    
272        gpx_t *gpx = context->appdata->gpx;        gpx_t *gpx = context->appdata->gpx;
273        while(gpx) {        while(gpx) {
274          map_draw_gpx(context->appdata, context->widget, gpx, NULL,          if(gpx != context->appdata->cur_gpx)
275                       gpx != context->appdata->cur_gpx);            map_draw_gpx(context->appdata, context->caches_displayed,
276                           context->widget, gpx, NULL, TRUE);
277    
278          gpx = gpx->next;          gpx = gpx->next;
279        }        }
280    
# Line 241  static void map_setup(map_context_t *con Line 284  static void map_setup(map_context_t *con
284    } else {    } else {
285      cache_t *cache = context->appdata->cur_cache;      cache_t *cache = context->appdata->cur_cache;
286    
287      printf("map_setp(CACHE)\n");      printf("map_setup(CACHE)\n");
288    
289      /* no balloons in this mode */      /* no balloons in this mode */
290      context->balloon = NULL;      context->balloon = NULL;
# Line 249  static void map_setup(map_context_t *con Line 292  static void map_setup(map_context_t *con
292    
293      /* clear all existing ccahe images */      /* clear all existing ccahe images */
294      osm_gps_map_clear_images (OSM_GPS_MAP(context->widget));      osm_gps_map_clear_images (OSM_GPS_MAP(context->widget));
295        memset(context->caches_displayed, 0,
296               (cache_num+1) * sizeof(cache_display_t));
297    
298      /* draw all geocaches and all but selected one are semi-transparent */      /* draw all geocaches and all but selected one are semi-transparent */
299      gpx_t *gpx = context->appdata->gpx;      gpx_t *gpx = context->appdata->gpx;
300      while(gpx) {      while(gpx) {
301        map_draw_gpx(context->appdata, context->widget, gpx, cache, FALSE);        map_draw_gpx(context->appdata, context->caches_displayed,
302                       context->widget, gpx, cache, FALSE);
303        gpx = gpx->next;        gpx = gpx->next;
304      }      }
305    
# Line 432  cairo_draw_pixbuf(cairo_t *cr, GdkPixbuf Line 478  cairo_draw_pixbuf(cairo_t *cr, GdkPixbuf
478                                 gdk_pixbuf_get_height(buf));                                 gdk_pixbuf_get_height(buf));
479    
480    // Create the new Context for the ImageSurface    // Create the new Context for the ImageSurface
481      g_assert(image_surface);
482    cairo_t *context = cairo_create(image_surface);    cairo_t *context = cairo_create(image_surface);
483    
484    // Draw the image on the new Context    // Draw the image on the new Context
# Line 696  static void on_window_destroy(GtkWidget Line 743  static void on_window_destroy(GtkWidget
743    gtk_timeout_remove(context->handler_id);    gtk_timeout_remove(context->handler_id);
744    gps_unregister_callback(appdata, context->cb_id);    gps_unregister_callback(appdata, context->cb_id);
745    
746      if(context->caches_displayed) {
747        g_free(context->caches_displayed);
748        context->caches_displayed = NULL;
749      }
750    
751    g_free(context);    g_free(context);
752    appdata->map.context = NULL;    appdata->map.context = NULL;
753  }  }

Legend:
Removed from v.151  
changed lines
  Added in v.155