Bug 588512 - Grid Spacing errors depending on unit

Always round grid spacings and offsets to integer precision when
using them for snapping and grid drawing. While we might *want* to
have subpixel precision grids, all the UI is pretending it to be
on pixel boundaries. Make that pretense an fact.
This commit is contained in:
Michael Natterer 2014-05-21 20:43:05 +02:00
parent 7266cd9c1f
commit 08c6aefa23
2 changed files with 45 additions and 17 deletions

View File

@ -106,6 +106,12 @@ gimp_image_snap_x (GimpImage *image,
"xoffset", &xoffset,
NULL);
/* FIXME subpixel grid */
xspacing = RINT (xspacing);
xoffset = RINT (xoffset);
g_printerr ("snap: spacing = %f offset = %f\n", xspacing, xoffset);
/* the snap-to-grid part could probably be rewritten */
while (xoffset > xspacing)
xoffset -= xspacing;
@ -193,6 +199,10 @@ gimp_image_snap_y (GimpImage *image,
"yoffset", &yoffset,
NULL);
/* FIXME subpixel grid */
yspacing = RINT (yspacing);
yoffset = RINT (yoffset);
while (yoffset > yspacing)
yoffset -= yspacing;
@ -303,6 +313,12 @@ gimp_image_snap_point (GimpImage *image,
"yoffset", &yoffset,
NULL);
/* FIXME subpixel grid */
xspacing = RINT (xspacing);
yspacing = RINT (yspacing);
xoffset = RINT (xoffset);
yoffset = RINT (yoffset);
while (xoffset > xspacing)
xoffset -= xspacing;

View File

@ -189,24 +189,38 @@ gimp_canvas_grid_draw (GimpCanvasItem *item,
GimpCanvasGridPrivate *private = GET_PRIVATE (item);
GimpDisplayShell *shell = gimp_canvas_item_get_shell (item);
GimpImage *image = gimp_canvas_item_get_image (item);
gdouble xspacing, yspacing;
gdouble xoffset, yoffset;
gdouble x, y;
gdouble dx1, dy1, dx2, dy2;
gint x0, x1, x2, x3;
gint y0, y1, y2, y3;
gint x_real, y_real;
gdouble x_offset, y_offset;
gint width, height;
#define CROSSHAIR 2
g_return_if_fail (private->grid->xspacing > 0 &&
private->grid->yspacing > 0);
g_object_get (private->grid,
"xspacing", &xspacing,
"yspacing", &yspacing,
"xoffset", &xoffset,
"yoffset", &yoffset,
NULL);
/* FIXME subpixel grid */
xspacing = RINT (xspacing);
yspacing = RINT (yspacing);
xoffset = RINT (xoffset);
yoffset = RINT (yoffset);
g_return_if_fail (xspacing > 0.0 &&
yspacing > 0.0);
/* skip grid drawing when the space between grid lines starts
* disappearing, see bug #599267.
*/
if (private->grid->xspacing * shell->scale_x < 2.0 ||
private->grid->yspacing * shell->scale_y < 2.0)
if (xspacing * shell->scale_x < 2.0 ||
yspacing * shell->scale_y < 2.0)
return;
cairo_clip_extents (cr, &dx1, &dy1, &dx2, &dy2);
@ -219,18 +233,16 @@ gimp_canvas_grid_draw (GimpCanvasItem *item,
width = gimp_image_get_width (image);
height = gimp_image_get_height (image);
x_offset = private->grid->xoffset;
while (x_offset > 0)
x_offset -= private->grid->xspacing;
while (xoffset > 0)
xoffset -= xspacing;
y_offset = private->grid->yoffset;
while (y_offset > 0)
y_offset -= private->grid->yspacing;
while (yoffset > 0)
yoffset -= yspacing;
switch (private->grid->style)
{
case GIMP_GRID_DOTS:
for (x = x_offset; x <= width; x += private->grid->xspacing)
for (x = xoffset; x <= width; x += xspacing)
{
if (x < 0)
continue;
@ -240,7 +252,7 @@ gimp_canvas_grid_draw (GimpCanvasItem *item,
if (x_real < x1 || x_real >= x2)
continue;
for (y = y_offset; y <= height; y += private->grid->yspacing)
for (y = yoffset; y <= height; y += yspacing)
{
if (y < 0)
continue;
@ -257,7 +269,7 @@ gimp_canvas_grid_draw (GimpCanvasItem *item,
break;
case GIMP_GRID_INTERSECTIONS:
for (x = x_offset; x <= width; x += private->grid->xspacing)
for (x = xoffset; x <= width; x += xspacing)
{
if (x < 0)
continue;
@ -267,7 +279,7 @@ gimp_canvas_grid_draw (GimpCanvasItem *item,
if (x_real + CROSSHAIR < x1 || x_real - CROSSHAIR >= x2)
continue;
for (y = y_offset; y <= height; y += private->grid->yspacing)
for (y = yoffset; y <= height; y += yspacing)
{
if (y < 0)
continue;
@ -310,7 +322,7 @@ gimp_canvas_grid_draw (GimpCanvasItem *item,
gimp_canvas_item_transform_xy (item, 0, 0, &x0, &y0);
gimp_canvas_item_transform_xy (item, width, height, &x3, &y3);
for (x = x_offset; x < width; x += private->grid->xspacing)
for (x = xoffset; x < width; x += xspacing)
{
if (x < 0)
continue;
@ -324,7 +336,7 @@ gimp_canvas_grid_draw (GimpCanvasItem *item,
}
}
for (y = y_offset; y < height; y += private->grid->yspacing)
for (y = yoffset; y < height; y += yspacing)
{
if (y < 0)
continue;