[gimp/gimp-2-10] app: add "Fade" options to filter tools



commit a643fc2ad1c9d6f2886a9652ce74a8e19c181e45
Author: Ell <ell_se yahoo com>
Date:   Tue Apr 7 18:45:17 2020 +0300

    app: add "Fade" options to filter tools
    
    As per commit ed7ea51fb739d1651946fd122a147f5d8415b7ff, reintroduce
    the "Fade" functionality for filters, by incorporating it directly
    into GimpFilterTool.
    
    Add "mode" and "opacity" options to GimpOperationSettings, and add
    a corresponding "Fade" expander to the GimpFilterTool dialog
    allowing to control them.
    
    Reintroduce the FADE layer-mode context, and use it to mark the
    layer modes avaialable for fading.

 app/operations/gimpoperationsettings.c        | 45 +++++++++++++++++++++++++++
 app/operations/gimpoperationsettings.h        |  2 ++
 app/operations/layer-modes/gimp-layer-modes.c | 16 +++++++---
 app/operations/operations-enums.c             |  2 ++
 app/operations/operations-enums.h             |  4 ++-
 app/tools/gimpfiltertool.c                    | 45 +++++++++++++++++++++++++--
 6 files changed, 107 insertions(+), 7 deletions(-)
---
diff --git a/app/operations/gimpoperationsettings.c b/app/operations/gimpoperationsettings.c
index 194e958659..88a6acee3e 100644
--- a/app/operations/gimpoperationsettings.c
+++ b/app/operations/gimpoperationsettings.c
@@ -42,6 +42,8 @@ enum
   PROP_0,
   PROP_CLIP,
   PROP_REGION,
+  PROP_MODE,
+  PROP_OPACITY,
   PROP_COLOR_MANAGED,
   PROP_GAMMA_HACK
 };
@@ -88,6 +90,23 @@ gimp_operation_settings_class_init (GimpOperationSettingsClass *klass)
                          GIMP_PARAM_STATIC_STRINGS |
                          GIMP_CONFIG_PARAM_DEFAULTS);
 
+  GIMP_CONFIG_PROP_ENUM (object_class, PROP_MODE,
+                         "gimp-mode",
+                         _("Mode"),
+                         NULL,
+                         GIMP_TYPE_LAYER_MODE,
+                         GIMP_LAYER_MODE_REPLACE,
+                         GIMP_PARAM_STATIC_STRINGS |
+                         GIMP_CONFIG_PARAM_DEFAULTS);
+
+  GIMP_CONFIG_PROP_DOUBLE (object_class, PROP_OPACITY,
+                           "gimp-opacity",
+                           _("Opacity"),
+                           NULL,
+                           0.0, 1.0, 1.0,
+                           GIMP_PARAM_STATIC_STRINGS |
+                           GIMP_CONFIG_PARAM_DEFAULTS);
+
   GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_COLOR_MANAGED,
                             "gimp-color-managed",
                             _("Color _managed"),
@@ -128,6 +147,14 @@ gimp_operation_settings_get_property (GObject    *object,
       g_value_set_enum (value, settings->region);
       break;
 
+    case PROP_MODE:
+      g_value_set_enum (value, settings->mode);
+      break;
+
+    case PROP_OPACITY:
+      g_value_set_double (value, settings->opacity);
+      break;
+
     case PROP_COLOR_MANAGED:
       g_value_set_boolean (value, settings->color_managed);
       break;
@@ -160,6 +187,14 @@ gimp_operation_settings_set_property (GObject      *object,
       settings->region = g_value_get_enum (value);
       break;
 
+    case PROP_MODE:
+      settings->mode = g_value_get_enum (value);
+      break;
+
+    case PROP_OPACITY:
+      settings->opacity = g_value_get_double (value);
+      break;
+
     case PROP_COLOR_MANAGED:
       settings->color_managed = g_value_get_boolean (value);
       break;
@@ -191,6 +226,12 @@ gimp_operation_settings_sync_drawable_filter (GimpOperationSettings *settings,
 
   gimp_drawable_filter_set_region        (filter, settings->region);
   gimp_drawable_filter_set_clip          (filter, clip);
+  gimp_drawable_filter_set_mode          (filter,
+                                          settings->mode,
+                                          GIMP_LAYER_COLOR_SPACE_AUTO,
+                                          GIMP_LAYER_COLOR_SPACE_AUTO,
+                                          GIMP_LAYER_COMPOSITE_AUTO);
+  gimp_drawable_filter_set_opacity       (filter, settings->opacity);
   gimp_drawable_filter_set_color_managed (filter, settings->color_managed);
   gimp_drawable_filter_set_gamma_hack    (filter, settings->gamma_hack);
 }
@@ -203,6 +244,8 @@ static const gchar * const base_properties[] =
   "time",
   "gimp-clip",
   "gimp-region",
+  "gimp-mode",
+  "gimp-opacity",
   "gimp-color-managed",
   "gimp-gamma-hack"
 };
@@ -236,6 +279,8 @@ gimp_operation_settings_config_equal_base (GimpConfig *a,
 
   return settings_a->clip          == settings_b->clip          &&
          settings_a->region        == settings_b->region        &&
+         settings_a->mode          == settings_b->mode          &&
+         settings_a->opacity       == settings_b->opacity       &&
          settings_a->color_managed == settings_b->color_managed &&
          settings_a->gamma_hack    == settings_b->gamma_hack;
 }
diff --git a/app/operations/gimpoperationsettings.h b/app/operations/gimpoperationsettings.h
index de98afd782..a081fce737 100644
--- a/app/operations/gimpoperationsettings.h
+++ b/app/operations/gimpoperationsettings.h
@@ -41,6 +41,8 @@ struct _GimpOperationSettings
 
   GimpTransformResize  clip;
   GimpFilterRegion     region;
+  GimpLayerMode        mode;
+  gdouble              opacity;
   gboolean             color_managed;
   gboolean             gamma_hack;
 };
