2006-12-09 13:33:38 -08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-24 14:05:25 -08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
|
*
|
2006-07-31 04:42:51 -07:00
|
|
|
* gimpregionselecttool.c
|
|
|
|
|
*
|
2009-01-17 14:28:01 -08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-24 14:05:25 -08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 14:28:01 -08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-24 14:05:25 -08:00
|
|
|
* (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
|
2018-07-11 14:47:19 -07:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1997-11-24 14:05:25 -08:00
|
|
|
*/
|
2001-03-09 09:39:18 -08:00
|
|
|
|
1999-07-26 17:14:14 -07:00
|
|
|
#include "config.h"
|
2000-03-25 10:17:01 -08:00
|
|
|
|
2008-10-09 13:24:04 -07:00
|
|
|
#include <gegl.h>
|
2000-12-16 13:37:03 -08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
2001-08-05 09:08:19 -07:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
2002-05-03 05:45:22 -07:00
|
|
|
#include "tools-types.h"
|
2000-12-16 13:37:03 -08:00
|
|
|
|
2014-06-11 13:15:00 -07:00
|
|
|
#include "core/gimp-utils.h"
|
2012-03-19 06:22:41 -07:00
|
|
|
#include "core/gimpboundary.h"
|
2001-05-08 19:32:03 -07:00
|
|
|
#include "core/gimpchannel.h"
|
2003-10-06 05:17:11 -07:00
|
|
|
#include "core/gimpchannel-select.h"
|
2001-05-08 19:32:03 -07:00
|
|
|
#include "core/gimpimage.h"
|
2016-05-20 07:46:26 -07:00
|
|
|
#include "core/gimplayer-floating-selection.h"
|
2001-05-08 19:32:03 -07:00
|
|
|
|
2001-09-25 16:23:09 -07:00
|
|
|
#include "display/gimpdisplay.h"
|
2001-10-31 13:20:09 -08:00
|
|
|
#include "display/gimpdisplayshell.h"
|
2003-01-03 10:01:30 -08:00
|
|
|
#include "display/gimpdisplayshell-cursor.h"
|
2001-09-25 16:23:09 -07:00
|
|
|
|
2008-03-09 08:05:54 -07:00
|
|
|
#include "gimpregionselectoptions.h"
|
2006-07-31 04:42:51 -07:00
|
|
|
#include "gimpregionselecttool.h"
|
2003-04-15 09:05:52 -07:00
|
|
|
#include "gimptoolcontrol.h"
|
1998-07-07 23:41:58 -07:00
|
|
|
|
2003-03-25 08:38:19 -08:00
|
|
|
#include "gimp-intl.h"
|
1999-07-06 11:13:59 -07:00
|
|
|
|
2000-12-29 07:22:01 -08:00
|
|
|
|
2007-02-27 10:55:12 -08:00
|
|
|
static void gimp_region_select_tool_finalize (GObject *object);
|
|
|
|
|
|
|
|
|
|
static void gimp_region_select_tool_button_press (GimpTool *tool,
|
2008-11-01 08:17:36 -07:00
|
|
|
const GimpCoords *coords,
|
2007-02-27 10:55:12 -08:00
|
|
|
guint32 time,
|
|
|
|
|
GdkModifierType state,
|
2009-06-20 08:37:31 -07:00
|
|
|
GimpButtonPressType press_type,
|
2007-02-27 10:55:12 -08:00
|
|
|
GimpDisplay *display);
|
|
|
|
|
static void gimp_region_select_tool_button_release (GimpTool *tool,
|
2008-11-01 08:17:36 -07:00
|
|
|
const GimpCoords *coords,
|
2007-02-27 10:55:12 -08:00
|
|
|
guint32 time,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GimpButtonReleaseType release_type,
|
|
|
|
|
GimpDisplay *display);
|
|
|
|
|
static void gimp_region_select_tool_motion (GimpTool *tool,
|
2008-11-01 08:17:36 -07:00
|
|
|
const GimpCoords *coords,
|
2007-02-27 10:55:12 -08:00
|
|
|
guint32 time,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GimpDisplay *display);
|
|
|
|
|
static void gimp_region_select_tool_cursor_update (GimpTool *tool,
|
2008-11-01 08:17:36 -07:00
|
|
|
const GimpCoords *coords,
|
2007-02-27 10:55:12 -08:00
|
|
|
GdkModifierType state,
|
|
|
|
|
GimpDisplay *display);
|
|
|
|
|
|
|
|
|
|
static void gimp_region_select_tool_draw (GimpDrawTool *draw_tool);
|
|
|
|
|
|
2014-06-11 13:15:00 -07:00
|
|
|
static void gimp_region_select_tool_get_mask (GimpRegionSelectTool *region_sel,
|
|
|
|
|
GimpDisplay *display);
|
1999-04-12 10:55:06 -07:00
|
|
|
|
2000-12-30 20:07:42 -08:00
|
|
|
|
2006-07-31 04:42:51 -07:00
|
|
|
G_DEFINE_TYPE (GimpRegionSelectTool, gimp_region_select_tool,
|
2006-05-15 02:46:31 -07:00
|
|
|
GIMP_TYPE_SELECTION_TOOL)
|
2005-12-13 01:13:50 -08:00
|
|
|
|
2006-07-31 04:42:51 -07:00
|
|
|
#define parent_class gimp_region_select_tool_parent_class
|
2001-11-20 15:00:47 -08:00
|
|
|
|
2001-03-09 09:39:18 -08:00
|
|
|
|
1997-11-24 14:05:25 -08:00
|
|
|
static void
|
2006-07-31 04:42:51 -07:00
|
|
|
gimp_region_select_tool_class_init (GimpRegionSelectToolClass *klass)
|
1997-11-24 14:05:25 -08:00
|
|
|
{
|
2004-06-04 16:08:29 -07:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
|
|
|
|
GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
|
1997-11-24 14:05:25 -08:00
|
|
|
|
2006-07-31 04:42:51 -07:00
|
|
|
object_class->finalize = gimp_region_select_tool_finalize;
|
2001-10-22 05:13:44 -07:00
|
|
|
|
2006-07-31 04:42:51 -07:00
|
|
|
tool_class->button_press = gimp_region_select_tool_button_press;
|
|
|
|
|
tool_class->button_release = gimp_region_select_tool_button_release;
|
|
|
|
|
tool_class->motion = gimp_region_select_tool_motion;
|
|
|
|
|
tool_class->cursor_update = gimp_region_select_tool_cursor_update;
|
2001-03-09 09:39:18 -08:00
|
|
|
|
2006-07-31 04:42:51 -07:00
|
|
|
draw_tool_class->draw = gimp_region_select_tool_draw;
|
2001-03-09 09:39:18 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2006-07-31 04:42:51 -07:00
|
|
|
gimp_region_select_tool_init (GimpRegionSelectTool *region_select)
|
2001-03-09 09:39:18 -08:00
|
|
|
{
|
2006-07-31 04:42:51 -07:00
|
|
|
GimpTool *tool = GIMP_TOOL (region_select);
|
2001-03-09 09:39:18 -08:00
|
|
|
|
2002-05-02 14:03:27 -07:00
|
|
|
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
|
2002-03-28 19:50:29 -08:00
|
|
|
|
2006-07-31 04:42:51 -07:00
|
|
|
region_select->x = 0;
|
|
|
|
|
region_select->y = 0;
|
|
|
|
|
region_select->saved_threshold = 0.0;
|
2002-06-26 15:16:59 -07:00
|
|
|
|
2006-07-31 04:42:51 -07:00
|
|
|
region_select->region_mask = NULL;
|
|
|
|
|
region_select->segs = NULL;
|
2010-09-24 11:58:22 -07:00
|
|
|
region_select->n_segs = 0;
|
2001-03-09 09:39:18 -08:00
|
|
|
}
|
|
|
|
|
|
2001-10-22 05:13:44 -07:00
|
|
|
static void
|
2006-07-31 04:42:51 -07:00
|
|
|
gimp_region_select_tool_finalize (GObject *object)
|
2001-10-22 05:13:44 -07:00
|
|
|
{
|
2006-07-31 04:42:51 -07:00
|
|
|
GimpRegionSelectTool *region_sel = GIMP_REGION_SELECT_TOOL (object);
|
2001-10-22 05:13:44 -07:00
|
|
|
|
2017-07-15 09:38:01 -07:00
|
|
|
g_clear_object (®ion_sel->region_mask);
|
2002-03-19 05:14:25 -08:00
|
|
|
|
2017-07-15 09:38:01 -07:00
|
|
|
g_clear_pointer (®ion_sel->segs, g_free);
|
|
|
|
|
region_sel->n_segs = 0;
|
2002-06-26 15:16:59 -07:00
|
|
|
|
2002-03-19 05:14:25 -08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2001-10-22 05:13:44 -07:00
|
|
|
}
|
|
|
|
|
|
2001-03-09 09:39:18 -08:00
|
|
|
static void
|
2009-06-20 08:37:31 -07:00
|
|
|
gimp_region_select_tool_button_press (GimpTool *tool,
|
|
|
|
|
const GimpCoords *coords,
|
|
|
|
|
guint32 time,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GimpButtonPressType press_type,
|
|
|
|
|
GimpDisplay *display)
|
2001-03-09 09:39:18 -08:00
|
|
|
{
|
2008-03-09 08:05:54 -07:00
|
|
|
GimpRegionSelectTool *region_sel = GIMP_REGION_SELECT_TOOL (tool);
|
|
|
|
|
GimpRegionSelectOptions *options = GIMP_REGION_SELECT_TOOL_GET_OPTIONS (tool);
|
2001-11-20 05:53:21 -08:00
|
|
|
|
2006-07-31 04:42:51 -07:00
|
|
|
region_sel->x = coords->x;
|
|
|
|
|
region_sel->y = coords->y;
|
|
|
|
|
region_sel->saved_threshold = options->threshold;
|
1997-11-24 14:05:25 -08:00
|
|
|
|
2011-06-03 00:46:10 -07:00
|
|
|
if (gimp_selection_tool_start_edit (GIMP_SELECTION_TOOL (region_sel),
|
|
|
|
|
display, coords))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-03 04:31:08 -07:00
|
|
|
gimp_tool_control_activate (tool->control);
|
2006-03-28 09:55:52 -08:00
|
|
|
tool->display = display;
|
1997-11-24 14:05:25 -08:00
|
|
|
|
2006-07-31 04:42:51 -07:00
|
|
|
gimp_tool_push_status (tool, display,
|
2006-09-11 23:37:54 -07:00
|
|
|
_("Move the mouse to change threshold"));
|
2005-04-11 05:10:39 -07:00
|
|
|
|
2014-06-11 13:15:00 -07:00
|
|
|
gimp_region_select_tool_get_mask (region_sel, display);
|
1997-11-24 14:05:25 -08:00
|
|
|
|
2006-03-28 09:55:52 -08:00
|
|
|
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
|
1997-11-24 14:05:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2007-02-27 10:55:12 -08:00
|
|
|
gimp_region_select_tool_button_release (GimpTool *tool,
|
2008-11-01 08:17:36 -07:00
|
|
|
const GimpCoords *coords,
|
2007-02-27 10:55:12 -08:00
|
|
|
guint32 time,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GimpButtonReleaseType release_type,
|
|
|
|
|
GimpDisplay *display)
|
1997-11-24 14:05:25 -08:00
|
|
|
{
|
2008-03-09 08:05:54 -07:00
|
|
|
GimpRegionSelectTool *region_sel = GIMP_REGION_SELECT_TOOL (tool);
|
|
|
|
|
GimpSelectionOptions *sel_options = GIMP_SELECTION_TOOL_GET_OPTIONS (tool);
|
|
|
|
|
GimpRegionSelectOptions *options = GIMP_REGION_SELECT_TOOL_GET_OPTIONS (tool);
|
2009-10-07 10:00:42 -07:00
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
2005-04-11 05:10:39 -07:00
|
|
|
|
2006-03-28 09:55:52 -08:00
|
|
|
gimp_tool_pop_status (tool, display);
|
2001-11-20 05:53:21 -08:00
|
|
|
|
2001-03-09 09:39:18 -08:00
|
|
|
gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
|
2002-02-05 03:35:03 -08:00
|
|
|
|
2003-01-03 05:59:23 -08:00
|
|
|
gimp_tool_control_halt (tool->control);
|
1997-11-24 14:05:25 -08:00
|
|
|
|
2014-06-11 13:15:00 -07:00
|
|
|
if (options->draw_mask)
|
|
|
|
|
gimp_display_shell_set_mask (gimp_display_get_shell (display),
|
2016-02-05 12:19:17 -08:00
|
|
|
NULL, 0, 0, NULL, FALSE);
|
2014-06-11 13:15:00 -07:00
|
|
|
|
2007-02-27 10:55:12 -08:00
|
|
|
if (release_type != GIMP_BUTTON_RELEASE_CANCEL)
|
1997-11-24 14:05:25 -08:00
|
|
|
{
|
Separate selection tool function (select, move, cut, ...) from selection
2006-10-18 Michael Natterer <mitch@gimp.org>
Separate selection tool function (select, move, cut, ...) from
selection mode (replace, add, ...). Fixes bug #313634 (that bug
wasn't triggered any more in HEAD, but was still there).
* app/tools/tools-enums.h: renamed enum SelectOp to SelectFunction
and replaced the values REPLACE, ADD, SUBTRACT and INTERSECT by a
single value SELECT.
* app/tools/gimpselectiontool.h (struct GimpSelectionTool):
renamed member "op" to "function". Changed "SelectOps saved_op" to
"GimpChannelOps saved_operation".
* app/tools/gimpselectiontool.c: we always have the right
GimpChannelOps in the tool options, so simply use it instead of
mixing up unrelated stuff in one enum. Results is some medium-ugly
nested switches, but is generally much cleaner than before.
* app/tools/gimpforegroundselecttool.c
* app/tools/gimpfreeselecttool.c
* app/tools/gimpiscissorstool.c
* app/tools/gimpregionselecttool.c: changed accordingly. Use the
operation from the tool options instead of selection_tool->op when
making the actual selection.
2006-10-18 01:04:55 -07:00
|
|
|
if (GIMP_SELECTION_TOOL (tool)->function == SELECTION_ANCHOR)
|
2004-07-26 07:50:51 -07:00
|
|
|
{
|
2009-10-07 10:00:42 -07:00
|
|
|
if (gimp_image_get_floating_selection (image))
|
2006-07-31 04:42:51 -07:00
|
|
|
{
|
|
|
|
|
/* If there is a floating selection, anchor it */
|
2009-10-07 10:00:42 -07:00
|
|
|
floating_sel_anchor (gimp_image_get_floating_selection (image));
|
2006-07-31 04:42:51 -07:00
|
|
|
}
|
2004-07-26 07:50:51 -07:00
|
|
|
else
|
2006-07-31 04:42:51 -07:00
|
|
|
{
|
|
|
|
|
/* Otherwise, clear the selection mask */
|
2009-10-07 10:00:42 -07:00
|
|
|
gimp_channel_clear (gimp_image_get_mask (image), NULL, TRUE);
|
2006-07-31 04:42:51 -07:00
|
|
|
}
|
2002-03-15 00:01:07 -08:00
|
|
|
|
2009-10-07 10:00:42 -07:00
|
|
|
gimp_image_flush (image);
|
2004-07-26 07:50:51 -07:00
|
|
|
}
|
2006-07-31 04:42:51 -07:00
|
|
|
else if (region_sel->region_mask)
|
2002-03-03 02:38:37 -08:00
|
|
|
{
|
2009-01-25 15:32:21 -08:00
|
|
|
gint off_x = 0;
|
|
|
|
|
gint off_y = 0;
|
|
|
|
|
|
|
|
|
|
if (! options->sample_merged)
|
2006-07-31 04:42:51 -07:00
|
|
|
{
|
2009-10-07 10:00:42 -07:00
|
|
|
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
|
2002-03-03 02:38:37 -08:00
|
|
|
|
2008-11-02 15:03:29 -08:00
|
|
|
gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
|
2006-07-31 04:42:51 -07:00
|
|
|
}
|
2001-10-22 05:13:44 -07:00
|
|
|
|
2013-04-08 16:38:24 -07:00
|
|
|
gimp_channel_select_buffer (gimp_image_get_mask (image),
|
|
|
|
|
GIMP_REGION_SELECT_TOOL_GET_CLASS (tool)->undo_desc,
|
|
|
|
|
region_sel->region_mask,
|
|
|
|
|
off_x,
|
|
|
|
|
off_y,
|
|
|
|
|
sel_options->operation,
|
|
|
|
|
sel_options->feather,
|
|
|
|
|
sel_options->feather_radius,
|
|
|
|
|
sel_options->feather_radius);
|
1999-06-26 04:16:47 -07:00
|
|
|
|
2001-03-09 09:39:18 -08:00
|
|
|
|
2009-10-07 10:00:42 -07:00
|
|
|
gimp_image_flush (image);
|
2006-07-31 04:42:51 -07:00
|
|
|
}
|
1997-11-24 14:05:25 -08:00
|
|
|
}
|
|
|
|
|
|
2017-07-15 09:38:01 -07:00
|
|
|
g_clear_object (®ion_sel->region_mask);
|
2006-07-31 04:42:51 -07:00
|
|
|
|
2017-07-15 09:38:01 -07:00
|
|
|
g_clear_pointer (®ion_sel->segs, g_free);
|
|
|
|
|
region_sel->n_segs = 0;
|
2003-12-17 04:59:06 -08:00
|
|
|
|
|
|
|
|
/* Restore the original threshold */
|
|
|
|
|
g_object_set (options,
|
2006-07-31 04:42:51 -07:00
|
|
|
"threshold", region_sel->saved_threshold,
|
2003-12-17 04:59:06 -08:00
|
|
|
NULL);
|
1997-11-24 14:05:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2008-11-01 08:17:36 -07:00
|
|
|
gimp_region_select_tool_motion (GimpTool *tool,
|
|
|
|
|
const GimpCoords *coords,
|
|
|
|
|
guint32 time,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GimpDisplay *display)
|
1997-11-24 14:05:25 -08:00
|
|
|
{
|
2008-03-09 08:05:54 -07:00
|
|
|
GimpRegionSelectTool *region_sel = GIMP_REGION_SELECT_TOOL (tool);
|
|
|
|
|
GimpRegionSelectOptions *options = GIMP_REGION_SELECT_TOOL_GET_OPTIONS (tool);
|
|
|
|
|
gint diff_x, diff_y;
|
|
|
|
|
gdouble diff;
|
1997-11-24 14:05:25 -08:00
|
|
|
|
2001-11-08 11:14:51 -08:00
|
|
|
static guint32 last_time = 0;
|
2000-02-19 05:19:08 -08:00
|
|
|
|
|
|
|
|
/* don't let the events come in too fast, ignore below a delay of 100 ms */
|
2003-09-16 06:12:50 -07:00
|
|
|
if (time - last_time < 100)
|
2000-02-19 05:19:08 -08:00
|
|
|
return;
|
2001-03-09 09:39:18 -08:00
|
|
|
|
2001-11-08 11:14:51 -08:00
|
|
|
last_time = time;
|
2000-02-19 05:19:08 -08:00
|
|
|
|
2006-07-31 04:42:51 -07:00
|
|
|
diff_x = coords->x - region_sel->x;
|
|
|
|
|
diff_y = coords->y - region_sel->y;
|
1997-11-24 14:05:25 -08:00
|
|
|
|
2000-01-22 14:26:20 -08:00
|
|
|
diff = ((ABS (diff_x) > ABS (diff_y)) ? diff_x : diff_y) / 2.0;
|
1997-11-24 14:05:25 -08:00
|
|
|
|
2003-02-27 17:14:30 -08:00
|
|
|
g_object_set (options,
|
2006-07-31 04:42:51 -07:00
|
|
|
"threshold", CLAMP (region_sel->saved_threshold + diff, 0, 255),
|
2003-02-07 09:12:21 -08:00
|
|
|
NULL);
|
2001-03-09 09:39:18 -08:00
|
|
|
|
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
1997-11-24 14:05:25 -08:00
|
|
|
|
2014-06-11 13:15:00 -07:00
|
|
|
gimp_region_select_tool_get_mask (region_sel, display);
|
1997-11-24 14:05:25 -08:00
|
|
|
|
2001-03-09 09:39:18 -08:00
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
1997-11-24 14:05:25 -08:00
|
|
|
}
|
|
|
|
|
|
2006-06-03 08:41:40 -07:00
|
|
|
static void
|
2008-11-01 08:17:36 -07:00
|
|
|
gimp_region_select_tool_cursor_update (GimpTool *tool,
|
|
|
|
|
const GimpCoords *coords,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GimpDisplay *display)
|
2006-06-03 08:41:40 -07:00
|
|
|
{
|
2008-03-09 08:05:54 -07:00
|
|
|
GimpRegionSelectOptions *options = GIMP_REGION_SELECT_TOOL_GET_OPTIONS (tool);
|
|
|
|
|
GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_NONE;
|
2009-10-07 10:00:42 -07:00
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
2006-06-03 08:41:40 -07:00
|
|
|
|
2009-10-07 10:00:42 -07:00
|
|
|
if (! gimp_image_coords_in_active_pickable (image, coords,
|
2006-07-31 04:42:51 -07:00
|
|
|
options->sample_merged, FALSE))
|
2006-06-03 08:41:40 -07:00
|
|
|
modifier = GIMP_CURSOR_MODIFIER_BAD;
|
|
|
|
|
|
|
|
|
|
gimp_tool_control_set_cursor_modifier (tool->control, modifier);
|
|
|
|
|
|
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-20 03:40:38 -07:00
|
|
|
static void
|
2006-07-31 04:42:51 -07:00
|
|
|
gimp_region_select_tool_draw (GimpDrawTool *draw_tool)
|
2002-08-20 03:40:38 -07:00
|
|
|
{
|
2010-09-24 11:58:22 -07:00
|
|
|
GimpRegionSelectTool *region_sel = GIMP_REGION_SELECT_TOOL (draw_tool);
|
|
|
|
|
GimpRegionSelectOptions *options = GIMP_REGION_SELECT_TOOL_GET_OPTIONS (draw_tool);
|
2002-08-20 03:40:38 -07:00
|
|
|
|
2014-06-11 13:15:00 -07:00
|
|
|
if (! options->draw_mask && region_sel->region_mask)
|
2003-11-10 11:35:56 -08:00
|
|
|
{
|
2014-06-11 13:15:00 -07:00
|
|
|
if (! region_sel->segs)
|
|
|
|
|
{
|
|
|
|
|
/* calculate and allocate a new segment array which represents
|
|
|
|
|
* the boundary of the contiguous region
|
|
|
|
|
*/
|
|
|
|
|
region_sel->segs = gimp_boundary_find (region_sel->region_mask, NULL,
|
|
|
|
|
babl_format ("Y float"),
|
|
|
|
|
GIMP_BOUNDARY_WITHIN_BOUNDS,
|
|
|
|
|
0, 0,
|
|
|
|
|
gegl_buffer_get_width (region_sel->region_mask),
|
|
|
|
|
gegl_buffer_get_height (region_sel->region_mask),
|
2018-04-09 15:26:01 -07:00
|
|
|
GIMP_BOUNDARY_HALF_WAY,
|
2014-06-11 13:15:00 -07:00
|
|
|
®ion_sel->n_segs);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-27 12:10:55 -07:00
|
|
|
if (region_sel->segs)
|
2010-09-24 11:58:22 -07:00
|
|
|
{
|
2014-08-27 12:10:55 -07:00
|
|
|
gint off_x = 0;
|
|
|
|
|
gint off_y = 0;
|
2003-11-10 11:35:56 -08:00
|
|
|
|
2014-08-27 12:10:55 -07:00
|
|
|
if (! options->sample_merged)
|
|
|
|
|
{
|
|
|
|
|
GimpImage *image = gimp_display_get_image (draw_tool->display);
|
|
|
|
|
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
|
2003-11-10 11:35:56 -08:00
|
|
|
|
2014-08-27 12:10:55 -07:00
|
|
|
gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gimp_draw_tool_add_boundary (draw_tool,
|
|
|
|
|
region_sel->segs,
|
|
|
|
|
region_sel->n_segs,
|
|
|
|
|
NULL,
|
|
|
|
|
off_x, off_y);
|
|
|
|
|
}
|
2003-11-10 11:35:56 -08:00
|
|
|
}
|
2002-08-20 03:40:38 -07:00
|
|
|
}
|
1999-07-06 11:13:59 -07:00
|
|
|
|
2014-06-11 13:15:00 -07:00
|
|
|
static void
|
|
|
|
|
gimp_region_select_tool_get_mask (GimpRegionSelectTool *region_sel,
|
|
|
|
|
GimpDisplay *display)
|
1997-11-24 14:05:25 -08:00
|
|
|
{
|
2014-06-11 13:15:00 -07:00
|
|
|
GimpRegionSelectOptions *options = GIMP_REGION_SELECT_TOOL_GET_OPTIONS (region_sel);
|
|
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (display);
|
2003-02-05 06:39:40 -08:00
|
|
|
|
2015-01-09 14:47:57 -08:00
|
|
|
gimp_display_shell_set_override_cursor (shell, (GimpCursorType) GDK_WATCH);
|
2000-03-25 10:17:01 -08:00
|
|
|
|
2017-07-15 09:38:01 -07:00
|
|
|
g_clear_pointer (®ion_sel->segs, g_free);
|
|
|
|
|
region_sel->n_segs = 0;
|
2014-06-11 13:15:00 -07:00
|
|
|
|
2006-07-31 04:42:51 -07:00
|
|
|
if (region_sel->region_mask)
|
|
|
|
|
g_object_unref (region_sel->region_mask);
|
2001-11-08 11:14:51 -08:00
|
|
|
|
2006-07-31 04:42:51 -07:00
|
|
|
region_sel->region_mask =
|
|
|
|
|
GIMP_REGION_SELECT_TOOL_GET_CLASS (region_sel)->get_mask (region_sel,
|
|
|
|
|
display);
|
1997-11-24 14:05:25 -08:00
|
|
|
|
2014-06-11 13:15:00 -07:00
|
|
|
if (options->draw_mask)
|
2006-07-31 04:42:51 -07:00
|
|
|
{
|
2014-06-11 13:15:00 -07:00
|
|
|
if (region_sel->region_mask)
|
|
|
|
|
{
|
|
|
|
|
GimpRGB color = { 1.0, 0.0, 1.0, 1.0 };
|
2016-02-05 12:19:17 -08:00
|
|
|
gint off_x = 0;
|
|
|
|
|
gint off_y = 0;
|
|
|
|
|
|
|
|
|
|
if (! options->sample_merged)
|
|
|
|
|
{
|
|
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
|
|
|
|
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
|
|
|
|
|
|
|
|
|
|
gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
|
|
|
|
|
}
|
2014-06-11 13:15:00 -07:00
|
|
|
|
|
|
|
|
gimp_display_shell_set_mask (shell, region_sel->region_mask,
|
2016-02-05 12:19:17 -08:00
|
|
|
off_x, off_y, &color, FALSE);
|
2014-06-11 13:15:00 -07:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-02-05 12:19:17 -08:00
|
|
|
gimp_display_shell_set_mask (shell, NULL, 0, 0, NULL, FALSE);
|
2014-06-11 13:15:00 -07:00
|
|
|
}
|
2001-11-08 11:14:51 -08:00
|
|
|
}
|
1997-11-24 14:05:25 -08:00
|
|
|
|
2002-06-26 15:16:59 -07:00
|
|
|
gimp_display_shell_unset_override_cursor (shell);
|
1997-11-24 14:05:25 -08:00
|
|
|
}
|