41
46
#include "gimptoolcontrol.h"
44
static GObject * gimp_brush_tool_constructor (GType type,
46
GObjectConstructParam *params);
48
static void gimp_brush_tool_motion (GimpTool *tool,
51
GdkModifierType state,
52
GimpDisplay *display);
53
static void gimp_brush_tool_oper_update (GimpTool *tool,
55
GdkModifierType state,
57
GimpDisplay *display);
58
static void gimp_brush_tool_cursor_update (GimpTool *tool,
60
GdkModifierType state,
61
GimpDisplay *display);
63
static void gimp_brush_tool_draw (GimpDrawTool *draw_tool);
65
static void gimp_brush_tool_brush_changed (GimpContext *context,
67
GimpBrushTool *brush_tool);
68
static void gimp_brush_tool_brush_scaled (GimpPaintOptions *options,
70
GimpBrushTool *brush_tool);
71
static void gimp_brush_tool_set_brush (GimpBrushCore *brush_core,
73
GimpBrushTool *brush_tool);
74
static void gimp_brush_tool_set_brush_after(GimpBrushCore *brush_core,
76
GimpBrushTool *brush_tool);
77
static void gimp_brush_tool_notify_brush (GimpDisplayConfig *config,
79
GimpBrushTool *brush_tool);
49
static void gimp_brush_tool_constructed (GObject *object);
51
static void gimp_brush_tool_motion (GimpTool *tool,
52
const GimpCoords *coords,
54
GdkModifierType state,
55
GimpDisplay *display);
56
static void gimp_brush_tool_oper_update (GimpTool *tool,
57
const GimpCoords *coords,
58
GdkModifierType state,
60
GimpDisplay *display);
61
static void gimp_brush_tool_cursor_update (GimpTool *tool,
62
const GimpCoords *coords,
63
GdkModifierType state,
64
GimpDisplay *display);
65
static void gimp_brush_tool_options_notify (GimpTool *tool,
66
GimpToolOptions *options,
67
const GParamSpec *pspec);
69
static void gimp_brush_tool_draw (GimpDrawTool *draw_tool);
71
static void gimp_brush_tool_brush_changed (GimpContext *context,
73
GimpBrushTool *brush_tool);
74
static void gimp_brush_tool_set_brush (GimpBrushCore *brush_core,
76
GimpBrushTool *brush_tool);
77
static void gimp_brush_tool_notify_brush (GimpDisplayConfig *config,
79
GimpBrushTool *brush_tool);
82
82
G_DEFINE_TYPE (GimpBrushTool, gimp_brush_tool, GIMP_TYPE_PAINT_TOOL)
194
gimp_brush_tool_oper_update (GimpTool *tool,
196
GdkModifierType state,
198
GimpDisplay *display)
181
gimp_brush_tool_oper_update (GimpTool *tool,
182
const GimpCoords *coords,
183
GdkModifierType state,
185
GimpDisplay *display)
200
187
GimpBrushTool *brush_tool = GIMP_BRUSH_TOOL (tool);
201
188
GimpPaintOptions *paint_options = GIMP_PAINT_TOOL_GET_OPTIONS (tool);
189
GimpDrawable *drawable;
203
191
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
205
193
GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state,
206
194
proximity, display);
196
drawable = gimp_image_get_active_drawable (gimp_display_get_image (display));
208
198
if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)) &&
209
gimp_image_get_active_drawable (display->image) && proximity)
199
drawable && proximity)
201
GimpContext *context = GIMP_CONTEXT (paint_options);
211
202
GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool);
212
203
GimpBrushCore *brush_core = GIMP_BRUSH_CORE (paint_tool->core);
215
205
brush_tool->brush_x = coords->x;
216
206
brush_tool->brush_y = coords->y;
218
brush = gimp_context_get_brush (GIMP_CONTEXT (paint_options));
220
if (brush_core->main_brush != brush)
221
gimp_brush_core_set_brush (brush_core, brush);
208
gimp_brush_core_set_brush (brush_core,
209
gimp_context_get_brush (context));
211
gimp_brush_core_set_dynamics (brush_core,
212
gimp_context_get_dynamics (context));
214
if (GIMP_BRUSH_CORE_GET_CLASS (brush_core)->handles_transforming_brush)
216
gimp_brush_core_eval_transform_dynamics (brush_core,
224
223
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
228
gimp_brush_tool_cursor_update (GimpTool *tool,
230
GdkModifierType state,
231
GimpDisplay *display)
227
gimp_brush_tool_cursor_update (GimpTool *tool,
228
const GimpCoords *coords,
229
GdkModifierType state,
230
GimpDisplay *display)
233
232
GimpBrushTool *brush_tool = GIMP_BRUSH_TOOL (tool);
233
GimpBrushCore *brush_core = GIMP_BRUSH_CORE (GIMP_PAINT_TOOL (brush_tool)->core);
235
if (! brush_tool->show_cursor &&
236
! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)) &&
237
gimp_tool_control_get_cursor_modifier (tool->control) !=
238
GIMP_CURSOR_MODIFIER_BAD)
235
if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)))
240
gimp_tool_set_cursor (tool, display,
242
GIMP_TOOL_CURSOR_NONE,
243
GIMP_CURSOR_MODIFIER_NONE);
237
if (! brush_core->main_brush || ! brush_core->dynamics)
239
gimp_tool_set_cursor (tool, display,
240
gimp_tool_control_get_cursor (tool->control),
241
gimp_tool_control_get_tool_cursor (tool->control),
242
GIMP_CURSOR_MODIFIER_BAD);
245
else if (! brush_tool->show_cursor &&
246
gimp_tool_control_get_cursor_modifier (tool->control) !=
247
GIMP_CURSOR_MODIFIER_BAD)
249
gimp_tool_set_cursor (tool, display,
251
GIMP_TOOL_CURSOR_NONE,
252
GIMP_CURSOR_MODIFIER_NONE);
257
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
261
gimp_brush_tool_options_notify (GimpTool *tool,
262
GimpToolOptions *options,
263
const GParamSpec *pspec)
265
GIMP_TOOL_CLASS (parent_class)->options_notify (tool, options, pspec);
267
if (! strcmp (pspec->name, "brush-size") ||
268
! strcmp (pspec->name, "brush-angle") ||
269
! strcmp (pspec->name, "brush-aspect-ratio"))
247
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool,
248
coords, state, display);
271
GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool);
272
GimpBrushCore *brush_core = GIMP_BRUSH_CORE (paint_tool->core);
274
g_signal_emit_by_name (brush_core, "set-brush",
275
brush_core->main_brush);
253
280
gimp_brush_tool_draw (GimpDrawTool *draw_tool)
255
GimpBrushTool *brush_tool = GIMP_BRUSH_TOOL (draw_tool);
282
GimpBrushTool *brush_tool = GIMP_BRUSH_TOOL (draw_tool);
283
GimpCanvasItem *item;
257
285
GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool);
259
287
if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (draw_tool)))
262
gimp_brush_tool_draw_brush (brush_tool,
263
brush_tool->brush_x, brush_tool->brush_y,
264
! brush_tool->show_cursor);
290
item = gimp_brush_tool_create_outline (brush_tool,
294
! brush_tool->show_cursor);
298
gimp_draw_tool_add_item (draw_tool, item);
299
g_object_unref (item);
268
gimp_brush_tool_draw_brush (GimpBrushTool *brush_tool,
271
gboolean draw_fallback)
304
gimp_brush_tool_create_outline (GimpBrushTool *brush_tool,
305
GimpDisplay *display,
308
gboolean draw_fallback)
273
GimpDrawTool *draw_tool;
274
GimpBrushCore *brush_core;
275
GimpPaintOptions *options;
310
GimpBrushCore *brush_core;
311
GimpPaintOptions *options;
312
GimpDisplayShell *shell;
313
const GimpBezierDesc *boundary = NULL;
277
g_return_if_fail (GIMP_IS_BRUSH_TOOL (brush_tool));
317
g_return_val_if_fail (GIMP_IS_BRUSH_TOOL (brush_tool), NULL);
318
g_return_val_if_fail (GIMP_IS_DISPLAY (display), NULL);
279
320
if (! brush_tool->draw_brush)
282
draw_tool = GIMP_DRAW_TOOL (brush_tool);
283
323
brush_core = GIMP_BRUSH_CORE (GIMP_PAINT_TOOL (brush_tool)->core);
284
324
options = GIMP_PAINT_TOOL_GET_OPTIONS (brush_tool);
286
/* don't create the segments for the purpose of undrawing (if we
287
* don't have the segments, we can hardly have drawn them before)
289
if (! brush_core->brush_bound_segs && brush_core->main_brush &&
290
! gimp_draw_tool_is_drawn (draw_tool))
292
gimp_brush_core_create_bound_segs (brush_core, options);
295
if (brush_core->brush_bound_segs)
297
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (draw_tool->display->shell);
298
gdouble width = brush_core->brush_bound_width;
299
gdouble height = brush_core->brush_bound_height;
301
/* don't draw the boundary if it becomes too small */
302
if (SCALEX (shell, width) > 4 && SCALEY (shell, height) > 4)
325
shell = gimp_display_get_shell (display);
327
if (! brush_core->main_brush || ! brush_core->dynamics)
330
if (brush_core->scale > 0.0)
331
boundary = gimp_brush_transform_boundary (brush_core->main_brush,
333
brush_core->aspect_ratio,
335
brush_core->hardness,
339
/* don't draw the boundary if it becomes too small */
341
SCALEX (shell, width) > 4 &&
342
SCALEY (shell, height) > 4)
347
if (gimp_paint_options_get_brush_mode (options) == GIMP_BRUSH_HARD)
307
if (gimp_paint_options_get_brush_mode (options) == GIMP_BRUSH_HARD)
309
349
#define EPSILON 0.000001
310
/* Add EPSILON before rounding since e.g.
311
* (5.0 - 0.5) may end up at (4.499999999....)
312
* due to floating point fnords
314
x = RINT (x + EPSILON);
315
y = RINT (y + EPSILON);
350
/* Add EPSILON before rounding since e.g.
351
* (5.0 - 0.5) may end up at (4.499999999....)
352
* due to floating point fnords
354
x = RINT (x + EPSILON);
355
y = RINT (y + EPSILON);
319
gimp_draw_tool_draw_boundary (draw_tool,
320
brush_core->brush_bound_segs,
321
brush_core->n_brush_bound_segs,
325
else if (draw_fallback)
327
gimp_draw_tool_draw_handle (draw_tool, GIMP_HANDLE_CROSS,
329
5, 5, GTK_ANCHOR_CENTER,
359
return gimp_canvas_path_new (shell, boundary, x, y, FALSE,
360
GIMP_PATH_STYLE_OUTLINE);
362
else if (draw_fallback)
364
return gimp_canvas_handle_new (shell,
366
GIMP_HANDLE_ANCHOR_CENTER,
368
GIMP_TOOL_HANDLE_SIZE_SMALL,
369
GIMP_TOOL_HANDLE_SIZE_SMALL);