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

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

revision 100 by harbaum, Tue Sep 8 10:24:11 2009 UTC revision 102 by harbaum, Tue Sep 8 19:08:37 2009 UTC
# Line 736  dist_str_metric(int dist) Line 736  dist_str_metric(int dist)
736      return g_strdup_printf("%u km", dist/1000);      return g_strdup_printf("%u km", dist/1000);
737  }  }
738    
739    #define OSD_SCALE_FONT_SIZE 12
740    
741  static void  static void
742  osd_render_scale(osm_gps_map_osd_t *osd)  osd_render_scale(osm_gps_map_osd_t *osd)
743  {  {
# Line 752  osd_render_scale(osm_gps_map_osd_t *osd) Line 754  osd_render_scale(osm_gps_map_osd_t *osd)
754    
755      /* determine the size of the scale width in meters */      /* determine the size of the scale width in meters */
756      float width = (OSD_SCALE_W-2) * m_per_pix;      float width = (OSD_SCALE_W-2) * m_per_pix;
757      printf("width = %f meters\n", width);      printf("%d pixels is %f m\n", OSD_SCALE_W-2, width);
758    
759      /* scale this to useful values */      /* scale this to useful values */
760      int exp = logf(width)*M_LOG10E;      int exp = logf(width)*M_LOG10E;
761      int mant = width/pow(10,exp);      int mant = width/pow(10,exp);
     printf("mant = %d, exp = %d \n", mant, exp);  
   
762      int width_metric = mant * pow(10,exp);      int width_metric = mant * pow(10,exp);
763      char *dist_str = dist_str_metric(width_metric);      char *dist_str = dist_str_metric(width_metric);
764      width_metric /= m_per_pix;      width_metric /= m_per_pix;
     printf("metric scale width = %d pixels: %s\n", width_metric, dist_str);  
765    
766      int font_size = 12;      /* and now the hard part: scale for useful imperial values :-( */
767        /* try to convert to feet, 1ft == 0.3048 m */
768        width /= 0.3048;
769        float imp_scale = 0.3048;
770        char *dist_imp_unit = "ft";
771    
772        if(width >= 100) {
773            /* 1yd == 3 feet */
774            width /= 3.0;
775            imp_scale *= 3.0;
776            dist_imp_unit = "yd";
777    
778            if(width >= 1760.0) {
779                /* 1mi == 1760 yd */
780                width /= 1760.0;
781                imp_scale *= 1760.0;
782                dist_imp_unit = "mi";
783            }
784        }
785    
786        printf("this is %f %s\n", width, dist_imp_unit);
787        printf("this is %f pixels\n", width * imp_scale / m_per_pix);
788    
789      cairo_select_font_face (cr, "Sans",      cairo_select_font_face (cr, "Sans",
790                              CAIRO_FONT_SLANT_NORMAL,                              CAIRO_FONT_SLANT_NORMAL,
791                              CAIRO_FONT_WEIGHT_BOLD);                              CAIRO_FONT_WEIGHT_BOLD);
792      cairo_set_font_size (cr, font_size);      cairo_set_font_size (cr, OSD_SCALE_FONT_SIZE);
793      cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);      cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
794    
795      cairo_text_extents_t extents;      cairo_text_extents_t extents;
796      cairo_text_extents (cr, dist_str, &extents);      cairo_text_extents (cr, dist_str, &extents);
797    
798      cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);      cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
799      cairo_move_to (cr, font_size/3, font_size);      cairo_move_to (cr, OSD_SCALE_FONT_SIZE/3, OSD_SCALE_FONT_SIZE);
800      cairo_text_path (cr, dist_str);      cairo_text_path (cr, dist_str);
801      cairo_set_line_width (cr, 2);      cairo_set_line_width (cr, 2);
802      cairo_stroke (cr);      cairo_stroke (cr);
803    
804      cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);      cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
805      cairo_move_to (cr, font_size/3, font_size);      cairo_move_to (cr, OSD_SCALE_FONT_SIZE/3, OSD_SCALE_FONT_SIZE);
806      cairo_show_text (cr, dist_str);      cairo_show_text (cr, dist_str);
807    
808      /* draw white line */      /* draw white line */
809      cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);      cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);
810      cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0);      cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0);
811      cairo_set_line_width (cr, 4);      cairo_set_line_width (cr, 4);
812      cairo_move_to (cr, 2, 2*font_size/3);      cairo_move_to (cr, 2, 2*OSD_SCALE_FONT_SIZE/3);
813      cairo_rel_line_to (cr, 0,  2*font_size/3);      cairo_rel_line_to (cr, 0,  2*OSD_SCALE_FONT_SIZE/3);
814      cairo_rel_line_to (cr, width_metric, 0);      cairo_rel_line_to (cr, width_metric, 0);
815      cairo_rel_line_to (cr, 0, -2*font_size/3);      cairo_rel_line_to (cr, 0, -2*OSD_SCALE_FONT_SIZE/3);
816      cairo_stroke(cr);      cairo_stroke(cr);
817    
818      /* draw black line */      /* draw black line */
819      cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);      cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
820      cairo_set_line_width (cr, 2);      cairo_set_line_width (cr, 2);
821      cairo_move_to (cr, 2, 2*font_size/3);      cairo_move_to (cr, 2, 2*OSD_SCALE_FONT_SIZE/3);
822      cairo_rel_line_to (cr, 0,  2*font_size/3);      cairo_rel_line_to (cr, 0,  2*OSD_SCALE_FONT_SIZE/3);
823      cairo_rel_line_to (cr, width_metric, 0);      cairo_rel_line_to (cr, width_metric, 0);
824      cairo_rel_line_to (cr, 0, -2*font_size/3);      cairo_rel_line_to (cr, 0, -2*OSD_SCALE_FONT_SIZE/3);
825      cairo_stroke(cr);      cairo_stroke(cr);
826    
827      /* xyz */      /* xyz */

Legend:
Removed from v.100  
changed lines
  Added in v.102