[gimp] app: restrict grid and guide drawing to the exposed region



commit 6e4be79befc3f0a690a1396240c1b24c6ea09044
Author: Michael Natterer <mitch gimp org>
Date:   Sun May 2 15:40:11 2010 +0200

    app: restrict grid and guide drawing to the exposed region
    
    Doesn't really clip yet for guide drawing, but at least doesn't bother
    to draw them when they are outside the expose region's bounding box.

 app/display/gimpdisplayshell-callbacks.c |    4 +-
 app/display/gimpdisplayshell-draw.c      |   66 +++++++++++++++++++-----------
 app/display/gimpdisplayshell-draw.h      |    6 ++-
 app/tools/gimpmovetool.c                 |   12 +++---
 4 files changed, 54 insertions(+), 34 deletions(-)
---
diff --git a/app/display/gimpdisplayshell-callbacks.c b/app/display/gimpdisplayshell-callbacks.c
index 4b84a02..86e0e23 100644
--- a/app/display/gimpdisplayshell-callbacks.c
+++ b/app/display/gimpdisplayshell-callbacks.c
@@ -2275,10 +2275,10 @@ gimp_display_shell_canvas_expose_image (GimpDisplayShell *shell,
   gimp_display_shell_preview_transform (shell);
 
   /* draw the grid */
-  gimp_display_shell_draw_grid (shell, &eevent->area);
+  gimp_display_shell_draw_grid (shell, eevent->region);
 
   /* draw the guides */
-  gimp_display_shell_draw_guides (shell);
+  gimp_display_shell_draw_guides (shell, eevent->region);
 
   /* draw the sample points */
   gimp_display_shell_draw_sample_points (shell);
diff --git a/app/display/gimpdisplayshell-draw.c b/app/display/gimpdisplayshell-draw.c
index 3ee4efb..87006a1 100644
--- a/app/display/gimpdisplayshell-draw.c
+++ b/app/display/gimpdisplayshell-draw.c
@@ -132,9 +132,10 @@ gimp_display_shell_draw_get_scaled_image_size_for_scale (GimpDisplayShell *shell
 }
 
 void
-gimp_display_shell_draw_guide (GimpDisplayShell *shell,
-                               GimpGuide        *guide,
-                               gboolean          active)
+gimp_display_shell_draw_guide (GimpDisplayShell   *shell,
+                               GimpGuide          *guide,
+                               const GdkRectangle *area,
+                               gboolean            active)
 {
   gint  position;
   gint  x1, y1, x2, y2;
@@ -157,11 +158,15 @@ gimp_display_shell_draw_guide (GimpDisplayShell *shell,
     {
     case GIMP_ORIENTATION_HORIZONTAL:
       gimp_display_shell_transform_xy (shell, 0, position, &x, &y, FALSE);
+      if (area && (y < area->y || y >= area->y + area->height))
+        return;
       y1 = y2 = y;
       break;
 
     case GIMP_ORIENTATION_VERTICAL:
       gimp_display_shell_transform_xy (shell, position, 0, &x, &y, FALSE);
+      if (area && (x < area->x || x >= area->x + area->width))
+        return;
       x1 = x2 = x;
       break;
 
@@ -176,48 +181,58 @@ gimp_display_shell_draw_guide (GimpDisplayShell *shell,
 }
 
 void
-gimp_display_shell_draw_guides (GimpDisplayShell *shell)
+gimp_display_shell_draw_guides (GimpDisplayShell *shell,
+                                const GdkRegion  *region)
 {
   GimpImage *image;
 
   g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
+  g_return_if_fail (region != NULL);
 
   image = gimp_display_get_image (shell->display);
 
   if (image && gimp_display_shell_get_show_guides (shell))
     {
-      GList *list;
+      GdkRectangle  area;
+      GList        *list;
+
+      if (region)
+        gdk_region_get_clipbox (region, &area);
 
       for (list = gimp_image_get_guides (image);
            list;
            list = g_list_next (list))
         {
-          gimp_display_shell_draw_guide (shell, list->data, FALSE);
+          gimp_display_shell_draw_guide (shell, list->data,
+                                         region ? &area : NULL,
+                                         FALSE);
         }
     }
 }
 
 void
-gimp_display_shell_draw_grid (GimpDisplayShell   *shell,
-                              const GdkRectangle *area)
+gimp_display_shell_draw_grid (GimpDisplayShell *shell,
+                              const GdkRegion  *region)
 {
   GimpImage *image;
 
   g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
-  g_return_if_fail (area != NULL);
+  g_return_if_fail (region != NULL);
 
   image = gimp_display_get_image (shell->display);
 
   if (image && gimp_display_shell_get_show_grid (shell))
     {
-      GimpGrid   *grid;
-      GimpCanvas *canvas;
-      gdouble     x, y;
-      gint        x0, x1, x2, x3;
-      gint        y0, y1, y2, y3;
-      gint        x_real, y_real;
-      gdouble     x_offset, y_offset;
-      gint        width, height;
+      GimpCanvas   *canvas = GIMP_CANVAS (shell->canvas);
+      GimpGrid     *grid;
+      GdkRectangle  area;
+      GdkGC        *grid_gc;
+      gdouble       x, y;
+      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
 
@@ -227,10 +242,12 @@ gimp_display_shell_draw_grid (GimpDisplayShell   *shell,
 
       g_return_if_fail (grid->xspacing > 0 && grid->yspacing > 0);
 
-      x1 = area->x;
-      y1 = area->y;
-      x2 = area->x + area->width;
-      y2 = area->y + area->height;
+      gdk_region_get_clipbox (region, &area);
+
+      x1 = area.x;
+      y1 = area.y;
+      x2 = area.x + area.width;
+      y2 = area.y + area.height;
 
       width  = gimp_image_get_width  (image);
       height = gimp_image_get_height (image);
@@ -243,10 +260,10 @@ gimp_display_shell_draw_grid (GimpDisplayShell   *shell,
       while (y_offset > 0)
         y_offset -= grid->yspacing;
 
-      canvas = GIMP_CANVAS (shell->canvas);
+      grid_gc = gimp_display_shell_get_grid_gc (shell, grid);
 
-      gimp_canvas_set_custom_gc (canvas,
-                                 gimp_display_shell_get_grid_gc (shell, grid));
+      gdk_gc_set_clip_region (grid_gc, region);
+      gimp_canvas_set_custom_gc (canvas, grid_gc);
 
       switch (grid->style)
         {
@@ -366,6 +383,7 @@ gimp_display_shell_draw_grid (GimpDisplayShell   *shell,
         }
 
       gimp_canvas_set_custom_gc (canvas, NULL);
+      gdk_gc_set_clip_region (grid_gc, NULL);
     }
 }
 
diff --git a/app/display/gimpdisplayshell-draw.h b/app/display/gimpdisplayshell-draw.h
index d8d625a..83fced8 100644
--- a/app/display/gimpdisplayshell-draw.h
+++ b/app/display/gimpdisplayshell-draw.h
@@ -29,10 +29,12 @@ void   gimp_display_shell_draw_get_scaled_image_size_for_scale
                                                       gint               *h);
 void   gimp_display_shell_draw_guide                 (GimpDisplayShell   *shell,
                                                       GimpGuide          *guide,
+                                                      const GdkRectangle *area,
                                                       gboolean            active);
-void   gimp_display_shell_draw_guides                (GimpDisplayShell   *shell);
+void   gimp_display_shell_draw_guides                (GimpDisplayShell   *shell,
+                                                      const GdkRegion    *region);
 void   gimp_display_shell_draw_grid                  (GimpDisplayShell   *shell,
-                                                      const GdkRectangle *area);
+                                                      const GdkRegion    *region);
 void   gimp_display_shell_draw_pen                   (GimpDisplayShell   *shell,
                                                       const GimpVector2  *points,
                                                       gint                num_points,
diff --git a/app/tools/gimpmovetool.c b/app/tools/gimpmovetool.c
index 29bf724..893c727 100644
--- a/app/tools/gimpmovetool.c
+++ b/app/tools/gimpmovetool.c
@@ -190,12 +190,12 @@ gimp_move_tool_control (GimpTool       *tool,
 
     case GIMP_TOOL_ACTION_RESUME:
       if (move->guide && gimp_display_shell_get_show_guides (shell))
-        gimp_display_shell_draw_guide (shell, move->guide, TRUE);
+        gimp_display_shell_draw_guide (shell, move->guide, NULL, TRUE);
       break;
 
     case GIMP_TOOL_ACTION_HALT:
       if (move->guide && gimp_display_shell_get_show_guides (shell))
-        gimp_display_shell_draw_guide (shell, move->guide, FALSE);
+        gimp_display_shell_draw_guide (shell, move->guide, NULL, FALSE);
       break;
     }
 
@@ -446,7 +446,7 @@ gimp_move_tool_button_release (GimpTool              *tool,
       gimp_image_flush (image);
 
       if (move->guide)
-        gimp_display_shell_draw_guide (shell, move->guide, TRUE);
+        gimp_display_shell_draw_guide (shell, move->guide, NULL, TRUE);
 
       move->moving_guide      = FALSE;
       move->guide_position    = -1;
@@ -667,12 +667,12 @@ gimp_move_tool_oper_update (GimpTool         *tool,
     }
 
   if (move->guide && move->guide != guide)
-    gimp_display_shell_draw_guide (shell, move->guide, FALSE);
+    gimp_display_shell_draw_guide (shell, move->guide, NULL, FALSE);
 
   move->guide = guide;
 
   if (move->guide)
-    gimp_display_shell_draw_guide (shell, move->guide, TRUE);
+    gimp_display_shell_draw_guide (shell, move->guide, NULL, TRUE);
 }
 
 static void
@@ -819,7 +819,7 @@ gimp_move_tool_start_guide (GimpMoveTool        *move,
 
   if (move->guide)
     gimp_display_shell_draw_guide (gimp_display_get_shell (display),
-                                   move->guide, FALSE);
+                                   move->guide, NULL, FALSE);
 
   move->guide             = NULL;
   move->moving_guide      = TRUE;



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