app: handle prepare-to-remove-slider signal in the blend tool

Add a tentative_gradient member to GimpBlendTool, which, when set,
is displayed instead of the current gradient.

Use this to show a version of the gradient with the currently
selected stop deleted, upon receiving a prepare-to-remove-slider
signal, i.e., when the slider is about to be removed.
This commit is contained in:
Ell 2017-10-06 12:11:45 -04:00
parent 9ae09fb03a
commit 63c8fc73dd
3 changed files with 111 additions and 27 deletions

View File

@ -49,29 +49,33 @@
/* local function prototypes */
static gboolean gimp_blend_tool_editor_line_can_add_slider (GimpToolLine *line,
gdouble value,
GimpBlendTool *blend_tool);
static gint gimp_blend_tool_editor_line_add_slider (GimpToolLine *line,
gdouble value,
GimpBlendTool *blend_tool);
static void gimp_blend_tool_editor_line_remove_slider (GimpToolLine *line,
gint slider,
GimpBlendTool *blend_tool);
static gboolean gimp_blend_tool_editor_line_can_add_slider (GimpToolLine *line,
gdouble value,
GimpBlendTool *blend_tool);
static gint gimp_blend_tool_editor_line_add_slider (GimpToolLine *line,
gdouble value,
GimpBlendTool *blend_tool);
static void gimp_blend_tool_editor_line_prepare_to_remove_slider (GimpToolLine *line,
gint slider,
gboolean remove,
GimpBlendTool *blend_tool);
static void gimp_blend_tool_editor_line_remove_slider (GimpToolLine *line,
gint slider,
GimpBlendTool *blend_tool);
static gboolean gimp_blend_tool_editor_is_gradient_editable (GimpBlendTool *blend_tool);
static gboolean gimp_blend_tool_editor_is_gradient_editable (GimpBlendTool *blend_tool);
static GimpGradientSegment * gimp_blend_tool_editor_handle_get_segment (GimpBlendTool *blend_tool,
gint handle);
static GimpGradientSegment * gimp_blend_tool_editor_handle_get_segment (GimpBlendTool *blend_tool,
gint handle);
static void gimp_blend_tool_editor_block_handlers (GimpBlendTool *blend_tool);
static void gimp_blend_tool_editor_unblock_handlers (GimpBlendTool *blend_tool);
static gboolean gimp_blend_tool_editor_are_handlers_blocked (GimpBlendTool *blend_tool);
static void gimp_blend_tool_editor_block_handlers (GimpBlendTool *blend_tool);
static void gimp_blend_tool_editor_unblock_handlers (GimpBlendTool *blend_tool);
static gboolean gimp_blend_tool_editor_are_handlers_blocked (GimpBlendTool *blend_tool);
static void gimp_blend_tool_editor_freeze_gradient (GimpBlendTool *blend_tool);
static void gimp_blend_tool_editor_thaw_gradient (GimpBlendTool *blend_tool);
static void gimp_blend_tool_editor_freeze_gradient (GimpBlendTool *blend_tool);
static void gimp_blend_tool_editor_thaw_gradient (GimpBlendTool *blend_tool);
static void gimp_blend_tool_editor_update_sliders (GimpBlendTool *blend_tool);
static void gimp_blend_tool_editor_update_sliders (GimpBlendTool *blend_tool);
/* private functions */
@ -122,6 +126,40 @@ gimp_blend_tool_editor_line_add_slider (GimpToolLine *line,
return slider;
}
static void
gimp_blend_tool_editor_line_prepare_to_remove_slider (GimpToolLine *line,
gint slider,
gboolean remove,
GimpBlendTool *blend_tool)
{
if (remove)
{
GimpGradient *tentative_gradient;
GimpGradientSegment *seg;
gint i;
tentative_gradient =
GIMP_GRADIENT (gimp_data_duplicate (GIMP_DATA (blend_tool->gradient)));
seg = gimp_blend_tool_editor_handle_get_segment (blend_tool, slider);
i = gimp_gradient_segment_range_get_n_segments (blend_tool->gradient,
blend_tool->gradient->segments,
seg) - 1;
seg = gimp_gradient_segment_get_nth (tentative_gradient->segments, i);
gimp_gradient_segment_range_merge (tentative_gradient,
seg, seg->next, NULL, NULL);
gimp_blend_tool_set_tentative_gradient (blend_tool, tentative_gradient);
}
else
{
gimp_blend_tool_set_tentative_gradient (blend_tool, NULL);
}
}
static void
gimp_blend_tool_editor_line_remove_slider (GimpToolLine *line,
gint slider,
@ -137,6 +175,8 @@ gimp_blend_tool_editor_line_remove_slider (GimpToolLine *line,
seg, seg->next, NULL, NULL);
gimp_blend_tool_editor_thaw_gradient (blend_tool);
gimp_blend_tool_set_tentative_gradient (blend_tool, NULL);
}
static gboolean
@ -404,6 +444,9 @@ gimp_blend_tool_editor_start (GimpBlendTool *blend_tool)
g_signal_connect (blend_tool->widget, "add-slider",
G_CALLBACK (gimp_blend_tool_editor_line_add_slider),
blend_tool);
g_signal_connect (blend_tool->widget, "prepare-to-remove-slider",
G_CALLBACK (gimp_blend_tool_editor_line_prepare_to_remove_slider),
blend_tool);
g_signal_connect (blend_tool->widget, "remove-slider",
G_CALLBACK (gimp_blend_tool_editor_line_remove_slider),
blend_tool);

