From 539f5378462670d10ea6500a7980f3a7f84fe0d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Tue, 1 Feb 2011 17:21:08 +0100 Subject: Fix drawing of the grid. --- liblogdiag/ld-canvas.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/liblogdiag/ld-canvas.c b/liblogdiag/ld-canvas.c index 1d05b4b..420232d 100644 --- a/liblogdiag/ld-canvas.c +++ b/liblogdiag/ld-canvas.c @@ -1339,12 +1339,17 @@ static void draw_grid (GtkWidget *widget, DrawData *data) { gdouble grid_step; + gint grid_factor; gdouble x_init, y_init; gdouble x, y; grid_step = data->scale; + grid_factor = 1; while (grid_step < 5) + { grid_step *= 5; + grid_factor *= 5; + } ld_canvas_color_apply (COLOR_GET (data->self, COLOR_GRID), data->cr); cairo_set_line_width (data->cr, 1); @@ -1353,8 +1358,14 @@ draw_grid (GtkWidget *widget, DrawData *data) /* Get coordinates of the top-left point. */ ld_canvas_widget_to_diagram_coords (data->self, data->exposed_rect.x, data->exposed_rect.y, &x_init, &y_init); + + x_init = ceil (x_init); + x_init = x_init - (gint) x_init % grid_factor; + y_init = ceil (y_init); + y_init = y_init - (gint) y_init % grid_factor; + ld_canvas_diagram_to_widget_coords (data->self, - ceil (x_init), ceil (y_init), &x_init, &y_init); + x_init, y_init, &x_init, &y_init); /* Iterate over all the points. */ for (x = x_init; x <= data->exposed_rect.x + data->exposed_rect.width; -- cgit v1.2.3