[gimp/gimp-2-8] app: add gimp_paint_options_set_default_brush_size()



commit b4477d8e01e4b03121a9b834d35b69d0d8374638
Author: Michael Natterer <mitch gimp org>
Date:   Sat Jan 4 15:45:25 2014 +0100

    app: add gimp_paint_options_set_default_brush_size()
    
    and use it globally instead of two different methods, one of which was
    forgotten to be ported to the new aspect ratio range where 0.0 means
    1:1. Add a FIXME comment in paint_tools.pdb where I think setting the
    default size is a bug, see #721249.
    
    (cherry picked from commit ef858453724f6d4ca105fc9daec038fdff358f30)

 app/core/gimpstrokeoptions.c     |   19 ++-----------------
 app/paint/gimppaintoptions.c     |   24 ++++++++++++++++++++++++
 app/paint/gimppaintoptions.h     |    3 +++
 app/pdb/context-cmds.c           |    8 ++------
 app/pdb/paint-tools-cmds.c       |   14 +++-----------
 app/tools/gimppaintoptions-gui.c |   10 +---------
 tools/pdbgen/pdb/context.pdb     |   10 +++-------
 tools/pdbgen/pdb/paint_tools.pdb |   14 +++-----------
 8 files changed, 41 insertions(+), 61 deletions(-)
---
diff --git a/app/core/gimpstrokeoptions.c b/app/core/gimpstrokeoptions.c
index 832e99a..9505398 100644
--- a/app/core/gimpstrokeoptions.c
+++ b/app/core/gimpstrokeoptions.c
@@ -31,7 +31,6 @@
 #include "config/gimpcoreconfig.h"
 
 #include "gimp.h"
-#include "gimpbrush.h"
 #include "gimpcontext.h"
 #include "gimpdashpattern.h"
 #include "gimpmarshal.h"