diff --git a/app/operations/layer-modes/gimp-layer-modes.c b/app/operations/layer-modes/gimp-layer-modes.c
index 2064ae539c..7a751bc855 100644
--- a/app/operations/layer-modes/gimp-layer-modes.c
+++ b/app/operations/layer-modes/gimp-layer-modes.c
@@ -86,7 +86,8 @@ static const GimpLayerModeInfo layer_mode_infos[] =
                             GIMP_LAYER_MODE_FLAG_BLEND_SPACE_IMMUTABLE     |
                             GIMP_LAYER_MODE_FLAG_COMPOSITE_SPACE_IMMUTABLE |
                             GIMP_LAYER_MODE_FLAG_COMPOSITE_MODE_IMMUTABLE,
-    .context              = GIMP_LAYER_MODE_CONTEXT_PAINT,
+    .context              = GIMP_LAYER_MODE_CONTEXT_PAINT |
+                            GIMP_LAYER_MODE_CONTEXT_FADE,
     .paint_composite_mode = GIMP_LAYER_COMPOSITE_UNION,
     .composite_mode       = GIMP_LAYER_COMPOSITE_UNION,
     .composite_space      = GIMP_LAYER_COLOR_SPACE_RGB_PERCEPTUAL
@@ -367,7 +368,8 @@ static const GimpLayerModeInfo layer_mode_infos[] =
                             GIMP_LAYER_MODE_FLAG_COMPOSITE_SPACE_IMMUTABLE |
                             GIMP_LAYER_MODE_FLAG_COMPOSITE_MODE_IMMUTABLE  |
                             GIMP_LAYER_MODE_FLAG_SUBTRACTIVE,
-    .context              = GIMP_LAYER_MODE_CONTEXT_PAINT,
+    .context              = GIMP_LAYER_MODE_CONTEXT_PAINT |
+                            GIMP_LAYER_MODE_CONTEXT_FADE,
     .paint_composite_mode = GIMP_LAYER_COMPOSITE_CLIP_TO_BACKDROP,
     .composite_mode       = GIMP_LAYER_COMPOSITE_CLIP_TO_BACKDROP,
     .composite_space      = GIMP_LAYER_COLOR_SPACE_RGB_PERCEPTUAL,
@@ -448,7 +450,8 @@ static const GimpLayerModeInfo layer_mode_infos[] =
 
     .op_name              = "gimp:behind",
     .flags                = GIMP_LAYER_MODE_FLAG_BLEND_SPACE_IMMUTABLE,
-    .context              = GIMP_LAYER_MODE_CONTEXT_PAINT,
+    .context              = GIMP_LAYER_MODE_CONTEXT_PAINT |
+                            GIMP_LAYER_MODE_CONTEXT_FADE,
     .paint_composite_mode = GIMP_LAYER_COMPOSITE_UNION,
     .composite_mode       = GIMP_LAYER_COMPOSITE_UNION,
     .composite_space      = GIMP_LAYER_COLOR_SPACE_RGB_LINEAR
