88 |
cb_map_gps(osd_button_t but, map_context_t *context) { |
cb_map_gps(osd_button_t but, map_context_t *context) { |
89 |
|
|
90 |
if(but == OSD_GPS) { |
if(but == OSD_GPS) { |
91 |
|
printf("clicked OSD_GPS %p\n", context); |
92 |
|
printf("clicked OSD_GPS a %p\n", context->appdata); |
93 |
|
|
94 |
pos_t *refpos = get_pos(context->appdata); |
pos_t *refpos = get_pos(context->appdata); |
95 |
if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { |
if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { |
96 |
gint zoom; |
gint zoom; |
118 |
|
|
119 |
static gboolean map_gps_update(gpointer data) { |
static gboolean map_gps_update(gpointer data) { |
120 |
map_context_t *context = (map_context_t*)data; |
map_context_t *context = (map_context_t*)data; |
|
static gboolean goto_is_enabled = FALSE; |
|
121 |
|
|
122 |
/* get reference position ... */ |
/* get reference position ... */ |
123 |
pos_t *refpos = get_pos(context->appdata); |
pos_t *refpos = get_pos(context->appdata); |
124 |
gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon); |
gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon); |
125 |
|
|
126 |
/* ... and enable "goto" button if it's valid */ |
/* ... and enable "goto" button if it's valid */ |
127 |
if(ok != goto_is_enabled) { |
if(ok != context->goto_is_enabled) { |
128 |
osm_gps_map_osd_enable_gps (OSM_GPS_MAP(context->widget), |
osm_gps_map_osd_enable_gps (OSM_GPS_MAP(context->widget), |
129 |
OSM_GPS_MAP_OSD_CALLBACK(ok?cb_map_gps:NULL), context); |
OSM_GPS_MAP_OSD_CALLBACK(ok?cb_map_gps:NULL), context); |
130 |
goto_is_enabled = ok; |
context->goto_is_enabled = ok; |
131 |
} |
} |
132 |
|
|
133 |
if(ok) { |
if(ok) { |
182 |
} |
} |
183 |
} |
} |
184 |
|
|
185 |
|
static void map_draw_wpt(GtkWidget *map, cache_t *cache, wpt_t *wpt) { |
186 |
|
/* only draw wpts that don't equal the main point */ |
187 |
|
if(pos_differ(&cache->pos, &wpt->pos)) { |
188 |
|
if(!isnan(wpt->pos.lat) && !isnan(wpt->pos.lon)) { |
189 |
|
GdkPixbuf *icon = |
190 |
|
icon_get(ICON_WPT, (wpt->sym!=WPT_SYM_UNKNOWN)? |
191 |
|
wpt->sym:WPT_SYM_REFPOINT); |
192 |
|
|
193 |
|
osm_gps_map_add_image(OSM_GPS_MAP(map), |
194 |
|
wpt->pos.lat, wpt->pos.lon, icon); |
195 |
|
} |
196 |
|
} |
197 |
|
} |
198 |
|
|
199 |
static void map_draw_gpx(appdata_t *appdata, cache_display_t *caches, |
static void map_draw_gpx(appdata_t *appdata, cache_display_t *caches, |
200 |
GtkWidget *map, gpx_t *gpx, |
GtkWidget *map, gpx_t *gpx, |
201 |
cache_t *nav, gboolean semi) { |
cache_t *nav, gboolean semi) { |
216 |
/* if nav is not given do what semi sais */ |
/* if nav is not given do what semi sais */ |
217 |
map_draw_cache(map, cache, nav?(cache != nav):semi); |
map_draw_cache(map, cache, nav?(cache != nav):semi); |
218 |
caches[i].id = cache->id; |
caches[i].id = cache->id; |
219 |
|
|
220 |
|
/* also draw waypoints of nav cache */ |
221 |
|
if(nav && cache == nav) { |
222 |
|
wpt_t *wpt = cache->wpt; |
223 |
|
while(wpt) { |
224 |
|
map_draw_wpt(map, cache, wpt); |
225 |
|
wpt = wpt->next; |
226 |
|
} |
227 |
|
} |
228 |
} |
} |
229 |
|
|
230 |
cache = cache->next; |
cache = cache->next; |
358 |
#endif |
#endif |
359 |
} |
} |
360 |
|
|
361 |
|
/* also mark geomath position */ |
362 |
|
|
363 |
|
/* remove all existing appearances of this icon first */ |
364 |
|
osm_gps_map_remove_image(OSM_GPS_MAP(context->widget), |
365 |
|
icon_get(ICON_MISC, 6)); |
366 |
|
|
367 |
|
if(!isnan(context->appdata->geomath.lat) && |
368 |
|
!isnan(context->appdata->geomath.lon)) { |
369 |
|
|
370 |
|
osm_gps_map_add_image(OSM_GPS_MAP(context->widget), |
371 |
|
context->appdata->geomath.lat, |
372 |
|
context->appdata->geomath.lon, |
373 |
|
icon_get(ICON_MISC, 6)); |
374 |
|
} |
375 |
|
|
376 |
if(name) { |
if(name) { |
377 |
char *title = g_strdup_printf(_("Map - %s"), name); |
char *title = g_strdup_printf(_("Map - %s"), name); |
378 |
g_free(name); |
g_free(name); |
822 |
context->caches_displayed = NULL; |
context->caches_displayed = NULL; |
823 |
} |
} |
824 |
|
|
825 |
|
printf("destroy map context\n"); |
826 |
g_free(context); |
g_free(context); |
827 |
appdata->map.context = NULL; |
appdata->map.context = NULL; |
828 |
} |
} |
866 |
return FALSE; |
return FALSE; |
867 |
} |
} |
868 |
|
|
|
#ifdef USE_MAEMO |
|
869 |
static gboolean on_focus_out(GtkWidget *widget, GdkEventFocus *event, |
static gboolean on_focus_out(GtkWidget *widget, GdkEventFocus *event, |
870 |
gpointer data) { |
gpointer data) { |
871 |
map_context_t *context = (map_context_t*)data; |
map_context_t *context = (map_context_t*)data; |
872 |
|
|
873 |
printf("map lost focus\n"); |
printf("map lost focus\n"); |
874 |
|
|
875 |
|
/* save new map position */ |
876 |
|
gfloat lat, lon; |
877 |
|
g_object_get(widget, "latitude", &lat, "longitude", &lon, NULL); |
878 |
|
|
879 |
|
context->appdata->map.pos.lat = lat; |
880 |
|
context->appdata->map.pos.lon = lon; |
881 |
|
|
882 |
|
#ifdef USE_MAEMO |
883 |
gtk_timeout_remove(context->handler_id); |
gtk_timeout_remove(context->handler_id); |
884 |
context->handler_id = 0; |
context->handler_id = 0; |
885 |
|
#endif |
886 |
|
|
887 |
return FALSE; |
return FALSE; |
888 |
} |
} |
|
#endif |
|
889 |
|
|
890 |
void map_update(appdata_t *appdata) { |
void map_update(appdata_t *appdata) { |
891 |
printf("map_update\n"); |
printf("map_update\n"); |
913 |
} |
} |
914 |
|
|
915 |
context = appdata->map.context = g_new0(map_context_t, 1); |
context = appdata->map.context = g_new0(map_context_t, 1); |
916 |
|
printf("allocated new context at %p\n", context); |
917 |
|
|
918 |
context->appdata = appdata; |
context->appdata = appdata; |
919 |
context->map_complete = FALSE; |
context->map_complete = FALSE; |
920 |
context->state = MAP_NONE; |
context->state = MAP_NONE; |
982 |
g_signal_connect(G_OBJECT(context->widget), "focus-in-event", |
g_signal_connect(G_OBJECT(context->widget), "focus-in-event", |
983 |
G_CALLBACK(on_focus_in), context); |
G_CALLBACK(on_focus_in), context); |
984 |
|
|
|
#ifdef USE_MAEMO |
|
985 |
g_signal_connect(G_OBJECT(context->widget), "focus-out-event", |
g_signal_connect(G_OBJECT(context->widget), "focus-out-event", |
986 |
G_CALLBACK(on_focus_out), context); |
G_CALLBACK(on_focus_out), context); |
|
#endif |
|
987 |
|
|
988 |
g_signal_connect(G_OBJECT(context->widget), "configure-event", |
g_signal_connect(G_OBJECT(context->widget), "configure-event", |
989 |
G_CALLBACK(on_map_configure), context); |
G_CALLBACK(on_map_configure), context); |