@@ -566,24 +565,10 @@ gimp_stroke_options_prepare (GimpStrokeOptions *options,
 
         if (use_default_values)
           {
-            GimpBrush *brush;
-            gdouble    brush_size;
-            gint       height;
-            gint       width;
-
             paint_options = gimp_paint_options_new (paint_info);
 
-            brush = gimp_context_get_brush (context);
-
-            if (GIMP_IS_BRUSH (brush))
-              {
-                gimp_brush_transform_size (brush, 1.0, 1.0, 0.0, &height, &width);
-                brush_size = MAX (height, width);
-
-                g_object_set (paint_options,
-                              "brush-size", brush_size,
-                              NULL);
-              }
+            gimp_paint_options_set_default_brush_size (paint_options,
+                                                       gimp_context_get_brush (context));
 
             /*  undefine the paint-relevant context properties and get them
              *  from the passed context
diff --git a/app/paint/gimppaintoptions.c b/app/paint/gimppaintoptions.c
index 10430a2..a624f2d 100644
--- a/app/paint/gimppaintoptions.c
+++ b/app/paint/gimppaintoptions.c
@@ -26,6 +26,7 @@
 #include "paint-types.h"
 
 #include "core/gimp.h"
+#include "core/gimpbrush.h"
 #include "core/gimpimage.h"
 #include "core/gimpdynamics.h"
 #include "core/gimpdynamicsoutput.h"
@@ -715,6 +716,29 @@ gimp_paint_options_get_brush_mode (GimpPaintOptions *paint_options)
 }
 
 void
+gimp_paint_options_set_default_brush_size (GimpPaintOptions *paint_options,
+                                           GimpBrush        *brush)
+{
+  g_return_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options));
+  g_return_if_fail (brush == NULL || GIMP_IS_BRUSH (brush));
+
+  if (! brush)
+    brush = gimp_context_get_brush (GIMP_CONTEXT (paint_options));
+
+  if (brush)
+    {
+      gint height;
+      gint width;
+
+      gimp_brush_transform_size (brush, 1.0, 0.0, 0.0, &height, &width);
+
+      g_object_set (paint_options,
+                    "brush-size", (gdouble) MAX (height, width),
+                    NULL);
+    }
+}
+
+void
 gimp_paint_options_copy_brush_props (GimpPaintOptions *src,
                                      GimpPaintOptions *dest)
 {
diff --git a/app/paint/gimppaintoptions.h b/app/paint/gimppaintoptions.h
index 70c4e40..a5a84c9 100644
--- a/app/paint/gimppaintoptions.h
+++ b/app/paint/gimppaintoptions.h
@@ -132,6 +132,9 @@ gboolean gimp_paint_options_get_gradient_color (GimpPaintOptions *paint_options,
 GimpBrushApplicationMode
              gimp_paint_options_get_brush_mode (GimpPaintOptions *paint_options);
 
+void gimp_paint_options_set_default_brush_size (GimpPaintOptions *paint_options,
+                                                GimpBrush        *brush);
+
 void    gimp_paint_options_copy_brush_props    (GimpPaintOptions *src,
                                                 GimpPaintOptions *dest);
 void    gimp_paint_options_copy_dynamics_props (GimpPaintOptions *src,
diff --git a/app/pdb/context-cmds.c b/app/pdb/context-cmds.c
index bf4ab08..ac2fc64 100644
--- a/app/pdb/context-cmds.c
+++ b/app/pdb/context-cmds.c
@@ -28,12 +28,11 @@
 
 #include "pdb-types.h"
 
-#include "base/temp-buf.h"
 #include "core/gimp.h"
-#include "core/gimpbrush.h"
 #include "core/gimpcontainer.h"
 #include "core/gimpdatafactory.h"
 #include "core/gimpparamspecs.h"
+#include "paint/gimppaintoptions.h"
 #include "plug-in/gimpplugin-context.h"
 #include "plug-in/gimpplugin.h"
 #include "plug-in/gimppluginmanager.h"
@@ -509,10 +508,7 @@ context_set_brush_default_size_invoker (GimpProcedure      *procedure,
       options = gimp_pdb_context_get_brush_options (GIMP_PDB_CONTEXT (context));
 
       for (list = options; list; list = g_list_next (list))
-        g_object_set (list->data,
-                      "brush-size", (gdouble) MAX (brush->mask->width,
-                                                   brush->mask->height),
-                      NULL);
+        gimp_paint_options_set_default_brush_size (list->data, brush);
 
       g_list_free (options);
     }
diff --git a/app/pdb/paint-tools-cmds.c b/app/pdb/paint-tools-cmds.c
index 99faf15..d1d6de3 100644
--- a/app/pdb/paint-tools-cmds.c
+++ b/app/pdb/paint-tools-cmds.c
@@ -26,7 +26,6 @@
 
 #include "pdb-types.h"
 
-#include "core/gimpbrush.h"
 #include "core/gimpdrawable.h"
 #include "core/gimpdynamics.h"
 #include "core/gimppaintinfo.h"
@@ -57,22 +56,15 @@ paint_tools_stroke (Gimp              *gimp,
 {
   GimpPaintCore *core;
   GimpCoords    *coords;
-  GimpBrush     *brush;
   gboolean       retval;
-  gdouble        brush_size;
-  gint           height, width;
   gint           i;
   va_list        args;
 
   n_strokes /= 2;  /* #doubles -> #points */
 
-  brush = gimp_context_get_brush (context);
-  gimp_brush_transform_size (brush, 1.0, 1.0, 0.0, &height, &width);
-  brush_size = MAX (height, width);
-
-  g_object_set (options,
-                "brush-size", brush_size,
-                NULL);
+  /* FIXME: i'm most certain that this is wrong, see bug 721249 --mitch */
+  gimp_paint_options_set_default_brush_size (options,
+                                             gimp_context_get_brush (context));
 
   /*  undefine the paint-relevant context properties and get them
    *  from the current context
diff --git a/app/tools/gimppaintoptions-gui.c b/app/tools/gimppaintoptions-gui.c
index 9ba8f74..11ca180 100644
--- a/app/tools/gimppaintoptions-gui.c
+++ b/app/tools/gimppaintoptions-gui.c
@@ -23,9 +23,6 @@
 
 #include "tools-types.h"
 
-#include "base/temp-buf.h"
-
-#include "core/gimpbrush.h"
 #include "core/gimptoolinfo.h"
 
 #include "paint/gimppaintoptions.h"
@@ -411,12 +408,7 @@ gimp_paint_options_gui_reset_size (GtkWidget        *button,
  GimpBrush *brush = gimp_context_get_brush (GIMP_CONTEXT (paint_options));
 
  if (brush)
-   {
-     g_object_set (paint_options,
-                   "brush-size", (gdouble) MAX (brush->mask->width,
-                                                brush->mask->height),
-                   NULL);
-   }
+   gimp_paint_options_set_default_brush_size (paint_options, brush);
 }
 
 static void
diff --git a/tools/pdbgen/pdb/context.pdb b/tools/pdbgen/pdb/context.pdb
index 8e1447e..3dfbe4b 100644
--- a/tools/pdbgen/pdb/context.pdb
+++ b/tools/pdbgen/pdb/context.pdb
@@ -569,10 +569,7 @@ HELP
       options = gimp_pdb_context_get_brush_options (GIMP_PDB_CONTEXT (context));
 
       for (list = options; list; list = g_list_next (list))
-        g_object_set (list->data,
-                      "brush-size", (gdouble) MAX (brush->mask->width,
-                                                   brush->mask->height),
-                      NULL);
+        gimp_paint_options_set_default_brush_size (list->data, brush);
 
       g_list_free (options);
     }
@@ -2195,11 +2192,10 @@ CODE
     );
 }
 
- headers = qw("base/temp-buf.h"
-              "core/gimp.h"
-              "core/gimpbrush.h"
+ headers = qw("core/gimp.h"
               "core/gimpcontainer.h"
               "core/gimpdatafactory.h"
+              "paint/gimppaintoptions.h"
               "libgimpconfig/gimpconfig.h"
               "plug-in/gimpplugin.h"
               "plug-in/gimpplugin-context.h"
diff --git a/tools/pdbgen/pdb/paint_tools.pdb b/tools/pdbgen/pdb/paint_tools.pdb
index f82c140..8544a56 100644
--- a/tools/pdbgen/pdb/paint_tools.pdb
+++ b/tools/pdbgen/pdb/paint_tools.pdb
@@ -981,22 +981,15 @@ paint_tools_stroke (Gimp              *gimp,
 {
   GimpPaintCore *core;
   GimpCoords    *coords;
-  GimpBrush     *brush;
   gboolean       retval;
-  gdouble        brush_size;
-  gint           height, width;
   gint           i;
   va_list        args;
 
   n_strokes /= 2;  /* #doubles -> #points */
 
-  brush = gimp_context_get_brush (context);
-  gimp_brush_transform_size (brush, 1.0, 1.0, 0.0, &height, &width);
-  brush_size = MAX (height, width);
-
-  g_object_set (options,
-                "brush-size", brush_size,
-                NULL);
+  /* FIXME: i'm most certain that this is wrong, see bug 721249 --mitch */
+  gimp_paint_options_set_default_brush_size (options,
+                                             gimp_context_get_brush (context));
 
   /*  undefine the paint-relevant context properties and get them
    *  from the current context
@@ -1036,7 +1029,6 @@ CODE
 
 @headers = qw("libgimpmath/gimpmath.h"
               "libgimpconfig/gimpconfig.h"
-              "core/gimpbrush.h"
               "core/gimpdynamics.h"
               "core/gimppaintinfo.h"
               "paint/gimppaintcore.h"


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