39 |
/* the offscreen representation of the OSD */ |
/* the offscreen representation of the OSD */ |
40 |
cairo_surface_t *overlay; |
cairo_surface_t *overlay; |
41 |
|
|
42 |
|
#ifdef OSD_SCALE |
43 |
|
cairo_surface_t *scale; |
44 |
|
int scale_zoom; |
45 |
|
#endif |
46 |
|
|
47 |
|
#ifdef OSD_CROSSHAIR |
48 |
|
cairo_surface_t *crosshair; |
49 |
|
#endif |
50 |
|
|
51 |
|
#ifdef OSD_COORDINATES |
52 |
|
cairo_surface_t *coordinates; |
53 |
|
#endif |
54 |
|
|
55 |
|
#ifdef OSD_SOURCE_SEL |
56 |
/* values to handle the "source" menu */ |
/* values to handle the "source" menu */ |
57 |
cairo_surface_t *map_source; |
cairo_surface_t *map_source; |
58 |
gboolean expanded; |
gboolean expanded; |
59 |
gint shift, dir, count; |
gint shift, dir, count; |
60 |
gint handler_id; |
gint handler_id; |
61 |
gint width, height; |
gint width, height; |
62 |
|
#endif |
63 |
|
|
64 |
} osd_priv_t; |
} osd_priv_t; |
65 |
|
|
273 |
return OSD_NONE; |
return OSD_NONE; |
274 |
} |
} |
275 |
|
|
276 |
|
#ifdef OSD_SOURCE_SEL |
277 |
|
|
278 |
/* place source selection at right border */ |
/* place source selection at right border */ |
279 |
#define OSD_S_RAD (Z_RAD) |
#define OSD_S_RAD (Z_RAD) |
280 |
#define OSD_S_X (-OSD_X) |
#define OSD_S_X (-OSD_X) |
298 |
#define OSD_TEXT_BORDER (OSD_FONT_SIZE/2) |
#define OSD_TEXT_BORDER (OSD_FONT_SIZE/2) |
299 |
#define OSD_TEXT_SKIP (OSD_FONT_SIZE/8) |
#define OSD_TEXT_SKIP (OSD_FONT_SIZE/8) |
300 |
|
|
301 |
|
/* draw the shape of the source selection OSD, either only the puller (not expanded) */ |
302 |
|
/* or the entire menu incl. the puller (expanded) */ |
303 |
static void |
static void |
304 |
osd_source_shape(osd_priv_t *priv, cairo_t *cr, gint x, gint y) { |
osd_source_shape(osd_priv_t *priv, cairo_t *cr, gint x, gint y) { |
305 |
if(!priv->expanded) { |
if(!priv->expanded) { |
355 |
CAIRO_FONT_WEIGHT_BOLD); |
CAIRO_FONT_WEIGHT_BOLD); |
356 |
cairo_set_font_size (cr, OSD_FONT_SIZE); |
cairo_set_font_size (cr, OSD_FONT_SIZE); |
357 |
|
|
358 |
int i, step = (priv->height - 2*OSD_TEXT_BORDER) |
int i, step = (priv->height - 2*OSD_TEXT_BORDER) / |
359 |
/ OSM_GPS_MAP_SOURCE_LAST; |
OSM_GPS_MAP_SOURCE_LAST; |
360 |
for(i=OSM_GPS_MAP_SOURCE_NULL+1;i<=OSM_GPS_MAP_SOURCE_LAST;i++) { |
for(i=OSM_GPS_MAP_SOURCE_NULL+1;i<=OSM_GPS_MAP_SOURCE_LAST;i++) { |
361 |
cairo_text_extents_t extents; |
cairo_text_extents_t extents; |
362 |
const char *src = osm_gps_map_source_get_friendly_name(i); |
const char *src = osm_gps_map_source_get_friendly_name(i); |
444 |
cairo_destroy(cr); |
cairo_destroy(cr); |
445 |
} |
} |
446 |
|
|
447 |
|
/* re-allocate the buffer used to draw the menu. This is used */ |
448 |
|
/* to collapse/expand the buffer */ |
449 |
static void |
static void |
450 |
osd_source_reallocate(osm_gps_map_osd_t *osd) { |
osd_source_reallocate(osm_gps_map_osd_t *osd) { |
451 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
455 |
|
|
456 |
int w = OSD_S_W, h = OSD_S_H; |
int w = OSD_S_W, h = OSD_S_H; |
457 |
if(priv->expanded) { |
if(priv->expanded) { |
|
/* ... and right of it the waypoint id */ |
|
458 |
cairo_text_extents_t extents; |
cairo_text_extents_t extents; |
459 |
|
|
460 |
/* determine content size */ |
/* determine content size */ |
470 |
const char *src = osm_gps_map_source_get_friendly_name(i); |
const char *src = osm_gps_map_source_get_friendly_name(i); |
471 |
cairo_text_extents (cr, src, &extents); |
cairo_text_extents (cr, src, &extents); |
472 |
|
|
|
// printf("Source %d: %s = %f %f\n", i, src, |
|
|
// extents.width, extents.height); |
|
|
|
|
473 |
if(extents.width > max_w) max_w = extents.width; |
if(extents.width > max_w) max_w = extents.width; |
474 |
if(extents.height > max_h) max_h = extents.height; |
if(extents.height > max_h) max_h = extents.height; |
475 |
} |
} |
488 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2); |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2); |
489 |
|
|
490 |
osd_render_source_sel(osd); |
osd_render_source_sel(osd); |
|
|
|
491 |
} |
} |
492 |
|
|
493 |
#define OSD_HZ 15 |
#define OSD_HZ 15 |
519 |
|
|
520 |
/* count runs linearly from 0 to 1000, map this nicely onto a position */ |
/* count runs linearly from 0 to 1000, map this nicely onto a position */ |
521 |
|
|
|
/* simple linear mapping */ |
|
|
// priv->shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) + |
|
|
// (diff * priv->count)/1000; |
|
|
|
|
522 |
/* nicer sinoid mapping */ |
/* nicer sinoid mapping */ |
523 |
float m = 0.5-cos(priv->count * M_PI / 1000.0)/2; |
float m = 0.5-cos(priv->count * M_PI / 1000.0)/2; |
524 |
priv->shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) + |
priv->shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) + |
559 |
priv->handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, osd_source_animate, osd); |
priv->handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, osd_source_animate, osd); |
560 |
} |
} |
561 |
|
|
562 |
|
/* check if the user clicked inside the source selection area */ |
563 |
static osd_button_t |
static osd_button_t |
564 |
osd_source_check(osm_gps_map_osd_t *osd, gint x, gint y) { |
osd_source_check(osm_gps_map_osd_t *osd, gint x, gint y) { |
565 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
586 |
return OSD_BG; |
return OSD_BG; |
587 |
} |
} |
588 |
} |
} |
589 |
|
|
590 |
|
/* check for clicks into data area */ |
591 |
|
if(priv->expanded && !priv->handler_id) { |
592 |
|
/* re-adjust from puller top to content top */ |
593 |
|
if(OSD_S_Y < 0) |
594 |
|
y += OSD_S_EXP_H - OSD_S_PH; |
595 |
|
|
596 |
|
if(x > OSD_S_PW && |
597 |
|
x < OSD_S_PW + OSD_S_EXP_W && |
598 |
|
y > 0 && |
599 |
|
y < OSD_S_EXP_H) { |
600 |
|
|
601 |
|
int step = (priv->height - 2*OSD_TEXT_BORDER) |
602 |
|
/ OSM_GPS_MAP_SOURCE_LAST; |
603 |
|
|
604 |
|
y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP; |
605 |
|
y /= step; |
606 |
|
y += 1; |
607 |
|
|
608 |
|
gint old = 0; |
609 |
|
g_object_get(osd->widget, "map-source", &old, NULL); |
610 |
|
|
611 |
|
if(y > OSM_GPS_MAP_SOURCE_NULL && |
612 |
|
y <= OSM_GPS_MAP_SOURCE_LAST && |
613 |
|
old != y) { |
614 |
|
g_object_set(osd->widget, "map-source", y, NULL); |
615 |
|
|
616 |
|
osd_render_source_sel(osd); |
617 |
|
osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
618 |
|
} |
619 |
|
|
620 |
|
/* return "clicked in OSD background" to prevent further */ |
621 |
|
/* processing by application */ |
622 |
|
return OSD_BG; |
623 |
|
} |
624 |
|
} |
625 |
|
|
626 |
return OSD_NONE; |
return OSD_NONE; |
627 |
} |
} |
628 |
|
#endif // OSD_SOURCE_SEL |
629 |
|
|
630 |
static osd_button_t |
static osd_button_t |
631 |
osd_check(osm_gps_map_osd_t *osd, gint x, gint y) { |
osd_check(osm_gps_map_osd_t *osd, gint x, gint y) { |
731 |
cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID); |
cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID); |
732 |
} |
} |
733 |
|
|
734 |
|
#ifdef OSD_COORDINATES |
735 |
|
|
736 |
|
#ifndef OSD_COORDINATES_FONT_SIZE |
737 |
|
#define OSD_COORDINATES_FONT_SIZE 12 |
738 |
|
#endif |
739 |
|
|
740 |
|
#define OSD_COORDINATES_W (9*OSD_COORDINATES_FONT_SIZE) |
741 |
|
#define OSD_COORDINATES_H (2*OSD_COORDINATES_FONT_SIZE) |
742 |
|
|
743 |
|
/* these can be overwritten with versions that support */ |
744 |
|
/* localization */ |
745 |
|
#ifndef OSD_COORDINATES_CHR_N |
746 |
|
#define OSD_COORDINATES_CHR_N "N" |
747 |
|
#endif |
748 |
|
#ifndef OSD_COORDINATES_CHR_S |
749 |
|
#define OSD_COORDINATES_CHR_S "S" |
750 |
|
#endif |
751 |
|
#ifndef OSD_COORDINATES_CHR_E |
752 |
|
#define OSD_COORDINATES_CHR_E "E" |
753 |
|
#endif |
754 |
|
#ifndef OSD_COORDINATES_CHR_W |
755 |
|
#define OSD_COORDINATES_CHR_W "W" |
756 |
|
#endif |
757 |
|
|
758 |
|
|
759 |
|
|
760 |
|
/* this is the classic geocaching notation */ |
761 |
|
static char |
762 |
|
*osd_latitude_str(float latitude) { |
763 |
|
char *c = OSD_COORDINATES_CHR_N; |
764 |
|
float integral, fractional; |
765 |
|
|
766 |
|
if(isnan(latitude)) |
767 |
|
return NULL; |
768 |
|
|
769 |
|
if(latitude < 0) { |
770 |
|
latitude = fabs(latitude); |
771 |
|
c = OSD_COORDINATES_CHR_S; |
772 |
|
} |
773 |
|
|
774 |
|
fractional = modff(latitude, &integral); |
775 |
|
|
776 |
|
return g_strdup_printf("%s %02d° %06.3f'", |
777 |
|
c, (int)integral, fractional*60.0); |
778 |
|
} |
779 |
|
|
780 |
|
static char |
781 |
|
*osd_longitude_str(float longitude) { |
782 |
|
char *c = OSD_COORDINATES_CHR_E; |
783 |
|
float integral, fractional; |
784 |
|
|
785 |
|
if(isnan(longitude)) |
786 |
|
return NULL; |
787 |
|
|
788 |
|
if(longitude < 0) { |
789 |
|
longitude = fabs(longitude); |
790 |
|
c = OSD_COORDINATES_CHR_W; |
791 |
|
} |
792 |
|
|
793 |
|
fractional = modff(longitude, &integral); |
794 |
|
|
795 |
|
return g_strdup_printf("%s %03d° %06.3f'", |
796 |
|
c, (int)integral, fractional*60.0); |
797 |
|
} |
798 |
|
|
799 |
|
#define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6) |
800 |
|
|
801 |
|
static void |
802 |
|
osd_render_coordinates(osm_gps_map_osd_t *osd) |
803 |
|
{ |
804 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
805 |
|
|
806 |
|
/* get current map position */ |
807 |
|
gfloat lat, lon; |
808 |
|
g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL); |
809 |
|
|
810 |
|
/* first fill with transparency */ |
811 |
|
cairo_t *cr = cairo_create(priv->coordinates); |
812 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
813 |
|
// cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); |
814 |
|
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2); |
815 |
|
cairo_paint(cr); |
816 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
817 |
|
|
818 |
|
cairo_select_font_face (cr, "Sans", |
819 |
|
CAIRO_FONT_SLANT_NORMAL, |
820 |
|
CAIRO_FONT_WEIGHT_BOLD); |
821 |
|
cairo_set_font_size (cr, OSD_COORDINATES_FONT_SIZE); |
822 |
|
|
823 |
|
char *latitude = osd_latitude_str(lat); |
824 |
|
char *longitude = osd_longitude_str(lon); |
825 |
|
|
826 |
|
cairo_text_extents_t lat_extents, lon_extents; |
827 |
|
cairo_text_extents (cr, latitude, &lat_extents); |
828 |
|
cairo_text_extents (cr, longitude, &lon_extents); |
829 |
|
|
830 |
|
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); |
831 |
|
cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6); |
832 |
|
cairo_move_to (cr, |
833 |
|
OSD_COORDINATES_OFFSET - lat_extents.x_bearing, |
834 |
|
OSD_COORDINATES_OFFSET - lat_extents.y_bearing); |
835 |
|
cairo_text_path (cr, latitude); |
836 |
|
cairo_move_to (cr, |
837 |
|
OSD_COORDINATES_OFFSET - lon_extents.x_bearing, |
838 |
|
OSD_COORDINATES_OFFSET - lon_extents.y_bearing + |
839 |
|
OSD_COORDINATES_FONT_SIZE); |
840 |
|
cairo_text_path (cr, longitude); |
841 |
|
cairo_stroke (cr); |
842 |
|
|
843 |
|
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); |
844 |
|
cairo_move_to (cr, |
845 |
|
OSD_COORDINATES_OFFSET - lat_extents.x_bearing, |
846 |
|
OSD_COORDINATES_OFFSET - lat_extents.y_bearing); |
847 |
|
cairo_show_text (cr, latitude); |
848 |
|
cairo_move_to (cr, |
849 |
|
OSD_COORDINATES_OFFSET - lon_extents.x_bearing, |
850 |
|
OSD_COORDINATES_OFFSET - lon_extents.y_bearing + |
851 |
|
OSD_COORDINATES_FONT_SIZE); |
852 |
|
cairo_show_text (cr, longitude); |
853 |
|
|
854 |
|
g_free(latitude); |
855 |
|
g_free(longitude); |
856 |
|
|
857 |
|
cairo_destroy(cr); |
858 |
|
} |
859 |
|
#endif // OSD_COORDINATES |
860 |
|
|
861 |
|
#ifdef OSD_CROSSHAIR |
862 |
|
|
863 |
|
#ifndef OSD_CROSSHAIR_RADIUS |
864 |
|
#define OSD_CROSSHAIR_RADIUS 10 |
865 |
|
#endif |
866 |
|
|
867 |
|
#define OSD_CROSSHAIR_TICK (OSD_CROSSHAIR_RADIUS/2) |
868 |
|
#define OSD_CROSSHAIR_BORDER (OSD_CROSSHAIR_TICK + OSD_CROSSHAIR_RADIUS/4) |
869 |
|
#define OSD_CROSSHAIR_W ((OSD_CROSSHAIR_RADIUS+OSD_CROSSHAIR_BORDER)*2) |
870 |
|
#define OSD_CROSSHAIR_H ((OSD_CROSSHAIR_RADIUS+OSD_CROSSHAIR_BORDER)*2) |
871 |
|
|
872 |
|
static void |
873 |
|
osd_render_crosshair_shape(cairo_t *cr) { |
874 |
|
cairo_arc (cr, OSD_CROSSHAIR_W/2, OSD_CROSSHAIR_H/2, |
875 |
|
OSD_CROSSHAIR_RADIUS, 0, 2*M_PI); |
876 |
|
|
877 |
|
cairo_move_to (cr, OSD_CROSSHAIR_W/2 - OSD_CROSSHAIR_RADIUS, |
878 |
|
OSD_CROSSHAIR_H/2); |
879 |
|
cairo_rel_line_to (cr, -OSD_CROSSHAIR_TICK, 0); |
880 |
|
cairo_move_to (cr, OSD_CROSSHAIR_W/2 + OSD_CROSSHAIR_RADIUS, |
881 |
|
OSD_CROSSHAIR_H/2); |
882 |
|
cairo_rel_line_to (cr, OSD_CROSSHAIR_TICK, 0); |
883 |
|
|
884 |
|
cairo_move_to (cr, OSD_CROSSHAIR_W/2, |
885 |
|
OSD_CROSSHAIR_H/2 - OSD_CROSSHAIR_RADIUS); |
886 |
|
cairo_rel_line_to (cr, 0, -OSD_CROSSHAIR_TICK); |
887 |
|
cairo_move_to (cr, OSD_CROSSHAIR_W/2, |
888 |
|
OSD_CROSSHAIR_H/2 + OSD_CROSSHAIR_RADIUS); |
889 |
|
cairo_rel_line_to (cr, 0, OSD_CROSSHAIR_TICK); |
890 |
|
|
891 |
|
cairo_stroke (cr); |
892 |
|
} |
893 |
|
|
894 |
|
static void |
895 |
|
osd_render_crosshair(osm_gps_map_osd_t *osd) |
896 |
|
{ |
897 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
898 |
|
|
899 |
|
/* first fill with transparency */ |
900 |
|
cairo_t *cr = cairo_create(priv->crosshair); |
901 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
902 |
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); |
903 |
|
// cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2); |
904 |
|
cairo_paint(cr); |
905 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
906 |
|
|
907 |
|
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); |
908 |
|
|
909 |
|
cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.5); |
910 |
|
cairo_set_line_width (cr, OSD_CROSSHAIR_RADIUS/2); |
911 |
|
osd_render_crosshair_shape(cr); |
912 |
|
|
913 |
|
cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.5); |
914 |
|
cairo_set_line_width (cr, OSD_CROSSHAIR_RADIUS/4); |
915 |
|
osd_render_crosshair_shape(cr); |
916 |
|
|
917 |
|
cairo_destroy(cr); |
918 |
|
} |
919 |
|
#endif |
920 |
|
|
921 |
|
#ifdef OSD_SCALE |
922 |
|
|
923 |
|
#ifndef OSD_SCALE_FONT_SIZE |
924 |
|
#define OSD_SCALE_FONT_SIZE 12 |
925 |
|
#endif |
926 |
|
#define OSD_SCALE_W (10*OSD_SCALE_FONT_SIZE) |
927 |
|
#define OSD_SCALE_H (5*OSD_SCALE_FONT_SIZE/2) |
928 |
|
|
929 |
|
/* various parameters used to create the scale */ |
930 |
|
#define OSD_SCALE_H2 (OSD_SCALE_H/2) |
931 |
|
#define OSD_SCALE_TICK (2*OSD_SCALE_FONT_SIZE/3) |
932 |
|
#define OSD_SCALE_M (OSD_SCALE_H2 - OSD_SCALE_TICK) |
933 |
|
#define OSD_SCALE_I (OSD_SCALE_H2 + OSD_SCALE_TICK) |
934 |
|
#define OSD_SCALE_FD (OSD_SCALE_FONT_SIZE/4) |
935 |
|
|
936 |
static void |
static void |
937 |
osd_render(osm_gps_map_osd_t *osd) { |
osd_render_scale(osm_gps_map_osd_t *osd) |
938 |
|
{ |
939 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
940 |
|
|
941 |
|
/* this only needs to be rendered if the zoom has changed */ |
942 |
|
gint zoom; |
943 |
|
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
944 |
|
if(zoom == priv->scale_zoom) |
945 |
|
return; |
946 |
|
|
947 |
|
priv->scale_zoom = zoom; |
948 |
|
|
949 |
|
float m_per_pix = osm_gps_map_get_scale(OSM_GPS_MAP(osd->widget)); |
950 |
|
|
951 |
|
/* first fill with transparency */ |
952 |
|
cairo_t *cr = cairo_create(priv->scale); |
953 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
954 |
|
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
955 |
|
// pink for testing: cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2); |
956 |
|
cairo_paint(cr); |
957 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
958 |
|
|
959 |
|
/* determine the size of the scale width in meters */ |
960 |
|
float width = (OSD_SCALE_W-OSD_SCALE_FONT_SIZE/6) * m_per_pix; |
961 |
|
|
962 |
|
/* scale this to useful values */ |
963 |
|
int exp = logf(width)*M_LOG10E; |
964 |
|
int mant = width/pow(10,exp); |
965 |
|
int width_metric = mant * pow(10,exp); |
966 |
|
char *dist_str = NULL; |
967 |
|
if(width_metric<1000) |
968 |
|
dist_str = g_strdup_printf("%u m", width_metric); |
969 |
|
else |
970 |
|
dist_str = g_strdup_printf("%u km", width_metric/1000); |
971 |
|
width_metric /= m_per_pix; |
972 |
|
|
973 |
|
/* and now the hard part: scale for useful imperial values :-( */ |
974 |
|
/* try to convert to feet, 1ft == 0.3048 m */ |
975 |
|
width /= 0.3048; |
976 |
|
float imp_scale = 0.3048; |
977 |
|
char *dist_imp_unit = "ft"; |
978 |
|
|
979 |
|
if(width >= 100) { |
980 |
|
/* 1yd == 3 feet */ |
981 |
|
width /= 3.0; |
982 |
|
imp_scale *= 3.0; |
983 |
|
dist_imp_unit = "yd"; |
984 |
|
|
985 |
|
if(width >= 1760.0) { |
986 |
|
/* 1mi == 1760 yd */ |
987 |
|
width /= 1760.0; |
988 |
|
imp_scale *= 1760.0; |
989 |
|
dist_imp_unit = "mi"; |
990 |
|
} |
991 |
|
} |
992 |
|
|
993 |
|
/* also convert this to full tens/hundreds */ |
994 |
|
exp = logf(width)*M_LOG10E; |
995 |
|
mant = width/pow(10,exp); |
996 |
|
int width_imp = mant * pow(10,exp); |
997 |
|
char *dist_str_imp = g_strdup_printf("%u %s", width_imp, dist_imp_unit); |
998 |
|
|
999 |
|
/* convert back to pixels */ |
1000 |
|
width_imp *= imp_scale; |
1001 |
|
width_imp /= m_per_pix; |
1002 |
|
|
1003 |
|
cairo_select_font_face (cr, "Sans", |
1004 |
|
CAIRO_FONT_SLANT_NORMAL, |
1005 |
|
CAIRO_FONT_WEIGHT_BOLD); |
1006 |
|
cairo_set_font_size (cr, OSD_SCALE_FONT_SIZE); |
1007 |
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0); |
1008 |
|
|
1009 |
|
cairo_text_extents_t extents; |
1010 |
|
cairo_text_extents (cr, dist_str, &extents); |
1011 |
|
|
1012 |
|
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); |
1013 |
|
cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/6); |
1014 |
|
cairo_move_to (cr, 2*OSD_SCALE_FD, OSD_SCALE_H2-OSD_SCALE_FD); |
1015 |
|
cairo_text_path (cr, dist_str); |
1016 |
|
cairo_stroke (cr); |
1017 |
|
cairo_move_to (cr, 2*OSD_SCALE_FD, |
1018 |
|
OSD_SCALE_H2+OSD_SCALE_FD + extents.height); |
1019 |
|
cairo_text_path (cr, dist_str_imp); |
1020 |
|
cairo_stroke (cr); |
1021 |
|
|
1022 |
|
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); |
1023 |
|
cairo_move_to (cr, 2*OSD_SCALE_FD, OSD_SCALE_H2-OSD_SCALE_FD); |
1024 |
|
cairo_show_text (cr, dist_str); |
1025 |
|
cairo_move_to (cr, 2*OSD_SCALE_FD, |
1026 |
|
OSD_SCALE_H2+OSD_SCALE_FD + extents.height); |
1027 |
|
cairo_show_text (cr, dist_str_imp); |
1028 |
|
|
1029 |
|
g_free(dist_str); |
1030 |
|
g_free(dist_str_imp); |
1031 |
|
|
1032 |
|
/* draw white line */ |
1033 |
|
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); |
1034 |
|
cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0); |
1035 |
|
cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/3); |
1036 |
|
cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_M); |
1037 |
|
cairo_rel_line_to (cr, 0, OSD_SCALE_TICK); |
1038 |
|
cairo_rel_line_to (cr, width_metric, 0); |
1039 |
|
cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK); |
1040 |
|
cairo_stroke(cr); |
1041 |
|
cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_I); |
1042 |
|
cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK); |
1043 |
|
cairo_rel_line_to (cr, width_imp, 0); |
1044 |
|
cairo_rel_line_to (cr, 0, +OSD_SCALE_TICK); |
1045 |
|
cairo_stroke(cr); |
1046 |
|
|
1047 |
|
/* draw black line */ |
1048 |
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0); |
1049 |
|
cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/6); |
1050 |
|
cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_M); |
1051 |
|
cairo_rel_line_to (cr, 0, OSD_SCALE_TICK); |
1052 |
|
cairo_rel_line_to (cr, width_metric, 0); |
1053 |
|
cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK); |
1054 |
|
cairo_stroke(cr); |
1055 |
|
cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_I); |
1056 |
|
cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK); |
1057 |
|
cairo_rel_line_to (cr, width_imp, 0); |
1058 |
|
cairo_rel_line_to (cr, 0, +OSD_SCALE_TICK); |
1059 |
|
cairo_stroke(cr); |
1060 |
|
|
1061 |
|
cairo_destroy(cr); |
1062 |
|
} |
1063 |
|
#endif |
1064 |
|
|
1065 |
|
static void |
1066 |
|
osd_render(osm_gps_map_osd_t *osd) |
1067 |
|
{ |
1068 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1069 |
|
|
1070 |
#ifndef OSD_COLOR |
#ifndef OSD_COLOR |
1146 |
|
|
1147 |
cairo_destroy(cr); |
cairo_destroy(cr); |
1148 |
|
|
1149 |
|
#ifdef OSD_SOURCE_SEL |
1150 |
osd_render_source_sel(osd); |
osd_render_source_sel(osd); |
1151 |
|
#endif |
1152 |
|
|
1153 |
|
#ifdef OSD_SCALE |
1154 |
|
osd_render_scale(osd); |
1155 |
|
#endif |
1156 |
|
|
1157 |
|
#ifdef OSD_CROSSHAIR |
1158 |
|
osd_render_crosshair(osd); |
1159 |
|
#endif |
1160 |
|
|
1161 |
|
#ifdef OSD_COORDINATES |
1162 |
|
osd_render_coordinates(osd); |
1163 |
|
#endif |
1164 |
} |
} |
1165 |
|
|
1166 |
static void |
static void |
1175 |
priv->overlay = |
priv->overlay = |
1176 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W+2, OSD_H+2); |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, OSD_W+2, OSD_H+2); |
1177 |
|
|
1178 |
|
#ifdef OSD_SOURCE_SEL |
1179 |
/* the initial OSD state is alway not-expanded */ |
/* the initial OSD state is alway not-expanded */ |
1180 |
priv->map_source = |
priv->map_source = |
1181 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1182 |
OSD_S_W+2, OSD_S_H+2); |
OSD_S_W+2, OSD_S_H+2); |
1183 |
|
#endif |
1184 |
|
|
1185 |
|
#ifdef OSD_SCALE |
1186 |
|
priv->scale = |
1187 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1188 |
|
OSD_SCALE_W, OSD_SCALE_H); |
1189 |
|
priv->scale_zoom = -1; |
1190 |
|
#endif |
1191 |
|
|
1192 |
|
#ifdef OSD_CROSSHAIR |
1193 |
|
priv->crosshair = |
1194 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1195 |
|
OSD_CROSSHAIR_W, OSD_CROSSHAIR_H); |
1196 |
|
#endif |
1197 |
|
|
1198 |
|
#ifdef OSD_COORDINATES |
1199 |
|
priv->coordinates = |
1200 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1201 |
|
OSD_COORDINATES_W, OSD_COORDINATES_H); |
1202 |
|
#endif |
1203 |
|
|
1204 |
/* ... and render it */ |
/* ... and render it */ |
1205 |
osd_render(osd); |
osd_render(osd); |
1208 |
// now draw this onto the original context |
// now draw this onto the original context |
1209 |
cairo_t *cr = gdk_cairo_create(drawable); |
cairo_t *cr = gdk_cairo_create(drawable); |
1210 |
|
|
1211 |
int x = OSD_X, y = OSD_Y; |
int x, y; |
|
if(OSD_X < 0) |
|
|
x = osd->widget->allocation.width - OSD_W + OSD_X; |
|
1212 |
|
|
1213 |
if(OSD_Y < 0) |
#ifdef OSD_SCALE |
1214 |
y = osd->widget->allocation.height - OSD_H + OSD_Y; |
x = OSD_X; |
1215 |
|
y = -OSD_Y; |
1216 |
|
if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W; |
1217 |
|
if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H; |
1218 |
|
|
1219 |
|
cairo_set_source_surface(cr, priv->scale, x, y); |
1220 |
|
cairo_paint(cr); |
1221 |
|
#endif |
1222 |
|
|
1223 |
|
#ifdef OSD_CROSSHAIR |
1224 |
|
x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2; |
1225 |
|
y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2; |
1226 |
|
|
1227 |
|
cairo_set_source_surface(cr, priv->crosshair, x, y); |
1228 |
|
cairo_paint(cr); |
1229 |
|
#endif |
1230 |
|
|
1231 |
|
#ifdef OSD_COORDINATES |
1232 |
|
x = -OSD_X; |
1233 |
|
y = -OSD_Y; |
1234 |
|
if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W; |
1235 |
|
if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H; |
1236 |
|
|
1237 |
|
cairo_set_source_surface(cr, priv->coordinates, x, y); |
1238 |
|
cairo_paint(cr); |
1239 |
|
#endif |
1240 |
|
|
1241 |
|
x = OSD_X; |
1242 |
|
if(x < 0) |
1243 |
|
x += osd->widget->allocation.width - OSD_W; |
1244 |
|
|
1245 |
|
y = OSD_Y; |
1246 |
|
if(y < 0) |
1247 |
|
y += osd->widget->allocation.height - OSD_H; |
1248 |
|
|
1249 |
cairo_set_source_surface(cr, priv->overlay, x, y); |
cairo_set_source_surface(cr, priv->overlay, x, y); |
1250 |
cairo_paint(cr); |
cairo_paint(cr); |
1279 |
{ |
{ |
1280 |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
1281 |
|
|
|
if(priv->handler_id) |
|
|
gtk_timeout_remove(priv->handler_id); |
|
|
|
|
1282 |
if (priv->overlay) |
if (priv->overlay) |
1283 |
cairo_surface_destroy(priv->overlay); |
cairo_surface_destroy(priv->overlay); |
1284 |
|
|
1285 |
|
#ifdef OSD_SOURCE_SEL |
1286 |
|
if(priv->handler_id) |
1287 |
|
gtk_timeout_remove(priv->handler_id); |
1288 |
|
|
1289 |
if (priv->map_source) |
if (priv->map_source) |
1290 |
cairo_surface_destroy(priv->map_source); |
cairo_surface_destroy(priv->map_source); |
1291 |
|
#endif |
1292 |
|
|
1293 |
|
#ifdef OSD_SCALE |
1294 |
|
if (priv->scale) |
1295 |
|
cairo_surface_destroy(priv->scale); |
1296 |
|
#endif |
1297 |
|
|
1298 |
|
#ifdef OSD_CROSSHAIR |
1299 |
|
if (priv->crosshair) |
1300 |
|
cairo_surface_destroy(priv->crosshair); |
1301 |
|
#endif |
1302 |
|
|
1303 |
|
#ifdef OSD_COORDINATES |
1304 |
|
if (priv->coordinates) |
1305 |
|
cairo_surface_destroy(priv->coordinates); |
1306 |
|
#endif |
1307 |
|
|
1308 |
g_free(priv); |
g_free(priv); |
1309 |
} |
} |
1310 |
|
|
|
/* this is the only function that's externally visible */ |
|
1311 |
static gboolean |
static gboolean |
1312 |
osd_busy(osm_gps_map_osd_t *osd) |
osd_busy(osm_gps_map_osd_t *osd) |
1313 |
{ |
{ |
1314 |
|
#ifdef OSD_SOURCE_SEL |
1315 |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
1316 |
return (priv->handler_id != 0); |
return (priv->handler_id != 0); |
1317 |
|
#else |
1318 |
|
return FALSE; |
1319 |
|
#endif |
1320 |
} |
} |
1321 |
|
|
1322 |
static osm_gps_map_osd_t osd_classic = { |
static osm_gps_map_osd_t osd_classic = { |
1323 |
|
.widget = NULL, |
1324 |
|
|
1325 |
.draw = osd_draw, |
.draw = osd_draw, |
1326 |
.check = osd_check, |
.check = osd_check, |
1327 |
.render = osd_render, |
.render = osd_render, |