[gimp] app: share brush modifiers along with the brush or dynamics



commit 52cd1b90433038764a6801aae90615dac9ef2e8f
Author: Alexia Death <alexiadeath gmail com>
Date:   Thu Jun 2 21:16:54 2011 +0300

    app: share brush modifiers along with the brush or dynamics

 app/paint/gimppaintoptions.c |   59 ++++++++++++++++++++++++++++++++++++++++++
 app/paint/gimppaintoptions.h |    6 ++++
 app/tools/tool_manager.c     |   41 +++++++++++++++++++++++++++--
 3 files changed, 103 insertions(+), 3 deletions(-)
---
diff --git a/app/paint/gimppaintoptions.c b/app/paint/gimppaintoptions.c
index 905d59b..5ca9234 100644
--- a/app/paint/gimppaintoptions.c
+++ b/app/paint/gimppaintoptions.c
@@ -710,3 +710,62 @@ gimp_paint_options_get_brush_mode (GimpPaintOptions *paint_options)
 
   return GIMP_BRUSH_SOFT;
 }
+
+void
+gimp_paint_options_copy_brush_props (GimpPaintOptions *src,
+                                     GimpPaintOptions *dest)
+{
+  gdouble  brush_size;
+  gdouble  brush_angle;
+  gdouble  brush_aspect_ratio;
+
+  g_return_if_fail (GIMP_IS_PAINT_OPTIONS (src));
+  g_return_if_fail (GIMP_IS_PAINT_OPTIONS (dest));
+
+  g_object_get (src,
+                "brush-size", &brush_size,
+                "brush-angle", &brush_angle,
+                "brush-aspect-ratio", &brush_aspect_ratio,
+                NULL);
+
+  g_object_set (dest,
+                "brush-size", brush_size,
+                "brush-angle", brush_angle,
+                "brush-aspect-ratio", brush_aspect_ratio,
+                NULL);
+}
+
+void
+gimp_paint_options_copy_dynamics_props (GimpPaintOptions *src,
+                                        GimpPaintOptions *dest)
+{
+  gboolean        dynamics_expanded;
+  gboolean        fade_reverse;
+  gdouble         fade_length;
+  GimpUnit        fade_unit;
+  GimpRepeatMode  fade_repeat;
+
+  gboolean        gradient_reverse;
+
+  g_return_if_fail (GIMP_IS_PAINT_OPTIONS (src));
+  g_return_if_fail (GIMP_IS_PAINT_OPTIONS (dest));
+
+    g_object_get (src,
+                  "dynamics-expanded", &dynamics_expanded,
+                  "fade-reverse", &fade_reverse,
+                  "fade-length", &fade_length,
+                  "fade-unit", &fade_unit,
+                  "fade-repeat", &fade_repeat,
+                  "gradient-reverse", &gradient_reverse,
+                  NULL);
+
+  g_object_set (dest,
+                "dynamics-expanded", dynamics_expanded,
+                "fade-reverse", fade_reverse,
+                "fade-length", fade_length,
+                "fade-unit", fade_unit,
+                "fade-repeat", fade_repeat,
+                "gradient-reverse", gradient_reverse,
+                NULL);
+
+}
diff --git a/app/paint/gimppaintoptions.h b/app/paint/gimppaintoptions.h
index 9ec361c..95fda9d 100644
--- a/app/paint/gimppaintoptions.h
+++ b/app/paint/gimppaintoptions.h
@@ -131,6 +131,12 @@ gboolean gimp_paint_options_get_gradient_color (GimpPaintOptions *paint_options,
 GimpBrushApplicationMode
              gimp_paint_options_get_brush_mode (GimpPaintOptions *paint_options);
 
+void       gimp_paint_options_copy_brush_props (GimpPaintOptions *src,
+                                                GimpPaintOptions *dest);
+
+void    gimp_paint_options_copy_dynamics_props (GimpPaintOptions *src,
+                                                GimpPaintOptions *dest);
+
 
 
 #endif  /*  __GIMP_PAINT_OPTIONS_H__  */
diff --git a/app/tools/tool_manager.c b/app/tools/tool_manager.c
index 37412c3..de28a9f 100644
--- a/app/tools/tool_manager.c
+++ b/app/tools/tool_manager.c
@@ -37,6 +37,8 @@
 
 #include "display/gimpdisplay.h"
 
+#include "paint/gimppaintoptions.h"
+
 #include "gimptool.h"
 #include "gimptoolcontrol.h"
 #include "tool_manager.h"
@@ -46,8 +48,9 @@ typedef struct _GimpToolManager GimpToolManager;
 
 struct _GimpToolManager
 {
-  GimpTool *active_tool;
-  GSList   *tool_stack;
+  GimpTool         *active_tool;
+  GimpPaintOptions *shared_paint_options;
+  GSList           *tool_stack;
 
   GQuark    image_clean_handler_id;
   GQuark    image_dirty_handler_id;
@@ -106,6 +109,11 @@ tool_manager_init (Gimp *gimp)
 
   user_context = gimp_get_user_context (gimp);
 
+  tool_manager->shared_paint_options = g_object_new (GIMP_TYPE_PAINT_OPTIONS,
+                                                     "gimp", gimp,
+                                                     "name", "tmp",
+                                                     NULL);
+
   g_signal_connect (user_context, "tool-changed",
                     G_CALLBACK (tool_manager_tool_changed),
                     tool_manager);
@@ -142,6 +150,9 @@ tool_manager_exit (Gimp *gimp)
   if (tool_manager->active_tool)
     g_object_unref (tool_manager->active_tool);
 
+  if (tool_manager->shared_paint_options)
+    g_object_unref (tool_manager->shared_paint_options);
+
   g_slice_free (GimpToolManager, tool_manager);
 }
 
@@ -599,8 +610,32 @@ tool_manager_tool_changed (GimpContext     *user_context,
   if (tool_manager->active_tool &&
       tool_manager->active_tool->tool_info)
     {
+      GimpToolInfo *old_tool_info = tool_manager->active_tool->tool_info;
+
       tool_manager_disconnect_options (user_context,
-                                       tool_manager->active_tool->tool_info);
+                                       old_tool_info);
+
+      if (GIMP_IS_PAINT_OPTIONS (old_tool_info->tool_options))
+        {
+          /* Storing is unconditional, because the user may turn on brush sharing mid use */
+          gimp_paint_options_copy_brush_props (GIMP_PAINT_OPTIONS(old_tool_info->tool_options),
+                                               tool_manager->shared_paint_options);
+
+          gimp_paint_options_copy_dynamics_props (GIMP_PAINT_OPTIONS(old_tool_info->tool_options),
+                                                  tool_manager->shared_paint_options);
+        }
+
+      if (GIMP_IS_PAINT_OPTIONS (tool_info->tool_options))
+        {
+          GimpCoreConfig *config = user_context->gimp->config;
+
+          if (config->global_brush)
+            gimp_paint_options_copy_brush_props (tool_manager->shared_paint_options,
+                                                 GIMP_PAINT_OPTIONS (tool_info->tool_options));
+          if (config->global_dynamics)
+            gimp_paint_options_copy_dynamics_props (tool_manager->shared_paint_options,
+                                                    GIMP_PAINT_OPTIONS (tool_info->tool_options));
+        }
     }
 
   /*  connect the new tool's context  */



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