[gimp/gimp-2-8] Bug 588512 - Grid Spacing errors depending on unit



commit 247267031eb8915641490d1385a74df42e794557
Author: Michael Natterer <mitch gimp org>
Date:   Wed May 21 20:43:05 2014 +0200

    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.
    
    (cherry picked from commit 08c6aefa2398dcd36f0c8963633715de6a6430b4)

 app/core/gimpimage-snap.c    |   16 ++++++++++++++
 app/display/gimpcanvasgrid.c |   45 +++++++++++++++++++++++++++--------------
 2 files changed, 45 insertions(+), 16 deletions(-)
---
diff --git a/app/core/gimpimage-snap.c b/app/core/gimpimage-snap.c
index 56f73f4..284d53c 100644
--- a/app/core/gimpimage-snap.c
+++ b/app/core/gimpimage-snap.c
@@ -105,6 +105,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;
@@ -192,6 +198,10 @@ gimp_image_snap_y (GimpImage *image,
                     "yoffset",  &yoffset,
                     NULL);
 
+      /* FIXME subpixel grid */
+      yspacing = RINT (yspacing);
+      yoffset  = RINT (yoffset);
+
       while (yoffset > yspacing)
         yoffset -= yspacing;
 
@@ -302,6 +312,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;
 
diff --git a/app/display/gimpcanvasgrid.c b/app/display/gimpcanvasgrid.c
index 9f3304c..011dcb5 100644
--- a/app/display/gimpcanvasgrid.c
+++ b/app/display/gimpcanvasgrid.c
@@ -194,23 +194,38 @@ gimp_canvas_grid_draw (GimpCanvasItem   *item,
 {
   GimpCanvasGridPrivate *private = GET_PRIVATE (item);
   GimpImage             *image   = gimp_display_get_image (shell->display);
+  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);
@@ -223,18 +238,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;
@@ -244,7 +257,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;
@@ -261,7 +274,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;
@@ -271,7 +284,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;
@@ -314,7 +327,7 @@ gimp_canvas_grid_draw (GimpCanvasItem   *item,
       gimp_display_shell_transform_xy (shell, 0, 0, &x0, &y0);
       gimp_display_shell_transform_xy (shell, 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;
@@ -328,7 +341,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;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]