[gimp] Bug 314379 - Allow stroking as outline (not with a paint tool) via the PDB



commit 8fa7bc3622c67313e97664eea87abc696fd4a5ce
Author: Michael Natterer <mitch gimp org>
Date:   Mon Nov 9 01:46:07 2015 +0100

    Bug 314379 - Allow stroking as outline (not with a paint tool) via the PDB
    
    Add new PDB procedures gimp-context-get/set-stroke-method and honor
    the new setting in gimp-edit-stroke and gimp-edit-stroke-vectors.
    
    Internally, keep a GimpStrokeOptions around in GimpPDBContext to keep
    track of the newly added PDB state, and use it for the stroke
    operations instead of creating a scratch GimpStrokeOptions.

 app/pdb/context-cmds.c       |   99 ++++++++++++++++++++++++++++++++++++++++++
 app/pdb/edit-cmds.c          |   14 +-----
 app/pdb/gimppdbcontext.c     |   29 ++++++++++++
 app/pdb/gimppdbcontext.h     |   17 ++++---
 app/pdb/internal-procs.c     |    2 +-
 libgimp/gimp.def             |    2 +
 libgimp/gimpcontext_pdb.c    |   63 ++++++++++++++++++++++++++
 libgimp/gimpcontext_pdb.h    |    2 +
 tools/pdbgen/pdb/context.pdb |   58 ++++++++++++++++++++++++
 tools/pdbgen/pdb/edit.pdb    |   14 +-----
 10 files changed, 270 insertions(+), 30 deletions(-)
---
diff --git a/app/pdb/context-cmds.c b/app/pdb/context-cmds.c
index a850ba4..17245cc 100644
--- a/app/pdb/context-cmds.c
+++ b/app/pdb/context-cmds.c
@@ -180,6 +180,57 @@ context_set_paint_method_invoker (GimpProcedure         *procedure,
 }
 
 static GimpValueArray *
+context_get_stroke_method_invoker (GimpProcedure         *procedure,
+                                   Gimp                  *gimp,
+                                   GimpContext           *context,
+                                   GimpProgress          *progress,
+                                   const GimpValueArray  *args,
+                                   GError               **error)
+{
+  GimpValueArray *return_vals;
+  gint32 stroke_method = 0;
+
+  GimpStrokeOptions *options =
+    gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context));
+
+  g_object_get (options,
+                "method", &stroke_method,
+                NULL);
+
+  return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL);
+  g_value_set_enum (gimp_value_array_index (return_vals, 1), stroke_method);
+
+  return return_vals;
+}
+
+static GimpValueArray *
+context_set_stroke_method_invoker (GimpProcedure         *procedure,
+                                   Gimp                  *gimp,
+                                   GimpContext           *context,
+                                   GimpProgress          *progress,
+                                   const GimpValueArray  *args,
+                                   GError               **error)
+{
+  gboolean success = TRUE;
+  gint32 stroke_method;
+
+  stroke_method = g_value_get_enum (gimp_value_array_index (args, 0));
+
+  if (success)
+    {
+      GimpStrokeOptions *options =
+        gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context));
+
+      g_object_set (options,
+                    "method", stroke_method,
+                    NULL);
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
+static GimpValueArray *
 context_get_foreground_invoker (GimpProcedure         *procedure,
                                 Gimp                  *gimp,
                                 GimpContext           *context,
@@ -2373,6 +2424,54 @@ register_context_procs (GimpPDB *pdb)
   g_object_unref (procedure);
 
   /*
+   * gimp-context-get-stroke-method
+   */
+  procedure = gimp_procedure_new (context_get_stroke_method_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-context-get-stroke-method");
+  gimp_procedure_set_static_strings (procedure,
+                                     "gimp-context-get-stroke-method",
+                                     "Retrieve the currently active stroke method.",
+                                     "This procedure returns the currently active stroke method.",
+                                     "Michael Natterer <mitch gimp org>",
+                                     "Michael Natterer",
+                                     "2015",
+                                     NULL);
+  gimp_procedure_add_return_value (procedure,
+                                   g_param_spec_enum ("stroke-method",
+                                                      "stroke method",
+                                                      "The active stroke method",
+                                                      GIMP_TYPE_STROKE_METHOD,
+                                                      GIMP_STROKE_LINE,
+                                                      GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
+   * gimp-context-set-stroke-method
+   */
+  procedure = gimp_procedure_new (context_set_stroke_method_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-context-set-stroke-method");
+  gimp_procedure_set_static_strings (procedure,
+                                     "gimp-context-set-stroke-method",
+                                     "Set the specified stroke method as the active stroke method.",
+                                     "This procedure set the specified stroke method as the active stroke 
method. The new method will be used in all subsequent stroke operations.",
+                                     "Michael Natterer <mitch gimp org>",
+                                     "Michael Natterer",
+                                     "2015",
+                                     NULL);
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_enum ("stroke-method",
+                                                  "stroke method",
+                                                  "The new stroke method",
+                                                  GIMP_TYPE_STROKE_METHOD,
+                                                  GIMP_STROKE_LINE,
+                                                  GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
    * gimp-context-get-foreground
    */
   procedure = gimp_procedure_new (context_get_foreground_invoker);
diff --git a/app/pdb/edit-cmds.c b/app/pdb/edit-cmds.c
index 990716b..bd69bc0 100644
--- a/app/pdb/edit-cmds.c
+++ b/app/pdb/edit-cmds.c
@@ -861,13 +861,10 @@ edit_stroke_invoker (GimpProcedure         *procedure,
           gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
         {
           GimpImage         *image = gimp_item_get_image (GIMP_ITEM (drawable));
-          GimpStrokeOptions *options = gimp_stroke_options_new (gimp, context, TRUE);
+          GimpStrokeOptions *options;
           GimpPaintOptions  *paint_options;
 
-          options = gimp_stroke_options_new (gimp, context, TRUE);
-          g_object_set (options,
-                        "method", GIMP_STROKE_PAINT_METHOD,
-                        NULL);
+          options = gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context));
 
           paint_options =
             gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context), NULL);
@@ -877,7 +874,6 @@ edit_stroke_invoker (GimpProcedure         *procedure,
                                       drawable, context, options, paint_options,
                                       TRUE, progress, error);
 
-          g_object_unref (options);
           g_object_unref (paint_options);
         }
       else
@@ -915,10 +911,7 @@ edit_stroke_vectors_invoker (GimpProcedure         *procedure,
           GimpStrokeOptions *options;
           GimpPaintOptions  *paint_options;
 
-          options = gimp_stroke_options_new (gimp, context, TRUE);
-          g_object_set (options,
-                        "method", GIMP_STROKE_PAINT_METHOD,
-                        NULL);
+          options = gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context));
 
           paint_options =
             gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context), NULL);
