app: avoid useless line art closure recomputation.

On various property changes, only recompute the line art when the
property actually changed. Also add a gimp_line_art_bind_gap_length() to
avoid computing twice the line art when changing both type of closure
(splines and segments) together, as is currently the case.
This commit is contained in:
Jehan 2019-03-04 16:43:19 +01:00
parent bc187cc5cc
commit c0996241f6
3 changed files with 46 additions and 20 deletions

View File

@ -80,6 +80,7 @@ struct _GimpLineArtPrivate
gdouble threshold;
gint spline_max_len;
gint segment_max_len;
gboolean max_len_bound;
/* Used in the grow step. */
gint max_grow;
@ -381,23 +382,39 @@ gimp_line_art_set_property (GObject *object,
switch (property_id)
{
case PROP_SELECT_TRANSPARENT:
line_art->priv->select_transparent = g_value_get_boolean (value);
gimp_line_art_compute (line_art);
if (line_art->priv->select_transparent != g_value_get_boolean (value))
{
line_art->priv->select_transparent = g_value_get_boolean (value);
gimp_line_art_compute (line_art);
}
break;
case PROP_MAX_GROW:
line_art->priv->max_grow = g_value_get_int (value);
break;
case PROP_THRESHOLD:
line_art->priv->threshold = g_value_get_double (value);
gimp_line_art_compute (line_art);
if (line_art->priv->threshold != g_value_get_double (value))
{
line_art->priv->threshold = g_value_get_double (value);
gimp_line_art_compute (line_art);
}
break;
case PROP_SPLINE_MAX_LEN:
line_art->priv->spline_max_len = g_value_get_int (value);
gimp_line_art_compute (line_art);
if (line_art->priv->spline_max_len != g_value_get_int (value))
{
line_art->priv->spline_max_len = g_value_get_int (value);
if (line_art->priv->max_len_bound)
line_art->priv->segment_max_len = line_art->priv->spline_max_len;
gimp_line_art_compute (line_art);
}
break;
case PROP_SEGMENT_MAX_LEN:
line_art->priv->segment_max_len = g_value_get_int (value);
gimp_line_art_compute (line_art);
if (line_art->priv->segment_max_len != g_value_get_int (value))
{
line_art->priv->segment_max_len = g_value_get_int (value);
if (line_art->priv->max_len_bound)
line_art->priv->spline_max_len = line_art->priv->segment_max_len;
gimp_line_art_compute (line_art);
}
break;
default:
@ -447,6 +464,13 @@ gimp_line_art_new (void)
NULL);
}
void
gimp_line_art_bind_gap_length (GimpLineArt *line_art,
gboolean bound)
{
line_art->priv->max_len_bound = bound;
}
void
gimp_line_art_set_input (GimpLineArt *line_art,
GimpPickable *pickable)

View File

@ -57,6 +57,9 @@ GType gimp_line_art_get_type (void) G_GNUC_CONST;
GimpLineArt * gimp_line_art_new (void);
void gimp_line_art_bind_gap_length (GimpLineArt *line_art,
gboolean bound);
void gimp_line_art_set_input (GimpLineArt *line_art,
GimpPickable *pickable);
GimpPickable * gimp_line_art_get_input (GimpLineArt *line_art);

View File

@ -235,6 +235,7 @@ gimp_bucket_fill_tool_constructed (GObject *object)
g_signal_connect_swapped (line_art, "computing-end",
G_CALLBACK (gimp_bucket_fill_tool_line_art_computing_end),
tool);
gimp_line_art_bind_gap_length (line_art, TRUE);
bucket_tool->priv->line_art = line_art;
gimp_bucket_fill_tool_reset_line_art (bucket_tool);
@ -800,19 +801,17 @@ gimp_bucket_fill_tool_options_notify (GimpTool *tool,
GIMP_TOOL_CLASS (parent_class)->options_notify (tool, options, pspec);
if (! strcmp (pspec->name, "fill-area"))
/* We want more motion events when the tool is used in a paint tool
* fashion. Unfortunately we only set exact mode in line art fill,
* because we can't as easily remove events from the similar color
* mode just because a point has already been selected (unless
* threshold were 0, but that's an edge case).
*/
gimp_tool_control_set_motion_mode (tool->control,
bucket_options->fill_area == GIMP_BUCKET_FILL_LINE_ART ?
GIMP_MOTION_MODE_EXACT : GIMP_MOTION_MODE_COMPRESS);
if (! strcmp (pspec->name, "fill-area") ||
! strcmp (pspec->name, "sample-merged"))
{
/* We want more motion events when the tool is used in a paint tool
* fashion. Unfortunately we only set exact mode in line art fill,
* because we can't as easily remove events from the similar color
* mode just because a point has already been selected (unless
* threshold were 0, but that's an edge case).
*/
gimp_tool_control_set_motion_mode (tool->control,
bucket_options->fill_area == GIMP_BUCKET_FILL_LINE_ART ?
GIMP_MOTION_MODE_EXACT : GIMP_MOTION_MODE_COMPRESS);
gimp_bucket_fill_tool_reset_line_art (bucket_tool);
}
else if (! strcmp (pspec->name, "fill-mode"))