]> git.street.me.uk Git - andy/viking.git/blobdiff - src/viktrwlayer_propwin.c
Windows port: typo in util.c
[andy/viking.git] / src / viktrwlayer_propwin.c
index c0984fa02ae16a80c72a7c384880f89e74542517..a562e9f3f646590c6cac7f600fd30157bf959bf2 100644 (file)
@@ -112,7 +112,7 @@ static void minmax_alt(const gdouble *altitudes, gdouble *min, gdouble *max)
   }
 }
 
-#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)
 {
@@ -135,17 +135,22 @@ static void set_center_at_graph_position(gdouble event_x, gint img_width, VikLay
   }
 }
 
-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))) {
@@ -159,7 +164,7 @@ static void draw_graph_mark(GtkWidget *image, gdouble x, GdkGC *gc, PropSaved *s
     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);
   }
 }
 
@@ -174,7 +179,7 @@ static void track_graph_click( GtkWidget *event_box, GdkEventButton *event, gpoi
 
 
   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);
 
@@ -324,19 +329,22 @@ GtkWidget *vik_trw_layer_create_profile ( GtkWidget *window, VikTrack *tr, gpoin
                     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);
@@ -448,12 +456,14 @@ GtkWidget *vik_trw_layer_create_vtdiag ( GtkWidget *window, VikTrack *tr, gpoint
 #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);
@@ -463,12 +473,14 @@ GtkWidget *vik_trw_layer_create_vtdiag ( GtkWidget *window, VikTrack *tr, gpoint
     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++ )