[gimp] app: port GimpVectors drawing to cairo



commit 4c57e3f19e54d2527abc8ee69bbd000ac7ff4441
Author: Sven Neumann <sven gimp org>
Date:   Sat Sep 11 23:37:17 2010 +0200

    app: port GimpVectors drawing to cairo
    
    This is just a rough proof of concept. More changes are about
    to follow.

 app/display/gimpdisplayshell-callbacks.c |    7 ++-
 app/display/gimpdisplayshell-draw.c      |   66 ++++++++++++++++--------------
 app/display/gimpdisplayshell-draw.h      |    5 +-
 app/display/gimpdisplayshell-expose.c    |   11 +++++
 app/display/gimpdisplayshell-expose.h    |    2 +
 app/display/gimpdisplayshell-handlers.c  |   18 ++++-----
 app/display/gimpdisplayshell.c           |    4 --
 7 files changed, 63 insertions(+), 50 deletions(-)
---
diff --git a/app/display/gimpdisplayshell-callbacks.c b/app/display/gimpdisplayshell-callbacks.c
index b5ed3f0..bbfc916 100644
--- a/app/display/gimpdisplayshell-callbacks.c
+++ b/app/display/gimpdisplayshell-callbacks.c
@@ -268,8 +268,6 @@ gimp_display_shell_canvas_realize (GtkWidget        *canvas,
 
   /*  allow shrinking  */
   gtk_widget_set_size_request (GTK_WIDGET (shell), 0, 0);
-
-  gimp_display_shell_draw_vectors (shell);
 }
 
 void
