[gimp/gimp-2-10] Issue #1714 - When GIMP starts, default brush hardness is always at 100



commit f1ffb06ccbf4dc8ca29686298ecabb53d0e38dcf
Author: Michael Natterer <mitch gimp org>
Date:   Tue Jun 26 00:30:12 2018 +0200

    Issue #1714 - When GIMP starts, default brush hardness is always at 100
    
    We should not have essential signal connections (such as setting tool
    options from brush properties) implemented in the tool options GUI
    files, because they are not active until the options GUI is created.
    Also, that magic is simply too hidden in the options GUI files.
    
    Move the signal connections and the brush property copying code to
    gimppaintoptions.c where is can also be done cleaner.
    
    However, this must only be done for the main tool options instance
    that is used for the GUI. Therefore, add a "gui_mode" boolean to
    GimpToolOptions and set it to TRUE for all main tool options.
    
    (this is ugly, but much less ugly and much less hidden than all the
    places where code lives (like tool_manager.c) that can now be moved
    into GimpToolOptions and its subclasses, and implemented cleanly
    there).
    
    (cherry picked from commit cb0e6c65d059513d09f20c33d8e09967840e564f)

 app/core/gimptoolinfo.c          |   2 +
 app/core/gimptooloptions.c       |  17 ++++++
 app/core/gimptooloptions.h       |  13 +++++
 app/paint/gimppaintoptions.c     | 120 ++++++++++++++++++++++++++++++---------
 app/tools/gimppaintoptions-gui.c |  71 -----------------------
 5 files changed, 126 insertions(+), 97 deletions(-)
---
diff --git a/app/core/gimptoolinfo.c b/app/core/gimptoolinfo.c
index 7cc2970254..0cd2231138 100644
--- a/app/core/gimptoolinfo.c
+++ b/app/core/gimptoolinfo.c
@@ -250,6 +250,8 @@ gimp_tool_info_new (Gimp                *gimp,
                 "tool",      tool_info,
                 "tool-info", tool_info, NULL);
 
