* Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
* Copyright (C) 2005-2007, Alex Foobarian <foobarian@gmail.com>
* Copyright (C) 2007-2008, Quy Tonthat <qtonthat@gmail.com>
+ * Copyright (C) 2011, Rob Norris <rw_norris@hotmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#define PROPWIN_LABEL_FONT "Sans 7"
-#define MIN_ALT_DIFF 100.0
-#define MIN_SPEED_DIFF 5.0
+typedef enum {
+ PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE,
+ PROPWIN_GRAPH_TYPE_SPEED_TIME,
+ PROPWIN_GRAPH_TYPE_DISTANCE_TIME,
+ PROPWIN_GRAPH_TYPE_ELEVATION_TIME,
+ PROPWIN_GRAPH_TYPE_SPEED_DISTANCE,
+ PROPWIN_GRAPH_TYPE_END,
+} VikPropWinGraphType_t;
+
+/* (Hopefully!) Human friendly altitude grid sizes - note no fixed 'ratio' just numbers that look nice...*/
+static const gdouble chunksa[] = {2.0, 5.0, 10.0, 15.0, 20.0,
+ 25.0, 50.0, 75.0, 100.0,
+ 150.0, 200.0, 250.0, 375.0, 500.0,
+ 750.0, 1000.0, 2000.0, 5000.0, 10000.0, 100000.0};
+
+/* (Hopefully!) Human friendly grid sizes - note no fixed 'ratio' just numbers that look nice...*/
+/* As need to cover walking speeds - have many low numbers (but also may go up to airplane speeds!) */
+static const gdouble chunkss[] = {1.0, 2.0, 3.0, 4.0, 5.0, 8.0, 10.0,
+ 15.0, 20.0, 25.0, 40.0, 50.0, 75.0,
+ 100.0, 150.0, 200.0, 250.0, 375.0, 500.0,
+ 750.0, 1000.0, 10000.0};
+
+/* (Hopefully!) Human friendly distance grid sizes - note no fixed 'ratio' just numbers that look nice...*/
+static const gdouble chunksd[] = {0.1, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0, 8.0, 10.0,
+ 15.0, 20.0, 25.0, 40.0, 50.0, 75.0,
+ 100.0, 150.0, 200.0, 250.0, 375.0, 500.0,
+ 750.0, 1000.0, 10000.0};
typedef struct _propsaved {
gboolean saved;
- gint pos;
GdkImage *img;
} PropSaved;
gboolean configure_dialog;
VikTrwLayer *vtl;
VikTrack *tr;
- VikLayersPanel *vlp;
gchar *track_name;
gint profile_width;
gint profile_height;
GtkWidget *w_cur_elevation;
GtkWidget *w_cur_time; /*< Current time */
GtkWidget *w_cur_speed;
+ GtkWidget *w_cur_dist_dist; /*< Current distance on distance graph */
+ GtkWidget *w_cur_dist_time; /*< Current time on distance graph */
+ GtkWidget *w_cur_elev_elev;
+ GtkWidget *w_cur_elev_time;
+ GtkWidget *w_cur_speed_dist;
+ GtkWidget *w_cur_speed_speed;
+ GtkWidget *w_show_dem;
+ GtkWidget *w_show_alt_gps_speed;
+ GtkWidget *w_show_gps_speed;
+ GtkWidget *w_show_dist_speed;
+ GtkWidget *w_show_elev_speed;
+ GtkWidget *w_show_sd_gps_speed;
gdouble track_length;
PropSaved elev_graph_saved_img;
PropSaved speed_graph_saved_img;
+ PropSaved dist_graph_saved_img;
+ PropSaved elev_time_graph_saved_img;
+ PropSaved speed_dist_graph_saved_img;
GtkWidget *elev_box;
GtkWidget *speed_box;
+ GtkWidget *dist_box;
+ GtkWidget *elev_time_box;
+ GtkWidget *speed_dist_box;
gdouble *altitudes;
+ gdouble *ats; // altitudes in time
+ gdouble min_altitude;
+ gdouble max_altitude;
+ gdouble draw_min_altitude;
+ gint cia; // Chunk size Index into Altitudes
gdouble *speeds;
+ gdouble *speeds_dist;
+ gdouble min_speed;
+ gdouble max_speed;
+ gdouble draw_min_speed;
+ gdouble max_speed_dist;
+ gint cis; // Chunk size Index into Speeds
+ gint cisd; // Chunk size Index into Speed/Distance
+ gdouble *distances;
+ gint cid; // Chunk size Index into Distance
VikTrackpoint *marker_tp;
gboolean is_marker_drawn;
+ VikTrackpoint *blob_tp;
+ gboolean is_blob_drawn;
} PropWidgets;
static PropWidgets *prop_widgets_new()
g_object_unref(widgets->elev_graph_saved_img.img);
if (widgets->speed_graph_saved_img.img)
g_object_unref(widgets->speed_graph_saved_img.img);
+ if (widgets->dist_graph_saved_img.img)
+ g_object_unref(widgets->dist_graph_saved_img.img);
+ if (widgets->elev_time_graph_saved_img.img)
+ g_object_unref(widgets->elev_time_graph_saved_img.img);
+ if (widgets->speed_dist_graph_saved_img.img)
+ g_object_unref(widgets->speed_dist_graph_saved_img.img);
if (widgets->altitudes)
g_free(widgets->altitudes);
if (widgets->speeds)
g_free(widgets->speeds);
+ if (widgets->distances)
+ g_free(widgets->distances);
+ if (widgets->ats)
+ g_free(widgets->ats);
+ if (widgets->speeds_dist)
+ g_free(widgets->speeds_dist);
g_free(widgets);
}
#define MARGIN 70
#define LINES 5
+/**
+ * Returns via pointers:
+ * the new minimum value to be used for the altitude graph
+ * the index in to the altitudes chunk sizes array (ci = Chunk Index)
+ */
+static void get_new_min_and_chunk_index_altitude (gdouble mina, gdouble maxa, gdouble *new_min, gint *ci)
+{
+ /* Get unitized chunk */
+ /* Find suitable chunk index */
+ *ci = 0;
+ gdouble diffa_chunk = (maxa - mina)/LINES;
+
+ /* Loop through to find best match */
+ while (diffa_chunk > chunksa[*ci]) {
+ (*ci)++;
+ /* Last Resort Check */
+ if ( *ci == sizeof(chunksa)/sizeof(chunksa[0]) )
+ break;
+ }
+
+ /* Ensure adjusted minimum .. maximum covers mina->maxa */
+
+ // Now work out adjusted minimum point to the nearest lowest chunk divisor value
+ // When negative ensure logic uses lowest value
+ if ( mina < 0 )
+ *new_min = (gdouble) ( ( (gint)(mina - chunksa[*ci]) / (gint)chunksa[*ci] ) * (gint)chunksa[*ci] );
+ else
+ *new_min = (gdouble) ( ( (gint)mina / (gint)chunksa[*ci] ) * (gint)chunksa[*ci] );
+
+ // Range not big enough - as new minimum has lowered
+ if ((*new_min + (chunksa[*ci] * LINES) < maxa)) {
+ // Next chunk should cover it
+ if ( *ci < sizeof(chunksa)/sizeof(chunksa[0]) ) {
+ (*ci)++;
+ }
+ }
+}
+
+/**
+ * Returns via pointers:
+ * the new minimum value to be used for the appropriate graph
+ * the index in to that array (ci = Chunk Index)
+ */
+static void get_new_min_and_chunk_index (gdouble mins, gdouble maxs, const gdouble *chunks, size_t chunky, gdouble *new_min, gint *ci)
+{
+ *ci = 0;
+ gdouble diff_chunk = (maxs - mins)/LINES;
+
+ /* Loop through to find best match */
+ while (diff_chunk > chunks[*ci]) {
+ (*ci)++;
+ /* Last Resort Check */
+ if ( *ci == chunky )
+ break;
+ }
+ *new_min = (gdouble) ( (gint)((mins / chunks[*ci] ) * chunks[*ci]) );
+
+ // Speeds are never negative so don't need to worry about a negative new minimum
+}
+
static VikTrackpoint *set_center_at_graph_position(gdouble event_x,
gint img_width,
VikTrwLayer *vtl,
}
/**
- * Returns whether the marker was drawn or not
+ * Returns whether the marker was drawn or not and whether the blob was drawn or not
*/
-static void save_image_and_draw_graph_mark (GtkWidget *image,
- gdouble event_x,
- gint img_width,
- GdkGC *gc,
- PropSaved *saved_img,
- gint PROFILE_WIDTH,
- gint PROFILE_HEIGHT,
- gboolean *marker_drawn)
+static void save_image_and_draw_graph_marks (GtkWidget *image,
+ gdouble marker_x,
+ GdkGC *gc,
+ gint blob_x,
+ gint blob_y,
+ PropSaved *saved_img,
+ gint PROFILE_WIDTH,
+ gint PROFILE_HEIGHT,
+ gboolean *marker_drawn,
+ gboolean *blob_drawn)
{
GdkPixmap *pix = NULL;
/* the pixmap = margin + graph area */
- gdouble x = event_x - img_width/2 + PROFILE_WIDTH/2 + MARGIN/2;
-
- // fprintf(stderr, "event_x=%f img_width=%d x=%f\n", event_x, img_width, x);
-
gtk_image_get_pixmap(GTK_IMAGE(image), &pix, NULL);
+
/* Restore previously saved image */
if (saved_img->saved) {
- gdk_draw_image(GDK_DRAWABLE(pix), gc, saved_img->img, 0, 0,
- saved_img->pos, 0, -1, -1);
+ gdk_draw_image(GDK_DRAWABLE(pix), gc, saved_img->img, 0, 0, 0, 0, MARGIN+PROFILE_WIDTH, PROFILE_HEIGHT);
saved_img->saved = FALSE;
- gtk_widget_queue_draw_area(image,
- saved_img->pos + img_width/2 - PROFILE_WIDTH/2 - MARGIN/2, 0,
- saved_img->img->width, saved_img->img->height);
- }
- if ((x >= MARGIN) && (x < (PROFILE_WIDTH + MARGIN))) {
- /* Save part of the image */
- if (saved_img->img)
- gdk_drawable_copy_to_image(GDK_DRAWABLE(pix), saved_img->img,
- x, 0, 0, 0, saved_img->img->width, saved_img->img->height);
- else
- saved_img->img = gdk_drawable_copy_to_image(GDK_DRAWABLE(pix),
- saved_img->img, x, 0, 0, 0, 1, PROFILE_HEIGHT);
- saved_img->pos = x;
- saved_img->saved = TRUE;
- gdk_draw_line (GDK_DRAWABLE(pix), gc, x, 0, x, image->allocation.height);
- /* redraw the area which contains the line, saved_width is just convenient */
- gtk_widget_queue_draw_area(image, event_x, 0, 1, PROFILE_HEIGHT);
+ }
+
+ // ATM always save whole image - as anywhere could have changed
+ if (saved_img->img)
+ gdk_drawable_copy_to_image(GDK_DRAWABLE(pix), saved_img->img, 0, 0, 0, 0, MARGIN+PROFILE_WIDTH, PROFILE_HEIGHT);
+ else
+ saved_img->img = gdk_drawable_copy_to_image(GDK_DRAWABLE(pix), saved_img->img, 0, 0, 0, 0, MARGIN+PROFILE_WIDTH, PROFILE_HEIGHT);
+ saved_img->saved = TRUE;
+
+ if ((marker_x >= MARGIN) && (marker_x < (PROFILE_WIDTH + MARGIN))) {
+ gdk_draw_line (GDK_DRAWABLE(pix), gc, marker_x, 0, marker_x, image->allocation.height);
*marker_drawn = TRUE;
}
else
*marker_drawn = FALSE;
+
+ // Draw a square blob to indicate where we are on track for this graph
+ if ( (blob_x >= MARGIN) && (blob_x < (PROFILE_WIDTH + MARGIN)) && (blob_y < PROFILE_HEIGHT) ) {
+ gdk_draw_rectangle (GDK_DRAWABLE(pix), gc, TRUE, blob_x-3, blob_y-3, 6, 6);
+ *blob_drawn = TRUE;
+ }
+ else
+ *blob_drawn = FALSE;
+
+ // Anywhere on image could have changed
+ if (*marker_drawn || *blob_drawn)
+ gtk_widget_queue_draw(image);
}
/**
return pc;
}
-static void track_graph_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along, gboolean is_vt_graph )
+static void track_graph_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along, VikPropWinGraphType_t graph_type )
{
VikTrack *tr = pass_along[0];
VikLayersPanel *vlp = pass_along[1];
VikViewport *vvp = pass_along[2];
PropWidgets *widgets = pass_along[3];
- GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
- GtkWidget *image = GTK_WIDGET(child->data);
- GtkWidget *window = gtk_widget_get_toplevel(GTK_WIDGET(event_box));
- VikTrackpoint *trackpoint = set_center_at_graph_position(event->x, event_box->allocation.width, widgets->vtl, vlp, vvp, tr, is_vt_graph, widgets->profile_width);
- save_image_and_draw_graph_mark(image,
- event->x,
- event_box->allocation.width,
- window->style->black_gc,
- is_vt_graph ? &widgets->speed_graph_saved_img : &widgets->elev_graph_saved_img,
- widgets->profile_width,
- widgets->profile_height,
- &widgets->is_marker_drawn);
- g_list_free(child);
- widgets->marker_tp = trackpoint;
- gtk_dialog_set_response_sensitive(GTK_DIALOG(widgets->dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, widgets->is_marker_drawn);
+ gboolean is_time_graph =
+ ( graph_type == PROPWIN_GRAPH_TYPE_SPEED_TIME ||
+ graph_type == PROPWIN_GRAPH_TYPE_DISTANCE_TIME ||
+ graph_type == PROPWIN_GRAPH_TYPE_ELEVATION_TIME );
- /* draw on the other graph */
- if (trackpoint == NULL || widgets->elev_box == NULL || widgets->speed_box == NULL)
- /* This test assumes we have only 2 graphs */
+ VikTrackpoint *trackpoint = set_center_at_graph_position(event->x, event_box->allocation.width, widgets->vtl, vlp, vvp, tr, is_time_graph, widgets->profile_width);
+ // Unable to get the point so give up
+ if ( trackpoint == NULL ) {
+ gtk_dialog_set_response_sensitive(GTK_DIALOG(widgets->dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, FALSE);
return;
+ }
+ widgets->marker_tp = trackpoint;
+
+ GList *child;
+ GtkWidget *image;
+ GtkWidget *window = gtk_widget_get_toplevel(GTK_WIDGET(event_box));
+ GtkWidget *graph_box;
+ PropSaved *graph_saved_img;
gdouble pc = NAN;
- gdouble x2;
- GList *other_child = gtk_container_get_children(GTK_CONTAINER(
- is_vt_graph ? widgets->elev_box : widgets->speed_box));
- GtkWidget *other_image = GTK_WIDGET(other_child->data);
- if (is_vt_graph) {
- pc = tp_percentage_by_distance ( tr, trackpoint, widgets->track_length );
- } else {
- pc = tp_percentage_by_time ( tr, trackpoint );
- }
- if (!isnan(pc)) {
- x2 = pc * widgets->profile_width + MARGIN + (event_box->allocation.width/2 - widgets->profile_width/2 - MARGIN/2);
- save_image_and_draw_graph_mark(other_image,
- x2,
- event_box->allocation.width,
- window->style->black_gc,
- is_vt_graph ? &widgets->elev_graph_saved_img : &widgets->speed_graph_saved_img,
- widgets->profile_width,
- widgets->profile_height,
- &widgets->is_marker_drawn);
- }
- g_list_free(other_child);
+ // Attempt to redraw marker on all graph types
+ gint graphite;
+ for ( graphite = PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE;
+ graphite < PROPWIN_GRAPH_TYPE_END;
+ graphite++ ) {
+
+ // Switch commonal variables to particular graph type
+ switch (graphite) {
+ default:
+ case PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE:
+ graph_box = widgets->elev_box;
+ graph_saved_img = &widgets->elev_graph_saved_img;
+ is_time_graph = FALSE;
+ break;
+ case PROPWIN_GRAPH_TYPE_SPEED_TIME:
+ graph_box = widgets->speed_box;
+ graph_saved_img = &widgets->speed_graph_saved_img;
+ is_time_graph = TRUE;
+ break;
+ case PROPWIN_GRAPH_TYPE_DISTANCE_TIME:
+ graph_box = widgets->dist_box;
+ graph_saved_img = &widgets->dist_graph_saved_img;
+ is_time_graph = TRUE;
+ break;
+ case PROPWIN_GRAPH_TYPE_ELEVATION_TIME:
+ graph_box = widgets->elev_time_box;
+ graph_saved_img = &widgets->elev_time_graph_saved_img;
+ is_time_graph = TRUE;
+ break;
+ case PROPWIN_GRAPH_TYPE_SPEED_DISTANCE:
+ graph_box = widgets->speed_dist_box;
+ graph_saved_img = &widgets->speed_dist_graph_saved_img;
+ is_time_graph = FALSE;
+ break;
+ }
+
+ // Commonal method of redrawing marker
+ if ( graph_box ) {
+
+ child = gtk_container_get_children(GTK_CONTAINER(graph_box));
+ image = GTK_WIDGET(child->data);
+
+ if (is_time_graph)
+ pc = tp_percentage_by_time ( tr, trackpoint );
+ else
+ pc = tp_percentage_by_distance ( tr, trackpoint, widgets->track_length );
+
+ if (!isnan(pc)) {
+ gdouble marker_x = (pc * widgets->profile_width) + MARGIN;
+ save_image_and_draw_graph_marks(image,
+ marker_x,
+ window->style->black_gc,
+ -1, // Don't draw blob on clicks
+ 0,
+ graph_saved_img,
+ widgets->profile_width,
+ widgets->profile_height,
+ &widgets->is_marker_drawn,
+ &widgets->is_blob_drawn);
+ }
+ g_list_free(child);
+ }
+ }
+ gtk_dialog_set_response_sensitive(GTK_DIALOG(widgets->dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, widgets->is_marker_drawn);
}
static gboolean track_profile_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along )
{
- track_graph_click(event_box, event, pass_along, FALSE);
+ track_graph_click(event_box, event, pass_along, PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE);
return TRUE; /* don't call other (further) callbacks */
}
static gboolean track_vt_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along )
{
- track_graph_click(event_box, event, pass_along, TRUE);
+ track_graph_click(event_box, event, pass_along, PROPWIN_GRAPH_TYPE_SPEED_TIME);
+ return TRUE; /* don't call other (further) callbacks */
+}
+
+static gboolean track_dt_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along )
+{
+ track_graph_click(event_box, event, pass_along, PROPWIN_GRAPH_TYPE_DISTANCE_TIME);
+ return TRUE; /* don't call other (further) callbacks */
+}
+
+static gboolean track_et_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along )
+{
+ track_graph_click(event_box, event, pass_along, PROPWIN_GRAPH_TYPE_ELEVATION_TIME);
+ return TRUE; /* don't call other (further) callbacks */
+}
+
+static gboolean track_sd_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along )
+{
+ track_graph_click(event_box, event, pass_along, PROPWIN_GRAPH_TYPE_SPEED_DISTANCE);
return TRUE; /* don't call other (further) callbacks */
}
-void track_profile_move( GtkWidget *image, GdkEventMotion *event, gpointer *pass_along )
+/**
+ * Calculate y position for blob on elevation graph
+ */
+static gint blobby_altitude ( gdouble x_blob, PropWidgets *widgets )
+{
+ gint ix = (gint)x_blob;
+ // Ensure ix is inbounds
+ if (ix == widgets->profile_width)
+ ix--;
+
+ gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->altitudes[ix]-widgets->draw_min_altitude)/(chunksa[widgets->cia]*LINES);
+
+ return y_blob;
+}
+
+/**
+ * Calculate y position for blob on speed graph
+ */
+static gint blobby_speed ( gdouble x_blob, PropWidgets *widgets )
+{
+ gint ix = (gint)x_blob;
+ // Ensure ix is inbounds
+ if (ix == widgets->profile_width)
+ ix--;
+
+ gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->speeds[ix]-widgets->draw_min_speed)/(chunkss[widgets->cis]*LINES);
+
+ return y_blob;
+}
+
+/**
+ * Calculate y position for blob on distance graph
+ */
+static gint blobby_distance ( gdouble x_blob, PropWidgets *widgets )
+{
+ gint ix = (gint)x_blob;
+ // Ensure ix is inbounds
+ if (ix == widgets->profile_width)
+ ix--;
+
+ gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->distances[ix])/(chunksd[widgets->cid]*LINES);
+ //NB min distance is always 0, so no need to subtract that from this ______/
+
+ return y_blob;
+}
+
+/**
+ * Calculate y position for blob on elevation/time graph
+ */
+static gint blobby_altitude_time ( gdouble x_blob, PropWidgets *widgets )
+{
+ gint ix = (gint)x_blob;
+ // Ensure ix is inbounds
+ if (ix == widgets->profile_width)
+ ix--;
+
+ gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->ats[ix]-widgets->draw_min_altitude)/(chunksa[widgets->cia]*LINES);
+ // only difference here [could refactor]? _____________________/
+ return y_blob;
+}
+
+/**
+ * Calculate y position for blob on speed/dist graph
+ */
+static gint blobby_speed_dist ( gdouble x_blob, PropWidgets *widgets )
+{
+ gint ix = (gint)x_blob;
+ // Ensure ix is inbounds
+ if (ix == widgets->profile_width)
+ ix--;
+
+ gint y_blob = widgets->profile_height-widgets->profile_height*(widgets->speeds_dist[ix]-widgets->draw_min_speed)/(chunkss[widgets->cisd]*LINES);
+
+ return y_blob;
+}
+
+
+void track_profile_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_along )
{
VikTrack *tr = pass_along[0];
PropWidgets *widgets = pass_along[3];
else
mouse_x = event->x;
- gdouble x = mouse_x - image->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
+ gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
if (x < 0)
x = 0;
if (x > widgets->profile_width)
g_snprintf(tmp_buf, sizeof(tmp_buf), "%d m", (int)trackpoint->altitude);
gtk_label_set_text(GTK_LABEL(widgets->w_cur_elevation), tmp_buf);
}
+
+ widgets->blob_tp = trackpoint;
+
+ if ( widgets->altitudes == NULL )
+ return;
+
+ GtkWidget *window = gtk_widget_get_toplevel (event_box);
+ GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
+ GtkWidget *image = GTK_WIDGET(child->data);
+
+ gint y_blob = blobby_altitude (x, widgets);
+
+ gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
+ if (widgets->is_marker_drawn) {
+ gdouble pc = tp_percentage_by_distance ( tr, widgets->marker_tp, widgets->track_length );
+ if (!isnan(pc)) {
+ marker_x = (pc * widgets->profile_width) + MARGIN;
+ }
+ }
+
+ save_image_and_draw_graph_marks (image,
+ marker_x,
+ window->style->black_gc,
+ MARGIN+x,
+ y_blob,
+ &widgets->elev_graph_saved_img,
+ widgets->profile_width,
+ widgets->profile_height,
+ &widgets->is_marker_drawn,
+ &widgets->is_blob_drawn);
+
+ g_list_free(child);
}
-void track_vt_move( GtkWidget *image, GdkEventMotion *event, gpointer *pass_along )
+void track_vt_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_along )
{
VikTrack *tr = pass_along[0];
PropWidgets *widgets = pass_along[3];
else
mouse_x = event->x;
- gdouble x = mouse_x - image->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
+ gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
if (x < 0)
x = 0;
if (x > widgets->profile_width)
gtk_label_set_text(GTK_LABEL(widgets->w_cur_time), tmp_buf);
}
+ gint ix = (gint)x;
+ // Ensure ix is inbounds
+ if (ix == widgets->profile_width)
+ ix--;
+
// Show track speed for this position
if (trackpoint && widgets->w_cur_speed) {
static gchar tmp_buf[20];
// Even if GPS speed available (trackpoint->speed), the text will correspond to the speed map shown
- gint ix = (gint)x;
- // Ensure ix is inbounds
- if (ix == widgets->profile_width)
- ix--;
-
+ // No conversions needed as already in appropriate units
vik_units_speed_t speed_units = a_vik_get_units_speed ();
switch (speed_units) {
case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
- g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f kph"), VIK_MPS_TO_KPH(widgets->speeds[ix]));
+ g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f kph"), widgets->speeds[ix]);
break;
case VIK_UNITS_SPEED_MILES_PER_HOUR:
- g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f mph"), VIK_MPS_TO_MPH(widgets->speeds[ix]));
+ g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f mph"), widgets->speeds[ix]);
break;
case VIK_UNITS_SPEED_KNOTS:
- g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f knots"), VIK_MPS_TO_KNOTS(widgets->speeds[ix]));
+ g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f knots"), widgets->speeds[ix]);
break;
default:
// VIK_UNITS_SPEED_METRES_PER_SECOND:
- // No need to convert as already in m/s
g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f m/s"), widgets->speeds[ix]);
break;
}
gtk_label_set_text(GTK_LABEL(widgets->w_cur_speed), tmp_buf);
}
+
+ widgets->blob_tp = trackpoint;
+
+ if ( widgets->speeds == NULL )
+ return;
+
+ GtkWidget *window = gtk_widget_get_toplevel (event_box);
+ GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
+ GtkWidget *image = GTK_WIDGET(child->data);
+
+ gint y_blob = blobby_speed (x, widgets);
+
+ gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
+ if (widgets->is_marker_drawn) {
+ gdouble pc = tp_percentage_by_time ( tr, widgets->marker_tp );
+ if (!isnan(pc)) {
+ marker_x = (pc * widgets->profile_width) + MARGIN;
+ }
+ }
+
+ save_image_and_draw_graph_marks (image,
+ marker_x,
+ window->style->black_gc,
+ MARGIN+x,
+ y_blob,
+ &widgets->speed_graph_saved_img,
+ widgets->profile_width,
+ widgets->profile_height,
+ &widgets->is_marker_drawn,
+ &widgets->is_blob_drawn);
+
+ g_list_free(child);
}
/**
- * Draws DEM points and a respresentative speed on the supplied pixmap
- * (which is the elevations graph)
+ * Update labels and blob marker on mouse moves in the distance/time graph
*/
-static void draw_dem_alt_speed_dist(VikTrack *tr,
- GdkDrawable *pix,
- GdkGC *alt_gc,
- GdkGC *speed_gc,
- gdouble alt_offset,
- gdouble alt_diff,
- gint width,
- gint height,
- gint margin,
- gboolean do_dem,
- gboolean do_speed)
+void track_dt_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_along )
{
- GList *iter;
- gdouble max_speed = 0;
- gdouble total_length = vik_track_get_length_including_gaps(tr);
+ VikTrack *tr = pass_along[0];
+ PropWidgets *widgets = pass_along[3];
+ int mouse_x, mouse_y;
+ GdkModifierType state;
- if (do_speed) {
- for (iter = tr->trackpoints->next; iter; iter = iter->next) {
- if (!isnan(VIK_TRACKPOINT(iter->data)->speed))
- max_speed = MAX(max_speed, VIK_TRACKPOINT(iter->data)->speed);
- }
- max_speed = max_speed * 110 / 100;
+ if (event->is_hint)
+ gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
+ else
+ mouse_x = event->x;
+
+ gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
+ if (x < 0)
+ x = 0;
+ if (x > widgets->profile_width)
+ x = widgets->profile_width;
+
+ time_t seconds_from_start;
+ VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
+ if (trackpoint && widgets->w_cur_dist_time) {
+ static gchar tmp_buf[20];
+ guint h, m, s;
+ h = seconds_from_start/3600;
+ m = (seconds_from_start - h*3600)/60;
+ s = seconds_from_start - (3600*h) - (60*m);
+ g_snprintf(tmp_buf, sizeof(tmp_buf), "%02d:%02d:%02d", h, m, s);
+
+ gtk_label_set_text(GTK_LABEL(widgets->w_cur_dist_time), tmp_buf);
}
- gdouble dist = 0;
- for (iter = tr->trackpoints->next; iter; iter = iter->next) {
- int x;
- dist += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord),
- &(VIK_TRACKPOINT(iter->prev->data)->coord) );
- x = (width * dist)/total_length + margin;
- if (do_dem) {
- gint16 elev = a_dems_get_elev_by_coord(&(VIK_TRACKPOINT(iter->data)->coord), VIK_DEM_INTERPOL_BEST);
- elev -= alt_offset;
- if ( elev != VIK_DEM_INVALID_ELEVATION ) {
- int y_alt = height - ((height * elev)/alt_diff);
- gdk_draw_rectangle(GDK_DRAWABLE(pix), alt_gc, TRUE, x-2, y_alt-2, 4, 4);
- }
- }
- if (do_speed) {
- // This is just a speed indicator - no actual values can be inferred by user
- if (!isnan(VIK_TRACKPOINT(iter->data)->speed)) {
- int y_speed = height - (height * VIK_TRACKPOINT(iter->data)->speed)/max_speed;
- gdk_draw_rectangle(GDK_DRAWABLE(pix), speed_gc, TRUE, x-2, y_speed-2, 4, 4);
- }
+ gint ix = (gint)x;
+ // Ensure ix is inbounds
+ if (ix == widgets->profile_width)
+ ix--;
+
+ if (trackpoint && widgets->w_cur_dist_dist) {
+ static gchar tmp_buf[20];
+ if ( a_vik_get_units_distance () == VIK_UNITS_DISTANCE_MILES )
+ g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", widgets->distances[ix]);
+ else
+ g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", widgets->distances[ix]);
+ gtk_label_set_text(GTK_LABEL(widgets->w_cur_dist_dist), tmp_buf);
+ }
+
+ widgets->blob_tp = trackpoint;
+
+ if ( widgets->distances == NULL )
+ return;
+
+ GtkWidget *window = gtk_widget_get_toplevel (event_box);
+ GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
+ GtkWidget *image = GTK_WIDGET(child->data);
+
+ gint y_blob = blobby_distance (x, widgets);
+
+ gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
+ if (widgets->is_marker_drawn) {
+ gdouble pc = tp_percentage_by_time ( tr, widgets->marker_tp );
+ if (!isnan(pc)) {
+ marker_x = (pc * widgets->profile_width) + MARGIN;
}
}
+
+ save_image_and_draw_graph_marks (image,
+ marker_x,
+ window->style->black_gc,
+ MARGIN+x,
+ y_blob,
+ &widgets->dist_graph_saved_img,
+ widgets->profile_width,
+ widgets->profile_height,
+ &widgets->is_marker_drawn,
+ &widgets->is_blob_drawn);
+
+ g_list_free(child);
}
/**
- * Draw just the height profile image
+ * Update labels and blob marker on mouse moves in the elevation/time graph
*/
-static void draw_elevations (GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
+void track_et_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_along )
{
- GtkWidget *window;
- GdkPixmap *pix;
- gdouble mina, maxa;
- guint i;
-
- GdkGC *no_alt_info;
- GdkGC *dem_alt_gc;
- GdkGC *gps_speed_gc;
+ VikTrack *tr = pass_along[0];
+ PropWidgets *widgets = pass_along[3];
+ int mouse_x, mouse_y;
+ GdkModifierType state;
- GdkColor color;
+ if (event->is_hint)
+ gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
+ else
+ mouse_x = event->x;
- // Free previous allocation
- if ( widgets->altitudes )
- g_free ( widgets->altitudes );
+ gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
+ if (x < 0)
+ x = 0;
+ if (x > widgets->profile_width)
+ x = widgets->profile_width;
- widgets->altitudes = vik_track_make_elevation_map ( tr, widgets->profile_width );
+ time_t seconds_from_start;
+ VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
+ if (trackpoint && widgets->w_cur_elev_time) {
+ static gchar tmp_buf[20];
+ guint h, m, s;
+ h = seconds_from_start/3600;
+ m = (seconds_from_start - h*3600)/60;
+ s = seconds_from_start - (3600*h) - (60*m);
+ g_snprintf(tmp_buf, sizeof(tmp_buf), "%02d:%02d:%02d", h, m, s);
+
+ gtk_label_set_text(GTK_LABEL(widgets->w_cur_elev_time), tmp_buf);
+ }
+
+ gint ix = (gint)x;
+ // Ensure ix is inbounds
+ if (ix == widgets->profile_width)
+ ix--;
+
+ if (trackpoint && widgets->w_cur_elev_elev) {
+ static gchar tmp_buf[20];
+ if (a_vik_get_units_height () == VIK_UNITS_HEIGHT_FEET)
+ g_snprintf(tmp_buf, sizeof(tmp_buf), "%d ft", (int)VIK_METERS_TO_FEET(trackpoint->altitude));
+ else
+ g_snprintf(tmp_buf, sizeof(tmp_buf), "%d m", (int)trackpoint->altitude);
+ gtk_label_set_text(GTK_LABEL(widgets->w_cur_elev_elev), tmp_buf);
+ }
+
+ widgets->blob_tp = trackpoint;
+
+ if ( widgets->ats == NULL )
+ return;
+
+ GtkWidget *window = gtk_widget_get_toplevel (event_box);
+ GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
+ GtkWidget *image = GTK_WIDGET(child->data);
+
+ gint y_blob = blobby_altitude_time (x, widgets);
+
+ gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
+ if (widgets->is_marker_drawn) {
+ gdouble pc = tp_percentage_by_time ( tr, widgets->marker_tp );
+ if (!isnan(pc)) {
+ marker_x = (pc * widgets->profile_width) + MARGIN;
+ }
+ }
+
+ save_image_and_draw_graph_marks (image,
+ marker_x,
+ window->style->black_gc,
+ MARGIN+x,
+ y_blob,
+ &widgets->elev_time_graph_saved_img,
+ widgets->profile_width,
+ widgets->profile_height,
+ &widgets->is_marker_drawn,
+ &widgets->is_blob_drawn);
+
+ g_list_free(child);
+}
+
+void track_sd_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_along )
+{
+ VikTrack *tr = pass_along[0];
+ PropWidgets *widgets = pass_along[3];
+ int mouse_x, mouse_y;
+ GdkModifierType state;
+
+ if (event->is_hint)
+ gdk_window_get_pointer (event->window, &mouse_x, &mouse_y, &state);
+ else
+ mouse_x = event->x;
+
+ gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
+ if (x < 0)
+ x = 0;
+ if (x > widgets->profile_width)
+ x = widgets->profile_width;
+
+ gdouble meters_from_start;
+ VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_dist ( tr, (gdouble) x / widgets->profile_width, &meters_from_start );
+ if (trackpoint && widgets->w_cur_speed_dist) {
+ static gchar tmp_buf[20];
+ vik_units_distance_t dist_units = a_vik_get_units_distance ();
+ switch (dist_units) {
+ case VIK_UNITS_DISTANCE_KILOMETRES:
+ g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", meters_from_start/1000.0);
+ break;
+ case VIK_UNITS_DISTANCE_MILES:
+ g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
+ break;
+ default:
+ g_critical("Houston, we've had a problem. distance=%d", dist_units);
+ }
+ gtk_label_set_text(GTK_LABEL(widgets->w_cur_speed_dist), tmp_buf);
+ }
+
+ gint ix = (gint)x;
+ // Ensure ix is inbounds
+ if (ix == widgets->profile_width)
+ ix--;
+
+ if ( widgets->speeds_dist == NULL )
+ return;
+
+ // Show track speed for this position
+ if (widgets->w_cur_speed_speed) {
+ static gchar tmp_buf[20];
+ // Even if GPS speed available (trackpoint->speed), the text will correspond to the speed map shown
+ // No conversions needed as already in appropriate units
+ vik_units_speed_t speed_units = a_vik_get_units_speed ();
+ switch (speed_units) {
+ case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
+ g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f kph"), widgets->speeds_dist[ix]);
+ break;
+ case VIK_UNITS_SPEED_MILES_PER_HOUR:
+ g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f mph"), widgets->speeds_dist[ix]);
+ break;
+ case VIK_UNITS_SPEED_KNOTS:
+ g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f knots"), widgets->speeds_dist[ix]);
+ break;
+ default:
+ // VIK_UNITS_SPEED_METRES_PER_SECOND:
+ g_snprintf(tmp_buf, sizeof(tmp_buf), _("%.1f m/s"), widgets->speeds_dist[ix]);
+ break;
+ }
+ gtk_label_set_text(GTK_LABEL(widgets->w_cur_speed_speed), tmp_buf);
+ }
+
+ widgets->blob_tp = trackpoint;
+
+ GtkWidget *window = gtk_widget_get_toplevel (event_box);
+ GList *child = gtk_container_get_children(GTK_CONTAINER(event_box));
+ GtkWidget *image = GTK_WIDGET(child->data);
+
+ gint y_blob = blobby_speed_dist (x, widgets);
+
+ gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
+ if (widgets->is_marker_drawn) {
+ gdouble pc = tp_percentage_by_distance ( tr, widgets->marker_tp, widgets->track_length );
+ if (!isnan(pc)) {
+ marker_x = (pc * widgets->profile_width) + MARGIN;
+ }
+ }
+
+ save_image_and_draw_graph_marks (image,
+ marker_x,
+ window->style->black_gc,
+ MARGIN+x,
+ y_blob,
+ &widgets->speed_dist_graph_saved_img,
+ widgets->profile_width,
+ widgets->profile_height,
+ &widgets->is_marker_drawn,
+ &widgets->is_blob_drawn);
+
+ g_list_free(child);
+}
+
+/**
+ * Draws DEM points and a respresentative speed on the supplied pixmap
+ * (which is the elevations graph)
+ */
+static void draw_dem_alt_speed_dist(VikTrack *tr,
+ GdkDrawable *pix,
+ GdkGC *alt_gc,
+ GdkGC *speed_gc,
+ gdouble alt_offset,
+ gdouble alt_diff,
+ gdouble max_speed_in,
+ gint cia,
+ gint width,
+ gint height,
+ gint margin,
+ gboolean do_dem,
+ gboolean do_speed)
+{
+ GList *iter;
+ gdouble max_speed = 0;
+ gdouble total_length = vik_track_get_length_including_gaps(tr);
+
+ // Calculate the max speed factor
+ if (do_speed)
+ max_speed = max_speed_in * 110 / 100;
+
+ gdouble dist = 0;
+ for (iter = tr->trackpoints->next; iter; iter = iter->next) {
+ int x;
+ dist += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord),
+ &(VIK_TRACKPOINT(iter->prev->data)->coord) );
+ x = (width * dist)/total_length + margin;
+ if (do_dem) {
+ gint16 elev = a_dems_get_elev_by_coord(&(VIK_TRACKPOINT(iter->data)->coord), VIK_DEM_INTERPOL_BEST);
+ elev -= alt_offset;
+ if ( elev != VIK_DEM_INVALID_ELEVATION ) {
+ // Convert into height units
+ if (a_vik_get_units_height () == VIK_UNITS_HEIGHT_FEET)
+ elev = VIK_METERS_TO_FEET(elev);
+ // No conversion needed if already in metres
+
+ // consider chunk size
+ int y_alt = height - ((height * (elev-alt_offset))/(chunksa[cia]*LINES) );
+ gdk_draw_rectangle(GDK_DRAWABLE(pix), alt_gc, TRUE, x-2, y_alt-2, 4, 4);
+ }
+ }
+ if (do_speed) {
+ // This is just a speed indicator - no actual values can be inferred by user
+ if (!isnan(VIK_TRACKPOINT(iter->data)->speed)) {
+ int y_speed = height - (height * VIK_TRACKPOINT(iter->data)->speed)/max_speed;
+ gdk_draw_rectangle(GDK_DRAWABLE(pix), speed_gc, TRUE, x-2, y_speed-2, 4, 4);
+ }
+ }
+ }
+}
+
+/**
+ * Draw just the height profile image
+ */
+static void draw_elevations (GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
+{
+ GtkWidget *window;
+ GdkPixmap *pix;
+ gdouble mina, maxa;
+ guint i;
+
+ GdkGC *no_alt_info;
+ GdkColor color;
+
+ // Free previous allocation
+ if ( widgets->altitudes )
+ g_free ( widgets->altitudes );
+
+ widgets->altitudes = vik_track_make_elevation_map ( tr, widgets->profile_width );
+
+ if ( widgets->altitudes == NULL )
+ return;
+
+ // Convert into appropriate units
+ vik_units_height_t height_units = a_vik_get_units_height ();
+ if ( height_units == VIK_UNITS_HEIGHT_FEET ) {
+ // Convert altitudes into feet units
+ for ( i = 0; i < widgets->profile_width; i++ ) {
+ widgets->altitudes[i] = VIK_METERS_TO_FEET(widgets->altitudes[i]);
+ }
+ }
+ // Otherwise leave in metres
+
+ minmax_array(widgets->altitudes, &widgets->min_altitude, &widgets->max_altitude, TRUE, widgets->profile_width);
+
+ get_new_min_and_chunk_index_altitude (widgets->min_altitude, widgets->max_altitude, &widgets->draw_min_altitude, &widgets->cia);
+
+ // Assign locally
+ mina = widgets->draw_min_altitude;
+ maxa = widgets->max_altitude;
+
+ window = gtk_widget_get_toplevel (widgets->elev_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 );
+
+ no_alt_info = gdk_gc_new ( window->window );
+ gdk_color_parse ( "yellow", &color );
+ gdk_gc_set_rgb_fg_color ( no_alt_info, &color);
+
+ /* 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);
+ switch (height_units) {
+ case VIK_UNITS_HEIGHT_METRES:
+ sprintf(s, "%8dm", (int)(mina + (LINES-i)*chunksa[widgets->cia]));
+ break;
+ case VIK_UNITS_HEIGHT_FEET:
+ // NB values already converted into feet
+ sprintf(s, "%8dft", (int)(mina + (LINES-i)*chunksa[widgets->cia]));
+ break;
+ default:
+ sprintf(s, "--");
+ g_critical("Houston, we've had a problem. height=%d", height_units);
+ }
+ 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 elevations */
+ for ( i = 0; i < widgets->profile_width; i++ )
+ if ( widgets->altitudes[i] == VIK_DEFAULT_ALTITUDE )
+ gdk_draw_line ( GDK_DRAWABLE(pix), no_alt_info,
+ i + MARGIN, 0, i + MARGIN, widgets->profile_height );
+ else
+ 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->altitudes[i]-mina)/(chunksa[widgets->cia]*LINES) );
+
+ if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_dem)) ||
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_alt_gps_speed)) ) {
+
+ GdkGC *dem_alt_gc = gdk_gc_new ( window->window );
+ GdkGC *gps_speed_gc = gdk_gc_new ( window->window );
+
+ gdk_color_parse ( "green", &color );
+ gdk_gc_set_rgb_fg_color ( dem_alt_gc, &color);
+
+ gdk_color_parse ( "red", &color );
+ gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
+
+ // Ensure somekind of max speed when not set
+ if ( widgets->max_speed < 0.01 )
+ widgets->max_speed = vik_track_get_max_speed(tr);
+
+ draw_dem_alt_speed_dist(tr,
+ GDK_DRAWABLE(pix),
+ dem_alt_gc,
+ gps_speed_gc,
+ mina,
+ maxa - mina,
+ widgets->max_speed,
+ widgets->cia,
+ widgets->profile_width,
+ widgets->profile_height,
+ MARGIN,
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_dem)),
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_alt_gps_speed)));
+
+ g_object_unref ( G_OBJECT(dem_alt_gc) );
+ g_object_unref ( G_OBJECT(gps_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) );
+ g_object_unref ( G_OBJECT(no_alt_info) );
+}
+
+/**
+ * Draw just the speed (velocity)/time image
+ */
+static void draw_vt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
+{
+ GtkWidget *window;
+ GdkPixmap *pix;
+ gdouble mins, maxs;
+ guint i;
+
+ // Free previous allocation
+ if ( widgets->speeds )
+ g_free ( widgets->speeds );
+
+ widgets->speeds = vik_track_make_speed_map ( tr, widgets->profile_width );
+ if ( widgets->speeds == 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[i] = VIK_MPS_TO_KPH(widgets->speeds[i]);
+ }
+ break;
+ case VIK_UNITS_SPEED_MILES_PER_HOUR:
+ for ( i = 0; i < widgets->profile_width; i++ ) {
+ widgets->speeds[i] = VIK_MPS_TO_MPH(widgets->speeds[i]);
+ }
+ break;
+ case VIK_UNITS_SPEED_KNOTS:
+ for ( i = 0; i < widgets->profile_width; i++ ) {
+ widgets->speeds[i] = VIK_MPS_TO_KNOTS(widgets->speeds[i]);
+ }
+ break;
+ default:
+ // VIK_UNITS_SPEED_METRES_PER_SECOND:
+ // No need to convert as already in m/s
+ break;
+ }
+
+ window = gtk_widget_get_toplevel (widgets->speed_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 );
+
+ minmax_array(widgets->speeds, &widgets->min_speed, &widgets->max_speed, 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, chunkss, sizeof(chunkss)/sizeof(chunkss[0]), &widgets->draw_min_speed, &widgets->cis);
+
+ // Assign locally
+ mins = widgets->draw_min_speed;
+ maxs = widgets->max_speed;
+
+ /* 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);
+ // 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->cis]));
+ break;
+ case VIK_UNITS_SPEED_MILES_PER_HOUR:
+ sprintf(s, "%8dmph", (int)(mins + (LINES-i)*chunkss[widgets->cis]));
+ break;
+ case VIK_UNITS_SPEED_METRES_PER_SECOND:
+ sprintf(s, "%8dm/s", (int)(mins + (LINES-i)*chunkss[widgets->cis]));
+ break;
+ case VIK_UNITS_SPEED_KNOTS:
+ sprintf(s, "%8dknots", (int)(mins + (LINES-i)*chunkss[widgets->cis]));
+ break;
+ default:
+ sprintf(s, "--");
+ g_critical("Houston, we've had a problem. speed=%d", speed_units);
+ }
+
+ 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 speeds */
+ 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->speeds[i]-mins)/(chunkss[widgets->cis]*LINES) );
+
+
+ if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_gps_speed)) ) {
+
+ GdkGC *gps_speed_gc = gdk_gc_new ( window->window );
+ GdkColor color;
+ gdk_color_parse ( "red", &color );
+ gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
+
+ time_t beg_time = VIK_TRACKPOINT(tr->trackpoints->data)->timestamp;
+ time_t dur = VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp - beg_time;
+
+ GList *iter;
+ for (iter = tr->trackpoints; iter; iter = iter->next) {
+ gdouble gps_speed = VIK_TRACKPOINT(iter->data)->speed;
+ if (isnan(gps_speed))
+ continue;
+ switch (speed_units) {
+ case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
+ gps_speed = VIK_MPS_TO_KPH(gps_speed);
+ break;
+ case VIK_UNITS_SPEED_MILES_PER_HOUR:
+ gps_speed = VIK_MPS_TO_MPH(gps_speed);
+ break;
+ case VIK_UNITS_SPEED_KNOTS:
+ gps_speed = VIK_MPS_TO_KNOTS(gps_speed);
+ break;
+ default:
+ // VIK_UNITS_SPEED_METRES_PER_SECOND:
+ // No need to convert as already in m/s
+ break;
+ }
+ int x = MARGIN + widgets->profile_width * (VIK_TRACKPOINT(iter->data)->timestamp - beg_time) / dur;
+ int y = widgets->profile_height - widgets->profile_height*(gps_speed - mins)/(chunkss[widgets->cis]*LINES);
+ gdk_draw_rectangle(GDK_DRAWABLE(pix), gps_speed_gc, TRUE, x-2, y-2, 4, 4);
+ }
+ g_object_unref ( G_OBJECT(gps_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) );
+}
+
+/**
+ * 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) );
+
+}
+
+/**
+ * Draw just the elevation/time image
+ */
+static void draw_et ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
+{
+ GtkWidget *window;
+ GdkPixmap *pix;
+ gdouble mina,maxa;
+ guint i;
+
+ // Free previous allocation
+ if ( widgets->ats )
+ g_free ( widgets->ats );
+
+ widgets->ats = vik_track_make_elevation_time_map ( tr, widgets->profile_width );
+
+ if ( widgets->ats == NULL )
+ return;
+
+ // Convert into appropriate units
+ vik_units_height_t height_units = a_vik_get_units_height ();
+ if ( height_units == VIK_UNITS_HEIGHT_FEET ) {
+ // Convert altitudes into feet units
+ for ( i = 0; i < widgets->profile_width; i++ ) {
+ widgets->ats[i] = VIK_METERS_TO_FEET(widgets->ats[i]);
+ }
+ }
+ // Otherwise leave in metres
+
+ minmax_array(widgets->ats, &widgets->min_altitude, &widgets->max_altitude, TRUE, widgets->profile_width);
- if ( widgets->altitudes == NULL )
- return;
+ get_new_min_and_chunk_index_altitude (widgets->min_altitude, widgets->max_altitude, &widgets->draw_min_altitude, &widgets->cia);
- minmax_array(widgets->altitudes, &mina, &maxa, TRUE, widgets->profile_width);
- maxa = maxa + ((maxa - mina) * 0.25); // Make visible window a bit bigger than highest point
+ // Assign locally
+ mina = widgets->draw_min_altitude;
+ maxa = widgets->max_altitude;
- window = gtk_widget_get_toplevel (widgets->elev_box);
+ window = gtk_widget_get_toplevel (widgets->elev_time_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 );
- no_alt_info = gdk_gc_new ( window->window );
- gdk_color_parse ( "yellow", &color );
- gdk_gc_set_rgb_fg_color ( no_alt_info, &color);
-
- dem_alt_gc = gdk_gc_new ( window->window );
- gdk_color_parse ( "green", &color );
- gdk_gc_set_rgb_fg_color ( dem_alt_gc, &color);
-
- gps_speed_gc = gdk_gc_new ( window->window );
- gdk_color_parse ( "red", &color );
- gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
-
/* clear the image */
- gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->bg_gc[0],
+ 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],
+ gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->mid_gc[0],
TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
-
+
/* draw grid */
- vik_units_height_t height_units = a_vik_get_units_height ();
for (i=0; i<=LINES; i++) {
PangoFontDescription *pfd;
PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
pango_font_description_free (pfd);
switch (height_units) {
case VIK_UNITS_HEIGHT_METRES:
- sprintf(s, "%8dm", (int)(mina + (LINES-i)*(maxa-mina)/LINES));
+ sprintf(s, "%8dm", (int)(mina + (LINES-i)*chunksa[widgets->cia]));
break;
case VIK_UNITS_HEIGHT_FEET:
- sprintf(s, "%8dft", (int)VIK_METERS_TO_FEET(mina + (LINES-i)*(maxa-mina)/LINES));
+ // NB values already converted into feet
+ sprintf(s, "%8dft", (int)(mina + (LINES-i)*chunksa[widgets->cia]));
break;
default:
sprintf(s, "--");
}
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,
+ 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],
+ 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 elevations */
for ( i = 0; i < widgets->profile_width; i++ )
- if ( widgets->altitudes[i] == VIK_DEFAULT_ALTITUDE )
- gdk_draw_line ( GDK_DRAWABLE(pix), no_alt_info,
- i + MARGIN, 0, i + MARGIN, widgets->profile_height );
- else
- 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->altitudes[i]-mina)/(maxa-mina) );
-
- draw_dem_alt_speed_dist(tr,
- GDK_DRAWABLE(pix),
- dem_alt_gc,
- gps_speed_gc,
- mina,
- maxa - mina,
- widgets->profile_width,
- widgets->profile_height,
- MARGIN,
- TRUE,
- TRUE);
+ 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->ats[i]-mina)/(chunksa[widgets->cia]*LINES) );
+
+ // Show speed indicator
+ if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_elev_speed)) ) {
+ GdkGC *elev_speed_gc = gdk_gc_new ( window->window );
+ GdkColor color;
+ gdk_color_parse ( "red", &color );
+ gdk_gc_set_rgb_fg_color ( elev_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), elev_speed_gc, TRUE, i+MARGIN-2, y_speed-2, 4, 4);
+ }
+ g_object_unref ( G_OBJECT(elev_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) );
- g_object_unref ( G_OBJECT(no_alt_info) );
- g_object_unref ( G_OBJECT(dem_alt_gc) );
- g_object_unref ( G_OBJECT(gps_speed_gc) );
}
/**
- * Draw just the speed (velocity)/time image
+ * Draw just the speed/distance image
*/
-static void draw_vt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
+static void draw_sd ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
{
GtkWidget *window;
GdkPixmap *pix;
guint i;
// Free previous allocation
- if ( widgets->speeds )
- g_free ( widgets->speeds );
+ if ( widgets->speeds_dist )
+ g_free ( widgets->speeds_dist );
- widgets->speeds = vik_track_make_speed_map ( tr, widgets->profile_width );
- if ( widgets->speeds == NULL )
+ widgets->speeds_dist = vik_track_make_speed_dist_map ( tr, widgets->profile_width );
+ if ( widgets->speeds_dist == NULL )
return;
- GdkGC *gps_speed_gc;
- GdkColor color;
+ // 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;
+ }
- window = gtk_widget_get_toplevel (widgets->speed_box);
+ window = gtk_widget_get_toplevel (widgets->speed_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 );
- gps_speed_gc = gdk_gc_new ( window->window );
- gdk_color_parse ( "red", &color );
- gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
+ // 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 */
- minmax_array(widgets->speeds, &mins, &maxs, FALSE, widgets->profile_width);
- if (mins < 0.0)
- mins = 0; /* splines sometimes give negative speeds */
- maxs = maxs + ((maxs - mins) * 0.1);
- if (maxs-mins < MIN_SPEED_DIFF) {
- maxs = mins + MIN_SPEED_DIFF;
- }
+ /* Find suitable chunk index */
+ get_new_min_and_chunk_index (widgets->min_speed, widgets->max_speed_dist, chunkss, sizeof(chunkss)/sizeof(chunkss[0]), &widgets->draw_min_speed, &widgets->cisd);
+
+ // Assign locally
+ mins = widgets->draw_min_speed;
+ maxs = widgets->max_speed_dist;
/* clear the image */
- gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->bg_gc[0],
+ 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],
+ gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->mid_gc[0],
TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
/* draw grid */
pfd = pango_font_description_from_string (PROPWIN_LABEL_FONT);
pango_layout_set_font_description (pl, pfd);
pango_font_description_free (pfd);
- vik_units_speed_t speed_units = a_vik_get_units_speed ();
+ // 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, "%6.1fkm/h", VIK_MPS_TO_KPH(mins + (LINES-i)*(maxs-mins)/LINES));
+ sprintf(s, "%8dkm/h", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
break;
case VIK_UNITS_SPEED_MILES_PER_HOUR:
- sprintf(s, "%6.1fmph", VIK_MPS_TO_MPH(mins + (LINES-i)*(maxs-mins)/LINES));
+ 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)*(maxs-mins)/LINES));
+ sprintf(s, "%8dm/s", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
break;
case VIK_UNITS_SPEED_KNOTS:
- sprintf(s, "%6.1fknots", VIK_MPS_TO_KNOTS(mins + (LINES-i)*(maxs-mins)/LINES));
+ sprintf(s, "%8dknots", (int)(mins + (LINES-i)*chunkss[widgets->cisd]));
break;
default:
sprintf(s, "--");
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,
+ 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],
+ 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 speeds */
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->speeds[i]-mins)/(maxs-mins) );
+ 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->speeds_dist[i]-mins)/(chunkss[widgets->cisd]*LINES) );
- time_t beg_time = VIK_TRACKPOINT(tr->trackpoints->data)->timestamp;
- time_t dur = VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp - beg_time;
- GList *iter;
- for (iter = tr->trackpoints; iter; iter = iter->next) {
- gdouble gps_speed = VIK_TRACKPOINT(iter->data)->speed;
- if (isnan(gps_speed))
+ if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_sd_gps_speed)) ) {
+
+ GdkGC *gps_speed_gc = gdk_gc_new ( window->window );
+ GdkColor color;
+ gdk_color_parse ( "red", &color );
+ gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
+
+ gdouble dist = vik_track_get_length_including_gaps(tr);
+ gdouble dist_tp = 0.0;
+
+ GList *iter = tr->trackpoints;
+ for (iter = iter->next; iter; iter = iter->next) {
+ gdouble gps_speed = VIK_TRACKPOINT(iter->data)->speed;
+ if (isnan(gps_speed))
continue;
- int x = MARGIN + widgets->profile_width * (VIK_TRACKPOINT(iter->data)->timestamp - beg_time) / dur;
- int y = widgets->profile_height - widgets->profile_height*(gps_speed - mins)/(maxs - mins);
- gdk_draw_rectangle(GDK_DRAWABLE(pix), gps_speed_gc, TRUE, x-2, y-2, 4, 4);
+ switch (speed_units) {
+ case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
+ gps_speed = VIK_MPS_TO_KPH(gps_speed);
+ break;
+ case VIK_UNITS_SPEED_MILES_PER_HOUR:
+ gps_speed = VIK_MPS_TO_MPH(gps_speed);
+ break;
+ case VIK_UNITS_SPEED_KNOTS:
+ gps_speed = VIK_MPS_TO_KNOTS(gps_speed);
+ break;
+ default:
+ // VIK_UNITS_SPEED_METRES_PER_SECOND:
+ // No need to convert as already in m/s
+ break;
+ }
+ dist_tp += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord), &(VIK_TRACKPOINT(iter->prev->data)->coord) );
+ int x = MARGIN + (widgets->profile_width * dist_tp / dist);
+ int y = widgets->profile_height - widgets->profile_height*(gps_speed - mins)/(chunkss[widgets->cisd]*LINES);
+ gdk_draw_rectangle(GDK_DRAWABLE(pix), gps_speed_gc, TRUE, x-2, y-2, 4, 4);
+ }
+ g_object_unref ( G_OBJECT(gps_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) );
- g_object_unref ( G_OBJECT(gps_speed_gc) );
-
}
#undef LINES
static void draw_all_graphs ( GtkWidget *widget, gpointer *pass_along, gboolean resized )
{
VikTrack *tr = pass_along[0];
- PropWidgets *widgets = pass_along[2];
+ PropWidgets *widgets = pass_along[3];
// Draw graphs even if they are not visible
GtkWidget *image = NULL;
GtkWidget *window = gtk_widget_get_toplevel(widget);
gdouble pc = NAN;
+ gdouble pc_blob = NAN;
// Draw elevations
if (widgets->elev_box != NULL) {
image = GTK_WIDGET(child->data);
g_list_free(child);
- // Ensure marker is redrawn if necessary
- if (widgets->is_marker_drawn) {
+ // Ensure marker or blob are redrawn if necessary
+ if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
pc = tp_percentage_by_distance ( tr, widgets->marker_tp, widgets->track_length );
- gdouble marker_x = 0.0;
+ gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
+ gint y_blob = 0;
+ if (widgets->is_blob_drawn) {
+ pc_blob = tp_percentage_by_distance ( tr, widgets->blob_tp, widgets->track_length );
+ if (!isnan(pc_blob)) {
+ x_blob = (pc_blob * widgets->profile_width);
+ }
+ y_blob = blobby_altitude (x_blob, widgets);
+ }
+
+ gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
if (!isnan(pc)) {
- marker_x = (pc * widgets->profile_width) + MARGIN + (image->allocation.width/2 - widgets->profile_width/2 - MARGIN/2);
- save_image_and_draw_graph_mark(image,
+ marker_x = (pc * widgets->profile_width) + MARGIN;
+ }
+
+ save_image_and_draw_graph_marks (image,
marker_x,
- image->allocation.width,
window->style->black_gc,
+ x_blob+MARGIN,
+ y_blob,
&widgets->elev_graph_saved_img,
widgets->profile_width,
widgets->profile_height,
- &widgets->is_marker_drawn);
- }
+ &widgets->is_marker_drawn,
+ &widgets->is_blob_drawn);
}
}
image = GTK_WIDGET(child->data);
g_list_free(child);
- // Ensure marker is redrawn if necessary
- if (widgets->is_marker_drawn) {
+ // Ensure marker or blob are redrawn if necessary
+ if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
pc = tp_percentage_by_time ( tr, widgets->marker_tp );
- gdouble marker_x = 0.0;
+ gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
+ gint y_blob = 0;
+ if (widgets->is_blob_drawn) {
+ pc_blob = tp_percentage_by_time ( tr, widgets->blob_tp );
+ if (!isnan(pc_blob)) {
+ x_blob = (pc_blob * widgets->profile_width);
+ }
+
+ y_blob = blobby_speed (x_blob, widgets);
+ }
+
+ gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
if (!isnan(pc)) {
- marker_x = (pc * widgets->profile_width) + MARGIN + (image->allocation.width/2 - widgets->profile_width/2 - MARGIN/2);
- save_image_and_draw_graph_mark(image,
+ marker_x = (pc * widgets->profile_width) + MARGIN;
+ }
+
+ save_image_and_draw_graph_marks (image,
marker_x,
- image->allocation.width,
window->style->black_gc,
+ x_blob+MARGIN,
+ y_blob,
&widgets->speed_graph_saved_img,
widgets->profile_width,
widgets->profile_height,
- &widgets->is_marker_drawn);
+ &widgets->is_marker_drawn,
+ &widgets->is_blob_drawn);
+ }
+ }
+
+ // Draw Distances
+ if (widgets->dist_box != NULL) {
+
+ // Saved image no longer any good as we've resized
+ if (resized && widgets->dist_graph_saved_img.img) {
+ g_object_unref(widgets->dist_graph_saved_img.img);
+ widgets->dist_graph_saved_img.img = NULL;
+ widgets->dist_graph_saved_img.saved = FALSE;
+ }
+
+ child = gtk_container_get_children(GTK_CONTAINER(widgets->dist_box));
+ draw_dt (GTK_WIDGET(child->data), tr, widgets );
+
+ image = GTK_WIDGET(child->data);
+ g_list_free(child);
+
+ // Ensure marker or blob are redrawn if necessary
+ if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
+
+ pc = tp_percentage_by_time ( tr, widgets->marker_tp );
+
+ gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
+ gint y_blob = 0;
+ if (widgets->is_blob_drawn) {
+ pc_blob = tp_percentage_by_time ( tr, widgets->blob_tp );
+ if (!isnan(pc_blob)) {
+ x_blob = (pc_blob * widgets->profile_width);
+ }
+
+ y_blob = blobby_distance (x_blob, widgets);
+ }
+
+ gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
+ if (!isnan(pc)) {
+ marker_x = (pc * widgets->profile_width) + MARGIN;
+ }
+
+ save_image_and_draw_graph_marks (image,
+ marker_x,
+ window->style->black_gc,
+ x_blob+MARGIN,
+ y_blob,
+ &widgets->dist_graph_saved_img,
+ widgets->profile_width,
+ widgets->profile_height,
+ &widgets->is_marker_drawn,
+ &widgets->is_blob_drawn);
+ }
+ }
+
+ // Draw Elevations in timely manner
+ if (widgets->elev_time_box != NULL) {
+
+ // Saved image no longer any good as we've resized
+ if (resized && widgets->elev_time_graph_saved_img.img) {
+ g_object_unref(widgets->elev_time_graph_saved_img.img);
+ widgets->elev_time_graph_saved_img.img = NULL;
+ widgets->elev_time_graph_saved_img.saved = FALSE;
+ }
+
+ child = gtk_container_get_children(GTK_CONTAINER(widgets->elev_time_box));
+ draw_et (GTK_WIDGET(child->data), tr, widgets );
+
+ image = GTK_WIDGET(child->data);
+ g_list_free(child);
+
+ // Ensure marker or blob are redrawn if necessary
+ if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
+
+ pc = tp_percentage_by_time ( tr, widgets->marker_tp );
+
+ gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
+ gint y_blob = 0;
+ if (widgets->is_blob_drawn) {
+ pc_blob = tp_percentage_by_time ( tr, widgets->blob_tp );
+ if (!isnan(pc_blob)) {
+ x_blob = (pc_blob * widgets->profile_width);
+ }
+ y_blob = blobby_altitude_time (x_blob, widgets);
+ }
+
+ gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
+ if (!isnan(pc)) {
+ marker_x = (pc * widgets->profile_width) + MARGIN;
+ }
+
+ save_image_and_draw_graph_marks (image,
+ marker_x,
+ window->style->black_gc,
+ x_blob+MARGIN,
+ y_blob,
+ &widgets->elev_time_graph_saved_img,
+ widgets->profile_width,
+ widgets->profile_height,
+ &widgets->is_marker_drawn,
+ &widgets->is_blob_drawn);
+ }
+ }
+
+ // Draw speed distances
+ if (widgets->speed_dist_box != NULL) {
+
+ // Saved image no longer any good as we've resized, so we remove it here
+ if (resized && widgets->speed_dist_graph_saved_img.img) {
+ g_object_unref(widgets->speed_dist_graph_saved_img.img);
+ widgets->speed_dist_graph_saved_img.img = NULL;
+ widgets->speed_dist_graph_saved_img.saved = FALSE;
+ }
+
+ child = gtk_container_get_children(GTK_CONTAINER(widgets->speed_dist_box));
+ draw_sd (GTK_WIDGET(child->data), tr, widgets );
+
+ image = GTK_WIDGET(child->data);
+ g_list_free(child);
+
+ // Ensure marker or blob are redrawn if necessary
+ if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
+
+ pc = tp_percentage_by_distance ( tr, widgets->marker_tp, widgets->track_length );
+ gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
+ gint y_blob = 0;
+ if (widgets->is_blob_drawn) {
+ pc_blob = tp_percentage_by_distance ( tr, widgets->blob_tp, widgets->track_length );
+ if (!isnan(pc_blob)) {
+ x_blob = (pc_blob * widgets->profile_width);
+ }
+ y_blob = blobby_speed_dist (x_blob, widgets);
+ }
+
+ gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
+ if (!isnan(pc)) {
+ marker_x = (pc * widgets->profile_width) + MARGIN;
}
+
+ save_image_and_draw_graph_marks (image,
+ marker_x,
+ window->style->black_gc,
+ x_blob+MARGIN,
+ y_blob,
+ &widgets->speed_dist_graph_saved_img,
+ widgets->profile_width,
+ widgets->profile_height,
+ &widgets->is_marker_drawn,
+ &widgets->is_blob_drawn);
}
}
+
}
/**
*/
static gboolean configure_event ( GtkWidget *widget, GdkEventConfigure *event, gpointer *pass_along )
{
- PropWidgets *widgets = pass_along[2];
+ PropWidgets *widgets = pass_along[3];
if (widgets->configure_dialog) {
// Determine size offsets between dialog size and size for images
return eventbox;
}
+
+/**
+ * Create distance / time widgets including the image and callbacks
+ */
+GtkWidget *vik_trw_layer_create_dtdiag ( GtkWidget *window, VikTrack *tr, gpointer vlp, VikViewport *vvp, PropWidgets *widgets)
+{
+ GdkPixmap *pix;
+ GtkWidget *image;
+ GtkWidget *eventbox;
+ gpointer *pass_along;
+
+ // First allocation
+ widgets->distances = vik_track_make_distance_map ( tr, widgets->profile_width );
+ if ( widgets->distances == NULL )
+ return NULL;
+
+ pass_along = g_malloc ( sizeof(gpointer) * 4 ); /* FIXME: mem leak -- never be freed */
+ pass_along[0] = tr;
+ pass_along[1] = vlp;
+ pass_along[2] = vvp;
+ pass_along[3] = widgets;
+
+ pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+ image = gtk_image_new_from_pixmap ( pix, NULL );
+
+ g_object_unref ( G_OBJECT(pix) );
+
+ eventbox = gtk_event_box_new ();
+ g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_dt_click), pass_along );
+ g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_dt_move), pass_along );
+ g_signal_connect_swapped ( G_OBJECT(eventbox), "destroy", G_CALLBACK(g_free), pass_along );
+ gtk_container_add ( GTK_CONTAINER(eventbox), image );
+ gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
+
+ return eventbox;
+}
+
+/**
+ * Create elevation / time widgets including the image and callbacks
+ */
+GtkWidget *vik_trw_layer_create_etdiag ( GtkWidget *window, VikTrack *tr, gpointer vlp, VikViewport *vvp, PropWidgets *widgets)
+{
+ GdkPixmap *pix;
+ GtkWidget *image;
+ GtkWidget *eventbox;
+ gpointer *pass_along;
+
+ // First allocation
+ widgets->ats = vik_track_make_elevation_time_map ( tr, widgets->profile_width );
+ if ( widgets->ats == NULL )
+ return NULL;
+
+ pass_along = g_malloc ( sizeof(gpointer) * 4 ); /* FIXME: mem leak -- never be freed */
+ pass_along[0] = tr;
+ pass_along[1] = vlp;
+ pass_along[2] = vvp;
+ pass_along[3] = widgets;
+
+ pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+ image = gtk_image_new_from_pixmap ( pix, NULL );
+
+ g_object_unref ( G_OBJECT(pix) );
+
+ eventbox = gtk_event_box_new ();
+ g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_et_click), pass_along );
+ g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_et_move), pass_along );
+ g_signal_connect_swapped ( G_OBJECT(eventbox), "destroy", G_CALLBACK(g_free), pass_along );
+ gtk_container_add ( GTK_CONTAINER(eventbox), image );
+ gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
+
+ return eventbox;
+}
+
+/**
+ * Create speed/distance widgets including the image and callbacks
+ */
+GtkWidget *vik_trw_layer_create_sddiag ( GtkWidget *window, VikTrack *tr, gpointer vlp, VikViewport *vvp, PropWidgets *widgets)
+{
+ GdkPixmap *pix;
+ GtkWidget *image;
+ GtkWidget *eventbox;
+ gpointer *pass_along;
+
+ // First allocation
+ widgets->speeds_dist = vik_track_make_speed_dist_map ( tr, widgets->profile_width );
+ if ( widgets->speeds_dist == NULL )
+ return NULL;
+
+ pass_along = g_malloc ( sizeof(gpointer) * 4 ); /* FIXME: mem leak -- never be freed */
+ pass_along[0] = tr;
+ pass_along[1] = vlp;
+ pass_along[2] = vvp;
+ pass_along[3] = widgets;
+
+ pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+ image = gtk_image_new_from_pixmap ( pix, NULL );
+
+ g_object_unref ( G_OBJECT(pix) );
+
+ eventbox = gtk_event_box_new ();
+ g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_sd_click), pass_along );
+ g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_sd_move), pass_along );
+ g_signal_connect_swapped ( G_OBJECT(eventbox), "destroy", G_CALLBACK(g_free), pass_along );
+ gtk_container_add ( GTK_CONTAINER(eventbox), image );
+ gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
+
+ return eventbox;
+}
#undef MARGIN
static void propwin_response_cb( GtkDialog *dialog, gint resp, PropWidgets *widgets)
}
}
+/**
+ * Force a redraw when checkbutton has been toggled to show/hide that information
+ */
+static void checkbutton_toggle_cb ( GtkToggleButton *togglebutton, gpointer *pass_along, gpointer dummy)
+{
+ PropWidgets *widgets = pass_along[3];
+ // Even though not resized, we'll pretend it is -
+ // as this invalidates the saved images (since the image may have changed)
+ draw_all_graphs ( widgets->dialog, pass_along, TRUE);
+}
+
/**
* Create the widgets for the given graph tab
*/
const gchar *markup,
GtkWidget *value,
const gchar *markup2,
- GtkWidget *value2)
+ GtkWidget *value2,
+ GtkWidget *checkbutton1,
+ gboolean checkbutton1_default,
+ GtkWidget *checkbutton2,
+ gboolean checkbutton2_default )
{
GtkWidget *hbox = gtk_hbox_new ( FALSE, 10 );
GtkWidget *vbox = gtk_vbox_new ( FALSE, 10 );
gtk_box_pack_start (GTK_BOX(hbox), value, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX(hbox), label2, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX(hbox), value2, FALSE, FALSE, 0);
+ if (checkbutton2) {
+ gtk_box_pack_end (GTK_BOX(hbox), checkbutton2, FALSE, FALSE, 0);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(checkbutton2), checkbutton2_default);
+ }
+ if (checkbutton1) {
+ gtk_box_pack_end (GTK_BOX(hbox), checkbutton1, FALSE, FALSE, 0);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(checkbutton1), checkbutton1_default);
+ }
gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
-
+
return vbox;
}
PropWidgets *widgets = prop_widgets_new();
widgets->vtl = vtl;
widgets->tr = tr;
- widgets->vlp = vlp;
widgets->profile_width = PROPWIN_PROFILE_WIDTH;
widgets->profile_height = PROPWIN_PROFILE_HEIGHT;
widgets->track_name = track_name;
gdouble min_alt, max_alt;
widgets->elev_box = vik_trw_layer_create_profile(GTK_WIDGET(parent), tr, vlp, vvp, widgets, &min_alt, &max_alt);
widgets->speed_box = vik_trw_layer_create_vtdiag(GTK_WIDGET(parent), tr, vlp, vvp, widgets);
+ widgets->dist_box = vik_trw_layer_create_dtdiag(GTK_WIDGET(parent), tr, vlp, vvp, widgets);
+ widgets->elev_time_box = vik_trw_layer_create_etdiag(GTK_WIDGET(parent), tr, vlp, vvp, widgets);
+ widgets->speed_dist_box = vik_trw_layer_create_sddiag(GTK_WIDGET(parent), tr, vlp, vvp, widgets);
GtkWidget *graphs = gtk_notebook_new();
GtkWidget *content[20];
gtk_notebook_append_page(GTK_NOTEBOOK(graphs), GTK_WIDGET(table), gtk_label_new(_("Statistics")));
+ gpointer *pass_along;
+ pass_along = g_malloc ( sizeof(gpointer) * 4 ); /* FIXME: mem leak -- never be freed */
+ pass_along[0] = tr;
+ pass_along[1] = vlp;
+ pass_along[2] = vvp;
+ pass_along[3] = widgets;
+
if ( widgets->elev_box ) {
GtkWidget *page = NULL;
widgets->w_cur_dist = gtk_label_new(_("No Data"));
widgets->w_cur_elevation = gtk_label_new(_("No Data"));
+ widgets->w_show_dem = gtk_check_button_new_with_mnemonic(_("Show D_EM"));
+ widgets->w_show_alt_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
page = create_graph_page (widgets->elev_box,
_("<b>Track Distance:</b>"), widgets->w_cur_dist,
- _("<b>Track Height:</b>"), widgets->w_cur_elevation);
+ _("<b>Track Height:</b>"), widgets->w_cur_elevation,
+ widgets->w_show_dem, TRUE,
+ widgets->w_show_alt_gps_speed, TRUE);
+ g_signal_connect (widgets->w_show_dem, "toggled", G_CALLBACK (checkbutton_toggle_cb), pass_along);
+ g_signal_connect (widgets->w_show_alt_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), pass_along);
gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Elevation-distance")));
}
GtkWidget *page = NULL;
widgets->w_cur_time = gtk_label_new(_("No Data"));
widgets->w_cur_speed = gtk_label_new(_("No Data"));
+ widgets->w_show_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
page = create_graph_page (widgets->speed_box,
_("<b>Track Time:</b>"), widgets->w_cur_time,
- _("<b>Track Speed:</b>"), widgets->w_cur_speed);
+ _("<b>Track Speed:</b>"), widgets->w_cur_speed,
+ widgets->w_show_gps_speed, TRUE,
+ NULL, FALSE);
+ g_signal_connect (widgets->w_show_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), pass_along);
gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Speed-time")));
}
+ if ( widgets->dist_box ) {
+ GtkWidget *page = NULL;
+ widgets->w_cur_dist_time = gtk_label_new(_("No Data"));
+ widgets->w_cur_dist_dist = gtk_label_new(_("No Data"));
+ widgets->w_show_dist_speed = gtk_check_button_new_with_mnemonic(_("Show S_peed"));
+ page = create_graph_page (widgets->dist_box,
+ _("<b>Track Distance:</b>"), widgets->w_cur_dist_dist,
+ _("<b>Track Time:</b>"), widgets->w_cur_dist_time,
+ widgets->w_show_dist_speed, FALSE,
+ NULL, FALSE);
+ g_signal_connect (widgets->w_show_dist_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), pass_along);
+ gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Distance-time")));
+ }
+
+ if ( widgets->elev_time_box ) {
+ GtkWidget *page = NULL;
+ widgets->w_cur_elev_time = gtk_label_new(_("No Data"));
+ widgets->w_cur_elev_elev = gtk_label_new(_("No Data"));
+ widgets->w_show_elev_speed = gtk_check_button_new_with_mnemonic(_("Show S_peed"));
+ page = create_graph_page (widgets->elev_time_box,
+ _("<b>Track Time:</b>"), widgets->w_cur_elev_time,
+ _("<b>Track Height:</b>"), widgets->w_cur_elev_elev,
+ widgets->w_show_elev_speed, FALSE,
+ NULL, FALSE);
+ g_signal_connect (widgets->w_show_elev_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), pass_along);
+ gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Elevation-time")));
+ }
+
+ if ( widgets->speed_dist_box ) {
+ GtkWidget *page = NULL;
+ widgets->w_cur_speed_dist = gtk_label_new(_("No Data"));
+ widgets->w_cur_speed_speed = gtk_label_new(_("No Data"));
+ widgets->w_show_sd_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
+ page = create_graph_page (widgets->speed_dist_box,
+ _("<b>Track Distance:</b>"), widgets->w_cur_speed_dist,
+ _("<b>Track Speed:</b>"), widgets->w_cur_speed_speed,
+ widgets->w_show_sd_gps_speed, TRUE,
+ NULL, FALSE);
+ g_signal_connect (widgets->w_show_sd_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), pass_along);
+ gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Speed-distance")));
+ }
+
gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), graphs, FALSE, FALSE, 0);
gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, FALSE);
if (vik_track_get_dup_point_count(tr) <= 0)
gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), VIK_TRW_LAYER_PROPWIN_DEL_DUP, FALSE);
- gpointer *pass_along;
- pass_along = g_malloc ( sizeof(gpointer) * 3 ); /* FIXME: mem leak -- never be freed */
- pass_along[0] = tr;
- pass_along[1] = vlp;
- pass_along[2] = widgets;
-
// On dialog realization configure_event casues the graphs to be initially drawn
widgets->configure_dialog = TRUE;
g_signal_connect ( G_OBJECT(dialog), "configure-event", G_CALLBACK (configure_event), pass_along);