@@ -2308,6 +2306,11 @@ gimp_display_shell_canvas_expose_image (GimpDisplayShell *shell,
   gimp_display_shell_preview_transform (shell, cr);
   cairo_restore (cr);
 
+  /* draw the vectors */
+  cairo_save (cr);
+  gimp_display_shell_draw_vectors (shell, cr);
+  cairo_restore (cr);
+
   /* draw the grid */
   cairo_save (cr);
   gimp_display_shell_draw_grid (shell, cr);
diff --git a/app/display/gimpdisplayshell-draw.c b/app/display/gimpdisplayshell-draw.c
index 9903574..65daa94 100644
--- a/app/display/gimpdisplayshell-draw.c
+++ b/app/display/gimpdisplayshell-draw.c
@@ -583,47 +583,38 @@ gimp_display_shell_draw_selection_in (GimpDisplayShell   *shell,
   cairo_mask (cr, mask);
 }
 
-void
-gimp_display_shell_draw_vector (GimpDisplayShell *shell,
-                                GimpVectors      *vectors)
+static void
+gimp_display_shell_draw_one_vectors (GimpDisplayShell *shell,
+                                     cairo_t          *cr,
+                                     GimpVectors      *vectors,
+                                     gdouble           width)
 {
   GimpStroke *stroke = NULL;
 
-  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
-  g_return_if_fail (GIMP_IS_VECTORS (vectors));
-
   while ((stroke = gimp_vectors_stroke_get_next (vectors, stroke)))
     {
-      GArray   *coords;
-      gboolean  closed;
+      GimpBezierDesc *desc = gimp_vectors_make_bezier (vectors);
 
-      coords = gimp_stroke_interpolate (stroke, 1.0, &closed);
-
-      if (coords && coords->len > 0)
+      if (desc)
         {
-          GdkPoint *gdk_coords = g_new (GdkPoint, coords->len);
+          cairo_append_path (cr, (cairo_path_t *) desc);
 
-          gimp_display_shell_transform_coords (shell,
-                                               &g_array_index (coords,
-                                                               GimpCoords, 0),
-                                               gdk_coords,
-                                               coords->len,
-                                               FALSE);
+          cairo_set_line_width (cr, 1.6 * width);
+          cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+          cairo_stroke_preserve (cr);
 
-          gimp_canvas_draw_lines (GIMP_CANVAS (shell->canvas),
-                                  GIMP_CANVAS_STYLE_XOR,
-                                  gdk_coords, coords->len);
+          cairo_set_line_width (cr, width);
+          cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
+          cairo_stroke (cr);
 
-          g_free (gdk_coords);
+          g_free (desc->data);
+          g_free (desc);
         }
-
-      if (coords)
-        g_array_free (coords, TRUE);
     }
 }
-
 void
-gimp_display_shell_draw_vectors (GimpDisplayShell *shell)
+gimp_display_shell_draw_vectors (GimpDisplayShell *shell,
+                                 cairo_t          *cr)
 {
   GimpImage *image;
 
@@ -633,17 +624,30 @@ gimp_display_shell_draw_vectors (GimpDisplayShell *shell)
 
   if (image && TRUE /* gimp_display_shell_get_show_vectors (shell) */)
     {
-      GList *all_vectors;
-      GList *list;
+      GList       *all_vectors = gimp_image_get_vectors_list (image);
+      const GList *list;
+      gdouble      xscale;
+      gdouble      yscale;
+      gdouble      width;
+
+      if (! all_vectors)
+        return;
+
+      cairo_translate (cr, - shell->offset_x, - shell->offset_y);
+      cairo_scale (cr, shell->scale_x, shell->scale_y);
 
-      all_vectors = gimp_image_get_vectors_list (image);
+      /* determine a reasonable line width */
+      xscale = yscale = 2.0;
+      cairo_device_to_user_distance (cr, &xscale, &yscale);
+      width = MAX (xscale, yscale);
+      width = MIN (width, 2.0);
 
       for (list = all_vectors; list; list = list->next)
         {
           GimpVectors *vectors = list->data;
 
           if (gimp_item_get_visible (GIMP_ITEM (vectors)))
-            gimp_display_shell_draw_vector (shell, vectors);
+            gimp_display_shell_draw_one_vectors (shell, cr, vectors, width);
         }
 
       g_list_free (all_vectors);
diff --git a/app/display/gimpdisplayshell-draw.h b/app/display/gimpdisplayshell-draw.h
index 5f51ba2..0baff69 100644
--- a/app/display/gimpdisplayshell-draw.h
+++ b/app/display/gimpdisplayshell-draw.h
@@ -61,9 +61,8 @@ void   gimp_display_shell_draw_selection_in          (GimpDisplayShell   *shell,
                                                       cairo_t            *cr,
                                                       cairo_pattern_t    *mask,
                                                       gint                index);
-void   gimp_display_shell_draw_vector                (GimpDisplayShell   *shell,
-                                                      GimpVectors        *vectors);
-void   gimp_display_shell_draw_vectors               (GimpDisplayShell   *shell);
+void   gimp_display_shell_draw_vectors               (GimpDisplayShell   *shell,
+                                                      cairo_t            *cr);
 void   gimp_display_shell_draw_cursor                (GimpDisplayShell   *shell,
                                                       cairo_t            *cr);
 void   gimp_display_shell_draw_area                  (GimpDisplayShell   *shell,
diff --git a/app/display/gimpdisplayshell-expose.c b/app/display/gimpdisplayshell-expose.c
index 560079b..701c279 100644
--- a/app/display/gimpdisplayshell-expose.c
+++ b/app/display/gimpdisplayshell-expose.c
@@ -108,6 +108,17 @@ gimp_display_shell_expose_sample_point (GimpDisplayShell *shell,
 }
 
 void
+gimp_display_shell_expose_vectors (GimpDisplayShell *shell,
+                                   GimpVectors      *vectors)
+{
+  g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
+  g_return_if_fail (vectors != NULL);
+
+  // FIXME
+  gimp_display_shell_expose_full (shell);
+}
+
+void
 gimp_display_shell_expose_full (GimpDisplayShell *shell)
 {
   g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
diff --git a/app/display/gimpdisplayshell-expose.h b/app/display/gimpdisplayshell-expose.h
index 110a865..44b7368 100644
--- a/app/display/gimpdisplayshell-expose.h
+++ b/app/display/gimpdisplayshell-expose.h
@@ -28,6 +28,8 @@ void        gimp_display_shell_expose_guide        (GimpDisplayShell   *shell,
                                                     GimpGuide          *guide);
 void        gimp_display_shell_expose_sample_point (GimpDisplayShell   *shell,
                                                     GimpSamplePoint    *sample_point);
+void        gimp_display_shell_expose_vectors      (GimpDisplayShell   *shell,
+                                                    GimpVectors        *vectors);
 void        gimp_display_shell_expose_full         (GimpDisplayShell   *shell);
 
 
diff --git a/app/display/gimpdisplayshell-handlers.c b/app/display/gimpdisplayshell-handlers.c
index b919849..9e03122 100644
--- a/app/display/gimpdisplayshell-handlers.c
+++ b/app/display/gimpdisplayshell-handlers.c
@@ -607,24 +607,22 @@ static void
 gimp_display_shell_vectors_freeze_handler (GimpVectors      *vectors,
                                            GimpDisplayShell *shell)
 {
-  if (shell->paused_count == 0 && gimp_item_get_visible (GIMP_ITEM (vectors)))
-    gimp_display_shell_draw_vector (shell, vectors);
+  /* do nothing */
 }
 
 static void
 gimp_display_shell_vectors_thaw_handler (GimpVectors      *vectors,
                                          GimpDisplayShell *shell)
 {
-  if (shell->paused_count == 0 && gimp_item_get_visible (GIMP_ITEM (vectors)))
-    gimp_display_shell_draw_vector (shell, vectors);
+  if (gimp_item_get_visible (GIMP_ITEM (vectors)))
+    gimp_display_shell_expose_vectors (shell, vectors);
 }
 
 static void
 gimp_display_shell_vectors_visible_handler (GimpVectors      *vectors,
                                             GimpDisplayShell *shell)
 {
-  if (shell->paused_count == 0)
-    gimp_display_shell_draw_vector (shell, vectors);
+  gimp_display_shell_expose_vectors (shell, vectors);
 }
 
 static void
@@ -632,8 +630,8 @@ gimp_display_shell_vectors_add_handler (GimpContainer    *container,
                                         GimpVectors      *vectors,
                                         GimpDisplayShell *shell)
 {
-  if (shell->paused_count == 0 && gimp_item_get_visible (GIMP_ITEM (vectors)))
-    gimp_display_shell_draw_vector (shell, vectors);
+  if (gimp_item_get_visible (GIMP_ITEM (vectors)))
+    gimp_display_shell_expose_vectors (shell, vectors);
 }
 
 static void
@@ -641,8 +639,8 @@ gimp_display_shell_vectors_remove_handler (GimpContainer    *container,
                                            GimpVectors      *vectors,
                                            GimpDisplayShell *shell)
 {
-  if (shell->paused_count == 0 && gimp_item_get_visible (GIMP_ITEM (vectors)))
-    gimp_display_shell_draw_vector (shell, vectors);
+  if (gimp_item_get_visible (GIMP_ITEM (vectors)))
+    gimp_display_shell_expose_vectors (shell, vectors);
 }
 
 static void
diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c
index d8a3870..5b3c469 100644
--- a/app/display/gimpdisplayshell.c
+++ b/app/display/gimpdisplayshell.c
@@ -1698,8 +1698,6 @@ gimp_display_shell_pause (GimpDisplayShell *shell)
       tool_manager_control_active (shell->display->gimp,
                                    GIMP_TOOL_ACTION_PAUSE,
                                    shell->display);
-
-      gimp_display_shell_draw_vectors (shell);
     }
 }
 
@@ -1722,8 +1720,6 @@ gimp_display_shell_resume (GimpDisplayShell *shell)
 
   if (shell->paused_count == 0)
     {
-      gimp_display_shell_draw_vectors (shell);
-
       /* start the currently active tool */
       tool_manager_control_active (shell->display->gimp,
                                    GIMP_TOOL_ACTION_RESUME,



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