gimp/app/tools/gimpbycolorselecttool.c

1226 lines
33 KiB
C
Raw Normal View History

1997-11-25 06:05:25 +08:00
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1997-11-25 06:05:25 +08:00
*/
#include "config.h"
#include <gdk/gdkkeysyms.h>
1997-11-25 06:05:25 +08:00
#include "appenv.h"
#include "boundary.h"
#include "by_color_select.h"
#include "cursorutil.h"
1997-11-25 06:05:25 +08:00
#include "drawable.h"
#include "draw_core.h"
#include "gimage_mask.h"
#include "gimpdnd.h"
1997-11-25 06:05:25 +08:00
#include "gimprc.h"
namespace cleanups. 1999-06-21 Michael Natterer <mitschel@cs.tu-berlin.de> * app/context_manager.c: namespace cleanups. * app/commands.[ch] * app/menus.c: moved the "Toggle Selection" menu entry to "View", sprinkled some separators and made the layers/channels/paths popup menus consistent with Tigert's last ops buttons change. * app/fileops.c * app/plug_in.c: check for gdisplay_active() returning NULL in some more places. * app/[all tool related files]: - Turned the ToolAction and ToolState #define's into typedef'ed enums, so the compiler can do some more sanity checking. - Removed one more unused global variable "active_tool_layer". - Removed some #include's from tools.c. - Standardized the individual tools' structure names. - Moved showing/hiding the tool options to separate functions. - Stuff... * app/commands.c * app/disp_callbacks.c * app/gdisplay.c * app/tools.c: fixed the segfaults which happened when the image of one of the tools which have dialogs (levels/posterize/...) was deleted. My approach was to do stricter sanity checking and to set some gdisplay pointers correctly where appropriate, so I can't tell exactly where the bug was. The curves tool now(??) updates on every _second_ display change only, which is really obscure. Finding/changing the display to operate on should definitely be done by connecting to the user context's "display_changed" signal. * app/gimpset.c: emit the "remove" signal _after_ removing the pointer from the set. If this was not a bug but a feature, please let me know, we'll need two signals then.
1999-06-22 06:12:07 +08:00
#include "gimpset.h"
app/Makefile.am app/gimphelp.[ch] new files 1999-09-27 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/gimphelp.[ch] * app/gimpui.[ch]: new files * app/interface.[ch] * app/preferences_dialog.[ch] The GIMP Help System part 1: Press "F1" in any dialog to pop up the help page for this dialog. Moved the widget constructors from preferences_dialog.[ch] and the query boxes from interface.[ch] to gimpui.[ch]. The dialog constructors take a help_func and a help_data parameter and install the "F1" accelerator which emits the new "help" signal. The "help" signal callback calls help_func(help_data) which finally has to call gimp_help() which in turn invokes the help browser. Still have to find a proper way to (1) prevent "F1" being assigned to some menu item and (2) to catch "F1" while browsing the menu trees in order to pop up the help for the selected item. * app/menus.c: a <Toolbox>/File/Help... menu item. * app/commands.[ch]: a command callback for the "Help..." menu item. * app/gimprc.[ch]: new boolean gimprc variable "use_help". * app/info_dialog.[ch]: pass a help function and data to the info dialog constructor. * app/tools.[ch]: store the tools help page names in the tool info structure. Export a special tools_help_func() which shows the help page for the active tool. * app/[all files calling a dialog constructor]: pass the dialog's help page to the constructor. Most dialogs are now created by gimp_dialog_new() which also sets up the action_area and the WM delete event callback, so I removed the resp. code from these files. Fixed some minor bugs and did some other stuff but didn't change any logic except dialog creation. * plug-ins/helpbrowser/helpbrowser.c: don't try to call a running help browser and don't install any menu path (all done in app/gimphelp.[ch] now).
1999-09-28 01:58:10 +08:00
#include "gimpui.h"
1997-11-25 06:05:25 +08:00
#include "gdisplay.h"
app/airbrush.c app/bezier_select.c app/blend.c app/brightness_contrast.c 1999-04-12 Michael Natterer <mitschel@cs.tu-berlin.de> * app/airbrush.c * app/bezier_select.c * app/blend.c * app/brightness_contrast.c * app/bucket_fill.c * app/by_color_select.c * app/clone.c * app/color_balance.c * app/color_picker.c * app/convolve.c * app/crop.c * app/curves.c * app/ellipse_select.c * app/eraser.c * app/flip_tool.c * app/free_select.c * app/fuzzy_select.c * app/histogram_tool.c * app/hue_saturation.c * app/ink.c * app/iscissors.c * app/levels.c * app/magnify.c * app/move.c * app/paintbrush.c * app/pencil.c * app/posterize.c * app/rect_select.[ch] * app/text_tool.c * app/threshold.c * app/transform_tool.c * app/tools.[ch] * app/toolsF.h: again: all tools :( * app/Makefile.am * app/tool_options.[ch] * app/selection_options.h * app/tool_options_ui.h: new files. Ok, this time it's general enough for future extensions: - The tool options structures are organized like the gtk object system to allow derived tool options. - Renamed all create and reset functions to *_options_new() and *_options_reset() to reflect this. - Changed tools_register() again. Now it takes just a pointer to a ToolOptions structure. - Moved almost the entire tool options gui code to tool_options.c. - Visually separated the common selection options from the tool-specific ones. I'd like to do the same with opacity/paint mode in all paint tool options but I think this needs some more discussion. * app/histogram_tool.c: changed packing boxes, label alignments. * app/paintbrush.c: some more sensitive settings. The gradient feature can now be toggled with a button. Hopefully didn't break anything.
1999-04-13 01:55:06 +08:00
#include "selection_options.h"
1997-11-25 06:05:25 +08:00
#include "tile.h" /* ick. */
1999-10-10 04:33:53 +08:00
#include "libgimp/gimpintl.h"
#define PREVIEW_WIDTH 256
#define PREVIEW_HEIGHT 256
1997-11-25 06:05:25 +08:00
#define PREVIEW_EVENT_MASK GDK_EXPOSURE_MASK | \
GDK_BUTTON_PRESS_MASK | \
GDK_ENTER_NOTIFY_MASK
/* the by color selection structures */
1997-11-25 06:05:25 +08:00
typedef struct _ByColorSelect ByColorSelect;
1997-11-25 06:05:25 +08:00
struct _ByColorSelect
{
gint x, y; /* Point from which to execute seed fill */
SelectOps operation; /* add, subtract, normal color selection */
1997-11-25 06:05:25 +08:00
};
typedef struct _ByColorDialog ByColorDialog;
1997-11-25 06:05:25 +08:00
struct _ByColorDialog
{
GtkWidget *shell;
1997-11-25 06:05:25 +08:00
GtkWidget *preview;
GtkWidget *gimage_name;
1997-11-25 06:05:25 +08:00
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 */
};
app/airbrush.c app/bezier_select.c app/blend.c app/brightness_contrast.c 1999-04-12 Michael Natterer <mitschel@cs.tu-berlin.de> * app/airbrush.c * app/bezier_select.c * app/blend.c * app/brightness_contrast.c * app/bucket_fill.c * app/by_color_select.c * app/clone.c * app/color_balance.c * app/color_picker.c * app/convolve.c * app/crop.c * app/curves.c * app/ellipse_select.c * app/eraser.c * app/flip_tool.c * app/free_select.c * app/fuzzy_select.c * app/histogram_tool.c * app/hue_saturation.c * app/ink.c * app/iscissors.c * app/levels.c * app/magnify.c * app/move.c * app/paintbrush.c * app/pencil.c * app/posterize.c * app/rect_select.[ch] * app/text_tool.c * app/threshold.c * app/transform_tool.c * app/tools.[ch] * app/toolsF.h: again: all tools :( * app/Makefile.am * app/tool_options.[ch] * app/selection_options.h * app/tool_options_ui.h: new files. Ok, this time it's general enough for future extensions: - The tool options structures are organized like the gtk object system to allow derived tool options. - Renamed all create and reset functions to *_options_new() and *_options_reset() to reflect this. - Changed tools_register() again. Now it takes just a pointer to a ToolOptions structure. - Moved almost the entire tool options gui code to tool_options.c. - Visually separated the common selection options from the tool-specific ones. I'd like to do the same with opacity/paint mode in all paint tool options but I think this needs some more discussion. * app/histogram_tool.c: changed packing boxes, label alignments. * app/paintbrush.c: some more sensitive settings. The gradient feature can now be toggled with a button. Hopefully didn't break anything.
1999-04-13 01:55:06 +08:00
/* the by color selection tool options */
static SelectionOptions * by_color_options = NULL;
1997-11-25 06:05:25 +08:00
/* the by color selection dialog */
static ByColorDialog * by_color_dialog = NULL;
1999-10-10 04:33:53 +08:00
/* dnd stuff */
static GtkTargetEntry by_color_select_targets[] =
1999-10-10 04:33:53 +08:00
{
GIMP_TARGET_COLOR
};
static guint n_by_color_select_targets = (sizeof (by_color_select_targets) /
sizeof (by_color_select_targets[0]));
static void by_color_select_color_drop (GtkWidget *widget,
guchar r,
guchar g,
guchar b,
gpointer data);
/* by_color select action functions */
namespace cleanups. 1999-06-21 Michael Natterer <mitschel@cs.tu-berlin.de> * app/context_manager.c: namespace cleanups. * app/commands.[ch] * app/menus.c: moved the "Toggle Selection" menu entry to "View", sprinkled some separators and made the layers/channels/paths popup menus consistent with Tigert's last ops buttons change. * app/fileops.c * app/plug_in.c: check for gdisplay_active() returning NULL in some more places. * app/[all tool related files]: - Turned the ToolAction and ToolState #define's into typedef'ed enums, so the compiler can do some more sanity checking. - Removed one more unused global variable "active_tool_layer". - Removed some #include's from tools.c. - Standardized the individual tools' structure names. - Moved showing/hiding the tool options to separate functions. - Stuff... * app/commands.c * app/disp_callbacks.c * app/gdisplay.c * app/tools.c: fixed the segfaults which happened when the image of one of the tools which have dialogs (levels/posterize/...) was deleted. My approach was to do stricter sanity checking and to set some gdisplay pointers correctly where appropriate, so I can't tell exactly where the bug was. The curves tool now(??) updates on every _second_ display change only, which is really obscure. Finding/changing the display to operate on should definitely be done by connecting to the user context's "display_changed" signal. * app/gimpset.c: emit the "remove" signal _after_ removing the pointer from the set. If this was not a bug but a feature, please let me know, we'll need two signals then.
1999-06-22 06:12:07 +08:00
static void by_color_select_button_press (Tool *, GdkEventButton *, gpointer);
static void by_color_select_button_release (Tool *, GdkEventButton *, gpointer);
static void by_color_select_modifier_update (Tool *, GdkEventKey * , gpointer);
static void by_color_select_cursor_update (Tool *, GdkEventMotion *, gpointer);
static void by_color_select_oper_update (Tool *, GdkEventMotion *, gpointer);
static void by_color_select_control (Tool *, ToolAction, gpointer);
namespace cleanups. 1999-06-21 Michael Natterer <mitschel@cs.tu-berlin.de> * app/context_manager.c: namespace cleanups. * app/commands.[ch] * app/menus.c: moved the "Toggle Selection" menu entry to "View", sprinkled some separators and made the layers/channels/paths popup menus consistent with Tigert's last ops buttons change. * app/fileops.c * app/plug_in.c: check for gdisplay_active() returning NULL in some more places. * app/[all tool related files]: - Turned the ToolAction and ToolState #define's into typedef'ed enums, so the compiler can do some more sanity checking. - Removed one more unused global variable "active_tool_layer". - Removed some #include's from tools.c. - Standardized the individual tools' structure names. - Moved showing/hiding the tool options to separate functions. - Stuff... * app/commands.c * app/disp_callbacks.c * app/gdisplay.c * app/tools.c: fixed the segfaults which happened when the image of one of the tools which have dialogs (levels/posterize/...) was deleted. My approach was to do stricter sanity checking and to set some gdisplay pointers correctly where appropriate, so I can't tell exactly where the bug was. The curves tool now(??) updates on every _second_ display change only, which is really obscure. Finding/changing the display to operate on should definitely be done by connecting to the user context's "display_changed" signal. * app/gimpset.c: emit the "remove" signal _after_ removing the pointer from the set. If this was not a bug but a feature, please let me know, we'll need two signals then.
1999-06-22 06:12:07 +08:00
static ByColorDialog * by_color_select_dialog_new (void);
static void by_color_select_render (ByColorDialog *, GImage *);
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);
namespace cleanups. 1999-06-21 Michael Natterer <mitschel@cs.tu-berlin.de> * app/context_manager.c: namespace cleanups. * app/commands.[ch] * app/menus.c: moved the "Toggle Selection" menu entry to "View", sprinkled some separators and made the layers/channels/paths popup menus consistent with Tigert's last ops buttons change. * app/fileops.c * app/plug_in.c: check for gdisplay_active() returning NULL in some more places. * app/[all tool related files]: - Turned the ToolAction and ToolState #define's into typedef'ed enums, so the compiler can do some more sanity checking. - Removed one more unused global variable "active_tool_layer". - Removed some #include's from tools.c. - Standardized the individual tools' structure names. - Moved showing/hiding the tool options to separate functions. - Stuff... * app/commands.c * app/disp_callbacks.c * app/gdisplay.c * app/tools.c: fixed the segfaults which happened when the image of one of the tools which have dialogs (levels/posterize/...) was deleted. My approach was to do stricter sanity checking and to set some gdisplay pointers correctly where appropriate, so I can't tell exactly where the bug was. The curves tool now(??) updates on every _second_ display change only, which is really obscure. Finding/changing the display to operate on should definitely be done by connecting to the user context's "display_changed" signal. * app/gimpset.c: emit the "remove" signal _after_ removing the pointer from the set. If this was not a bug but a feature, please let me know, we'll need two signals then.
1999-06-22 06:12:07 +08:00
static void by_color_select_preview_button_press (ByColorDialog *,
GdkEventButton *);
1997-11-25 06:05:25 +08:00
static gint is_pixel_sufficiently_different (guchar *, guchar *,
gint, gint, gint, gint);
static Channel * by_color_select_color (GImage *, GimpDrawable *,
guchar *, gint, gint, gint);
app/airbrush.c app/bezier_select.c app/blend.c app/brightness_contrast.c 1999-04-12 Michael Natterer <mitschel@cs.tu-berlin.de> * app/airbrush.c * app/bezier_select.c * app/blend.c * app/brightness_contrast.c * app/bucket_fill.c * app/by_color_select.c * app/clone.c * app/color_balance.c * app/color_picker.c * app/convolve.c * app/crop.c * app/curves.c * app/ellipse_select.c * app/eraser.c * app/flip_tool.c * app/free_select.c * app/fuzzy_select.c * app/histogram_tool.c * app/hue_saturation.c * app/ink.c * app/iscissors.c * app/levels.c * app/magnify.c * app/move.c * app/paintbrush.c * app/pencil.c * app/posterize.c * app/rect_select.[ch] * app/text_tool.c * app/threshold.c * app/transform_tool.c * app/tools.[ch] * app/toolsF.h: again: all tools :( * app/Makefile.am * app/tool_options.[ch] * app/selection_options.h * app/tool_options_ui.h: new files. Ok, this time it's general enough for future extensions: - The tool options structures are organized like the gtk object system to allow derived tool options. - Renamed all create and reset functions to *_options_new() and *_options_reset() to reflect this. - Changed tools_register() again. Now it takes just a pointer to a ToolOptions structure. - Moved almost the entire tool options gui code to tool_options.c. - Visually separated the common selection options from the tool-specific ones. I'd like to do the same with opacity/paint mode in all paint tool options but I think this needs some more discussion. * app/histogram_tool.c: changed packing boxes, label alignments. * app/paintbrush.c: some more sensitive settings. The gradient feature can now be toggled with a button. Hopefully didn't break anything.
1999-04-13 01:55:06 +08:00
namespace cleanups. 1999-06-21 Michael Natterer <mitschel@cs.tu-berlin.de> * app/context_manager.c: namespace cleanups. * app/commands.[ch] * app/menus.c: moved the "Toggle Selection" menu entry to "View", sprinkled some separators and made the layers/channels/paths popup menus consistent with Tigert's last ops buttons change. * app/fileops.c * app/plug_in.c: check for gdisplay_active() returning NULL in some more places. * app/[all tool related files]: - Turned the ToolAction and ToolState #define's into typedef'ed enums, so the compiler can do some more sanity checking. - Removed one more unused global variable "active_tool_layer". - Removed some #include's from tools.c. - Standardized the individual tools' structure names. - Moved showing/hiding the tool options to separate functions. - Stuff... * app/commands.c * app/disp_callbacks.c * app/gdisplay.c * app/tools.c: fixed the segfaults which happened when the image of one of the tools which have dialogs (levels/posterize/...) was deleted. My approach was to do stricter sanity checking and to set some gdisplay pointers correctly where appropriate, so I can't tell exactly where the bug was. The curves tool now(??) updates on every _second_ display change only, which is really obscure. Finding/changing the display to operate on should definitely be done by connecting to the user context's "display_changed" signal. * app/gimpset.c: emit the "remove" signal _after_ removing the pointer from the set. If this was not a bug but a feature, please let me know, we'll need two signals then.
1999-06-22 06:12:07 +08:00
1997-11-25 06:05:25 +08:00
/* by_color selection machinery */
static gint
is_pixel_sufficiently_different (guchar *col1,
guchar *col2,
gint antialias,
gint threshold,
gint bytes,
gint has_alpha)
1997-11-25 06:05:25 +08:00
{
gint diff;
gint max;
gint b;
gint alpha;
1997-11-25 06:05:25 +08:00
max = 0;
alpha = (has_alpha) ? bytes - 1 : bytes;
/* if there is an alpha channel, never select transparent regions */
if (has_alpha && col2[alpha] == 0)
return 0;
for (b = 0; b < alpha; b++)
{
diff = col1[b] - col2[b];
diff = abs (diff);
if (diff > max)
max = diff;
}
if (antialias && threshold > 0)
1997-11-25 06:05:25 +08:00
{
gfloat aa;
1997-11-25 06:05:25 +08:00
aa = 1.5 - ((gfloat) max / threshold);
1997-11-25 06:05:25 +08:00
if (aa <= 0)
return 0;
else if (aa < 0.5)
return (guchar) (aa * 512);
1997-11-25 06:05:25 +08:00
else
return 255;
}
else
{
if (max > threshold)
return 0;
else
return 255;
}
}
static Channel *
by_color_select_color (GImage *gimage,
GimpDrawable *drawable,
guchar *color,
gboolean antialias,
gint threshold,
gboolean sample_merged)
1997-11-25 06:05:25 +08:00
{
/* Scan over the gimage's active layer, finding pixels within the specified
* threshold from the given R, G, & B values. If antialiasing is on,
* use the same antialiasing scheme as in fuzzy_select. Modify the gimage's
* mask to reflect the additional selection
*/
Channel *mask;
PixelRegion imagePR, maskPR;
guchar *image_data;
guchar *mask_data;
guchar *idata, *mdata;
guchar rgb[MAX_CHANNELS];
gint has_alpha, indexed;
gint width, height;
gint bytes, color_bytes, alpha;
gint i, j;
1997-11-25 06:05:25 +08:00
void * pr;
gint d_type;
1997-11-25 06:05:25 +08:00
/* Get the image information */
if (sample_merged)
{
bytes = gimage_composite_bytes (gimage);
d_type = gimage_composite_type (gimage);
has_alpha = (d_type == RGBA_GIMAGE ||
d_type == GRAYA_GIMAGE ||
d_type == INDEXEDA_GIMAGE);
indexed = d_type == INDEXEDA_GIMAGE || d_type == INDEXED_GIMAGE;
1997-11-25 06:05:25 +08:00
width = gimage->width;
height = gimage->height;
pixel_region_init (&imagePR, gimage_composite (gimage),
0, 0, width, height, FALSE);
1997-11-25 06:05:25 +08:00
}
else
{
bytes = drawable_bytes (drawable);
d_type = drawable_type (drawable);
has_alpha = drawable_has_alpha (drawable);
indexed = drawable_indexed (drawable);
1997-11-25 06:05:25 +08:00
width = drawable_width (drawable);
height = drawable_height (drawable);
pixel_region_init (&imagePR, drawable_data (drawable),
0, 0, width, height, FALSE);
1997-11-25 06:05:25 +08:00
}
if (indexed)
{
/* indexed colors are always RGB or RGBA */
color_bytes = has_alpha ? 4 : 3;
}
else
{
/* RGB, RGBA, GRAY and GRAYA colors are shaped just like the image */
color_bytes = bytes;
}
1997-11-25 06:05:25 +08:00
alpha = bytes - 1;
mask = channel_new_mask (gimage, width, height);
pixel_region_init (&maskPR, drawable_data (GIMP_DRAWABLE(mask)),
0, 0, width, height, TRUE);
1997-11-25 06:05:25 +08:00
/* iterate over the entire image */
for (pr = pixel_regions_register (2, &imagePR, &maskPR);
pr != NULL;
pr = pixel_regions_process (pr))
1997-11-25 06:05:25 +08:00
{
image_data = imagePR.data;
mask_data = maskPR.data;
for (i = 0; i < imagePR.h; i++)
{
idata = image_data;
mdata = mask_data;
for (j = 0; j < imagePR.w; j++)
{
/* Get the rgb values for the color */
gimage_get_color (gimage, d_type, rgb, idata);
/* Plug the alpha channel in there */
if (has_alpha)
rgb[color_bytes - 1] = idata[alpha];
1997-11-25 06:05:25 +08:00
/* Find how closely the colors match */
*mdata++ = is_pixel_sufficiently_different (color,
rgb,
antialias,
threshold,
color_bytes,
has_alpha);
1997-11-25 06:05:25 +08:00
idata += bytes;
}
image_data += imagePR.rowstride;
mask_data += maskPR.rowstride;
}
}
return mask;
}
void
by_color_select (GImage *gimage,
GimpDrawable *drawable,
guchar *color,
gint threshold,
SelectOps op,
gboolean antialias,
gboolean feather,
gdouble feather_radius,
gboolean sample_merged)
1997-11-25 06:05:25 +08:00
{
Channel *new_mask;
gint off_x, off_y;
1997-11-25 06:05:25 +08:00
if (!drawable)
return;
new_mask = by_color_select_color (gimage, drawable, color,
antialias, threshold, sample_merged);
1997-11-25 06:05:25 +08:00
/* if applicable, replace the current selection */
if (op == SELECTION_REPLACE)
1997-11-25 06:05:25 +08:00
gimage_mask_clear (gimage);
else
gimage_mask_undo (gimage);
if (sample_merged)
{
off_x = 0; off_y = 0;
}
else
drawable_offsets (drawable, &off_x, &off_y);
1997-11-25 06:05:25 +08:00
if (feather)
channel_feather (new_mask, gimage_get_mask (gimage),
feather_radius,
feather_radius,
op, off_x, off_y);
1997-11-25 06:05:25 +08:00
else
channel_combine_mask (gimage_get_mask (gimage),
new_mask, op, off_x, off_y);
channel_delete (new_mask);
}
/* by_color select action functions */
static void
by_color_select_button_press (Tool *tool,
GdkEventButton *bevent,
gpointer gdisp_ptr)
{
GDisplay *gdisp;
1997-11-25 06:05:25 +08:00
ByColorSelect *by_color_sel;
gdisp = (GDisplay *) gdisp_ptr;
by_color_sel = (ByColorSelect *) tool->private;
tool->drawable = gimage_active_drawable (gdisp->gimage);
1997-11-25 06:05:25 +08:00
if (!by_color_dialog)
return;
by_color_sel->x = bevent->x;
by_color_sel->y = bevent->y;
tool->state = ACTIVE;
tool->gdisp_ptr = gdisp_ptr;
/* Make sure the "by color" select dialog is visible */
if (! GTK_WIDGET_VISIBLE (by_color_dialog->shell))
gtk_widget_show (by_color_dialog->shell);
/* Update the by_color_dialog's active gdisp pointer */
if (by_color_dialog->gimage)
by_color_dialog->gimage->by_color_select = FALSE;
if (by_color_dialog->gimage != gdisp->gimage)
{
gdk_draw_rectangle
(by_color_dialog->preview->window,
by_color_dialog->preview->style->bg_gc[GTK_STATE_NORMAL],
TRUE,
0, 0,
by_color_dialog->preview->allocation.width,
by_color_dialog->preview->allocation.width);
}
1997-11-25 06:05:25 +08:00
by_color_dialog->gimage = gdisp->gimage;
gdisp->gimage->by_color_select = TRUE;
gdk_pointer_grab (gdisp->canvas->window, FALSE,
GDK_POINTER_MOTION_HINT_MASK |
GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK,
NULL, NULL, bevent->time);
1997-11-25 06:05:25 +08:00
}
static void
by_color_select_button_release (Tool *tool,
GdkEventButton *bevent,
gpointer gdisp_ptr)
{
ByColorSelect *by_color_sel;
GDisplay *gdisp;
gint x, y;
GimpDrawable *drawable;
guchar *color;
gint use_offsets;
1997-11-25 06:05:25 +08:00
gdisp = (GDisplay *) gdisp_ptr;
by_color_sel = (ByColorSelect *) tool->private;
drawable = gimage_active_drawable (gdisp->gimage);
1997-11-25 06:05:25 +08:00
gdk_pointer_ungrab (bevent->time);
1997-11-25 06:05:25 +08:00
tool->state = INACTIVE;
/* First take care of the case where the user "cancels" the action */
if (! (bevent->state & GDK_BUTTON3_MASK))
{
use_offsets = (by_color_options->sample_merged) ? FALSE : TRUE;
gdisplay_untransform_coords (gdisp, by_color_sel->x, by_color_sel->y,
&x, &y, FALSE, use_offsets);
1997-11-25 06:05:25 +08:00
if( x >= 0 && x < gimp_drawable_width (drawable) &&
y >= 0 && y < gimp_drawable_height (drawable))
1997-11-25 06:05:25 +08:00
{
/* Get the start color */
if (by_color_options->sample_merged)
{
if (!(color = gimp_image_get_color_at (gdisp->gimage, x, y)))
return;
}
else
{
if (!(color = gimp_drawable_get_color_at (drawable, x, y)))
return;
}
1997-11-25 06:05:25 +08:00
/* select the area */
by_color_select (gdisp->gimage, drawable, color,
by_color_dialog->threshold,
by_color_sel->operation,
by_color_options->antialias,
by_color_options->feather,
by_color_options->feather_radius,
by_color_options->sample_merged);
1997-11-25 06:05:25 +08:00
g_free (color);
/* show selection on all views */
gdisplays_flush ();
1997-11-25 06:05:25 +08:00
/* update the preview window */
by_color_select_render (by_color_dialog, gdisp->gimage);
by_color_select_draw (by_color_dialog, gdisp->gimage);
}
1997-11-25 06:05:25 +08:00
}
}
static void
by_color_select_cursor_update (Tool *tool,
GdkEventMotion *mevent,
gpointer gdisp_ptr)
{
ByColorSelect *by_col_sel;
GDisplay *gdisp;
Layer *layer;
gint x, y;
1997-11-25 06:05:25 +08:00
gdisp = (GDisplay *) gdisp_ptr;
by_col_sel = (ByColorSelect *) tool->private;
1997-11-25 06:05:25 +08:00
gdisplay_untransform_coords (gdisp, mevent->x, mevent->y,
&x, &y, FALSE, FALSE);
if (by_color_options->sample_merged ||
((layer = gimage_pick_correlate_layer (gdisp->gimage, x, y)) &&
layer == gdisp->gimage->active_layer))
{
switch (by_col_sel->operation)
{
case SELECTION_ADD:
gdisplay_install_tool_cursor (gdisp, GIMP_MOUSE_CURSOR,
TOOL_TYPE_NONE,
CURSOR_MODIFIER_PLUS,
FALSE);
break;
case SELECTION_SUB:
gdisplay_install_tool_cursor (gdisp, GIMP_MOUSE_CURSOR,
TOOL_TYPE_NONE,
CURSOR_MODIFIER_MINUS,
FALSE);
break;
case SELECTION_INTERSECT:
gdisplay_install_tool_cursor (gdisp, GIMP_MOUSE_CURSOR,
TOOL_TYPE_NONE,
CURSOR_MODIFIER_INTERSECT,
FALSE);
break;
case SELECTION_REPLACE:
gdisplay_install_tool_cursor (gdisp, GIMP_MOUSE_CURSOR,
TOOL_TYPE_NONE,
CURSOR_MODIFIER_NONE,
FALSE);
break;
case SELECTION_MOVE_MASK:
gdisplay_install_tool_cursor (gdisp, GIMP_MOUSE_CURSOR,
RECT_SELECT,
CURSOR_MODIFIER_MOVE,
FALSE);
break;
case SELECTION_MOVE:
gdisplay_install_tool_cursor (gdisp, GIMP_MOUSE_CURSOR,
MOVE,
CURSOR_MODIFIER_NONE,
FALSE);
}
return;
}
gdisplay_install_tool_cursor (gdisp, GIMP_BAD_CURSOR,
TOOL_TYPE_NONE,
CURSOR_MODIFIER_NONE,
FALSE);
1997-11-25 06:05:25 +08:00
}
static void
by_color_select_update_op_state (ByColorSelect *by_col_sel,
gint state,
GDisplay *gdisp)
{
if (active_tool->state == ACTIVE)
return;
if ((state & GDK_SHIFT_MASK) &&
!(state & GDK_CONTROL_MASK))
by_col_sel->operation = SELECTION_ADD; /* add to the selection */
else if ((state & GDK_CONTROL_MASK) &&
!(state & GDK_SHIFT_MASK))
by_col_sel->operation = SELECTION_SUB; /* subtract from the selection */
else if ((state & GDK_CONTROL_MASK) &&
(state & GDK_SHIFT_MASK))
by_col_sel->operation = SELECTION_INTERSECT; /* intersect with selection */
else
by_col_sel->operation = by_color_dialog->operation;
}
static void
by_color_select_modifier_update (Tool *tool,
GdkEventKey *kevent,
gpointer gdisp_ptr)
{
ByColorSelect *by_col_sel;
gint state;
by_col_sel = (ByColorSelect *) tool->private;
state = kevent->state;
switch (kevent->keyval)
{
case GDK_Alt_L: case GDK_Alt_R:
if (state & GDK_MOD1_MASK)
state &= ~GDK_MOD1_MASK;
else
state |= GDK_MOD1_MASK;
break;
case GDK_Shift_L: case GDK_Shift_R:
if (state & GDK_SHIFT_MASK)
state &= ~GDK_SHIFT_MASK;
else
state |= GDK_SHIFT_MASK;
break;
case GDK_Control_L: case GDK_Control_R:
if (state & GDK_CONTROL_MASK)
state &= ~GDK_CONTROL_MASK;
else
state |= GDK_CONTROL_MASK;
break;
}
by_color_select_update_op_state (by_col_sel, state, (GDisplay *) gdisp_ptr);
}
static void
by_color_select_oper_update (Tool *tool,
GdkEventMotion *mevent,
gpointer gdisp_ptr)
{
ByColorSelect *by_col_sel;
by_col_sel = (ByColorSelect *) tool->private;
by_color_select_update_op_state (by_col_sel, mevent->state,
(GDisplay *) gdisp_ptr);
}
1997-11-25 06:05:25 +08:00
static void
namespace cleanups. 1999-06-21 Michael Natterer <mitschel@cs.tu-berlin.de> * app/context_manager.c: namespace cleanups. * app/commands.[ch] * app/menus.c: moved the "Toggle Selection" menu entry to "View", sprinkled some separators and made the layers/channels/paths popup menus consistent with Tigert's last ops buttons change. * app/fileops.c * app/plug_in.c: check for gdisplay_active() returning NULL in some more places. * app/[all tool related files]: - Turned the ToolAction and ToolState #define's into typedef'ed enums, so the compiler can do some more sanity checking. - Removed one more unused global variable "active_tool_layer". - Removed some #include's from tools.c. - Standardized the individual tools' structure names. - Moved showing/hiding the tool options to separate functions. - Stuff... * app/commands.c * app/disp_callbacks.c * app/gdisplay.c * app/tools.c: fixed the segfaults which happened when the image of one of the tools which have dialogs (levels/posterize/...) was deleted. My approach was to do stricter sanity checking and to set some gdisplay pointers correctly where appropriate, so I can't tell exactly where the bug was. The curves tool now(??) updates on every _second_ display change only, which is really obscure. Finding/changing the display to operate on should definitely be done by connecting to the user context's "display_changed" signal. * app/gimpset.c: emit the "remove" signal _after_ removing the pointer from the set. If this was not a bug but a feature, please let me know, we'll need two signals then.
1999-06-22 06:12:07 +08:00
by_color_select_control (Tool *tool,
ToolAction action,
gpointer gdisp_ptr)
1997-11-25 06:05:25 +08:00
{
switch (action)
{
case PAUSE:
1997-11-25 06:05:25 +08:00
break;
namespace cleanups. 1999-06-21 Michael Natterer <mitschel@cs.tu-berlin.de> * app/context_manager.c: namespace cleanups. * app/commands.[ch] * app/menus.c: moved the "Toggle Selection" menu entry to "View", sprinkled some separators and made the layers/channels/paths popup menus consistent with Tigert's last ops buttons change. * app/fileops.c * app/plug_in.c: check for gdisplay_active() returning NULL in some more places. * app/[all tool related files]: - Turned the ToolAction and ToolState #define's into typedef'ed enums, so the compiler can do some more sanity checking. - Removed one more unused global variable "active_tool_layer". - Removed some #include's from tools.c. - Standardized the individual tools' structure names. - Moved showing/hiding the tool options to separate functions. - Stuff... * app/commands.c * app/disp_callbacks.c * app/gdisplay.c * app/tools.c: fixed the segfaults which happened when the image of one of the tools which have dialogs (levels/posterize/...) was deleted. My approach was to do stricter sanity checking and to set some gdisplay pointers correctly where appropriate, so I can't tell exactly where the bug was. The curves tool now(??) updates on every _second_ display change only, which is really obscure. Finding/changing the display to operate on should definitely be done by connecting to the user context's "display_changed" signal. * app/gimpset.c: emit the "remove" signal _after_ removing the pointer from the set. If this was not a bug but a feature, please let me know, we'll need two signals then.
1999-06-22 06:12:07 +08:00
case RESUME:
1997-11-25 06:05:25 +08:00
break;
namespace cleanups. 1999-06-21 Michael Natterer <mitschel@cs.tu-berlin.de> * app/context_manager.c: namespace cleanups. * app/commands.[ch] * app/menus.c: moved the "Toggle Selection" menu entry to "View", sprinkled some separators and made the layers/channels/paths popup menus consistent with Tigert's last ops buttons change. * app/fileops.c * app/plug_in.c: check for gdisplay_active() returning NULL in some more places. * app/[all tool related files]: - Turned the ToolAction and ToolState #define's into typedef'ed enums, so the compiler can do some more sanity checking. - Removed one more unused global variable "active_tool_layer". - Removed some #include's from tools.c. - Standardized the individual tools' structure names. - Moved showing/hiding the tool options to separate functions. - Stuff... * app/commands.c * app/disp_callbacks.c * app/gdisplay.c * app/tools.c: fixed the segfaults which happened when the image of one of the tools which have dialogs (levels/posterize/...) was deleted. My approach was to do stricter sanity checking and to set some gdisplay pointers correctly where appropriate, so I can't tell exactly where the bug was. The curves tool now(??) updates on every _second_ display change only, which is really obscure. Finding/changing the display to operate on should definitely be done by connecting to the user context's "display_changed" signal. * app/gimpset.c: emit the "remove" signal _after_ removing the pointer from the set. If this was not a bug but a feature, please let me know, we'll need two signals then.
1999-06-22 06:12:07 +08:00
case HALT:
1997-11-25 06:05:25 +08:00
if (by_color_dialog)
by_color_select_close_callback (NULL, (gpointer) by_color_dialog);
1997-11-25 06:05:25 +08:00
break;
namespace cleanups. 1999-06-21 Michael Natterer <mitschel@cs.tu-berlin.de> * app/context_manager.c: namespace cleanups. * app/commands.[ch] * app/menus.c: moved the "Toggle Selection" menu entry to "View", sprinkled some separators and made the layers/channels/paths popup menus consistent with Tigert's last ops buttons change. * app/fileops.c * app/plug_in.c: check for gdisplay_active() returning NULL in some more places. * app/[all tool related files]: - Turned the ToolAction and ToolState #define's into typedef'ed enums, so the compiler can do some more sanity checking. - Removed one more unused global variable "active_tool_layer". - Removed some #include's from tools.c. - Standardized the individual tools' structure names. - Moved showing/hiding the tool options to separate functions. - Stuff... * app/commands.c * app/disp_callbacks.c * app/gdisplay.c * app/tools.c: fixed the segfaults which happened when the image of one of the tools which have dialogs (levels/posterize/...) was deleted. My approach was to do stricter sanity checking and to set some gdisplay pointers correctly where appropriate, so I can't tell exactly where the bug was. The curves tool now(??) updates on every _second_ display change only, which is really obscure. Finding/changing the display to operate on should definitely be done by connecting to the user context's "display_changed" signal. * app/gimpset.c: emit the "remove" signal _after_ removing the pointer from the set. If this was not a bug but a feature, please let me know, we'll need two signals then.
1999-06-22 06:12:07 +08:00
default:
break;
1997-11-25 06:05:25 +08:00
}
}
static void
by_color_select_options_reset (void)
{
app/airbrush.c app/bezier_select.c app/blend.c app/brightness_contrast.c 1999-04-12 Michael Natterer <mitschel@cs.tu-berlin.de> * app/airbrush.c * app/bezier_select.c * app/blend.c * app/brightness_contrast.c * app/bucket_fill.c * app/by_color_select.c * app/clone.c * app/color_balance.c * app/color_picker.c * app/convolve.c * app/crop.c * app/curves.c * app/ellipse_select.c * app/eraser.c * app/flip_tool.c * app/free_select.c * app/fuzzy_select.c * app/histogram_tool.c * app/hue_saturation.c * app/ink.c * app/iscissors.c * app/levels.c * app/magnify.c * app/move.c * app/paintbrush.c * app/pencil.c * app/posterize.c * app/rect_select.[ch] * app/text_tool.c * app/threshold.c * app/transform_tool.c * app/tools.[ch] * app/toolsF.h: again: all tools :( * app/Makefile.am * app/tool_options.[ch] * app/selection_options.h * app/tool_options_ui.h: new files. Ok, this time it's general enough for future extensions: - The tool options structures are organized like the gtk object system to allow derived tool options. - Renamed all create and reset functions to *_options_new() and *_options_reset() to reflect this. - Changed tools_register() again. Now it takes just a pointer to a ToolOptions structure. - Moved almost the entire tool options gui code to tool_options.c. - Visually separated the common selection options from the tool-specific ones. I'd like to do the same with opacity/paint mode in all paint tool options but I think this needs some more discussion. * app/histogram_tool.c: changed packing boxes, label alignments. * app/paintbrush.c: some more sensitive settings. The gradient feature can now be toggled with a button. Hopefully didn't break anything.
1999-04-13 01:55:06 +08:00
selection_options_reset (by_color_options);
}
1997-11-25 06:05:25 +08:00
Tool *
tools_new_by_color_select (void)
1997-11-25 06:05:25 +08:00
{
Tool *tool;
ByColorSelect *private;
1997-11-25 06:05:25 +08:00
/* The tool options */
if (!by_color_options)
app/airbrush.c app/bezier_select.c app/blend.c app/brightness_contrast.c 1999-04-12 Michael Natterer <mitschel@cs.tu-berlin.de> * app/airbrush.c * app/bezier_select.c * app/blend.c * app/brightness_contrast.c * app/bucket_fill.c * app/by_color_select.c * app/clone.c * app/color_balance.c * app/color_picker.c * app/convolve.c * app/crop.c * app/curves.c * app/ellipse_select.c * app/eraser.c * app/flip_tool.c * app/free_select.c * app/fuzzy_select.c * app/histogram_tool.c * app/hue_saturation.c * app/ink.c * app/iscissors.c * app/levels.c * app/magnify.c * app/move.c * app/paintbrush.c * app/pencil.c * app/posterize.c * app/rect_select.[ch] * app/text_tool.c * app/threshold.c * app/transform_tool.c * app/tools.[ch] * app/toolsF.h: again: all tools :( * app/Makefile.am * app/tool_options.[ch] * app/selection_options.h * app/tool_options_ui.h: new files. Ok, this time it's general enough for future extensions: - The tool options structures are organized like the gtk object system to allow derived tool options. - Renamed all create and reset functions to *_options_new() and *_options_reset() to reflect this. - Changed tools_register() again. Now it takes just a pointer to a ToolOptions structure. - Moved almost the entire tool options gui code to tool_options.c. - Visually separated the common selection options from the tool-specific ones. I'd like to do the same with opacity/paint mode in all paint tool options but I think this needs some more discussion. * app/histogram_tool.c: changed packing boxes, label alignments. * app/paintbrush.c: some more sensitive settings. The gradient feature can now be toggled with a button. Hopefully didn't break anything.
1999-04-13 01:55:06 +08:00
{
by_color_options =
selection_options_new (BY_COLOR_SELECT, by_color_select_options_reset);
tools_register (BY_COLOR_SELECT, (ToolOptions *) by_color_options);
}
1997-11-25 06:05:25 +08:00
tool = tools_new_tool (BY_COLOR_SELECT);
allocate the tool's paint_core with g_new0. This prevents us from having 2000-06-22 Matt Wilson <msw@redhat.com> * app/paint_core.c (paint_core_new): allocate the tool's paint_core with g_new0. This prevents us from having cruft in unused tools. Systems with sensitive FPUs (Alpha) will raise exception in the paint_core_cursor_update if paint_core->last{x,y} are messy. * app/bezier_select.c (tools_new_bezier_select) * app/blend.c (blend_options_new) * app/brightness_contrast.c (tools_new_brightness_contrast) * app/bucket_fill.c (tools_new_bucket_fill) * app/by_color_select.c (tools_new_by_color_select) * app/color_balance.c (tools_new_color_balance) * app/color_panel.c (color_panel_new) * app/color_picker.c (tools_new_color_picker) * app/crop.c (tools_new_crop) * app/curves.c (tools_new_curves) * app/ellipse_select.c (tools_new_ellipse_select) * app/free_select.c (tools_new_free_select) * app/fuzzy_select.c (tools_new_fuzzy_select) * app/histogram_tool.c (tools_new_histogram_tool) * app/hue_saturation.c (tools_new_hue_saturation) * app/ink.c (tools_new_ink) * app/iscissors.c (tools_new_iscissors) * app/levels.c (tools_new_levels) * app/magnify.c (tools_new_magnify) * app/measure.c (tools_new_measure_tool) * app/move.c (tools_new_move_tool) * app/path_tool.c (tools_new_path_tool) * app/posterize.c (tools_new_posterize) * app/rect_select.c (tools_new_rect_select) * app/resize.c (resize_widget_new) * app/threshold.c (tools_new_threshold) * app/transform_core.c (transform_core_new) * app/xinput_airbrush.c (tools_new_xinput_airbrush): likewise (it can only help and it really isn't slow.) * app/color_area.c: #include <string.h> for memcpy declaration * app/gimphelp.c: #include <string.h> for strlen declaration
2000-06-23 08:14:07 +08:00
private = g_new0 (ByColorSelect, 1);
1997-11-25 06:05:25 +08:00
private->operation = SELECTION_REPLACE;
tool->private = (void *) private;
tool->scroll_lock = TRUE; /* Disallow scrolling */
tool->button_press_func = by_color_select_button_press;
1997-11-25 06:05:25 +08:00
tool->button_release_func = by_color_select_button_release;
tool->cursor_update_func = by_color_select_cursor_update;
tool->modifier_key_func = by_color_select_modifier_update;
tool->oper_update_func = by_color_select_oper_update;
tool->control_func = by_color_select_control;
1997-11-25 06:05:25 +08:00
return tool;
}
void
tools_free_by_color_select (Tool *tool)
{
ByColorSelect *by_color_sel;
1997-11-25 06:05:25 +08:00
by_color_sel = (ByColorSelect *) tool->private;
/* Close the color select dialog */
if (by_color_dialog)
by_color_select_close_callback (NULL, (gpointer) by_color_dialog);
1997-11-25 06:05:25 +08:00
g_free (by_color_sel);
}
void
by_color_select_initialize_by_image (GImage *gimage)
1997-11-25 06:05:25 +08:00
{
/* update the preview window */
if (by_color_dialog)
{
by_color_dialog->gimage = gimage;
gimage->by_color_select = TRUE;
by_color_select_render (by_color_dialog, gimage);
by_color_select_draw (by_color_dialog, gimage);
}
}
void
by_color_select_initialize (GDisplay *gdisp)
{
/* The "by color" dialog */
if (!by_color_dialog)
by_color_dialog = by_color_select_dialog_new ();
else
if (!GTK_WIDGET_VISIBLE (by_color_dialog->shell))
gtk_widget_show (by_color_dialog->shell);
by_color_select_initialize_by_image (gdisp->gimage);
}
1997-11-25 06:05:25 +08:00
/****************************/
/* Select by Color dialog */
/****************************/
static ByColorDialog *
by_color_select_dialog_new (void)
1997-11-25 06:05:25 +08:00
{
ByColorDialog *bcd;
GtkWidget *hbox;
GtkWidget *frame;
GtkWidget *options_box;
GtkWidget *label;
GtkWidget *util_box;
GtkWidget *slider;
GtkWidget *table;
GtkWidget *button;
1997-11-25 06:05:25 +08:00
app/Makefile.am app/gimphelp.[ch] new files 1999-09-27 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/gimphelp.[ch] * app/gimpui.[ch]: new files * app/interface.[ch] * app/preferences_dialog.[ch] The GIMP Help System part 1: Press "F1" in any dialog to pop up the help page for this dialog. Moved the widget constructors from preferences_dialog.[ch] and the query boxes from interface.[ch] to gimpui.[ch]. The dialog constructors take a help_func and a help_data parameter and install the "F1" accelerator which emits the new "help" signal. The "help" signal callback calls help_func(help_data) which finally has to call gimp_help() which in turn invokes the help browser. Still have to find a proper way to (1) prevent "F1" being assigned to some menu item and (2) to catch "F1" while browsing the menu trees in order to pop up the help for the selected item. * app/menus.c: a <Toolbox>/File/Help... menu item. * app/commands.[ch]: a command callback for the "Help..." menu item. * app/gimprc.[ch]: new boolean gimprc variable "use_help". * app/info_dialog.[ch]: pass a help function and data to the info dialog constructor. * app/tools.[ch]: store the tools help page names in the tool info structure. Export a special tools_help_func() which shows the help page for the active tool. * app/[all files calling a dialog constructor]: pass the dialog's help page to the constructor. Most dialogs are now created by gimp_dialog_new() which also sets up the action_area and the WM delete event callback, so I removed the resp. code from these files. Fixed some minor bugs and did some other stuff but didn't change any logic except dialog creation. * plug-ins/helpbrowser/helpbrowser.c: don't try to call a running help browser and don't install any menu path (all done in app/gimphelp.[ch] now).
1999-09-28 01:58:10 +08:00
bcd = g_new (ByColorDialog, 1);
bcd->gimage = NULL;
bcd->operation = SELECTION_REPLACE;
bcd->threshold = default_threshold;
1997-11-25 06:05:25 +08:00
/* The shell and main vbox */
app/Makefile.am app/gimphelp.[ch] new files 1999-09-27 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/gimphelp.[ch] * app/gimpui.[ch]: new files * app/interface.[ch] * app/preferences_dialog.[ch] The GIMP Help System part 1: Press "F1" in any dialog to pop up the help page for this dialog. Moved the widget constructors from preferences_dialog.[ch] and the query boxes from interface.[ch] to gimpui.[ch]. The dialog constructors take a help_func and a help_data parameter and install the "F1" accelerator which emits the new "help" signal. The "help" signal callback calls help_func(help_data) which finally has to call gimp_help() which in turn invokes the help browser. Still have to find a proper way to (1) prevent "F1" being assigned to some menu item and (2) to catch "F1" while browsing the menu trees in order to pop up the help for the selected item. * app/menus.c: a <Toolbox>/File/Help... menu item. * app/commands.[ch]: a command callback for the "Help..." menu item. * app/gimprc.[ch]: new boolean gimprc variable "use_help". * app/info_dialog.[ch]: pass a help function and data to the info dialog constructor. * app/tools.[ch]: store the tools help page names in the tool info structure. Export a special tools_help_func() which shows the help page for the active tool. * app/[all files calling a dialog constructor]: pass the dialog's help page to the constructor. Most dialogs are now created by gimp_dialog_new() which also sets up the action_area and the WM delete event callback, so I removed the resp. code from these files. Fixed some minor bugs and did some other stuff but didn't change any logic except dialog creation. * plug-ins/helpbrowser/helpbrowser.c: don't try to call a running help browser and don't install any menu path (all done in app/gimphelp.[ch] now).
1999-09-28 01:58:10 +08:00
bcd->shell = gimp_dialog_new (_("By Color Selection"), "by_color_selection",
tools_help_func, NULL,
GTK_WIN_POS_NONE,
FALSE, TRUE, FALSE,
_("Reset"), by_color_select_reset_callback,
bcd, NULL, NULL, FALSE, FALSE,
app/Makefile.am app/gimphelp.[ch] new files 1999-09-27 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/gimphelp.[ch] * app/gimpui.[ch]: new files * app/interface.[ch] * app/preferences_dialog.[ch] The GIMP Help System part 1: Press "F1" in any dialog to pop up the help page for this dialog. Moved the widget constructors from preferences_dialog.[ch] and the query boxes from interface.[ch] to gimpui.[ch]. The dialog constructors take a help_func and a help_data parameter and install the "F1" accelerator which emits the new "help" signal. The "help" signal callback calls help_func(help_data) which finally has to call gimp_help() which in turn invokes the help browser. Still have to find a proper way to (1) prevent "F1" being assigned to some menu item and (2) to catch "F1" while browsing the menu trees in order to pop up the help for the selected item. * app/menus.c: a <Toolbox>/File/Help... menu item. * app/commands.[ch]: a command callback for the "Help..." menu item. * app/gimprc.[ch]: new boolean gimprc variable "use_help". * app/info_dialog.[ch]: pass a help function and data to the info dialog constructor. * app/tools.[ch]: store the tools help page names in the tool info structure. Export a special tools_help_func() which shows the help page for the active tool. * app/[all files calling a dialog constructor]: pass the dialog's help page to the constructor. Most dialogs are now created by gimp_dialog_new() which also sets up the action_area and the WM delete event callback, so I removed the resp. code from these files. Fixed some minor bugs and did some other stuff but didn't change any logic except dialog creation. * plug-ins/helpbrowser/helpbrowser.c: don't try to call a running help browser and don't install any menu path (all done in app/gimphelp.[ch] now).
1999-09-28 01:58:10 +08:00
_("Close"), by_color_select_close_callback,
bcd, NULL, NULL, TRUE, TRUE,
1997-11-25 06:05:25 +08:00
app/Makefile.am app/gimphelp.[ch] new files 1999-09-27 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/gimphelp.[ch] * app/gimpui.[ch]: new files * app/interface.[ch] * app/preferences_dialog.[ch] The GIMP Help System part 1: Press "F1" in any dialog to pop up the help page for this dialog. Moved the widget constructors from preferences_dialog.[ch] and the query boxes from interface.[ch] to gimpui.[ch]. The dialog constructors take a help_func and a help_data parameter and install the "F1" accelerator which emits the new "help" signal. The "help" signal callback calls help_func(help_data) which finally has to call gimp_help() which in turn invokes the help browser. Still have to find a proper way to (1) prevent "F1" being assigned to some menu item and (2) to catch "F1" while browsing the menu trees in order to pop up the help for the selected item. * app/menus.c: a <Toolbox>/File/Help... menu item. * app/commands.[ch]: a command callback for the "Help..." menu item. * app/gimprc.[ch]: new boolean gimprc variable "use_help". * app/info_dialog.[ch]: pass a help function and data to the info dialog constructor. * app/tools.[ch]: store the tools help page names in the tool info structure. Export a special tools_help_func() which shows the help page for the active tool. * app/[all files calling a dialog constructor]: pass the dialog's help page to the constructor. Most dialogs are now created by gimp_dialog_new() which also sets up the action_area and the WM delete event callback, so I removed the resp. code from these files. Fixed some minor bugs and did some other stuff but didn't change any logic except dialog creation. * plug-ins/helpbrowser/helpbrowser.c: don't try to call a running help browser and don't install any menu path (all done in app/gimphelp.[ch] now).
1999-09-28 01:58:10 +08:00
NULL);
/* The main hbox */
hbox = gtk_hbox_new (FALSE, 4);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (bcd->shell)->vbox), hbox);
1997-11-25 06:05:25 +08:00
/* The preview */
util_box = gtk_vbox_new (FALSE, 0);
1997-11-25 06:05:25 +08:00
gtk_box_pack_start (GTK_BOX (hbox), util_box, FALSE, FALSE, 0);
1997-11-25 06:05:25 +08:00
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_box_pack_start (GTK_BOX (util_box), frame, FALSE, FALSE, 0);
1997-11-25 06:05:25 +08:00
bcd->preview = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
gtk_preview_size (GTK_PREVIEW (bcd->preview), PREVIEW_WIDTH, PREVIEW_HEIGHT);
gtk_widget_set_events (bcd->preview, PREVIEW_EVENT_MASK);
gtk_container_add (GTK_CONTAINER (frame), bcd->preview);
1997-11-25 06:05:25 +08:00
gtk_signal_connect (GTK_OBJECT (bcd->preview), "button_press_event",
GTK_SIGNAL_FUNC (by_color_select_preview_events),
1997-11-25 06:05:25 +08:00
bcd);
/* dnd colors to the image window */
1999-10-10 04:33:53 +08:00
gtk_drag_dest_set (bcd->preview,
GTK_DEST_DEFAULT_HIGHLIGHT |
GTK_DEST_DEFAULT_MOTION |
GTK_DEST_DEFAULT_DROP,
by_color_select_targets,
n_by_color_select_targets,
1999-10-10 04:33:53 +08:00
GDK_ACTION_COPY);
gimp_dnd_color_dest_set (bcd->preview, by_color_select_color_drop, bcd);
1997-11-25 06:05:25 +08:00
gtk_widget_show (bcd->preview);
gtk_widget_show (frame);
gtk_widget_show (util_box);
/* options box */
options_box = gtk_vbox_new (FALSE, 4);
gtk_box_pack_start (GTK_BOX (hbox), options_box, FALSE, FALSE, 0);
1997-11-25 06:05:25 +08:00
/* Create the active image label */
1997-11-25 06:05:25 +08:00
util_box = gtk_hbox_new (FALSE, 2);
gtk_box_pack_start (GTK_BOX (options_box), util_box, FALSE, FALSE, 0);
bcd->gimage_name = gtk_label_new (_("Inactive"));
gtk_box_pack_start (GTK_BOX (util_box), bcd->gimage_name, FALSE, FALSE, 0);
1997-11-25 06:05:25 +08:00
gtk_widget_show (bcd->gimage_name);
gtk_widget_show (util_box);
/* Create the selection mode radio box */
frame =
gimp_radio_group_new2 (TRUE, _("Selection Mode"),
gimp_radio_button_update,
&bcd->operation,
(gpointer) bcd->operation,
1997-11-25 06:05:25 +08:00
_("Replace"), (gpointer) SELECTION_REPLACE,
&bcd->replace_button,
_("Add"), (gpointer) SELECTION_ADD, NULL,
_("Subtract"), (gpointer) SELECTION_SUB, NULL,
_("Intersect"), (gpointer) SELECTION_INTERSECT, NULL,
1997-11-25 06:05:25 +08:00
NULL);
gtk_box_pack_start (GTK_BOX (options_box), frame, FALSE, FALSE, 0);
1997-11-25 06:05:25 +08:00
gtk_widget_show (frame);
/* Create the opacity scale widget */
util_box = gtk_vbox_new (FALSE, 2);
gtk_box_pack_start (GTK_BOX (options_box), util_box, FALSE, FALSE, 0);
label = gtk_label_new (_("Fuzziness Threshold"));
1997-11-25 06:05:25 +08:00
gtk_box_pack_start (GTK_BOX (util_box), label, FALSE, FALSE, 2);
gtk_widget_show (label);
gtk_widget_show (util_box);
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));
1997-11-25 06:05:25 +08:00
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 (bcd->threshold_adj), "value_changed",
GTK_SIGNAL_FUNC (gimp_int_adjustment_update),
&bcd->threshold);
1997-11-25 06:05:25 +08:00
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);
1997-11-25 06:05:25 +08:00
gtk_widget_show (options_box);
gtk_widget_show (hbox);
gtk_widget_show (bcd->shell);
gtk_signal_connect_object (GTK_OBJECT (bcd->shell), "unmap_event",
GTK_SIGNAL_FUNC (gimp_dialog_hide),
(gpointer) bcd->shell);
1997-11-25 06:05:25 +08:00
return bcd;
}
static void
by_color_select_render (ByColorDialog *bcd,
GImage *gimage)
{
Channel * mask;
MaskBuf * scaled_buf = NULL;
guchar *buf;
1997-11-25 06:05:25 +08:00
PixelRegion srcPR, destPR;
guchar *src;
gint subsample;
gint width, height;
gint srcwidth;
gint i;
gint scale;
1997-11-25 06:05:25 +08:00
mask = gimage_get_mask (gimage);
if ((drawable_width (GIMP_DRAWABLE(mask)) > PREVIEW_WIDTH) ||
(drawable_height (GIMP_DRAWABLE(mask)) > PREVIEW_HEIGHT))
1997-11-25 06:05:25 +08:00
{
if (((float) drawable_width (GIMP_DRAWABLE (mask)) / (float) PREVIEW_WIDTH) >
((float) drawable_height (GIMP_DRAWABLE (mask)) / (float) PREVIEW_HEIGHT))
1997-11-25 06:05:25 +08:00
{
width = PREVIEW_WIDTH;
height = ((drawable_height (GIMP_DRAWABLE (mask)) * PREVIEW_WIDTH) /
drawable_width (GIMP_DRAWABLE (mask)));
1997-11-25 06:05:25 +08:00
}
else
{
width = ((drawable_width (GIMP_DRAWABLE (mask)) * PREVIEW_HEIGHT) /
drawable_height (GIMP_DRAWABLE (mask)));
1997-11-25 06:05:25 +08:00
height = PREVIEW_HEIGHT;
}
scale = TRUE;
}
else
{
width = drawable_width (GIMP_DRAWABLE (mask));
height = drawable_height (GIMP_DRAWABLE (mask));
1997-11-25 06:05:25 +08:00
scale = FALSE;
}
if ((width != bcd->preview->requisition.width) ||
(height != bcd->preview->requisition.height))
gtk_preview_size (GTK_PREVIEW (bcd->preview), width, height);
/* clear the image buf */
buf = g_new0 (guchar, bcd->preview->requisition.width);
1997-11-25 06:05:25 +08:00
for (i = 0; i < bcd->preview->requisition.height; i++)
gtk_preview_draw_row (GTK_PREVIEW (bcd->preview), buf,
0, i, bcd->preview->requisition.width);
1997-11-25 06:05:25 +08:00
g_free (buf);
/* if the mask is empty, no need to scale and update again */
if (gimage_mask_is_empty (gimage))
return;
if (scale)
{
/* calculate 'acceptable' subsample */
subsample = 1;
while ((width * (subsample + 1) * 2 < drawable_width (GIMP_DRAWABLE (mask))) &&
(height * (subsample + 1) * 2 < drawable_height (GIMP_DRAWABLE (mask))))
1997-11-25 06:05:25 +08:00
subsample = subsample + 1;
pixel_region_init (&srcPR, drawable_data (GIMP_DRAWABLE (mask)),
0, 0,
drawable_width (GIMP_DRAWABLE (mask)),
drawable_height (GIMP_DRAWABLE (mask)), FALSE);
1997-11-25 06:05:25 +08:00
scaled_buf = mask_buf_new (width, height);
destPR.bytes = 1;
destPR.x = 0;
destPR.y = 0;
destPR.w = width;
destPR.h = height;
destPR.rowstride = srcPR.bytes * width;
destPR.data = mask_buf_data (scaled_buf);
destPR.tiles = NULL;
subsample_region (&srcPR, &destPR, subsample);
}
else
{
pixel_region_init (&srcPR, drawable_data (GIMP_DRAWABLE (mask)),
0, 0,
drawable_width (GIMP_DRAWABLE (mask)),
drawable_height (GIMP_DRAWABLE (mask)), FALSE);
1997-11-25 06:05:25 +08:00
scaled_buf = mask_buf_new (width, height);
destPR.bytes = 1;
destPR.x = 0;
destPR.y = 0;
destPR.w = width;
destPR.h = height;
destPR.rowstride = srcPR.bytes * width;
destPR.data = mask_buf_data (scaled_buf);
destPR.tiles = NULL;
copy_region (&srcPR, &destPR);
}
src = mask_buf_data (scaled_buf);
srcwidth = scaled_buf->width;
for (i = 0; i < height; i++)
{
gtk_preview_draw_row (GTK_PREVIEW (bcd->preview), src, 0, i, width);
src += srcwidth;
}
mask_buf_free (scaled_buf);
}
static void
by_color_select_draw (ByColorDialog *bcd,
GImage *gimage)
{
/* Draw the image buf to the preview window */
gtk_widget_draw (bcd->preview, NULL);
/* Update the gimage label to reflect the displayed gimage name */
gtk_label_set_text (GTK_LABEL (bcd->gimage_name),
g_basename (gimage_filename (gimage)));
1997-11-25 06:05:25 +08:00
}
static gint
by_color_select_preview_events (GtkWidget *widget,
GdkEventButton *bevent,
ByColorDialog *bcd)
{
switch (bevent->type)
{
case GDK_BUTTON_PRESS:
by_color_select_preview_button_press (bcd, bevent);
break;
default:
break;
}
return FALSE;
}
static void
by_color_select_reset_callback (GtkWidget *widget,
gpointer data)
1997-11-25 06:05:25 +08:00
{
ByColorDialog *bcd;
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;
1997-11-25 06:05:25 +08:00
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;
1997-11-25 06:05:25 +08:00
/* reset the mask */
gimage_mask_clear (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_close_callback (GtkWidget *widget,
gpointer data)
1997-11-25 06:05:25 +08:00
{
ByColorDialog *bcd;
bcd = (ByColorDialog *) data;
gimp_dialog_hide (bcd->shell);
if (bcd->gimage && gimp_set_have (image_context, bcd->gimage))
{
bcd->gimage->by_color_select = FALSE;
bcd->gimage = NULL;
}
1997-11-25 06:05:25 +08:00
}
static void
by_color_select_preview_button_press (ByColorDialog *bcd,
GdkEventButton *bevent)
{
gint x, y;
gboolean replace;
SelectOps operation;
GimpDrawable *drawable;
Tile *tile;
guchar *col;
1997-11-25 06:05:25 +08:00
if (!bcd->gimage)
return;
drawable = gimage_active_drawable (bcd->gimage);
1997-11-25 06:05:25 +08:00
/* check if the gimage associated to the drawable still exists */
if (!drawable_gimage (drawable))
return;
1997-11-25 06:05:25 +08:00
/* Defaults */
replace = FALSE;
operation = SELECTION_REPLACE;
1997-11-25 06:05:25 +08:00
/* Based on modifiers, and the "by color" dialog's selection mode */
if ((bevent->state & GDK_SHIFT_MASK) &&
!(bevent->state & GDK_CONTROL_MASK))
operation = SELECTION_ADD;
else if ((bevent->state & GDK_CONTROL_MASK) &&
!(bevent->state & GDK_SHIFT_MASK))
operation = SELECTION_SUB;
else if ((bevent->state & GDK_CONTROL_MASK) &&
(bevent->state & GDK_SHIFT_MASK))
operation = SELECTION_INTERSECT;
1997-11-25 06:05:25 +08:00
else
operation = by_color_dialog->operation;
/* Find x, y and modify selection */
/* Get the start color */
if (by_color_options->sample_merged)
{
x = bcd->gimage->width * bevent->x / bcd->preview->requisition.width;
y = bcd->gimage->height * bevent->y / bcd->preview->requisition.height;
if (x < 0 || y < 0 || x >= bcd->gimage->width || y >= bcd->gimage->height)
return;
tile = tile_manager_get_tile (gimage_composite (bcd->gimage),
x, y, TRUE, FALSE);
1998-08-12 01:35:34 +08:00
col = tile_data_pointer (tile, x % TILE_WIDTH, y % TILE_HEIGHT);
1997-11-25 06:05:25 +08:00
}
else
{
gint offx, offy;
1997-11-25 06:05:25 +08:00
drawable_offsets (drawable, &offx, &offy);
x = drawable_width (drawable) * bevent->x / bcd->preview->requisition.width - offx;
y = drawable_height (drawable) * bevent->y / bcd->preview->requisition.height - offy;
if (x < 0 || y < 0 ||
x >= drawable_width (drawable) || y >= drawable_height (drawable))
1997-11-25 06:05:25 +08:00
return;
tile = tile_manager_get_tile (drawable_data (drawable), x, y, TRUE, FALSE);
1998-08-12 01:35:34 +08:00
col = tile_data_pointer (tile, x % TILE_WIDTH, y % TILE_HEIGHT);
1997-11-25 06:05:25 +08:00
}
by_color_select (bcd->gimage, drawable, col,
1997-11-25 06:05:25 +08:00
bcd->threshold,
operation,
by_color_options->antialias,
by_color_options->feather,
by_color_options->feather_radius,
by_color_options->sample_merged);
tile_release (tile, FALSE);
1997-11-25 06:05:25 +08:00
/* 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);
}
1999-10-10 04:33:53 +08:00
static void
by_color_select_color_drop (GtkWidget *widget,
guchar r,
guchar g,
guchar b,
gpointer data)
{
GimpDrawable *drawable;
ByColorDialog *bcd;
guchar col[3];
bcd = (ByColorDialog*) data;
drawable = gimage_active_drawable (bcd->gimage);
col[0] = r;
col[1] = g;
col[2] = b;
by_color_select (bcd->gimage,
drawable,
col,
bcd->threshold,
bcd->operation,
by_color_options->antialias,
by_color_options->feather,
by_color_options->feather_radius,
by_color_options->sample_merged);
/* 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);
}