1
/* GIMP - The GNU 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.
23
#include "tools-types.h"
25
#include "core/gimpchannel.h"
26
#include "core/gimpimage.h"
27
#include "core/gimppickable.h"
29
#include "paint/gimpsourcecore.h"
30
#include "paint/gimpsourceoptions.h"
32
#include "widgets/gimpwidgets-utils.h"
34
#include "display/gimpdisplay.h"
36
#include "gimpsourcetool.h"
37
#include "gimptoolcontrol.h"
39
#include "gimp-intl.h"
42
#define TARGET_SIZE 15
45
static gboolean gimp_source_tool_has_display (GimpTool *tool,
46
GimpDisplay *display);
47
static GimpDisplay * gimp_source_tool_has_image (GimpTool *tool,
49
static void gimp_source_tool_control (GimpTool *tool,
50
GimpToolAction action,
51
GimpDisplay *display);
52
static void gimp_source_tool_button_press (GimpTool *tool,
55
GdkModifierType state,
56
GimpDisplay *display);
57
static void gimp_source_tool_motion (GimpTool *tool,
60
GdkModifierType state,
61
GimpDisplay *display);
62
static void gimp_source_tool_cursor_update (GimpTool *tool,
64
GdkModifierType state,
65
GimpDisplay *display);
66
static void gimp_source_tool_modifier_key (GimpTool *tool,
69
GdkModifierType state,
70
GimpDisplay *display);
71
static void gimp_source_tool_oper_update (GimpTool *tool,
73
GdkModifierType state,
75
GimpDisplay *display);
77
static void gimp_source_tool_draw (GimpDrawTool *draw_tool);
80
G_DEFINE_TYPE (GimpSourceTool, gimp_source_tool, GIMP_TYPE_BRUSH_TOOL)
82
#define parent_class gimp_source_tool_parent_class
86
gimp_source_tool_class_init (GimpSourceToolClass *klass)
88
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
89
GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
91
tool_class->has_display = gimp_source_tool_has_display;
92
tool_class->has_image = gimp_source_tool_has_image;
93
tool_class->control = gimp_source_tool_control;
94
tool_class->button_press = gimp_source_tool_button_press;
95
tool_class->motion = gimp_source_tool_motion;
96
tool_class->modifier_key = gimp_source_tool_modifier_key;
97
tool_class->oper_update = gimp_source_tool_oper_update;
98
tool_class->cursor_update = gimp_source_tool_cursor_update;
100
draw_tool_class->draw = gimp_source_tool_draw;
104
gimp_source_tool_init (GimpSourceTool *source)
109
gimp_source_tool_has_display (GimpTool *tool,
110
GimpDisplay *display)
112
GimpSourceTool *source_tool = GIMP_SOURCE_TOOL (tool);
114
return (display == source_tool->src_display ||
115
GIMP_TOOL_CLASS (parent_class)->has_display (tool, display));
119
gimp_source_tool_has_image (GimpTool *tool,
122
GimpSourceTool *source_tool = GIMP_SOURCE_TOOL (tool);
123
GimpDisplay *display;
125
display = GIMP_TOOL_CLASS (parent_class)->has_image (tool, image);
127
if (! display && source_tool->src_display)
129
if (image && source_tool->src_display->image == image)
130
display = source_tool->src_display;
132
/* NULL image means any display */
134
display = source_tool->src_display;
141
gimp_source_tool_control (GimpTool *tool,
142
GimpToolAction action,
143
GimpDisplay *display)
145
GimpSourceTool *source_tool = GIMP_SOURCE_TOOL (tool);
147
/* chain up early so the draw tool can undraw the source marker
148
* while we still know about source drawable and display
150
GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
154
case GIMP_TOOL_ACTION_PAUSE:
155
case GIMP_TOOL_ACTION_RESUME:
158
case GIMP_TOOL_ACTION_HALT:
159
source_tool->src_display = NULL;
160
g_object_set (GIMP_PAINT_TOOL (tool)->core,
161
"src-drawable", NULL,
168
gimp_source_tool_button_press (GimpTool *tool,
171
GdkModifierType state,
172
GimpDisplay *display)
174
GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool);
175
GimpSourceTool *source_tool = GIMP_SOURCE_TOOL (tool);
176
GimpSourceCore *source = GIMP_SOURCE_CORE (paint_tool->core);
178
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
180
if ((state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) == GDK_CONTROL_MASK)
182
source->set_source = TRUE;
184
source_tool->src_display = display;
188
source->set_source = FALSE;
191
GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state,
194
source_tool->src_x = source->src_x;
195
source_tool->src_y = source->src_y;
197
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
201
gimp_source_tool_motion (GimpTool *tool,
204
GdkModifierType state,
205
GimpDisplay *display)
207
GimpSourceTool *source_tool = GIMP_SOURCE_TOOL (tool);
208
GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool);
209
GimpSourceCore *source = GIMP_SOURCE_CORE (paint_tool->core);
211
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
213
if ((state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) == GDK_CONTROL_MASK)
214
source->set_source = TRUE;
216
source->set_source = FALSE;
218
GIMP_TOOL_CLASS (parent_class)->motion (tool, coords, time, state, display);
220
source_tool->src_x = source->src_x;
221
source_tool->src_y = source->src_y;
223
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
227
gimp_source_tool_modifier_key (GimpTool *tool,
230
GdkModifierType state,
231
GimpDisplay *display)
233
GimpSourceTool *source_tool = GIMP_SOURCE_TOOL (tool);
234
GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool);
235
GimpSourceOptions *options = GIMP_SOURCE_TOOL_GET_OPTIONS (tool);
237
if (options->use_source && key == GDK_CONTROL_MASK)
240
paint_tool->status = source_tool->status_set_source;
242
paint_tool->status = source_tool->status_paint;
245
GIMP_TOOL_CLASS (parent_class)->modifier_key (tool, key, press, state,
250
gimp_source_tool_cursor_update (GimpTool *tool,
252
GdkModifierType state,
253
GimpDisplay *display)
255
GimpSourceOptions *options = GIMP_SOURCE_TOOL_GET_OPTIONS (tool);
256
GimpCursorType cursor = GIMP_CURSOR_MOUSE;
257
GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_NONE;
259
if (options->use_source)
261
if ((state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) == GDK_CONTROL_MASK)
263
cursor = GIMP_CURSOR_CROSSHAIR_SMALL;
265
else if (! GIMP_SOURCE_CORE (GIMP_PAINT_TOOL (tool)->core)->src_drawable)
267
modifier = GIMP_CURSOR_MODIFIER_BAD;
271
gimp_tool_control_set_cursor (tool->control, cursor);
272
gimp_tool_control_set_cursor_modifier (tool->control, modifier);
274
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
278
gimp_source_tool_oper_update (GimpTool *tool,
280
GdkModifierType state,
282
GimpDisplay *display)
284
GimpSourceTool *source_tool = GIMP_SOURCE_TOOL (tool);
285
GimpSourceOptions *options = GIMP_SOURCE_TOOL_GET_OPTIONS (tool);
289
GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool);
291
if (options->use_source)
292
paint_tool->status_ctrl = source_tool->status_set_source_ctrl;
294
paint_tool->status_ctrl = NULL;
297
GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, proximity,
300
if (options->use_source)
302
GimpSourceCore *source = GIMP_SOURCE_CORE (GIMP_PAINT_TOOL (tool)->core);
304
if (source->src_drawable == NULL)
306
if (state & GDK_CONTROL_MASK)
307
gimp_tool_replace_status (tool, display,
308
source_tool->status_set_source);
313
status = g_strconcat (gimp_get_mod_name_control (),
314
gimp_get_mod_separator (),
315
source_tool->status_set_source,
317
gimp_tool_replace_status (tool, display, status);
323
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
325
source_tool->src_x = source->src_x;
326
source_tool->src_y = source->src_y;
328
if (! source->first_stroke)
330
switch (options->align_mode)
332
case GIMP_SOURCE_ALIGN_YES:
333
source_tool->src_x = coords->x + source->offset_x;
334
source_tool->src_y = coords->y + source->offset_y;
337
case GIMP_SOURCE_ALIGN_REGISTERED:
338
source_tool->src_x = coords->x;
339
source_tool->src_y = coords->y;
347
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
353
gimp_source_tool_draw (GimpDrawTool *draw_tool)
355
GimpTool *tool = GIMP_TOOL (draw_tool);
356
GimpSourceTool *source_tool = GIMP_SOURCE_TOOL (draw_tool);
357
GimpSourceCore *source = GIMP_SOURCE_CORE (GIMP_PAINT_TOOL (tool)->core);
358
GimpSourceOptions *options = GIMP_SOURCE_TOOL_GET_OPTIONS (draw_tool);
360
if (options->use_source && source->src_drawable && source_tool->src_display)
362
GimpDisplay *tmp_display;
366
gimp_item_offsets (GIMP_ITEM (source->src_drawable), &off_x, &off_y);
368
tmp_display = draw_tool->display;
369
draw_tool->display = source_tool->src_display;
371
gimp_draw_tool_draw_handle (draw_tool,
373
source_tool->src_x + off_x,
374
source_tool->src_y + off_y,
375
TARGET_SIZE, TARGET_SIZE,
379
draw_tool->display = tmp_display;
382
GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool);