34 |
#include "osm-gps-map.h" |
#include "osm-gps-map.h" |
35 |
#include "osm-gps-map-osd-classic.h" |
#include "osm-gps-map-osd-classic.h" |
36 |
|
|
37 |
|
#define OSD_COORDINATES |
38 |
|
|
39 |
//the osd controls |
//the osd controls |
40 |
typedef struct { |
typedef struct { |
41 |
/* the offscreen representation of the OSD */ |
/* the offscreen representation of the OSD */ |
42 |
cairo_surface_t *overlay; |
cairo_surface_t *overlay; |
43 |
|
|
44 |
|
#ifdef OSD_SCALE |
45 |
|
cairo_surface_t *scale; |
46 |
|
int scale_zoom; |
47 |
|
#endif |
48 |
|
|
49 |
|
#ifdef OSD_CROSSHAIR |
50 |
|
cairo_surface_t *crosshair; |
51 |
|
#endif |
52 |
|
|
53 |
|
#ifdef OSD_COORDINATES |
54 |
|
cairo_surface_t *coordinates; |
55 |
|
#endif |
56 |
|
|
57 |
|
#ifdef OSD_SOURCE_SEL |
58 |
/* values to handle the "source" menu */ |
/* values to handle the "source" menu */ |
59 |
cairo_surface_t *map_source; |
cairo_surface_t *map_source; |
60 |
gboolean expanded; |
gboolean expanded; |
61 |
gint shift, dir, count; |
gint shift, dir, count; |
62 |
gint handler_id; |
gint handler_id; |
63 |
gint width, height; |
gint width, height; |
64 |
|
#endif |
65 |
|
|
66 |
} osd_priv_t; |
} osd_priv_t; |
67 |
|
|
275 |
return OSD_NONE; |
return OSD_NONE; |
276 |
} |
} |
277 |
|
|
278 |
|
#ifdef OSD_SOURCE_SEL |
279 |
|
|
280 |
/* place source selection at right border */ |
/* place source selection at right border */ |
281 |
#define OSD_S_RAD (Z_RAD) |
#define OSD_S_RAD (Z_RAD) |
282 |
#define OSD_S_X (-OSD_X) |
#define OSD_S_X (-OSD_X) |
300 |
#define OSD_TEXT_BORDER (OSD_FONT_SIZE/2) |
#define OSD_TEXT_BORDER (OSD_FONT_SIZE/2) |
301 |
#define OSD_TEXT_SKIP (OSD_FONT_SIZE/8) |
#define OSD_TEXT_SKIP (OSD_FONT_SIZE/8) |
302 |
|
|
303 |
|
/* draw the shape of the source selection OSD, either only the puller (not expanded) */ |
304 |
|
/* or the entire menu incl. the puller (expanded) */ |
305 |
static void |
static void |
306 |
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) { |
307 |
if(!priv->expanded) { |
if(!priv->expanded) { |
357 |
CAIRO_FONT_WEIGHT_BOLD); |
CAIRO_FONT_WEIGHT_BOLD); |
358 |
cairo_set_font_size (cr, OSD_FONT_SIZE); |
cairo_set_font_size (cr, OSD_FONT_SIZE); |
359 |
|
|
360 |
int i, step = (priv->height - 2*OSD_TEXT_BORDER) |
int i, step = (priv->height - 2*OSD_TEXT_BORDER) / |
361 |
/ OSM_GPS_MAP_SOURCE_LAST; |
OSM_GPS_MAP_SOURCE_LAST; |
362 |
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++) { |
363 |
cairo_text_extents_t extents; |
cairo_text_extents_t extents; |
364 |
const char *src = osm_gps_map_source_get_friendly_name(i); |
const char *src = osm_gps_map_source_get_friendly_name(i); |
446 |
cairo_destroy(cr); |
cairo_destroy(cr); |
447 |
} |
} |
448 |
|
|
449 |
|
/* re-allocate the buffer used to draw the menu. This is used */ |
450 |
|
/* to collapse/expand the buffer */ |
451 |
static void |
static void |
452 |
osd_source_reallocate(osm_gps_map_osd_t *osd) { |
osd_source_reallocate(osm_gps_map_osd_t *osd) { |
453 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
457 |
|
|
458 |
int w = OSD_S_W, h = OSD_S_H; |
int w = OSD_S_W, h = OSD_S_H; |
459 |
if(priv->expanded) { |
if(priv->expanded) { |
|
/* ... and right of it the waypoint id */ |
|
460 |
cairo_text_extents_t extents; |
cairo_text_extents_t extents; |
461 |
|
|
462 |
/* determine content size */ |
/* determine content size */ |
472 |
const char *src = osm_gps_map_source_get_friendly_name(i); |
const char *src = osm_gps_map_source_get_friendly_name(i); |
473 |
cairo_text_extents (cr, src, &extents); |
cairo_text_extents (cr, src, &extents); |
474 |
|
|
|
// printf("Source %d: %s = %f %f\n", i, src, |
|
|
// extents.width, extents.height); |
|
|
|
|
475 |
if(extents.width > max_w) max_w = extents.width; |
if(extents.width > max_w) max_w = extents.width; |
476 |
if(extents.height > max_h) max_h = extents.height; |
if(extents.height > max_h) max_h = extents.height; |
477 |
} |
} |
490 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2); |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2); |
491 |
|
|
492 |
osd_render_source_sel(osd); |
osd_render_source_sel(osd); |
|
|
|
493 |
} |
} |
494 |
|
|
495 |
#define OSD_HZ 15 |
#define OSD_HZ 15 |
521 |
|
|
522 |
/* 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 */ |
523 |
|
|
|
/* simple linear mapping */ |
|
|
// priv->shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) + |
|
|
// (diff * priv->count)/1000; |
|
|
|
|
524 |
/* nicer sinoid mapping */ |
/* nicer sinoid mapping */ |
525 |
float m = 0.5-cos(priv->count * M_PI / 1000.0)/2; |
float m = 0.5-cos(priv->count * M_PI / 1000.0)/2; |
526 |
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) + |
561 |
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); |
562 |
} |
} |
563 |
|
|
564 |
|
/* check if the user clicked inside the source selection area */ |
565 |
static osd_button_t |
static osd_button_t |
566 |
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) { |
567 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
588 |
return OSD_BG; |
return OSD_BG; |
589 |
} |
} |
590 |
} |
} |
591 |
|
|
592 |
|
/* check for clicks into data area */ |
593 |
|
if(priv->expanded && !priv->handler_id) { |
594 |
|
/* re-adjust from puller top to content top */ |
595 |
|
if(OSD_S_Y < 0) |
596 |
|
y += OSD_S_EXP_H - OSD_S_PH; |
597 |
|
|
598 |
|
if(x > OSD_S_PW && |
599 |
|
x < OSD_S_PW + OSD_S_EXP_W && |
600 |
|
y > 0 && |
601 |
|
y < OSD_S_EXP_H) { |
602 |
|
|
603 |
|
int step = (priv->height - 2*OSD_TEXT_BORDER) |
604 |
|
/ OSM_GPS_MAP_SOURCE_LAST; |
605 |
|
|
606 |
|
y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP; |
607 |
|
y /= step; |
608 |
|
y += 1; |
609 |
|
|
610 |
|
gint old = 0; |
611 |
|
g_object_get(osd->widget, "map-source", &old, NULL); |
612 |
|
|
613 |
|
if(y > OSM_GPS_MAP_SOURCE_NULL && |
614 |
|
y <= OSM_GPS_MAP_SOURCE_LAST && |
615 |
|
old != y) { |
616 |
|
g_object_set(osd->widget, "map-source", y, NULL); |
617 |
|
|
618 |
|
osd_render_source_sel(osd); |
619 |
|
osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
620 |
|
} |
621 |
|
|
622 |
|
/* return "clicked in OSD background" to prevent further */ |
623 |
|
/* processing by application */ |
624 |
|
return OSD_BG; |
625 |
|
} |
626 |
|
} |
627 |
|
|
628 |
return OSD_NONE; |
return OSD_NONE; |
629 |
} |
} |
630 |
|
#endif // OSD_SOURCE_SEL |
631 |
|
|
632 |
static osd_button_t |
static osd_button_t |
633 |
osd_check(osm_gps_map_osd_t *osd, gint x, gint y) { |
osd_check(osm_gps_map_osd_t *osd, gint x, gint y) { |
733 |
cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID); |
cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID); |
734 |
} |
} |
735 |
|
|
736 |
|
#ifdef OSD_COORDINATES |
737 |
|
#define OSD_COORDINATES_W 100 |
738 |
|
#define OSD_COORDINATES_H 50 |
739 |
|
|
740 |
static void |
static void |
741 |
osd_render(osm_gps_map_osd_t *osd) { |
osd_render_coordinates(osm_gps_map_osd_t *osd) |
742 |
|
{ |
743 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
744 |
|
|
745 |
|
/* first fill with transparency */ |
746 |
|
cairo_t *cr = cairo_create(priv->coordinates); |
747 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
748 |
|
// cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); |
749 |
|
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2); |
750 |
|
cairo_paint(cr); |
751 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
752 |
|
|
753 |
|
cairo_destroy(cr); |
754 |
|
} |
755 |
|
#endif // OSD_COORDINATES |
756 |
|
|
757 |
|
#ifdef OSD_CROSSHAIR |
758 |
|
|
759 |
|
#ifndef OSD_CROSSHAIR_RADIUS |
760 |
|
#define OSD_CROSSHAIR_RADIUS 10 |
761 |
|
#endif |
762 |
|
|
763 |
|
#define OSD_CROSSHAIR_TICK (OSD_CROSSHAIR_RADIUS/2) |
764 |
|
#define OSD_CROSSHAIR_BORDER (OSD_CROSSHAIR_TICK + OSD_CROSSHAIR_RADIUS/4) |
765 |
|
#define OSD_CROSSHAIR_W ((OSD_CROSSHAIR_RADIUS+OSD_CROSSHAIR_BORDER)*2) |
766 |
|
#define OSD_CROSSHAIR_H ((OSD_CROSSHAIR_RADIUS+OSD_CROSSHAIR_BORDER)*2) |
767 |
|
|
768 |
|
static void |
769 |
|
osd_render_crosshair_shape(cairo_t *cr) { |
770 |
|
cairo_arc (cr, OSD_CROSSHAIR_W/2, OSD_CROSSHAIR_H/2, |
771 |
|
OSD_CROSSHAIR_RADIUS, 0, 2*M_PI); |
772 |
|
|
773 |
|
cairo_move_to (cr, OSD_CROSSHAIR_W/2 - OSD_CROSSHAIR_RADIUS, |
774 |
|
OSD_CROSSHAIR_H/2); |
775 |
|
cairo_rel_line_to (cr, -OSD_CROSSHAIR_TICK, 0); |
776 |
|
cairo_move_to (cr, OSD_CROSSHAIR_W/2 + OSD_CROSSHAIR_RADIUS, |
777 |
|
OSD_CROSSHAIR_H/2); |
778 |
|
cairo_rel_line_to (cr, OSD_CROSSHAIR_TICK, 0); |
779 |
|
|
780 |
|
cairo_move_to (cr, OSD_CROSSHAIR_W/2, |
781 |
|
OSD_CROSSHAIR_H/2 - OSD_CROSSHAIR_RADIUS); |
782 |
|
cairo_rel_line_to (cr, 0, -OSD_CROSSHAIR_TICK); |
783 |
|
cairo_move_to (cr, OSD_CROSSHAIR_W/2, |
784 |
|
OSD_CROSSHAIR_H/2 + OSD_CROSSHAIR_RADIUS); |
785 |
|
cairo_rel_line_to (cr, 0, OSD_CROSSHAIR_TICK); |
786 |
|
|
787 |
|
cairo_stroke (cr); |
788 |
|
} |
789 |
|
|
790 |
|
static void |
791 |
|
osd_render_crosshair(osm_gps_map_osd_t *osd) |
792 |
|
{ |
793 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
794 |
|
|
795 |
|
/* first fill with transparency */ |
796 |
|
cairo_t *cr = cairo_create(priv->crosshair); |
797 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
798 |
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); |
799 |
|
// cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2); |
800 |
|
cairo_paint(cr); |
801 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
802 |
|
|
803 |
|
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); |
804 |
|
|
805 |
|
cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.5); |
806 |
|
cairo_set_line_width (cr, OSD_CROSSHAIR_RADIUS/2); |
807 |
|
osd_render_crosshair_shape(cr); |
808 |
|
|
809 |
|
cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.5); |
810 |
|
cairo_set_line_width (cr, OSD_CROSSHAIR_RADIUS/4); |
811 |
|
osd_render_crosshair_shape(cr); |
812 |
|
|
813 |
|
cairo_destroy(cr); |
814 |
|
} |
815 |
|
#endif |
816 |
|
|
817 |
|
#ifdef OSD_SCALE |
818 |
|
|
819 |
|
#ifndef OSD_SCALE_FONT_SIZE |
820 |
|
#define OSD_SCALE_FONT_SIZE 12 |
821 |
|
#endif |
822 |
|
#define OSD_SCALE_W (10*OSD_SCALE_FONT_SIZE) |
823 |
|
#define OSD_SCALE_H (5*OSD_SCALE_FONT_SIZE/2) |
824 |
|
|
825 |
|
/* various parameters used to create the scale */ |
826 |
|
#define OSD_SCALE_H2 (OSD_SCALE_H/2) |
827 |
|
#define OSD_SCALE_TICK (2*OSD_SCALE_FONT_SIZE/3) |
828 |
|
#define OSD_SCALE_M (OSD_SCALE_H2 - OSD_SCALE_TICK) |
829 |
|
#define OSD_SCALE_I (OSD_SCALE_H2 + OSD_SCALE_TICK) |
830 |
|
#define OSD_SCALE_FD (OSD_SCALE_FONT_SIZE/4) |
831 |
|
|
832 |
|
static void |
833 |
|
osd_render_scale(osm_gps_map_osd_t *osd) |
834 |
|
{ |
835 |
|
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
836 |
|
|
837 |
|
/* this only needs to be rendered if the zoom has changed */ |
838 |
|
gint zoom; |
839 |
|
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
840 |
|
if(zoom == priv->scale_zoom) |
841 |
|
return; |
842 |
|
|
843 |
|
priv->scale_zoom = zoom; |
844 |
|
|
845 |
|
float m_per_pix = osm_gps_map_get_scale(OSM_GPS_MAP(osd->widget)); |
846 |
|
|
847 |
|
/* first fill with transparency */ |
848 |
|
cairo_t *cr = cairo_create(priv->scale); |
849 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
850 |
|
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.0); |
851 |
|
// pink for testing: cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2); |
852 |
|
cairo_paint(cr); |
853 |
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
854 |
|
|
855 |
|
/* determine the size of the scale width in meters */ |
856 |
|
float width = (OSD_SCALE_W-OSD_SCALE_FONT_SIZE/6) * m_per_pix; |
857 |
|
|
858 |
|
/* scale this to useful values */ |
859 |
|
int exp = logf(width)*M_LOG10E; |
860 |
|
int mant = width/pow(10,exp); |
861 |
|
int width_metric = mant * pow(10,exp); |
862 |
|
char *dist_str = NULL; |
863 |
|
if(width_metric<1000) |
864 |
|
dist_str = g_strdup_printf("%u m", width_metric); |
865 |
|
else |
866 |
|
dist_str = g_strdup_printf("%u km", width_metric/1000); |
867 |
|
width_metric /= m_per_pix; |
868 |
|
|
869 |
|
/* and now the hard part: scale for useful imperial values :-( */ |
870 |
|
/* try to convert to feet, 1ft == 0.3048 m */ |
871 |
|
width /= 0.3048; |
872 |
|
float imp_scale = 0.3048; |
873 |
|
char *dist_imp_unit = "ft"; |
874 |
|
|
875 |
|
if(width >= 100) { |
876 |
|
/* 1yd == 3 feet */ |
877 |
|
width /= 3.0; |
878 |
|
imp_scale *= 3.0; |
879 |
|
dist_imp_unit = "yd"; |
880 |
|
|
881 |
|
if(width >= 1760.0) { |
882 |
|
/* 1mi == 1760 yd */ |
883 |
|
width /= 1760.0; |
884 |
|
imp_scale *= 1760.0; |
885 |
|
dist_imp_unit = "mi"; |
886 |
|
} |
887 |
|
} |
888 |
|
|
889 |
|
/* also convert this to full tens/hundreds */ |
890 |
|
exp = logf(width)*M_LOG10E; |
891 |
|
mant = width/pow(10,exp); |
892 |
|
int width_imp = mant * pow(10,exp); |
893 |
|
char *dist_str_imp = g_strdup_printf("%u %s", width_imp, dist_imp_unit); |
894 |
|
|
895 |
|
/* convert back to pixels */ |
896 |
|
width_imp *= imp_scale; |
897 |
|
width_imp /= m_per_pix; |
898 |
|
|
899 |
|
cairo_select_font_face (cr, "Sans", |
900 |
|
CAIRO_FONT_SLANT_NORMAL, |
901 |
|
CAIRO_FONT_WEIGHT_BOLD); |
902 |
|
cairo_set_font_size (cr, OSD_SCALE_FONT_SIZE); |
903 |
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0); |
904 |
|
|
905 |
|
cairo_text_extents_t extents; |
906 |
|
cairo_text_extents (cr, dist_str, &extents); |
907 |
|
|
908 |
|
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); |
909 |
|
cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/6); |
910 |
|
cairo_move_to (cr, 2*OSD_SCALE_FD, OSD_SCALE_H2-OSD_SCALE_FD); |
911 |
|
cairo_text_path (cr, dist_str); |
912 |
|
cairo_stroke (cr); |
913 |
|
cairo_move_to (cr, 2*OSD_SCALE_FD, |
914 |
|
OSD_SCALE_H2+OSD_SCALE_FD + extents.height); |
915 |
|
cairo_text_path (cr, dist_str_imp); |
916 |
|
cairo_stroke (cr); |
917 |
|
|
918 |
|
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); |
919 |
|
cairo_move_to (cr, 2*OSD_SCALE_FD, OSD_SCALE_H2-OSD_SCALE_FD); |
920 |
|
cairo_show_text (cr, dist_str); |
921 |
|
cairo_move_to (cr, 2*OSD_SCALE_FD, |
922 |
|
OSD_SCALE_H2+OSD_SCALE_FD + extents.height); |
923 |
|
cairo_show_text (cr, dist_str_imp); |
924 |
|
|
925 |
|
g_free(dist_str); |
926 |
|
g_free(dist_str_imp); |
927 |
|
|
928 |
|
/* draw white line */ |
929 |
|
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); |
930 |
|
cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0); |
931 |
|
cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/3); |
932 |
|
cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_M); |
933 |
|
cairo_rel_line_to (cr, 0, OSD_SCALE_TICK); |
934 |
|
cairo_rel_line_to (cr, width_metric, 0); |
935 |
|
cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK); |
936 |
|
cairo_stroke(cr); |
937 |
|
cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_I); |
938 |
|
cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK); |
939 |
|
cairo_rel_line_to (cr, width_imp, 0); |
940 |
|
cairo_rel_line_to (cr, 0, +OSD_SCALE_TICK); |
941 |
|
cairo_stroke(cr); |
942 |
|
|
943 |
|
/* draw black line */ |
944 |
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0); |
945 |
|
cairo_set_line_width (cr, OSD_SCALE_FONT_SIZE/6); |
946 |
|
cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_M); |
947 |
|
cairo_rel_line_to (cr, 0, OSD_SCALE_TICK); |
948 |
|
cairo_rel_line_to (cr, width_metric, 0); |
949 |
|
cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK); |
950 |
|
cairo_stroke(cr); |
951 |
|
cairo_move_to (cr, OSD_SCALE_FONT_SIZE/6, OSD_SCALE_I); |
952 |
|
cairo_rel_line_to (cr, 0, -OSD_SCALE_TICK); |
953 |
|
cairo_rel_line_to (cr, width_imp, 0); |
954 |
|
cairo_rel_line_to (cr, 0, +OSD_SCALE_TICK); |
955 |
|
cairo_stroke(cr); |
956 |
|
|
957 |
|
cairo_destroy(cr); |
958 |
|
} |
959 |
|
#endif |
960 |
|
|
961 |
|
static void |
962 |
|
osd_render(osm_gps_map_osd_t *osd) |
963 |
|
{ |
964 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
965 |
|
|
966 |
#ifndef OSD_COLOR |
#ifndef OSD_COLOR |
1042 |
|
|
1043 |
cairo_destroy(cr); |
cairo_destroy(cr); |
1044 |
|
|
1045 |
|
#ifdef OSD_SOURCE_SEL |
1046 |
osd_render_source_sel(osd); |
osd_render_source_sel(osd); |
1047 |
|
#endif |
1048 |
|
|
1049 |
|
#ifdef OSD_SCALE |
1050 |
|
osd_render_scale(osd); |
1051 |
|
#endif |
1052 |
|
|
1053 |
|
#ifdef OSD_CROSSHAIR |
1054 |
|
osd_render_crosshair(osd); |
1055 |
|
#endif |
1056 |
|
|
1057 |
|
#ifdef OSD_COORDINATES |
1058 |
|
osd_render_coordinates(osd); |
1059 |
|
#endif |
1060 |
} |
} |
1061 |
|
|
1062 |
static void |
static void |
1071 |
priv->overlay = |
priv->overlay = |
1072 |
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); |
1073 |
|
|
1074 |
|
#ifdef OSD_SOURCE_SEL |
1075 |
/* the initial OSD state is alway not-expanded */ |
/* the initial OSD state is alway not-expanded */ |
1076 |
priv->map_source = |
priv->map_source = |
1077 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1078 |
OSD_S_W+2, OSD_S_H+2); |
OSD_S_W+2, OSD_S_H+2); |
1079 |
|
#endif |
1080 |
|
|
1081 |
|
#ifdef OSD_SCALE |
1082 |
|
priv->scale = |
1083 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1084 |
|
OSD_SCALE_W, OSD_SCALE_H); |
1085 |
|
priv->scale_zoom = -1; |
1086 |
|
#endif |
1087 |
|
|
1088 |
|
#ifdef OSD_CROSSHAIR |
1089 |
|
priv->crosshair = |
1090 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1091 |
|
OSD_CROSSHAIR_W, OSD_CROSSHAIR_H); |
1092 |
|
#endif |
1093 |
|
|
1094 |
|
#ifdef OSD_COORDINATES |
1095 |
|
priv->coordinates = |
1096 |
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1097 |
|
OSD_COORDINATES_W, OSD_COORDINATES_H); |
1098 |
|
#endif |
1099 |
|
|
1100 |
/* ... and render it */ |
/* ... and render it */ |
1101 |
osd_render(osd); |
osd_render(osd); |
1104 |
// now draw this onto the original context |
// now draw this onto the original context |
1105 |
cairo_t *cr = gdk_cairo_create(drawable); |
cairo_t *cr = gdk_cairo_create(drawable); |
1106 |
|
|
1107 |
int x = OSD_X, y = OSD_Y; |
int x, y; |
|
if(OSD_X < 0) |
|
|
x = osd->widget->allocation.width - OSD_W + OSD_X; |
|
1108 |
|
|
1109 |
if(OSD_Y < 0) |
#ifdef OSD_SCALE |
1110 |
y = osd->widget->allocation.height - OSD_H + OSD_Y; |
x = OSD_X; |
1111 |
|
y = -OSD_Y; |
1112 |
|
if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W; |
1113 |
|
if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H; |
1114 |
|
|
1115 |
|
cairo_set_source_surface(cr, priv->scale, x, y); |
1116 |
|
cairo_paint(cr); |
1117 |
|
#endif |
1118 |
|
|
1119 |
|
#ifdef OSD_CROSSHAIR |
1120 |
|
x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2; |
1121 |
|
y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2; |
1122 |
|
|
1123 |
|
cairo_set_source_surface(cr, priv->crosshair, x, y); |
1124 |
|
cairo_paint(cr); |
1125 |
|
#endif |
1126 |
|
|
1127 |
|
#ifdef OSD_COORDINATES |
1128 |
|
x = -OSD_X; |
1129 |
|
y = -OSD_Y; |
1130 |
|
if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W; |
1131 |
|
if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H; |
1132 |
|
|
1133 |
|
cairo_set_source_surface(cr, priv->coordinates, x, y); |
1134 |
|
cairo_paint(cr); |
1135 |
|
#endif |
1136 |
|
|
1137 |
|
x = OSD_X; |
1138 |
|
if(x < 0) |
1139 |
|
x += osd->widget->allocation.width - OSD_W; |
1140 |
|
|
1141 |
|
y = OSD_Y; |
1142 |
|
if(y < 0) |
1143 |
|
y += osd->widget->allocation.height - OSD_H; |
1144 |
|
|
1145 |
cairo_set_source_surface(cr, priv->overlay, x, y); |
cairo_set_source_surface(cr, priv->overlay, x, y); |
1146 |
cairo_paint(cr); |
cairo_paint(cr); |
1175 |
{ |
{ |
1176 |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
1177 |
|
|
|
if(priv->handler_id) |
|
|
gtk_timeout_remove(priv->handler_id); |
|
|
|
|
1178 |
if (priv->overlay) |
if (priv->overlay) |
1179 |
cairo_surface_destroy(priv->overlay); |
cairo_surface_destroy(priv->overlay); |
1180 |
|
|
1181 |
|
#ifdef OSD_SOURCE_SEL |
1182 |
|
if(priv->handler_id) |
1183 |
|
gtk_timeout_remove(priv->handler_id); |
1184 |
|
|
1185 |
if (priv->map_source) |
if (priv->map_source) |
1186 |
cairo_surface_destroy(priv->map_source); |
cairo_surface_destroy(priv->map_source); |
1187 |
|
#endif |
1188 |
|
|
1189 |
|
#ifdef OSD_SCALE |
1190 |
|
if (priv->scale) |
1191 |
|
cairo_surface_destroy(priv->scale); |
1192 |
|
#endif |
1193 |
|
|
1194 |
|
#ifdef OSD_CROSSHAIR |
1195 |
|
if (priv->crosshair) |
1196 |
|
cairo_surface_destroy(priv->crosshair); |
1197 |
|
#endif |
1198 |
|
|
1199 |
|
#ifdef OSD_COORDINATES |
1200 |
|
if (priv->coordinates) |
1201 |
|
cairo_surface_destroy(priv->coordinates); |
1202 |
|
#endif |
1203 |
|
|
1204 |
g_free(priv); |
g_free(priv); |
1205 |
} |
} |
1206 |
|
|
|
/* this is the only function that's externally visible */ |
|
1207 |
static gboolean |
static gboolean |
1208 |
osd_busy(osm_gps_map_osd_t *osd) |
osd_busy(osm_gps_map_osd_t *osd) |
1209 |
{ |
{ |
1210 |
|
#ifdef OSD_SOURCE_SEL |
1211 |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
1212 |
return (priv->handler_id != 0); |
return (priv->handler_id != 0); |
1213 |
|
#else |
1214 |
|
return FALSE; |
1215 |
|
#endif |
1216 |
} |
} |
1217 |
|
|
1218 |
static osm_gps_map_osd_t osd_classic = { |
static osm_gps_map_osd_t osd_classic = { |
1219 |
|
.widget = NULL, |
1220 |
|
|
1221 |
.draw = osd_draw, |
.draw = osd_draw, |
1222 |
.check = osd_check, |
.check = osd_check, |
1223 |
.render = osd_render, |
.render = osd_render, |