135 |
|
|
136 |
#define CLOSE_BUTTON_RADIUS (BALLOON_CORNER_RADIUS) |
#define CLOSE_BUTTON_RADIUS (BALLOON_CORNER_RADIUS) |
137 |
|
|
138 |
|
#if 0 |
139 |
#define FIN printf("entering function %s\n", __func__); |
#define FIN printf("entering function %s\n", __func__); |
140 |
#define FOUT printf("leaving function %s\n", __func__); |
#define FOUT printf("leaving function %s\n", __func__); |
141 |
|
#else |
142 |
|
#define FIN ; |
143 |
|
#define FOUT ; |
144 |
|
#endif |
145 |
|
|
146 |
/* draw the bubble shape. this is used twice, once for the shape and once */ |
/* draw the bubble shape. this is used twice, once for the shape and once */ |
147 |
/* for the shadow */ |
/* for the shadow */ |
189 |
|
|
190 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
191 |
|
|
192 |
|
if(!priv->balloon.surface) |
193 |
|
return; |
194 |
|
|
195 |
/* get zoom */ |
/* get zoom */ |
196 |
gint zoom; |
gint zoom; |
197 |
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
252 |
priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER; |
priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER; |
253 |
priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER; |
priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER; |
254 |
|
|
255 |
|
g_assert(priv->balloon.surface); |
256 |
cairo_t *cr = cairo_create(priv->balloon.surface); |
cairo_t *cr = cairo_create(priv->balloon.surface); |
257 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
258 |
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); |
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); |
652 |
/* internal value to draw the arrow on the "puller" */ |
/* internal value to draw the arrow on the "puller" */ |
653 |
#define OSD_S_D0 (OSD_S_RAD/2) |
#define OSD_S_D0 (OSD_S_RAD/2) |
654 |
#ifndef OSD_FONT_SIZE |
#ifndef OSD_FONT_SIZE |
655 |
#define OSD_FONT_SIZE 16.0 |
#define OSD_FONT_SIZE (16.0) |
656 |
#endif |
#endif |
657 |
#define OSD_TEXT_BORDER (OSD_FONT_SIZE/2) |
#define OSD_TEXT_BORDER (OSD_FONT_SIZE/2) |
658 |
#define OSD_TEXT_SKIP (OSD_FONT_SIZE/8) |
#define OSD_TEXT_SKIP (OSD_FONT_SIZE/8) |
764 |
|
|
765 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
766 |
|
|
767 |
if(priv->source_sel.rendered && !force_rerender) |
if(!priv->source_sel.surface || |
768 |
|
(priv->source_sel.rendered && !force_rerender)) |
769 |
return; |
return; |
770 |
|
|
771 |
priv->source_sel.rendered = TRUE; |
priv->source_sel.rendered = TRUE; |
777 |
#endif |
#endif |
778 |
|
|
779 |
/* draw source selector */ |
/* draw source selector */ |
780 |
|
g_assert(priv->source_sel.surface); |
781 |
cairo_t *cr = cairo_create(priv->source_sel.surface); |
cairo_t *cr = cairo_create(priv->source_sel.surface); |
782 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
783 |
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
828 |
cairo_text_extents_t extents; |
cairo_text_extents_t extents; |
829 |
|
|
830 |
/* determine content size */ |
/* determine content size */ |
831 |
|
g_assert(priv->source_sel.surface); |
832 |
cairo_t *cr = cairo_create(priv->source_sel.surface); |
cairo_t *cr = cairo_create(priv->source_sel.surface); |
833 |
cairo_select_font_face (cr, "Sans", |
cairo_select_font_face (cr, "Sans", |
834 |
CAIRO_FONT_SLANT_NORMAL, |
CAIRO_FONT_SLANT_NORMAL, |
1015 |
} |
} |
1016 |
#endif // OSD_SOURCE_SEL |
#endif // OSD_SOURCE_SEL |
1017 |
|
|
|
static osd_button_t |
|
|
osd_check_int(osm_gps_map_osd_t *osd, gboolean click, gboolean down, gint x, gint y) { |
|
|
FIN; |
|
|
osd_button_t but = OSD_NONE; |
|
|
|
|
|
#ifdef OSD_BALLOON |
|
|
if(down) { |
|
|
/* needed to handle balloons that are created at click */ |
|
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
|
|
priv->balloon.just_created = FALSE; |
|
|
} |
|
|
#endif |
|
|
|
|
|
#ifdef OSD_SOURCE_SEL |
|
|
/* the source selection area is handles internally */ |
|
|
but = osd_source_check(osd, down, x, y); |
|
|
#endif |
|
|
|
|
|
if(but == OSD_NONE) { |
|
|
gint mx = x - OSD_X; |
|
|
gint my = y - OSD_Y; |
|
|
|
|
|
if(OSD_X < 0) |
|
|
mx -= (osd->widget->allocation.width - OSD_W); |
|
|
|
|
|
if(OSD_Y < 0) |
|
|
my -= (osd->widget->allocation.height - OSD_H); |
|
|
|
|
|
/* first do a rough test for the OSD area. */ |
|
|
/* this is just to avoid an unnecessary detailed test */ |
|
|
if(mx > 0 && mx < OSD_W && my > 0 && my < OSD_H) { |
|
|
#ifndef OSD_NO_DPAD |
|
|
but = osd_check_dpad(mx, my); |
|
|
#endif |
|
|
} |
|
|
|
|
|
if(but == OSD_NONE) |
|
|
but = osd_check_zoom(mx, my); |
|
|
} |
|
|
|
|
|
#ifdef OSD_BALLOON |
|
|
if(but == OSD_NONE) { |
|
|
/* check if user clicked into balloon */ |
|
|
if(osd_balloon_check(osd, click, down, x, y)) |
|
|
but = OSD_BG; |
|
|
} |
|
|
#endif |
|
|
|
|
|
FOUT; |
|
|
return but; |
|
|
} |
|
|
|
|
1018 |
#ifndef OSD_NO_DPAD |
#ifndef OSD_NO_DPAD |
1019 |
static void |
static void |
1020 |
osd_dpad_labels(cairo_t *cr, gint x, gint y) { |
osd_dpad_labels(cairo_t *cr, gint x, gint y) { |
1088 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
1089 |
|
|
1090 |
#ifndef OSD_COORDINATES_FONT_SIZE |
#ifndef OSD_COORDINATES_FONT_SIZE |
1091 |
#define OSD_COORDINATES_FONT_SIZE 12 |
#define OSD_COORDINATES_FONT_SIZE (12.0) |
1092 |
#endif |
#endif |
1093 |
|
|
1094 |
#define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6) |
#define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6) |
1157 |
osd_render_centered_text(cairo_t *cr, int y, int width, char *text) { |
osd_render_centered_text(cairo_t *cr, int y, int width, char *text) { |
1158 |
FIN; |
FIN; |
1159 |
|
|
|
printf("params: %p %d %d %p\n", cr, y, width, text); // XXX |
|
|
|
|
1160 |
if(!text) return y; |
if(!text) return y; |
1161 |
|
|
|
printf("text given: %s\n", text); // XXX |
|
|
|
|
1162 |
char *p = g_malloc(strlen(text)+4); // space for "...\n" |
char *p = g_malloc(strlen(text)+4); // space for "...\n" |
1163 |
strcpy(p, text); |
strcpy(p, text); |
1164 |
|
|
1165 |
cairo_text_extents_t extents; |
cairo_text_extents_t extents; |
1166 |
printf("getting extents for \"%s\"\n", p); // XXX |
memset(&extents, 0, sizeof(cairo_text_extents_t)); |
1167 |
cairo_text_extents (cr, p, &extents); |
cairo_text_extents (cr, p, &extents); |
1168 |
printf("initial extents.width = %d\n", extents.width); // XXX |
g_assert(extents.width != 0.0); |
1169 |
|
|
1170 |
/* check if text needs to be truncated */ |
/* check if text needs to be truncated */ |
1171 |
int trunc_at = strlen(text)-1; |
int trunc_at = strlen(text); |
1172 |
while(extents.width > width) { |
while(extents.width > width) { |
|
g_assert(trunc_at > 0); |
|
1173 |
|
|
1174 |
printf("trunc at %d\n", trunc_at); // XXX |
/* cut off all utf8 multibyte remains so the actual */ |
1175 |
printf("extents.width = %d > %d\n", extents.width, width); // XXX |
/* truncation only deals with one byte */ |
1176 |
|
while((p[trunc_at-1] & 0xc0) == 0x80) { |
1177 |
|
trunc_at--; |
1178 |
|
g_assert(trunc_at > 0); |
1179 |
|
} |
1180 |
|
|
1181 |
trunc_at--; |
trunc_at--; |
1182 |
|
g_assert(trunc_at > 0); |
1183 |
|
|
1184 |
strcpy(p+trunc_at, "..."); |
strcpy(p+trunc_at, "..."); |
|
printf("getting extents for \"%s\"\n", p); // XXX |
|
1185 |
cairo_text_extents (cr, p, &extents); |
cairo_text_extents (cr, p, &extents); |
1186 |
} |
} |
1187 |
|
|
|
printf("painting\n"); // XXX |
|
|
|
|
1188 |
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); |
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); |
1189 |
cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6); |
cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6); |
1190 |
cairo_move_to (cr, (width - extents.width)/2, y - extents.y_bearing); |
cairo_move_to (cr, (width - extents.width)/2, y - extents.y_bearing); |
1208 |
FIN; |
FIN; |
1209 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1210 |
|
|
1211 |
|
if(!priv->coordinates.surface) |
1212 |
|
return; |
1213 |
|
|
1214 |
/* get current map position */ |
/* get current map position */ |
1215 |
gfloat lat, lon; |
gfloat lat, lon; |
1216 |
g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL); |
g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL); |
1226 |
priv->coordinates.lon = lon; |
priv->coordinates.lon = lon; |
1227 |
|
|
1228 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1229 |
|
|
1230 |
|
g_assert(priv->coordinates.surface); |
1231 |
cairo_t *cr = cairo_create(priv->coordinates.surface); |
cairo_t *cr = cairo_create(priv->coordinates.surface); |
1232 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1233 |
// cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5); |
// cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5); |
1286 |
return; |
return; |
1287 |
|
|
1288 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1289 |
|
g_assert(priv->nav.surface); |
1290 |
cairo_t *cr = cairo_create(priv->nav.surface); |
cairo_t *cr = cairo_create(priv->nav.surface); |
1291 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1292 |
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
1388 |
FOUT; |
FOUT; |
1389 |
} |
} |
1390 |
|
|
1391 |
|
/* check if the user clicked inside the source selection area */ |
1392 |
|
static osd_button_t |
1393 |
|
osd_nav_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) { |
1394 |
|
FIN; |
1395 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1396 |
|
|
1397 |
|
if(!priv->nav.surface || down) |
1398 |
|
return OSD_NONE; |
1399 |
|
|
1400 |
|
x -= OSD_X; |
1401 |
|
if(OSD_X < 0) |
1402 |
|
x -= (osd->widget->allocation.width - OSD_NAV_W); |
1403 |
|
|
1404 |
|
y -= (osd->widget->allocation.height - OSD_NAV_H)/2; |
1405 |
|
|
1406 |
|
if(x >= 0 && y >= 0 && x <= OSD_NAV_W && y <= OSD_NAV_H) { |
1407 |
|
osm_gps_map_set_center(OSM_GPS_MAP(osd->widget), |
1408 |
|
priv->nav.lat, priv->nav.lon); |
1409 |
|
} |
1410 |
|
|
1411 |
|
FOUT; |
1412 |
|
return OSD_NONE; |
1413 |
|
} |
1414 |
|
|
1415 |
void osm_gps_map_osd_clear_nav (OsmGpsMap *map) { |
void osm_gps_map_osd_clear_nav (OsmGpsMap *map) { |
1416 |
FIN; |
FIN; |
1417 |
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
1465 |
|
|
1466 |
#endif // OSD_NAV |
#endif // OSD_NAV |
1467 |
|
|
1468 |
|
static osd_button_t |
1469 |
|
osd_check_int(osm_gps_map_osd_t *osd, gboolean click, gboolean down, gint x, gint y) { |
1470 |
|
FIN; |
1471 |
|
osd_button_t but = OSD_NONE; |
1472 |
|
|
1473 |
|
#ifdef OSD_BALLOON |
1474 |
|
if(down) { |
1475 |
|
/* needed to handle balloons that are created at click */ |
1476 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1477 |
|
priv->balloon.just_created = FALSE; |
1478 |
|
} |
1479 |
|
#endif |
1480 |
|
|
1481 |
|
#ifdef OSD_SOURCE_SEL |
1482 |
|
/* the source selection area is handles internally */ |
1483 |
|
but = osd_source_check(osd, down, x, y); |
1484 |
|
#endif |
1485 |
|
|
1486 |
|
#ifdef OSD_NAV |
1487 |
|
if(but == OSD_NONE) { |
1488 |
|
/* the source selection area is handles internally */ |
1489 |
|
but = osd_nav_check(osd, down, x, y); |
1490 |
|
} |
1491 |
|
#endif |
1492 |
|
|
1493 |
|
if(but == OSD_NONE) { |
1494 |
|
gint mx = x - OSD_X; |
1495 |
|
gint my = y - OSD_Y; |
1496 |
|
|
1497 |
|
if(OSD_X < 0) |
1498 |
|
mx -= (osd->widget->allocation.width - OSD_W); |
1499 |
|
|
1500 |
|
if(OSD_Y < 0) |
1501 |
|
my -= (osd->widget->allocation.height - OSD_H); |
1502 |
|
|
1503 |
|
/* first do a rough test for the OSD area. */ |
1504 |
|
/* this is just to avoid an unnecessary detailed test */ |
1505 |
|
if(mx > 0 && mx < OSD_W && my > 0 && my < OSD_H) { |
1506 |
|
#ifndef OSD_NO_DPAD |
1507 |
|
but = osd_check_dpad(mx, my); |
1508 |
|
#endif |
1509 |
|
} |
1510 |
|
|
1511 |
|
if(but == OSD_NONE) |
1512 |
|
but = osd_check_zoom(mx, my); |
1513 |
|
} |
1514 |
|
|
1515 |
|
#ifdef OSD_BALLOON |
1516 |
|
if(but == OSD_NONE) { |
1517 |
|
/* check if user clicked into balloon */ |
1518 |
|
if(osd_balloon_check(osd, click, down, x, y)) |
1519 |
|
but = OSD_BG; |
1520 |
|
} |
1521 |
|
#endif |
1522 |
|
|
1523 |
|
FOUT; |
1524 |
|
return but; |
1525 |
|
} |
1526 |
|
|
1527 |
|
|
1528 |
#ifdef OSD_CROSSHAIR |
#ifdef OSD_CROSSHAIR |
1529 |
|
|
1566 |
FIN; |
FIN; |
1567 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1568 |
|
|
1569 |
if(priv->crosshair.rendered) |
if(!priv->crosshair.surface || priv->crosshair.rendered) |
1570 |
return; |
return; |
1571 |
|
|
1572 |
priv->crosshair.rendered = TRUE; |
priv->crosshair.rendered = TRUE; |
1573 |
|
|
1574 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1575 |
|
g_assert(priv->crosshair.surface); |
1576 |
cairo_t *cr = cairo_create(priv->crosshair.surface); |
cairo_t *cr = cairo_create(priv->crosshair.surface); |
1577 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1578 |
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); |
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); |
1597 |
#ifdef OSD_SCALE |
#ifdef OSD_SCALE |
1598 |
|
|
1599 |
#ifndef OSD_SCALE_FONT_SIZE |
#ifndef OSD_SCALE_FONT_SIZE |
1600 |
#define OSD_SCALE_FONT_SIZE 12 |
#define OSD_SCALE_FONT_SIZE (12.0) |
1601 |
#endif |
#endif |
1602 |
#define OSD_SCALE_W (10*OSD_SCALE_FONT_SIZE) |
#define OSD_SCALE_W (10*OSD_SCALE_FONT_SIZE) |
1603 |
#define OSD_SCALE_H (5*OSD_SCALE_FONT_SIZE/2) |
#define OSD_SCALE_H (5*OSD_SCALE_FONT_SIZE/2) |
1615 |
FIN; |
FIN; |
1616 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1617 |
|
|
1618 |
|
if(!priv->scale.surface) |
1619 |
|
return; |
1620 |
|
|
1621 |
/* this only needs to be rendered if the zoom has changed */ |
/* this only needs to be rendered if the zoom has changed */ |
1622 |
gint zoom; |
gint zoom; |
1623 |
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
1629 |
float m_per_pix = osm_gps_map_get_scale(OSM_GPS_MAP(osd->widget)); |
float m_per_pix = osm_gps_map_get_scale(OSM_GPS_MAP(osd->widget)); |
1630 |
|
|
1631 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1632 |
|
g_assert(priv->scale.surface); |
1633 |
cairo_t *cr = cairo_create(priv->scale.surface); |
cairo_t *cr = cairo_create(priv->scale.surface); |
1634 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1635 |
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
1750 |
FIN; |
FIN; |
1751 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1752 |
|
|
1753 |
|
if(!priv->controls.surface) |
1754 |
|
return; |
1755 |
|
|
1756 |
if(priv->controls.rendered |
if(priv->controls.rendered |
1757 |
#ifdef OSD_GPS_BUTTON |
#ifdef OSD_GPS_BUTTON |
1758 |
&& (priv->controls.gps_enabled == (osd->cb != NULL)) |
&& (priv->controls.gps_enabled == (osd->cb != NULL)) |
1772 |
#endif |
#endif |
1773 |
|
|
1774 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1775 |
|
g_assert(priv->controls.surface); |
1776 |
cairo_t *cr = cairo_create(priv->controls.surface); |
cairo_t *cr = cairo_create(priv->controls.surface); |
1777 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1778 |
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |