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 |
|
gboolean imperial; // display distance imperial/metric |
86 |
|
} nav; |
87 |
|
#endif |
88 |
|
|
89 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
90 |
struct { |
struct { |
91 |
cairo_surface_t *surface; |
cairo_surface_t *surface; |
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__); |
140 |
|
#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 */ |
149 |
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, |
150 |
gboolean bottom, int px, int py, int px0, int px1) { |
gboolean bottom, int px, int py, int px0, int px1) { |
151 |
|
|
152 |
|
FIN; |
153 |
|
|
154 |
cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS); |
cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS); |
155 |
cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS, |
cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS, |
156 |
BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2); |
BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2); |
179 |
BALLOON_CORNER_RADIUS, M_PI/2, M_PI); |
BALLOON_CORNER_RADIUS, M_PI/2, M_PI); |
180 |
|
|
181 |
cairo_close_path (cr); |
cairo_close_path (cr); |
182 |
|
|
183 |
|
FOUT; |
184 |
} |
} |
185 |
|
|
186 |
static void |
static void |
187 |
osd_render_balloon(osm_gps_map_osd_t *osd) { |
osd_render_balloon(osm_gps_map_osd_t *osd) { |
188 |
|
FIN; |
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); |
283 |
cairo_stroke (cr); |
cairo_stroke (cr); |
284 |
|
|
285 |
if (priv->balloon.cb) { |
if (priv->balloon.cb) { |
286 |
|
osm_gps_map_balloon_event_t event; |
287 |
|
|
288 |
/* clip in case application tries to draw in */ |
/* clip in case application tries to draw in */ |
289 |
/* exceed of the balloon */ |
/* exceed of the balloon */ |
290 |
cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y, |
cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y, |
291 |
priv->balloon.rect.w, priv->balloon.rect.h); |
priv->balloon.rect.w, priv->balloon.rect.h); |
292 |
cairo_clip (cr); |
cairo_clip (cr); |
293 |
cairo_new_path (cr); /* current path is not |
cairo_new_path (cr); /* current path is not consumed by cairo_clip */ |
294 |
consumed by cairo_clip() */ |
|
295 |
|
/* request the application to draw the balloon contents */ |
296 |
|
event.type = OSM_GPS_MAP_BALLOON_EVENT_TYPE_DRAW; |
297 |
|
event.data.draw.rect = &priv->balloon.rect; |
298 |
|
event.data.draw.cr = cr; |
299 |
|
|
300 |
priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data); |
priv->balloon.cb(&event, priv->balloon.data); |
301 |
} |
} |
302 |
|
|
303 |
cairo_destroy(cr); |
cairo_destroy(cr); |
304 |
|
|
305 |
|
FOUT; |
306 |
} |
} |
307 |
|
|
308 |
/* return true if balloon is being displayed and if */ |
/* return true if balloon is being displayed and if */ |
309 |
/* the given coordinate is within this balloon */ |
/* the given coordinate is within this balloon */ |
310 |
static gboolean |
static gboolean |
311 |
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) |
312 |
{ |
{ |
313 |
|
FIN; |
314 |
|
|
315 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
316 |
|
|
317 |
if(!priv->balloon.surface) |
if(!priv->balloon.surface) |
322 |
priv->balloon.lat, priv->balloon.lon, |
priv->balloon.lat, priv->balloon.lon, |
323 |
&xs, &ys); |
&xs, &ys); |
324 |
|
|
|
printf("click at %d/%d\n", x, y); |
|
|
|
|
325 |
xs += priv->balloon.rect.x + priv->balloon.offset_x; |
xs += priv->balloon.rect.x + priv->balloon.offset_x; |
326 |
ys += priv->balloon.rect.y + priv->balloon.offset_y; |
ys += priv->balloon.rect.y + priv->balloon.offset_y; |
327 |
|
|
|
printf("balloon at %d/%d/%d/%d\n", |
|
|
xs, ys, |
|
|
xs + priv->balloon.rect.w, |
|
|
ys + priv->balloon.rect.h); |
|
|
|
|
328 |
gboolean is_in = |
gboolean is_in = |
329 |
(x > xs) && (x < xs + priv->balloon.rect.w) && |
(x > xs) && (x < xs + priv->balloon.rect.w) && |
330 |
(y > ys) && (y < ys + priv->balloon.rect.h); |
(y > ys) && (y < ys + priv->balloon.rect.h); |
331 |
|
|
332 |
/* 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? */ |
333 |
/* button down event */ |
if(click) { |
|
if(!is_in && !down && !priv->balloon.just_created) { |
|
|
/* the user actually clicked outside the balloon */ |
|
334 |
|
|
335 |
/* close the balloon! */ |
/* handle the fact that the balloon may have been created by the */ |
336 |
osm_gps_map_osd_clear_balloon (OSM_GPS_MAP(osd->widget)); |
/* button down event */ |
337 |
} |
if(!is_in && !down && !priv->balloon.just_created) { |
338 |
|
/* the user actually clicked outside the balloon */ |
339 |
|
|
340 |
|
/* close the balloon! */ |
341 |
|
osm_gps_map_osd_clear_balloon (OSM_GPS_MAP(osd->widget)); |
342 |
|
|
343 |
|
/* and inform application about this */ |
344 |
|
if(priv->balloon.cb) { |
345 |
|
osm_gps_map_balloon_event_t event; |
346 |
|
event.type = OSM_GPS_MAP_BALLOON_EVENT_TYPE_REMOVED; |
347 |
|
priv->balloon.cb(&event, priv->balloon.data); |
348 |
|
} |
349 |
|
|
350 |
|
} |
351 |
|
|
352 |
|
if(is_in && priv->balloon.cb) { |
353 |
|
osm_gps_map_balloon_event_t event; |
354 |
|
|
355 |
|
/* notify application of click */ |
356 |
|
event.type = OSM_GPS_MAP_BALLOON_EVENT_TYPE_CLICK; |
357 |
|
event.data.click.x = x - xs; |
358 |
|
event.data.click.y = y - ys; |
359 |
|
event.data.click.down = down; |
360 |
|
|
361 |
|
priv->balloon.cb(&event, priv->balloon.data); |
362 |
|
} |
363 |
|
} |
364 |
|
FOUT; |
365 |
return is_in; |
return is_in; |
366 |
} |
} |
367 |
|
|
368 |
void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) { |
void osm_gps_map_osd_clear_balloon (OsmGpsMap *map) { |
369 |
|
FIN; |
370 |
|
|
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); |
383 |
priv->balloon.lon = OSM_GPS_MAP_INVALID; |
priv->balloon.lon = OSM_GPS_MAP_INVALID; |
384 |
} |
} |
385 |
osm_gps_map_redraw(map); |
osm_gps_map_redraw(map); |
386 |
|
FOUT; |
387 |
} |
} |
388 |
|
|
389 |
void |
void |
390 |
osm_gps_map_osd_draw_balloon (OsmGpsMap *map, float latitude, float longitude, |
osm_gps_map_osd_draw_balloon (OsmGpsMap *map, float latitude, float longitude, |
391 |
OsmGpsMapBalloonCallback cb, gpointer data) { |
OsmGpsMapBalloonCallback cb, gpointer data) { |
392 |
|
FIN; |
393 |
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
394 |
|
|
395 |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
416 |
osd_render_balloon(osd); |
osd_render_balloon(osd); |
417 |
|
|
418 |
osm_gps_map_redraw(map); |
osm_gps_map_redraw(map); |
419 |
|
FOUT; |
420 |
} |
} |
421 |
|
|
422 |
#endif // OSD_BALLOON |
#endif // OSD_BALLOON |
561 |
static gboolean |
static gboolean |
562 |
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) |
563 |
{ |
{ |
564 |
|
FIN; |
565 |
return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad); |
return( pow(cx - x, 2) + pow(cy - y, 2) < rad * rad); |
566 |
} |
} |
567 |
|
|
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) |
760 |
|
|
761 |
static void |
static void |
762 |
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) { |
763 |
|
FIN; |
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); |
810 |
cairo_stroke (cr); |
cairo_stroke (cr); |
811 |
|
|
812 |
cairo_destroy(cr); |
cairo_destroy(cr); |
813 |
|
FOUT; |
814 |
} |
} |
815 |
|
|
816 |
/* re-allocate the buffer used to draw the menu. This is used */ |
/* re-allocate the buffer used to draw the menu. This is used */ |
817 |
/* to collapse/expand the buffer */ |
/* to collapse/expand the buffer */ |
818 |
static void |
static void |
819 |
osd_source_reallocate(osm_gps_map_osd_t *osd) { |
osd_source_reallocate(osm_gps_map_osd_t *osd) { |
820 |
|
FIN; |
821 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
822 |
|
|
823 |
/* re-allocate offscreen bitmap */ |
/* re-allocate offscreen bitmap */ |
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, |
859 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2); |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2); |
860 |
|
|
861 |
osd_render_source_sel(osd, TRUE); |
osd_render_source_sel(osd, TRUE); |
862 |
|
FOUT; |
863 |
} |
} |
864 |
|
|
865 |
#define OSD_HZ 15 |
#define OSD_HZ 15 |
866 |
#define OSD_TIME 500 |
#define OSD_TIME 500 |
867 |
|
|
868 |
static gboolean osd_source_animate(gpointer data) { |
static gboolean osd_source_animate(gpointer data) { |
869 |
|
FIN; |
870 |
osm_gps_map_osd_t *osd = (osm_gps_map_osd_t*)data; |
osm_gps_map_osd_t *osd = (osm_gps_map_osd_t*)data; |
871 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
872 |
int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X; |
int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X; |
905 |
if(done) |
if(done) |
906 |
priv->source_sel.handler_id = 0; |
priv->source_sel.handler_id = 0; |
907 |
|
|
908 |
|
FOUT; |
909 |
return !done; |
return !done; |
910 |
} |
} |
911 |
|
|
913 |
static void |
static void |
914 |
osd_source_toggle(osm_gps_map_osd_t *osd) |
osd_source_toggle(osm_gps_map_osd_t *osd) |
915 |
{ |
{ |
916 |
|
FIN; |
917 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
918 |
|
|
919 |
/* ignore clicks while animation is running */ |
/* ignore clicks while animation is running */ |
939 |
/* start timer to handle animation */ |
/* start timer to handle animation */ |
940 |
priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, |
priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, |
941 |
osd_source_animate, osd); |
osd_source_animate, osd); |
942 |
|
FOUT; |
943 |
} |
} |
944 |
|
|
945 |
/* check if the user clicked inside the source selection area */ |
/* check if the user clicked inside the source selection area */ |
946 |
static osd_button_t |
static osd_button_t |
947 |
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) { |
948 |
|
FIN; |
949 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
950 |
|
|
951 |
if(!priv->source_sel.expanded) |
if(!priv->source_sel.expanded) |
1003 |
osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
1004 |
} |
} |
1005 |
} |
} |
1006 |
|
|
1007 |
/* return "clicked in OSD background" to prevent further */ |
/* return "clicked in OSD background" to prevent further */ |
1008 |
/* processing by application */ |
/* processing by application */ |
1009 |
return OSD_BG; |
return OSD_BG; |
1010 |
} |
} |
1011 |
} |
} |
1012 |
|
|
1013 |
|
FOUT; |
1014 |
return OSD_NONE; |
return OSD_NONE; |
1015 |
} |
} |
1016 |
#endif // OSD_SOURCE_SEL |
#endif // OSD_SOURCE_SEL |
1017 |
|
|
1018 |
static osd_button_t |
static osd_button_t |
1019 |
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) { |
1020 |
|
FIN; |
1021 |
osd_button_t but = OSD_NONE; |
osd_button_t but = OSD_NONE; |
1022 |
|
|
1023 |
#ifdef OSD_BALLOON |
#ifdef OSD_BALLOON |
1058 |
#ifdef OSD_BALLOON |
#ifdef OSD_BALLOON |
1059 |
if(but == OSD_NONE) { |
if(but == OSD_NONE) { |
1060 |
/* check if user clicked into balloon */ |
/* check if user clicked into balloon */ |
1061 |
if(osd_balloon_check(osd, down, x, y)) |
if(osd_balloon_check(osd, click, down, x, y)) |
1062 |
but = OSD_BG; |
but = OSD_BG; |
1063 |
} |
} |
1064 |
#endif |
#endif |
1065 |
|
|
1066 |
|
FOUT; |
1067 |
return but; |
return but; |
1068 |
} |
} |
1069 |
|
|
1140 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
1141 |
|
|
1142 |
#ifndef OSD_COORDINATES_FONT_SIZE |
#ifndef OSD_COORDINATES_FONT_SIZE |
1143 |
#define OSD_COORDINATES_FONT_SIZE 12 |
#define OSD_COORDINATES_FONT_SIZE (12.0) |
1144 |
#endif |
#endif |
1145 |
|
|
1146 |
#define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6) |
#define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6) |
1147 |
|
|
1148 |
#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) |
1149 |
#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) |
1150 |
|
|
1151 |
/* these can be overwritten with versions that support */ |
/* these can be overwritten with versions that support */ |
1152 |
/* localization */ |
/* localization */ |
1204 |
c, (int)integral, fractional*60.0); |
c, (int)integral, fractional*60.0); |
1205 |
} |
} |
1206 |
|
|
1207 |
|
/* render a string at the given screen position */ |
1208 |
|
static int |
1209 |
|
osd_render_centered_text(cairo_t *cr, int y, int width, char *text) { |
1210 |
|
FIN; |
1211 |
|
|
1212 |
|
if(!text) return y; |
1213 |
|
|
1214 |
|
char *p = g_malloc(strlen(text)+4); // space for "...\n" |
1215 |
|
strcpy(p, text); |
1216 |
|
|
1217 |
|
cairo_text_extents_t extents; |
1218 |
|
memset(&extents, 0, sizeof(cairo_text_extents_t)); |
1219 |
|
cairo_text_extents (cr, p, &extents); |
1220 |
|
g_assert(extents.width != 0.0); |
1221 |
|
|
1222 |
|
/* check if text needs to be truncated */ |
1223 |
|
int trunc_at = strlen(text); |
1224 |
|
while(extents.width > width) { |
1225 |
|
|
1226 |
|
/* cut off all utf8 multibyte remains so the actual */ |
1227 |
|
/* truncation only deals with one byte */ |
1228 |
|
while((p[trunc_at-1] & 0xc0) == 0x80) { |
1229 |
|
trunc_at--; |
1230 |
|
g_assert(trunc_at > 0); |
1231 |
|
} |
1232 |
|
|
1233 |
|
trunc_at--; |
1234 |
|
g_assert(trunc_at > 0); |
1235 |
|
|
1236 |
|
strcpy(p+trunc_at, "..."); |
1237 |
|
cairo_text_extents (cr, p, &extents); |
1238 |
|
} |
1239 |
|
|
1240 |
|
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); |
1241 |
|
cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6); |
1242 |
|
cairo_move_to (cr, (width - extents.width)/2, y - extents.y_bearing); |
1243 |
|
cairo_text_path (cr, p); |
1244 |
|
cairo_stroke (cr); |
1245 |
|
|
1246 |
|
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); |
1247 |
|
cairo_move_to (cr, (width - extents.width)/2, y - extents.y_bearing); |
1248 |
|
cairo_show_text (cr, p); |
1249 |
|
|
1250 |
|
g_free(p); |
1251 |
|
|
1252 |
|
/* skip + 1/5 line */ |
1253 |
|
FOUT; |
1254 |
|
return y + 6*OSD_COORDINATES_FONT_SIZE/5; |
1255 |
|
} |
1256 |
|
|
1257 |
static void |
static void |
1258 |
osd_render_coordinates(osm_gps_map_osd_t *osd) |
osd_render_coordinates(osm_gps_map_osd_t *osd) |
1259 |
{ |
{ |
1260 |
|
FIN; |
1261 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1262 |
|
|
1263 |
|
if(!priv->coordinates.surface) |
1264 |
|
return; |
1265 |
|
|
1266 |
/* get current map position */ |
/* get current map position */ |
1267 |
gfloat lat, lon; |
gfloat lat, lon; |
1268 |
g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL); |
g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL); |
1278 |
priv->coordinates.lon = lon; |
priv->coordinates.lon = lon; |
1279 |
|
|
1280 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1281 |
|
|
1282 |
|
g_assert(priv->coordinates.surface); |
1283 |
cairo_t *cr = cairo_create(priv->coordinates.surface); |
cairo_t *cr = cairo_create(priv->coordinates.surface); |
1284 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1285 |
// 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); |
1295 |
char *latitude = osd_latitude_str(lat); |
char *latitude = osd_latitude_str(lat); |
1296 |
char *longitude = osd_longitude_str(lon); |
char *longitude = osd_longitude_str(lon); |
1297 |
|
|
1298 |
cairo_text_extents_t lat_extents, lon_extents; |
int y = OSD_COORDINATES_OFFSET; |
1299 |
cairo_text_extents (cr, latitude, &lat_extents); |
y = osd_render_centered_text(cr, y, OSD_COORDINATES_W, latitude); |
1300 |
cairo_text_extents (cr, longitude, &lon_extents); |
y = osd_render_centered_text(cr, y, OSD_COORDINATES_W, longitude); |
1301 |
|
|
1302 |
|
g_free(latitude); |
1303 |
|
g_free(longitude); |
1304 |
|
|
1305 |
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); |
cairo_destroy(cr); |
1306 |
cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6); |
FOUT; |
1307 |
cairo_move_to (cr, |
} |
1308 |
(OSD_COORDINATES_W - lat_extents.width)/2, |
#endif // OSD_COORDINATES |
|
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); |
|
1309 |
|
|
1310 |
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); |
#ifdef OSD_NAV |
1311 |
cairo_move_to (cr, |
#define OSD_NAV_W (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET) |
1312 |
(OSD_COORDINATES_W - lat_extents.width)/2, |
#define OSD_NAV_H (11*OSD_COORDINATES_FONT_SIZE) |
1313 |
OSD_COORDINATES_OFFSET - lat_extents.y_bearing); |
|
1314 |
cairo_show_text (cr, latitude); |
/* http://mathforum.org/library/drmath/view/55417.html */ |
1315 |
cairo_move_to (cr, |
static float get_bearing(float lat1, float lon1, float lat2, float lon2) { |
1316 |
(OSD_COORDINATES_W - lon_extents.width)/2, |
return atan2( sin(lon2 - lon1) * cos(lat2), |
1317 |
OSD_COORDINATES_OFFSET - lon_extents.y_bearing + |
cos(lat1) * sin(lat2) - |
1318 |
OSD_COORDINATES_FONT_SIZE); |
sin(lat1) * cos(lat2) * cos(lon2 - lon1)); |
1319 |
cairo_show_text (cr, longitude); |
} |
1320 |
|
|
1321 |
|
/* http://mathforum.org/library/drmath/view/51722.html */ |
1322 |
|
static float get_distance(float lat1, float lon1, float lat2, float lon2) { |
1323 |
|
float aob = acos(cos(lat1) * cos(lat2) * cos(lon2 - lon1) + |
1324 |
|
sin(lat1) * sin(lat2)); |
1325 |
|
|
1326 |
|
// return(aob * 3959.0); /* great circle radius in miles */ |
1327 |
|
|
1328 |
|
return(aob * 6371000.0); /* great circle radius in meters */ |
1329 |
|
} |
1330 |
|
|
1331 |
|
static void |
1332 |
|
osd_render_nav(osm_gps_map_osd_t *osd) |
1333 |
|
{ |
1334 |
|
FIN; |
1335 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1336 |
|
|
1337 |
|
if(!priv->nav.surface || isnan(priv->nav.lat) || isnan(priv->nav.lon)) |
1338 |
|
return; |
1339 |
|
|
1340 |
|
/* first fill with transparency */ |
1341 |
|
g_assert(priv->nav.surface); |
1342 |
|
cairo_t *cr = cairo_create(priv->nav.surface); |
1343 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1344 |
|
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
1345 |
|
cairo_paint(cr); |
1346 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
1347 |
|
|
1348 |
|
cairo_select_font_face (cr, "Sans", |
1349 |
|
CAIRO_FONT_SLANT_NORMAL, |
1350 |
|
CAIRO_FONT_WEIGHT_BOLD); |
1351 |
|
cairo_set_font_size (cr, OSD_COORDINATES_FONT_SIZE); |
1352 |
|
|
1353 |
|
char *latitude = osd_latitude_str(priv->nav.lat); |
1354 |
|
char *longitude = osd_longitude_str(priv->nav.lon); |
1355 |
|
|
1356 |
|
int y = OSD_COORDINATES_OFFSET; |
1357 |
|
y = osd_render_centered_text(cr, y, OSD_NAV_W, priv->nav.name); |
1358 |
|
y = osd_render_centered_text(cr, y, OSD_NAV_W, latitude); |
1359 |
|
y = osd_render_centered_text(cr, y, OSD_NAV_W, longitude); |
1360 |
|
|
1361 |
g_free(latitude); |
g_free(latitude); |
1362 |
g_free(longitude); |
g_free(longitude); |
1363 |
|
|
1364 |
|
/* draw the compass */ |
1365 |
|
int radius = (OSD_NAV_H - y - 5*OSD_COORDINATES_FONT_SIZE/4)/2; |
1366 |
|
if(radius > OSD_NAV_W/2) |
1367 |
|
radius = OSD_NAV_W/2; |
1368 |
|
|
1369 |
|
int x = OSD_NAV_W/2+1; |
1370 |
|
y += radius; |
1371 |
|
|
1372 |
|
cairo_stroke (cr); |
1373 |
|
|
1374 |
|
/* draw background */ |
1375 |
|
cairo_arc(cr, x, y, radius, 0, 2*M_PI); |
1376 |
|
cairo_set_source_rgba (cr, 1, 1, 1, 0.5); |
1377 |
|
cairo_fill_preserve (cr); |
1378 |
|
cairo_set_source_rgb (cr, 0, 0, 0); |
1379 |
|
cairo_set_line_width (cr, 1); |
1380 |
|
cairo_stroke (cr); |
1381 |
|
|
1382 |
|
/* draw pointer */ |
1383 |
|
#define ARROW_WIDTH 0.3 |
1384 |
|
#define ARROW_LENGTH 0.7 |
1385 |
|
|
1386 |
|
coord_t *gps = osm_gps_map_get_gps (OSM_GPS_MAP(osd->widget)); |
1387 |
|
if(gps) { |
1388 |
|
float arot = get_bearing(gps->rlat, gps->rlon, |
1389 |
|
deg2rad(priv->nav.lat), deg2rad(priv->nav.lon)); |
1390 |
|
|
1391 |
|
cairo_move_to(cr, |
1392 |
|
x + radius * ARROW_LENGTH * sin(arot), |
1393 |
|
y + radius * ARROW_LENGTH * -cos(arot)); |
1394 |
|
|
1395 |
|
cairo_line_to(cr, |
1396 |
|
x + radius * -ARROW_LENGTH * sin(arot+ARROW_WIDTH), |
1397 |
|
y + radius * -ARROW_LENGTH * -cos(arot+ARROW_WIDTH)); |
1398 |
|
|
1399 |
|
cairo_line_to(cr, |
1400 |
|
x + radius * -0.5 * ARROW_LENGTH * sin(arot), |
1401 |
|
y + radius * -0.5 * ARROW_LENGTH * -cos(arot)); |
1402 |
|
|
1403 |
|
cairo_line_to(cr, |
1404 |
|
x + radius * -ARROW_LENGTH * sin(arot-ARROW_WIDTH), |
1405 |
|
y + radius * -ARROW_LENGTH * -cos(arot-ARROW_WIDTH)); |
1406 |
|
|
1407 |
|
cairo_close_path(cr); |
1408 |
|
cairo_set_source_rgb (cr, 0, 0, 0); |
1409 |
|
cairo_fill (cr); |
1410 |
|
|
1411 |
|
y += radius + OSD_COORDINATES_FONT_SIZE/4; |
1412 |
|
|
1413 |
|
float dist = get_distance(gps->rlat, gps->rlon, |
1414 |
|
deg2rad(priv->nav.lat), deg2rad(priv->nav.lon)); |
1415 |
|
|
1416 |
|
char *dist_str = NULL; |
1417 |
|
if(!priv->nav.imperial) { |
1418 |
|
/* metric is easy ... */ |
1419 |
|
if(dist<1000) |
1420 |
|
dist_str = g_strdup_printf("%u m", (int)dist); |
1421 |
|
else |
1422 |
|
dist_str = g_strdup_printf("%.1f km", dist/1000); |
1423 |
|
} else { |
1424 |
|
/* and now the hard part: scale for useful imperial values :-( */ |
1425 |
|
/* try to convert to feet, 1ft == 0.3048 m */ |
1426 |
|
|
1427 |
|
if(dist/(3*0.3048) >= 1760.0) /* more than 1760 yard? */ |
1428 |
|
dist_str = g_strdup_printf("%.1f mi", dist/(0.3048*3*1760.0)); |
1429 |
|
else if(dist/0.3048 >= 100) /* more than 100 feet? */ |
1430 |
|
dist_str = g_strdup_printf("%.1f yd", dist/(0.3048*3)); |
1431 |
|
else |
1432 |
|
dist_str = g_strdup_printf("%.0f ft", dist/0.3048); |
1433 |
|
} |
1434 |
|
|
1435 |
|
y = osd_render_centered_text(cr, y, OSD_NAV_W, dist_str); |
1436 |
|
g_free(dist_str); |
1437 |
|
} |
1438 |
|
|
1439 |
cairo_destroy(cr); |
cairo_destroy(cr); |
1440 |
|
FOUT; |
1441 |
} |
} |
1442 |
#endif // OSD_COORDINATES |
|
1443 |
|
void osm_gps_map_osd_clear_nav (OsmGpsMap *map) { |
1444 |
|
FIN; |
1445 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
1446 |
|
|
1447 |
|
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
1448 |
|
g_return_if_fail (osd); |
1449 |
|
|
1450 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1451 |
|
g_return_if_fail (priv); |
1452 |
|
|
1453 |
|
if(priv->nav.surface) { |
1454 |
|
cairo_surface_destroy(priv->nav.surface); |
1455 |
|
priv->nav.surface = NULL; |
1456 |
|
priv->nav.lat = OSM_GPS_MAP_INVALID; |
1457 |
|
priv->nav.lon = OSM_GPS_MAP_INVALID; |
1458 |
|
if(priv->nav.name) g_free(priv->nav.name); |
1459 |
|
} |
1460 |
|
osm_gps_map_redraw(map); |
1461 |
|
FOUT; |
1462 |
|
} |
1463 |
|
|
1464 |
|
void |
1465 |
|
osm_gps_map_osd_draw_nav (OsmGpsMap *map, gboolean imperial, |
1466 |
|
float latitude, float longitude, char *name) { |
1467 |
|
FIN; |
1468 |
|
g_return_if_fail (OSM_IS_GPS_MAP (map)); |
1469 |
|
|
1470 |
|
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
1471 |
|
g_return_if_fail (osd); |
1472 |
|
|
1473 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1474 |
|
g_return_if_fail (priv); |
1475 |
|
|
1476 |
|
osm_gps_map_osd_clear_nav (map); |
1477 |
|
|
1478 |
|
/* allocate balloon surface */ |
1479 |
|
priv->nav.surface = |
1480 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1481 |
|
OSD_NAV_W+2, OSD_NAV_H+2); |
1482 |
|
|
1483 |
|
priv->nav.lat = latitude; |
1484 |
|
priv->nav.lon = longitude; |
1485 |
|
priv->nav.name = g_strdup(name); |
1486 |
|
priv->nav.imperial = imperial; |
1487 |
|
|
1488 |
|
osd_render_nav(osd); |
1489 |
|
|
1490 |
|
osm_gps_map_redraw(map); |
1491 |
|
FOUT; |
1492 |
|
} |
1493 |
|
|
1494 |
|
#endif // OSD_NAV |
1495 |
|
|
1496 |
|
|
1497 |
#ifdef OSD_CROSSHAIR |
#ifdef OSD_CROSSHAIR |
1498 |
|
|
1507 |
|
|
1508 |
static void |
static void |
1509 |
osd_render_crosshair_shape(cairo_t *cr) { |
osd_render_crosshair_shape(cairo_t *cr) { |
1510 |
|
FIN; |
1511 |
cairo_arc (cr, OSD_CROSSHAIR_W/2, OSD_CROSSHAIR_H/2, |
cairo_arc (cr, OSD_CROSSHAIR_W/2, OSD_CROSSHAIR_H/2, |
1512 |
OSD_CROSSHAIR_RADIUS, 0, 2*M_PI); |
OSD_CROSSHAIR_RADIUS, 0, 2*M_PI); |
1513 |
|
|
1526 |
cairo_rel_line_to (cr, 0, OSD_CROSSHAIR_TICK); |
cairo_rel_line_to (cr, 0, OSD_CROSSHAIR_TICK); |
1527 |
|
|
1528 |
cairo_stroke (cr); |
cairo_stroke (cr); |
1529 |
|
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 |
{ |
{ |
1535 |
|
FIN; |
1536 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1537 |
|
|
1538 |
if(priv->crosshair.rendered) |
if(!priv->crosshair.surface || priv->crosshair.rendered) |
1539 |
return; |
return; |
1540 |
|
|
1541 |
priv->crosshair.rendered = TRUE; |
priv->crosshair.rendered = TRUE; |
1542 |
|
|
1543 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1544 |
|
g_assert(priv->crosshair.surface); |
1545 |
cairo_t *cr = cairo_create(priv->crosshair.surface); |
cairo_t *cr = cairo_create(priv->crosshair.surface); |
1546 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1547 |
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); |
1559 |
osd_render_crosshair_shape(cr); |
osd_render_crosshair_shape(cr); |
1560 |
|
|
1561 |
cairo_destroy(cr); |
cairo_destroy(cr); |
1562 |
|
FOUT; |
1563 |
} |
} |
1564 |
#endif |
#endif |
1565 |
|
|
1566 |
#ifdef OSD_SCALE |
#ifdef OSD_SCALE |
1567 |
|
|
1568 |
#ifndef OSD_SCALE_FONT_SIZE |
#ifndef OSD_SCALE_FONT_SIZE |
1569 |
#define OSD_SCALE_FONT_SIZE 12 |
#define OSD_SCALE_FONT_SIZE (12.0) |
1570 |
#endif |
#endif |
1571 |
#define OSD_SCALE_W (10*OSD_SCALE_FONT_SIZE) |
#define OSD_SCALE_W (10*OSD_SCALE_FONT_SIZE) |
1572 |
#define OSD_SCALE_H (5*OSD_SCALE_FONT_SIZE/2) |
#define OSD_SCALE_H (5*OSD_SCALE_FONT_SIZE/2) |
1581 |
static void |
static void |
1582 |
osd_render_scale(osm_gps_map_osd_t *osd) |
osd_render_scale(osm_gps_map_osd_t *osd) |
1583 |
{ |
{ |
1584 |
|
FIN; |
1585 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1586 |
|
|
1587 |
|
if(!priv->scale.surface) |
1588 |
|
return; |
1589 |
|
|
1590 |
/* this only needs to be rendered if the zoom has changed */ |
/* this only needs to be rendered if the zoom has changed */ |
1591 |
gint zoom; |
gint zoom; |
1592 |
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
1598 |
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)); |
1599 |
|
|
1600 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1601 |
|
g_assert(priv->scale.surface); |
1602 |
cairo_t *cr = cairo_create(priv->scale.surface); |
cairo_t *cr = cairo_create(priv->scale.surface); |
1603 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1604 |
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); |
1709 |
cairo_stroke(cr); |
cairo_stroke(cr); |
1710 |
|
|
1711 |
cairo_destroy(cr); |
cairo_destroy(cr); |
1712 |
|
FOUT; |
1713 |
} |
} |
1714 |
#endif |
#endif |
1715 |
|
|
1716 |
static void |
static void |
1717 |
osd_render_controls(osm_gps_map_osd_t *osd) |
osd_render_controls(osm_gps_map_osd_t *osd) |
1718 |
{ |
{ |
1719 |
|
FIN; |
1720 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1721 |
|
|
1722 |
|
if(!priv->controls.surface) |
1723 |
|
return; |
1724 |
|
|
1725 |
if(priv->controls.rendered |
if(priv->controls.rendered |
1726 |
#ifdef OSD_GPS_BUTTON |
#ifdef OSD_GPS_BUTTON |
1727 |
&& (priv->controls.gps_enabled == (osd->cb != NULL)) |
&& (priv->controls.gps_enabled == (osd->cb != NULL)) |
1741 |
#endif |
#endif |
1742 |
|
|
1743 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1744 |
|
g_assert(priv->controls.surface); |
1745 |
cairo_t *cr = cairo_create(priv->controls.surface); |
cairo_t *cr = cairo_create(priv->controls.surface); |
1746 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1747 |
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); |
1837 |
osd_render_crosshair(osd); |
osd_render_crosshair(osd); |
1838 |
#endif |
#endif |
1839 |
|
|
1840 |
|
#ifdef OSD_NAV |
1841 |
|
osd_render_nav(osd); |
1842 |
|
#endif |
1843 |
|
|
1844 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
1845 |
osd_render_coordinates(osd); |
osd_render_coordinates(osd); |
1846 |
#endif |
#endif |
1920 |
cairo_paint(cr); |
cairo_paint(cr); |
1921 |
#endif |
#endif |
1922 |
|
|
1923 |
|
#ifdef OSD_NAV |
1924 |
|
if(priv->nav.surface) { |
1925 |
|
x = OSD_X; |
1926 |
|
if(x < 0) x += osd->widget->allocation.width - OSD_NAV_W; |
1927 |
|
y = (osd->widget->allocation.height - OSD_NAV_H)/2; |
1928 |
|
|
1929 |
|
cairo_set_source_surface(cr, priv->nav.surface, x, y); |
1930 |
|
cairo_paint(cr); |
1931 |
|
} |
1932 |
|
#endif |
1933 |
|
|
1934 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
1935 |
x = -OSD_X; |
x = -OSD_X; |
1936 |
y = -OSD_Y; |
y = -OSD_Y; |
1994 |
#endif |
#endif |
1995 |
|
|
1996 |
cairo_destroy(cr); |
cairo_destroy(cr); |
1997 |
|
FOUT; |
1998 |
} |
} |
1999 |
|
|
2000 |
static void |
static void |
2001 |
osd_free(osm_gps_map_osd_t *osd) |
osd_free(osm_gps_map_osd_t *osd) |
2002 |
{ |
{ |
2003 |
|
FIN; |
2004 |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
2005 |
|
|
2006 |
if (priv->controls.surface) |
if (priv->controls.surface) |
2024 |
cairo_surface_destroy(priv->crosshair.surface); |
cairo_surface_destroy(priv->crosshair.surface); |
2025 |
#endif |
#endif |
2026 |
|
|
2027 |
|
#ifdef OSD_NAV |
2028 |
|
if (priv->nav.surface) |
2029 |
|
cairo_surface_destroy(priv->nav.surface); |
2030 |
|
#endif |
2031 |
|
|
2032 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
2033 |
if (priv->coordinates.surface) |
if (priv->coordinates.surface) |
2034 |
cairo_surface_destroy(priv->coordinates.surface); |
cairo_surface_destroy(priv->coordinates.surface); |
2040 |
#endif |
#endif |
2041 |
|
|
2042 |
g_free(priv); |
g_free(priv); |
2043 |
|
FOUT; |
2044 |
} |
} |
2045 |
|
|
2046 |
static gboolean |
static gboolean |
2047 |
osd_busy(osm_gps_map_osd_t *osd) |
osd_busy(osm_gps_map_osd_t *osd) |
2048 |
{ |
{ |
2049 |
|
FIN; |
2050 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
2051 |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
2052 |
return (priv->source_sel.handler_id != 0); |
return (priv->source_sel.handler_id != 0); |
2055 |
#endif |
#endif |
2056 |
} |
} |
2057 |
|
|
2058 |
|
static osd_button_t |
2059 |
|
osd_check(osm_gps_map_osd_t *osd, gboolean down, gint x, gint y) { |
2060 |
|
FIN; |
2061 |
|
return osd_check_int(osd, TRUE, down, x, y); |
2062 |
|
} |
2063 |
|
|
2064 |
static osm_gps_map_osd_t osd_classic = { |
static osm_gps_map_osd_t osd_classic = { |
2065 |
.widget = NULL, |
.widget = NULL, |
2066 |
|
|
2080 |
void |
void |
2081 |
osm_gps_map_osd_classic_init(OsmGpsMap *map) |
osm_gps_map_osd_classic_init(OsmGpsMap *map) |
2082 |
{ |
{ |
2083 |
|
FIN; |
2084 |
osd_priv_t *priv = osd_classic.priv = g_new0(osd_priv_t, 1); |
osd_priv_t *priv = osd_classic.priv = g_new0(osd_priv_t, 1); |
2085 |
|
|
2086 |
#ifdef OSD_BALLOON |
#ifdef OSD_BALLOON |
2091 |
osd_classic.priv = priv; |
osd_classic.priv = priv; |
2092 |
|
|
2093 |
osm_gps_map_register_osd(map, &osd_classic); |
osm_gps_map_register_osd(map, &osd_classic); |
2094 |
|
FOUT; |
2095 |
} |
} |
2096 |
|
|
2097 |
#ifdef OSD_GPS_BUTTON |
#ifdef OSD_GPS_BUTTON |
2099 |
/* but instead are to be used by the main application */ |
/* but instead are to be used by the main application */ |
2100 |
void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb, |
void osm_gps_map_osd_enable_gps (OsmGpsMap *map, OsmGpsMapOsdCallback cb, |
2101 |
gpointer data) { |
gpointer data) { |
2102 |
|
FIN; |
2103 |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
2104 |
g_return_if_fail (osd); |
g_return_if_fail (osd); |
2105 |
|
|
2111 |
osd->render(osd); |
osd->render(osd); |
2112 |
|
|
2113 |
osm_gps_map_redraw(map); |
osm_gps_map_redraw(map); |
2114 |
|
FOUT; |
2115 |
} |
} |
2116 |
#endif |
#endif |
2117 |
|
|
2118 |
osd_button_t |
osd_button_t |
2119 |
osm_gps_map_osd_check(OsmGpsMap *map, gint x, gint y) { |
osm_gps_map_osd_check(OsmGpsMap *map, gint x, gint y) { |
2120 |
|
FIN; |
2121 |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
osm_gps_map_osd_t *osd = osm_gps_map_osd_get(map); |
2122 |
g_return_val_if_fail (osd, OSD_NONE); |
g_return_val_if_fail (osd, OSD_NONE); |
2123 |
|
|
2124 |
return osd_check(osd, TRUE, x, y); |
return osd_check_int(osd, FALSE, TRUE, x, y); |
2125 |
} |
} |