2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-25 06:05:25 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1997-11-25 06: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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2000-04-28 01:27:28 +08:00
|
|
|
#include "config.h"
|
2000-01-14 20:41:00 +08:00
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-01-14 20:41:00 +08:00
|
|
|
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2002-05-03 20:45:22 +08:00
|
|
|
#include "tools-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2007-12-07 03:07:11 +08:00
|
|
|
#include "core/gimp.h"
|
2012-03-19 06:05:44 +08:00
|
|
|
#include "core/gimp-edit.h"
|
2001-11-09 03:14:51 +08:00
|
|
|
#include "core/gimpdrawable-bucket-fill.h"
|
2009-08-20 23:05:23 +08:00
|
|
|
#include "core/gimperror.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpimage.h"
|
2007-03-08 23:32:58 +08:00
|
|
|
#include "core/gimpitem.h"
|
2005-07-12 03:21:52 +08:00
|
|
|
#include "core/gimppickable.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
|
2003-08-22 09:42:57 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
2011-10-07 03:59:07 +08:00
|
|
|
#include "widgets/gimpwidgets-utils.h"
|
2003-08-22 09:42:57 +08:00
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
|
2003-02-05 22:39:40 +08:00
|
|
|
#include "gimpbucketfilloptions.h"
|
2001-03-08 09:07:03 +08:00
|
|
|
#include "gimpbucketfilltool.h"
|
2003-04-16 00:05:52 +08:00
|
|
|
#include "gimptoolcontrol.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
Lots of ii8n stuff here and some additions to the de.po. Applied
Wed Oct 14 17:46:15 EDT 1998 Adrian Likins <adrian@gimp.org>
* app/*, po/de.po, de/POTFILES.in, libgimp/gimpintl.h:
Lots of ii8n stuff here and some additions to the de.po.
Applied gimp-egger-981005-1 ,gimp-egger-981006-1,
gimp-egger-981007-1, gimp-egger-981008-1,
gimp-egger-981009-1.patch, gimp-egger-981010-1.patch
* plug-in/guillotine/guillotine.c: added the coordinates
of the split images from the original image to the title.
ie foo.jpg (0,0) for the image in the topleft.
* plug-in/script-fu/scripts/neon-logo.scm,
perspective-shadow.scm, predator.scm,rendermap.scm,
ripply-anim.scm, select_to_image.scm,swirltile.scm,
xach-effect.scm: updated scripts to use new script-fu stuff
wooo boy! a big un!
in testing this, it looks like some of the po files are busted.
but the code stuff seems okay.
-adrian
1998-10-15 07:23:52 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-12-13 17:13:50 +08:00
|
|
|
/* local function prototypes */
|
2001-02-28 09:05:22 +08:00
|
|
|
|
2009-08-20 23:05:23 +08:00
|
|
|
static gboolean gimp_bucket_fill_tool_initialize (GimpTool *tool,
|
|
|
|
GimpDisplay *display,
|
|
|
|
GError **error);
|
2007-02-28 02:55:12 +08:00
|
|
|
static void gimp_bucket_fill_tool_button_release (GimpTool *tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
const GimpCoords *coords,
|
2007-02-28 02:55:12 +08:00
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpButtonReleaseType release_type,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_bucket_fill_tool_modifier_key (GimpTool *tool,
|
|
|
|
GdkModifierType key,
|
|
|
|
gboolean press,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display);
|
|
|
|
static void gimp_bucket_fill_tool_cursor_update (GimpTool *tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
const GimpCoords *coords,
|
2007-02-28 02:55:12 +08:00
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display);
|
1999-04-09 06:25:54 +08:00
|
|
|
|
1999-06-22 06:12:07 +08:00
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpBucketFillTool, gimp_bucket_fill_tool, GIMP_TYPE_TOOL)
|
2005-12-13 17:13:50 +08:00
|
|
|
|
|
|
|
#define parent_class gimp_bucket_fill_tool_parent_class
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-28 09:05:22 +08:00
|
|
|
void
|
2002-03-29 11:50:29 +08:00
|
|
|
gimp_bucket_fill_tool_register (GimpToolRegisterCallback callback,
|
2003-08-22 09:42:57 +08:00
|
|
|
gpointer data)
|
2001-02-28 09:05:22 +08:00
|
|
|
{
|
2002-03-29 11:50:29 +08:00
|
|
|
(* callback) (GIMP_TYPE_BUCKET_FILL_TOOL,
|
2003-02-05 22:39:40 +08:00
|
|
|
GIMP_TYPE_BUCKET_FILL_OPTIONS,
|
|
|
|
gimp_bucket_fill_options_gui,
|
2015-09-09 03:18:49 +08:00
|
|
|
GIMP_CONTEXT_PROP_MASK_FOREGROUND |
|
|
|
|
GIMP_CONTEXT_PROP_MASK_BACKGROUND |
|
|
|
|
GIMP_CONTEXT_PROP_MASK_OPACITY |
|
|
|
|
GIMP_CONTEXT_PROP_MASK_PAINT_MODE |
|
|
|
|
GIMP_CONTEXT_PROP_MASK_PATTERN,
|
2002-03-21 20:17:17 +08:00
|
|
|
"gimp-bucket-fill-tool",
|
2001-11-21 07:00:47 +08:00
|
|
|
_("Bucket Fill"),
|
2006-09-19 02:00:22 +08:00
|
|
|
_("Bucket Fill Tool: Fill selected area with a color or pattern"),
|
2004-04-29 21:19:28 +08:00
|
|
|
N_("_Bucket Fill"), "<shift>B",
|
2003-08-22 09:42:57 +08:00
|
|
|
NULL, GIMP_HELP_TOOL_BUCKET_FILL,
|
2002-03-29 11:50:29 +08:00
|
|
|
GIMP_STOCK_TOOL_BUCKET_FILL,
|
2002-05-03 19:31:08 +08:00
|
|
|
data);
|
2001-02-28 09:05:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_bucket_fill_tool_class_init (GimpBucketFillToolClass *klass)
|
|
|
|
{
|
2005-03-04 19:42:46 +08:00
|
|
|
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
2001-02-28 09:05:22 +08:00
|
|
|
|
2009-08-20 23:05:23 +08:00
|
|
|
tool_class->initialize = gimp_bucket_fill_tool_initialize;
|
2001-02-28 09:05:22 +08:00
|
|
|
tool_class->button_release = gimp_bucket_fill_tool_button_release;
|
|
|
|
tool_class->modifier_key = gimp_bucket_fill_tool_modifier_key;
|
|
|
|
tool_class->cursor_update = gimp_bucket_fill_tool_cursor_update;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_bucket_fill_tool_init (GimpBucketFillTool *bucket_fill_tool)
|
|
|
|
{
|
2005-03-04 19:42:46 +08:00
|
|
|
GimpTool *tool = GIMP_TOOL (bucket_fill_tool);
|
2001-02-28 09:05:22 +08:00
|
|
|
|
2005-03-05 03:05:40 +08:00
|
|
|
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
|
2007-03-08 23:32:58 +08:00
|
|
|
gimp_tool_control_set_wants_click (tool->control, TRUE);
|
2005-03-05 03:05:40 +08:00
|
|
|
gimp_tool_control_set_tool_cursor (tool->control,
|
|
|
|
GIMP_TOOL_CURSOR_BUCKET_FILL);
|
2014-04-20 02:09:39 +08:00
|
|
|
gimp_tool_control_set_action_opacity (tool->control,
|
2005-03-05 03:05:40 +08:00
|
|
|
"context/context-opacity-set");
|
|
|
|
gimp_tool_control_set_action_object_1 (tool->control,
|
|
|
|
"context/context-pattern-select-set");
|
2001-02-28 09:05:22 +08:00
|
|
|
}
|
|
|
|
|
2009-08-20 23:05:23 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_bucket_fill_tool_initialize (GimpTool *tool,
|
|
|
|
GimpDisplay *display,
|
|
|
|
GError **error)
|
|
|
|
{
|
2009-10-08 01:00:42 +08:00
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
|
|
|
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
|
2009-08-20 23:05:23 +08:00
|
|
|
|
|
|
|
if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-08-29 02:07:14 +08:00
|
|
|
if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable)))
|
|
|
|
{
|
|
|
|
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
2009-09-03 20:57:18 +08:00
|
|
|
_("Cannot modify the pixels of layer groups."));
|
2009-08-29 02:07:14 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-08-29 21:27:04 +08:00
|
|
|
if (gimp_item_is_content_locked (GIMP_ITEM (drawable)))
|
2009-08-20 23:05:23 +08:00
|
|
|
{
|
|
|
|
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
|
|
|
_("The active layer's pixels are locked."));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-04-24 22:27:12 +08:00
|
|
|
if (! gimp_item_is_visible (GIMP_ITEM (drawable)))
|
|
|
|
{
|
|
|
|
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
|
|
|
_("The active layer is not visible."));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-08-20 23:05:23 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
1998-03-19 06:35:31 +08:00
|
|
|
static void
|
2007-02-28 02:55:12 +08:00
|
|
|
gimp_bucket_fill_tool_button_release (GimpTool *tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
const GimpCoords *coords,
|
2007-02-28 02:55:12 +08:00
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpButtonReleaseType release_type,
|
|
|
|
GimpDisplay *display)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2007-03-08 23:32:58 +08:00
|
|
|
GimpBucketFillOptions *options = GIMP_BUCKET_FILL_TOOL_GET_OPTIONS (tool);
|
2009-10-08 01:00:42 +08:00
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
2001-11-20 21:53:21 +08:00
|
|
|
|
2007-03-10 23:07:56 +08:00
|
|
|
if ((release_type == GIMP_BUTTON_RELEASE_CLICK ||
|
|
|
|
release_type == GIMP_BUTTON_RELEASE_NO_MOTION) &&
|
2009-10-08 01:00:42 +08:00
|
|
|
gimp_image_coords_in_active_pickable (image, coords,
|
2007-03-08 23:32:58 +08:00
|
|
|
options->sample_merged, TRUE))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2009-10-08 01:00:42 +08:00
|
|
|
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
|
2007-03-08 23:32:58 +08:00
|
|
|
GimpContext *context = GIMP_CONTEXT (options);
|
2014-06-03 07:34:51 +08:00
|
|
|
GimpFillType fill_type;
|
2007-03-08 23:32:58 +08:00
|
|
|
gint x, y;
|
2014-06-03 20:00:01 +08:00
|
|
|
gboolean success;
|
|
|
|
GError *error = NULL;
|
2007-03-08 23:32:58 +08:00
|
|
|
|
2014-06-03 07:34:51 +08:00
|
|
|
switch (options->fill_mode)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case GIMP_BUCKET_FILL_FG:
|
|
|
|
fill_type = GIMP_FILL_FOREGROUND;
|
|
|
|
break;
|
|
|
|
case GIMP_BUCKET_FILL_BG:
|
|
|
|
fill_type = GIMP_FILL_BACKGROUND;
|
|
|
|
break;
|
|
|
|
case GIMP_BUCKET_FILL_PATTERN:
|
|
|
|
fill_type = GIMP_FILL_PATTERN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-03-08 23:32:58 +08:00
|
|
|
x = coords->x;
|
|
|
|
y = coords->y;
|
|
|
|
|
|
|
|
if (! options->sample_merged)
|
|
|
|
{
|
|
|
|
gint off_x, off_y;
|
|
|
|
|
2008-11-03 07:03:29 +08:00
|
|
|
gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
|
2007-03-08 23:32:58 +08:00
|
|
|
|
|
|
|
x -= off_x;
|
|
|
|
y -= off_y;
|
|
|
|
}
|
|
|
|
|
2012-03-19 06:05:44 +08:00
|
|
|
if (options->fill_selection)
|
2007-12-07 03:07:11 +08:00
|
|
|
{
|
2014-06-03 20:00:01 +08:00
|
|
|
success = gimp_edit_fill (image, drawable, context, fill_type,
|
|
|
|
gimp_context_get_opacity (context),
|
|
|
|
gimp_context_get_paint_mode (context),
|
|
|
|
&error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
success = gimp_drawable_bucket_fill (drawable, context, fill_type,
|
|
|
|
gimp_context_get_paint_mode (context),
|
|
|
|
gimp_context_get_opacity (context),
|
|
|
|
options->fill_transparent,
|
|
|
|
options->fill_criterion,
|
|
|
|
options->threshold / 255.0,
|
|
|
|
options->sample_merged,
|
2016-01-08 21:18:10 +08:00
|
|
|
options->diagonal_neighbors,
|
2014-06-03 20:00:01 +08:00
|
|
|
x, y, &error);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
{
|
2012-03-19 06:05:44 +08:00
|
|
|
gimp_image_flush (image);
|
2007-12-07 03:07:11 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-06-03 20:00:01 +08:00
|
|
|
gimp_message_literal (display->gimp, G_OBJECT (display),
|
|
|
|
GIMP_MESSAGE_WARNING, error->message);
|
|
|
|
g_clear_error (&error);
|
2007-12-07 03:07:11 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2007-03-08 23:32:58 +08:00
|
|
|
GIMP_TOOL_CLASS (parent_class)->button_release (tool, coords, time, state,
|
|
|
|
release_type, display);
|
2009-08-22 01:04:45 +08:00
|
|
|
|
|
|
|
tool->display = NULL;
|
|
|
|
tool->drawable = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-09 03:14:51 +08:00
|
|
|
gimp_bucket_fill_tool_modifier_key (GimpTool *tool,
|
|
|
|
GdkModifierType key,
|
|
|
|
gboolean press,
|
|
|
|
GdkModifierType state,
|
2006-03-29 01:55:52 +08:00
|
|
|
GimpDisplay *display)
|
2001-11-09 03:14:51 +08:00
|
|
|
{
|
2006-09-06 02:25:31 +08:00
|
|
|
GimpBucketFillOptions *options = GIMP_BUCKET_FILL_TOOL_GET_OPTIONS (tool);
|
2001-11-20 21:53:21 +08:00
|
|
|
|
2011-10-07 03:59:07 +08:00
|
|
|
if (key == gimp_get_toggle_behavior_mask ())
|
2001-11-09 03:14:51 +08:00
|
|
|
{
|
2001-11-20 21:53:21 +08:00
|
|
|
switch (options->fill_mode)
|
2001-11-09 03:14:51 +08:00
|
|
|
{
|
2014-04-30 02:55:08 +08:00
|
|
|
case GIMP_BUCKET_FILL_FG:
|
|
|
|
g_object_set (options, "fill-mode", GIMP_BUCKET_FILL_BG, NULL);
|
2001-11-09 03:14:51 +08:00
|
|
|
break;
|
2003-02-08 01:12:21 +08:00
|
|
|
|
2014-04-30 02:55:08 +08:00
|
|
|
case GIMP_BUCKET_FILL_BG:
|
|
|
|
g_object_set (options, "fill-mode", GIMP_BUCKET_FILL_FG, NULL);
|
2001-11-09 03:14:51 +08:00
|
|
|
break;
|
2003-02-08 01:12:21 +08:00
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-10-17 21:31:08 +08:00
|
|
|
else if (key == gimp_get_extend_selection_mask ())
|
2004-01-27 23:26:11 +08:00
|
|
|
{
|
|
|
|
g_object_set (options, "fill-selection", ! options->fill_selection, NULL);
|
|
|
|
}
|
2001-11-09 03:14:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-11-01 23:17:36 +08:00
|
|
|
gimp_bucket_fill_tool_cursor_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-09-06 02:25:31 +08:00
|
|
|
GimpBucketFillOptions *options = GIMP_BUCKET_FILL_TOOL_GET_OPTIONS (tool);
|
2006-06-03 23:41:40 +08:00
|
|
|
GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_BAD;
|
2009-10-08 01:00:42 +08:00
|
|
|
GimpImage *image = gimp_display_get_image (display);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2009-10-08 01:00:42 +08:00
|
|
|
if (gimp_image_coords_in_active_pickable (image, coords,
|
2006-06-03 23:41:40 +08:00
|
|
|
options->sample_merged, TRUE))
|
1998-01-22 15:02:57 +08:00
|
|
|
{
|
2009-10-08 01:00:42 +08:00
|
|
|
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
|
2006-06-03 23:41:40 +08:00
|
|
|
|
2009-08-29 02:07:14 +08:00
|
|
|
if (! gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) &&
|
2013-04-24 22:27:12 +08:00
|
|
|
! gimp_item_is_content_locked (GIMP_ITEM (drawable)) &&
|
|
|
|
gimp_item_is_visible (GIMP_ITEM (drawable)))
|
2009-08-22 01:34:59 +08:00
|
|
|
{
|
|
|
|
switch (options->fill_mode)
|
|
|
|
{
|
2014-04-30 02:55:08 +08:00
|
|
|
case GIMP_BUCKET_FILL_FG:
|
2009-08-22 01:34:59 +08:00
|
|
|
modifier = GIMP_CURSOR_MODIFIER_FOREGROUND;
|
|
|
|
break;
|
|
|
|
|
2014-04-30 02:55:08 +08:00
|
|
|
case GIMP_BUCKET_FILL_BG:
|
2009-08-22 01:34:59 +08:00
|
|
|
modifier = GIMP_CURSOR_MODIFIER_BACKGROUND;
|
|
|
|
break;
|
|
|
|
|
2014-04-30 02:55:08 +08:00
|
|
|
case GIMP_BUCKET_FILL_PATTERN:
|
2009-08-22 01:34:59 +08:00
|
|
|
modifier = GIMP_CURSOR_MODIFIER_PATTERN;
|
|
|
|
break;
|
|
|
|
}
|
2003-05-08 22:06:03 +08:00
|
|
|
}
|
1998-01-22 15:02:57 +08:00
|
|
|
}
|
2000-07-30 00:12:40 +08:00
|
|
|
|
2006-06-03 23:41:40 +08:00
|
|
|
gimp_tool_control_set_cursor_modifier (tool->control, modifier);
|
2002-02-05 01:43:01 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|