+/**
+ * draw_grid_y:
+ *
+ * A common way to draw the grid with y axis labels
+ *
+ */
+static void draw_grid_y ( GtkWidget *window, GtkWidget *image, PropWidgets *widgets, GdkPixmap *pix, gchar *ss, gint i )
+{
+ PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
+
+ pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
+ pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
+
+ gchar *label_markup = g_strdup_printf ( "<span size=\"small\">%s</span>", ss );
+ pango_layout_set_markup ( pl, label_markup, -1 );
+ g_free ( label_markup );
+
+ int w, h;
+ pango_layout_get_pixel_size ( pl, &w, &h );
+
+ gdk_draw_layout ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->fg_gc[0],
+ MARGIN_X-w-3,
+ CLAMP((int)i*widgets->profile_height/LINES - h/2 + MARGIN_Y, 0, widgets->profile_height-h+MARGIN_Y),
+ pl );
+ g_object_unref ( G_OBJECT ( pl ) );
+
+ gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[0],
+ MARGIN_X, MARGIN_Y + widgets->profile_height/LINES * i,
+ MARGIN_X + widgets->profile_width, MARGIN_Y + widgets->profile_height/LINES * i );
+}
+
+/**
+ * draw_grid_x_time:
+ *
+ * A common way to draw the grid with x axis labels for time graphs
+ *
+ */
+static void draw_grid_x_time ( GtkWidget *window, GtkWidget *image, PropWidgets *widgets, GdkPixmap *pix, guint ii, guint tt, guint xx )
+{
+ gchar *label_markup = NULL;
+ switch (ii) {
+ case 0:
+ case 1:
+ case 2:
+ case 3:
+ // Minutes
+ label_markup = g_strdup_printf ( "<span size=\"small\">%d %s</span>", tt/60, _("mins") );
+ break;
+ case 4:
+ case 5:
+ case 6:
+ case 7:
+ // Hours
+ label_markup = g_strdup_printf ( "<span size=\"small\">%.1f %s</span>", (gdouble)tt/(60*60), _("h") );
+ break;
+ case 8:
+ case 9:
+ case 10:
+ // Days
+ label_markup = g_strdup_printf ( "<span size=\"small\">%.1f %s</span>", (gdouble)tt/(60*60*24), _("d") );
+ break;
+ case 11:
+ case 12:
+ // Weeks
+ label_markup = g_strdup_printf ( "<span size=\"small\">%.1f %s</span>", (gdouble)tt/(60*60*24*7), _("w") );
+ break;
+ case 13:
+ // 'Months'
+ label_markup = g_strdup_printf ( "<span size=\"small\">%.1f %s</span>", (gdouble)tt/(60*60*24*28), _("M") );
+ break;
+ default:
+ break;
+ }
+ if ( label_markup ) {
+
+ PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
+ pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
+
+ pango_layout_set_markup ( pl, label_markup, -1 );
+ g_free ( label_markup );
+ int ww, hh;
+ pango_layout_get_pixel_size ( pl, &ww, &hh );
+
+ gdk_draw_layout ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->fg_gc[0],
+ MARGIN_X+xx-ww/2, MARGIN_Y/2-hh/2, pl );
+ g_object_unref ( G_OBJECT ( pl ) );
+ }
+
+ gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[0],
+ MARGIN_X+xx, MARGIN_Y, MARGIN_X+xx, MARGIN_Y+widgets->profile_height );
+}
+
+/**
+ * draw_grid_x_distance:
+ *
+ * A common way to draw the grid with x axis labels for distance graphs
+ *
+ */
+static void draw_grid_x_distance ( GtkWidget *window, GtkWidget *image, PropWidgets *widgets, GdkPixmap *pix, guint ii, gdouble dd, guint xx, vik_units_distance_t dist_units )
+{
+ gchar *label_markup = NULL;
+ switch ( dist_units ) {
+ case VIK_UNITS_DISTANCE_MILES:
+ if ( ii > 4 )
+ label_markup = g_strdup_printf ( "<span size=\"small\">%d %s</span>", (guint)dd, _("miles") );
+ else
+ label_markup = g_strdup_printf ( "<span size=\"small\">%.1f %s</span>", dd, _("miles") );
+ break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ if ( ii > 4 )
+ label_markup = g_strdup_printf ( "<span size=\"small\">%d %s</span>", (guint)dd, _("NM") );
+ else
+ label_markup = g_strdup_printf ( "<span size=\"small\">%.1f %s</span>", dd, _("NM") );
+ break;
+ default:
+ // VIK_UNITS_DISTANCE_KILOMETRES:
+ if ( ii > 4 )
+ label_markup = g_strdup_printf ( "<span size=\"small\">%d %s</span>", (guint)dd, _("km") );
+ else
+ label_markup = g_strdup_printf ( "<span size=\"small\">%.1f %s</span>", dd, _("km") );
+ break;
+ }
+
+ if ( label_markup ) {
+ PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
+ pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
+
+ pango_layout_set_markup ( pl, label_markup, -1 );
+ g_free ( label_markup );
+ int ww, hh;
+ pango_layout_get_pixel_size ( pl, &ww, &hh );
+
+ gdk_draw_layout ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->fg_gc[0],
+ MARGIN_X+xx-ww/2, MARGIN_Y/2-hh/2, pl );
+ g_object_unref ( G_OBJECT ( pl ) );
+ }
+
+ gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[0],
+ MARGIN_X+xx, MARGIN_Y, MARGIN_X+xx, MARGIN_Y+widgets->profile_height );
+}
+
+/**
+ * clear the images (scale texts & actual graph)
+ */
+static void clear_images (GdkPixmap *pix, GtkWidget *window, PropWidgets *widgets)
+{
+ gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
+ TRUE, 0, 0, widgets->profile_width+MARGIN_X, widgets->profile_height+MARGIN_Y);
+ gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
+ TRUE, 0, 0, widgets->profile_width+MARGIN_X, widgets->profile_height+MARGIN_Y);
+}
+
+/**
+ *
+ */
+static void draw_distance_divisions ( GtkWidget *window, GtkWidget *image, GdkPixmap *pix, PropWidgets *widgets, vik_units_distance_t dist_units )
+{
+ // Set to display units from length in metres.
+ gdouble length = widgets->track_length_inc_gaps;
+ switch (dist_units) {
+ case VIK_UNITS_DISTANCE_MILES:
+ length = VIK_METERS_TO_MILES(length);
+ break;
+ case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+ length = VIK_METERS_TO_NAUTICAL_MILES(length);
+ break;
+ default:
+ // KM
+ length = length/1000.0;
+ break;
+ }
+ guint index = get_distance_chunk_index ( length );
+ gdouble dist_per_pixel = length/widgets->profile_width;
+
+ for (guint i=1; chunksd[index]*i <= length; i++) {
+ draw_grid_x_distance ( window, image, widgets, pix, index, chunksd[index]*i, (guint)(chunksd[index]*i/dist_per_pixel), dist_units );
+ }
+}
+