[gimp] app: in GimpFilterTool, consolidate drawable-filter option setup



commit d61a541475d1341331aac6cae088a2666df5e335
Author: Ell <ell_se yahoo com>
Date:   Fri Jan 17 10:44:59 2020 +0200

    app: in GimpFilterTool, consolidate drawable-filter option setup
    
    In GimpFilterTool, move all the drawable-filter option setup to a
    new gimp_filter_tool_update_filter() function, and call it whenever
    the drawable-filter's options need to be updated.  This avoids
    duplicating logic in various places.

 app/tools/gimpfiltertool.c | 86 +++++++++++++++++++---------------------------
 1 file changed, 35 insertions(+), 51 deletions(-)
---
diff --git a/app/tools/gimpfiltertool.c b/app/tools/gimpfiltertool.c
index 3798baf0f6..54334c03bc 100644
--- a/app/tools/gimpfiltertool.c
+++ b/app/tools/gimpfiltertool.c
@@ -188,6 +188,8 @@ static void      gimp_filter_tool_response       (GimpToolGui         *gui,
                                                   gint                 response_id,
                                                   GimpFilterTool      *filter_tool);
 
+static void      gimp_filter_tool_update_filter  (GimpFilterTool      *filter_tool);
+
 static void    gimp_filter_tool_set_has_settings (GimpFilterTool      *filter_tool,
                                                   gboolean             has_settings);
 
@@ -767,37 +769,26 @@ gimp_filter_tool_options_notify (GimpTool         *tool,
             }
         }
 
-      gimp_drawable_filter_set_preview (filter_tool->filter,
-                                        filter_options->preview_split,
-                                        filter_options->preview_alignment,
-                                        filter_options->preview_position);
+      gimp_filter_tool_update_filter (filter_tool);
 
       if (filter_options->preview_split)
         gimp_filter_tool_add_guide (filter_tool);
       else
         gimp_filter_tool_remove_guide (filter_tool);
     }
-  else if (! strcmp (pspec->name, "preview-alignment") &&
-           filter_tool->filter)
+  else if (! strcmp (pspec->name, "preview-alignment") ||
+           ! strcmp (pspec->name, "preview-position"))
     {
-      gimp_drawable_filter_set_preview (filter_tool->filter,
-                                        filter_options->preview_split,
-                                        filter_options->preview_alignment,
-                                        filter_options->preview_position);
+      gimp_filter_tool_update_filter (filter_tool);
 
       if (filter_options->preview_split)
         gimp_filter_tool_move_guide (filter_tool);
     }
-  else if (! strcmp (pspec->name, "preview-position") &&
-           filter_tool->filter)
+  else if (! strcmp (pspec->name, "clip")   ||
+           ! strcmp (pspec->name, "region") ||
+           ! strcmp (pspec->name, "gamma-hack"))
     {
-      gimp_drawable_filter_set_preview (filter_tool->filter,
-                                        filter_options->preview_split,
-                                        filter_options->preview_alignment,
-                                        filter_options->preview_position);
-
-      if (filter_options->preview_split)
-        gimp_filter_tool_move_guide (filter_tool);
+      gimp_filter_tool_update_filter (filter_tool);
     }
   else if (! strcmp (pspec->name, "controller") &&
            filter_tool->widget)
@@ -805,29 +796,6 @@ gimp_filter_tool_options_notify (GimpTool         *tool,
       gimp_tool_widget_set_visible (filter_tool->widget,
                                     filter_options->controller);
     }
-  else if (! strcmp (pspec->name, "clip") &&
-           filter_tool->filter)
-    {
-      gimp_drawable_filter_set_clip (filter_tool->filter,
-                                     filter_options->clip ==
-                                     GIMP_TRANSFORM_RESIZE_CLIP ||
-                                     ! gimp_drawable_has_alpha (
-                                         tool->drawable));
-    }
-  else if (! strcmp (pspec->name, "region") &&
-           filter_tool->filter)
-    {
-      gimp_drawable_filter_set_region (filter_tool->filter,
-                                       filter_options->region);
-
-      gimp_filter_tool_region_changed (filter_tool);
-    }
-  else if (! strcmp (pspec->name, "gamma-hack") &&
-           filter_tool->filter)
-    {
-      gimp_drawable_filter_set_gamma_hack (filter_tool->filter,
-                                           filter_options->gamma_hack);
-    }
 }
 
 static gboolean
@@ -1120,15 +1088,7 @@ gimp_filter_tool_create_filter (GimpFilterTool *filter_tool)
                                                   filter_tool->operation,
                                                   gimp_tool_get_icon_name (tool));
 
-  gimp_drawable_filter_set_clip       (filter_tool->filter,
-                                       options->clip ==
-                                       GIMP_TRANSFORM_RESIZE_CLIP ||
-                                       ! gimp_drawable_has_alpha (
-                                           tool->drawable));
-  gimp_drawable_filter_set_region     (filter_tool->filter,
-                                       options->region);
-  gimp_drawable_filter_set_gamma_hack (filter_tool->filter,
-                                       options->gamma_hack);
+  gimp_filter_tool_update_filter (filter_tool);
 
   g_signal_connect (filter_tool->filter, "flush",
                     G_CALLBACK (gimp_filter_tool_flush),
@@ -1419,6 +1379,30 @@ gimp_filter_tool_response (GimpToolGui    *gui,
     }
 }
 
+static void
+gimp_filter_tool_update_filter (GimpFilterTool *filter_tool)
+{
+  GimpTool          *tool    = GIMP_TOOL (filter_tool);
+  GimpFilterOptions *options = GIMP_FILTER_TOOL_GET_OPTIONS (filter_tool);
+
+  if (! filter_tool->filter)
+    return;
+
+  gimp_drawable_filter_set_clip          (filter_tool->filter,
+                                          options->clip ==
+                                          GIMP_TRANSFORM_RESIZE_CLIP ||
+                                          ! gimp_drawable_has_alpha (
+                                              tool->drawable));
+  gimp_drawable_filter_set_region        (filter_tool->filter,
+                                          options->region);
+  gimp_drawable_filter_set_preview       (filter_tool->filter,
+                                          options->preview_split,
+                                          options->preview_alignment,
+                                          options->preview_position);
+  gimp_drawable_filter_set_gamma_hack    (filter_tool->filter,
+                                          options->gamma_hack);
+}
+
 static void
 gimp_filter_tool_set_has_settings (GimpFilterTool *filter_tool,
                                    gboolean        has_settings)


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