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 |
|
|
|
#define OSD_COORDINATES |
|
|
|
|
37 |
//the osd controls |
//the osd controls |
38 |
typedef struct { |
typedef struct { |
39 |
/* the offscreen representation of the OSD */ |
/* the offscreen representation of the OSD */ |
40 |
cairo_surface_t *overlay; |
struct { |
41 |
|
cairo_surface_t *surface; |
42 |
|
gboolean rendered; |
43 |
|
#ifdef OSD_GPS_BUTTON |
44 |
|
gboolean gps_enabled; |
45 |
|
#endif |
46 |
|
} controls; |
47 |
|
|
48 |
#ifdef OSD_SCALE |
#ifdef OSD_SCALE |
49 |
cairo_surface_t *scale; |
struct { |
50 |
int scale_zoom; |
cairo_surface_t *surface; |
51 |
|
int zoom; |
52 |
|
} scale; |
53 |
#endif |
#endif |
54 |
|
|
55 |
#ifdef OSD_CROSSHAIR |
#ifdef OSD_CROSSHAIR |
56 |
cairo_surface_t *crosshair; |
struct { |
57 |
|
cairo_surface_t *surface; |
58 |
|
gboolean rendered; |
59 |
|
} crosshair; |
60 |
#endif |
#endif |
61 |
|
|
62 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
63 |
cairo_surface_t *coordinates; |
struct { |
64 |
|
cairo_surface_t *surface; |
65 |
|
float lat, lon; |
66 |
|
} coordinates; |
67 |
#endif |
#endif |
68 |
|
|
69 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
70 |
/* values to handle the "source" menu */ |
struct { |
71 |
cairo_surface_t *map_source; |
/* values to handle the "source" menu */ |
72 |
gboolean expanded; |
cairo_surface_t *surface; |
73 |
gint shift, dir, count; |
gboolean expanded; |
74 |
gint handler_id; |
gint shift, dir, count; |
75 |
gint width, height; |
gint handler_id; |
76 |
|
gint width, height; |
77 |
|
} source_sel; |
78 |
#endif |
#endif |
79 |
|
|
80 |
} osd_priv_t; |
} osd_priv_t; |
301 |
#define OSD_S_H (OSD_S_PH + OSD_SHADOW) |
#define OSD_S_H (OSD_S_PH + OSD_SHADOW) |
302 |
|
|
303 |
/* size of usable area when expanded */ |
/* size of usable area when expanded */ |
304 |
#define OSD_S_AREA_W (priv->width) |
#define OSD_S_AREA_W (priv->source_sel.width) |
305 |
#define OSD_S_AREA_H (priv->height) |
#define OSD_S_AREA_H (priv->source_sel.height) |
306 |
#define OSD_S_EXP_W (OSD_S_PW + OSD_S_AREA_W + OSD_SHADOW) |
#define OSD_S_EXP_W (OSD_S_PW + OSD_S_AREA_W + OSD_SHADOW) |
307 |
#define OSD_S_EXP_H (OSD_S_AREA_H + OSD_SHADOW) |
#define OSD_S_EXP_H (OSD_S_AREA_H + OSD_SHADOW) |
308 |
|
|
318 |
/* or the entire menu incl. the puller (expanded) */ |
/* or the entire menu incl. the puller (expanded) */ |
319 |
static void |
static void |
320 |
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) { |
321 |
if(!priv->expanded) { |
if(!priv->source_sel.expanded) { |
322 |
/* just draw the puller */ |
/* just draw the puller */ |
323 |
cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH); |
cairo_move_to (cr, x + OSD_S_PW, y + OSD_S_PH); |
324 |
cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2); |
cairo_arc (cr, x+OSD_S_RAD, y+OSD_S_RAD, OSD_S_RAD, M_PI/2, -M_PI/2); |
346 |
|
|
347 |
int py = offset + OSD_S_RAD - OSD_S_D0; |
int py = offset + OSD_S_RAD - OSD_S_D0; |
348 |
|
|
349 |
if(!priv->expanded) { |
if(!priv->source_sel.expanded) { |
350 |
/* draw the "puller" open (<) arrow */ |
/* draw the "puller" open (<) arrow */ |
351 |
cairo_move_to (cr, offset + OSD_S_RAD + OSD_S_D0/2, py); |
cairo_move_to (cr, offset + OSD_S_RAD + OSD_S_D0/2, py); |
352 |
cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0); |
cairo_rel_line_to (cr, -OSD_S_D0, +OSD_S_D0); |
371 |
CAIRO_FONT_WEIGHT_BOLD); |
CAIRO_FONT_WEIGHT_BOLD); |
372 |
cairo_set_font_size (cr, OSD_FONT_SIZE); |
cairo_set_font_size (cr, OSD_FONT_SIZE); |
373 |
|
|
374 |
int i, step = (priv->height - 2*OSD_TEXT_BORDER) / |
int i, step = (priv->source_sel.height - 2*OSD_TEXT_BORDER) / |
375 |
OSM_GPS_MAP_SOURCE_LAST; |
OSM_GPS_MAP_SOURCE_LAST; |
376 |
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++) { |
377 |
cairo_text_extents_t extents; |
cairo_text_extents_t extents; |
385 |
if(source == i) { |
if(source == i) { |
386 |
cairo_rectangle(cr, x - OSD_TEXT_BORDER/2, |
cairo_rectangle(cr, x - OSD_TEXT_BORDER/2, |
387 |
y - OSD_TEXT_SKIP, |
y - OSD_TEXT_SKIP, |
388 |
priv->width - OSD_TEXT_BORDER, |
priv->source_sel.width - OSD_TEXT_BORDER, |
389 |
step + OSD_TEXT_SKIP); |
step + OSD_TEXT_SKIP); |
390 |
cairo_fill(cr); |
cairo_fill(cr); |
391 |
|
|
426 |
#endif |
#endif |
427 |
|
|
428 |
/* draw source selector */ |
/* draw source selector */ |
429 |
cairo_t *cr = cairo_create(priv->map_source); |
cairo_t *cr = cairo_create(priv->source_sel.surface); |
430 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
431 |
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); |
432 |
cairo_paint(cr); |
cairo_paint(cr); |
467 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
468 |
|
|
469 |
/* re-allocate offscreen bitmap */ |
/* re-allocate offscreen bitmap */ |
470 |
g_assert (priv->map_source); |
g_assert (priv->source_sel.surface); |
471 |
|
|
472 |
int w = OSD_S_W, h = OSD_S_H; |
int w = OSD_S_W, h = OSD_S_H; |
473 |
if(priv->expanded) { |
if(priv->source_sel.expanded) { |
474 |
cairo_text_extents_t extents; |
cairo_text_extents_t extents; |
475 |
|
|
476 |
/* determine content size */ |
/* determine content size */ |
477 |
cairo_t *cr = cairo_create(priv->map_source); |
cairo_t *cr = cairo_create(priv->source_sel.surface); |
478 |
cairo_select_font_face (cr, "Sans", |
cairo_select_font_face (cr, "Sans", |
479 |
CAIRO_FONT_SLANT_NORMAL, |
CAIRO_FONT_SLANT_NORMAL, |
480 |
CAIRO_FONT_WEIGHT_BOLD); |
CAIRO_FONT_WEIGHT_BOLD); |
491 |
} |
} |
492 |
cairo_destroy(cr); |
cairo_destroy(cr); |
493 |
|
|
494 |
priv->width = max_w + 2*OSD_TEXT_BORDER; |
priv->source_sel.width = max_w + 2*OSD_TEXT_BORDER; |
495 |
priv->height = OSM_GPS_MAP_SOURCE_LAST * |
priv->source_sel.height = OSM_GPS_MAP_SOURCE_LAST * |
496 |
(max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER; |
(max_h + 2*OSD_TEXT_SKIP) + 2*OSD_TEXT_BORDER; |
497 |
|
|
498 |
w = OSD_S_EXP_W; |
w = OSD_S_EXP_W; |
499 |
h = OSD_S_EXP_H; |
h = OSD_S_EXP_H; |
500 |
} |
} |
501 |
|
|
502 |
cairo_surface_destroy(priv->map_source); |
cairo_surface_destroy(priv->source_sel.surface); |
503 |
priv->map_source = |
priv->source_sel.surface = |
504 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2); |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w+2, h+2); |
505 |
|
|
506 |
osd_render_source_sel(osd); |
osd_render_source_sel(osd); |
514 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
515 |
int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X; |
int diff = OSD_S_EXP_W - OSD_S_W - OSD_S_X; |
516 |
gboolean done = FALSE; |
gboolean done = FALSE; |
517 |
priv->count += priv->dir; |
priv->source_sel.count += priv->source_sel.dir; |
518 |
|
|
519 |
/* shifting in */ |
/* shifting in */ |
520 |
if(priv->dir < 0) { |
if(priv->source_sel.dir < 0) { |
521 |
if(priv->count <= 0) { |
if(priv->source_sel.count <= 0) { |
522 |
priv->count = 0; |
priv->source_sel.count = 0; |
523 |
done = TRUE; |
done = TRUE; |
524 |
} |
} |
525 |
} else { |
} else { |
526 |
if(priv->count >= 1000) { |
if(priv->source_sel.count >= 1000) { |
527 |
priv->expanded = FALSE; |
priv->source_sel.expanded = FALSE; |
528 |
osd_source_reallocate(osd); |
osd_source_reallocate(osd); |
529 |
|
|
530 |
priv->count = 1000; |
priv->source_sel.count = 1000; |
531 |
done = TRUE; |
done = TRUE; |
532 |
} |
} |
533 |
} |
} |
536 |
/* 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 */ |
537 |
|
|
538 |
/* nicer sinoid mapping */ |
/* nicer sinoid mapping */ |
539 |
float m = 0.5-cos(priv->count * M_PI / 1000.0)/2; |
float m = 0.5-cos(priv->source_sel.count * M_PI / 1000.0)/2; |
540 |
priv->shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) + |
priv->source_sel.shift = (osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X) + |
541 |
m * diff; |
m * diff; |
542 |
|
|
543 |
osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
osm_gps_map_repaint(OSM_GPS_MAP(osd->widget)); |
544 |
|
|
545 |
if(done) |
if(done) |
546 |
priv->handler_id = 0; |
priv->source_sel.handler_id = 0; |
547 |
|
|
548 |
return !done; |
return !done; |
549 |
} |
} |
555 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
556 |
|
|
557 |
/* ignore clicks while animation is running */ |
/* ignore clicks while animation is running */ |
558 |
if(priv->handler_id) |
if(priv->source_sel.handler_id) |
559 |
return; |
return; |
560 |
|
|
561 |
/* expand immediately, collapse is handle at the end of the collapse animation */ |
/* expand immediately, collapse is handle at the end of the collapse animation */ |
562 |
if(!priv->expanded) { |
if(!priv->source_sel.expanded) { |
563 |
priv->expanded = TRUE; |
priv->source_sel.expanded = TRUE; |
564 |
osd_source_reallocate(osd); |
osd_source_reallocate(osd); |
565 |
|
|
566 |
priv->count = 1000; |
priv->source_sel.count = 1000; |
567 |
priv->shift = osd->widget->allocation.width - OSD_S_W; |
priv->source_sel.shift = osd->widget->allocation.width - OSD_S_W; |
568 |
priv->dir = -1000/OSD_HZ; |
priv->source_sel.dir = -1000/OSD_HZ; |
569 |
} else { |
} else { |
570 |
priv->count = 0; |
priv->source_sel.count = 0; |
571 |
priv->shift = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
priv->source_sel.shift = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
572 |
priv->dir = +1000/OSD_HZ; |
priv->source_sel.dir = +1000/OSD_HZ; |
573 |
} |
} |
574 |
|
|
575 |
priv->handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, osd_source_animate, osd); |
priv->source_sel.handler_id = gtk_timeout_add(OSD_TIME/OSD_HZ, osd_source_animate, osd); |
576 |
} |
} |
577 |
|
|
578 |
/* check if the user clicked inside the source selection area */ |
/* check if the user clicked inside the source selection area */ |
580 |
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) { |
581 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
582 |
|
|
583 |
if(!priv->expanded) |
if(!priv->source_sel.expanded) |
584 |
x -= osd->widget->allocation.width - OSD_S_W; |
x -= osd->widget->allocation.width - OSD_S_W; |
585 |
else |
else |
586 |
x -= osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
x -= osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
604 |
} |
} |
605 |
|
|
606 |
/* check for clicks into data area */ |
/* check for clicks into data area */ |
607 |
if(priv->expanded && !priv->handler_id) { |
if(priv->source_sel.expanded && !priv->source_sel.handler_id) { |
608 |
/* re-adjust from puller top to content top */ |
/* re-adjust from puller top to content top */ |
609 |
if(OSD_S_Y < 0) |
if(OSD_S_Y < 0) |
610 |
y += OSD_S_EXP_H - OSD_S_PH; |
y += OSD_S_EXP_H - OSD_S_PH; |
614 |
y > 0 && |
y > 0 && |
615 |
y < OSD_S_EXP_H) { |
y < OSD_S_EXP_H) { |
616 |
|
|
617 |
int step = (priv->height - 2*OSD_TEXT_BORDER) |
int step = (priv->source_sel.height - 2*OSD_TEXT_BORDER) |
618 |
/ OSM_GPS_MAP_SOURCE_LAST; |
/ OSM_GPS_MAP_SOURCE_LAST; |
619 |
|
|
620 |
y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP; |
y -= OSD_TEXT_BORDER - OSD_TEXT_SKIP; |
748 |
} |
} |
749 |
|
|
750 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
751 |
#define OSD_COORDINATES_W 100 |
|
752 |
#define OSD_COORDINATES_H 50 |
#ifndef OSD_COORDINATES_FONT_SIZE |
753 |
|
#define OSD_COORDINATES_FONT_SIZE 12 |
754 |
|
#endif |
755 |
|
|
756 |
|
#define OSD_COORDINATES_OFFSET (OSD_COORDINATES_FONT_SIZE/6) |
757 |
|
|
758 |
|
#define OSD_COORDINATES_W (8*OSD_COORDINATES_FONT_SIZE+2*OSD_COORDINATES_OFFSET) |
759 |
|
#define OSD_COORDINATES_H (2*OSD_COORDINATES_FONT_SIZE+OSD_COORDINATES_OFFSET) |
760 |
|
|
761 |
|
/* these can be overwritten with versions that support */ |
762 |
|
/* localization */ |
763 |
|
#ifndef OSD_COORDINATES_CHR_N |
764 |
|
#define OSD_COORDINATES_CHR_N "N" |
765 |
|
#endif |
766 |
|
#ifndef OSD_COORDINATES_CHR_S |
767 |
|
#define OSD_COORDINATES_CHR_S "S" |
768 |
|
#endif |
769 |
|
#ifndef OSD_COORDINATES_CHR_E |
770 |
|
#define OSD_COORDINATES_CHR_E "E" |
771 |
|
#endif |
772 |
|
#ifndef OSD_COORDINATES_CHR_W |
773 |
|
#define OSD_COORDINATES_CHR_W "W" |
774 |
|
#endif |
775 |
|
|
776 |
|
|
777 |
|
|
778 |
|
/* this is the classic geocaching notation */ |
779 |
|
static char |
780 |
|
*osd_latitude_str(float latitude) { |
781 |
|
char *c = OSD_COORDINATES_CHR_N; |
782 |
|
float integral, fractional; |
783 |
|
|
784 |
|
if(isnan(latitude)) |
785 |
|
return NULL; |
786 |
|
|
787 |
|
if(latitude < 0) { |
788 |
|
latitude = fabs(latitude); |
789 |
|
c = OSD_COORDINATES_CHR_S; |
790 |
|
} |
791 |
|
|
792 |
|
fractional = modff(latitude, &integral); |
793 |
|
|
794 |
|
return g_strdup_printf("%s %02d° %06.3f'", |
795 |
|
c, (int)integral, fractional*60.0); |
796 |
|
} |
797 |
|
|
798 |
|
static char |
799 |
|
*osd_longitude_str(float longitude) { |
800 |
|
char *c = OSD_COORDINATES_CHR_E; |
801 |
|
float integral, fractional; |
802 |
|
|
803 |
|
if(isnan(longitude)) |
804 |
|
return NULL; |
805 |
|
|
806 |
|
if(longitude < 0) { |
807 |
|
longitude = fabs(longitude); |
808 |
|
c = OSD_COORDINATES_CHR_W; |
809 |
|
} |
810 |
|
|
811 |
|
fractional = modff(longitude, &integral); |
812 |
|
|
813 |
|
return g_strdup_printf("%s %03d° %06.3f'", |
814 |
|
c, (int)integral, fractional*60.0); |
815 |
|
} |
816 |
|
|
817 |
static void |
static void |
818 |
osd_render_coordinates(osm_gps_map_osd_t *osd) |
osd_render_coordinates(osm_gps_map_osd_t *osd) |
819 |
{ |
{ |
820 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
821 |
|
|
822 |
/* first fill with transparency */ |
/* get current map position */ |
823 |
cairo_t *cr = cairo_create(priv->coordinates); |
gfloat lat, lon; |
824 |
|
g_object_get(osd->widget, "latitude", &lat, "longitude", &lon, NULL); |
825 |
|
|
826 |
|
/* check if position has changed enough to require redraw */ |
827 |
|
if(!isnan(priv->coordinates.lat) && !isnan(priv->coordinates.lon)) |
828 |
|
/* 1/60000 == 1/1000 minute */ |
829 |
|
if((fabsf(lat - priv->coordinates.lat) < 1/60000) && |
830 |
|
(fabsf(lon - priv->coordinates.lon) < 1/60000)) |
831 |
|
return; |
832 |
|
|
833 |
|
priv->coordinates.lat = lat; |
834 |
|
priv->coordinates.lon = lon; |
835 |
|
|
836 |
|
/* first fill with light transparency */ |
837 |
|
cairo_t *cr = cairo_create(priv->coordinates.surface); |
838 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
839 |
// cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); |
cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.5); |
|
cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2); |
|
840 |
cairo_paint(cr); |
cairo_paint(cr); |
841 |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
842 |
|
|
843 |
|
cairo_select_font_face (cr, "Sans", |
844 |
|
CAIRO_FONT_SLANT_NORMAL, |
845 |
|
CAIRO_FONT_WEIGHT_BOLD); |
846 |
|
cairo_set_font_size (cr, OSD_COORDINATES_FONT_SIZE); |
847 |
|
|
848 |
|
char *latitude = osd_latitude_str(lat); |
849 |
|
char *longitude = osd_longitude_str(lon); |
850 |
|
|
851 |
|
cairo_text_extents_t lat_extents, lon_extents; |
852 |
|
cairo_text_extents (cr, latitude, &lat_extents); |
853 |
|
cairo_text_extents (cr, longitude, &lon_extents); |
854 |
|
|
855 |
|
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); |
856 |
|
cairo_set_line_width (cr, OSD_COORDINATES_FONT_SIZE/6); |
857 |
|
cairo_move_to (cr, |
858 |
|
(OSD_COORDINATES_W - lat_extents.width)/2, |
859 |
|
OSD_COORDINATES_OFFSET - lat_extents.y_bearing); |
860 |
|
cairo_text_path (cr, latitude); |
861 |
|
cairo_move_to (cr, |
862 |
|
(OSD_COORDINATES_W - lon_extents.width)/2, |
863 |
|
OSD_COORDINATES_OFFSET - lon_extents.y_bearing + |
864 |
|
OSD_COORDINATES_FONT_SIZE); |
865 |
|
cairo_text_path (cr, longitude); |
866 |
|
cairo_stroke (cr); |
867 |
|
|
868 |
|
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); |
869 |
|
cairo_move_to (cr, |
870 |
|
(OSD_COORDINATES_W - lat_extents.width)/2, |
871 |
|
OSD_COORDINATES_OFFSET - lat_extents.y_bearing); |
872 |
|
cairo_show_text (cr, latitude); |
873 |
|
cairo_move_to (cr, |
874 |
|
(OSD_COORDINATES_W - lon_extents.width)/2, |
875 |
|
OSD_COORDINATES_OFFSET - lon_extents.y_bearing + |
876 |
|
OSD_COORDINATES_FONT_SIZE); |
877 |
|
cairo_show_text (cr, longitude); |
878 |
|
|
879 |
|
g_free(latitude); |
880 |
|
g_free(longitude); |
881 |
|
|
882 |
cairo_destroy(cr); |
cairo_destroy(cr); |
883 |
} |
} |
884 |
#endif // OSD_COORDINATES |
#endif // OSD_COORDINATES |
921 |
{ |
{ |
922 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
923 |
|
|
924 |
|
if(priv->crosshair.rendered) |
925 |
|
return; |
926 |
|
|
927 |
|
priv->crosshair.rendered = TRUE; |
928 |
|
|
929 |
/* first fill with transparency */ |
/* first fill with transparency */ |
930 |
cairo_t *cr = cairo_create(priv->crosshair); |
cairo_t *cr = cairo_create(priv->crosshair.surface); |
931 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
932 |
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); |
|
// cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2); |
|
933 |
cairo_paint(cr); |
cairo_paint(cr); |
934 |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
935 |
|
|
970 |
/* this only needs to be rendered if the zoom has changed */ |
/* this only needs to be rendered if the zoom has changed */ |
971 |
gint zoom; |
gint zoom; |
972 |
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
g_object_get(OSM_GPS_MAP(osd->widget), "zoom", &zoom, NULL); |
973 |
if(zoom == priv->scale_zoom) |
if(zoom == priv->scale.zoom) |
974 |
return; |
return; |
975 |
|
|
976 |
priv->scale_zoom = zoom; |
priv->scale.zoom = zoom; |
977 |
|
|
978 |
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)); |
979 |
|
|
980 |
/* first fill with transparency */ |
/* first fill with transparency */ |
981 |
cairo_t *cr = cairo_create(priv->scale); |
cairo_t *cr = cairo_create(priv->scale.surface); |
982 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
983 |
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); |
984 |
// pink for testing: cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2); |
// pink for testing: cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.2); |
1092 |
#endif |
#endif |
1093 |
|
|
1094 |
static void |
static void |
1095 |
osd_render(osm_gps_map_osd_t *osd) |
osd_render_controls(osm_gps_map_osd_t *osd) |
1096 |
{ |
{ |
1097 |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
osd_priv_t *priv = (osd_priv_t*)osd->priv; |
1098 |
|
|
1099 |
|
if(priv->controls.rendered |
1100 |
|
#ifdef OSD_GPS_BUTTON |
1101 |
|
&& (priv->controls.gps_enabled == (osd->cb != NULL)) |
1102 |
|
#endif |
1103 |
|
) |
1104 |
|
return; |
1105 |
|
|
1106 |
|
#ifdef OSD_GPS_BUTTON |
1107 |
|
priv->controls.gps_enabled = (osd->cb != NULL); |
1108 |
|
#endif |
1109 |
|
priv->controls.rendered = TRUE; |
1110 |
|
|
1111 |
#ifndef OSD_COLOR |
#ifndef OSD_COLOR |
1112 |
GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL]; |
GdkColor bg = GTK_WIDGET(osd->widget)->style->bg[GTK_STATE_NORMAL]; |
1113 |
GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL]; |
GdkColor fg = GTK_WIDGET(osd->widget)->style->fg[GTK_STATE_NORMAL]; |
1115 |
#endif |
#endif |
1116 |
|
|
1117 |
/* first fill with transparency */ |
/* first fill with transparency */ |
1118 |
cairo_t *cr = cairo_create(priv->overlay); |
cairo_t *cr = cairo_create(priv->controls.surface); |
1119 |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
1120 |
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); |
1121 |
cairo_paint(cr); |
cairo_paint(cr); |
1186 |
cairo_stroke(cr); |
cairo_stroke(cr); |
1187 |
|
|
1188 |
cairo_destroy(cr); |
cairo_destroy(cr); |
1189 |
|
} |
1190 |
|
|
1191 |
|
static void |
1192 |
|
osd_render(osm_gps_map_osd_t *osd) |
1193 |
|
{ |
1194 |
|
osd_render_controls(osd); |
1195 |
|
|
1196 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
1197 |
osd_render_source_sel(osd); |
osd_render_source_sel(osd); |
1217 |
|
|
1218 |
/* OSD itself uses some off-screen rendering, so check if the */ |
/* OSD itself uses some off-screen rendering, so check if the */ |
1219 |
/* offscreen buffer is present and create it if not */ |
/* offscreen buffer is present and create it if not */ |
1220 |
if(!priv->overlay) { |
if(!priv->controls.surface) { |
1221 |
/* create overlay ... */ |
/* create overlay ... */ |
1222 |
priv->overlay = |
priv->controls.surface = |
1223 |
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); |
1224 |
|
|
1225 |
|
priv->controls.rendered = FALSE; |
1226 |
|
#ifdef OSD_GPS_BUTTON |
1227 |
|
priv->controls.gps_enabled = FALSE; |
1228 |
|
#endif |
1229 |
|
|
1230 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
1231 |
/* the initial OSD state is alway not-expanded */ |
/* the initial OSD state is alway not-expanded */ |
1232 |
priv->map_source = |
priv->source_sel.surface = |
1233 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1234 |
OSD_S_W+2, OSD_S_H+2); |
OSD_S_W+2, OSD_S_H+2); |
1235 |
#endif |
#endif |
1236 |
|
|
1237 |
#ifdef OSD_SCALE |
#ifdef OSD_SCALE |
1238 |
priv->scale = |
priv->scale.surface = |
1239 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1240 |
OSD_SCALE_W, OSD_SCALE_H); |
OSD_SCALE_W, OSD_SCALE_H); |
1241 |
priv->scale_zoom = -1; |
priv->scale.zoom = -1; |
1242 |
#endif |
#endif |
1243 |
|
|
1244 |
#ifdef OSD_CROSSHAIR |
#ifdef OSD_CROSSHAIR |
1245 |
priv->crosshair = |
priv->crosshair.surface = |
1246 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1247 |
OSD_CROSSHAIR_W, OSD_CROSSHAIR_H); |
OSD_CROSSHAIR_W, OSD_CROSSHAIR_H); |
1248 |
|
priv->crosshair.rendered = FALSE; |
1249 |
#endif |
#endif |
1250 |
|
|
1251 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
1252 |
priv->coordinates = |
priv->coordinates.surface = |
1253 |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, |
1254 |
OSD_COORDINATES_W, OSD_COORDINATES_H); |
OSD_COORDINATES_W, OSD_COORDINATES_H); |
1255 |
|
|
1256 |
|
priv->coordinates.lat = priv->coordinates.lon = OSM_GPS_MAP_INVALID; |
1257 |
#endif |
#endif |
1258 |
|
|
1259 |
/* ... and render it */ |
/* ... and render it */ |
1271 |
if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W; |
if(x < 0) x += osd->widget->allocation.width - OSD_SCALE_W; |
1272 |
if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H; |
if(y < 0) y += osd->widget->allocation.height - OSD_SCALE_H; |
1273 |
|
|
1274 |
cairo_set_source_surface(cr, priv->scale, x, y); |
cairo_set_source_surface(cr, priv->scale.surface, x, y); |
1275 |
cairo_paint(cr); |
cairo_paint(cr); |
1276 |
#endif |
#endif |
1277 |
|
|
1279 |
x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2; |
x = (osd->widget->allocation.width - OSD_CROSSHAIR_W)/2; |
1280 |
y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2; |
y = (osd->widget->allocation.height - OSD_CROSSHAIR_H)/2; |
1281 |
|
|
1282 |
cairo_set_source_surface(cr, priv->crosshair, x, y); |
cairo_set_source_surface(cr, priv->crosshair.surface, x, y); |
1283 |
cairo_paint(cr); |
cairo_paint(cr); |
1284 |
#endif |
#endif |
1285 |
|
|
1289 |
if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W; |
if(x < 0) x += osd->widget->allocation.width - OSD_COORDINATES_W; |
1290 |
if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H; |
if(y < 0) y += osd->widget->allocation.height - OSD_COORDINATES_H; |
1291 |
|
|
1292 |
cairo_set_source_surface(cr, priv->coordinates, x, y); |
cairo_set_source_surface(cr, priv->coordinates.surface, x, y); |
1293 |
cairo_paint(cr); |
cairo_paint(cr); |
1294 |
#endif |
#endif |
1295 |
|
|
1301 |
if(y < 0) |
if(y < 0) |
1302 |
y += osd->widget->allocation.height - OSD_H; |
y += osd->widget->allocation.height - OSD_H; |
1303 |
|
|
1304 |
cairo_set_source_surface(cr, priv->overlay, x, y); |
cairo_set_source_surface(cr, priv->controls.surface, x, y); |
1305 |
cairo_paint(cr); |
cairo_paint(cr); |
1306 |
|
|
1307 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
1308 |
if(!priv->handler_id) { |
if(!priv->source_sel.handler_id) { |
1309 |
/* the OSD source selection is not being animated */ |
/* the OSD source selection is not being animated */ |
1310 |
if(!priv->expanded) |
if(!priv->source_sel.expanded) |
1311 |
x = osd->widget->allocation.width - OSD_S_W; |
x = osd->widget->allocation.width - OSD_S_W; |
1312 |
else |
else |
1313 |
x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
x = osd->widget->allocation.width - OSD_S_EXP_W + OSD_S_X; |
1314 |
} else |
} else |
1315 |
x = priv->shift; |
x = priv->source_sel.shift; |
1316 |
|
|
1317 |
y = OSD_S_Y; |
y = OSD_S_Y; |
1318 |
if(OSD_S_Y < 0) { |
if(OSD_S_Y < 0) { |
1319 |
if(!priv->expanded) |
if(!priv->source_sel.expanded) |
1320 |
y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y; |
y = osd->widget->allocation.height - OSD_S_H + OSD_S_Y; |
1321 |
else |
else |
1322 |
y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y; |
y = osd->widget->allocation.height - OSD_S_EXP_H + OSD_S_Y; |
1323 |
} |
} |
1324 |
|
|
1325 |
cairo_set_source_surface(cr, priv->map_source, x, y); |
cairo_set_source_surface(cr, priv->source_sel.surface, x, y); |
1326 |
cairo_paint(cr); |
cairo_paint(cr); |
1327 |
#endif |
#endif |
1328 |
|
|
1334 |
{ |
{ |
1335 |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
1336 |
|
|
1337 |
if (priv->overlay) |
if (priv->controls.surface) |
1338 |
cairo_surface_destroy(priv->overlay); |
cairo_surface_destroy(priv->controls.surface); |
1339 |
|
|
1340 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
1341 |
if(priv->handler_id) |
if(priv->source_sel.handler_id) |
1342 |
gtk_timeout_remove(priv->handler_id); |
gtk_timeout_remove(priv->source_sel.handler_id); |
1343 |
|
|
1344 |
if (priv->map_source) |
if (priv->source_sel.surface) |
1345 |
cairo_surface_destroy(priv->map_source); |
cairo_surface_destroy(priv->source_sel.surface); |
1346 |
#endif |
#endif |
1347 |
|
|
1348 |
#ifdef OSD_SCALE |
#ifdef OSD_SCALE |
1349 |
if (priv->scale) |
if (priv->scale.surface) |
1350 |
cairo_surface_destroy(priv->scale); |
cairo_surface_destroy(priv->scale.surface); |
1351 |
#endif |
#endif |
1352 |
|
|
1353 |
#ifdef OSD_CROSSHAIR |
#ifdef OSD_CROSSHAIR |
1354 |
if (priv->crosshair) |
if (priv->crosshair.surface) |
1355 |
cairo_surface_destroy(priv->crosshair); |
cairo_surface_destroy(priv->crosshair.surface); |
1356 |
#endif |
#endif |
1357 |
|
|
1358 |
#ifdef OSD_COORDINATES |
#ifdef OSD_COORDINATES |
1359 |
if (priv->coordinates) |
if (priv->coordinates.surface) |
1360 |
cairo_surface_destroy(priv->coordinates); |
cairo_surface_destroy(priv->coordinates.surface); |
1361 |
#endif |
#endif |
1362 |
|
|
1363 |
g_free(priv); |
g_free(priv); |
1368 |
{ |
{ |
1369 |
#ifdef OSD_SOURCE_SEL |
#ifdef OSD_SOURCE_SEL |
1370 |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
osd_priv_t *priv = (osd_priv_t *)(osd->priv); |
1371 |
return (priv->handler_id != 0); |
return (priv->source_sel.handler_id != 0); |
1372 |
#else |
#else |
1373 |
return FALSE; |
return FALSE; |
1374 |
#endif |
#endif |