From 350c7ca338dcb37e3df6e13fb4dc603489aca166 Mon Sep 17 00:00:00 2001 From: Ell Date: Fri, 8 Jan 2016 13:18:10 +0000 Subject: [PATCH] app: Add "Diagonal neighbors" option to the bucket fill tool When checked, diagonally neighboring pixels are considered connected when calculating the affected area. This commit also adds a corresponding diagonal_neighbors parameter to gimp_drawable_bucket_fill(), and modifies the callers, other than the bucket fill tool, to pass FALSE for this parameter, to retain the current behavior. --- app/core/gimpdrawable-bucket-fill.c | 7 +++++-- app/core/gimpdrawable-bucket-fill.h | 1 + app/pdb/edit-cmds.c | 8 ++++++-- app/tools/gimpbucketfilloptions.c | 19 +++++++++++++++++++ app/tools/gimpbucketfilloptions.h | 1 + app/tools/gimpbucketfilltool.c | 1 + tools/pdbgen/pdb/edit.pdb | 10 +++++++--- 7 files changed, 40 insertions(+), 7 deletions(-) diff --git a/app/core/gimpdrawable-bucket-fill.c b/app/core/gimpdrawable-bucket-fill.c index 93d1bf6f6c..35bb048cc5 100644 --- a/app/core/gimpdrawable-bucket-fill.c +++ b/app/core/gimpdrawable-bucket-fill.c @@ -55,6 +55,7 @@ static void gimp_drawable_bucket_fill_internal (GimpDrawable *drawable, GimpSelectCriterion fill_criterion, gdouble threshold, gboolean sample_merged, + gboolean diagonal_neighbors, gdouble x, gdouble y, const GimpRGB *color, @@ -73,6 +74,7 @@ gimp_drawable_bucket_fill (GimpDrawable *drawable, GimpSelectCriterion fill_criterion, gdouble threshold, gboolean sample_merged, + gboolean diagonal_neighbors, gdouble x, gdouble y, GError **error) @@ -96,7 +98,7 @@ gimp_drawable_bucket_fill (GimpDrawable *drawable, paint_mode, opacity, fill_transparent, fill_criterion, threshold, sample_merged, - x, y, + diagonal_neighbors, x, y, &color, pattern); return TRUE; @@ -114,6 +116,7 @@ gimp_drawable_bucket_fill_internal (GimpDrawable *drawable, GimpSelectCriterion fill_criterion, gdouble threshold, gboolean sample_merged, + gboolean diagonal_neighbors, gdouble x, gdouble y, const GimpRGB *color, @@ -158,7 +161,7 @@ gimp_drawable_bucket_fill_internal (GimpDrawable *drawable, threshold, fill_transparent, fill_criterion, - FALSE /* no diagonal neighbors */, + diagonal_neighbors, (gint) x, (gint) y); diff --git a/app/core/gimpdrawable-bucket-fill.h b/app/core/gimpdrawable-bucket-fill.h index b4fe1eb8b2..2e2cf2bf0e 100644 --- a/app/core/gimpdrawable-bucket-fill.h +++ b/app/core/gimpdrawable-bucket-fill.h @@ -28,6 +28,7 @@ gboolean gimp_drawable_bucket_fill (GimpDrawable *drawable, GimpSelectCriterion fill_criterion, gdouble threshold, gboolean sample_merged, + gboolean diagonal_neighbors, gdouble x, gdouble y, GError **error); diff --git a/app/pdb/edit-cmds.c b/app/pdb/edit-cmds.c index bd69bc0a66..6829dc8777 100644 --- a/app/pdb/edit-cmds.c +++ b/app/pdb/edit-cmds.c @@ -636,7 +636,9 @@ edit_bucket_fill_invoker (GimpProcedure *procedure, FALSE /* don't fill transparent */, GIMP_SELECT_CRITERION_COMPOSITE, threshold / 255.0, - sample_merged, x, y, + sample_merged, + FALSE /* no diagonal neighbors */, + x, y, error); } } @@ -720,7 +722,9 @@ edit_bucket_fill_full_invoker (GimpProcedure *procedure, fill_transparent, select_criterion, threshold / 255.0, - sample_merged, x, y, + sample_merged, + FALSE /* no diagonal neighbors */, + x, y, error); } } diff --git a/app/tools/gimpbucketfilloptions.c b/app/tools/gimpbucketfilloptions.c index dffde6f819..38e8f5eb47 100644 --- a/app/tools/gimpbucketfilloptions.c +++ b/app/tools/gimpbucketfilloptions.c @@ -50,6 +50,7 @@ enum PROP_FILL_SELECTION, PROP_FILL_TRANSPARENT, PROP_SAMPLE_MERGED, + PROP_DIAGONAL_NEIGHBORS, PROP_THRESHOLD, PROP_FILL_CRITERION }; @@ -109,6 +110,12 @@ gimp_bucket_fill_options_class_init (GimpBucketFillOptionsClass *klass) "layers"), FALSE, GIMP_PARAM_STATIC_STRINGS); + GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_DIAGONAL_NEIGHBORS, + "diagonal-neighbors", + _("Treat diagonally neighboring pixels as " + "connected"), + FALSE, + GIMP_PARAM_STATIC_STRINGS); GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_THRESHOLD, "threshold", _("Maximum color difference"), @@ -157,6 +164,9 @@ gimp_bucket_fill_options_set_property (GObject *object, case PROP_SAMPLE_MERGED: options->sample_merged = g_value_get_boolean (value); break; + case PROP_DIAGONAL_NEIGHBORS: + options->diagonal_neighbors = g_value_get_boolean (value); + break; case PROP_THRESHOLD: options->threshold = g_value_get_double (value); break; @@ -192,6 +202,9 @@ gimp_bucket_fill_options_get_property (GObject *object, case PROP_SAMPLE_MERGED: g_value_set_boolean (value, options->sample_merged); break; + case PROP_DIAGONAL_NEIGHBORS: + g_value_set_boolean (value, options->diagonal_neighbors); + break; case PROP_THRESHOLD: g_value_set_double (value, options->threshold); break; @@ -291,6 +304,12 @@ gimp_bucket_fill_options_gui (GimpToolOptions *tool_options) gtk_box_pack_start (GTK_BOX (vbox2), button, FALSE, FALSE, 0); gtk_widget_show (button); + /* the diagonal neighbors toggle */ + button = gimp_prop_check_button_new (config, "diagonal-neighbors", + _("Diagonal neighbors")); + gtk_box_pack_start (GTK_BOX (vbox2), button, FALSE, FALSE, 0); + gtk_widget_show (button); + /* the threshold scale */ scale = gimp_prop_spin_scale_new (config, "threshold", _("Threshold"), diff --git a/app/tools/gimpbucketfilloptions.h b/app/tools/gimpbucketfilloptions.h index 7e6fed2431..083feefe57 100644 --- a/app/tools/gimpbucketfilloptions.h +++ b/app/tools/gimpbucketfilloptions.h @@ -41,6 +41,7 @@ struct _GimpBucketFillOptions gboolean fill_selection; gboolean fill_transparent; gboolean sample_merged; + gboolean diagonal_neighbors; gdouble threshold; GimpSelectCriterion fill_criterion; }; diff --git a/app/tools/gimpbucketfilltool.c b/app/tools/gimpbucketfilltool.c index 2a9be1667b..8feafec25c 100644 --- a/app/tools/gimpbucketfilltool.c +++ b/app/tools/gimpbucketfilltool.c @@ -221,6 +221,7 @@ gimp_bucket_fill_tool_button_release (GimpTool *tool, options->fill_criterion, options->threshold / 255.0, options->sample_merged, + options->diagonal_neighbors, x, y, &error); } diff --git a/tools/pdbgen/pdb/edit.pdb b/tools/pdbgen/pdb/edit.pdb index 164f5e9199..b0f4cff5fc 100644 --- a/tools/pdbgen/pdb/edit.pdb +++ b/tools/pdbgen/pdb/edit.pdb @@ -671,8 +671,10 @@ HELP paint_mode, opacity / 100.0, FALSE /* don't fill transparent */, GIMP_SELECT_CRITERION_COMPOSITE, - threshold / 255.0, - sample_merged, x, y, + threshold / 255.0, + sample_merged, + FALSE /* no diagonal neighbors */, + x, y, error); } } @@ -784,7 +786,9 @@ HELP fill_transparent, select_criterion, threshold / 255.0, - sample_merged, x, y, + sample_merged, + FALSE /* no diagonal neighbors */, + x, y, error); } }