19 |
|
|
20 |
#include "config.h" |
#include "config.h" |
21 |
#include <stdlib.h> // abs |
#include <stdlib.h> // abs |
22 |
|
#include <string.h> |
23 |
#include <math.h> // M_PI/cos() |
#include <math.h> // M_PI/cos() |
24 |
|
|
25 |
/* parameters that can be overwritten from the config file: */ |
/* parameters that can be overwritten from the config file: */ |
77 |
} crosshair; |
} crosshair; |
78 |
#endif |
#endif |
79 |
|
|
80 |
|
#ifdef OSD_NAV |
81 |
|
struct { |
82 |
|
cairo_surface_t *surface; |
83 |
|
float lat, lon; |
84 |
|
char *name; |
85 |
|
} nav; |
86 |
|
#endif |
87 |
|
|
88 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
89 |
struct { |
struct { |
90 |
cairo_surface_t *surface; |
cairo_surface_t *surface; |
297 |
xs += priv->balloon.rect.x + priv->balloon.offset_x; |
xs += priv->balloon.rect.x + priv->balloon.offset_x; |
298 |
ys += priv->balloon.rect.y + priv->balloon.offset_y; |
ys += priv->balloon.rect.y + priv->balloon.offset_y; |
299 |
|
|
|
/* handle the fact that the balloon may have been created by the */ |
|
|
/* button down event */ |
|
|
|
|
300 |
gboolean is_in = |
gboolean is_in = |
301 |
(x > xs) && (x < xs + priv->balloon.rect.w) && |
(x > xs) && (x < xs + priv->balloon.rect.w) && |
302 |
(y > ys) && (y < ys + priv->balloon.rect.h); |
(y > ys) && (y < ys + priv->balloon.rect.h); |
303 |
|
|
304 |
|
/* handle the fact that the balloon may have been created by the */ |
305 |
|
/* button down event */ |
306 |
if(!is_in && !down && !priv->balloon.just_created) { |
if(!is_in && !down && !priv->balloon.just_created) { |
307 |
/* the user actually clicked outside the balloon */ |
/* the user actually clicked outside the balloon */ |
308 |
|
|
961 |
#endif |
#endif |
962 |
|
|
963 |
if(but == OSD_NONE) { |
if(but == OSD_NONE) { |
964 |
x -= OSD_X; |
gint mx = x - OSD_X; |
965 |
y -= OSD_Y; |
gint my = y - OSD_Y; |
966 |
|
|
967 |
if(OSD_X < 0) |
if(OSD_X < 0) |
968 |
x -= (osd->widget->allocation.width - OSD_W); |
mx -= (osd->widget->allocation.width - OSD_W); |
969 |
|
|
970 |
if(OSD_Y < 0) |
if(OSD_Y < 0) |
971 |
y -= (osd->widget->allocation.height - OSD_H); |
my -= (osd->widget->allocation.height - OSD_H); |
972 |
|
|
973 |
/* first do a rough test for the OSD area. */ |
/* first do a rough test for the OSD area. */ |
974 |
/* this is just to avoid an unnecessary detailed test */ |
/* this is just to avoid an unnecessary detailed test */ |
975 |
if(x > 0 && x < OSD_W && y > 0 && y < OSD_H) { |
if(mx > 0 && mx < OSD_W && my > 0 && my < OSD_H) { |
976 |
#ifndef OSD_NO_DPAD |
#ifndef OSD_NO_DPAD |
977 |
but = osd_check_dpad(x, y); |
but = osd_check_dpad(mx, my); |
978 |
#endif |
#endif |
979 |
} |
} |
980 |
|
|
981 |
if(but == OSD_NONE) |
if(but == OSD_NONE) |
982 |
but = osd_check_zoom(x, y); |
but = osd_check_zoom(mx, my); |
983 |
} |
} |
984 |
|
|
985 |
#ifdef OSD_BALLOON |
#ifdef OSD_BALLOON |
1072 |
#define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6) |
#define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6) |
1073 |
|
|
1074 |
#define OSD_COORDINATES_W (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET) |
#define OSD_COORDINATES_W (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET) |
1075 |
#define OSD_COORDINATES_H (2*OSD_COORDINATES_FONT_SIZE+OSD_COORDINATES_OFFSET) |
#define OSD_COORDINATES_H (2*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET+OSD_COORDINATES_FONT_SIZE/4) |
1076 |
|
|
1077 |
/* these can be overwritten with versions that support */ |
/* these can be overwritten with versions that support */ |
1078 |
/* localization */ |
/* localization */ |
1130 |
c, (int)integral, fractional*60.0); |
c, (int)integral, fractional*60.0); |
1131 |
} |
} |
1132 |
|
|
1133 |
|
/* render a string at the given screen position */ |
1134 |
|
static int |
1135 |
|
osd_render_centered_text(cairo_t *cr, int y, int width, char *text) { |
1136 |
|
char *p = g_strdup(text); |
1137 |
|
cairo_text_extents_t extents; |
1138 |
|
cairo_text_extents (cr, p, &extents); |
1139 |
|
|
1140 |
|
/* check if text needs to be truncated */ |
1141 |
|
int len = strlen(text)-2; |
1142 |
|
while(extents.width > width) { |
1143 |
|
len--; |
1144 |
|
strcpy(p+len, "..."); |
1145 |
|
cairo_text_extents (cr, p, &extents); |
1146 |
|
} |
1147 |
|
|
1148 |
|
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); |
1149 |
|
cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6); |
1150 |
|
cairo_move_to (cr, (width - extents.width)/2, y - extents.y_bearing); |
1151 |
|
cairo_text_path (cr, p); |
1152 |
|
cairo_stroke (cr); |
1153 |
|
|
1154 |
|
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); |
1155 |
|
cairo_move_to (cr, (width - extents.width)/2, y - extents.y_bearing); |
1156 |
|
cairo_show_text (cr, p); |
1157 |
|
|
1158 |
|
g_free(p); |
1159 |
|
|
1160 |
|
/* skip + 1/4 line */ |
1161 |
|
return y + 5*OSD_COORDINATES_FONT_SIZE/4; |
1162 |
|
} |
1163 |
|
|
1164 |
static void |
static void |
1165 |
osd_render_coordinates(osm_gps_map_osd_t *osd) |
osd_render_coordinates(osm_gps_map_osd_t *osd) |
1166 |
{ |
{ |
1196 |
char *latitude = osd_latitude_str(lat); |
char *latitude = osd_latitude_str(lat); |
1197 |
char *longitude = osd_longitude_str(lon); |
char *longitude = osd_longitude_str(lon); |
1198 |
|
|
1199 |
cairo_text_extents_t lat_extents, lon_extents; |
int y = OSD_COORDINATES_OFFSET; |
1200 |
cairo_text_extents (cr, latitude, &lat_extents); |
y = osd_render_centered_text(cr, y, OSD_COORDINATES_W, latitude); |
1201 |
cairo_text_extents (cr, longitude, &lon_extents); |
y = osd_render_centered_text(cr, y, OSD_COORDINATES_W, longitude); |
1202 |
|
|
1203 |
|
g_free(latitude); |
1204 |
|
g_free(longitude); |
1205 |
|
|
1206 |
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); |
cairo_destroy(cr); |
1207 |
cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6); |
} |
1208 |
cairo_move_to (cr, |
#endif // OSD_COORDINATES |
|
(OSD_COORDINATES_W - lat_extents.width)/2, |
|
|
OSD_COORDINATES_OFFSET - lat_extents.y_bearing); |
|
|
cairo_text_path (cr, latitude); |
|
|
cairo_move_to (cr, |
|
|
(OSD_COORDINATES_W - lon_extents.width)/2, |
|
|
OSD_COORDINATES_OFFSET - lon_extents.y_bearing + |
|
|
OSD_COORDINATES_FONT_SIZE); |
|
|
cairo_text_path (cr, longitude); |
|
|
cairo_stroke (cr); |
|
1209 |
|
|
1210 |
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); |
#ifdef OSD_NAV |
1211 |
cairo_move_to (cr, |
#define OSD_NAV_W (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET) |
1212 |
(OSD_COORDINATES_W - lat_extents.width)/2, |
#define OSD_NAV_H (150) |
1213 |
OSD_COORDINATES_OFFSET - lat_extents.y_bearing); |
|
1214 |
cairo_show_text (cr, latitude); |
static void |
1215 |
cairo_move_to (cr, |
osd_render_nav(osm_gps_map_osd_t *osd) |
1216 |
(OSD_COORDINATES_W - lon_extents.width)/2, |
{ |
1217 |
OSD_COORDINATES_OFFSET - lon_extents.y_bearing + |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
|
OSD_COORDINATES_FONT_SIZE); |
|
|
cairo_show_text (cr, longitude); |
|
1218 |
|
|
1219 |
|
if(!priv->nav.surface || isnan(priv->nav.lat) || isnan(priv->nav.lon)) |
1220 |
|
return; |
1221 |
|
|
1222 |
|
/* first fill with transparency */ |
1223 |
|
cairo_t *cr = cairo_create(priv->nav.surface); |
1224 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1225 |
|
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2); |
1226 |
|
cairo_paint(cr); |
1227 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
1228 |
|
|
1229 |
|
cairo_select_font_face (cr, "Sans", |
1230 |
|
CAIRO_FONT_SLANT_NORMAL, |
1231 |
|
CAIRO_FONT_WEIGHT_BOLD); |
1232 |
|
cairo_set_font_size (cr, OSD_COORDINATES_FONT_SIZE); |
1233 |
|
|
1234 |
|
char *latitude = osd_latitude_str(priv->nav.lat); |
1235 |
|
char *longitude = osd_longitude_str(priv->nav.lon); |
1236 |
|
|
1237 |
|
int y = OSD_COORDINATES_OFFSET; |
1238 |
|
y = osd_render_centered_text(cr, y, OSD_NAV_W, priv->nav.name); |
1239 |
|
y = osd_render_centered_text(cr, y, OSD_NAV_W, latitude); |
1240 |
|
y = osd_render_centered_text(cr, y, OSD_NAV_W, longitude); |
1241 |
|
|
1242 |
g_free(latitude); |
g_free(latitude); |
1243 |
g_free(longitude); |
g_free(longitude); |
1244 |
|
|
1245 |
|
/* draw the compass */ |
1246 |
|
int radius = (OSD_NAV_H - y - 5*OSD_COORDINATES_FONT_SIZE/4)/2; |
1247 |
|
if(radius > OSD_NAV_W/2) |
1248 |
|
radius = OSD_NAV_W/2; |
1249 |
|
|
1250 |
|
int x = OSD_NAV_W/2+1; |
1251 |
|
y += radius; |
1252 |
|
|
1253 |
|
cairo_stroke (cr); |
1254 |
|
|
1255 |
|
/* draw background */ |
1256 |
|
cairo_arc(cr, x, y, radius, 0, 2*M_PI); |
1257 |
|
cairo_set_source_rgba (cr, 1, 1, 1, 0.5); |
1258 |
|
cairo_fill_preserve (cr); |
1259 |
|
cairo_set_source_rgb (cr, 0, 0, 0); |
1260 |
|
cairo_set_line_width (cr, 1); |
1261 |
|
cairo_stroke (cr); |
1262 |
|
|
1263 |
|
/* draw pointer */ |
1264 |
|
#define ARROW_WIDTH 0.3 |
1265 |
|
#define ARROW_LENGTH 0.7 |
1266 |
|
|
1267 |
|
float arot = deg2rad(45); |
1268 |
|
|
1269 |
|
cairo_move_to(cr, |
1270 |
|
x + radius * ARROW_LENGTH * sin(arot), |
1271 |
|
y + radius * ARROW_LENGTH * -cos(arot)); |
1272 |
|
|
1273 |
|
cairo_line_to(cr, |
1274 |
|
x + radius * -ARROW_LENGTH * sin(arot+ARROW_WIDTH), |
1275 |
|
y + radius * -ARROW_LENGTH * -cos(arot+ARROW_WIDTH)); |
1276 |
|
|
1277 |
|
cairo_line_to(cr, |
1278 |
|
x + radius * -0.5 * ARROW_LENGTH * sin(arot), |
1279 |
|
y + radius * -0.5 * ARROW_LENGTH * -cos(arot)); |
1280 |
|
|
1281 |
|
cairo_line_to(cr, |
1282 |
|
x + radius * -ARROW_LENGTH * sin(arot-ARROW_WIDTH), |
1283 |
|
y + radius * -ARROW_LENGTH * -cos(arot-ARROW_WIDTH)); |
1284 |
|
|
1285 |
|
cairo_close_path(cr); |
1286 |
|
cairo_set_source_rgb (cr, 0, 0, 0); |
1287 |
|
cairo_fill (cr); |
1288 |
|
|
1289 |
|
y += radius + OSD_COORDINATES_FONT_SIZE/4; |
1290 |
|
y = osd_render_centered_text(cr, y, OSD_NAV_W, "xx,xx km"); |
1291 |
|
|
1292 |
cairo_destroy(cr); |
cairo_destroy(cr); |
1293 |
} |
} |
1294 |
#endif // OSD_COORDINATES |
|
1295 |
|
void osm_gps_map_osd_clear_nav (OsmGpsMap *map) { |
1296 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
1297 |
|
|
1298 |
|
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
1299 |
|
g_return_if_fail (osd); |
1300 |
|
|
1301 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1302 |
|
g_return_if_fail (priv); |
1303 |
|
|
1304 |
|
if(priv->nav.surface) { |
1305 |
|
cairo_surface_destroy(priv->nav.surface); |
1306 |
|
priv->nav.surface = NULL; |
1307 |
|
priv->nav.lat = OSM_GPS_MAP_INVALID; |
1308 |
|
priv->nav.lon = OSM_GPS_MAP_INVALID; |
1309 |
|
if(priv->nav.name) g_free(priv->nav.name); |
1310 |
|
} |
1311 |
|
osm_gps_map_redraw(map); |
1312 |
|
} |
1313 |
|
|
1314 |
|
void |
1315 |
|
osm_gps_map_osd_draw_nav (OsmGpsMap *map, float latitude, float longitude, |
1316 |
|
char *name) { |
1317 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
1318 |
|
|
1319 |
|
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
1320 |
|
g_return_if_fail (osd); |
1321 |
|
|
1322 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1323 |
|
g_return_if_fail (priv); |
1324 |
|
|
1325 |
|
osm_gps_map_osd_clear_nav (map); |
1326 |
|
|
1327 |
|
/* allocate balloon surface */ |
1328 |
|
priv->nav.surface = |
1329 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1330 |
|
OSD_NAV_W+2, OSD_NAV_H+2); |
1331 |
|
|
1332 |
|
priv->nav.lat = latitude; |
1333 |
|
priv->nav.lon = longitude; |
1334 |
|
priv->nav.name = g_strdup(name); |
1335 |
|
|
1336 |
|
osd_render_nav(osd); |
1337 |
|
|
1338 |
|
osm_gps_map_redraw(map); |
1339 |
|
} |
1340 |
|
|
1341 |
|
#endif // OSD_NAV |
1342 |
|
|
1343 |
|
|
1344 |
#ifdef OSD_CROSSHAIR |
#ifdef OSD_CROSSHAIR |
1345 |
|
|
1668 |
osd_render_crosshair(osd); |
osd_render_crosshair(osd); |
1669 |
#endif |
#endif |
1670 |
|
|
1671 |
|
#ifdef OSD_NAV |
1672 |
|
osd_render_nav(osd); |
1673 |
|
#endif |
1674 |
|
|
1675 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
1676 |
osd_render_coordinates(osd); |
osd_render_coordinates(osd); |
1677 |
#endif |
#endif |
1751 |
cairo_paint(cr); |
cairo_paint(cr); |
1752 |
#endif |
#endif |
1753 |
|
|
1754 |
|
#ifdef OSD_NAV |
1755 |
|
if(priv->nav.surface) { |
1756 |
|
x = OSD_X; |
1757 |
|
if(x < 0) x += osd->widget->allocation.width - OSD_NAV_W; |
1758 |
|
y = (osd->widget->allocation.height - OSD_NAV_H)/2; |
1759 |
|
|
1760 |
|
cairo_set_source_surface(cr, priv->nav.surface, x, y); |
1761 |
|
cairo_paint(cr); |
1762 |
|
} |
1763 |
|
#endif |
1764 |
|
|
1765 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
1766 |
x = -OSD_X; |
x = -OSD_X; |
1767 |
y = -OSD_Y; |
y = -OSD_Y; |
1853 |
cairo_surface_destroy(priv->crosshair.surface); |
cairo_surface_destroy(priv->crosshair.surface); |
1854 |
#endif |
#endif |
1855 |
|
|
1856 |
|
#ifdef OSD_NAV |
1857 |
|
if (priv->nav.surface) |
1858 |
|
cairo_surface_destroy(priv->nav.surface); |
1859 |
|
#endif |
1860 |
|
|
1861 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
1862 |
if (priv->coordinates.surface) |
if (priv->coordinates.surface) |
1863 |
cairo_surface_destroy(priv->coordinates.surface); |
cairo_surface_destroy(priv->coordinates.surface); |