View File

@ -908,13 +908,16 @@ gimp_blend_tool_gradient_dirty (GimpBlendTool *blend_tool)
if (! blend_tool->filter)
return;
/* Set a property on the node. Otherwise it will cache and refuse to update */
gegl_node_set (blend_tool->render_node,
"gradient", blend_tool->gradient,
NULL);
if (! blend_tool->tentative_gradient)
{
/* Set a property on the node. Otherwise it will cache and refuse to update */
gegl_node_set (blend_tool->render_node,
"gradient", blend_tool->gradient,
NULL);
/* Update the filter */
gimp_drawable_filter_apply (blend_tool->filter, NULL);
/* Update the filter */
gimp_drawable_filter_apply (blend_tool->filter, NULL);
}
gimp_blend_tool_editor_gradient_dirty (blend_tool);
}
@ -1039,3 +1042,34 @@ blend_info_free (BlendInfo *info)
{
g_slice_free (BlendInfo, info);
}
/* protected functions */
void
gimp_blend_tool_set_tentative_gradient (GimpBlendTool *blend_tool,
GimpGradient *gradient)
{
g_return_if_fail (GIMP_IS_BLEND_TOOL (blend_tool));
g_return_if_fail (gradient == NULL || GIMP_IS_GRADIENT (gradient));
if (gradient != blend_tool->tentative_gradient)
{
g_clear_object (&blend_tool->tentative_gradient);
blend_tool->tentative_gradient = gradient;
if (gradient)
g_object_ref (gradient);
if (blend_tool->render_node)
{
gegl_node_set (blend_tool->render_node,
"gradient", gradient ? gradient : blend_tool->gradient,
NULL);
gimp_drawable_filter_apply (blend_tool->filter, NULL);
}
}
}

View File

@ -40,6 +40,7 @@ struct _GimpBlendTool
GimpDrawTool parent_instance;
GimpGradient *gradient;
GimpGradient *tentative_gradient;
gdouble start_x; /* starting x coord */
gdouble start_y; /* starting y coord */
@ -73,10 +74,16 @@ struct _GimpBlendToolClass
};
void gimp_blend_tool_register (GimpToolRegisterCallback callback,
gpointer data);
void gimp_blend_tool_register (GimpToolRegisterCallback callback,
gpointer data);
GType gimp_blend_tool_get_type (void) G_GNUC_CONST;
GType gimp_blend_tool_get_type (void) G_GNUC_CONST;
/* protected functions */
void gimp_blend_tool_set_tentative_gradient (GimpBlendTool *blend_tool,
GimpGradient *gradient);
#endif /* __GIMP_BLEND_TOOL_H__ */