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 |
gboolean imperial, mode; // display distance imperial/metric |
86 |
|
int click_sep; |
87 |
} nav; |
} nav; |
88 |
#endif |
#endif |
89 |
|
|
136 |
|
|
137 |
#define CLOSE_BUTTON_RADIUS (BALLOON_CORNER_RADIUS) |
#define CLOSE_BUTTON_RADIUS (BALLOON_CORNER_RADIUS) |
138 |
|
|
|
#define FIN printf("entering function %s\n", __func__); |
|
|
#define FOUT printf("leaving function %s\n", __func__); |
|
|
|
|
139 |
/* 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 */ |
140 |
/* for the shadow */ |
/* for the shadow */ |
141 |
static void |
static void |
142 |
osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1, |
osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1, |
143 |
gboolean bottom, int px, int py, int px0, int px1) { |
gboolean bottom, int px, int py, int px0, int px1) { |
144 |
|
|
|
FIN; |
|
|
|
|
145 |
cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS); |
cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS); |
146 |
cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS, |
cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS, |
147 |
BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2); |
BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2); |
170 |
BALLOON_CORNER_RADIUS, M_PI/2, M_PI); |
BALLOON_CORNER_RADIUS, M_PI/2, M_PI); |
171 |
|
|
172 |
cairo_close_path (cr); |
cairo_close_path (cr); |
|
|
|
|
FOUT; |
|
173 |
} |
} |
174 |
|
|
175 |
static void |
static void |
176 |
osd_render_balloon(osm_gps_map_osd_t *osd) { |
osd_render_balloon(osm_gps_map_osd_t *osd) { |
|
FIN; |
|
|
|
|
177 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
178 |
|
|
179 |
|
if(!priv->balloon.surface) |
180 |
|
return; |
181 |
|
|
182 |
/* get zoom */ |
/* get zoom */ |
183 |
gint zoom; |
gint zoom; |
184 |
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
239 |
priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER; |
priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER; |
240 |
priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER; |
priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER; |
241 |
|
|
242 |
|
g_assert(priv->balloon.surface); |
243 |
cairo_t *cr = cairo_create(priv->balloon.surface); |
cairo_t *cr = cairo_create(priv->balloon.surface); |
244 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
245 |
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); |
288 |
} |
} |
289 |
|
|
290 |
cairo_destroy(cr); |
cairo_destroy(cr); |
|
|
|
|
FOUT; |
|
291 |
} |
} |
292 |
|
|
293 |
/* return true if balloon is being displayed and if */ |
/* return true if balloon is being displayed and if */ |
295 |
static gboolean |
static gboolean |
296 |
osd_balloon_check(osm_gps_map_osd_t *osd, gboolean click, gboolean down, gint x, gint y) |
osd_balloon_check(osm_gps_map_osd_t *osd, gboolean click, gboolean down, gint x, gint y) |
297 |
{ |
{ |
|
FIN; |
|
|
|
|
298 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
299 |
|
|
300 |
if(!priv->balloon.surface) |
if(!priv->balloon.surface) |
344 |
priv->balloon.cb(&event, priv->balloon.data); |
priv->balloon.cb(&event, priv->balloon.data); |
345 |
} |
} |
346 |
} |
} |
|
FOUT; |
|
347 |
return is_in; |
return is_in; |
348 |
} |
} |
349 |
|
|
350 |
void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) { |
void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) { |
|
FIN; |
|
|
|
|
351 |
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
352 |
|
|
353 |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
363 |
priv->balloon.lon = OSM_GPS_MAP_INVALID; |
priv->balloon.lon = OSM_GPS_MAP_INVALID; |
364 |
} |
} |
365 |
osm_gps_map_redraw(map); |
osm_gps_map_redraw(map); |
|
FOUT; |
|
366 |
} |
} |
367 |
|
|
368 |
void |
void |
369 |
osm_gps_map_osd_draw_balloon (OsmGpsMap *map, float latitude, float longitude, |
osm_gps_map_osd_draw_balloon (OsmGpsMap *map, float latitude, float longitude, |
370 |
OsmGpsMapBalloonCallback cb, gpointer data) { |
OsmGpsMapBalloonCallback cb, gpointer data) { |
|
FIN; |
|
371 |
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
372 |
|
|
373 |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
394 |
osd_render_balloon(osd); |
osd_render_balloon(osd); |
395 |
|
|
396 |
osm_gps_map_redraw(map); |
osm_gps_map_redraw(map); |
|
FOUT; |
|
397 |
} |
} |
398 |
|
|
399 |
#endif // OSD_BALLOON |
#endif // OSD_BALLOON |
538 |
static gboolean |
static gboolean |
539 |
osm_gps_map_in_circle(gint x, gint y, gint cx, gint cy, gint rad) |
osm_gps_map_in_circle(gint x, gint y, gint cx, gint cy, gint rad) |
540 |
{ |
{ |
|
FIN; |
|
541 |
return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad); |
return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad); |
542 |
} |
} |
543 |
|
|
628 |
/* internal value to draw the arrow on the "puller" */ |
/* internal value to draw the arrow on the "puller" */ |
629 |
#define OSD_S_D0 (OSD_S_RAD/2) |
#define OSD_S_D0 (OSD_S_RAD/2) |
630 |
#ifndef OSD_FONT_SIZE |
#ifndef OSD_FONT_SIZE |
631 |
#define OSD_FONT_SIZE 16.0 |
#define OSD_FONT_SIZE (16.0) |
632 |
#endif |
#endif |
633 |
#define OSD_TEXT_BORDER (OSD_FONT_SIZE/2) |
#define OSD_TEXT_BORDER (OSD_FONT_SIZE/2) |
634 |
#define OSD_TEXT_SKIP (OSD_FONT_SIZE/8) |
#define OSD_TEXT_SKIP (OSD_FONT_SIZE/8) |
736 |
|
|
737 |
static void |
static void |
738 |
osd_render_source_sel(osm_gps_map_osd_t *osd, gboolean force_rerender) { |
osd_render_source_sel(osm_gps_map_osd_t *osd, gboolean force_rerender) { |
|
FIN; |
|
|
|
|
739 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
740 |
|
|
741 |
if(priv->source_sel.rendered && !force_rerender) |
if(!priv->source_sel.surface || |
742 |
|
(priv->source_sel.rendered && !force_rerender)) |
743 |
return; |
return; |
744 |
|
|
745 |
priv->source_sel.rendered = TRUE; |
priv->source_sel.rendered = TRUE; |
751 |
#endif |
#endif |
752 |
|
|
753 |
/* draw source selector */ |
/* draw source selector */ |
754 |
|
g_assert(priv->source_sel.surface); |
755 |
cairo_t *cr = cairo_create(priv->source_sel.surface); |
cairo_t *cr = cairo_create(priv->source_sel.surface); |
756 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
757 |
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); |
784 |
cairo_stroke (cr); |
cairo_stroke (cr); |
785 |
|
|
786 |
cairo_destroy(cr); |
cairo_destroy(cr); |
|
FOUT; |
|
787 |
} |
} |
788 |
|
|
789 |
/* re-allocate the buffer used to draw the menu. This is used */ |
/* re-allocate the buffer used to draw the menu. This is used */ |
790 |
/* to collapse/expand the buffer */ |
/* to collapse/expand the buffer */ |
791 |
static void |
static void |
792 |
osd_source_reallocate(osm_gps_map_osd_t *osd) { |
osd_source_reallocate(osm_gps_map_osd_t *osd) { |
|
FIN; |
|
793 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
794 |
|
|
795 |
/* re-allocate offscreen bitmap */ |
/* re-allocate offscreen bitmap */ |
800 |
cairo_text_extents_t extents; |
cairo_text_extents_t extents; |
801 |
|
|
802 |
/* determine content size */ |
/* determine content size */ |
803 |
|
g_assert(priv->source_sel.surface); |
804 |
cairo_t *cr = cairo_create(priv->source_sel.surface); |
cairo_t *cr = cairo_create(priv->source_sel.surface); |
805 |
cairo_select_font_face (cr, "Sans", |
cairo_select_font_face (cr, "Sans", |
806 |
CAIRO_FONT_SLANT_NORMAL, |
CAIRO_FONT_SLANT_NORMAL, |
831 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2); |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2); |
832 |
|
|
833 |
osd_render_source_sel(osd, TRUE); |
osd_render_source_sel(osd, TRUE); |
|
FOUT; |
|
834 |
} |
} |
835 |
|
|
836 |
#define OSD_HZ 15 |
#define OSD_HZ 15 |
837 |
#define OSD_TIME 500 |
#define OSD_TIME 500 |
838 |
|
|
839 |
static gboolean osd_source_animate(gpointer data) { |
static gboolean osd_source_animate(gpointer data) { |
|
FIN; |
|
840 |
osm_gps_map_osd_t *osd = (osm_gps_map_osd_t*)data; |
osm_gps_map_osd_t *osd = (osm_gps_map_osd_t*)data; |
841 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
842 |
int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X; |
int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X; |
875 |
if(done) |
if(done) |
876 |
priv->source_sel.handler_id = 0; |
priv->source_sel.handler_id = 0; |
877 |
|
|
|
FOUT; |
|
878 |
return !done; |
return !done; |
879 |
} |
} |
880 |
|
|
882 |
static void |
static void |
883 |
osd_source_toggle(osm_gps_map_osd_t *osd) |
osd_source_toggle(osm_gps_map_osd_t *osd) |
884 |
{ |
{ |
|
FIN; |
|
885 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
886 |
|
|
887 |
/* ignore clicks while animation is running */ |
/* ignore clicks while animation is running */ |
907 |
/* start timer to handle animation */ |
/* start timer to handle animation */ |
908 |
priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, |
priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, |
909 |
osd_source_animate, osd); |
osd_source_animate, osd); |
|
FOUT; |
|
910 |
} |
} |
911 |
|
|
912 |
/* check if the user clicked inside the source selection area */ |
/* check if the user clicked inside the source selection area */ |
913 |
static osd_button_t |
static osd_button_t |
914 |
osd_source_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) { |
osd_source_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) { |
|
FIN; |
|
915 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
916 |
|
|
917 |
if(!priv->source_sel.expanded) |
if(!priv->source_sel.expanded) |
976 |
} |
} |
977 |
} |
} |
978 |
|
|
|
FOUT; |
|
979 |
return OSD_NONE; |
return OSD_NONE; |
980 |
} |
} |
981 |
#endif // OSD_SOURCE_SEL |
#endif // OSD_SOURCE_SEL |
982 |
|
|
|
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; |
|
|
} |
|
|
|
|
983 |
#ifndef OSD_NO_DPAD |
#ifndef OSD_NO_DPAD |
984 |
static void |
static void |
985 |
osd_dpad_labels(cairo_t *cr, gint x, gint y) { |
osd_dpad_labels(cairo_t *cr, gint x, gint y) { |
1053 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
1054 |
|
|
1055 |
#ifndef OSD_COORDINATES_FONT_SIZE |
#ifndef OSD_COORDINATES_FONT_SIZE |
1056 |
#define OSD_COORDINATES_FONT_SIZE 12 |
#define OSD_COORDINATES_FONT_SIZE (12.0) |
1057 |
#endif |
#endif |
1058 |
|
|
1059 |
#define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6) |
#define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6) |
1120 |
/* render a string at the given screen position */ |
/* render a string at the given screen position */ |
1121 |
static int |
static int |
1122 |
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) { |
|
FIN; |
|
|
|
|
|
printf("params: %p %d %d %p\n", cr, y, width, text); // XXX |
|
|
|
|
1123 |
if(!text) return y; |
if(!text) return y; |
1124 |
|
|
|
printf("text given: %s\n", text); // XXX |
|
|
|
|
1125 |
char *p = g_malloc(strlen(text)+4); // space for "...\n" |
char *p = g_malloc(strlen(text)+4); // space for "...\n" |
1126 |
strcpy(p, text); |
strcpy(p, text); |
1127 |
|
|
1128 |
cairo_text_extents_t extents; |
cairo_text_extents_t extents; |
1129 |
|
memset(&extents, 0, sizeof(cairo_text_extents_t)); |
1130 |
cairo_text_extents (cr, p, &extents); |
cairo_text_extents (cr, p, &extents); |
1131 |
|
g_assert(extents.width != 0.0); |
1132 |
|
|
1133 |
/* check if text needs to be truncated */ |
/* check if text needs to be truncated */ |
1134 |
int trunc_at = strlen(text)-1; |
int trunc_at = strlen(text); |
1135 |
while(extents.width > width) { |
while(extents.width > width) { |
1136 |
printf("trunc at %d\n", trunc_at); // XXX |
|
1137 |
|
/* cut off all utf8 multibyte remains so the actual */ |
1138 |
|
/* truncation only deals with one byte */ |
1139 |
|
while((p[trunc_at-1] & 0xc0) == 0x80) { |
1140 |
|
trunc_at--; |
1141 |
|
g_assert(trunc_at > 0); |
1142 |
|
} |
1143 |
|
|
1144 |
trunc_at--; |
trunc_at--; |
1145 |
|
g_assert(trunc_at > 0); |
1146 |
|
|
1147 |
strcpy(p+trunc_at, "..."); |
strcpy(p+trunc_at, "..."); |
1148 |
cairo_text_extents (cr, p, &extents); |
cairo_text_extents (cr, p, &extents); |
1149 |
} |
} |
1150 |
|
|
|
printf("painting\n"); // XXX |
|
|
|
|
1151 |
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); |
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); |
1152 |
cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6); |
cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6); |
1153 |
cairo_move_to (cr, (width - extents.width)/2, y - extents.y_bearing); |
cairo_move_to (cr, (width - extents.width)/2, y - extents.y_bearing); |
1161 |
g_free(p); |
g_free(p); |
1162 |
|
|
1163 |
/* skip + 1/5 line */ |
/* skip + 1/5 line */ |
|
FOUT; |
|
1164 |
return y + 6*OSD_COORDINATES_FONT_SIZE/5; |
return y + 6*OSD_COORDINATES_FONT_SIZE/5; |
1165 |
} |
} |
1166 |
|
|
1167 |
static void |
static void |
1168 |
osd_render_coordinates(osm_gps_map_osd_t *osd) |
osd_render_coordinates(osm_gps_map_osd_t *osd) |
1169 |
{ |
{ |
|
FIN; |
|
1170 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1171 |
|
|
1172 |
|
if(!priv->coordinates.surface) |
1173 |
|
return; |
1174 |
|
|
1175 |
/* get current map position */ |
/* get current map position */ |
1176 |
gfloat lat, lon; |
gfloat lat, lon; |
1177 |
g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL); |
g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL); |
1187 |
priv->coordinates.lon = lon; |
priv->coordinates.lon = lon; |
1188 |
|
|
1189 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1190 |
|
|
1191 |
|
g_assert(priv->coordinates.surface); |
1192 |
cairo_t *cr = cairo_create(priv->coordinates.surface); |
cairo_t *cr = cairo_create(priv->coordinates.surface); |
1193 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1194 |
// 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); |
1212 |
g_free(longitude); |
g_free(longitude); |
1213 |
|
|
1214 |
cairo_destroy(cr); |
cairo_destroy(cr); |
|
FOUT; |
|
1215 |
} |
} |
1216 |
#endif // OSD_COORDINATES |
#endif // OSD_COORDINATES |
1217 |
|
|
1239 |
static void |
static void |
1240 |
osd_render_nav(osm_gps_map_osd_t *osd) |
osd_render_nav(osm_gps_map_osd_t *osd) |
1241 |
{ |
{ |
|
FIN; |
|
1242 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1243 |
|
|
1244 |
if(!priv->nav.surface || isnan(priv->nav.lat) || isnan(priv->nav.lon)) |
if(!priv->nav.surface || isnan(priv->nav.lat) || isnan(priv->nav.lon)) |
1245 |
return; |
return; |
1246 |
|
|
1247 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1248 |
|
g_assert(priv->nav.surface); |
1249 |
cairo_t *cr = cairo_create(priv->nav.surface); |
cairo_t *cr = cairo_create(priv->nav.surface); |
1250 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1251 |
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); |
1264 |
y = osd_render_centered_text(cr, y, OSD_NAV_W, priv->nav.name); |
y = osd_render_centered_text(cr, y, OSD_NAV_W, priv->nav.name); |
1265 |
y = osd_render_centered_text(cr, y, OSD_NAV_W, latitude); |
y = osd_render_centered_text(cr, y, OSD_NAV_W, latitude); |
1266 |
y = osd_render_centered_text(cr, y, OSD_NAV_W, longitude); |
y = osd_render_centered_text(cr, y, OSD_NAV_W, longitude); |
1267 |
|
|
1268 |
g_free(latitude); |
g_free(latitude); |
1269 |
g_free(longitude); |
g_free(longitude); |
1270 |
|
|
1271 |
|
/* everything below this is the compass. we need to know this */ |
1272 |
|
/* to differ between coordinate clicks and compass clicks */ |
1273 |
|
priv->nav.click_sep = y; |
1274 |
|
|
1275 |
/* draw the compass */ |
/* draw the compass */ |
1276 |
int radius = (OSD_NAV_H - y - 5*OSD_COORDINATES_FONT_SIZE/4)/2; |
int radius = (OSD_NAV_H - y - 5*OSD_COORDINATES_FONT_SIZE/4)/2; |
1277 |
if(radius > OSD_NAV_W/2) |
if(radius > OSD_NAV_W/2) |
1294 |
#define ARROW_WIDTH 0.3 |
#define ARROW_WIDTH 0.3 |
1295 |
#define ARROW_LENGTH 0.7 |
#define ARROW_LENGTH 0.7 |
1296 |
|
|
1297 |
coord_t *gps = osm_gps_map_get_gps (OSM_GPS_MAP(osd->widget)); |
coord_t mpos, *pos = osm_gps_map_get_gps (OSM_GPS_MAP(osd->widget)); |
1298 |
if(gps) { |
if(priv->nav.mode) { |
1299 |
float arot = get_bearing(gps->rlat, gps->rlon, |
gfloat lat, lon; |
1300 |
|
g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL); |
1301 |
|
mpos.rlat = deg2rad(lat); |
1302 |
|
mpos.rlon = deg2rad(lon); |
1303 |
|
pos = &mpos; |
1304 |
|
} |
1305 |
|
|
1306 |
|
if(pos) { |
1307 |
|
float arot = get_bearing(pos->rlat, pos->rlon, |
1308 |
deg2rad(priv->nav.lat), deg2rad(priv->nav.lon)); |
deg2rad(priv->nav.lat), deg2rad(priv->nav.lon)); |
1309 |
|
|
1310 |
cairo_move_to(cr, |
cairo_move_to(cr, |
1324 |
y + radius * -ARROW_LENGTH * -cos(arot-ARROW_WIDTH)); |
y + radius * -ARROW_LENGTH * -cos(arot-ARROW_WIDTH)); |
1325 |
|
|
1326 |
cairo_close_path(cr); |
cairo_close_path(cr); |
1327 |
cairo_set_source_rgb (cr, 0, 0, 0); |
if(priv->nav.mode) |
1328 |
|
cairo_set_source_rgb (cr, 0, 0, 0); |
1329 |
|
else |
1330 |
|
cairo_set_source_rgb (cr, 0, 0, 0.8); |
1331 |
|
|
1332 |
cairo_fill (cr); |
cairo_fill (cr); |
1333 |
|
|
1334 |
y += radius + OSD_COORDINATES_FONT_SIZE/4; |
y += radius + OSD_COORDINATES_FONT_SIZE/4; |
1335 |
|
|
1336 |
float dist = get_distance(gps->rlat, gps->rlon, |
float dist = get_distance(pos->rlat, pos->rlon, |
1337 |
deg2rad(priv->nav.lat), deg2rad(priv->nav.lon)); |
deg2rad(priv->nav.lat), deg2rad(priv->nav.lon)); |
1338 |
|
|
1339 |
char *dist_str = NULL; |
char *dist_str = NULL; |
1360 |
} |
} |
1361 |
|
|
1362 |
cairo_destroy(cr); |
cairo_destroy(cr); |
1363 |
FOUT; |
} |
1364 |
|
|
1365 |
|
/* check if the user clicked inside the source selection area */ |
1366 |
|
static osd_button_t |
1367 |
|
osd_nav_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) { |
1368 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1369 |
|
|
1370 |
|
if(!priv->nav.surface || down) |
1371 |
|
return OSD_NONE; |
1372 |
|
|
1373 |
|
x -= OSD_X; |
1374 |
|
if(OSD_X < 0) |
1375 |
|
x -= (osd->widget->allocation.width - OSD_NAV_W); |
1376 |
|
|
1377 |
|
y -= (osd->widget->allocation.height - OSD_NAV_H)/2; |
1378 |
|
|
1379 |
|
if(x >= 0 && y >= 0 && x <= OSD_NAV_W && y <= OSD_NAV_H) { |
1380 |
|
if(y < priv->nav.click_sep) |
1381 |
|
osm_gps_map_set_center(OSM_GPS_MAP(osd->widget), |
1382 |
|
priv->nav.lat, priv->nav.lon); |
1383 |
|
else { |
1384 |
|
priv->nav.mode = !priv->nav.mode; |
1385 |
|
osm_gps_map_redraw(OSM_GPS_MAP(osd->widget)); |
1386 |
|
} |
1387 |
|
} |
1388 |
|
|
1389 |
|
return OSD_NONE; |
1390 |
} |
} |
1391 |
|
|
1392 |
void osm_gps_map_osd_clear_nav (OsmGpsMap *map) { |
void osm_gps_map_osd_clear_nav (OsmGpsMap *map) { |
|
FIN; |
|
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); |
1406 |
if(priv->nav.name) g_free(priv->nav.name); |
if(priv->nav.name) g_free(priv->nav.name); |
1407 |
} |
} |
1408 |
osm_gps_map_redraw(map); |
osm_gps_map_redraw(map); |
|
FOUT; |
|
1409 |
} |
} |
1410 |
|
|
1411 |
void |
void |
1412 |
osm_gps_map_osd_draw_nav (OsmGpsMap *map, gboolean imperial, |
osm_gps_map_osd_draw_nav (OsmGpsMap *map, gboolean imperial, |
1413 |
float latitude, float longitude, char *name) { |
float latitude, float longitude, char *name) { |
|
FIN; |
|
1414 |
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
1415 |
|
|
1416 |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
1434 |
osd_render_nav(osd); |
osd_render_nav(osd); |
1435 |
|
|
1436 |
osm_gps_map_redraw(map); |
osm_gps_map_redraw(map); |
|
FOUT; |
|
1437 |
} |
} |
1438 |
|
|
1439 |
#endif // OSD_NAV |
#endif // OSD_NAV |
1440 |
|
|
1441 |
|
static osd_button_t |
1442 |
|
osd_check_int(osm_gps_map_osd_t *osd, gboolean click, gboolean down, gint x, gint y) { |
1443 |
|
osd_button_t but = OSD_NONE; |
1444 |
|
|
1445 |
|
#ifdef OSD_BALLOON |
1446 |
|
if(down) { |
1447 |
|
/* needed to handle balloons that are created at click */ |
1448 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1449 |
|
priv->balloon.just_created = FALSE; |
1450 |
|
} |
1451 |
|
#endif |
1452 |
|
|
1453 |
|
#ifdef OSD_SOURCE_SEL |
1454 |
|
/* the source selection area is handles internally */ |
1455 |
|
but = osd_source_check(osd, down, x, y); |
1456 |
|
#endif |
1457 |
|
|
1458 |
|
#ifdef OSD_NAV |
1459 |
|
if(but == OSD_NONE) { |
1460 |
|
/* the source selection area is handles internally */ |
1461 |
|
but = osd_nav_check(osd, down, x, y); |
1462 |
|
} |
1463 |
|
#endif |
1464 |
|
|
1465 |
|
if(but == OSD_NONE) { |
1466 |
|
gint mx = x - OSD_X; |
1467 |
|
gint my = y - OSD_Y; |
1468 |
|
|
1469 |
|
if(OSD_X < 0) |
1470 |
|
mx -= (osd->widget->allocation.width - OSD_W); |
1471 |
|
|
1472 |
|
if(OSD_Y < 0) |
1473 |
|
my -= (osd->widget->allocation.height - OSD_H); |
1474 |
|
|
1475 |
|
/* first do a rough test for the OSD area. */ |
1476 |
|
/* this is just to avoid an unnecessary detailed test */ |
1477 |
|
if(mx > 0 && mx < OSD_W && my > 0 && my < OSD_H) { |
1478 |
|
#ifndef OSD_NO_DPAD |
1479 |
|
but = osd_check_dpad(mx, my); |
1480 |
|
#endif |
1481 |
|
} |
1482 |
|
|
1483 |
|
if(but == OSD_NONE) |
1484 |
|
but = osd_check_zoom(mx, my); |
1485 |
|
} |
1486 |
|
|
1487 |
|
#ifdef OSD_BALLOON |
1488 |
|
if(but == OSD_NONE) { |
1489 |
|
/* check if user clicked into balloon */ |
1490 |
|
if(osd_balloon_check(osd, click, down, x, y)) |
1491 |
|
but = OSD_BG; |
1492 |
|
} |
1493 |
|
#endif |
1494 |
|
|
1495 |
|
return but; |
1496 |
|
} |
1497 |
|
|
1498 |
|
|
1499 |
#ifdef OSD_CROSSHAIR |
#ifdef OSD_CROSSHAIR |
1500 |
|
|
1509 |
|
|
1510 |
static void |
static void |
1511 |
osd_render_crosshair_shape(cairo_t *cr) { |
osd_render_crosshair_shape(cairo_t *cr) { |
|
FIN; |
|
1512 |
cairo_arc (cr, OSD_CROSSHAIR_W/2, OSD_CROSSHAIR_H/2, |
cairo_arc (cr, OSD_CROSSHAIR_W/2, OSD_CROSSHAIR_H/2, |
1513 |
OSD_CROSSHAIR_RADIUS, 0, 2*M_PI); |
OSD_CROSSHAIR_RADIUS, 0, 2*M_PI); |
1514 |
|
|
1527 |
cairo_rel_line_to (cr, 0, OSD_CROSSHAIR_TICK); |
cairo_rel_line_to (cr, 0, OSD_CROSSHAIR_TICK); |
1528 |
|
|
1529 |
cairo_stroke (cr); |
cairo_stroke (cr); |
|
FOUT; |
|
1530 |
} |
} |
1531 |
|
|
1532 |
static void |
static void |
1533 |
osd_render_crosshair(osm_gps_map_osd_t *osd) |
osd_render_crosshair(osm_gps_map_osd_t *osd) |
1534 |
{ |
{ |
|
FIN; |
|
1535 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1536 |
|
|
1537 |
if(priv->crosshair.rendered) |
if(!priv->crosshair.surface || priv->crosshair.rendered) |
1538 |
return; |
return; |
1539 |
|
|
1540 |
priv->crosshair.rendered = TRUE; |
priv->crosshair.rendered = TRUE; |
1541 |
|
|
1542 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1543 |
|
g_assert(priv->crosshair.surface); |
1544 |
cairo_t *cr = cairo_create(priv->crosshair.surface); |
cairo_t *cr = cairo_create(priv->crosshair.surface); |
1545 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1546 |
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); |
1558 |
osd_render_crosshair_shape(cr); |
osd_render_crosshair_shape(cr); |
1559 |
|
|
1560 |
cairo_destroy(cr); |
cairo_destroy(cr); |
|
FOUT; |
|
1561 |
} |
} |
1562 |
#endif |
#endif |
1563 |
|
|
1564 |
#ifdef OSD_SCALE |
#ifdef OSD_SCALE |
1565 |
|
|
1566 |
#ifndef OSD_SCALE_FONT_SIZE |
#ifndef OSD_SCALE_FONT_SIZE |
1567 |
#define OSD_SCALE_FONT_SIZE 12 |
#define OSD_SCALE_FONT_SIZE (12.0) |
1568 |
#endif |
#endif |
1569 |
#define OSD_SCALE_W (10*OSD_SCALE_FONT_SIZE) |
#define OSD_SCALE_W (10*OSD_SCALE_FONT_SIZE) |
1570 |
#define OSD_SCALE_H (5*OSD_SCALE_FONT_SIZE/2) |
#define OSD_SCALE_H (5*OSD_SCALE_FONT_SIZE/2) |
1579 |
static void |
static void |
1580 |
osd_render_scale(osm_gps_map_osd_t *osd) |
osd_render_scale(osm_gps_map_osd_t *osd) |
1581 |
{ |
{ |
|
FIN; |
|
1582 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1583 |
|
|
1584 |
|
if(!priv->scale.surface) |
1585 |
|
return; |
1586 |
|
|
1587 |
/* this only needs to be rendered if the zoom has changed */ |
/* this only needs to be rendered if the zoom has changed */ |
1588 |
gint zoom; |
gint zoom; |
1589 |
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
1595 |
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)); |
1596 |
|
|
1597 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1598 |
|
g_assert(priv->scale.surface); |
1599 |
cairo_t *cr = cairo_create(priv->scale.surface); |
cairo_t *cr = cairo_create(priv->scale.surface); |
1600 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1601 |
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); |
1706 |
cairo_stroke(cr); |
cairo_stroke(cr); |
1707 |
|
|
1708 |
cairo_destroy(cr); |
cairo_destroy(cr); |
|
FOUT; |
|
1709 |
} |
} |
1710 |
#endif |
#endif |
1711 |
|
|
1712 |
static void |
static void |
1713 |
osd_render_controls(osm_gps_map_osd_t *osd) |
osd_render_controls(osm_gps_map_osd_t *osd) |
1714 |
{ |
{ |
|
FIN; |
|
1715 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1716 |
|
|
1717 |
|
if(!priv->controls.surface) |
1718 |
|
return; |
1719 |
|
|
1720 |
if(priv->controls.rendered |
if(priv->controls.rendered |
1721 |
#ifdef OSD_GPS_BUTTON |
#ifdef OSD_GPS_BUTTON |
1722 |
&& (priv->controls.gps_enabled == (osd->cb != NULL)) |
&& (priv->controls.gps_enabled == (osd->cb != NULL)) |
1736 |
#endif |
#endif |
1737 |
|
|
1738 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1739 |
|
g_assert(priv->controls.surface); |
1740 |
cairo_t *cr = cairo_create(priv->controls.surface); |
cairo_t *cr = cairo_create(priv->controls.surface); |
1741 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1742 |
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); |
1989 |
#endif |
#endif |
1990 |
|
|
1991 |
cairo_destroy(cr); |
cairo_destroy(cr); |
|
FOUT; |
|
1992 |
} |
} |
1993 |
|
|
1994 |
static void |
static void |
1995 |
osd_free(osm_gps_map_osd_t *osd) |
osd_free(osm_gps_map_osd_t *osd) |
1996 |
{ |
{ |
|
FIN; |
|
1997 |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
1998 |
|
|
1999 |
if (priv->controls.surface) |
if (priv->controls.surface) |
2032 |
cairo_surface_destroy(priv->balloon.surface); |
cairo_surface_destroy(priv->balloon.surface); |
2033 |
#endif |
#endif |
2034 |
|
|
2035 |
|
printf("freeing priv\n"); |
2036 |
g_free(priv); |
g_free(priv); |
|
FOUT; |
|
2037 |
} |
} |
2038 |
|
|
2039 |
static gboolean |
static gboolean |
2040 |
osd_busy(osm_gps_map_osd_t *osd) |
osd_busy(osm_gps_map_osd_t *osd) |
2041 |
{ |
{ |
|
FIN; |
|
2042 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
2043 |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
2044 |
return (priv->source_sel.handler_id != 0); |
return (priv->source_sel.handler_id != 0); |
2049 |
|
|
2050 |
static osd_button_t |
static osd_button_t |
2051 |
osd_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) { |
osd_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) { |
|
FIN; |
|
2052 |
return osd_check_int(osd, TRUE, down, x, y); |
return osd_check_int(osd, TRUE, down, x, y); |
2053 |
} |
} |
2054 |
|
|
2071 |
void |
void |
2072 |
osm_gps_map_osd_classic_init(OsmGpsMap *map) |
osm_gps_map_osd_classic_init(OsmGpsMap *map) |
2073 |
{ |
{ |
2074 |
FIN; |
osd_priv_t *priv = g_new0(osd_priv_t, 1); |
2075 |
osd_priv_t *priv = osd_classic.priv = g_new0(osd_priv_t, 1); |
printf("alloc new osd priv\n"); |
2076 |
|
|
2077 |
|
/* reset entries to default value */ |
2078 |
|
osd_classic.widget = NULL; |
2079 |
|
osd_classic.cb = NULL; |
2080 |
|
osd_classic.data = NULL; |
2081 |
|
osd_classic.priv = priv; |
2082 |
|
|
2083 |
#ifdef OSD_BALLOON |
#ifdef OSD_BALLOON |
2084 |
priv->balloon.lat = OSM_GPS_MAP_INVALID; |
priv->balloon.lat = OSM_GPS_MAP_INVALID; |
2085 |
priv->balloon.lon = OSM_GPS_MAP_INVALID; |
priv->balloon.lon = OSM_GPS_MAP_INVALID; |
2086 |
#endif |
#endif |
2087 |
|
|
|
osd_classic.priv = priv; |
|
|
|
|
2088 |
osm_gps_map_register_osd(map, &osd_classic); |
osm_gps_map_register_osd(map, &osd_classic); |
|
FOUT; |
|
2089 |
} |
} |
2090 |
|
|
2091 |
#ifdef OSD_GPS_BUTTON |
#ifdef OSD_GPS_BUTTON |
2093 |
/* but instead are to be used by the main application */ |
/* but instead are to be used by the main application */ |
2094 |
void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb, |
void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb, |
2095 |
gpointer data) { |
gpointer data) { |
|
FIN; |
|
2096 |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
2097 |
g_return_if_fail (osd); |
g_return_if_fail (osd); |
2098 |
|
|
2104 |
osd->render(osd); |
osd->render(osd); |
2105 |
|
|
2106 |
osm_gps_map_redraw(map); |
osm_gps_map_redraw(map); |
|
FOUT; |
|
2107 |
} |
} |
2108 |
#endif |
#endif |
2109 |
|
|
2110 |
osd_button_t |
osd_button_t |
2111 |
osm_gps_map_osd_check(OsmGpsMap *map, gint x, gint y) { |
osm_gps_map_osd_check(OsmGpsMap *map, gint x, gint y) { |
|
FIN; |
|
2112 |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
2113 |
g_return_val_if_fail (osd, OSD_NONE); |
g_return_val_if_fail (osd, OSD_NONE); |
2114 |
|
|