@@ -823,6 +826,7 @@ static const GimpLayerModeInfo layer_mode_infos[] =
     .op_name              = "gimp:replace",
     .flags                = GIMP_LAYER_MODE_FLAG_BLEND_SPACE_IMMUTABLE |
                             GIMP_LAYER_MODE_FLAG_TRIVIAL,
+    .context              = GIMP_LAYER_MODE_CONTEXT_FADE,
     .paint_composite_mode = GIMP_LAYER_COMPOSITE_UNION,
     .composite_mode       = GIMP_LAYER_COMPOSITE_UNION,
     .composite_space      = GIMP_LAYER_COLOR_SPACE_RGB_LINEAR
@@ -834,6 +838,7 @@ static const GimpLayerModeInfo layer_mode_infos[] =
     .flags                = GIMP_LAYER_MODE_FLAG_BLEND_SPACE_IMMUTABLE     |
                             GIMP_LAYER_MODE_FLAG_COMPOSITE_SPACE_IMMUTABLE |
                             GIMP_LAYER_MODE_FLAG_ALPHA_ONLY,
+    .context              = GIMP_LAYER_MODE_CONTEXT_FADE,
     .paint_composite_mode = GIMP_LAYER_COMPOSITE_UNION,
     .composite_mode       = GIMP_LAYER_COMPOSITE_UNION
   }
@@ -845,8 +850,11 @@ static const GimpLayerMode layer_mode_group_default[] =
 
   GIMP_LAYER_MODE_SEPARATOR,
 
-  GIMP_LAYER_MODE_NORMAL,
   GIMP_LAYER_MODE_REPLACE,
+
+  GIMP_LAYER_MODE_SEPARATOR,
+
+  GIMP_LAYER_MODE_NORMAL,
   GIMP_LAYER_MODE_DISSOLVE,
   GIMP_LAYER_MODE_BEHIND,
   GIMP_LAYER_MODE_COLOR_ERASE,
diff --git a/app/operations/operations-enums.c b/app/operations/operations-enums.c
index dabf1fca01..a0d67b88e0 100644
--- a/app/operations/operations-enums.c
+++ b/app/operations/operations-enums.c
@@ -338,6 +338,7 @@ gimp_layer_mode_context_get_type (void)
     { GIMP_LAYER_MODE_CONTEXT_LAYER, "GIMP_LAYER_MODE_CONTEXT_LAYER", "layer" },
     { GIMP_LAYER_MODE_CONTEXT_GROUP, "GIMP_LAYER_MODE_CONTEXT_GROUP", "group" },
     { GIMP_LAYER_MODE_CONTEXT_PAINT, "GIMP_LAYER_MODE_CONTEXT_PAINT", "paint" },
+    { GIMP_LAYER_MODE_CONTEXT_FADE, "GIMP_LAYER_MODE_CONTEXT_FADE", "fade" },
     { GIMP_LAYER_MODE_CONTEXT_ALL, "GIMP_LAYER_MODE_CONTEXT_ALL", "all" },
     { 0, NULL, NULL }
   };
@@ -347,6 +348,7 @@ gimp_layer_mode_context_get_type (void)
     { GIMP_LAYER_MODE_CONTEXT_LAYER, "GIMP_LAYER_MODE_CONTEXT_LAYER", NULL },
     { GIMP_LAYER_MODE_CONTEXT_GROUP, "GIMP_LAYER_MODE_CONTEXT_GROUP", NULL },
     { GIMP_LAYER_MODE_CONTEXT_PAINT, "GIMP_LAYER_MODE_CONTEXT_PAINT", NULL },
+    { GIMP_LAYER_MODE_CONTEXT_FADE, "GIMP_LAYER_MODE_CONTEXT_FADE", NULL },
     { GIMP_LAYER_MODE_CONTEXT_ALL, "GIMP_LAYER_MODE_CONTEXT_ALL", NULL },
     { 0, NULL, NULL }
   };
diff --git a/app/operations/operations-enums.h b/app/operations/operations-enums.h
index 8bcfb06e00..e9cb41b3b3 100644
--- a/app/operations/operations-enums.h
+++ b/app/operations/operations-enums.h
@@ -153,10 +153,12 @@ typedef enum  /*< pdb-skip >*/
   GIMP_LAYER_MODE_CONTEXT_LAYER = 1 << 0,
   GIMP_LAYER_MODE_CONTEXT_GROUP = 1 << 1,
   GIMP_LAYER_MODE_CONTEXT_PAINT = 1 << 2,
