tools: Add NDE option for Gradient tool

This adds a new toggle that lets the user
choose to apply a gradient as a
non-destructive filter (off by default)
This commit is contained in:
Alx Sa 2024-02-06 13:28:40 +00:00
parent f2681ac49c
commit 99eeb94704
3 changed files with 42 additions and 3 deletions

View file

@ -51,7 +51,8 @@ enum
PROP_SUPERSAMPLE_THRESHOLD,
PROP_DITHER,
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"),
FALSE,
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
@ -191,6 +200,9 @@ gimp_gradient_options_set_property (GObject *object,
case PROP_MODIFY_ACTIVE:
options->modify_active = g_value_get_boolean (value);
break;
case PROP_APPLY_NON_DESTRUCTIVELY:
options->apply_non_destructively = g_value_get_boolean (value);
break;
default:
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:
g_value_set_boolean (value, options->modify_active);
break;
case PROP_APPLY_NON_DESTRUCTIVELY:
g_value_set_boolean (value, options->apply_non_destructively);
break;
default:
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;
/* 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 */
vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
frame = gimp_prop_expanding_frame_new (config, "modify-active", NULL,

View file

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

View file

@ -43,6 +43,7 @@
#include "core/gimperror.h"
#include "core/gimpgradient.h"
#include "core/gimpimage.h"
#include "core/gimpimage-undo-push.h"
#include "core/gimpprogress.h"
#include "core/gimpprojection.h"
@ -757,7 +758,8 @@ gimp_gradient_tool_halt (GimpGradientTool *gradient_tool)
static void
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)
{
@ -769,8 +771,25 @@ gimp_gradient_tool_commit (GimpGradientTool *gradient_tool)
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);
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);
gimp_tool_control_pop_preserve (tool->control);