@@ -928,7 +921,6 @@ edit_stroke_vectors_invoker (GimpProcedure         *procedure,
                                       drawable, context, options, paint_options,
                                       TRUE, progress, error);
 
-          g_object_unref (options);
           g_object_unref (paint_options);
         }
       else
diff --git a/app/pdb/gimppdbcontext.c b/app/pdb/gimppdbcontext.c
index b5257a8..d8967c0 100644
--- a/app/pdb/gimppdbcontext.c
+++ b/app/pdb/gimppdbcontext.c
@@ -31,6 +31,7 @@
 #include "core/gimp.h"
 #include "core/gimplist.h"
 #include "core/gimppaintinfo.h"
+#include "core/gimpstrokeoptions.h"
 
 #include "paint/gimpbrushcore.h"
 #include "paint/gimppaintoptions.h"
@@ -155,12 +156,26 @@ gimp_pdb_context_init (GimpPDBContext *context)
 static void
 gimp_pdb_context_constructed (GObject *object)
 {
+  GimpPDBContext        *context = GIMP_PDB_CONTEXT (object);
   GimpInterpolationType  interpolation;
   gint                   threshold;
   GParamSpec            *pspec;
 
   G_OBJECT_CLASS (parent_class)->constructed (object);
 
+  context->stroke_options = gimp_stroke_options_new (GIMP_CONTEXT (context)->gimp,
+                                                     GIMP_CONTEXT (context),
+                                                     TRUE);
+
+  /* preserve the traditional PDB default */
+  g_object_set (context->stroke_options,
+                "method", GIMP_STROKE_PAINT_METHOD,
+                NULL);
+
+  g_object_bind_property (G_OBJECT (context),                 "antialias",
+                          G_OBJECT (context->stroke_options), "antialias",
+                          G_BINDING_SYNC_CREATE);
+
   /* get default interpolation from gimprc */
 
   interpolation = GIMP_CONTEXT (object)->gimp->config->interpolation_type;
@@ -197,6 +212,12 @@ gimp_pdb_context_finalize (GObject *object)
       context->paint_options_list = NULL;
     }
 
+  if (context->stroke_options)
+    {
+      g_object_unref (context->stroke_options);
+      context->stroke_options = NULL;
+    }
+
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
@@ -404,3 +425,11 @@ gimp_pdb_context_get_brush_options (GimpPDBContext *context)
 
   return g_list_reverse (brush_options);
 }
+
+GimpStrokeOptions *
+gimp_pdb_context_get_stroke_options (GimpPDBContext *context)
+{
+  g_return_val_if_fail (GIMP_IS_PDB_CONTEXT (context), NULL);
+
+  return context->stroke_options;
+}
diff --git a/app/pdb/gimppdbcontext.h b/app/pdb/gimppdbcontext.h
index c9d6908..1607f8d 100644
--- a/app/pdb/gimppdbcontext.h
+++ b/app/pdb/gimppdbcontext.h
@@ -53,6 +53,7 @@ struct _GimpPDBContext
   GimpTransformResize     transform_resize;
 
   GimpContainer          *paint_options_list;
