[gimp] app: add gimp_paint_options_set_default_brush_size()



commit ef858453724f6d4ca105fc9daec038fdff358f30
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.

 app/core/gimpstrokeoptions.c     |   19 ++-----------------
 app/paint/gimppaintoptions.c     |   24 ++++++++++++++++++++++++
 app/paint/gimppaintoptions.h     |    3 +++
 app/pdb/context-cmds.c           |    9 ++-------
 app/pdb/paint-tools-cmds.c       |   14 +++-----------
 app/tools/gimppaintoptions-gui.c |   10 +---------
 tools/pdbgen/pdb/context.pdb     |    9 ++-------
 tools/pdbgen/pdb/paint_tools.pdb |   14 +++-----------
 8 files changed, 40 insertions(+), 62 deletions(-)
---
diff --git a/app/core/gimpstrokeoptions.c b/app/core/gimpstrokeoptions.c
index b1701a7..2aa5501 100644
--- a/app/core/gimpstrokeoptions.c
+++ b/app/core/gimpstrokeoptions.c
@@ -32,7 +32,6 @@
 #include "config/gimpcoreconfig.h"
 
 #include "gimp.h"
-#include "gimpbrush.h"
 #include "gimpcontext.h"
 #include "gimpdashpattern.h"
 #include "gimpmarshal.h"
@@ -568,24 +567,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 61c22d6..e0c7a67 100644
--- a/app/paint/gimppaintoptions.c
+++ b/app/paint/gimppaintoptions.c
@@ -27,6 +27,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"
@@ -733,6 +734,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 ab17463..2b23604 100644
--- a/app/paint/gimppaintoptions.h
+++ b/app/paint/gimppaintoptions.h
@@ -134,6 +134,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 f6f75d2..4fd84cb 100644
--- a/app/pdb/context-cmds.c
+++ b/app/pdb/context-cmds.c
@@ -33,11 +33,10 @@
 #include "pdb-types.h"
 
 #include "core/gimp.h"
-#include "core/gimpbrush.h"
 #include "core/gimpcontainer.h"
 #include "core/gimpdatafactory.h"
 #include "core/gimpparamspecs.h"
-#include "core/gimptempbuf.h"
+#include "paint/gimppaintoptions.h"
 #include "plug-in/gimpplugin-context.h"
 #include "plug-in/gimpplugin.h"
 #include "plug-in/gimppluginmanager.h"
@@ -513,11 +512,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 (gimp_temp_buf_get_width  (brush->mask),
-                                     gimp_temp_buf_get_height (brush->mask)),
-                      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 77299b3..419cf59 100644
--- a/app/pdb/paint-tools-cmds.c
+++ b/app/pdb/paint-tools-cmds.c
@@ -30,7 +30,6 @@
 
 #include "pdb-types.h"
 
-#include "core/gimpbrush.h"
 #include "core/gimpdrawable.h"
 #include "core/gimpdynamics.h"
 #include "core/gimppaintinfo.h"
@@ -61,22 +60,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 eb78f33..114b4b4 100644
--- a/app/tools/gimppaintoptions-gui.c
+++ b/app/tools/gimppaintoptions-gui.c
@@ -24,8 +24,6 @@
 
 #include "tools-types.h"
 
-#include "core/gimpbrush.h"
-#include "core/gimptempbuf.h"
 #include "core/gimptoolinfo.h"
 
 #include "paint/gimppaintoptions.h"
@@ -409,13 +407,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 (gimp_temp_buf_get_width  (brush->mask),
-                                  gimp_temp_buf_get_height (brush->mask)),
-                   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 5db61e7..0360e93 100644
--- a/tools/pdbgen/pdb/context.pdb
+++ b/tools/pdbgen/pdb/context.pdb
@@ -569,11 +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 (gimp_temp_buf_get_width  (brush->mask),
-                                     gimp_temp_buf_get_height (brush->mask)),
-                      NULL);
+        gimp_paint_options_set_default_brush_size (list->data, brush);
 
       g_list_free (options);
     }
@@ -2168,10 +2164,9 @@ CODE
 }
 
 @headers = qw("core/gimp.h"
-              "core/gimpbrush.h"
               "core/gimpcontainer.h"
               "core/gimpdatafactory.h"
-              "core/gimptempbuf.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 d720529..40a9907 100644
--- a/tools/pdbgen/pdb/paint_tools.pdb
+++ b/tools/pdbgen/pdb/paint_tools.pdb
@@ -999,22 +999,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
@@ -1054,7 +1047,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]