22 |
* http://topo.geofabrik.de/trail/${z}/${x}/${y}.png 8-15 |
* http://topo.geofabrik.de/trail/${z}/${x}/${y}.png 8-15 |
23 |
*/ |
*/ |
24 |
|
|
25 |
|
/* |
26 |
|
* TODO: |
27 |
|
* - draw caches only once |
28 |
|
* - prefer duplicates from selected files |
29 |
|
* - make semi-transparent caches selectable |
30 |
|
*/ |
31 |
|
|
32 |
#include "gpxview.h" |
#include "gpxview.h" |
33 |
#include "converter.h" |
#include "converter.h" |
34 |
#include <math.h> // for isnan |
#include <math.h> // for isnan |
153 |
return TRUE; |
return TRUE; |
154 |
} |
} |
155 |
|
|
156 |
static void map_draw_cache(GtkWidget *map, cache_t *cache) { |
static void map_draw_cache(GtkWidget *map, cache_t *cache, gboolean semi) { |
157 |
GdkPixbuf *icon = icon_get(ICON_CACHE_TYPE, cache->type); |
GdkPixbuf *icon = icon_get(semi?ICON_CACHE_TYPE_SEMI:ICON_CACHE_TYPE, |
158 |
|
cache->type); |
159 |
|
|
160 |
/* check if there's also an overwritten coordinate */ |
/* check if there's also an overwritten coordinate */ |
161 |
if(cache->notes && cache->notes->override) { |
if(cache->notes && cache->notes->override) { |
173 |
} |
} |
174 |
} |
} |
175 |
|
|
176 |
static void map_draw_gpx(appdata_t *appdata, GtkWidget *map, gpx_t *gpx) { |
static void map_draw_gpx(appdata_t *appdata, cache_display_t *caches, |
177 |
|
GtkWidget *map, gpx_t *gpx, |
178 |
|
cache_t *nav, gboolean semi) { |
179 |
if(!gpx->notes_loaded) { |
if(!gpx->notes_loaded) { |
180 |
notes_load_all(appdata, gpx); |
notes_load_all(appdata, gpx); |
181 |
gpx->notes_loaded = TRUE; |
gpx->notes_loaded = TRUE; |
183 |
|
|
184 |
cache_t *cache = gpx->cache; |
cache_t *cache = gpx->cache; |
185 |
while(cache) { |
while(cache) { |
186 |
map_draw_cache(map, cache); |
/* search if we have that cache already in our list/displayed */ |
187 |
|
int i=0; |
188 |
|
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 |
} |
} |
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"); |
229 |
osm_gps_map_osd_clear_nav (OSM_GPS_MAP(context->widget)); |
osm_gps_map_osd_clear_nav (OSM_GPS_MAP(context->widget)); |
230 |
#endif |
#endif |
231 |
|
|
232 |
/* clear all existing ccahe 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 */ |
/* 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); |
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 |
} |
} |
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 */ |
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; |
273 |
|
while(gpx) { |
274 |
|
if(gpx != context->appdata->cur_gpx) |
275 |
|
map_draw_gpx(context->appdata, context->caches_displayed, |
276 |
|
context->widget, gpx, NULL, TRUE); |
277 |
|
|
278 |
|
gpx = gpx->next; |
279 |
|
} |
280 |
|
|
|
map_draw_gpx(context->appdata, context->widget, |
|
|
context->appdata->cur_gpx); |
|
281 |
name = g_strdup(context->appdata->cur_gpx->name); |
name = g_strdup(context->appdata->cur_gpx->name); |
282 |
context->state = MAP_GPX; |
context->state = MAP_GPX; |
283 |
} |
} |
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; |
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 |
map_draw_cache(context->widget, cache); |
/* draw all geocaches and all but selected one are semi-transparent */ |
299 |
|
gpx_t *gpx = context->appdata->gpx; |
300 |
|
while(gpx) { |
301 |
|
map_draw_gpx(context->appdata, context->caches_displayed, |
302 |
|
context->widget, gpx, cache, FALSE); |
303 |
|
gpx = gpx->next; |
304 |
|
} |
305 |
|
|
306 |
name = g_strdup(cache->name); |
name = g_strdup(cache->name); |
307 |
context->state = MAP_CACHE; |
context->state = MAP_CACHE; |
308 |
|
|
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 |
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 |
} |
} |