53
52
/* local function prototypes */
55
static void gimp_blend_tool_class_init (GimpBlendToolClass *klass);
56
static void gimp_blend_tool_init (GimpBlendTool *blend_tool);
58
static void gimp_blend_tool_button_press (GimpTool *tool,
61
GdkModifierType state,
63
static void gimp_blend_tool_button_release (GimpTool *tool,
66
GdkModifierType state,
68
static void gimp_blend_tool_motion (GimpTool *tool,
71
GdkModifierType state,
73
static void gimp_blend_tool_cursor_update (GimpTool *tool,
75
GdkModifierType state,
78
static void gimp_blend_tool_draw (GimpDrawTool *draw_tool);
81
/* private variables */
83
static GimpDrawToolClass *parent_class = NULL;
86
/* public functions */
54
static gboolean gimp_blend_tool_initialize (GimpTool *tool,
57
static void gimp_blend_tool_button_press (GimpTool *tool,
60
GdkModifierType state,
61
GimpDisplay *display);
62
static void gimp_blend_tool_button_release (GimpTool *tool,
65
GdkModifierType state,
66
GimpButtonReleaseType release_type,
67
GimpDisplay *display);
68
static void gimp_blend_tool_motion (GimpTool *tool,
71
GdkModifierType state,
72
GimpDisplay *display);
73
static void gimp_blend_tool_active_modifier_key (GimpTool *tool,
76
GdkModifierType state,
77
GimpDisplay *display);
78
static void gimp_blend_tool_cursor_update (GimpTool *tool,
80
GdkModifierType state,
81
GimpDisplay *display);
83
static void gimp_blend_tool_draw (GimpDrawTool *draw_tool);
85
static void gimp_blend_tool_push_status (GimpBlendTool *blend_tool,
86
GdkModifierType state,
87
GimpDisplay *display);
90
G_DEFINE_TYPE (GimpBlendTool, gimp_blend_tool, GIMP_TYPE_DRAW_TOOL)
92
#define parent_class gimp_blend_tool_parent_class
89
96
gimp_blend_tool_register (GimpToolRegisterCallback callback,
99
106
GIMP_CONTEXT_GRADIENT_MASK,
100
107
"gimp-blend-tool",
102
_("Fill with a color gradient"),
109
_("Blend Tool: Fill selected area with a color gradient"),
103
110
N_("Blen_d"), "L",
104
111
NULL, GIMP_HELP_TOOL_BLEND,
105
112
GIMP_STOCK_TOOL_BLEND,
110
gimp_blend_tool_get_type (void)
112
static GType tool_type = 0;
116
static const GTypeInfo tool_info =
118
sizeof (GimpBlendToolClass),
119
(GBaseInitFunc) NULL,
120
(GBaseFinalizeFunc) NULL,
121
(GClassInitFunc) gimp_blend_tool_class_init,
122
NULL, /* class_finalize */
123
NULL, /* class_data */
124
sizeof (GimpBlendTool),
126
(GInstanceInitFunc) gimp_blend_tool_init,
129
tool_type = g_type_register_static (GIMP_TYPE_DRAW_TOOL,
138
/* private functions */
141
117
gimp_blend_tool_class_init (GimpBlendToolClass *klass)
143
GObjectClass *object_class;
144
GimpToolClass *tool_class;
145
GimpDrawToolClass *draw_tool_class;
147
object_class = G_OBJECT_CLASS (klass);
148
tool_class = GIMP_TOOL_CLASS (klass);
149
draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
151
parent_class = g_type_class_peek_parent (klass);
153
tool_class->button_press = gimp_blend_tool_button_press;
154
tool_class->button_release = gimp_blend_tool_button_release;
155
tool_class->motion = gimp_blend_tool_motion;
156
tool_class->cursor_update = gimp_blend_tool_cursor_update;
158
draw_tool_class->draw = gimp_blend_tool_draw;
119
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
120
GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
122
tool_class->initialize = gimp_blend_tool_initialize;
123
tool_class->button_press = gimp_blend_tool_button_press;
124
tool_class->button_release = gimp_blend_tool_button_release;
125
tool_class->motion = gimp_blend_tool_motion;
126
tool_class->active_modifier_key = gimp_blend_tool_active_modifier_key;
127
tool_class->cursor_update = gimp_blend_tool_cursor_update;
129
draw_tool_class->draw = gimp_blend_tool_draw;
162
133
gimp_blend_tool_init (GimpBlendTool *blend_tool)
166
tool = GIMP_TOOL (blend_tool);
168
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
169
gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_BLEND);
135
GimpTool *tool = GIMP_TOOL (blend_tool);
137
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
138
gimp_tool_control_set_cursor (tool->control,
140
gimp_tool_control_set_tool_cursor (tool->control,
141
GIMP_TOOL_CURSOR_BLEND);
142
gimp_tool_control_set_action_value_1 (tool->control,
143
"context/context-opacity-set");
144
gimp_tool_control_set_action_object_1 (tool->control,
145
"context/context-gradient-select-set");
149
gimp_blend_tool_initialize (GimpTool *tool,
150
GimpDisplay *display,
153
GimpDrawable *drawable = gimp_image_active_drawable (display->image);
155
if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error))
160
if (gimp_drawable_is_indexed (drawable))
162
g_set_error (error, 0, 0,
163
_("Blend does not operate on indexed layers."));
175
172
GimpCoords *coords,
177
174
GdkModifierType state,
175
GimpDisplay *display)
180
GimpBlendTool *blend_tool;
181
GimpDrawable *drawable;
184
blend_tool = GIMP_BLEND_TOOL (tool);
186
drawable = gimp_image_active_drawable (gdisp->gimage);
188
switch (gimp_drawable_type (drawable))
190
case GIMP_INDEXED_IMAGE: case GIMP_INDEXEDA_IMAGE:
191
g_message (_("Blend: Invalid for indexed images."));
199
gimp_item_offsets (GIMP_ITEM (drawable), &off_x, &off_y);
201
blend_tool->endx = blend_tool->startx = coords->x - off_x;
202
blend_tool->endy = blend_tool->starty = coords->y - off_y;
177
GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool);
179
blend_tool->start_x = blend_tool->end_x = coords->x;
180
blend_tool->start_y = blend_tool->end_y = coords->y;
182
blend_tool->last_x = blend_tool->mouse_x = coords->x;
183
blend_tool->last_y = blend_tool->mouse_y = coords->y;
185
tool->display = display;
206
187
gimp_tool_control_activate (tool->control);
208
/* initialize the statusbar display */
209
gimp_tool_push_status_coords (tool, _("Blend: "), 0, ", ", 0);
189
gimp_blend_tool_push_status (blend_tool, state, display);
211
/* Start drawing the blend tool */
212
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), gdisp);
191
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
216
gimp_blend_tool_button_release (GimpTool *tool,
219
GdkModifierType state,
195
gimp_blend_tool_button_release (GimpTool *tool,
198
GdkModifierType state,
199
GimpButtonReleaseType release_type,
200
GimpDisplay *display)
222
GimpBlendTool *blend_tool;
223
GimpPaintOptions *paint_options;
224
GimpBlendOptions *options;
225
GimpContext *context;
228
blend_tool = GIMP_BLEND_TOOL (tool);
229
paint_options = GIMP_PAINT_OPTIONS (tool->tool_info->tool_options);
230
options = GIMP_BLEND_OPTIONS (paint_options);
231
context = GIMP_CONTEXT (options);
233
gimage = gdisp->gimage;
235
gimp_tool_pop_status (tool);
202
GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool);
203
GimpBlendOptions *options = GIMP_BLEND_TOOL_GET_OPTIONS (tool);
204
GimpPaintOptions *paint_options = GIMP_PAINT_OPTIONS (options);
205
GimpContext *context = GIMP_CONTEXT (options);
206
GimpImage *image = display->image;
208
gimp_tool_pop_status (tool, display);
237
210
gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
239
212
gimp_tool_control_halt (tool->control);
241
/* if the 3rd button isn't pressed, fill the selected region */
242
if (! (state & GDK_BUTTON3_MASK) &&
243
((blend_tool->startx != blend_tool->endx) ||
244
(blend_tool->starty != blend_tool->endy)))
214
if ((release_type != GIMP_BUTTON_RELEASE_CANCEL) &&
215
((blend_tool->start_x != blend_tool->end_x) ||
216
(blend_tool->start_y != blend_tool->end_y)))
246
218
GimpProgress *progress;
248
progress = gimp_progress_start (GIMP_PROGRESS (gdisp),
249
_("Blending..."), FALSE);
251
gimp_drawable_blend (gimp_image_active_drawable (gimage),
222
progress = gimp_progress_start (GIMP_PROGRESS (display),
223
_("Blending"), FALSE);
225
gimp_item_offsets (GIMP_ITEM (gimp_image_active_drawable (image)),
228
gimp_drawable_blend (gimp_image_active_drawable (image),
253
230
GIMP_CUSTOM_MODE,
254
231
gimp_context_get_paint_mode (context),
279
256
GimpCoords *coords,
281
258
GdkModifierType state,
259
GimpDisplay *display)
284
GimpBlendTool *blend_tool;
287
blend_tool = GIMP_BLEND_TOOL (tool);
261
GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool);
289
263
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
291
gimp_item_offsets (GIMP_ITEM (gimp_image_active_drawable (gdisp->gimage)),
294
/* Get the current coordinates */
295
blend_tool->endx = coords->x - off_x;
296
blend_tool->endy = coords->y - off_y;
265
blend_tool->mouse_x = coords->x;
266
blend_tool->mouse_y = coords->y;
268
/* Move the whole line if alt is pressed */
269
if (state & GDK_MOD1_MASK)
271
gdouble dx = blend_tool->last_x - coords->x;
272
gdouble dy = blend_tool->last_y - coords->y;
274
blend_tool->start_x -= dx;
275
blend_tool->start_y -= dy;
277
blend_tool->end_x -= dx;
278
blend_tool->end_y -= dy;
282
blend_tool->end_x = coords->x;
283
blend_tool->end_y = coords->y;
298
286
/* Restrict to multiples of 15 degrees if ctrl is pressed */
299
287
if (state & GDK_CONTROL_MASK)
301
gimp_tool_motion_constrain (blend_tool->startx, blend_tool->starty,
302
&blend_tool->endx, &blend_tool->endy);
289
gimp_tool_motion_constrain (blend_tool->start_x, blend_tool->start_y,
290
&blend_tool->end_x, &blend_tool->end_y);
305
gimp_tool_pop_status (tool);
307
gimp_tool_push_status_coords (tool,
309
blend_tool->endx - blend_tool->startx,
311
blend_tool->endy - blend_tool->starty);
293
gimp_tool_pop_status (tool, display);
294
gimp_blend_tool_push_status (blend_tool, state, display);
313
296
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
298
blend_tool->last_x = coords->x;
299
blend_tool->last_y = coords->y;
303
gimp_blend_tool_active_modifier_key (GimpTool *tool,
306
GdkModifierType state,
307
GimpDisplay *display)
309
GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool);
311
if (key == GDK_CONTROL_MASK)
313
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
315
blend_tool->end_x = blend_tool->mouse_x;
316
blend_tool->end_y = blend_tool->mouse_y;
318
/* Restrict to multiples of 15 degrees if ctrl is pressed */
321
gimp_tool_motion_constrain (blend_tool->start_x, blend_tool->start_y,
322
&blend_tool->end_x, &blend_tool->end_y);
325
gimp_tool_pop_status (tool, display);
326
gimp_blend_tool_push_status (blend_tool, state, display);
328
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
317
333
gimp_blend_tool_cursor_update (GimpTool *tool,
318
334
GimpCoords *coords,
319
335
GdkModifierType state,
336
GimpDisplay *display)
322
switch (gimp_drawable_type (gimp_image_active_drawable (gdisp->gimage)))
338
switch (gimp_drawable_type (gimp_image_active_drawable (display->image)))
324
340
case GIMP_INDEXED_IMAGE:
325
341
case GIMP_INDEXEDA_IMAGE:
326
gimp_tool_control_set_cursor (tool->control, GIMP_CURSOR_BAD);
342
gimp_tool_control_set_cursor_modifier (tool->control,
343
GIMP_CURSOR_MODIFIER_BAD);
329
gimp_tool_control_set_cursor (tool->control, GIMP_CURSOR_MOUSE);
346
gimp_tool_control_set_cursor_modifier (tool->control,
347
GIMP_CURSOR_MODIFIER_NONE);
333
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, gdisp);
351
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
337
355
gimp_blend_tool_draw (GimpDrawTool *draw_tool)
339
GimpBlendTool *blend_tool;
341
blend_tool = GIMP_BLEND_TOOL (draw_tool);
357
GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (draw_tool);
343
359
/* Draw start target */
344
360
gimp_draw_tool_draw_handle (draw_tool,
345
361
GIMP_HANDLE_CROSS,
346
floor (blend_tool->startx) + 0.5,
347
floor (blend_tool->starty) + 0.5,
362
floor (blend_tool->start_x) + 0.5,
363
floor (blend_tool->start_y) + 0.5,
350
366
GTK_ANCHOR_CENTER,
353
369
/* Draw end target */
354
370
gimp_draw_tool_draw_handle (draw_tool,
355
371
GIMP_HANDLE_CROSS,
356
floor (blend_tool->endx) + 0.5,
357
floor (blend_tool->endy) + 0.5,
372
floor (blend_tool->end_x) + 0.5,
373
floor (blend_tool->end_y) + 0.5,
360
376
GTK_ANCHOR_CENTER,
363
379
/* Draw the line between the start and end coords */
364
380
gimp_draw_tool_draw_line (draw_tool,
365
floor (blend_tool->startx) + 0.5,
366
floor (blend_tool->starty) + 0.5,
367
floor (blend_tool->endx) + 0.5,
368
floor (blend_tool->endy) + 0.5,
381
floor (blend_tool->start_x) + 0.5,
382
floor (blend_tool->start_y) + 0.5,
383
floor (blend_tool->end_x) + 0.5,
384
floor (blend_tool->end_y) + 0.5,
389
gimp_blend_tool_push_status (GimpBlendTool *blend_tool,
390
GdkModifierType state,
391
GimpDisplay *display)
395
status_help = gimp_suggest_modifiers ("",
396
((GDK_CONTROL_MASK | GDK_MOD1_MASK)
399
_("%s for constrained angles"),
400
_("%s to move the whole line"));
401
gimp_tool_push_status_coords (GIMP_TOOL (blend_tool), display,
403
blend_tool->end_x - blend_tool->start_x,
405
blend_tool->end_y - blend_tool->start_y,
407
g_free (status_help);