[gimp/gimp-2-8] Bug 721249 - pdb.gimp_context_set_brush_size() dont't work



commit c15d7bcc8083533fa360c49eafcb48aeb119ce38
Author: Michael Natterer <mitch gimp org>
Date:   Thu Feb 6 23:20:39 2014 +0100

    Bug 721249 - pdb.gimp_context_set_brush_size() dont't work
    
    Port selection/path stroking to using the PDB-controllable
    paint options that live in GimpPDBContext.
    
    Change gimp_item_stroke()'s "use_default_values" boolean which was
    introduced at a time where we had no better way by a GimpPaintOptions
    parameter. If a non-NULL paint_options is passed (when called from the
    PDB), use it for stroking; if NULL is passed, use the actual paint
    tool options from the GUI (when called from the menus or the stroke
    dialog). In the PDB wrappers, get the right paint options object from
    the PDB context associated with the calling plug-in.
    
    (cherry picked from commit 4d6640ff79ff13ae6d031da477a21c85119b2f15)

 app/actions/select-commands.c  |    3 ++-
 app/actions/vectors-commands.c |    3 ++-
 app/core/gimpitem.c            |    8 ++++++--
 app/core/gimpitem.h            |    2 +-
 app/core/gimpstrokeoptions.c   |   14 ++++++--------
 app/core/gimpstrokeoptions.h   |    2 +-
 app/dialogs/stroke-dialog.c    |    4 ++--
 app/pdb/edit-cmds.c            |   29 +++++++++++++++++++++++------
 app/pdb/gimppdbcontext.c       |    4 +++-
 app/pdb/paths-cmds.c           |   15 ++++++++++++---
 tools/pdbgen/pdb/edit.pdb      |   28 ++++++++++++++++++++++------
 tools/pdbgen/pdb/paths.pdb     |   15 ++++++++++++---
 12 files changed, 92 insertions(+), 35 deletions(-)
---
diff --git a/app/actions/select-commands.c b/app/actions/select-commands.c
index 89e5012..7c13e7a 100644
--- a/app/actions/select-commands.c
+++ b/app/actions/select-commands.c
@@ -387,7 +387,8 @@ select_stroke_last_vals_cmd_callback (GtkAction *action,
     options = gimp_stroke_options_new (image->gimp, context, TRUE);
 
   if (! gimp_item_stroke (GIMP_ITEM (gimp_image_get_mask (image)),
-                          drawable, context, options, FALSE, TRUE, NULL, &error))
+                          drawable, context, options, NULL,
+                          TRUE, NULL, &error))
     {
       gimp_message_literal (image->gimp,
                            G_OBJECT (widget), GIMP_MESSAGE_WARNING,
diff --git a/app/actions/vectors-commands.c b/app/actions/vectors-commands.c
index 5a6c1b5..a0d4b61 100644
--- a/app/actions/vectors-commands.c
+++ b/app/actions/vectors-commands.c
@@ -429,7 +429,8 @@ vectors_stroke_last_vals_cmd_callback (GtkAction *action,
   else
     options = gimp_stroke_options_new (image->gimp, context, TRUE);
 
-  if (! gimp_item_stroke (GIMP_ITEM (vectors), drawable, context, options, FALSE,
+  if (! gimp_item_stroke (GIMP_ITEM (vectors),
+                          drawable, context, options, NULL,
                           TRUE, NULL, &error))
     {
       gimp_message_literal (image->gimp, G_OBJECT (widget),
diff --git a/app/core/gimpitem.c b/app/core/gimpitem.c
index 5e949f6..374e02f 100644
--- a/app/core/gimpitem.c
+++ b/app/core/gimpitem.c
@@ -43,6 +43,8 @@
 #include "gimpprogress.h"
 #include "gimpstrokeoptions.h"
 
+#include "paint/gimppaintoptions.h"
+
 #include "gimp-intl.h"
 
 
@@ -1475,7 +1477,7 @@ gimp_item_stroke (GimpItem          *item,
                   GimpDrawable      *drawable,
                   GimpContext       *context,
                   GimpStrokeOptions *stroke_options,
-                  gboolean           use_default_values,
+                  GimpPaintOptions  *paint_options,
                   gboolean           push_undo,
                   GimpProgress      *progress,
                   GError           **error)
@@ -1489,6 +1491,8 @@ gimp_item_stroke (GimpItem          *item,
   g_return_val_if_fail (gimp_item_is_attached (GIMP_ITEM (drawable)), FALSE);
   g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE);
   g_return_val_if_fail (GIMP_IS_STROKE_OPTIONS (stroke_options), FALSE);
+  g_return_val_if_fail (paint_options == NULL ||
+                        GIMP_IS_PAINT_OPTIONS (paint_options), FALSE);
   g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), FALSE);
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
@@ -1498,7 +1502,7 @@ gimp_item_stroke (GimpItem          *item,
     {
       GimpImage *image = gimp_item_get_image (item);
 
-      gimp_stroke_options_prepare (stroke_options, context, use_default_values);
+      gimp_stroke_options_prepare (stroke_options, context, paint_options);
 
       if (push_undo)
         gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_PAINT,
diff --git a/app/core/gimpitem.h b/app/core/gimpitem.h
index cc6f01b..23f2e96 100644
--- a/app/core/gimpitem.h
+++ b/app/core/gimpitem.h
@@ -240,7 +240,7 @@ gboolean        gimp_item_stroke             (GimpItem           *item,
                                               GimpDrawable       *drawable,
                                               GimpContext        *context,
                                               GimpStrokeOptions  *stroke_options,
-                                              gboolean            use_default_values,
+                                              GimpPaintOptions   *paint_options,
                                               gboolean            push_undo,
                                               GimpProgress       *progress,
                                               GError            **error);
diff --git a/app/core/gimpstrokeoptions.c b/app/core/gimpstrokeoptions.c
index 9505398..e2e5f1d 100644
--- a/app/core/gimpstrokeoptions.c
+++ b/app/core/gimpstrokeoptions.c
@@ -544,12 +544,14 @@ gimp_stroke_options_take_dash_pattern (GimpStrokeOptions *options,
 void
 gimp_stroke_options_prepare (GimpStrokeOptions *options,
                              GimpContext       *context,
-                             gboolean           use_default_values)
+                             GimpPaintOptions  *paint_options)
 {
   GimpStrokeOptionsPrivate *private;
 
   g_return_if_fail (GIMP_IS_STROKE_OPTIONS (options));
   g_return_if_fail (GIMP_IS_CONTEXT (context));
+  g_return_if_fail (paint_options == NULL ||
+                    GIMP_IS_PAINT_OPTIONS (paint_options));
 
   private = GET_PRIVATE (options);
 
@@ -560,15 +562,11 @@ gimp_stroke_options_prepare (GimpStrokeOptions *options,
 
     case GIMP_STROKE_METHOD_PAINT_CORE:
       {
-        GimpPaintInfo    *paint_info = GIMP_CONTEXT (options)->paint_info;
-        GimpPaintOptions *paint_options;
+        GimpPaintInfo *paint_info = GIMP_CONTEXT (options)->paint_info;
 
-        if (use_default_values)
+        if (paint_options)
           {
-            paint_options = gimp_paint_options_new (paint_info);
-
-            gimp_paint_options_set_default_brush_size (paint_options,
-                                                       gimp_context_get_brush (context));
+            g_return_if_fail (paint_info == paint_options->paint_info);
 
             /*  undefine the paint-relevant context properties and get them
              *  from the passed context
diff --git a/app/core/gimpstrokeoptions.h b/app/core/gimpstrokeoptions.h
index f7737a5..5f125a5 100644
--- a/app/core/gimpstrokeoptions.h
+++ b/app/core/gimpstrokeoptions.h
@@ -74,7 +74,7 @@ void                gimp_stroke_options_take_dash_pattern    (GimpStrokeOptions
 
 void                gimp_stroke_options_prepare              (GimpStrokeOptions *options,
                                                               GimpContext       *context,
-                                                              gboolean           use_default_values);
+                                                              GimpPaintOptions  *paint_options);
 void                gimp_stroke_options_finish               (GimpStrokeOptions *options);
 
 
diff --git a/app/dialogs/stroke-dialog.c b/app/dialogs/stroke-dialog.c
index 118f1f2..eb361a4 100644
--- a/app/dialogs/stroke-dialog.c
+++ b/app/dialogs/stroke-dialog.c
@@ -297,8 +297,8 @@ stroke_dialog_response (GtkWidget  *widget,
                                 saved_options,
                                 (GDestroyNotify) g_object_unref);
 
-        if (! gimp_item_stroke (item, drawable, context, options, FALSE, TRUE,
-                                NULL, &error))
+        if (! gimp_item_stroke (item, drawable, context, options, NULL,
+                                TRUE, NULL, &error))
           {
             gimp_message_literal (context->gimp,
                                   G_OBJECT (widget),
diff --git a/app/pdb/edit-cmds.c b/app/pdb/edit-cmds.c
index 95746eb..d2e5ac7 100644
--- a/app/pdb/edit-cmds.c
+++ b/app/pdb/edit-cmds.c
@@ -23,6 +23,8 @@
 
 #include <gegl.h>
 
+#include "libgimpconfig/gimpconfig.h"
+
 #include "pdb-types.h"
 
 #include "core/gimp-edit.h"
@@ -41,6 +43,7 @@
 
 #include "gimppdb.h"
 #include "gimppdb-utils.h"
+#include "gimppdbcontext.h"
 #include "gimpprocedure.h"
 #include "internal-procs.h"
 
@@ -763,18 +766,25 @@ edit_stroke_invoker (GimpProcedure      *procedure,
       if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error) &&
           gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
         {
-          GimpImage         *image   = gimp_item_get_image (GIMP_ITEM (drawable));
+          GimpImage         *image = gimp_item_get_image (GIMP_ITEM (drawable));
           GimpStrokeOptions *options = gimp_stroke_options_new (gimp, context, TRUE);
+          GimpPaintOptions  *paint_options;
 
+          options = gimp_stroke_options_new (gimp, context, TRUE);
           g_object_set (options,
                         "method", GIMP_STROKE_METHOD_PAINT_CORE,
                         NULL);
 
+          paint_options =
+            gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context), NULL);
+          paint_options = gimp_config_duplicate (GIMP_CONFIG (paint_options));
+
           success = gimp_item_stroke (GIMP_ITEM (gimp_image_get_mask (image)),
-                                      drawable, context, options, TRUE, TRUE,
-                                      progress, error);
+                                      drawable, context, options, paint_options,
+                                      TRUE, progress, error);
 
           g_object_unref (options);
+          g_object_unref (paint_options);
         }
       else
         success = FALSE;
@@ -806,17 +816,24 @@ edit_stroke_vectors_invoker (GimpProcedure      *procedure,
           gimp_pdb_item_is_attached (GIMP_ITEM (vectors),
                                      gimp_item_get_image (GIMP_ITEM (drawable)), FALSE, error))
         {
-          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_METHOD_PAINT_CORE,
                         NULL);
 
+          paint_options =
+            gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context), NULL);
+          paint_options = gimp_config_duplicate (GIMP_CONFIG (paint_options));
+
           success = gimp_item_stroke (GIMP_ITEM (vectors),
-                                      drawable, context, options, TRUE, TRUE,
-                                      progress, error);
+                                      drawable, context, options, paint_options,
+                                      TRUE, progress, error);
 
           g_object_unref (options);
+          g_object_unref (paint_options);
         }
       else
         success = FALSE;
diff --git a/app/pdb/gimppdbcontext.c b/app/pdb/gimppdbcontext.c
index 9b848ec..d609dd7 100644
--- a/app/pdb/gimppdbcontext.c
+++ b/app/pdb/gimppdbcontext.c
@@ -390,7 +390,9 @@ gimp_pdb_context_get_paint_options (GimpPDBContext *context,
                                     const gchar    *name)
 {
   g_return_val_if_fail (GIMP_IS_PDB_CONTEXT (context), NULL);
-  g_return_val_if_fail (name != NULL, NULL);
+
+  if (! name)
+    name = gimp_object_get_name (gimp_context_get_paint_info (GIMP_CONTEXT (context)));
 
   return (GimpPaintOptions *)
     gimp_container_get_child_by_name (context->paint_options_list, name);
diff --git a/app/pdb/paths-cmds.c b/app/pdb/paths-cmds.c
index 56292ab..74aba4a 100644
--- a/app/pdb/paths-cmds.c
+++ b/app/pdb/paths-cmds.c
@@ -23,6 +23,7 @@
 
 #include <gegl.h>
 
+#include "libgimpconfig/gimpconfig.h"
 #include "libgimpmath/gimpmath.h"
 
 #include "pdb-types.h"
@@ -39,6 +40,7 @@
 
 #include "gimppdb.h"
 #include "gimppdb-utils.h"
+#include "gimppdbcontext.h"
 #include "gimpprocedure.h"
 #include "internal-procs.h"
 
@@ -333,17 +335,24 @@ path_stroke_current_invoker (GimpProcedure      *procedure,
           gimp_pdb_item_is_writable (GIMP_ITEM (drawable), error) &&
           gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
         {
-          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_METHOD_PAINT_CORE,
                         NULL);
 
+          paint_options =
+            gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context), NULL);
+          paint_options = gimp_config_duplicate (GIMP_CONFIG (paint_options));
+
           success = gimp_item_stroke (GIMP_ITEM (vectors),
-                                      drawable, context, options, TRUE, TRUE,
-                                      progress, error);
+                                      drawable, context, options, paint_options,
+                                      TRUE, progress, error);
 
           g_object_unref (options);
+          g_object_unref (paint_options);
         }
       else
         success = FALSE;
diff --git a/tools/pdbgen/pdb/edit.pdb b/tools/pdbgen/pdb/edit.pdb
index 1bfd0f3..f598280 100644
--- a/tools/pdbgen/pdb/edit.pdb
+++ b/tools/pdbgen/pdb/edit.pdb
@@ -848,18 +848,25 @@ HELP
   if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, TRUE, error) &&
       gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
     {
-      GimpImage         *image   = gimp_item_get_image (GIMP_ITEM (drawable));
+      GimpImage         *image = gimp_item_get_image (GIMP_ITEM (drawable));
       GimpStrokeOptions *options = gimp_stroke_options_new (gimp, context, TRUE);
+      GimpPaintOptions  *paint_options;
 
+      options = gimp_stroke_options_new (gimp, context, TRUE);
       g_object_set (options,
                     "method", GIMP_STROKE_METHOD_PAINT_CORE,
                     NULL);
 
+      paint_options =
+        gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context), NULL);
+      paint_options = gimp_config_duplicate (GIMP_CONFIG (paint_options));
+
       success = gimp_item_stroke (GIMP_ITEM (gimp_image_get_mask (image)),
-                                  drawable, context, options, TRUE, TRUE,
-                                  progress, error);
+                                  drawable, context, options, paint_options,
+                                  TRUE, progress, error);
 
       g_object_unref (options);
+      g_object_unref (paint_options);
     }
   else
     success = FALSE;
@@ -894,17 +901,24 @@ HELP
       gimp_pdb_item_is_attached (GIMP_ITEM (vectors),
                                  gimp_item_get_image (GIMP_ITEM (drawable)), FALSE, error))
     {
-      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_METHOD_PAINT_CORE,
                     NULL);
 
+      paint_options =
+        gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context), NULL);
+      paint_options = gimp_config_duplicate (GIMP_CONFIG (paint_options));
+
       success = gimp_item_stroke (GIMP_ITEM (vectors),
-                                  drawable, context, options, TRUE, TRUE,
-                                  progress, error);
+                                  drawable, context, options, paint_options,
+                                  TRUE, progress, error);
 
       g_object_unref (options);
+      g_object_unref (paint_options);
     }
   else
     success = FALSE;
@@ -915,12 +929,14 @@ CODE
 
 
 @headers = qw(<string.h>
+              "libgimpconfig/gimpconfig.h"
               "core/gimp.h"
               "core/gimp-edit.h"
               "core/gimpimage.h"
               "core/gimpimage-new.h"
               "core/gimpprogress.h"
               "gimppdb-utils.h"
+              "gimppdbcontext.h"
               "gimp-intl.h");
 
 @procs = qw(edit_cut
diff --git a/tools/pdbgen/pdb/paths.pdb b/tools/pdbgen/pdb/paths.pdb
index f8e08d6..6c164df 100644
--- a/tools/pdbgen/pdb/paths.pdb
+++ b/tools/pdbgen/pdb/paths.pdb
@@ -270,17 +270,24 @@ sub path_stroke_current {
       gimp_pdb_item_is_writable (GIMP_ITEM (drawable), error) &&
       gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
     {
-      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_METHOD_PAINT_CORE,
                     NULL);
 
+      paint_options =
+        gimp_pdb_context_get_paint_options (GIMP_PDB_CONTEXT (context), NULL);
+      paint_options = gimp_config_duplicate (GIMP_CONFIG (paint_options));
+
       success = gimp_item_stroke (GIMP_ITEM (vectors),
-                                  drawable, context, options, TRUE, TRUE,
-                                  progress, error);
+                                  drawable, context, options, paint_options,
+                                  TRUE, progress, error);
 
       g_object_unref (options);
+      g_object_unref (paint_options);
     }
   else
     success = FALSE;
@@ -596,6 +603,7 @@ CODE
 
 
 @headers = qw(<string.h>
+              "libgimpconfig/gimpconfig.h"
               "libgimpmath/gimpmath.h"
               "core/gimplist.h"
               "vectors/gimpanchor.h"
@@ -603,6 +611,7 @@ CODE
               "vectors/gimpvectors.h"
               "vectors/gimpvectors-compat.h"
               "gimppdb-utils.h"
+              "gimppdbcontext.h"
               "gimp-intl.h");
 
 @procs = qw(path_list path_get_current path_set_current path_delete


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