+  GimpStrokeOptions      *stroke_options;
 };
 
 struct _GimpPDBContextClass
@@ -61,15 +62,17 @@ struct _GimpPDBContextClass
 };
 
 
-GType              gimp_pdb_context_get_type          (void) G_GNUC_CONST;
+GType               gimp_pdb_context_get_type           (void) G_GNUC_CONST;
 
-GimpContext      * gimp_pdb_context_new               (Gimp           *gimp,
-                                                       GimpContext    *parent,
-                                                       gboolean        set_parent);
+GimpContext       * gimp_pdb_context_new                (Gimp           *gimp,
+                                                         GimpContext    *parent,
+                                                         gboolean        set_parent);
 
-GimpPaintOptions * gimp_pdb_context_get_paint_options (GimpPDBContext *context,
-                                                       const gchar    *name);
-GList            * gimp_pdb_context_get_brush_options (GimpPDBContext *context);
+GimpPaintOptions  * gimp_pdb_context_get_paint_options  (GimpPDBContext *context,
+                                                         const gchar    *name);
+GList             * gimp_pdb_context_get_brush_options  (GimpPDBContext *context);
+
+GimpStrokeOptions * gimp_pdb_context_get_stroke_options (GimpPDBContext *context);
 
 
 #endif  /*  __GIMP_PDB_CONTEXT_H__  */
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index 4ab48f8..0989bdc 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
 #include "internal-procs.h"
 
 
-/* 773 procedures registered total */
+/* 775 procedures registered total */
 
 void
 internal_procs_init (GimpPDB *pdb)
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index 6a4ffdf..470acbb 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -102,6 +102,7 @@ EXPORTS
        gimp_context_get_sample_threshold
        gimp_context_get_sample_threshold_int
        gimp_context_get_sample_transparent
+       gimp_context_get_stroke_method
        gimp_context_get_transform_direction
        gimp_context_get_transform_recursion
        gimp_context_get_transform_resize
@@ -147,6 +148,7 @@ EXPORTS
        gimp_context_set_sample_threshold
        gimp_context_set_sample_threshold_int
        gimp_context_set_sample_transparent
+       gimp_context_set_stroke_method
        gimp_context_set_transform_direction
        gimp_context_set_transform_recursion
        gimp_context_set_transform_resize
