}
}
-#define MARGIN 50
+#define MARGIN 70
#define LINES 5
static void set_center_at_graph_position(gdouble event_x, gint img_width, VikLayersPanel *vlp, VikTrack *tr, gboolean time_base)
{
}
}
-static void draw_graph_mark(GtkWidget *image, gdouble x, GdkGC *gc, PropSaved *saved_img)
+static void draw_graph_mark(GtkWidget *image, gdouble event_x, gint img_width, GdkGC *gc, PropSaved *saved_img)
{
GdkPixmap *pix;
const int saved_width = 5;
+ /* 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);
if (saved_img->saved) {
gdk_draw_image(GDK_DRAWABLE(pix), gc, saved_img->img, 0, 0,
saved_img->pos, 0, -1, -1);
saved_img->saved = FALSE;
- gtk_widget_queue_draw_area(image, saved_img->pos, 0,
+ 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))) {
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, x - saved_width/2, 0, saved_width, PROFILE_HEIGHT);
+ gtk_widget_queue_draw_area(image, event_x - saved_width/2, 0, saved_width, PROFILE_HEIGHT);
}
}
set_center_at_graph_position(event->x, event_box->allocation.width, vlp, tr, is_vt_graph);
- draw_graph_mark(image, event->x, window->style->black_gc,
+ 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);
g_list_free(child);
TRUE, MARGIN, 0, PROFILE_WIDTH, PROFILE_HEIGHT);
/* draw grid */
-#define LABEL_FONT "Sans 8"
+#define LABEL_FONT "Sans 7"
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 (LABEL_FONT);
pango_layout_set_font_description (pl, pfd);
pango_font_description_free (pfd);
sprintf(s, "%8dm", (int)(mina + (LINES-i)*(maxa-mina)/LINES));
pango_layout_set_text(pl, s, -1);
- gdk_draw_layout(GDK_DRAWABLE(pix), window->style->fg_gc[0], 0,
- CLAMP((int)i*PROFILE_HEIGHT/LINES - 5, 0, PROFILE_HEIGHT-15), pl);
+ 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*PROFILE_HEIGHT/LINES - h/2, 0, PROFILE_HEIGHT-h), pl);
gdk_draw_line (GDK_DRAWABLE(pix), window->style->dark_gc[0],
MARGIN, PROFILE_HEIGHT/LINES * i, MARGIN + PROFILE_WIDTH, PROFILE_HEIGHT/LINES * i);
#else
/* draw grid */
-#define LABEL_FONT "Sans 8"
+#define LABEL_FONT "Sans 7"
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 (LABEL_FONT);
pango_layout_set_font_description (pl, pfd);
pango_font_description_free (pfd);
sprintf(s, "%8dmph", (int)(mins + (LINES-i)*(maxs-mins)/LINES));
#endif
pango_layout_set_text(pl, s, -1);
- gdk_draw_layout(GDK_DRAWABLE(pix), window->style->fg_gc[0], 0,
- CLAMP((int)i*PROFILE_HEIGHT/LINES - 5, 0, PROFILE_HEIGHT-15), pl);
+ 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*PROFILE_HEIGHT/LINES - h/2, 0, PROFILE_HEIGHT-h), pl);
gdk_draw_line (GDK_DRAWABLE(pix), window->style->dark_gc[0],
MARGIN, PROFILE_HEIGHT/LINES * i, MARGIN + PROFILE_WIDTH, PROFILE_HEIGHT/LINES * i);
}
+
/* draw speeds */
for ( i = 0; i < PROFILE_WIDTH; i++ )