+ GdkColor color;
+ // This is just an indicator - no actual values can be inferred by user
+ GdkGC *elev_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
+ gdk_color_parse ( "red", &color );
+ gdk_gc_set_rgb_fg_color ( elev_speed_gc, &color);
+
+ gdouble max_speed = widgets->max_speed * 110 / 100;
+
+ 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), elev_speed_gc, TRUE, i+MARGIN_X-2, y_speed-2, 4, 4);
+ }
+
+ g_object_unref ( G_OBJECT(elev_speed_gc) );
+ }
+
+ /* draw border */
+ gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN_X, MARGIN_Y, widgets->profile_width-1, widgets->profile_height-1);
+
+ g_object_unref ( G_OBJECT(pix) );
+}
+
+/**
+ * Draw just the speed/distance image
+ */
+static void draw_sd ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
+{
+ gdouble mins;
+ guint i;
+
+ // Free previous allocation
+ if ( widgets->speeds_dist )
+ g_free ( widgets->speeds_dist );
+
+ widgets->speeds_dist = vik_track_make_speed_dist_map ( tr, widgets->profile_width );
+ if ( widgets->speeds_dist == NULL )
+ return;
+
+ // Convert into appropriate units
+ vik_units_speed_t speed_units = a_vik_get_units_speed ();
+ switch (speed_units) {
+ case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
+ for ( i = 0; i < widgets->profile_width; i++ ) {
+ widgets->speeds_dist[i] = VIK_MPS_TO_KPH(widgets->speeds_dist[i]);
+ }
+ break;
+ case VIK_UNITS_SPEED_MILES_PER_HOUR:
+ for ( i = 0; i < widgets->profile_width; i++ ) {
+ widgets->speeds_dist[i] = VIK_MPS_TO_MPH(widgets->speeds_dist[i]);
+ }
+ break;
+ case VIK_UNITS_SPEED_KNOTS:
+ for ( i = 0; i < widgets->profile_width; i++ ) {
+ widgets->speeds_dist[i] = VIK_MPS_TO_KNOTS(widgets->speeds_dist[i]);
+ }
+ break;
+ default:
+ // VIK_UNITS_SPEED_METRES_PER_SECOND:
+ // No need to convert as already in m/s
+ break;
+ }
+
+ GtkWidget *window = gtk_widget_get_toplevel (widgets->speed_dist_box);
+ GdkPixmap *pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width+MARGIN_X, widgets->profile_height+MARGIN_Y, -1 );
+
+ gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
+
+ // OK to resuse min_speed here
+ minmax_array(widgets->speeds_dist, &widgets->min_speed, &widgets->max_speed_dist, FALSE, widgets->profile_width);
+ if (widgets->min_speed < 0.0)
+ widgets->min_speed = 0; /* splines sometimes give negative speeds */
+
+ /* Find suitable chunk index */
+ get_new_min_and_chunk_index (widgets->min_speed, widgets->max_speed_dist, chunkss, G_N_ELEMENTS(chunkss), &widgets->draw_min_speed, &widgets->cisd);
+
+ // Assign locally
+ mins = widgets->draw_min_speed;
+
+ // Reset before redrawing
+ clear_images (pix, window, widgets);
+
+ /* draw grid */
+ for (i=0; i<=LINES; i++) {
+ gchar s[32];
+
+ // NB: No need to convert here anymore as numbers are in the appropriate units
+ switch (speed_units) {
+ case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
+ sprintf(s, "%8dkm/h", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
+ break;
+ case VIK_UNITS_SPEED_MILES_PER_HOUR:
+ sprintf(s, "%8dmph", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
+ break;
+ case VIK_UNITS_SPEED_METRES_PER_SECOND:
+ sprintf(s, "%8dm/s", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
+ break;
+ case VIK_UNITS_SPEED_KNOTS:
+ sprintf(s, "%8dknots", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
+ break;
+ default:
+ sprintf(s, "--");
+ g_critical("Houston, we've had a problem. speed=%d", speed_units);
+ }
+
+ draw_grid_y ( window, image, widgets, pix, s, i );
+ }
+
+ draw_distance_divisions ( window, image, pix, widgets, a_vik_get_units_distance() );
+
+ /* draw speeds */
+ guint height = widgets->profile_height + MARGIN_Y;
+ for ( i = 0; i < widgets->profile_width; i++ )
+ gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
+ i + MARGIN_X, height, i + MARGIN_X, height - widgets->profile_height*(widgets->speeds_dist[i]-mins)/(chunkss[widgets->cisd]*LINES) );
+
+
+ if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_sd_gps_speed)) ) {
+
+ GdkGC *gps_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );