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
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2001-03-10 01:39:18 +08:00
|
|
|
|
1999-07-27 08:14:14 +08:00
|
|
|
#include "config.h"
|
2000-03-26 02:17:01 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdlib.h>
|
2000-03-26 02:17:01 +08:00
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-08-06 00:08:19 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2001-01-24 07:56:18 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "tools-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/boundary.h"
|
|
|
|
#include "base/pixel-region.h"
|
|
|
|
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpchannel.h"
|
|
|
|
#include "core/gimpdrawable.h"
|
|
|
|
#include "core/gimpimage.h"
|
2001-10-22 20:13:44 +08:00
|
|
|
#include "core/gimpimage-contiguous-region.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpimage-mask.h"
|
2001-10-22 20:13:44 +08:00
|
|
|
#include "core/gimpimage-mask-select.h"
|
2001-11-20 21:53:21 +08:00
|
|
|
#include "core/gimptoolinfo.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
2001-10-13 20:52:30 +08:00
|
|
|
#include "display/gimpdisplay-foreach.h"
|
2001-11-01 05:20:09 +08:00
|
|
|
#include "display/gimpdisplayshell.h"
|
2001-09-26 07:23:09 +08:00
|
|
|
|
2001-03-08 09:07:03 +08:00
|
|
|
#include "gimpeditselectiontool.h"
|
|
|
|
#include "gimpfuzzyselecttool.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "selection_options.h"
|
1998-07-08 14:41:58 +08:00
|
|
|
|
removed the gimp_busy boolean, check whether user_installation is needed
2001-07-10 Michael Natterer <mitch@gimp.org>
* app/app_procs.[ch]: removed the gimp_busy boolean, check whether
user_installation is needed here, not in user_install.c, parse
gtkrc an friends only if(!no_interface), create the Gimp object
before parsing gimp's rc files an pas it to the parse functions,
many other cleanups.
* app/appenums.h: added MessageHandlerType and StackTraceMode.
* app/appenv.h: removed MessageHandlerType, declare all global
variables from main.c (no more hidden global stuff please).
* app/errors.[ch]: added the fatal message func here (from main.c),
removed the StackTraceMode enum.
* app/gimprc.[ch]: renamed functions to gimprc_*(), pass a Gimp
pointer to some functions.
* app/gimpunit.c
* app/unitrc.h: ok, this is ugly: renamed all functions to
_gimp_unit_*() and made them public. The unit list is part
of the Gimp object now, so pass a Gimp* to all functions.
* app/libgimp_glue.[ch]: added EEKy wrappers for all gimp_unit_*()
functions which are used by widgets.
* app/main.c: cleaned up the global variables, removed the fatal
message handler, call app_init() directly, not via the
user_install stuff, misc. cleanups.
* app/user_install.[ch]: removed the check if user_installation is
needed (done by app_procs.c now).
* app/core/gimp.[ch]: added the user_unit list and the "busy"
boolean. Moved gimp_[set|unset]_busy() here. Added
gimp_initialize() which is called after unitrc and gimprc are
parsed.
* app/batch.c
* app/colormaps.c
* app/devices.c
* app/disp_callbacks.c
* app/gdisplay_ops.c
* app/gimphelp.c
* app/module_db.c
* app/nav_window.c
* app/plug_in.c
* app/core/gimpcontext.c
* app/core/gimpdatafiles.c
* app/core/gimpimage-convert.c
* app/core/gimpimage-duplicate.c
* app/core/gimpimage.c
* app/core/gimpparasite.c
* app/core/gimpparasitelist.h
* app/gui/file-open-dialog.c
* app/gui/gui.[ch]
* app/gui/info-dialog.c
* app/gui/info-window.c
* app/gui/preferences-dialog.c
* app/gui/session.c
* app/gui/tips-dialog.c
* app/gui/toolbox.c
* app/tools/gimpblendtool.c
* app/tools/gimpbucketfilltool.c
* app/tools/gimpcolorpickertool.c
* app/tools/gimpfuzzyselecttool.c
* app/tools/gimptransformtool.c
* app/tools/tool_manager.c
* app/widgets/gimpcolorpanel.c
* app/widgets/gimpcursor.c
* app/xcf/xcf-load.c
* app/xcf/xcf-save.c
* app/xcf/xcf.c
* tools/pdbgen/Makefile.am
* tools/pdbgen/app.pl
* tools/pdbgen/enums.pl
* tools/pdbgen/pdb/image.pdb
* tools/pdbgen/pdb/message.pdb
* tools/pdbgen/pdb/unit.pdb
* app/pdb/image_cmds.c
* app/pdb/message_cmds.c
* app/pdb/unit_cmds.c: changed accordingly, minor cleanups.
2001-07-11 03:16:16 +08:00
|
|
|
#include "gimprc.h"
|
|
|
|
|
1999-07-07 02:13:59 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
static void gimp_fuzzy_select_tool_class_init (GimpFuzzySelectToolClass *klass);
|
|
|
|
static void gimp_fuzzy_select_tool_init (GimpFuzzySelectTool *fuzzy_select);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
static void gimp_fuzzy_select_tool_finalize (GObject *object);
|
|
|
|
|
|
|
|
static void gimp_fuzzy_select_tool_button_press (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void gimp_fuzzy_select_tool_button_release (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void gimp_fuzzy_select_tool_motion (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
|
|
|
|
static void gimp_fuzzy_select_tool_draw (GimpDrawTool *draw_tool);
|
2000-03-02 07:22:43 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
static GdkSegment * fuzzy_select_calculate (GimpFuzzySelectTool *fuzzy_sel,
|
2001-10-22 20:13:44 +08:00
|
|
|
GimpDisplay *gdisp,
|
2001-03-10 01:39:18 +08:00
|
|
|
gint *nsegs);
|
1999-04-13 01:55:06 +08:00
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
/* XSegments which make up the fuzzy selection boundary */
|
2000-03-26 02:17:01 +08:00
|
|
|
static GdkSegment *segs = NULL;
|
|
|
|
static gint num_segs = 0;
|
1999-04-19 05:22:41 +08:00
|
|
|
|
2001-11-21 07:00:47 +08:00
|
|
|
static GimpSelectionToolClass *parent_class = NULL;
|
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
|
|
|
void
|
2001-11-21 07:00:47 +08:00
|
|
|
gimp_fuzzy_select_tool_register (Gimp *gimp,
|
|
|
|
GimpToolRegisterCallback callback)
|
2001-03-10 01:39:18 +08:00
|
|
|
{
|
2001-11-21 07:00:47 +08:00
|
|
|
(* callback) (gimp,
|
|
|
|
GIMP_TYPE_FUZZY_SELECT_TOOL,
|
|
|
|
selection_options_new,
|
|
|
|
FALSE,
|
|
|
|
"gimp:fuzzy_select_tool",
|
|
|
|
_("Fuzzy Select"),
|
|
|
|
_("Select contiguous regions"),
|
|
|
|
_("/Tools/Selection Tools/Fuzzy Select"), "Z",
|
|
|
|
NULL, "tools/fuzzy_select.html",
|
|
|
|
GIMP_STOCK_TOOL_FUZZY_SELECT);
|
2001-03-10 01:39:18 +08:00
|
|
|
}
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
GType
|
2001-03-10 01:39:18 +08:00
|
|
|
gimp_fuzzy_select_tool_get_type (void)
|
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
static GType tool_type = 0;
|
2001-03-10 01:39:18 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
if (! tool_type)
|
2001-03-10 01:39:18 +08:00
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
static const GTypeInfo tool_info =
|
2001-03-10 01:39:18 +08:00
|
|
|
{
|
|
|
|
sizeof (GimpFuzzySelectToolClass),
|
2001-08-14 22:53:55 +08:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_fuzzy_select_tool_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpFuzzySelectTool),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_fuzzy_select_tool_init,
|
2001-03-10 01:39:18 +08:00
|
|
|
};
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
tool_type = g_type_register_static (GIMP_TYPE_SELECTION_TOOL,
|
|
|
|
"GimpFuzzySelectTool",
|
|
|
|
&tool_info, 0);
|
2001-03-10 01:39:18 +08:00
|
|
|
}
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
return tool_type;
|
2001-03-10 01:39:18 +08:00
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-10-22 20:13:44 +08:00
|
|
|
/* private functions */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2001-03-10 01:39:18 +08:00
|
|
|
gimp_fuzzy_select_tool_class_init (GimpFuzzySelectToolClass *klass)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-10-22 20:13:44 +08:00
|
|
|
GObjectClass *object_class;
|
2001-03-10 01:39:18 +08:00
|
|
|
GimpToolClass *tool_class;
|
|
|
|
GimpDrawToolClass *draw_tool_class;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-10-22 20:13:44 +08:00
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
2001-08-14 22:53:55 +08:00
|
|
|
tool_class = GIMP_TOOL_CLASS (klass);
|
|
|
|
draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-03-10 01:39:18 +08:00
|
|
|
|
2001-10-22 20:13:44 +08:00
|
|
|
object_class->finalize = gimp_fuzzy_select_tool_finalize;
|
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
tool_class->button_press = gimp_fuzzy_select_tool_button_press;
|
|
|
|
tool_class->button_release = gimp_fuzzy_select_tool_button_release;
|
|
|
|
tool_class->motion = gimp_fuzzy_select_tool_motion;
|
|
|
|
|
|
|
|
draw_tool_class->draw = gimp_fuzzy_select_tool_draw;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_fuzzy_select_tool_init (GimpFuzzySelectTool *fuzzy_select)
|
|
|
|
{
|
|
|
|
GimpTool *tool;
|
|
|
|
GimpSelectionTool *select_tool;
|
|
|
|
|
|
|
|
tool = GIMP_TOOL (fuzzy_select);
|
|
|
|
select_tool = GIMP_SELECTION_TOOL (fuzzy_select);
|
|
|
|
|
|
|
|
tool->tool_cursor = GIMP_FUZZY_SELECT_TOOL_CURSOR;
|
|
|
|
tool->scroll_lock = TRUE; /* Do not allow scrolling */
|
|
|
|
|
2001-10-22 20:13:44 +08:00
|
|
|
fuzzy_select->fuzzy_mask = NULL;
|
2001-03-10 01:39:18 +08:00
|
|
|
fuzzy_select->x = 0;
|
|
|
|
fuzzy_select->y = 0;
|
|
|
|
fuzzy_select->first_x = 0;
|
|
|
|
fuzzy_select->first_y = 0;
|
|
|
|
fuzzy_select->first_threshold = 0.0;
|
|
|
|
}
|
|
|
|
|
2001-10-22 20:13:44 +08:00
|
|
|
static void
|
|
|
|
gimp_fuzzy_select_tool_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GimpFuzzySelectTool *fuzzy_sel;
|
|
|
|
|
|
|
|
fuzzy_sel = GIMP_FUZZY_SELECT_TOOL (object);
|
|
|
|
|
|
|
|
if (fuzzy_sel->fuzzy_mask)
|
|
|
|
{
|
|
|
|
g_object_unref (G_OBJECT (fuzzy_sel->fuzzy_mask));
|
|
|
|
fuzzy_sel->fuzzy_mask = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
static void
|
2001-11-09 03:14:51 +08:00
|
|
|
gimp_fuzzy_select_tool_button_press (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
2001-03-10 01:39:18 +08:00
|
|
|
{
|
|
|
|
GimpFuzzySelectTool *fuzzy_sel;
|
2001-11-20 21:53:21 +08:00
|
|
|
SelectionOptions *sel_options;
|
2001-03-10 01:39:18 +08:00
|
|
|
|
|
|
|
fuzzy_sel = GIMP_FUZZY_SELECT_TOOL (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-20 21:53:21 +08:00
|
|
|
sel_options = (SelectionOptions *) tool->tool_info->tool_options;
|
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
fuzzy_sel->x = coords->x;
|
|
|
|
fuzzy_sel->y = coords->y;
|
|
|
|
fuzzy_sel->first_x = fuzzy_sel->x;
|
|
|
|
fuzzy_sel->first_y = fuzzy_sel->y;
|
2001-11-20 21:53:21 +08:00
|
|
|
fuzzy_sel->first_threshold = sel_options->threshold;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
tool->state = ACTIVE;
|
2000-12-31 12:07:42 +08:00
|
|
|
tool->gdisp = gdisp;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
switch (GIMP_SELECTION_TOOL (tool)->op)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-10 01:39:18 +08:00
|
|
|
case SELECTION_MOVE_MASK:
|
2001-11-09 03:14:51 +08:00
|
|
|
init_edit_selection (tool, gdisp, coords, EDIT_MASK_TRANSLATE);
|
1997-11-25 06:05:25 +08:00
|
|
|
return;
|
2001-03-10 01:39:18 +08:00
|
|
|
case SELECTION_MOVE:
|
2001-11-09 03:14:51 +08:00
|
|
|
init_edit_selection (tool, gdisp, coords, EDIT_MASK_TO_LAYER_TRANSLATE);
|
1999-05-05 17:10:35 +08:00
|
|
|
return;
|
2001-03-10 01:39:18 +08:00
|
|
|
default:
|
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate the region boundary */
|
2001-03-10 01:39:18 +08:00
|
|
|
segs = fuzzy_select_calculate (fuzzy_sel, gdisp, &num_segs);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-02-03 20:10:23 +08:00
|
|
|
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), gdisp);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-09 03:14:51 +08:00
|
|
|
gimp_fuzzy_select_tool_button_release (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-10 01:39:18 +08:00
|
|
|
GimpFuzzySelectTool *fuzzy_sel;
|
2001-11-20 21:53:21 +08:00
|
|
|
SelectionOptions *sel_options;
|
2001-03-10 01:39:18 +08:00
|
|
|
GimpDrawable *drawable;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
fuzzy_sel = GIMP_FUZZY_SELECT_TOOL (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-20 21:53:21 +08:00
|
|
|
sel_options = (SelectionOptions *) tool->tool_info->tool_options;
|
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
|
2002-02-05 19:35:03 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
tool->state = INACTIVE;
|
|
|
|
|
|
|
|
/* First take care of the case where the user "cancels" the action */
|
2001-11-09 03:14:51 +08:00
|
|
|
if (! (state & GDK_BUTTON3_MASK))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-10-22 20:13:44 +08:00
|
|
|
drawable = gimp_image_active_drawable (gdisp->gimage);
|
|
|
|
|
|
|
|
gimp_image_mask_select_channel (gdisp->gimage,
|
|
|
|
drawable,
|
2001-11-20 21:53:21 +08:00
|
|
|
sel_options->sample_merged,
|
2001-10-22 20:13:44 +08:00
|
|
|
fuzzy_sel->fuzzy_mask,
|
|
|
|
GIMP_SELECTION_TOOL (tool)->op,
|
2001-11-20 21:53:21 +08:00
|
|
|
sel_options->feather,
|
|
|
|
sel_options->feather_radius,
|
|
|
|
sel_options->feather_radius);
|
1999-06-26 19:16:47 +08:00
|
|
|
|
2001-10-22 20:13:44 +08:00
|
|
|
g_object_unref (G_OBJECT (fuzzy_sel->fuzzy_mask));
|
|
|
|
fuzzy_sel->fuzzy_mask = NULL;
|
2001-03-10 01:39:18 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
gdisplays_flush ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the segment array is allocated, free it */
|
|
|
|
if (segs)
|
2001-10-22 20:13:44 +08:00
|
|
|
{
|
|
|
|
g_free (segs);
|
|
|
|
segs = NULL;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-09 03:14:51 +08:00
|
|
|
gimp_fuzzy_select_tool_motion (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-10 01:39:18 +08:00
|
|
|
GimpFuzzySelectTool *fuzzy_sel;
|
|
|
|
GimpSelectionTool *sel_tool;
|
2001-11-20 21:53:21 +08:00
|
|
|
SelectionOptions *sel_options;
|
2001-03-10 01:39:18 +08:00
|
|
|
GdkSegment *new_segs;
|
|
|
|
gint num_new_segs;
|
|
|
|
gint diff_x, diff_y;
|
|
|
|
gdouble diff;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
static guint32 last_time = 0;
|
2000-02-19 21:19:08 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
fuzzy_sel = GIMP_FUZZY_SELECT_TOOL (tool);
|
|
|
|
sel_tool = GIMP_SELECTION_TOOL (tool);
|
2000-03-02 07:22:43 +08:00
|
|
|
|
2001-11-20 21:53:21 +08:00
|
|
|
sel_options = (SelectionOptions *) tool->tool_info->tool_options;
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (tool->state != ACTIVE)
|
|
|
|
return;
|
|
|
|
|
2000-02-19 21:19:08 +08:00
|
|
|
/* don't let the events come in too fast, ignore below a delay of 100 ms */
|
2001-11-09 03:14:51 +08:00
|
|
|
if (ABS (time - last_time) < 100)
|
2000-02-19 21:19:08 +08:00
|
|
|
return;
|
2001-03-10 01:39:18 +08:00
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
last_time = time;
|
2000-02-19 21:19:08 +08:00
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
diff_x = coords->x - fuzzy_sel->first_x;
|
|
|
|
diff_y = coords->y - fuzzy_sel->first_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-01-23 06:26:20 +08:00
|
|
|
diff = ((ABS (diff_x) > ABS (diff_y)) ? diff_x : diff_y) / 2.0;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-20 21:53:21 +08:00
|
|
|
gtk_adjustment_set_value (GTK_ADJUSTMENT (sel_options->threshold_w),
|
2000-01-23 06:26:20 +08:00
|
|
|
fuzzy_sel->first_threshold + diff);
|
2001-03-10 01:39:18 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* calculate the new fuzzy boundary */
|
2001-03-10 01:39:18 +08:00
|
|
|
new_segs = fuzzy_select_calculate (fuzzy_sel, gdisp, &num_new_segs);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* make sure the XSegment array is freed before we assign the new one */
|
|
|
|
if (segs)
|
|
|
|
g_free (segs);
|
|
|
|
segs = new_segs;
|
|
|
|
num_segs = num_new_segs;
|
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-07-07 02:13:59 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static GdkSegment *
|
2001-03-10 01:39:18 +08:00
|
|
|
fuzzy_select_calculate (GimpFuzzySelectTool *fuzzy_sel,
|
2001-10-22 20:13:44 +08:00
|
|
|
GimpDisplay *gdisp,
|
2001-03-10 01:39:18 +08:00
|
|
|
gint *nsegs)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-02-07 19:33:01 +08:00
|
|
|
GimpTool *tool;
|
2001-11-20 21:53:21 +08:00
|
|
|
SelectionOptions *sel_options;
|
|
|
|
PixelRegion maskPR;
|
|
|
|
GimpChannel *new;
|
|
|
|
GdkSegment *segs;
|
|
|
|
BoundSeg *bsegs;
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
gint i;
|
|
|
|
gint x, y;
|
|
|
|
|
2002-02-07 19:33:01 +08:00
|
|
|
tool = GIMP_TOOL (fuzzy_sel);
|
|
|
|
|
|
|
|
sel_options = (SelectionOptions *) tool->tool_info->tool_options;
|
1999-01-11 07:36:29 +08:00
|
|
|
|
2001-11-20 21:53:21 +08:00
|
|
|
drawable = gimp_image_active_drawable (gdisp->gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-02-07 19:33:01 +08:00
|
|
|
gimp_display_shell_set_override_cursor (GIMP_DISPLAY_SHELL (gdisp->shell),
|
|
|
|
GDK_WATCH);
|
2000-03-26 02:17:01 +08:00
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
x = fuzzy_sel->x;
|
|
|
|
y = fuzzy_sel->y;
|
|
|
|
|
2001-11-20 21:53:21 +08:00
|
|
|
if (! sel_options->sample_merged)
|
2001-11-09 03:14:51 +08:00
|
|
|
{
|
|
|
|
gint off_x, off_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
gimp_drawable_offsets (drawable, &off_x, &off_y);
|
|
|
|
|
|
|
|
x -= off_x;
|
|
|
|
y -= off_y;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-10-22 20:13:44 +08:00
|
|
|
new = gimp_image_contiguous_region_by_seed (gdisp->gimage, drawable,
|
2001-11-20 21:53:21 +08:00
|
|
|
sel_options->sample_merged,
|
|
|
|
sel_options->antialias,
|
|
|
|
sel_options->threshold,
|
2002-02-10 23:18:08 +08:00
|
|
|
sel_options->select_transparent,
|
2001-10-22 20:13:44 +08:00
|
|
|
x, y);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-10-22 20:13:44 +08:00
|
|
|
if (fuzzy_sel->fuzzy_mask)
|
|
|
|
g_object_unref (G_OBJECT (fuzzy_sel->fuzzy_mask));
|
2000-12-29 00:19:55 +08:00
|
|
|
|
2001-10-22 20:13:44 +08:00
|
|
|
fuzzy_sel->fuzzy_mask = new;
|
2000-12-29 00:19:55 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* calculate and allocate a new XSegment array which represents the boundary
|
|
|
|
* of the color-contiguous region
|
|
|
|
*/
|
2001-10-22 20:13:44 +08:00
|
|
|
pixel_region_init (&maskPR,
|
|
|
|
gimp_drawable_data (GIMP_DRAWABLE (fuzzy_sel->fuzzy_mask)),
|
2001-01-15 05:11:52 +08:00
|
|
|
0, 0,
|
2001-10-22 20:13:44 +08:00
|
|
|
gimp_drawable_width (GIMP_DRAWABLE (fuzzy_sel->fuzzy_mask)),
|
|
|
|
gimp_drawable_height (GIMP_DRAWABLE (fuzzy_sel->fuzzy_mask)),
|
1999-07-07 02:13:59 +08:00
|
|
|
FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
bsegs = find_mask_boundary (&maskPR, nsegs, WithinBounds,
|
|
|
|
0, 0,
|
2001-10-22 20:13:44 +08:00
|
|
|
gimp_drawable_width (GIMP_DRAWABLE (fuzzy_sel->fuzzy_mask)),
|
|
|
|
gimp_drawable_height (GIMP_DRAWABLE (fuzzy_sel->fuzzy_mask)));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-03-26 02:17:01 +08:00
|
|
|
segs = g_new (GdkSegment, *nsegs);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
for (i = 0; i < *nsegs; i++)
|
|
|
|
{
|
2001-11-09 03:14:51 +08:00
|
|
|
gdisplay_transform_coords (gdisp,
|
|
|
|
bsegs[i].x1, bsegs[i].y1,
|
|
|
|
&x, &y,
|
2001-11-20 21:53:21 +08:00
|
|
|
! sel_options->sample_merged);
|
2001-11-09 03:14:51 +08:00
|
|
|
segs[i].x1 = x;
|
|
|
|
segs[i].y1 = y;
|
|
|
|
|
|
|
|
gdisplay_transform_coords (gdisp,
|
|
|
|
bsegs[i].x2, bsegs[i].y2,
|
|
|
|
&x, &y,
|
2001-11-20 21:53:21 +08:00
|
|
|
! sel_options->sample_merged);
|
2001-11-09 03:14:51 +08:00
|
|
|
segs[i].x2 = x;
|
|
|
|
segs[i].y2 = y;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_free (bsegs);
|
|
|
|
|
2002-02-07 19:33:01 +08:00
|
|
|
gimp_display_shell_unset_override_cursor (GIMP_DISPLAY_SHELL (gdisp->shell));
|
1999-01-11 07:36:29 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
return segs;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-03-10 01:39:18 +08:00
|
|
|
gimp_fuzzy_select_tool_draw (GimpDrawTool *draw_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-03-10 01:39:18 +08:00
|
|
|
GimpFuzzySelectTool *fuzzy_sel;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-10 01:39:18 +08:00
|
|
|
fuzzy_sel = GIMP_FUZZY_SELECT_TOOL (draw_tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (segs)
|
2001-03-10 01:39:18 +08:00
|
|
|
gdk_draw_segments (draw_tool->win,
|
|
|
|
draw_tool->gc,
|
|
|
|
segs, num_segs);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|