82 |
cairo_surface_t *surface; |
cairo_surface_t *surface; |
83 |
float lat, lon; |
float lat, lon; |
84 |
char *name; |
char *name; |
85 |
|
gboolean imperial; // display distance imperial/metric |
86 |
} nav; |
} nav; |
87 |
#endif |
#endif |
88 |
|
|
266 |
cairo_stroke (cr); |
cairo_stroke (cr); |
267 |
|
|
268 |
if (priv->balloon.cb) { |
if (priv->balloon.cb) { |
269 |
|
osm_gps_map_balloon_event_t event; |
270 |
|
|
271 |
/* clip in case application tries to draw in */ |
/* clip in case application tries to draw in */ |
272 |
/* exceed of the balloon */ |
/* exceed of the balloon */ |
273 |
cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y, |
cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y, |
274 |
priv->balloon.rect.w, priv->balloon.rect.h); |
priv->balloon.rect.w, priv->balloon.rect.h); |
275 |
cairo_clip (cr); |
cairo_clip (cr); |
276 |
cairo_new_path (cr); /* current path is not |
cairo_new_path (cr); /* current path is not consumed by cairo_clip */ |
277 |
consumed by cairo_clip() */ |
|
278 |
|
/* request the application to draw the balloon contents */ |
279 |
|
event.type = OSM_GPS_MAP_BALLOON_EVENT_TYPE_DRAW; |
280 |
|
event.data.draw.rect = &priv->balloon.rect; |
281 |
|
event.data.draw.cr = cr; |
282 |
|
|
283 |
priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data); |
priv->balloon.cb(&event, priv->balloon.data); |
284 |
} |
} |
285 |
|
|
286 |
cairo_destroy(cr); |
cairo_destroy(cr); |
289 |
/* return true if balloon is being displayed and if */ |
/* return true if balloon is being displayed and if */ |
290 |
/* the given coordinate is within this balloon */ |
/* the given coordinate is within this balloon */ |
291 |
static gboolean |
static gboolean |
292 |
osd_balloon_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) |
osd_balloon_check(osm_gps_map_osd_t *osd, gboolean click, gboolean down, gint x, gint y) |
293 |
{ |
{ |
294 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
295 |
|
|
308 |
(x > xs) && (x < xs + priv->balloon.rect.w) && |
(x > xs) && (x < xs + priv->balloon.rect.w) && |
309 |
(y > ys) && (y < ys + priv->balloon.rect.h); |
(y > ys) && (y < ys + priv->balloon.rect.h); |
310 |
|
|
311 |
/* handle the fact that the balloon may have been created by the */ |
/* is this a real click or is the application just checking for something? */ |
312 |
/* button down event */ |
if(click) { |
313 |
if(!is_in && !down && !priv->balloon.just_created) { |
|
314 |
/* the user actually clicked outside the balloon */ |
/* handle the fact that the balloon may have been created by the */ |
315 |
|
/* button down event */ |
316 |
|
if(!is_in && !down && !priv->balloon.just_created) { |
317 |
|
/* the user actually clicked outside the balloon */ |
318 |
|
|
319 |
|
/* close the balloon! */ |
320 |
|
osm_gps_map_osd_clear_balloon (OSM_GPS_MAP(osd->widget)); |
321 |
|
|
322 |
|
/* and inform application about this */ |
323 |
|
if(priv->balloon.cb) { |
324 |
|
osm_gps_map_balloon_event_t event; |
325 |
|
event.type = OSM_GPS_MAP_BALLOON_EVENT_TYPE_REMOVED; |
326 |
|
priv->balloon.cb(&event, priv->balloon.data); |
327 |
|
} |
328 |
|
|
329 |
/* close the balloon! */ |
} |
330 |
osm_gps_map_osd_clear_balloon (OSM_GPS_MAP(osd->widget)); |
|
331 |
|
if(is_in && priv->balloon.cb) { |
332 |
|
osm_gps_map_balloon_event_t event; |
333 |
|
|
334 |
|
/* notify application of click */ |
335 |
|
event.type = OSM_GPS_MAP_BALLOON_EVENT_TYPE_CLICK; |
336 |
|
event.data.click.x = x - xs; |
337 |
|
event.data.click.y = y - ys; |
338 |
|
event.data.click.down = down; |
339 |
|
|
340 |
|
priv->balloon.cb(&event, priv->balloon.data); |
341 |
|
} |
342 |
} |
} |
343 |
|
|
344 |
return is_in; |
return is_in; |
975 |
#endif // OSD_SOURCE_SEL |
#endif // OSD_SOURCE_SEL |
976 |
|
|
977 |
static osd_button_t |
static osd_button_t |
978 |
osd_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) { |
osd_check_int(osm_gps_map_osd_t *osd, gboolean click, gboolean down, gint x, gint y) { |
979 |
osd_button_t but = OSD_NONE; |
osd_button_t but = OSD_NONE; |
980 |
|
|
981 |
#ifdef OSD_BALLOON |
#ifdef OSD_BALLOON |
1016 |
#ifdef OSD_BALLOON |
#ifdef OSD_BALLOON |
1017 |
if(but == OSD_NONE) { |
if(but == OSD_NONE) { |
1018 |
/* check if user clicked into balloon */ |
/* check if user clicked into balloon */ |
1019 |
if(osd_balloon_check(osd, down, x, y)) |
if(osd_balloon_check(osd, click, down, x, y)) |
1020 |
but = OSD_BG; |
but = OSD_BG; |
1021 |
} |
} |
1022 |
#endif |
#endif |
1240 |
|
|
1241 |
#ifdef OSD_NAV |
#ifdef OSD_NAV |
1242 |
#define OSD_NAV_W (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET) |
#define OSD_NAV_W (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET) |
1243 |
#define OSD_NAV_H (150) |
#define OSD_NAV_H (11*OSD_COORDINATES_FONT_SIZE) |
1244 |
|
|
1245 |
|
/* http://mathforum.org/library/drmath/view/55417.html */ |
1246 |
|
static float get_bearing(float lat1, float lon1, float lat2, float lon2) { |
1247 |
|
return atan2( sin(lon2 - lon1) * cos(lat2), |
1248 |
|
cos(lat1) * sin(lat2) - |
1249 |
|
sin(lat1) * cos(lat2) * cos(lon2 - lon1)); |
1250 |
|
} |
1251 |
|
|
1252 |
|
/* http://mathforum.org/library/drmath/view/51722.html */ |
1253 |
|
static float get_distance(float lat1, float lon1, float lat2, float lon2) { |
1254 |
|
float aob = acos(cos(lat1) * cos(lat2) * cos(lon2 - lon1) + |
1255 |
|
sin(lat1) * sin(lat2)); |
1256 |
|
|
1257 |
|
// return(aob * 3959.0); /* great circle radius in miles */ |
1258 |
|
|
1259 |
|
return(aob * 6371000.0); /* great circle radius in meters */ |
1260 |
|
} |
1261 |
|
|
1262 |
static void |
static void |
1263 |
osd_render_nav(osm_gps_map_osd_t *osd) |
osd_render_nav(osm_gps_map_osd_t *osd) |
1270 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1271 |
cairo_t *cr = cairo_create(priv->nav.surface); |
cairo_t *cr = cairo_create(priv->nav.surface); |
1272 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1273 |
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2); |
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
1274 |
cairo_paint(cr); |
cairo_paint(cr); |
1275 |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
1276 |
|
|
1312 |
#define ARROW_WIDTH 0.3 |
#define ARROW_WIDTH 0.3 |
1313 |
#define ARROW_LENGTH 0.7 |
#define ARROW_LENGTH 0.7 |
1314 |
|
|
1315 |
float arot = deg2rad(45); |
coord_t *gps = osm_gps_map_get_gps (OSM_GPS_MAP(osd->widget)); |
1316 |
|
if(gps) { |
1317 |
cairo_move_to(cr, |
float arot = get_bearing(gps->rlat, gps->rlon, |
1318 |
x + radius * ARROW_LENGTH * sin(arot), |
deg2rad(priv->nav.lat), deg2rad(priv->nav.lon)); |
1319 |
y + radius * ARROW_LENGTH * -cos(arot)); |
|
1320 |
|
cairo_move_to(cr, |
1321 |
cairo_line_to(cr, |
x + radius * ARROW_LENGTH * sin(arot), |
1322 |
x + radius * -ARROW_LENGTH * sin(arot+ARROW_WIDTH), |
y + radius * ARROW_LENGTH * -cos(arot)); |
1323 |
y + radius * -ARROW_LENGTH * -cos(arot+ARROW_WIDTH)); |
|
1324 |
|
cairo_line_to(cr, |
1325 |
cairo_line_to(cr, |
x + radius * -ARROW_LENGTH * sin(arot+ARROW_WIDTH), |
1326 |
x + radius * -0.5 * ARROW_LENGTH * sin(arot), |
y + radius * -ARROW_LENGTH * -cos(arot+ARROW_WIDTH)); |
1327 |
y + radius * -0.5 * ARROW_LENGTH * -cos(arot)); |
|
1328 |
|
cairo_line_to(cr, |
1329 |
cairo_line_to(cr, |
x + radius * -0.5 * ARROW_LENGTH * sin(arot), |
1330 |
x + radius * -ARROW_LENGTH * sin(arot-ARROW_WIDTH), |
y + radius * -0.5 * ARROW_LENGTH * -cos(arot)); |
1331 |
y + radius * -ARROW_LENGTH * -cos(arot-ARROW_WIDTH)); |
|
1332 |
|
cairo_line_to(cr, |
1333 |
cairo_close_path(cr); |
x + radius * -ARROW_LENGTH * sin(arot-ARROW_WIDTH), |
1334 |
cairo_set_source_rgb (cr, 0, 0, 0); |
y + radius * -ARROW_LENGTH * -cos(arot-ARROW_WIDTH)); |
1335 |
cairo_fill (cr); |
|
1336 |
|
cairo_close_path(cr); |
1337 |
|
cairo_set_source_rgb (cr, 0, 0, 0); |
1338 |
|
cairo_fill (cr); |
1339 |
|
|
1340 |
|
y += radius + OSD_COORDINATES_FONT_SIZE/4; |
1341 |
|
|
1342 |
|
float dist = get_distance(gps->rlat, gps->rlon, |
1343 |
|
deg2rad(priv->nav.lat), deg2rad(priv->nav.lon)); |
1344 |
|
|
1345 |
|
char *dist_str = NULL; |
1346 |
|
if(!priv->nav.imperial) { |
1347 |
|
/* metric is easy ... */ |
1348 |
|
if(dist<1000) |
1349 |
|
dist_str = g_strdup_printf("%u m", (int)dist); |
1350 |
|
else |
1351 |
|
dist_str = g_strdup_printf("%.1f km", dist/1000); |
1352 |
|
} else { |
1353 |
|
/* and now the hard part: scale for useful imperial values :-( */ |
1354 |
|
/* try to convert to feet, 1ft == 0.3048 m */ |
1355 |
|
|
1356 |
y += radius + OSD_COORDINATES_FONT_SIZE/4; |
if(dist/(3*0.3048) >= 1760.0) /* more than 1760 yard? */ |
1357 |
y = osd_render_centered_text(cr, y, OSD_NAV_W, "xx,xx km"); |
dist_str = g_strdup_printf("%.1f mi", dist/(0.3048*3*1760.0)); |
1358 |
|
else if(dist/0.3048 >= 100) /* more than 100 feet? */ |
1359 |
|
dist_str = g_strdup_printf("%.1f yd", dist/(0.3048*3)); |
1360 |
|
else |
1361 |
|
dist_str = g_strdup_printf("%.0f ft", dist/0.3048); |
1362 |
|
} |
1363 |
|
|
1364 |
|
y = osd_render_centered_text(cr, y, OSD_NAV_W, dist_str); |
1365 |
|
g_free(dist_str); |
1366 |
|
} |
1367 |
|
|
1368 |
cairo_destroy(cr); |
cairo_destroy(cr); |
1369 |
} |
} |
1388 |
} |
} |
1389 |
|
|
1390 |
void |
void |
1391 |
osm_gps_map_osd_draw_nav (OsmGpsMap *map, float latitude, float longitude, |
osm_gps_map_osd_draw_nav (OsmGpsMap *map, gboolean imperial, |
1392 |
char *name) { |
float latitude, float longitude, char *name) { |
1393 |
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
1394 |
|
|
1395 |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
1408 |
priv->nav.lat = latitude; |
priv->nav.lat = latitude; |
1409 |
priv->nav.lon = longitude; |
priv->nav.lon = longitude; |
1410 |
priv->nav.name = g_strdup(name); |
priv->nav.name = g_strdup(name); |
1411 |
|
priv->nav.imperial = imperial; |
1412 |
|
|
1413 |
osd_render_nav(osd); |
osd_render_nav(osd); |
1414 |
|
|
1959 |
#endif |
#endif |
1960 |
} |
} |
1961 |
|
|
1962 |
|
static osd_button_t |
1963 |
|
osd_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) { |
1964 |
|
return osd_check_int(osd, TRUE, down, x, y); |
1965 |
|
} |
1966 |
|
|
1967 |
static osm_gps_map_osd_t osd_classic = { |
static osm_gps_map_osd_t osd_classic = { |
1968 |
.widget = NULL, |
.widget = NULL, |
1969 |
|
|
2019 |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
2020 |
g_return_val_if_fail (osd, OSD_NONE); |
g_return_val_if_fail (osd, OSD_NONE); |
2021 |
|
|
2022 |
return osd_check(osd, TRUE, x, y); |
return osd_check_int(osd, FALSE, TRUE, x, y); |
2023 |
} |
} |