Diff of /trunk/src/osm-gps-map-osd-classic.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 106 by harbaum, Thu Sep 10 13:06:16 2009 UTC revision 107 by harbaum, Fri Sep 11 12:16:50 2009 UTC
# Line 34  Line 34 
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 */
# Line 734  osd_zoom_labels(cairo_t *cr, gint x, gin Line 732  osd_zoom_labels(cairo_t *cr, gint x, gin
732  }  }
733    
734  #ifdef OSD_COORDINATES  #ifdef OSD_COORDINATES
735  #define OSD_COORDINATES_W  100  
736  #define OSD_COORDINATES_H   50  #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  static void
802  osd_render_coordinates(osm_gps_map_osd_t *osd)  osd_render_coordinates(osm_gps_map_osd_t *osd)
803  {  {
804      osd_priv_t *priv = (osd_priv_t*)osd->priv;      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 */      /* first fill with transparency */
811      cairo_t *cr = cairo_create(priv->coordinates);      cairo_t *cr = cairo_create(priv->coordinates);
812      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);      cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
# Line 750  osd_render_coordinates(osm_gps_map_osd_t Line 815  osd_render_coordinates(osm_gps_map_osd_t
815      cairo_paint(cr);      cairo_paint(cr);
816      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);      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);      cairo_destroy(cr);
858  }  }
859  #endif  // OSD_COORDINATES  #endif  // OSD_COORDINATES

Legend:
Removed from v.106  
changed lines
  Added in v.107