+  GIMP_LAYER_MODE_CONTEXT_FADE  = 1 << 3,
 
   GIMP_LAYER_MODE_CONTEXT_ALL = (GIMP_LAYER_MODE_CONTEXT_LAYER |
                                  GIMP_LAYER_MODE_CONTEXT_GROUP |
-                                 GIMP_LAYER_MODE_CONTEXT_PAINT)
+                                 GIMP_LAYER_MODE_CONTEXT_PAINT |
+                                 GIMP_LAYER_MODE_CONTEXT_FADE)
 } GimpLayerModeContext;
 
 
diff --git a/app/tools/gimpfiltertool.c b/app/tools/gimpfiltertool.c
index 435bec9ffd..14fbb574d7 100644
--- a/app/tools/gimpfiltertool.c
+++ b/app/tools/gimpfiltertool.c
@@ -60,6 +60,8 @@
 #include "core/gimpsettings.h"
 #include "core/gimptoolinfo.h"
 
+#include "widgets/gimplayermodebox.h"
+#include "widgets/gimppropwidgets.h"
 #include "widgets/gimpsettingsbox.h"
 #include "widgets/gimpwidgets-utils.h"
 
@@ -913,6 +915,8 @@ gimp_filter_tool_real_config_notify (GimpFilterTool   *filter_tool,
   if (filter_tool->filter)
     {
       if (! strcmp (pspec->name, "gimp-clip")          ||
+          ! strcmp (pspec->name, "gimp-mode")          ||
+          ! strcmp (pspec->name, "gimp-opacity")       ||
           ! strcmp (pspec->name, "gimp-color-managed") ||
           ! strcmp (pspec->name, "gimp-gamma-hack"))
         {
@@ -1050,8 +1054,9 @@ gimp_filter_tool_dialog (GimpFilterTool *filter_tool)
 static void
 gimp_filter_tool_update_dialog_operation_settings (GimpFilterTool *filter_tool)
 {
-  GimpTool  *tool  = GIMP_TOOL (filter_tool);
-  GimpImage *image = gimp_display_get_image (tool->display);
+  GimpTool          *tool    = GIMP_TOOL (filter_tool);
+  GimpFilterOptions *options = GIMP_FILTER_TOOL_GET_OPTIONS (filter_tool);
+  GimpImage         *image   = gimp_display_get_image (tool->display);
 
   if (filter_tool->operation_settings_box)
     {
@@ -1065,6 +1070,8 @@ gimp_filter_tool_update_dialog_operation_settings (GimpFilterTool *filter_tool)
           GtkWidget *frame;
           GtkWidget *vbox2;
           GtkWidget *combo;
+          GtkWidget *mode_box;
+          GtkWidget *scale;
           GtkWidget *toggle;
 
           vbox = filter_tool->operation_settings_box;
@@ -1088,6 +1095,40 @@ gimp_filter_tool_update_dialog_operation_settings (GimpFilterTool *filter_tool)
           gtk_box_pack_start (GTK_BOX (vbox), filter_tool->region_combo,
                               FALSE, FALSE, 0);
 
+          /*  The Fade expander  */
+          expander = gtk_expander_new (_("Fade"));
+          gtk_box_pack_start (GTK_BOX (vbox), expander,
+                              FALSE, FALSE, 0);
+          gtk_widget_show (expander);
+
+          frame = gimp_frame_new (NULL);
+          gtk_container_add (GTK_CONTAINER (expander), frame);
+          gtk_widget_show (frame);
+
+          vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
+          gtk_container_add (GTK_CONTAINER (frame), vbox2);
+          gtk_widget_show (vbox2);
+
+          /*  The mode box  */
+          mode_box = gimp_prop_layer_mode_box_new (
+            filter_tool->config, "gimp-mode",
+            GIMP_LAYER_MODE_CONTEXT_FADE);
+          gimp_layer_mode_box_set_label (GIMP_LAYER_MODE_BOX (mode_box),
+                                         _("Mode"));
+          gtk_box_pack_start (GTK_BOX (vbox2), mode_box,
+                              FALSE, FALSE, 0);
+          gtk_widget_show (mode_box);
+
+          /*  The opacity scale  */
+          scale = gimp_prop_spin_scale_new (filter_tool->config,
+                                            "gimp-opacity",
+                                            NULL,
+                                            1.0, 10.0, 1);
+          gimp_prop_widget_set_factor (scale, 100.0, 1.0, 10.0, 1);
+          gtk_box_pack_start (GTK_BOX (vbox2), scale,
+                              FALSE, FALSE, 0);
+          gtk_widget_show (scale);
+
           /*  The Color Options expander  */
           expander = gtk_expander_new (_("Advanced Color Options"));
           gtk_box_pack_start (GTK_BOX (vbox), expander,


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