diff --git a/ChangeLog b/ChangeLog index 20b41273d6..b89701f2a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2003-07-10 Michael Natterer + + * app/display/gimpdisplayshell-transform.[ch]: removed + gimp_display_shell_transform_boundary() again... + + * app/tools/gimpdrawtool.[ch]: ...and added as + gimp_draw_tool_draw_boundary(). Removed the GimpDrawToolState enum + and the "draw_state" member since they were redundant. Cleanup. + + * app/tools/gimpeditselectiontool.c: changed accordingly. + + * app/tools/gimppainttool.[ch]: added a brush preview so we + finally see where we will paint. Fixes bug #32498. Cleanup. + + * app/tools/tool_manager.c: also look at draw_tool->gdisp, not + only at tool->gdisp when deciding whether the active tool has to + be suspended/resumed/halted. Fixes a couple of fnords with the + line preview and the new brush preview. + + * app/tools/gimpcolortool.c: minor cleanup. + 2003-07-10 Michael Natterer * app/core/gimpbrush.c diff --git a/app/display/gimpdisplayshell-transform.c b/app/display/gimpdisplayshell-transform.c index 03c9fd8888..2ac4f6cdab 100644 --- a/app/display/gimpdisplayshell-transform.c +++ b/app/display/gimpdisplayshell-transform.c @@ -22,8 +22,6 @@ #include "display-types.h" -#include "base/boundary.h" - #include "core/gimpdrawable.h" #include "core/gimpimage.h" @@ -216,67 +214,3 @@ gimp_display_shell_untransform_xy_f (GimpDisplayShell *shell, *nx = (x + shell->offset_x) / scalex - offset_x; *ny = (y + shell->offset_y) / scaley - offset_y; } - -GdkSegment * -gimp_display_shell_transform_boundary (GimpDisplayShell *shell, - BoundSeg *bound_segs, - gint n_bound_segs, - gint offset_x, - gint offset_y) -{ - GdkSegment *dest_segs; - gint x, y; - gint xclamp, yclamp; - gint i; - - g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), NULL); - g_return_val_if_fail (n_bound_segs > 0 || bound_segs == NULL, NULL); - - dest_segs = g_new0 (GdkSegment, n_bound_segs); - - xclamp = shell->disp_width + 1; - yclamp = shell->disp_height + 1; - - for (i = 0; i < n_bound_segs; i++) - { - gimp_display_shell_transform_xy (shell, - bound_segs[i].x1 + offset_x, - bound_segs[i].y1 + offset_y, - &x, &y, - FALSE); - - dest_segs[i].x1 = CLAMP (x, -1, xclamp); - dest_segs[i].y1 = CLAMP (y, -1, yclamp); - - gimp_display_shell_transform_xy (shell, - bound_segs[i].x2 + offset_x, - bound_segs[i].y2 + offset_y, - &x, &y, - FALSE); - - dest_segs[i].x2 = CLAMP (x, -1, xclamp); - dest_segs[i].y2 = CLAMP (y, -1, yclamp); - - /* If this segment is a closing segment && the segments lie inside - * the region, OR if this is an opening segment and the segments - * lie outside the region... - * we need to transform it by one display pixel - */ - if (! bound_segs[i].open) - { - /* If it is vertical */ - if (dest_segs[i].x1 == dest_segs[i].x2) - { - dest_segs[i].x1 -= 1; - dest_segs[i].x2 -= 1; - } - else - { - dest_segs[i].y1 -= 1; - dest_segs[i].y2 -= 1; - } - } - } - - return dest_segs; -} diff --git a/app/display/gimpdisplayshell-transform.h b/app/display/gimpdisplayshell-transform.h index 13b1175ca2..e86d9bfd1f 100644 --- a/app/display/gimpdisplayshell-transform.h +++ b/app/display/gimpdisplayshell-transform.h @@ -54,12 +54,5 @@ void gimp_display_shell_untransform_xy_f (GimpDisplayShell *shell, gdouble *ny, gboolean use_offsets); -GdkSegment * - gimp_display_shell_transform_boundary (GimpDisplayShell *shell, - BoundSeg *bound_segs, - gint n_bound_segs, - gint offset_x, - gint offset_y); - #endif /* __GIMP_DISPLAY_SHELL_TRANSFORM_H__ */ diff --git a/app/tools/gimpbrushtool.c b/app/tools/gimpbrushtool.c index 1a04207660..62099adea4 100644 --- a/app/tools/gimpbrushtool.c +++ b/app/tools/gimpbrushtool.c @@ -48,6 +48,14 @@ #include "gimptoolcontrol.h" #include "tool_manager.h" + +#include "base/boundary.h" +#include "base/pixel-region.h" +#include "base/temp-buf.h" +#include "core/gimpbrush.h" +#include "display/gimpdisplayshell-transform.h" + + #include "gimp-intl.h" @@ -83,11 +91,14 @@ static void gimp_paint_tool_modifier_key (GimpTool *tool, gboolean press, GdkModifierType state, GimpDisplay *gdisp); - static void gimp_paint_tool_oper_update (GimpTool *tool, GimpCoords *coords, GdkModifierType state, GimpDisplay *gdisp); +static void gimp_paint_tool_cursor_update (GimpTool *tool, + GimpCoords *coords, + GdkModifierType state, + GimpDisplay *gdisp); static void gimp_paint_tool_draw (GimpDrawTool *draw_tool); @@ -121,7 +132,7 @@ gimp_paint_tool_get_type (void) }; tool_type = g_type_register_static (GIMP_TYPE_COLOR_TOOL, - "GimpPaintTool", + "GimpPaintTool", &tool_info, 0); } @@ -151,6 +162,7 @@ gimp_paint_tool_class_init (GimpPaintToolClass *klass) tool_class->motion = gimp_paint_tool_motion; tool_class->modifier_key = gimp_paint_tool_modifier_key; tool_class->oper_update = gimp_paint_tool_oper_update; + tool_class->cursor_update = gimp_paint_tool_cursor_update; draw_tool_class->draw = gimp_paint_tool_draw; @@ -165,6 +177,13 @@ gimp_paint_tool_init (GimpPaintTool *paint_tool) gimp_tool_control_set_motion_mode (tool->control, GIMP_MOTION_MODE_EXACT); paint_tool->pick_colors = FALSE; + paint_tool->draw_line = FALSE; + paint_tool->draw_brush = TRUE; + + paint_tool->brush_bound_segs = NULL; + paint_tool->n_brush_bound_segs = 0; + paint_tool->brush_x = 0; + paint_tool->brush_y = 0; } static void @@ -172,6 +191,13 @@ gimp_paint_tool_finalize (GObject *object) { GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (object); + if (paint_tool->brush_bound_segs) + { + g_free (paint_tool->brush_bound_segs); + paint_tool->brush_bound_segs = NULL; + paint_tool->n_brush_bound_segs = 0; + } + if (paint_tool->core) { g_object_unref (paint_tool->core); @@ -253,7 +279,7 @@ gimp_paint_tool_round_line (GimpPaintCore *core, core->last_coords.y = floor (core->last_coords.y) + 0.5; core->cur_coords.x = floor (core->cur_coords.x ) + 0.5; core->cur_coords.y = floor (core->cur_coords.y ) + 0.5; - + /* Restrict to multiples of 15 degrees if ctrl is pressed */ if (state & GDK_CONTROL_MASK) gimp_paint_core_constrain (core); @@ -274,7 +300,6 @@ gimp_paint_tool_button_press (GimpTool *tool, GimpDrawable *drawable; GimpCoords curr_coords; gint off_x, off_y; - gboolean draw_line = FALSE; draw_tool = GIMP_DRAW_TOOL (tool); paint_tool = GIMP_PAINT_TOOL (tool); @@ -291,7 +316,7 @@ gimp_paint_tool_button_press (GimpTool *tool, curr_coords.x -= off_x; curr_coords.y -= off_y; - if (draw_tool->gdisp) + if (gimp_draw_tool_is_active (draw_tool)) gimp_draw_tool_stop (draw_tool); if (tool->gdisp && @@ -307,34 +332,24 @@ gimp_paint_tool_button_press (GimpTool *tool, tool->gdisp = gdisp; } - if (gimp_devices_get_current (gdisp->gimage->gimp) == - gdk_device_get_core_pointer ()) - { - core->use_pressure = FALSE; - } - else - { - core->use_pressure = TRUE; - } + core->use_pressure = (gimp_devices_get_current (gdisp->gimage->gimp) != + gdk_device_get_core_pointer ()); if (! gimp_paint_core_start (core, drawable, paint_options, &curr_coords)) return; - if ((gdisp != tool->gdisp) || ! (state & GDK_SHIFT_MASK)) + if ((gdisp != tool->gdisp) || ! paint_tool->draw_line) { /* if this is a new image, reinit the core vals */ core->start_coords = core->cur_coords; core->last_coords = core->cur_coords; } - else if (state & GDK_SHIFT_MASK) + else if (paint_tool->draw_line) { /* If shift is down and this is not the first paint * stroke, then draw a line from the last coords to the pointer */ - - draw_line = TRUE; - core->start_coords = core->last_coords; gimp_paint_tool_round_line (core, state); @@ -360,7 +375,7 @@ gimp_paint_tool_button_press (GimpTool *tool, gimp_paint_core_paint (core, drawable, paint_options, PRETRACE_PAINT); /* Paint to the image */ - if (draw_line) + if (paint_tool->draw_line) { gimp_paint_core_interpolate (core, drawable, paint_options); @@ -442,7 +457,7 @@ gimp_paint_tool_motion (GimpTool *tool, core->cur_coords.y -= off_y; GIMP_TOOL_CLASS (parent_class)->motion (tool, coords, time, state, gdisp); - + if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool))) return; @@ -466,10 +481,16 @@ gimp_paint_tool_modifier_key (GimpTool *tool, GdkModifierType state, GimpDisplay *gdisp) { + GimpPaintTool *paint_tool; + GimpDrawTool *draw_tool; + + paint_tool = GIMP_PAINT_TOOL (tool); + draw_tool = GIMP_DRAW_TOOL (tool); + if (key != GDK_CONTROL_MASK) return; - if (GIMP_PAINT_TOOL (tool)->pick_colors && ! (state & GDK_SHIFT_MASK)) + if (paint_tool->pick_colors && ! paint_tool->draw_line) { if (press) { @@ -478,6 +499,9 @@ gimp_paint_tool_modifier_key (GimpTool *tool, info = tool_manager_get_info_by_type (gdisp->gimage->gimp, GIMP_TYPE_COLOR_PICKER_TOOL); + if (gimp_draw_tool_is_active (draw_tool)) + gimp_draw_tool_stop (draw_tool); + gimp_color_tool_enable (GIMP_COLOR_TOOL (tool), GIMP_COLOR_OPTIONS (info->tool_options)); } @@ -488,7 +512,6 @@ gimp_paint_tool_modifier_key (GimpTool *tool, } } - static void gimp_paint_tool_oper_update (GimpTool *tool, GimpCoords *coords, @@ -504,12 +527,17 @@ gimp_paint_tool_oper_update (GimpTool *tool, paint_tool = GIMP_PAINT_TOOL (tool); draw_tool = GIMP_DRAW_TOOL (tool); + if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (draw_tool))) + { + GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, gdisp); + return; + } + core = paint_tool->core; shell = GIMP_DISPLAY_SHELL (gdisp->shell); - /* undraw the old line (if any) */ - if (draw_tool->gdisp) + if (gimp_draw_tool_is_active (draw_tool)) gimp_draw_tool_stop (draw_tool); gimp_statusbar_pop (GIMP_STATUSBAR (shell->statusbar), @@ -530,13 +558,16 @@ gimp_paint_tool_oper_update (GimpTool *tool, if ((layer = gimp_image_get_active_layer (gdisp->gimage))) { + paint_tool->brush_x = coords->x; + paint_tool->brush_y = coords->y; + if (gdisp == tool->gdisp && (state & GDK_SHIFT_MASK)) - { + { /* If shift is down and this is not the first paint stroke, * draw a line */ - gdouble dx, dy, dist; + gdouble dx, dy, dist; gchar status_str[STATUSBAR_SIZE]; gint off_x, off_y; @@ -549,44 +580,74 @@ gimp_paint_tool_oper_update (GimpTool *tool, gimp_paint_tool_round_line (core, state); - dx = core->cur_coords.x - core->last_coords.x; - dy = core->cur_coords.y - core->last_coords.y; + dx = core->cur_coords.x - core->last_coords.x; + dy = core->cur_coords.y - core->last_coords.y; - /* show distance in statusbar */ - if (shell->dot_for_dot) - { - dist = sqrt (SQR (dx) + SQR (dy)); + /* show distance in statusbar */ + if (shell->dot_for_dot) + { + dist = sqrt (SQR (dx) + SQR (dy)); - g_snprintf (status_str, sizeof (status_str), "%.1f %s", + g_snprintf (status_str, sizeof (status_str), "%.1f %s", dist, _("pixels")); - } - else - { - gchar format_str[64]; + } + else + { + gchar format_str[64]; g_snprintf (format_str, sizeof (format_str), "%%.%df %s", gimp_unit_get_digits (gdisp->gimage->unit), gimp_unit_get_symbol (gdisp->gimage->unit)); - dist = (gimp_unit_get_factor (gdisp->gimage->unit) * + dist = (gimp_unit_get_factor (gdisp->gimage->unit) * sqrt (SQR (dx / gdisp->gimage->xresolution) + SQR (dy / gdisp->gimage->yresolution))); - g_snprintf (status_str, sizeof (status_str), format_str, + g_snprintf (status_str, sizeof (status_str), format_str, dist); - } + } - gimp_statusbar_push (GIMP_STATUSBAR (shell->statusbar), + gimp_statusbar_push (GIMP_STATUSBAR (shell->statusbar), g_type_name (G_TYPE_FROM_INSTANCE (tool)), status_str); - gimp_draw_tool_start (draw_tool, gdisp); - } + paint_tool->draw_line = TRUE; + } + else + { + paint_tool->draw_line = FALSE; + } + + gimp_draw_tool_start (draw_tool, gdisp); } GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, gdisp); } +static void +gimp_paint_tool_cursor_update (GimpTool *tool, + GimpCoords *coords, + GdkModifierType state, + GimpDisplay *gdisp) +{ + if (gimp_image_get_active_layer (gdisp->gimage)) + { + GimpDrawTool *draw_tool; + GimpDisplayShell *shell; + + draw_tool = GIMP_DRAW_TOOL (tool); + shell = GIMP_DISPLAY_SHELL (gdisp->shell); + + if (! shell->proximity && + gimp_draw_tool_is_active (draw_tool)) + { + gimp_draw_tool_stop (draw_tool); + } + } + + GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, gdisp); +} + static void gimp_paint_tool_draw (GimpDrawTool *draw_tool) { @@ -596,35 +657,92 @@ gimp_paint_tool_draw (GimpDrawTool *draw_tool) GimpPaintCore *core; paint_tool = GIMP_PAINT_TOOL (draw_tool); - core = paint_tool->core; + core = paint_tool->core; - /* Draw start target */ - gimp_draw_tool_draw_handle (draw_tool, - GIMP_HANDLE_CROSS, - core->last_coords.x, - core->last_coords.y, - TARGET_SIZE, - TARGET_SIZE, - GTK_ANCHOR_CENTER, - TRUE); + if (paint_tool->draw_line) + { + /* Draw start target */ + gimp_draw_tool_draw_handle (draw_tool, + GIMP_HANDLE_CROSS, + core->last_coords.x, + core->last_coords.y, + TARGET_SIZE, + TARGET_SIZE, + GTK_ANCHOR_CENTER, + TRUE); - /* Draw end target */ - gimp_draw_tool_draw_handle (draw_tool, - GIMP_HANDLE_CROSS, - core->cur_coords.x, - core->cur_coords.y, - TARGET_SIZE, - TARGET_SIZE, - GTK_ANCHOR_CENTER, - TRUE); + /* Draw end target */ + gimp_draw_tool_draw_handle (draw_tool, + GIMP_HANDLE_CROSS, + core->cur_coords.x, + core->cur_coords.y, + TARGET_SIZE, + TARGET_SIZE, + GTK_ANCHOR_CENTER, + TRUE); - /* Draw the line between the start and end coords */ - gimp_draw_tool_draw_line (draw_tool, - core->last_coords.x, - core->last_coords.y, - core->cur_coords.x, - core->cur_coords.y, - TRUE); + /* Draw the line between the start and end coords */ + gimp_draw_tool_draw_line (draw_tool, + core->last_coords.x, + core->last_coords.y, + core->cur_coords.x, + core->cur_coords.y, + TRUE); + } + + if (paint_tool->draw_brush) + { + GimpContext *context; + GimpBrush *brush; + TempBuf *mask; + + context = + GIMP_CONTEXT (GIMP_TOOL (draw_tool)->tool_info->tool_options); + + brush = gimp_context_get_brush (context); + mask = gimp_brush_get_mask (brush); + + if (! paint_tool->brush_bound_segs) + { + PixelRegion PR = { 0, }; + + PR.data = temp_buf_data (mask); + PR.x = 0; + PR.y = 0; + PR.w = mask->width; + PR.h = mask->height; + PR.bytes = mask->bytes; + PR.rowstride = PR.w * PR.bytes; + + paint_tool->brush_bound_segs = + find_mask_boundary (&PR, &paint_tool->n_brush_bound_segs, + WithinBounds, + 0, 0, + PR.w, PR.h, + 1); + } + + if (paint_tool->brush_bound_segs) + { + gint brush_x, brush_y; + + brush_x = floor (paint_tool->brush_x) - (mask->width >> 1); + brush_y = floor (paint_tool->brush_y) - (mask->height >> 1); + + gimp_draw_tool_draw_boundary (draw_tool, + paint_tool->brush_bound_segs, + paint_tool->n_brush_bound_segs, + brush_x, + brush_y); + } + + if (paint_tool->brush_bound_segs) + { + g_free (paint_tool->brush_bound_segs); + paint_tool->brush_bound_segs = NULL; + paint_tool->n_brush_bound_segs = 0; + } + } } GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool); diff --git a/app/tools/gimpbrushtool.h b/app/tools/gimpbrushtool.h index 2ddaa145b8..5124cb1da6 100644 --- a/app/tools/gimpbrushtool.h +++ b/app/tools/gimpbrushtool.h @@ -38,6 +38,13 @@ struct _GimpPaintTool GimpColorTool parent_instance; gboolean pick_colors; /* pick color if ctrl is pressed */ + gboolean draw_line; + gboolean draw_brush; + + BoundSeg *brush_bound_segs; + gint n_brush_bound_segs; + gdouble brush_x; + gdouble brush_y; GimpPaintCore *core; }; diff --git a/app/tools/gimpcolortool.c b/app/tools/gimpcolortool.c index ce960541f4..b96c458cec 100644 --- a/app/tools/gimpcolortool.c +++ b/app/tools/gimpcolortool.c @@ -289,13 +289,11 @@ gimp_color_tool_cursor_update (GimpTool *tool, static void gimp_color_tool_draw (GimpDrawTool *draw_tool) { - GimpColorTool *color_tool; + GimpColorTool *color_tool = GIMP_COLOR_TOOL (draw_tool); - if (! GIMP_COLOR_TOOL (draw_tool)->enabled) + if (! color_tool->enabled) return; - color_tool = GIMP_COLOR_TOOL (draw_tool); - if (color_tool->options->sample_average) { gdouble radius = color_tool->options->average_radius; diff --git a/app/tools/gimpdrawtool.c b/app/tools/gimpdrawtool.c index 94a505c516..d52f69d68d 100644 --- a/app/tools/gimpdrawtool.c +++ b/app/tools/gimpdrawtool.c @@ -24,6 +24,8 @@ #include "tools-types.h" +#include "base/boundary.h" + #include "display/gimpdisplay.h" #include "display/gimpdisplayshell.h" #include "display/gimpdisplayshell-transform.h" @@ -116,7 +118,6 @@ gimp_draw_tool_init (GimpDrawTool *draw_tool) draw_tool->win = NULL; draw_tool->gc = NULL; - draw_tool->draw_state = GIMP_DRAW_TOOL_STATE_INVISIBLE; draw_tool->paused_count = 0; draw_tool->line_width = 0; @@ -174,15 +175,10 @@ gimp_draw_tool_control (GimpTool *tool, static void gimp_draw_tool_draw (GimpDrawTool *draw_tool) { - if (draw_tool->draw_state == GIMP_DRAW_TOOL_STATE_VISIBLE) - draw_tool->draw_state = GIMP_DRAW_TOOL_STATE_INVISIBLE; - else - draw_tool->draw_state = GIMP_DRAW_TOOL_STATE_VISIBLE; - - if (draw_tool->gdisp) - { + if (draw_tool->paused_count == 0 && draw_tool->gdisp) + { GIMP_DRAW_TOOL_GET_CLASS (draw_tool)->draw (draw_tool); - } + } } void @@ -199,9 +195,9 @@ gimp_draw_tool_start (GimpDrawTool *draw_tool, gimp_draw_tool_stop (draw_tool); - draw_tool->gdisp = gdisp; - draw_tool->win = shell->canvas->window; - draw_tool->gc = gdk_gc_new (draw_tool->win); + draw_tool->gdisp = gdisp; + draw_tool->win = shell->canvas->window; + draw_tool->gc = gdk_gc_new (draw_tool->win); gdk_gc_set_function (draw_tool->gc, GDK_INVERT); fg.pixel = 0xFFFFFFFF; @@ -222,12 +218,7 @@ gimp_draw_tool_stop (GimpDrawTool *draw_tool) { g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool)); - if (draw_tool->draw_state == GIMP_DRAW_TOOL_STATE_VISIBLE) - { - gimp_draw_tool_draw (draw_tool); - } - - draw_tool->paused_count = 0; + gimp_draw_tool_draw (draw_tool); draw_tool->gdisp = NULL; draw_tool->win = NULL; @@ -252,10 +243,7 @@ gimp_draw_tool_pause (GimpDrawTool *draw_tool) { g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool)); - if (draw_tool->paused_count == 0) - { - gimp_draw_tool_draw (draw_tool); - } + gimp_draw_tool_draw (draw_tool); draw_tool->paused_count++; } @@ -269,10 +257,7 @@ gimp_draw_tool_resume (GimpDrawTool *draw_tool) { draw_tool->paused_count--; - if (draw_tool->paused_count == 0) - { - gimp_draw_tool_draw (draw_tool); - } + gimp_draw_tool_draw (draw_tool); } else { @@ -592,7 +577,7 @@ gimp_draw_tool_draw_cross_by_anchor (GimpDrawTool *draw_tool, } void -gimp_draw_tool_draw_handle (GimpDrawTool *draw_tool, +gimp_draw_tool_draw_handle (GimpDrawTool *draw_tool, GimpHandleType type, gdouble x, gdouble y, @@ -730,7 +715,7 @@ gimp_draw_tool_on_handle (GimpDrawTool *draw_tool, } void -gimp_draw_tool_draw_lines (GimpDrawTool *draw_tool, +gimp_draw_tool_draw_lines (GimpDrawTool *draw_tool, gdouble *points, gint n_points, gboolean filled, @@ -741,6 +726,8 @@ gimp_draw_tool_draw_lines (GimpDrawTool *draw_tool, gint i; gdouble sx, sy; + g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool)); + shell = GIMP_DISPLAY_SHELL (draw_tool->gdisp->shell); coords = g_new (GdkPoint, n_points); @@ -772,7 +759,7 @@ gimp_draw_tool_draw_lines (GimpDrawTool *draw_tool, } void -gimp_draw_tool_draw_strokes (GimpDrawTool *draw_tool, +gimp_draw_tool_draw_strokes (GimpDrawTool *draw_tool, GimpCoords *points, gint n_points, gboolean filled, @@ -783,6 +770,8 @@ gimp_draw_tool_draw_strokes (GimpDrawTool *draw_tool, gint i; gdouble sx, sy; + g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool)); + shell = GIMP_DISPLAY_SHELL (draw_tool->gdisp->shell); coords = g_new (GdkPoint, n_points); @@ -813,6 +802,84 @@ gimp_draw_tool_draw_strokes (GimpDrawTool *draw_tool, g_free (coords); } +void +gimp_draw_tool_draw_boundary (GimpDrawTool *draw_tool, + BoundSeg *bound_segs, + gint n_bound_segs, + gint offset_x, + gint offset_y) +{ + GimpDisplayShell *shell; + GdkSegment *gdk_segs; + gint n_gdk_segs; + gint xclamp, yclamp; + gint x, y; + gint i; + + g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool)); + g_return_if_fail (n_bound_segs > 0 || bound_segs == NULL); + + shell = GIMP_DISPLAY_SHELL (draw_tool->gdisp->shell); + + gdk_segs = g_new0 (GdkSegment, n_bound_segs); + n_gdk_segs = 0; + + xclamp = shell->disp_width + 1; + yclamp = shell->disp_height + 1; + + for (i = 0; i < n_bound_segs; i++) + { + gimp_display_shell_transform_xy (shell, + bound_segs[i].x1 + offset_x, + bound_segs[i].y1 + offset_y, + &x, &y, + FALSE); + + gdk_segs[n_gdk_segs].x1 = CLAMP (x, -1, xclamp); + gdk_segs[n_gdk_segs].y1 = CLAMP (y, -1, yclamp); + + gimp_display_shell_transform_xy (shell, + bound_segs[i].x2 + offset_x, + bound_segs[i].y2 + offset_y, + &x, &y, + FALSE); + + gdk_segs[n_gdk_segs].x2 = CLAMP (x, -1, xclamp); + gdk_segs[n_gdk_segs].y2 = CLAMP (y, -1, yclamp); + + if (gdk_segs[n_gdk_segs].x1 == gdk_segs[n_gdk_segs].x2 && + gdk_segs[n_gdk_segs].y1 == gdk_segs[n_gdk_segs].y2) + continue; + + /* If this segment is a closing segment && the segments lie inside + * the region, OR if this is an opening segment and the segments + * lie outside the region... + * we need to transform it by one display pixel + */ + if (! bound_segs[i].open) + { + /* If it is vertical */ + if (gdk_segs[n_gdk_segs].x1 == gdk_segs[n_gdk_segs].x2) + { + gdk_segs[n_gdk_segs].x1 -= 1; + gdk_segs[n_gdk_segs].x2 -= 1; + } + else + { + gdk_segs[n_gdk_segs].y1 -= 1; + gdk_segs[n_gdk_segs].y2 -= 1; + } + } + + n_gdk_segs++; + } + + gdk_draw_segments (draw_tool->win, draw_tool->gc, + gdk_segs, n_gdk_segs); + + g_free (gdk_segs); +} + /* private functions */ @@ -877,7 +944,7 @@ gimp_draw_tool_shift_to_north_west (gdouble x, if (shifted_y) *shifted_y = y; } - + static inline void gimp_draw_tool_shift_to_center (gdouble x, gdouble y, diff --git a/app/tools/gimpdrawtool.h b/app/tools/gimpdrawtool.h index 448769831a..29e658744b 100644 --- a/app/tools/gimpdrawtool.h +++ b/app/tools/gimpdrawtool.h @@ -23,12 +23,6 @@ #include "gimptool.h" -typedef enum -{ - GIMP_DRAW_TOOL_STATE_INVISIBLE, - GIMP_DRAW_TOOL_STATE_VISIBLE -} GimpDrawToolState; - typedef enum { GIMP_HANDLE_SQUARE, @@ -51,21 +45,20 @@ typedef struct _GimpDrawToolClass GimpDrawToolClass; struct _GimpDrawTool { - GimpTool parent_instance; + GimpTool parent_instance; - GimpDisplay *gdisp; /* The display we are drawing to (may be - * a different one than tool->gdisp) - */ - GdkWindow *win; /* Window to draw draw operation to */ - GdkGC *gc; /* Graphics context for draw functions */ + GimpDisplay *gdisp; /* The display we are drawing to (may be + * a different one than tool->gdisp) + */ + GdkWindow *win; /* Window to draw draw operation to */ + GdkGC *gc; /* Graphics context for draw functions */ - GimpDrawToolState draw_state; /* Current state in the draw process */ - gint paused_count; /* count to keep track of multiple pauses */ + gint paused_count; /* count to keep track of multiple pauses */ - gint line_width; /* line attributes */ - gint line_style; /**/ - gint cap_style; /**/ - gint join_style; /**/ + gint line_width; /* line attributes */ + GdkLineStyle line_style; /**/ + GdkCapStyle cap_style; /**/ + GdkJoinStyle join_style; /**/ }; struct _GimpDrawToolClass @@ -152,7 +145,7 @@ void gimp_draw_tool_draw_cross_by_anchor (GimpDrawTool *draw_tool, GtkAnchorType anchor, gboolean use_offsets); -void gimp_draw_tool_draw_handle (GimpDrawTool *draw_tool, +void gimp_draw_tool_draw_handle (GimpDrawTool *draw_tool, GimpHandleType type, gdouble x, gdouble y, @@ -172,17 +165,23 @@ gboolean gimp_draw_tool_on_handle (GimpDrawTool *draw_tool, GtkAnchorType anchor, gboolean use_offsets); -void gimp_draw_tool_draw_lines (GimpDrawTool *draw_tool, +void gimp_draw_tool_draw_lines (GimpDrawTool *draw_tool, gdouble *points, gint n_points, gboolean filled, gboolean use_offsets); -void gimp_draw_tool_draw_strokes (GimpDrawTool *draw_tool, +void gimp_draw_tool_draw_strokes (GimpDrawTool *draw_tool, GimpCoords *points, gint n_points, gboolean filled, gboolean use_offsets); +void gimp_draw_tool_draw_boundary (GimpDrawTool *draw_tool, + BoundSeg *bound_segs, + gint n_bound_segs, + gint offset_x, + gint offset_y); + #endif /* __GIMP_DRAW_TOOL_H__ */ diff --git a/app/tools/gimpeditselectiontool.c b/app/tools/gimpeditselectiontool.c index ad89f2766a..43e7865b13 100644 --- a/app/tools/gimpeditselectiontool.c +++ b/app/tools/gimpeditselectiontool.c @@ -659,17 +659,10 @@ static void gimp_edit_selection_tool_draw (GimpDrawTool *draw_tool) { GimpEditSelectionTool *edit_select; - GimpTool *tool; GimpDisplay *gdisp; - GimpDisplayShell *shell; - Selection *select; edit_select = GIMP_EDIT_SELECTION_TOOL (draw_tool); - tool = GIMP_TOOL (draw_tool); - - gdisp = tool->gdisp; - shell = GIMP_DISPLAY_SHELL (gdisp->shell); - select = shell->select; + gdisp = GIMP_TOOL (draw_tool)->gdisp; switch (edit_select->edit_type) { @@ -677,36 +670,19 @@ gimp_edit_selection_tool_draw (GimpDrawTool *draw_tool) { GimpLayer *layer = gimp_image_get_active_layer (gdisp->gimage); gboolean floating_sel = gimp_layer_is_floating_sel (layer); - GdkSegment *segs_copy; if (! floating_sel) - { - segs_copy = - gimp_display_shell_transform_boundary (shell, - edit_select->segs_in, - edit_select->num_segs_in, - edit_select->cumlx, - edit_select->cumly); + gimp_draw_tool_draw_boundary (draw_tool, + edit_select->segs_in, + edit_select->num_segs_in, + edit_select->cumlx, + edit_select->cumly); - /* Draw the items */ - gdk_draw_segments (draw_tool->win, draw_tool->gc, - segs_copy, select->num_segs_in); - - g_free (segs_copy); - } - - segs_copy = - gimp_display_shell_transform_boundary (shell, - edit_select->segs_out, - edit_select->num_segs_out, - edit_select->cumlx, - edit_select->cumly); - - /* Draw the items */ - gdk_draw_segments (draw_tool->win, draw_tool->gc, - segs_copy, select->num_segs_out); - - g_free (segs_copy); + gimp_draw_tool_draw_boundary (draw_tool, + edit_select->segs_out, + edit_select->num_segs_out, + edit_select->cumlx, + edit_select->cumly); } break; @@ -774,22 +750,11 @@ gimp_edit_selection_tool_draw (GimpDrawTool *draw_tool) break; case EDIT_FLOATING_SEL_TRANSLATE: - { - GdkSegment *segs_copy; - - segs_copy = - gimp_display_shell_transform_boundary (shell, - edit_select->segs_in, - edit_select->num_segs_in, - edit_select->cumlx, - edit_select->cumly); - - /* Draw the items */ - gdk_draw_segments (draw_tool->win, draw_tool->gc, - segs_copy, select->num_segs_in); - - g_free (segs_copy); - } + gimp_draw_tool_draw_boundary (draw_tool, + edit_select->segs_in, + edit_select->num_segs_in, + edit_select->cumlx, + edit_select->cumly); break; } } diff --git a/app/tools/gimppainttool.c b/app/tools/gimppainttool.c index 1a04207660..62099adea4 100644 --- a/app/tools/gimppainttool.c +++ b/app/tools/gimppainttool.c @@ -48,6 +48,14 @@ #include "gimptoolcontrol.h" #include "tool_manager.h" + +#include "base/boundary.h" +#include "base/pixel-region.h" +#include "base/temp-buf.h" +#include "core/gimpbrush.h" +#include "display/gimpdisplayshell-transform.h" + + #include "gimp-intl.h" @@ -83,11 +91,14 @@ static void gimp_paint_tool_modifier_key (GimpTool *tool, gboolean press, GdkModifierType state, GimpDisplay *gdisp); - static void gimp_paint_tool_oper_update (GimpTool *tool, GimpCoords *coords, GdkModifierType state, GimpDisplay *gdisp); +static void gimp_paint_tool_cursor_update (GimpTool *tool, + GimpCoords *coords, + GdkModifierType state, + GimpDisplay *gdisp); static void gimp_paint_tool_draw (GimpDrawTool *draw_tool); @@ -121,7 +132,7 @@ gimp_paint_tool_get_type (void) }; tool_type = g_type_register_static (GIMP_TYPE_COLOR_TOOL, - "GimpPaintTool", + "GimpPaintTool", &tool_info, 0); } @@ -151,6 +162,7 @@ gimp_paint_tool_class_init (GimpPaintToolClass *klass) tool_class->motion = gimp_paint_tool_motion; tool_class->modifier_key = gimp_paint_tool_modifier_key; tool_class->oper_update = gimp_paint_tool_oper_update; + tool_class->cursor_update = gimp_paint_tool_cursor_update; draw_tool_class->draw = gimp_paint_tool_draw; @@ -165,6 +177,13 @@ gimp_paint_tool_init (GimpPaintTool *paint_tool) gimp_tool_control_set_motion_mode (tool->control, GIMP_MOTION_MODE_EXACT); paint_tool->pick_colors = FALSE; + paint_tool->draw_line = FALSE; + paint_tool->draw_brush = TRUE; + + paint_tool->brush_bound_segs = NULL; + paint_tool->n_brush_bound_segs = 0; + paint_tool->brush_x = 0; + paint_tool->brush_y = 0; } static void @@ -172,6 +191,13 @@ gimp_paint_tool_finalize (GObject *object) { GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (object); + if (paint_tool->brush_bound_segs) + { + g_free (paint_tool->brush_bound_segs); + paint_tool->brush_bound_segs = NULL; + paint_tool->n_brush_bound_segs = 0; + } + if (paint_tool->core) { g_object_unref (paint_tool->core); @@ -253,7 +279,7 @@ gimp_paint_tool_round_line (GimpPaintCore *core, core->last_coords.y = floor (core->last_coords.y) + 0.5; core->cur_coords.x = floor (core->cur_coords.x ) + 0.5; core->cur_coords.y = floor (core->cur_coords.y ) + 0.5; - + /* Restrict to multiples of 15 degrees if ctrl is pressed */ if (state & GDK_CONTROL_MASK) gimp_paint_core_constrain (core); @@ -274,7 +300,6 @@ gimp_paint_tool_button_press (GimpTool *tool, GimpDrawable *drawable; GimpCoords curr_coords; gint off_x, off_y; - gboolean draw_line = FALSE; draw_tool = GIMP_DRAW_TOOL (tool); paint_tool = GIMP_PAINT_TOOL (tool); @@ -291,7 +316,7 @@ gimp_paint_tool_button_press (GimpTool *tool, curr_coords.x -= off_x; curr_coords.y -= off_y; - if (draw_tool->gdisp) + if (gimp_draw_tool_is_active (draw_tool)) gimp_draw_tool_stop (draw_tool); if (tool->gdisp && @@ -307,34 +332,24 @@ gimp_paint_tool_button_press (GimpTool *tool, tool->gdisp = gdisp; } - if (gimp_devices_get_current (gdisp->gimage->gimp) == - gdk_device_get_core_pointer ()) - { - core->use_pressure = FALSE; - } - else - { - core->use_pressure = TRUE; - } + core->use_pressure = (gimp_devices_get_current (gdisp->gimage->gimp) != + gdk_device_get_core_pointer ()); if (! gimp_paint_core_start (core, drawable, paint_options, &curr_coords)) return; - if ((gdisp != tool->gdisp) || ! (state & GDK_SHIFT_MASK)) + if ((gdisp != tool->gdisp) || ! paint_tool->draw_line) { /* if this is a new image, reinit the core vals */ core->start_coords = core->cur_coords; core->last_coords = core->cur_coords; } - else if (state & GDK_SHIFT_MASK) + else if (paint_tool->draw_line) { /* If shift is down and this is not the first paint * stroke, then draw a line from the last coords to the pointer */ - - draw_line = TRUE; - core->start_coords = core->last_coords; gimp_paint_tool_round_line (core, state); @@ -360,7 +375,7 @@ gimp_paint_tool_button_press (GimpTool *tool, gimp_paint_core_paint (core, drawable, paint_options, PRETRACE_PAINT); /* Paint to the image */ - if (draw_line) + if (paint_tool->draw_line) { gimp_paint_core_interpolate (core, drawable, paint_options); @@ -442,7 +457,7 @@ gimp_paint_tool_motion (GimpTool *tool, core->cur_coords.y -= off_y; GIMP_TOOL_CLASS (parent_class)->motion (tool, coords, time, state, gdisp); - + if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool))) return; @@ -466,10 +481,16 @@ gimp_paint_tool_modifier_key (GimpTool *tool, GdkModifierType state, GimpDisplay *gdisp) { + GimpPaintTool *paint_tool; + GimpDrawTool *draw_tool; + + paint_tool = GIMP_PAINT_TOOL (tool); + draw_tool = GIMP_DRAW_TOOL (tool); + if (key != GDK_CONTROL_MASK) return; - if (GIMP_PAINT_TOOL (tool)->pick_colors && ! (state & GDK_SHIFT_MASK)) + if (paint_tool->pick_colors && ! paint_tool->draw_line) { if (press) { @@ -478,6 +499,9 @@ gimp_paint_tool_modifier_key (GimpTool *tool, info = tool_manager_get_info_by_type (gdisp->gimage->gimp, GIMP_TYPE_COLOR_PICKER_TOOL); + if (gimp_draw_tool_is_active (draw_tool)) + gimp_draw_tool_stop (draw_tool); + gimp_color_tool_enable (GIMP_COLOR_TOOL (tool), GIMP_COLOR_OPTIONS (info->tool_options)); } @@ -488,7 +512,6 @@ gimp_paint_tool_modifier_key (GimpTool *tool, } } - static void gimp_paint_tool_oper_update (GimpTool *tool, GimpCoords *coords, @@ -504,12 +527,17 @@ gimp_paint_tool_oper_update (GimpTool *tool, paint_tool = GIMP_PAINT_TOOL (tool); draw_tool = GIMP_DRAW_TOOL (tool); + if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (draw_tool))) + { + GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, gdisp); + return; + } + core = paint_tool->core; shell = GIMP_DISPLAY_SHELL (gdisp->shell); - /* undraw the old line (if any) */ - if (draw_tool->gdisp) + if (gimp_draw_tool_is_active (draw_tool)) gimp_draw_tool_stop (draw_tool); gimp_statusbar_pop (GIMP_STATUSBAR (shell->statusbar), @@ -530,13 +558,16 @@ gimp_paint_tool_oper_update (GimpTool *tool, if ((layer = gimp_image_get_active_layer (gdisp->gimage))) { + paint_tool->brush_x = coords->x; + paint_tool->brush_y = coords->y; + if (gdisp == tool->gdisp && (state & GDK_SHIFT_MASK)) - { + { /* If shift is down and this is not the first paint stroke, * draw a line */ - gdouble dx, dy, dist; + gdouble dx, dy, dist; gchar status_str[STATUSBAR_SIZE]; gint off_x, off_y; @@ -549,44 +580,74 @@ gimp_paint_tool_oper_update (GimpTool *tool, gimp_paint_tool_round_line (core, state); - dx = core->cur_coords.x - core->last_coords.x; - dy = core->cur_coords.y - core->last_coords.y; + dx = core->cur_coords.x - core->last_coords.x; + dy = core->cur_coords.y - core->last_coords.y; - /* show distance in statusbar */ - if (shell->dot_for_dot) - { - dist = sqrt (SQR (dx) + SQR (dy)); + /* show distance in statusbar */ + if (shell->dot_for_dot) + { + dist = sqrt (SQR (dx) + SQR (dy)); - g_snprintf (status_str, sizeof (status_str), "%.1f %s", + g_snprintf (status_str, sizeof (status_str), "%.1f %s", dist, _("pixels")); - } - else - { - gchar format_str[64]; + } + else + { + gchar format_str[64]; g_snprintf (format_str, sizeof (format_str), "%%.%df %s", gimp_unit_get_digits (gdisp->gimage->unit), gimp_unit_get_symbol (gdisp->gimage->unit)); - dist = (gimp_unit_get_factor (gdisp->gimage->unit) * + dist = (gimp_unit_get_factor (gdisp->gimage->unit) * sqrt (SQR (dx / gdisp->gimage->xresolution) + SQR (dy / gdisp->gimage->yresolution))); - g_snprintf (status_str, sizeof (status_str), format_str, + g_snprintf (status_str, sizeof (status_str), format_str, dist); - } + } - gimp_statusbar_push (GIMP_STATUSBAR (shell->statusbar), + gimp_statusbar_push (GIMP_STATUSBAR (shell->statusbar), g_type_name (G_TYPE_FROM_INSTANCE (tool)), status_str); - gimp_draw_tool_start (draw_tool, gdisp); - } + paint_tool->draw_line = TRUE; + } + else + { + paint_tool->draw_line = FALSE; + } + + gimp_draw_tool_start (draw_tool, gdisp); } GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, gdisp); } +static void +gimp_paint_tool_cursor_update (GimpTool *tool, + GimpCoords *coords, + GdkModifierType state, + GimpDisplay *gdisp) +{ + if (gimp_image_get_active_layer (gdisp->gimage)) + { + GimpDrawTool *draw_tool; + GimpDisplayShell *shell; + + draw_tool = GIMP_DRAW_TOOL (tool); + shell = GIMP_DISPLAY_SHELL (gdisp->shell); + + if (! shell->proximity && + gimp_draw_tool_is_active (draw_tool)) + { + gimp_draw_tool_stop (draw_tool); + } + } + + GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, gdisp); +} + static void gimp_paint_tool_draw (GimpDrawTool *draw_tool) { @@ -596,35 +657,92 @@ gimp_paint_tool_draw (GimpDrawTool *draw_tool) GimpPaintCore *core; paint_tool = GIMP_PAINT_TOOL (draw_tool); - core = paint_tool->core; + core = paint_tool->core; - /* Draw start target */ - gimp_draw_tool_draw_handle (draw_tool, - GIMP_HANDLE_CROSS, - core->last_coords.x, - core->last_coords.y, - TARGET_SIZE, - TARGET_SIZE, - GTK_ANCHOR_CENTER, - TRUE); + if (paint_tool->draw_line) + { + /* Draw start target */ + gimp_draw_tool_draw_handle (draw_tool, + GIMP_HANDLE_CROSS, + core->last_coords.x, + core->last_coords.y, + TARGET_SIZE, + TARGET_SIZE, + GTK_ANCHOR_CENTER, + TRUE); - /* Draw end target */ - gimp_draw_tool_draw_handle (draw_tool, - GIMP_HANDLE_CROSS, - core->cur_coords.x, - core->cur_coords.y, - TARGET_SIZE, - TARGET_SIZE, - GTK_ANCHOR_CENTER, - TRUE); + /* Draw end target */ + gimp_draw_tool_draw_handle (draw_tool, + GIMP_HANDLE_CROSS, + core->cur_coords.x, + core->cur_coords.y, + TARGET_SIZE, + TARGET_SIZE, + GTK_ANCHOR_CENTER, + TRUE); - /* Draw the line between the start and end coords */ - gimp_draw_tool_draw_line (draw_tool, - core->last_coords.x, - core->last_coords.y, - core->cur_coords.x, - core->cur_coords.y, - TRUE); + /* Draw the line between the start and end coords */ + gimp_draw_tool_draw_line (draw_tool, + core->last_coords.x, + core->last_coords.y, + core->cur_coords.x, + core->cur_coords.y, + TRUE); + } + + if (paint_tool->draw_brush) + { + GimpContext *context; + GimpBrush *brush; + TempBuf *mask; + + context = + GIMP_CONTEXT (GIMP_TOOL (draw_tool)->tool_info->tool_options); + + brush = gimp_context_get_brush (context); + mask = gimp_brush_get_mask (brush); + + if (! paint_tool->brush_bound_segs) + { + PixelRegion PR = { 0, }; + + PR.data = temp_buf_data (mask); + PR.x = 0; + PR.y = 0; + PR.w = mask->width; + PR.h = mask->height; + PR.bytes = mask->bytes; + PR.rowstride = PR.w * PR.bytes; + + paint_tool->brush_bound_segs = + find_mask_boundary (&PR, &paint_tool->n_brush_bound_segs, + WithinBounds, + 0, 0, + PR.w, PR.h, + 1); + } + + if (paint_tool->brush_bound_segs) + { + gint brush_x, brush_y; + + brush_x = floor (paint_tool->brush_x) - (mask->width >> 1); + brush_y = floor (paint_tool->brush_y) - (mask->height >> 1); + + gimp_draw_tool_draw_boundary (draw_tool, + paint_tool->brush_bound_segs, + paint_tool->n_brush_bound_segs, + brush_x, + brush_y); + } + + if (paint_tool->brush_bound_segs) + { + g_free (paint_tool->brush_bound_segs); + paint_tool->brush_bound_segs = NULL; + paint_tool->n_brush_bound_segs = 0; + } + } } GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool); diff --git a/app/tools/gimppainttool.h b/app/tools/gimppainttool.h index 2ddaa145b8..5124cb1da6 100644 --- a/app/tools/gimppainttool.h +++ b/app/tools/gimppainttool.h @@ -38,6 +38,13 @@ struct _GimpPaintTool GimpColorTool parent_instance; gboolean pick_colors; /* pick color if ctrl is pressed */ + gboolean draw_line; + gboolean draw_brush; + + BoundSeg *brush_bound_segs; + gint n_brush_bound_segs; + gdouble brush_x; + gdouble brush_y; GimpPaintCore *core; }; diff --git a/app/tools/tool_manager.c b/app/tools/tool_manager.c index c41ab3c20b..4f0655c25e 100644 --- a/app/tools/tool_manager.c +++ b/app/tools/tool_manager.c @@ -242,11 +242,17 @@ tool_manager_select_tool (Gimp *gimp, if (tool_manager->active_tool) { - if (tool_manager->active_tool->gdisp) + if (tool_manager->active_tool->gdisp || + GIMP_DRAW_TOOL (tool_manager->active_tool)->gdisp) { - tool_manager_control_active (gimp, - HALT, - tool_manager->active_tool->gdisp); + GimpDisplay *gdisp; + + gdisp = tool_manager->active_tool->gdisp; + + if (! gdisp) + gdisp = GIMP_DRAW_TOOL (tool_manager->active_tool)->gdisp; + + tool_manager_control_active (gimp, HALT, gdisp); } g_object_unref (tool_manager->active_tool); @@ -336,7 +342,8 @@ tool_manager_control_active (Gimp *gimp, if (! tool_manager->active_tool) return; - if (gdisp && tool_manager->active_tool->gdisp == gdisp) + if (gdisp && (tool_manager->active_tool->gdisp == gdisp || + GIMP_DRAW_TOOL (tool_manager->active_tool)->gdisp == gdisp)) { gimp_tool_control (tool_manager->active_tool, action,