Commit 236e4856 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

app/bucket_fill.c app/by_color_select.c app/fuzzy_select.c made the

2000-04-19  Michael Natterer  <mitch@gimp.org>

	* app/bucket_fill.c
	* app/by_color_select.c
	* app/fuzzy_select.c
	* app/preferences_dialog.c: made the "default_threshold" gimprc
	variable work as advertized:

	- initialize the thresholds with it.
	- use it for "Reset".
	- added a widget to the "Tool Options" preferences page.
	- noticed that the "Reset" button of "By Color Select" doesn't
	  behave like all the other "Reset" buttons and changed it to
	  reset the ui, not the selection.
	  (There is now a "None" button and because it was so trivial, I
	  couldn't resist to add "All" and "Invert" buttons, too)

	* libgimp/Makefile.am
	* libgimp/gimpui.c: new file.
	* libgimp/gimpui.h: new function gimp_ui_init() which will be
	called by all plugins which have a ui (not only by those with a
	preview because plugins should always follow gimp's colormap
	installation policy).

	Could someone please check if the FIXME stuff in the function
	is the right thing to do (TM). Does GdkRGB allocate the correct
	colors for the widgets in all cases or do we have to find another
	way to ensure this across processes (gtk instances)?
parent 4e875998
2000-04-19 Michael Natterer <mitch@gimp.org>
* app/bucket_fill.c
* app/by_color_select.c
* app/fuzzy_select.c
* app/preferences_dialog.c: made the "default_threshold" gimprc
variable work as advertized:
- initialize the thresholds with it.
- use it for "Reset".
- added a widget to the "Tool Options" preferences page.
- noticed that the "Reset" button of "By Color Select" doesn't
behave like all the other "Reset" buttons and changed it to
reset the ui, not the selection.
(There is now a "None" button and because it was so trivial, I
couldn't resist to add "All" and "Invert" buttons, too)
* libgimp/Makefile.am
* libgimp/gimpui.c: new file.
* libgimp/gimpui.h: new function gimp_ui_init() which will be
called by all plugins which have a ui (not only by those with a
preview because plugins should always follow gimp's colormap
installation policy).
Could someone please check if the FIXME stuff in the function
is the right thing to do (TM). Does GdkRGB allocate the correct
colors for the widgets in all cases or do we have to find another
way to ensure this across processes (gtk instances)?
2000-04-19 Sven Neumann <sven@gimp.org>
* plug-ins/common/mail.c: Changed "To:" and "From:" strings to
......
......@@ -26,6 +26,7 @@
#include "fuzzy_select.h"
#include "gdisplay.h"
#include "gimage_mask.h"
#include "gimprc.h"
#include "gimpui.h"
#include "interface.h"
#include "paint_funcs.h"
......@@ -52,7 +53,7 @@ struct _BucketOptions
PaintOptions paint_options;
gdouble threshold;
gdouble threshold_d;
/* gdouble threshold_d; (from gimprc) */
GtkObject *threshold_w;
gboolean sample_merged;
......@@ -93,7 +94,7 @@ bucket_options_reset (void)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->sample_merged_w),
options->sample_merged_d);
gtk_adjustment_set_value (GTK_ADJUSTMENT (options->threshold_w),
options->threshold_d);
default_threshold);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->fill_mode_w[options->fill_mode_d]), TRUE);
}
......@@ -114,7 +115,7 @@ bucket_options_new (void)
BUCKET_FILL,
bucket_options_reset);
options->sample_merged = options->sample_merged_d = FALSE;
options->threshold = options->threshold_d = 15.0;
options->threshold = default_threshold;
options->fill_mode = options->fill_mode_d = FG_BUCKET_FILL;
/* the main vbox */
......@@ -130,7 +131,7 @@ bucket_options_new (void)
gtk_widget_show (label);
options->threshold_w =
gtk_adjustment_new (options->threshold_d, 1.0, 255.0, 1.0, 1.0, 0.0);
gtk_adjustment_new (default_threshold, 1.0, 255.0, 1.0, 1.0, 0.0);
scale = gtk_hscale_new (GTK_ADJUSTMENT (options->threshold_w));
gtk_box_pack_start (GTK_BOX (hbox), scale, TRUE, TRUE, 0);
gtk_scale_set_value_pos (GTK_SCALE (scale), GTK_POS_TOP);
......
......@@ -37,7 +37,6 @@
#include "config.h"
#include "libgimp/gimpintl.h"
#define DEFAULT_FUZZINESS 15
#define PREVIEW_WIDTH 256
#define PREVIEW_HEIGHT 256
#define PREVIEW_EVENT_MASK GDK_EXPOSURE_MASK | \
......@@ -63,6 +62,9 @@ struct _ByColorDialog
GtkWidget *preview;
GtkWidget *gimage_name;
GtkWidget *replace_button;
GtkObject *threshold_adj;
gint threshold; /* threshold value for color select */
gint operation; /* Add, Subtract, Replace */
GImage *gimage; /* gimage which is currently under examination */
......@@ -104,6 +106,9 @@ static void by_color_select_draw (ByColorDialog *, GImage *);
static gint by_color_select_preview_events (GtkWidget *,
GdkEventButton *,
ByColorDialog *);
static void by_color_select_invert_callback (GtkWidget *, gpointer);
static void by_color_select_select_all_callback (GtkWidget *, gpointer);
static void by_color_select_select_none_callback (GtkWidget *, gpointer);
static void by_color_select_reset_callback (GtkWidget *, gpointer);
static void by_color_select_close_callback (GtkWidget *, gpointer);
static void by_color_select_preview_button_press (ByColorDialog *,
......@@ -672,12 +677,13 @@ by_color_select_dialog_new (void)
GtkWidget *label;
GtkWidget *util_box;
GtkWidget *slider;
GtkObject *data;
GtkWidget *table;
GtkWidget *button;
bcd = g_new (ByColorDialog, 1);
bcd->gimage = NULL;
bcd->operation = SELECTION_REPLACE;
bcd->threshold = DEFAULT_FUZZINESS;
bcd->threshold = default_threshold;
/* The shell and main vbox */
bcd->shell = gimp_dialog_new (_("By Color Selection"), "by_color_selection",
......@@ -749,12 +755,13 @@ by_color_select_dialog_new (void)
&bcd->operation,
(gpointer) bcd->operation,
_("Replace"), (gpointer) SELECTION_REPLACE, NULL,
_("Add"), (gpointer) SELECTION_ADD, NULL,
_("Subtract"), (gpointer) SELECTION_SUB, NULL,
_("Intersect"), (gpointer) SELECTION_INTERSECT, NULL,
_("Replace"), (gpointer) SELECTION_REPLACE,
&bcd->replace_button,
_("Add"), (gpointer) SELECTION_ADD, NULL,
_("Subtract"), (gpointer) SELECTION_SUB, NULL,
_("Intersect"), (gpointer) SELECTION_INTERSECT, NULL,
NULL);
NULL);
gtk_box_pack_start (GTK_BOX (options_box), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
......@@ -769,18 +776,51 @@ by_color_select_dialog_new (void)
gtk_widget_show (label);
gtk_widget_show (util_box);
data = gtk_adjustment_new (bcd->threshold, 0.0, 255.0, 1.0, 1.0, 0.0);
slider = gtk_hscale_new (GTK_ADJUSTMENT (data));
bcd->threshold_adj =
gtk_adjustment_new (bcd->threshold, 0.0, 255.0, 1.0, 1.0, 0.0);
slider = gtk_hscale_new (GTK_ADJUSTMENT (bcd->threshold_adj));
gtk_box_pack_start (GTK_BOX (util_box), slider, TRUE, TRUE, 0);
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
gtk_signal_connect (GTK_OBJECT (data), "value_changed",
gtk_signal_connect (GTK_OBJECT (bcd->threshold_adj), "value_changed",
GTK_SIGNAL_FUNC (gimp_int_adjustment_update),
&bcd->threshold);
gtk_widget_show (slider);
frame = gtk_frame_new (_("Selection"));
gtk_box_pack_end (GTK_BOX (options_box), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
table = gtk_table_new (2, 2, TRUE);
gtk_container_set_border_width (GTK_CONTAINER (table), 2);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_container_add (GTK_CONTAINER (frame), table);
gtk_widget_show (table);
button = gtk_button_new_with_label (_("Invert"));
gtk_table_attach_defaults (GTK_TABLE (table), button, 0, 2, 0, 1);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (by_color_select_invert_callback),
bcd);
gtk_widget_show (button);
button = gtk_button_new_with_label (_("All"));
gtk_table_attach_defaults (GTK_TABLE (table), button, 0, 1, 1, 2);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (by_color_select_select_all_callback),
bcd);
gtk_widget_show (button);
button = gtk_button_new_with_label (_("None"));
gtk_table_attach_defaults (GTK_TABLE (table), button, 1, 2, 1, 2);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (by_color_select_select_none_callback),
bcd);
gtk_widget_show (button);
gtk_widget_show (options_box);
gtk_widget_show (hbox);
gtk_widget_show (bcd->shell);
......@@ -944,6 +984,71 @@ by_color_select_reset_callback (GtkWidget *widget,
bcd = (ByColorDialog *) data;
gtk_widget_activate (bcd->replace_button);
gtk_adjustment_set_value (GTK_ADJUSTMENT (bcd->threshold_adj),
default_threshold);
}
static void
by_color_select_invert_callback (GtkWidget *widget,
gpointer data)
{
ByColorDialog *bcd;
bcd = (ByColorDialog *) data;
if (!bcd->gimage)
return;
/* check if the image associated to the mask still exists */
if (!drawable_gimage (GIMP_DRAWABLE (gimage_get_mask (bcd->gimage))))
return;
/* invert the mask */
gimage_mask_invert (bcd->gimage);
/* show selection on all views */
gdisplays_flush ();
/* update the preview window */
by_color_select_render (bcd, bcd->gimage);
by_color_select_draw (bcd, bcd->gimage);
}
static void
by_color_select_select_all_callback (GtkWidget *widget,
gpointer data)
{
ByColorDialog *bcd;
bcd = (ByColorDialog *) data;
if (!bcd->gimage)
return;
/* check if the image associated to the mask still exists */
if (!drawable_gimage (GIMP_DRAWABLE (gimage_get_mask (bcd->gimage))))
return;
/* fill the mask */
gimage_mask_all (bcd->gimage);
/* show selection on all views */
gdisplays_flush ();
/* update the preview window */
by_color_select_render (bcd, bcd->gimage);
by_color_select_draw (bcd, bcd->gimage);
}
static void
by_color_select_select_none_callback (GtkWidget *widget,
gpointer data)
{
ByColorDialog *bcd;
bcd = (ByColorDialog *) data;
if (!bcd->gimage)
return;
......
......@@ -126,6 +126,7 @@ static gint old_use_help;
static gint old_nav_window_per_display;
static gint old_info_window_follows_mouse;
static gint old_help_browser;
static gint old_default_threshold;
/* variables which can't be changed on the fly */
static gint edit_stingy_memory_use;
......@@ -188,7 +189,7 @@ static GtkWidget * prefs_dlg = NULL;
Here are the remaining issues as I see them:
Still no settings for default-gradient, default-palette,
gamma-correction, color-cube.
gamma-correction.
No widget for confirm-on-close although a lot of stuff is there.
......@@ -666,7 +667,10 @@ file_prefs_save_callback (GtkWidget *widget,
{
update = g_list_append (update, "help-browser");
}
if (default_threshold != old_default_threshold)
{
update = g_list_append (update, "default-threshold");
}
/* values which can't be changed on the fly */
if (edit_stingy_memory_use != old_stingy_memory_use)
......@@ -836,6 +840,7 @@ file_prefs_cancel_callback (GtkWidget *widget,
trust_dirty_flag = old_trust_dirty_flag;
use_help = old_use_help;
help_browser = old_help_browser;
default_threshold = old_default_threshold;
/* restore variables which need some magic */
if (preview_size != old_preview_size)
......@@ -1046,7 +1051,7 @@ static void
file_prefs_default_size_callback (GtkWidget *widget,
gpointer data)
{
default_width =
default_width =
(gint) (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 0) + 0.5);
default_height =
(gint) (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 1) + 0.5);
......@@ -1392,6 +1397,7 @@ file_pref_cmd_callback (GtkWidget *widget,
old_trust_dirty_flag = trust_dirty_flag;
old_use_help = use_help;
old_help_browser = help_browser;
old_default_threshold = default_threshold;
file_prefs_strset (&old_image_title_format, image_title_format);
file_prefs_strset (&old_default_comment, default_comment);
......@@ -2042,6 +2048,28 @@ file_pref_cmd_callback (GtkWidget *widget,
&global_paint_options);
gtk_widget_show (button);
vbox2 = file_prefs_frame_new (_("Finding Contiguous Regions"),
GTK_BOX (vbox));
table = gtk_table_new (1, 2, FALSE);
gtk_container_set_border_width (GTK_CONTAINER (table), 2);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
gtk_box_pack_start (GTK_BOX (vbox2), table, FALSE, FALSE, 0);
gtk_widget_show (table);
/* Default threshold */
spinbutton =
gimp_spin_button_new (&adjustment,
default_threshold, 0.0, 255.0,
1.0, 5.0, 0.0, 1.0, 0.0);
gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed",
GTK_SIGNAL_FUNC (gimp_int_adjustment_update),
&default_threshold);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Default Threshold:"), 1.0, 0.5,
spinbutton, 1, TRUE);
/* Expand the "Interface" branch */
gtk_ctree_expand (GTK_CTREE (ctree), top_insert);
......
......@@ -63,7 +63,7 @@ struct _FuzzySelectOptions
{
SelectionOptions selection_options;
gdouble threshold;
gdouble threshold_d;
/* gdouble threshold_d; (from gimprc) */
GtkObject *threshold_w;
};
......@@ -631,7 +631,7 @@ fuzzy_select_options_reset (void)
selection_options_reset ((SelectionOptions *)options);
gtk_adjustment_set_value (GTK_ADJUSTMENT (options->threshold_w),
options->threshold_d);
default_threshold);
}
static FuzzySelectOptions *
......@@ -648,7 +648,7 @@ fuzzy_select_options_new (void)
selection_options_init ((SelectionOptions *) options,
FUZZY_SELECT,
fuzzy_select_options_reset);
options->threshold = options->threshold_d = default_threshold;
options->threshold = default_threshold;
/* the main vbox */
vbox = ((ToolOptions *) options)->main_vbox;
......@@ -663,7 +663,7 @@ fuzzy_select_options_new (void)
gtk_widget_show (label);
options->threshold_w =
gtk_adjustment_new (options->threshold_d, 0.0, 255.0, 1.0, 1.0, 0.0);
gtk_adjustment_new (default_threshold, 0.0, 255.0, 1.0, 1.0, 0.0);
scale = gtk_hscale_new (GTK_ADJUSTMENT (options->threshold_w));
gtk_box_pack_start (GTK_BOX (hbox), scale, TRUE, TRUE, 0);
gtk_scale_set_value_pos (GTK_SCALE (scale), GTK_POS_TOP);
......
......@@ -126,6 +126,7 @@ static gint old_use_help;
static gint old_nav_window_per_display;
static gint old_info_window_follows_mouse;
static gint old_help_browser;
static gint old_default_threshold;
/* variables which can't be changed on the fly */
static gint edit_stingy_memory_use;
......@@ -188,7 +189,7 @@ static GtkWidget * prefs_dlg = NULL;
Here are the remaining issues as I see them:
Still no settings for default-gradient, default-palette,
gamma-correction, color-cube.
gamma-correction.
No widget for confirm-on-close although a lot of stuff is there.
......@@ -666,7 +667,10 @@ file_prefs_save_callback (GtkWidget *widget,
{
update = g_list_append (update, "help-browser");
}
if (default_threshold != old_default_threshold)
{
update = g_list_append (update, "default-threshold");
}
/* values which can't be changed on the fly */
if (edit_stingy_memory_use != old_stingy_memory_use)
......@@ -836,6 +840,7 @@ file_prefs_cancel_callback (GtkWidget *widget,
trust_dirty_flag = old_trust_dirty_flag;
use_help = old_use_help;
help_browser = old_help_browser;
default_threshold = old_default_threshold;
/* restore variables which need some magic */
if (preview_size != old_preview_size)
......@@ -1046,7 +1051,7 @@ static void
file_prefs_default_size_callback (GtkWidget *widget,
gpointer data)
{
default_width =
default_width =
(gint) (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 0) + 0.5);
default_height =
(gint) (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 1) + 0.5);
......@@ -1392,6 +1397,7 @@ file_pref_cmd_callback (GtkWidget *widget,
old_trust_dirty_flag = trust_dirty_flag;
old_use_help = use_help;
old_help_browser = help_browser;
old_default_threshold = default_threshold;
file_prefs_strset (&old_image_title_format, image_title_format);
file_prefs_strset (&old_default_comment, default_comment);
......@@ -2042,6 +2048,28 @@ file_pref_cmd_callback (GtkWidget *widget,
&global_paint_options);
gtk_widget_show (button);
vbox2 = file_prefs_frame_new (_("Finding Contiguous Regions"),
GTK_BOX (vbox));
table = gtk_table_new (1, 2, FALSE);
gtk_container_set_border_width (GTK_CONTAINER (table), 2);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
gtk_box_pack_start (GTK_BOX (vbox2), table, FALSE, FALSE, 0);
gtk_widget_show (table);
/* Default threshold */
spinbutton =
gimp_spin_button_new (&adjustment,
default_threshold, 0.0, 255.0,
1.0, 5.0, 0.0, 1.0, 0.0);
gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed",
GTK_SIGNAL_FUNC (gimp_int_adjustment_update),
&default_threshold);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Default Threshold:"), 1.0, 0.5,
spinbutton, 1, TRUE);
/* Expand the "Interface" branch */
gtk_ctree_expand (GTK_CTREE (ctree), top_insert);
......
......@@ -126,6 +126,7 @@ static gint old_use_help;
static gint old_nav_window_per_display;
static gint old_info_window_follows_mouse;
static gint old_help_browser;
static gint old_default_threshold;
/* variables which can't be changed on the fly */
static gint edit_stingy_memory_use;
......@@ -188,7 +189,7 @@ static GtkWidget * prefs_dlg = NULL;
Here are the remaining issues as I see them:
Still no settings for default-gradient, default-palette,
gamma-correction, color-cube.
gamma-correction.
No widget for confirm-on-close although a lot of stuff is there.
......@@ -666,7 +667,10 @@ file_prefs_save_callback (GtkWidget *widget,
{
update = g_list_append (update, "help-browser");
}
if (default_threshold != old_default_threshold)
{
update = g_list_append (update, "default-threshold");
}
/* values which can't be changed on the fly */
if (edit_stingy_memory_use != old_stingy_memory_use)
......@@ -836,6 +840,7 @@ file_prefs_cancel_callback (GtkWidget *widget,
trust_dirty_flag = old_trust_dirty_flag;
use_help = old_use_help;
help_browser = old_help_browser;
default_threshold = old_default_threshold;
/* restore variables which need some magic */
if (preview_size != old_preview_size)
......@@ -1046,7 +1051,7 @@ static void
file_prefs_default_size_callback (GtkWidget *widget,
gpointer data)
{
default_width =
default_width =
(gint) (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 0) + 0.5);
default_height =
(gint) (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 1) + 0.5);
......@@ -1392,6 +1397,7 @@ file_pref_cmd_callback (GtkWidget *widget,
old_trust_dirty_flag = trust_dirty_flag;
old_use_help = use_help;
old_help_browser = help_browser;
old_default_threshold = default_threshold;
file_prefs_strset (&old_image_title_format, image_title_format);
file_prefs_strset (&old_default_comment, default_comment);
......@@ -2042,6 +2048,28 @@ file_pref_cmd_callback (GtkWidget *widget,
&global_paint_options);
gtk_widget_show (button);
vbox2 = file_prefs_frame_new (_("Finding Contiguous Regions"),
GTK_BOX (vbox));
table = gtk_table_new (1, 2, FALSE);
gtk_container_set_border_width (GTK_CONTAINER (table), 2);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
gtk_box_pack_start (GTK_BOX (vbox2), table, FALSE, FALSE, 0);
gtk_widget_show (table);
/* Default threshold */
spinbutton =
gimp_spin_button_new (&adjustment,
default_threshold, 0.0, 255.0,
1.0, 5.0, 0.0, 1.0, 0.0);
gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed",
GTK_SIGNAL_FUNC (gimp_int_adjustment_update),
&default_threshold);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Default Threshold:"), 1.0, 0.5,
spinbutton, 1, TRUE);
/* Expand the "Interface" branch */
gtk_ctree_expand (GTK_CTREE (ctree), top_insert);
......
......@@ -26,6 +26,7 @@
#include "fuzzy_select.h"
#include "gdisplay.h"
#include "gimage_mask.h"
#include "gimprc.h"
#include "gimpui.h"
#include "interface.h"
#include "paint_funcs.h"
......@@ -52,7 +53,7 @@ struct _BucketOptions
PaintOptions paint_options;
gdouble threshold;
gdouble threshold_d;
/* gdouble threshold_d; (from gimprc) */
GtkObject *threshold_w;
gboolean sample_merged;
......@@ -93,7 +94,7 @@ bucket_options_reset (void)
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->sample_merged_w),
options->sample_merged_d);
gtk_adjustment_set_value (GTK_ADJUSTMENT (options->threshold_w),
options->threshold_d);
default_threshold);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (options->fill_mode_w[options->fill_mode_d]), TRUE);
}
......@@ -114,7 +115,7 @@ bucket_options_new (void)
BUCKET_FILL,
bucket_options_reset);
options->sample_merged = options->sample_merged_d = FALSE;
options->threshold = options->threshold_d = 15.0;
options->threshold = default_threshold;
options->fill_mode = options->fill_mode_d = FG_BUCKET_FILL;
/* the main vbox */
......@@ -130,7 +131,7 @@ bucket_options_new (void)
gtk_widget_show (label);
options->threshold_w =
gtk_adjustment_new (options->threshold_d, 1.0, 255.0, 1.0, 1.0, 0.0);
gtk_adjustment_new (default_threshold, 1.0, 255.0, 1.0, 1.0, 0.0);
scale = gtk_hscale_new (GTK_ADJUSTMENT (options->threshold_w));
gtk_box_pack_start (GTK_BOX (hbox), scale, TRUE, TRUE, 0);
gtk_scale_set_value_pos (GTK_SCALE (scale), GTK_POS_TOP);
......
......@@ -37,7 +37,6 @@
#include "config.h"
#include "libgimp/gimpintl.h"
#define DEFAULT_FUZZINESS 15
#define PREVIEW_WIDTH 256
#define PREVIEW_HEIGHT 256
#define PREVIEW_EVENT_MASK GDK_EXPOSURE_MASK | \
......@@ -63,6 +62,9 @@ struct _ByColorDialog
GtkWidget *preview;
GtkWidget *gimage_name;
GtkWidget *replace_button;
GtkObject *threshold_adj;
gint threshold; /* threshold value for color select */
gint operation; /* Add, Subtract, Replace */
GImage *gimage; /* gimage which is currently under examination */
......@@ -104,6 +106,9 @@ static void by_color_select_draw (ByColorDialog *, GImage *);
static gint by_color_select_preview_events (GtkWidget *,
GdkEventButton *,
ByColorDialog *);
static void by_color_select_invert_callback (GtkWidget *, gpointer);
static void by_color_select_select_all_callback (GtkWidget *, gpointer);
static void by_color_select_select_none_callback (GtkWidget *, gpointer);
static void by_color_select_reset_callback (GtkWidget *, gpointer);
static void by_color_select_close_callback (GtkWidget *, gpointer);
static void by_color_select_preview_button_press (ByColorDialog *,
......@@ -672,12 +677,13 @@ by_color_select_dialog_new (void)
GtkWidget *label;
GtkWidget *util_box;
GtkWidget *slider;
GtkObject *data;
GtkWidget *table;
GtkWidget *button;
bcd = g_new (ByColorDialog, 1);
bcd->gimage = NULL;
bcd->operation = SELECTION_REPLACE;
bcd->threshold = DEFAULT_FUZZINESS;
bcd->threshold = default_threshold;
/* The shell and main vbox */
bcd->shell = gimp_dialog_new (_("By Color Selection"), "by_color_selection",
......@@ -749,12 +755,13 @@ by_color_select_dialog_new (void)
&bcd->operation,
(gpointer) bcd->operation,
_("Replace"), (gpointer) SELECTION_REPLACE, NULL,
_("Add"), (gpointer) SELECTION_ADD, NULL,
_("Subtract"), (gpointer) SELECTION_SUB, NULL,
_("Intersect"), (gpointer) SELECTION_INTERSECT, NULL,
_("Replace"), (gpointer) SELECTION_REPLACE,
&bcd->replace_button,
_("Add"), (gpointer) SELECTION_ADD, NULL,
_("Subtract"), (gpointer) SELECTION_SUB, NULL,
_("Intersect"), (gpointer) SELECTION_INTERSECT, NULL,
NULL);
NULL);
gtk_box_pack_start (GTK_BOX (options_box), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
......@@ -769,18 +776,51 @@ by_color_select_dialog_new (void)
gtk_widget_show (label);
gtk_widget_show (util_box);
data = gtk_adjustment_new (bcd->threshold, 0.0, 255.0, 1.0, 1.0, 0.0);
slider = gtk_hscale_new (GTK_ADJUSTMENT (data));
bcd->threshold_adj =
gtk_adjustment_new (bcd->threshold, 0.0, 255.0, 1.0, 1.0, 0.0);
slider = gtk_hscale_new (GTK_ADJUSTMENT (bcd->threshold_adj));
gtk_box_pack_start (GTK_BOX (util_box), slider, TRUE, TRUE, 0);
gtk_scale_set_value_pos (GTK_SCALE (slider), GTK_POS_TOP);
gtk_range_set_update_policy (GTK_RANGE (slider), GTK_UPDATE_DELAYED);
gtk_signal_connect (GTK_OBJECT (data), "value_changed",
gtk_signal_connect (GTK_OBJECT (bcd->threshold_adj), "value_changed",
GTK_SIGNAL_FUNC (gimp_int_adjustment_update),
&bcd->threshold);
gtk_widget_show (slider);
frame = gtk_frame_new (_("Selection"));
gtk_box_pack_end (GTK_BOX (options_box), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
table = gtk_table_new (2, 2, TRUE);
gtk_container_set_border_width (GTK_CONTAINER (table), 2);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_container_add (GTK_CONTAINER (frame), table);
gtk_widget_show (table);
button = gtk_button_new_with_label (_("Invert"));
gtk_table_attach_defaults (GTK_TABLE (table), button, 0, 2, 0, 1);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (by_color_select_invert_callback),
bcd);
gtk_widget_show (button);
button = gtk_button_new_with_label (_("All"));
gtk_table_attach_defaults (GTK_TABLE (table), button, 0, 1, 1, 2);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (by_color_select_select_all_callback),
bcd);
gtk_widget_show (button);
button = gtk_button_new_with_label (_("None"));
gtk_table_attach_defaults (GTK_TABLE (table), button, 1, 2, 1, 2);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (by_color_select_select_none_callback),
bcd);
gtk_widget_show (button);
gtk_widget_show (options_box);
gtk_widget_show (hbox);
gtk_widget_show (bcd->shell);
......@@ -944,6 +984,71 @@ by_color_select_reset_callback (GtkWidget *widget,
bcd = (ByColorDialog *) data;
gtk_widget_activate (bcd->replace_button);
gtk_adjustment_set_value (GTK_ADJUSTMENT (bcd->threshold_adj),
default_threshold);
}
static void
by_color_select_invert_callback (GtkWidget *widget,
gpointer data)
{
ByColorDialog *bcd;
bcd = (ByColorDialog *) data;
if (!bcd->gimage)
return;
/* check if the image associated to the mask still exists */
if (!drawable_gimage (GIMP_DRAWABLE (gimage_get_mask (bcd->gimage))))
return;
/* invert the mask */
gimage_mask_invert (bcd->gimage);
/* show selection on all views */
gdisplays_flush ();
/* update the preview window */
by_color_select_render (bcd, bcd->gimage);
by_color_select_draw (bcd, bcd->gimage);
}