Take a better approach to drawing the grid.

If the diagram is zoomed out too much, just use bigger steps between dots.
This commit is contained in:
Přemysl Eric Janouch 2011-01-08 16:41:55 +01:00
parent 909a0352cc
commit fe996324d3
1 changed files with 6 additions and 4 deletions

View File

@ -1072,11 +1072,13 @@ on_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
static void static void
draw_grid (GtkWidget *widget, DrawData *data) draw_grid (GtkWidget *widget, DrawData *data)
{ {
gdouble grid_step;
gdouble x_init, y_init; gdouble x_init, y_init;
gdouble x, y; gdouble x, y;
if (data->scale < 2) grid_step = data->scale;
return; while (grid_step < 5)
grid_step *= 5;
ld_canvas_color_apply (COLOR_GET (data->self, COLOR_GRID), data->cr); ld_canvas_color_apply (COLOR_GET (data->self, COLOR_GRID), data->cr);
cairo_set_line_width (data->cr, 1); cairo_set_line_width (data->cr, 1);
@ -1090,10 +1092,10 @@ draw_grid (GtkWidget *widget, DrawData *data)
/* Iterate over all the points. */ /* Iterate over all the points. */
for (x = x_init; x <= data->exposed_rect.x + data->exposed_rect.width; for (x = x_init; x <= data->exposed_rect.x + data->exposed_rect.width;
x += data->scale) x += grid_step)
{ {
for (y = y_init; y <= data->exposed_rect.y + data->exposed_rect.height; for (y = y_init; y <= data->exposed_rect.y + data->exposed_rect.height;
y += data->scale) y += grid_step)
{ {
cairo_move_to (data->cr, x, y); cairo_move_to (data->cr, x, y);
cairo_line_to (data->cr, x, y); cairo_line_to (data->cr, x, y);