Merge branch 'alxsa-nde-gradient' into 'master'

Draft: Issue #10759: Add NDE option for Gradient tool

Closes #10759

See merge request GNOME/gimp!1324
This commit is contained in:
Alx Sa 2025-07-01 18:52:55 +00:00
commit b472ee368c
3 changed files with 42 additions and 3 deletions

View file

@ -51,7 +51,8 @@ enum
PROP_SUPERSAMPLE_THRESHOLD, PROP_SUPERSAMPLE_THRESHOLD,
PROP_DITHER, PROP_DITHER,
PROP_INSTANT, PROP_INSTANT,
PROP_MODIFY_ACTIVE PROP_MODIFY_ACTIVE,
PROP_APPLY_NON_DESTRUCTIVELY
}; };
@ -144,6 +145,14 @@ gimp_gradient_options_class_init (GimpGradientOptionsClass *klass)
_("Modify the active gradient in-place"), _("Modify the active gradient in-place"),
FALSE, FALSE,
GIMP_PARAM_STATIC_STRINGS); GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_APPLY_NON_DESTRUCTIVELY,
"apply-non-destructively",
_("Apply non-destructively"),
_("If enabled, gradient will be applied as "
"a non-destructive filter"),
FALSE,
GIMP_PARAM_STATIC_STRINGS);
} }
static void static void
@ -191,6 +200,9 @@ gimp_gradient_options_set_property (GObject *object,
case PROP_MODIFY_ACTIVE: case PROP_MODIFY_ACTIVE:
options->modify_active = g_value_get_boolean (value); options->modify_active = g_value_get_boolean (value);
break; break;
case PROP_APPLY_NON_DESTRUCTIVELY:
options->apply_non_destructively = g_value_get_boolean (value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@ -238,6 +250,9 @@ gimp_gradient_options_get_property (GObject *object,
case PROP_MODIFY_ACTIVE: case PROP_MODIFY_ACTIVE:
g_value_set_boolean (value, options->modify_active); g_value_set_boolean (value, options->modify_active);
break; break;
case PROP_APPLY_NON_DESTRUCTIVELY:
g_value_set_boolean (value, options->apply_non_destructively);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@ -349,6 +364,10 @@ gimp_gradient_options_gui (GimpToolOptions *tool_options)
options->instant_toggle = button; options->instant_toggle = button;
/* the non-destructive filter toggle */
button = gimp_prop_check_button_new (config, "apply-non-destructively", NULL);
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
/* the modify active toggle */ /* the modify active toggle */
vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2); vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
frame = gimp_prop_expanding_frame_new (config, "modify-active", NULL, frame = gimp_prop_expanding_frame_new (config, "modify-active", NULL,

View file

@ -49,6 +49,7 @@ struct _GimpGradientOptions
gboolean instant; gboolean instant;
gboolean modify_active; gboolean modify_active;
gboolean apply_non_destructively;
/* options gui */ /* options gui */
GtkWidget *instant_toggle; GtkWidget *instant_toggle;

View file

@ -45,6 +45,7 @@
#include "core/gimperror.h" #include "core/gimperror.h"
#include "core/gimpgradient.h" #include "core/gimpgradient.h"
#include "core/gimpimage.h" #include "core/gimpimage.h"
#include "core/gimpimage-undo-push.h"
#include "core/gimpprogress.h" #include "core/gimpprogress.h"
#include "core/gimpprojection.h" #include "core/gimpprojection.h"
@ -778,7 +779,8 @@ gimp_gradient_tool_halt (GimpGradientTool *gradient_tool)
static void static void
gimp_gradient_tool_commit (GimpGradientTool *gradient_tool) gimp_gradient_tool_commit (GimpGradientTool *gradient_tool)
{ {
GimpTool *tool = GIMP_TOOL (gradient_tool); GimpTool *tool = GIMP_TOOL (gradient_tool);
GimpGradientOptions *options = GIMP_GRADIENT_TOOL_GET_OPTIONS (gradient_tool);
if (gradient_tool->filter) if (gradient_tool->filter)
{ {
@ -790,8 +792,25 @@ gimp_gradient_tool_commit (GimpGradientTool *gradient_tool)
gimp_tool_control_push_preserve (tool->control, TRUE); gimp_tool_control_push_preserve (tool->control, TRUE);
gimp_drawable_filter_commit (gradient_tool->filter, FALSE, gimp_drawable_filter_commit (gradient_tool->filter,
options->apply_non_destructively,
GIMP_PROGRESS (tool), FALSE); GIMP_PROGRESS (tool), FALSE);
if (options->apply_non_destructively)
{
GimpDrawable *drawable =
gimp_drawable_filter_get_drawable (gradient_tool->filter);
gimp_drawable_filter_layer_mask_freeze (gradient_tool->filter);
gimp_image_undo_push_filter_add (gimp_display_get_image (tool->display),
_("Add filter"),
drawable, gradient_tool->filter);
}
g_signal_handlers_disconnect_by_func (gradient_tool->filter,
gimp_gradient_tool_filter_flush,
gradient_tool);
g_clear_object (&gradient_tool->filter); g_clear_object (&gradient_tool->filter);
gimp_tool_control_pop_preserve (tool->control); gimp_tool_control_pop_preserve (tool->control);