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

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

revision 98 by harbaum, Mon Sep 7 13:20:37 2009 UTC revision 99 by harbaum, Mon Sep 7 19:22:02 2009 UTC
# Line 728  osd_zoom_labels(cairo_t *cr, gint x, gin Line 728  osd_zoom_labels(cairo_t *cr, gint x, gin
728      cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID);      cairo_line_to (cr, x + Z_RIGHT + Z_LEN, y + Z_MID);
729  }  }
730    
731  static float pixel2m(OsmGpsMap *map, int pixel) {  static char *
732    return pixel*osm_gps_map_get_scale(OSM_GPS_MAP(map));  dist_str_metric(int dist)
733    {
734        if(dist<1000)
735            return g_strdup_printf("%u m",  dist);
736    
737        return g_strdup_printf("%u km", dist/1000);
738  }  }
739    
740  static void  static void
741  osd_render_scale(osm_gps_map_osd_t *osd)  osd_render_scale(osm_gps_map_osd_t *osd)
742  {  {
743      osd_priv_t *priv = (osd_priv_t*)osd->priv;      osd_priv_t *priv = (osd_priv_t*)osd->priv;
744        float m_per_pix = osm_gps_map_get_scale(OSM_GPS_MAP(osd->widget));
745    
746      /* first fill with transparency */      /* first fill with transparency */
747      cairo_t *cr = cairo_create(priv->scale);      cairo_t *cr = cairo_create(priv->scale);
# Line 746  osd_render_scale(osm_gps_map_osd_t *osd) Line 752  osd_render_scale(osm_gps_map_osd_t *osd)
752      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);      cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
753    
754      /* determine the size of the scale width in meters */      /* determine the size of the scale width in meters */
755      float width = pixel2m(OSM_GPS_MAP(osd->widget), OSD_SCALE_W);      float width = (OSD_SCALE_W-2) * m_per_pix;
756      printf("width = %f meters\n", width);      printf("width = %f meters\n", width);
757    
758      /* scale this to useful values */      /* scale this to useful values */
# Line 754  osd_render_scale(osm_gps_map_osd_t *osd) Line 760  osd_render_scale(osm_gps_map_osd_t *osd)
760      int mant = width/pow(10,exp);      int mant = width/pow(10,exp);
761      printf("mant = %d, exp = %d \n", mant, exp);      printf("mant = %d, exp = %d \n", mant, exp);
762    
763        int width_metric = mant * pow(10,exp);
764        char *dist_str = dist_str_metric(width_metric);
765        width_metric /= m_per_pix;
766        printf("metric scale width = %d pixels: %s\n", width_metric, dist_str);
767    
768        int font_size = 12;
769    
770        cairo_select_font_face (cr, "Sans",
771                                CAIRO_FONT_SLANT_NORMAL,
772                                CAIRO_FONT_WEIGHT_BOLD);
773        cairo_set_font_size (cr, font_size);
774        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
775    
776        cairo_text_extents_t extents;
777        cairo_text_extents (cr, dist_str, &extents);
778    
779        cairo_move_to (cr, font_size/3, font_size);
780        cairo_show_text (cr, dist_str);
781    
782        printf("height = %f, bearing = %f\n",  extents.height, extents.y_bearing);
783    
784        /* draw white line */
785        cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);
786        cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0);
787        cairo_set_line_width (cr, 3);
788        cairo_move_to (cr, 2, 2*font_size/3);
789        cairo_rel_line_to (cr, 0,  2*font_size/3);
790        cairo_rel_line_to (cr, width_metric, 0);
791        cairo_rel_line_to (cr, 0, -2*font_size/3);
792        cairo_stroke(cr);
793    
794        /* draw black line */
795        cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 1.0);
796        cairo_set_line_width (cr, 2);
797        cairo_move_to (cr, 2, 2*font_size/3);
798        cairo_rel_line_to (cr, 0,  2*font_size/3);
799        cairo_rel_line_to (cr, width_metric, 0);
800        cairo_rel_line_to (cr, 0, -2*font_size/3);
801        cairo_stroke(cr);
802    
803        /* xyz */
804    
805      cairo_destroy(cr);      cairo_destroy(cr);
806  }  }
807    
# Line 872  osd_draw(osm_gps_map_osd_t *osd, GdkDraw Line 920  osd_draw(osm_gps_map_osd_t *osd, GdkDraw
920  #ifdef OSD_SCALE  #ifdef OSD_SCALE
921          priv->scale =          priv->scale =
922              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,              cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
923                                         OSD_SCALE_W, OSD_SCALE_H);                                         OSD_SCALE_W+2, OSD_SCALE_H+2);
924  #endif  #endif
925    
926          /* ... and render it */          /* ... and render it */

Legend:
Removed from v.98  
changed lines
  Added in v.99