1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
#include <gdk/gdkkeysyms.h>
24
#include "libgimpwidgets/gimpwidgets.h"
26
#include "tools-types.h"
28
#include "config/gimpguiconfig.h"
30
#include "core/gimp.h"
31
#include "core/gimpchannel.h"
32
#include "core/gimpdrawable-bucket-fill.h"
33
#include "core/gimpimage.h"
34
#include "core/gimptoolinfo.h"
36
#include "widgets/gimphelp-ids.h"
38
#include "display/gimpdisplay.h"
40
#include "gimpbucketfilloptions.h"
41
#include "gimpbucketfilltool.h"
42
#include "gimptoolcontrol.h"
44
#include "gimp-intl.h"
47
static GimpToolClass *parent_class = NULL;
50
/* local function prototypes */
52
static void gimp_bucket_fill_tool_class_init (GimpBucketFillToolClass *klass);
53
static void gimp_bucket_fill_tool_init (GimpBucketFillTool *bucket_fill_tool);
55
static void gimp_bucket_fill_tool_button_press (GimpTool *tool,
58
GdkModifierType state,
60
static void gimp_bucket_fill_tool_button_release (GimpTool *tool,
63
GdkModifierType state,
65
static void gimp_bucket_fill_tool_modifier_key (GimpTool *tool,
68
GdkModifierType state,
70
static void gimp_bucket_fill_tool_cursor_update (GimpTool *tool,
72
GdkModifierType state,
76
/* public functions */
79
gimp_bucket_fill_tool_register (GimpToolRegisterCallback callback,
82
(* callback) (GIMP_TYPE_BUCKET_FILL_TOOL,
83
GIMP_TYPE_BUCKET_FILL_OPTIONS,
84
gimp_bucket_fill_options_gui,
85
GIMP_CONTEXT_FOREGROUND_MASK |
86
GIMP_CONTEXT_BACKGROUND_MASK |
87
GIMP_CONTEXT_OPACITY_MASK |
88
GIMP_CONTEXT_PAINT_MODE_MASK |
89
GIMP_CONTEXT_PATTERN_MASK,
90
"gimp-bucket-fill-tool",
92
_("Fill with a color or pattern"),
93
N_("_Bucket Fill"), "<shift>B",
94
NULL, GIMP_HELP_TOOL_BUCKET_FILL,
95
GIMP_STOCK_TOOL_BUCKET_FILL,
100
gimp_bucket_fill_tool_get_type (void)
102
static GType tool_type = 0;
106
static const GTypeInfo tool_info =
108
sizeof (GimpBucketFillToolClass),
109
(GBaseInitFunc) NULL,
110
(GBaseFinalizeFunc) NULL,
111
(GClassInitFunc) gimp_bucket_fill_tool_class_init,
112
NULL, /* class_finalize */
113
NULL, /* class_data */
114
sizeof (GimpBucketFillTool),
116
(GInstanceInitFunc) gimp_bucket_fill_tool_init,
119
tool_type = g_type_register_static (GIMP_TYPE_TOOL,
120
"GimpBucketFillTool",
128
/* private functions */
131
gimp_bucket_fill_tool_class_init (GimpBucketFillToolClass *klass)
133
GimpToolClass *tool_class;
135
tool_class = GIMP_TOOL_CLASS (klass);
137
parent_class = g_type_class_peek_parent (klass);
139
tool_class->button_press = gimp_bucket_fill_tool_button_press;
140
tool_class->button_release = gimp_bucket_fill_tool_button_release;
141
tool_class->modifier_key = gimp_bucket_fill_tool_modifier_key;
142
tool_class->cursor_update = gimp_bucket_fill_tool_cursor_update;
146
gimp_bucket_fill_tool_init (GimpBucketFillTool *bucket_fill_tool)
150
tool = GIMP_TOOL (bucket_fill_tool);
152
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
153
gimp_tool_control_set_tool_cursor (tool->control,
154
GIMP_TOOL_CURSOR_BUCKET_FILL);
158
gimp_bucket_fill_tool_button_press (GimpTool *tool,
161
GdkModifierType state,
164
GimpBucketFillTool *bucket_tool;
165
GimpBucketFillOptions *options;
167
bucket_tool = GIMP_BUCKET_FILL_TOOL (tool);
168
options = GIMP_BUCKET_FILL_OPTIONS (tool->tool_info->tool_options);
170
bucket_tool->target_x = coords->x;
171
bucket_tool->target_y = coords->y;
173
if (! options->sample_merged)
177
gimp_item_offsets (GIMP_ITEM (gimp_image_active_drawable (gdisp->gimage)),
180
bucket_tool->target_x -= off_x;
181
bucket_tool->target_y -= off_y;
185
gimp_tool_control_activate (tool->control);
189
gimp_bucket_fill_tool_button_release (GimpTool *tool,
192
GdkModifierType state,
195
GimpBucketFillTool *bucket_tool;
196
GimpBucketFillOptions *options;
197
GimpContext *context;
199
bucket_tool = GIMP_BUCKET_FILL_TOOL (tool);
200
options = GIMP_BUCKET_FILL_OPTIONS (tool->tool_info->tool_options);
201
context = GIMP_CONTEXT (options);
203
/* if the 3rd button isn't pressed, fill the selected region */
204
if (! (state & GDK_BUTTON3_MASK))
206
gimp_drawable_bucket_fill (gimp_image_active_drawable (gdisp->gimage),
209
gimp_context_get_paint_mode (context),
210
gimp_context_get_opacity (context),
211
! options->fill_selection,
212
options->fill_transparent,
214
options->sample_merged,
215
bucket_tool->target_x,
216
bucket_tool->target_y);
218
gimp_image_flush (gdisp->gimage);
221
gimp_tool_control_halt (tool->control);
225
gimp_bucket_fill_tool_modifier_key (GimpTool *tool,
228
GdkModifierType state,
231
GimpBucketFillOptions *options;
233
options = GIMP_BUCKET_FILL_OPTIONS (tool->tool_info->tool_options);
235
if (key == GDK_CONTROL_MASK)
237
switch (options->fill_mode)
239
case GIMP_FG_BUCKET_FILL:
240
g_object_set (options, "fill-mode", GIMP_BG_BUCKET_FILL, NULL);
243
case GIMP_BG_BUCKET_FILL:
244
g_object_set (options, "fill-mode", GIMP_FG_BUCKET_FILL, NULL);
251
else if (key == GDK_SHIFT_MASK)
253
g_object_set (options, "fill-selection", ! options->fill_selection, NULL);
258
gimp_bucket_fill_tool_cursor_update (GimpTool *tool,
260
GdkModifierType state,
263
GimpBucketFillOptions *options;
264
GimpCursorModifier cmodifier = GIMP_CURSOR_MODIFIER_NONE;
266
options = GIMP_BUCKET_FILL_OPTIONS (tool->tool_info->tool_options);
268
if (gimp_image_coords_in_active_drawable (gdisp->gimage, coords))
270
GimpChannel *selection = gimp_image_get_mask (gdisp->gimage);
272
/* One more test--is there a selected region?
273
* if so, is cursor inside?
275
if (gimp_channel_is_empty (selection) ||
276
gimp_channel_value (selection, coords->x, coords->y))
278
switch (options->fill_mode)
280
case GIMP_FG_BUCKET_FILL:
281
cmodifier = GIMP_CURSOR_MODIFIER_FOREGROUND;
284
case GIMP_BG_BUCKET_FILL:
285
cmodifier = GIMP_CURSOR_MODIFIER_BACKGROUND;
288
case GIMP_PATTERN_BUCKET_FILL:
289
cmodifier = GIMP_CURSOR_MODIFIER_PATTERN;
295
gimp_tool_control_set_cursor_modifier (tool->control, cmodifier);
297
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, gdisp);