+  gimp_tool_options_set_gui_mode (tool_info->tool_options, TRUE);
+
   if (tool_info->tool_options_type != GIMP_TYPE_TOOL_OPTIONS)
     {
       GimpContainer *presets;
diff --git a/app/core/gimptooloptions.c b/app/core/gimptooloptions.c
index 17bf430e8d..a50c627acb 100644
--- a/app/core/gimptooloptions.c
+++ b/app/core/gimptooloptions.c
@@ -262,6 +262,23 @@ gimp_tool_options_tool_notify (GimpToolOptions *options,
 
 /*  public functions  */
 
+void
+gimp_tool_options_set_gui_mode (GimpToolOptions *tool_options,
+                                gboolean         gui_mode)
+{
+  g_return_if_fail (GIMP_IS_TOOL_OPTIONS (tool_options));
+
+  tool_options->gui_mode = gui_mode ? TRUE : FALSE;
+}
+
+gboolean
+gimp_tool_options_get_gui_mode (GimpToolOptions *tool_options)
+{
+  g_return_val_if_fail (GIMP_IS_TOOL_OPTIONS (tool_options), FALSE);
+
+  return tool_options->gui_mode;
+}
+
 gboolean
 gimp_tool_options_serialize (GimpToolOptions  *tool_options,
                              GError          **error)
diff --git a/app/core/gimptooloptions.h b/app/core/gimptooloptions.h
index 055ecf5cc6..d28d406a7e 100644
--- a/app/core/gimptooloptions.h
+++ b/app/core/gimptooloptions.h
@@ -37,6 +37,15 @@ struct _GimpToolOptions
   GimpContext   parent_instance;
 
   GimpToolInfo *tool_info;
+
+  /*  if TRUE this instance is the main tool options object used for
+   *  the GUI, this is not exactly clean, but there are some things
+   *  (like linking brush properties to the active brush, or properly
+   *  maintaining global brush, pattern etc.) that can only be done
+   *  right in the object, and not by signal connections from the GUI,
+   *  or upon switching tools, all of which was much more horrible.
+   */
+  gboolean      gui_mode;
 };
 
 struct _GimpToolOptionsClass
@@ -47,6 +56,10 @@ struct _GimpToolOptionsClass
 
 GType      gimp_tool_options_get_type      (void) G_GNUC_CONST;
 
+void       gimp_tool_options_set_gui_mode  (GimpToolOptions   *tool_options,
+                                            gboolean           gui_mode);
+gboolean   gimp_tool_options_get_gui_mode  (GimpToolOptions   *tool_options);
+
 gboolean   gimp_tool_options_serialize     (GimpToolOptions   *tool_options,
                                             GError           **error);
 gboolean   gimp_tool_options_deserialize   (GimpToolOptions   *tool_options,
diff --git a/app/paint/gimppaintoptions.c b/app/paint/gimppaintoptions.c
index 0c13501c96..a5659f43e1 100644
--- a/app/paint/gimppaintoptions.c
+++ b/app/paint/gimppaintoptions.c
@@ -34,6 +34,7 @@
 #include "core/gimpgradient.h"
 #include "core/gimppaintinfo.h"
 
+#include "gimpbrushcore.h"
 #include "gimppaintoptions.h"
 
 #include "gimp-intl.h"
@@ -135,22 +136,28 @@ enum
 
 static void         gimp_paint_options_config_iface_init (GimpConfigInterface *config_iface);
 
-static void         gimp_paint_options_dispose           (GObject      *object);
-static void         gimp_paint_options_finalize          (GObject      *object);
-static void         gimp_paint_options_set_property      (GObject      *object,
-                                                          guint         property_id,
-                                                          const GValue *value,
-                                                          GParamSpec   *pspec);
-static void         gimp_paint_options_get_property      (GObject      *object,
-                                                          guint         property_id,
-                                                          GValue       *value,
-                                                          GParamSpec   *pspec);
-
-static GimpConfig * gimp_paint_options_duplicate         (GimpConfig   *config);
-static gboolean     gimp_paint_options_copy              (GimpConfig   *src,
-                                                          GimpConfig   *dest,
-                                                          GParamFlags   flags);
-static void         gimp_paint_options_reset             (GimpConfig   *config);
+static void         gimp_paint_options_dispose           (GObject          *object);
+static void         gimp_paint_options_finalize          (GObject          *object);
+static void         gimp_paint_options_set_property      (GObject          *object,
+                                                          guint             property_id,
+                                                          const GValue     *value,
+                                                          GParamSpec       *pspec);
+static void         gimp_paint_options_get_property      (GObject          *object,
+                                                          guint             property_id,
+                                                          GValue           *value,
+                                                          GParamSpec       *pspec);
+
+static void         gimp_paint_options_brush_changed     (GimpContext      *context,
+                                                          GimpBrush        *brush);
+static void         gimp_paint_options_brush_notify      (GimpBrush        *brush,
+                                                          const GParamSpec *pspec,
+                                                          GimpPaintOptions *options);
+
+static GimpConfig * gimp_paint_options_duplicate         (GimpConfig       *config);
+static gboolean     gimp_paint_options_copy              (GimpConfig       *src,
+                                                          GimpConfig       *dest,
+                                                          GParamFlags       flags);
+static void         gimp_paint_options_reset             (GimpConfig       *config);
 
 
 G_DEFINE_TYPE_WITH_CODE (GimpPaintOptions, gimp_paint_options,
@@ -166,12 +173,15 @@ static GimpConfigInterface *parent_config_iface = NULL;
 static void
 gimp_paint_options_class_init (GimpPaintOptionsClass *klass)
 {
-  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GObjectClass     *object_class  = G_OBJECT_CLASS (klass);
+  GimpContextClass *context_class = GIMP_CONTEXT_CLASS (klass);
+
+  object_class->dispose         = gimp_paint_options_dispose;
+  object_class->finalize        = gimp_paint_options_finalize;
+  object_class->set_property    = gimp_paint_options_set_property;
+  object_class->get_property    = gimp_paint_options_get_property;
 
-  object_class->dispose        = gimp_paint_options_dispose;
-  object_class->finalize       = gimp_paint_options_finalize;
-  object_class->set_property   = gimp_paint_options_set_property;
-  object_class->get_property   = gimp_paint_options_get_property;
+  context_class->brush_changed  = gimp_paint_options_brush_changed;
 
   g_object_class_install_property (object_class, PROP_PAINT_INFO,
                                    g_param_spec_object ("paint-info",
@@ -454,11 +464,7 @@ gimp_paint_options_dispose (GObject *object)
 {
   GimpPaintOptions *options = GIMP_PAINT_OPTIONS (object);
 
-  if (options->paint_info)
-    {
-      g_object_unref (options->paint_info);
-      options->paint_info = NULL;
-    }
+  g_clear_object (&options->paint_info);
 
   G_OBJECT_CLASS (parent_class)->dispose (object);
 }
@@ -802,6 +808,68 @@ gimp_paint_options_get_property (GObject    *object,
     }
 }
 
+static void
+gimp_paint_options_brush_changed (GimpContext *context,
+                                  GimpBrush   *brush)
+{
+  GimpPaintOptions *options = GIMP_PAINT_OPTIONS (context);
+
+  if (options->paint_info &&
+      g_type_is_a (options->paint_info->paint_type,
+                   GIMP_TYPE_BRUSH_CORE))
+    {
+      if (options->brush)
+        {
+          g_signal_handlers_disconnect_by_func (options->brush,
+                                                gimp_paint_options_brush_notify,
+                                                options);
+          g_object_remove_weak_pointer (G_OBJECT (options->brush),
+                                        (gpointer) &options->brush);
+        }
+
+      options->brush = brush;
+
+      if (options->brush)
+        {
+          g_object_add_weak_pointer (G_OBJECT (options->brush),
+                                     (gpointer) &options->brush);
+          g_signal_connect_object (options->brush, "notify",
+                                   G_CALLBACK (gimp_paint_options_brush_notify),
+                                   options, 0);
+
+          gimp_paint_options_brush_notify (options->brush, NULL, options);
+        }
+    }
+}
+
+static void
+gimp_paint_options_brush_notify (GimpBrush        *brush,
+                                 const GParamSpec *pspec,
+                                 GimpPaintOptions *options)
+{
+  if (gimp_tool_options_get_gui_mode (GIMP_TOOL_OPTIONS (options)))
+    {
+#define IS_PSPEC(p,n) (p == NULL || ! strcmp (n, p->name))
+
+      if (options->brush_link_size && IS_PSPEC (pspec, "radius"))
+        gimp_paint_options_set_default_brush_size (options, brush);
+
+      if (options->brush_link_aspect_ratio && IS_PSPEC (pspec, "aspect-ratio"))
+        gimp_paint_options_set_default_brush_aspect_ratio (options, brush);
+
+      if (options->brush_link_angle && IS_PSPEC (pspec, "angle"))
+        gimp_paint_options_set_default_brush_angle (options, brush);
+
+      if (options->brush_link_spacing && IS_PSPEC (pspec, "spacing"))
+        gimp_paint_options_set_default_brush_spacing (options, brush);
+
+      if (options->brush_link_hardness && IS_PSPEC (pspec, "hardness"))
+        gimp_paint_options_set_default_brush_hardness (options, brush);
+
+#undef IS_SPEC
+    }
+}
+
 static GimpConfig *
 gimp_paint_options_duplicate (GimpConfig *config)
 {
diff --git a/app/tools/gimppaintoptions-gui.c b/app/tools/gimppaintoptions-gui.c
index 28756818a3..b08e6773ad 100644
--- a/app/tools/gimppaintoptions-gui.c
+++ b/app/tools/gimppaintoptions-gui.c
@@ -52,14 +52,6 @@
 #include "gimp-intl.h"
 
 
-static void gimp_paint_options_gui_brush_changed
-                                               (GimpContext      *context,
-                                                GimpBrush        *brush,
-                                                GtkWidget        *gui);
-static void gimp_paint_options_gui_brush_notify(GimpBrush        *brush,
-                                                const GParamSpec *pspec,
-                                                GimpPaintOptions *options);
-
 static void gimp_paint_options_gui_reset_size  (GtkWidget        *button,
                                                 GimpPaintOptions *paint_options);
 static void gimp_paint_options_gui_reset_aspect_ratio
@@ -238,10 +230,6 @@ gimp_paint_options_gui (GimpToolOptions *tool_options)
       frame = jitter_options_gui (options, tool_type);
       gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
       gtk_widget_show (frame);
-
-      g_signal_connect_object (options, "brush-changed",
-                               G_CALLBACK (gimp_paint_options_gui_brush_changed),
-                               G_OBJECT (vbox), 0);
     }
 
   /*  the "smooth stroke" options  */
@@ -444,65 +432,6 @@ smoothing_options_gui (GimpPaintOptions *paint_options,
   return frame;
 }
 
-static void
-gimp_paint_options_gui_brush_changed (GimpContext *context,
-                                      GimpBrush   *brush,
-                                      GtkWidget   *gui)
-{
-  GimpPaintOptions *options = GIMP_PAINT_OPTIONS (context);
-
-  if (options->brush)
-    {
-      g_signal_handlers_disconnect_by_func (options->brush,
-                                            gimp_paint_options_gui_brush_notify,
-                                            options);
-      g_object_remove_weak_pointer (G_OBJECT (options->brush),
-                                    (gpointer) &options->brush);
-    }
-
-  options->brush = brush;
-
-  if (options->brush)
-    {
-      GClosure *closure;
-
-      g_object_add_weak_pointer (G_OBJECT (options->brush),
-                                 (gpointer) &options->brush);
-
-      closure = g_cclosure_new (G_CALLBACK (gimp_paint_options_gui_brush_notify),
-                                options, NULL);
-      g_object_watch_closure (G_OBJECT (gui), closure);
-      g_signal_connect_closure (options->brush, "notify", closure, FALSE);
-
-      gimp_paint_options_gui_brush_notify (options->brush, NULL, options);
-    }
-}
-
-static void
-gimp_paint_options_gui_brush_notify (GimpBrush        *brush,
-                                     const GParamSpec *pspec,
-                                     GimpPaintOptions *options)
-{
-#define IS_PSPEC(p,n) (p == NULL || ! strcmp (n, p->name))
-
-  if (options->brush_link_size && IS_PSPEC (pspec, "radius"))
-    gimp_paint_options_set_default_brush_size (options, brush);
-
-  if (options->brush_link_aspect_ratio && IS_PSPEC (pspec, "aspect-ratio"))
-    gimp_paint_options_set_default_brush_aspect_ratio (options, brush);
-
-  if (options->brush_link_angle && IS_PSPEC (pspec, "angle"))
-    gimp_paint_options_set_default_brush_angle (options, brush);
-
-  if (options->brush_link_spacing && IS_PSPEC (pspec, "spacing"))
-    gimp_paint_options_set_default_brush_spacing (options, brush);
-
-  if (options->brush_link_hardness && IS_PSPEC (pspec, "hardness"))
-    gimp_paint_options_set_default_brush_hardness (options, brush);
-
-#undef IS_SPEC
-}
-
 static void
 gimp_paint_options_gui_reset_size (GtkWidget        *button,
                                    GimpPaintOptions *paint_options)


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