diff --git a/libgimp/gimpcontext_pdb.c b/libgimp/gimpcontext_pdb.c
index 4254701..e437b0d 100644
--- a/libgimp/gimpcontext_pdb.c
+++ b/libgimp/gimpcontext_pdb.c
@@ -246,6 +246,69 @@ gimp_context_set_paint_method (const gchar *name)
 }
 
 /**
+ * gimp_context_get_stroke_method:
+ *
+ * Retrieve the currently active stroke method.
+ *
+ * This procedure returns the currently active stroke method.
+ *
+ * Returns: The active stroke method.
+ *
+ * Since: 2.10
+ **/
+GimpStrokeMethod
+gimp_context_get_stroke_method (void)
+{
+  GimpParam *return_vals;
+  gint nreturn_vals;
+  GimpStrokeMethod stroke_method = 0;
+
+  return_vals = gimp_run_procedure ("gimp-context-get-stroke-method",
+                                    &nreturn_vals,
+                                    GIMP_PDB_END);
+
+  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
+    stroke_method = return_vals[1].data.d_int32;
+
+  gimp_destroy_params (return_vals, nreturn_vals);
+
+  return stroke_method;
+}
+
+/**
+ * gimp_context_set_stroke_method:
+ * @stroke_method: The new stroke method.
+ *
+ * Set the specified stroke method as the active stroke method.
+ *
+ * This procedure set the specified stroke method as the active stroke
+ * method. The new method will be used in all subsequent stroke
+ * operations.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: 2.10
+ **/
+gboolean
+gimp_context_set_stroke_method (GimpStrokeMethod stroke_method)
+{
+  GimpParam *return_vals;
+  gint nreturn_vals;
+  gboolean success = TRUE;
+
+  return_vals = gimp_run_procedure ("gimp-context-set-stroke-method",
+                                    &nreturn_vals,
+                                    GIMP_PDB_INT32, stroke_method,
+                                    GIMP_PDB_END);
+
+  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
+
+  gimp_destroy_params (return_vals, nreturn_vals);
+
+  return success;
+}
+
+/**
  * gimp_context_get_foreground:
  * @foreground: The foreground color.
  *
diff --git a/libgimp/gimpcontext_pdb.h b/libgimp/gimpcontext_pdb.h
index 58960c3..6525214 100644
--- a/libgimp/gimpcontext_pdb.h
+++ b/libgimp/gimpcontext_pdb.h
@@ -39,6 +39,8 @@ gboolean               gimp_context_list_paint_methods         (gint
                                                                 gchar                  ***paint_methods);
 gchar*                 gimp_context_get_paint_method           (void);
 gboolean               gimp_context_set_paint_method           (const gchar              *name);
+GimpStrokeMethod       gimp_context_get_stroke_method          (void);
+gboolean               gimp_context_set_stroke_method          (GimpStrokeMethod          stroke_method);
 gboolean               gimp_context_get_foreground             (GimpRGB                  *foreground);
 gboolean               gimp_context_set_foreground             (const GimpRGB            *foreground);
 gboolean               gimp_context_get_background             (GimpRGB                  *background);
diff --git a/tools/pdbgen/pdb/context.pdb b/tools/pdbgen/pdb/context.pdb
index 80a8385..29b4e09 100644
--- a/tools/pdbgen/pdb/context.pdb
+++ b/tools/pdbgen/pdb/context.pdb
@@ -184,6 +184,63 @@ CODE
     );
 }
 
+sub context_get_stroke_method {
+    $blurb = 'Retrieve the currently active stroke method.';
+
+    $help = <<'HELP';
+This procedure returns the currently active stroke method.
+HELP
+
+    &mitch_pdb_misc('2015', '2.10');
+
+    @outargs = (
+       { name  => 'stroke_method', type  => 'enum GimpStrokeMethod',
+         desc  => 'The active stroke method' }
+    );
+
+    %invoke = (
+       code => <<'CODE'
+{
+  GimpStrokeOptions *options =
+    gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context));
+
+  g_object_get (options,
+                "method", &stroke_method,
+               NULL);
+}
+CODE
+    );
+}
+
+sub context_set_stroke_method {
+    $blurb = 'Set the specified stroke method as the active stroke method.';
+
+    $help = <<'HELP';
+This procedure set the specified stroke method as the active stroke
+method. The new method will be used in all subsequent stroke
+operations.
+HELP
+
+    &mitch_pdb_misc('2015', '2.10');
+
+    @inargs = (
+        { name => 'stroke_method', type => 'enum GimpStrokeMethod',
+          desc => 'The new stroke method' }
+    );
+
+    %invoke = (
+       code => <<'CODE'
+{
+  GimpStrokeOptions *options =
+    gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context));
+
+  g_object_set (options,
+                "method", stroke_method,
+               NULL);
+}
+CODE
+    );
+}
 
 sub context_get_foreground {
     $blurb = "Get the current GIMP foreground color.";
@@ -2430,6 +2487,7 @@ CODE
 @procs = qw(context_push context_pop context_set_defaults
             context_list_paint_methods
             context_get_paint_method context_set_paint_method
+            context_get_stroke_method context_set_stroke_method
             context_get_foreground context_set_foreground
             context_get_background context_set_background
             context_set_default_colors
diff --git a/tools/pdbgen/pdb/edit.pdb b/tools/pdbgen/pdb/edit.pdb
index 77d07d8..164f5e9 100644
--- a/tools/pdbgen/pdb/edit.pdb
+++ b/tools/pdbgen/pdb/edit.pdb
@@ -938,13 +938,10 @@ HELP
       gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
     {
       GimpImage         *image = gimp_item_get_image (GIMP_ITEM (drawable));
-      GimpStrokeOptions *options = gimp_stroke_options_new (gimp, context, TRUE);
+      GimpStrokeOptions *options;
       GimpPaintOptions  *paint_options;
 
-      options = gimp_stroke_options_new (gimp, context, TRUE);
-      g_object_set (options,
-                    "method", GIMP_STROKE_PAINT_METHOD,
-                    NULL);
+      options = gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context));
 
       paint_options =
         gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context), NULL);
@@ -954,7 +951,6 @@ HELP
                                   drawable, context, options, paint_options,
                                   TRUE, progress, error);
 
-      g_object_unref (options);
       g_object_unref (paint_options);
     }
   else
@@ -995,10 +991,7 @@ HELP
       GimpStrokeOptions *options;
       GimpPaintOptions  *paint_options;
 
-      options = gimp_stroke_options_new (gimp, context, TRUE);
-      g_object_set (options,
-                    "method", GIMP_STROKE_PAINT_METHOD,
-                    NULL);
+      options = gimp_pdb_context_get_stroke_options (GIMP_PDB_CONTEXT (context));
 
       paint_options =
         gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context), NULL);
@@ -1008,7 +1001,6 @@ HELP
                                   drawable, context, options, paint_options,
                                   TRUE, progress, error);
 
-      g_object_unref (options);
       g_object_unref (paint_options);
     }
   else


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