+}
+
+/**
+ * Draw just the distance/time image
+ */
+static void draw_dt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
+{
+ GtkWidget *window;
+ GdkPixmap *pix;
+ gdouble maxd;
+ guint i;
+
+ // Free previous allocation
+ if ( widgets->distances )
+ g_free ( widgets->distances );
+
+ widgets->distances = vik_track_make_distance_map ( tr, widgets->profile_width );
+ if ( widgets->distances == NULL )
+ return;
+
+ // Convert into appropriate units
+ vik_units_distance_t dist_units = a_vik_get_units_distance ();
+ if ( dist_units == VIK_UNITS_DISTANCE_MILES ) {
+ for ( i = 0; i < widgets->profile_width; i++ ) {
+ widgets->distances[i] = VIK_METERS_TO_MILES(widgets->distances[i]);
+ }
+ }
+ else {
+ // Metres - but want in kms
+ for ( i = 0; i < widgets->profile_width; i++ ) {
+ widgets->distances[i] = widgets->distances[i]/1000.0;
+ }
+ }
+
+ window = gtk_widget_get_toplevel (widgets->dist_box);
+
+ pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+
+ gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
+
+ // easy to work out min / max of distance!
+ // Assign locally
+ // mind = 0.0; - Thus not used
+ if ( dist_units == VIK_UNITS_DISTANCE_MILES )
+ maxd = VIK_METERS_TO_MILES(vik_track_get_length_including_gaps (tr));
+ else
+ maxd = vik_track_get_length_including_gaps (tr) / 1000.0;
+
+ /* Find suitable chunk index */
+ gdouble dummy = 0.0; // expect this to remain the same! (not that it's used)
+ get_new_min_and_chunk_index (0, maxd, chunksd, sizeof(chunksd)/sizeof(chunksd[0]), &dummy, &widgets->cid);
+
+ /* clear the image */
+ gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->bg_gc[0],
+ TRUE, 0, 0, MARGIN, widgets->profile_height);
+ gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->mid_gc[0],
+ TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
+
+ /* draw grid */
+ for (i=0; i<=LINES; i++) {
+ PangoFontDescription *pfd;
+ PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
+ gchar s[32];
+ int w, h;
+
+ pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
+ pfd = pango_font_description_from_string (PROPWIN_LABEL_FONT);
+ pango_layout_set_font_description (pl, pfd);
+ pango_font_description_free (pfd);
+ if ( dist_units == VIK_UNITS_DISTANCE_MILES )
+ sprintf(s, _("%.1f miles"), ((LINES-i)*chunksd[widgets->cid]));
+ else
+ sprintf(s, _("%.1f km"), ((LINES-i)*chunksd[widgets->cid]));
+
+ pango_layout_set_text(pl, s, -1);
+ pango_layout_get_pixel_size (pl, &w, &h);
+ gdk_draw_layout(GDK_DRAWABLE(pix), window->style->fg_gc[0], MARGIN-w-3,
+ CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
+
+ gdk_draw_line (GDK_DRAWABLE(pix), window->style->dark_gc[0],
+ MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
+ g_object_unref ( G_OBJECT ( pl ) );
+ pl = NULL;
+ }
+
+ /* draw distance */
+ for ( i = 0; i < widgets->profile_width; i++ )
+ gdk_draw_line ( GDK_DRAWABLE(pix), window->style->dark_gc[3],
+ i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->distances[i])/(chunksd[widgets->cid]*LINES) );
+
+ // Show speed indicator
+ if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_dist_speed)) ) {
+ GdkGC *dist_speed_gc = gdk_gc_new ( window->window );
+ GdkColor color;
+ gdk_color_parse ( "red", &color );
+ gdk_gc_set_rgb_fg_color ( dist_speed_gc, &color);
+
+ gdouble max_speed = 0;
+ max_speed = widgets->max_speed * 110 / 100;
+
+ // This is just an indicator - no actual values can be inferred by user
+ gint i;
+ for ( i = 0; i < widgets->profile_width; i++ ) {
+ int y_speed = widgets->profile_height - (widgets->profile_height * widgets->speeds[i])/max_speed;
+ gdk_draw_rectangle(GDK_DRAWABLE(pix), dist_speed_gc, TRUE, i+MARGIN-2, y_speed-2, 4, 4);
+ }
+ g_object_unref ( G_OBJECT(dist_speed_gc) );
+ }
+
+ /* draw border */
+ gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
+
+ g_object_unref ( G_OBJECT(pix) );
+