static void gimp_paint_tool_modifier_key (GimpTool *tool, GdkModifierType key, gboolean press, GdkModifierType state, GimpDisplay *display) { GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool); GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool); if (paint_tool->pick_colors && ! paint_tool->draw_line) { if ((state & gimp_get_all_modifiers_mask ()) == gimp_get_constrain_behavior_mask ()) { if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool))) { GimpToolInfo *info = gimp_get_tool_info (display->gimp, "gimp-color-picker-tool"); if (GIMP_IS_TOOL_INFO (info)) { 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)); switch (GIMP_COLOR_TOOL (tool)->pick_mode) { case GIMP_COLOR_PICK_MODE_FOREGROUND: gimp_tool_push_status (tool, display, _("Click in any image to pick the " "foreground color")); break; case GIMP_COLOR_PICK_MODE_BACKGROUND: gimp_tool_push_status (tool, display, _("Click in any image to pick the " "background color")); break; default: break; } } } } else { if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool))) { gimp_tool_pop_status (tool, display); gimp_color_tool_disable (GIMP_COLOR_TOOL (tool)); } } } }
static void gimp_paint_tool_cursor_update (GimpTool *tool, const GimpCoords *coords, GdkModifierType state, GimpDisplay *display) { GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool); GimpCursorModifier modifier; GimpCursorModifier toggle_modifier; GimpCursorModifier old_modifier; GimpCursorModifier old_toggle_modifier; modifier = tool->control->cursor_modifier; toggle_modifier = tool->control->toggle_cursor_modifier; old_modifier = modifier; old_toggle_modifier = toggle_modifier; if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool))) { GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable)) || gimp_item_is_content_locked (GIMP_ITEM (drawable)) || ! gimp_item_is_visible (GIMP_ITEM (drawable))) { modifier = GIMP_CURSOR_MODIFIER_BAD; toggle_modifier = GIMP_CURSOR_MODIFIER_BAD; } if (! paint_tool->show_cursor && modifier != GIMP_CURSOR_MODIFIER_BAD) { gimp_tool_set_cursor (tool, display, GIMP_CURSOR_NONE, GIMP_TOOL_CURSOR_NONE, GIMP_CURSOR_MODIFIER_NONE); return; } gimp_tool_control_set_cursor_modifier (tool->control, modifier); gimp_tool_control_set_toggle_cursor_modifier (tool->control, toggle_modifier); } GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display); /* reset old stuff here so we are not interferring with the modifiers * set by our subclasses */ gimp_tool_control_set_cursor_modifier (tool->control, old_modifier); gimp_tool_control_set_toggle_cursor_modifier (tool->control, old_toggle_modifier); }
static void gimp_paint_tool_motion (GimpTool *tool, const GimpCoords *coords, guint32 time, GdkModifierType state, GimpDisplay *display) { GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool); GimpPaintOptions *paint_options = GIMP_PAINT_TOOL_GET_OPTIONS (tool); GimpPaintCore *core = paint_tool->core; GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); GimpCoords curr_coords; gint off_x, off_y; GIMP_TOOL_CLASS (parent_class)->motion (tool, coords, time, state, display); if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool))) return; curr_coords = *coords; gimp_paint_core_smooth_coords (core, paint_options, &curr_coords); gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y); curr_coords.x -= off_x; curr_coords.y -= off_y; /* don't paint while the Shift key is pressed for line drawing */ if (paint_tool->draw_line) { gimp_paint_core_set_current_coords (core, &curr_coords); return; } gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool)); gimp_paint_core_interpolate (core, drawable, paint_options, &curr_coords, time); gimp_projection_flush_now (gimp_image_get_projection (image)); gimp_display_flush_now (display); gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool)); }
static void gimp_paint_tool_button_release (GimpTool *tool, const GimpCoords *coords, guint32 time, GdkModifierType state, GimpButtonReleaseType release_type, GimpDisplay *display) { GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool); GimpPaintOptions *paint_options = GIMP_PAINT_TOOL_GET_OPTIONS (tool); GimpPaintCore *core = paint_tool->core; GimpDisplayShell *shell = gimp_display_get_shell (display); GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool))) { GIMP_TOOL_CLASS (parent_class)->button_release (tool, coords, time, state, release_type, display); return; } gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool)); /* Let the specific painting function finish up */ gimp_paint_core_paint (core, drawable, paint_options, GIMP_PAINT_STATE_FINISH, time); /* resume the current selection */ gimp_display_shell_selection_resume (shell); /* chain up to halt the tool */ GIMP_TOOL_CLASS (parent_class)->button_release (tool, coords, time, state, release_type, display); if (release_type == GIMP_BUTTON_RELEASE_CANCEL) gimp_paint_core_cancel (core, drawable); else gimp_paint_core_finish (core, drawable, TRUE); gimp_image_flush (image); gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool)); }
static void gimp_brush_tool_oper_update (GimpTool *tool, const GimpCoords *coords, GdkModifierType state, gboolean proximity, GimpDisplay *display) { GimpPaintOptions *paint_options = GIMP_PAINT_TOOL_GET_OPTIONS (tool); GimpDrawable *drawable; gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool)); GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, proximity, display); drawable = gimp_image_get_active_drawable (gimp_display_get_image (display)); if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool)) && drawable && proximity) { GimpContext *context = GIMP_CONTEXT (paint_options); GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool); GimpBrushCore *brush_core = GIMP_BRUSH_CORE (paint_tool->core); gimp_brush_core_set_brush (brush_core, gimp_context_get_brush (context)); gimp_brush_core_set_dynamics (brush_core, gimp_context_get_dynamics (context)); if (GIMP_BRUSH_CORE_GET_CLASS (brush_core)->handles_transforming_brush) { gimp_brush_core_eval_transform_dynamics (brush_core, drawable, paint_options, coords); } } gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool)); }
static void gimp_brush_tool_cursor_update (GimpTool *tool, const GimpCoords *coords, GdkModifierType state, GimpDisplay *display) { GimpBrushTool *brush_tool = GIMP_BRUSH_TOOL (tool); GimpBrushCore *brush_core = GIMP_BRUSH_CORE (GIMP_PAINT_TOOL (brush_tool)->core); if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool))) { if (! brush_core->main_brush || ! brush_core->dynamics) { gimp_tool_set_cursor (tool, display, gimp_tool_control_get_cursor (tool->control), gimp_tool_control_get_tool_cursor (tool->control), GIMP_CURSOR_MODIFIER_BAD); return; } } GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display); }
static void gimp_paint_tool_draw (GimpDrawTool *draw_tool) { if (! gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (draw_tool))) { GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (draw_tool); GimpPaintCore *core = paint_tool->core; GimpImage *image = gimp_display_get_image (draw_tool->display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); GimpCanvasItem *outline = NULL; gboolean line_drawn = FALSE; gdouble last_x, last_y; gdouble cur_x, cur_y; gint off_x, off_y; gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y); last_x = core->last_coords.x + off_x; last_y = core->last_coords.y + off_y; cur_x = core->cur_coords.x + off_x; cur_y = core->cur_coords.y + off_y; if (paint_tool->draw_line && ! gimp_tool_control_is_active (GIMP_TOOL (draw_tool)->control)) { GimpCanvasGroup *group; group = gimp_draw_tool_add_stroke_group (draw_tool); gimp_draw_tool_push_group (draw_tool, group); gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_CIRCLE, last_x, last_y, GIMP_TOOL_HANDLE_SIZE_CIRCLE, GIMP_TOOL_HANDLE_SIZE_CIRCLE, GIMP_HANDLE_ANCHOR_CENTER); gimp_draw_tool_add_line (draw_tool, last_x, last_y, cur_x, cur_y); gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_CIRCLE, cur_x, cur_y, GIMP_TOOL_HANDLE_SIZE_CIRCLE, GIMP_TOOL_HANDLE_SIZE_CIRCLE, GIMP_HANDLE_ANCHOR_CENTER); gimp_draw_tool_pop_group (draw_tool); line_drawn = TRUE; } gimp_paint_tool_set_draw_fallback (paint_tool, FALSE, 0.0); if (paint_tool->draw_brush) outline = gimp_paint_tool_get_outline (paint_tool, draw_tool->display, cur_x, cur_y); if (outline) { gimp_draw_tool_add_item (draw_tool, outline); g_object_unref (outline); } else if (paint_tool->draw_fallback) { /* Lets make a sensible fallback cursor * * Sensible cursor is * * crossed to indicate draw point * * reactive to options alterations * * not a full circle that would be in the way */ gint size = (gint) paint_tool->fallback_size; #define TICKMARK_ANGLE 48 #define ROTATION_ANGLE G_PI / 4 /* marks for indicating full size */ gimp_draw_tool_add_arc (draw_tool, FALSE, cur_x - (size / 2.0), cur_y - (size / 2.0), size, size, ROTATION_ANGLE - (2.0 * G_PI) / (TICKMARK_ANGLE * 2), (2.0 * G_PI) / TICKMARK_ANGLE); gimp_draw_tool_add_arc (draw_tool, FALSE, cur_x - (size / 2.0), cur_y - (size / 2.0), size, size, ROTATION_ANGLE + G_PI / 2 - (2.0 * G_PI) / (TICKMARK_ANGLE * 2), (2.0 * G_PI) / TICKMARK_ANGLE); gimp_draw_tool_add_arc (draw_tool, FALSE, cur_x - (size / 2.0), cur_y - (size / 2.0), size, size, ROTATION_ANGLE + G_PI - (2.0 * G_PI) / (TICKMARK_ANGLE * 2), (2.0 * G_PI) / TICKMARK_ANGLE); gimp_draw_tool_add_arc (draw_tool, FALSE, cur_x - (size / 2.0), cur_y - (size / 2.0), size, size, ROTATION_ANGLE + 3 * G_PI / 2 - (2.0 * G_PI) / (TICKMARK_ANGLE * 2), (2.0 * G_PI) / TICKMARK_ANGLE); } else if (paint_tool->draw_circle) { gint size = (gint) paint_tool->circle_size; /* draw an indicatory circle */ gimp_draw_tool_add_arc (draw_tool, FALSE, cur_x - (size / 2.0), cur_y - (size / 2.0), size, size, 0.0, (2.0 * G_PI)); } if (! outline && ! line_drawn && ! paint_tool->show_cursor && ! paint_tool->draw_circle) { /* don't leave the user without any indication and draw * a fallback crosshair */ gimp_draw_tool_add_handle (draw_tool, GIMP_HANDLE_CROSSHAIR, cur_x, cur_y, GIMP_TOOL_HANDLE_SIZE_CROSSHAIR, GIMP_TOOL_HANDLE_SIZE_CROSSHAIR, GIMP_HANDLE_ANCHOR_CENTER); } } GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool); }
static void gimp_paint_tool_oper_update (GimpTool *tool, const GimpCoords *coords, GdkModifierType state, gboolean proximity, GimpDisplay *display) { GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool); GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool); GimpPaintOptions *paint_options = GIMP_PAINT_TOOL_GET_OPTIONS (tool); GimpPaintCore *core = paint_tool->core; GimpDisplayShell *shell = gimp_display_get_shell (display); GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool))) { GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, proximity, display); return; } gimp_draw_tool_pause (draw_tool); if (gimp_draw_tool_is_active (draw_tool) && draw_tool->display != display) gimp_draw_tool_stop (draw_tool); gimp_tool_pop_status (tool, display); if (tool->display && tool->display != display && gimp_display_get_image (tool->display) == image) { /* if this is a different display, but the same image, HACK around * in tool internals AFTER stopping the current draw_tool, so * straight line drawing works across different views of the * same image. */ tool->display = display; } if (drawable && proximity) { gboolean constrain_mask = gimp_get_constrain_behavior_mask (); gint off_x, off_y; core->cur_coords = *coords; gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y); core->cur_coords.x -= off_x; core->cur_coords.y -= off_y; if (display == tool->display && (state & GIMP_PAINT_TOOL_LINE_MASK)) { /* If shift is down and this is not the first paint stroke, * draw a line. */ gchar *status_help; gdouble dx, dy, dist; gimp_paint_core_round_line (core, paint_options, (state & constrain_mask) != 0); dx = core->cur_coords.x - core->last_coords.x; dy = core->cur_coords.y - core->last_coords.y; status_help = gimp_suggest_modifiers (paint_tool->status_line, constrain_mask & ~state, NULL, _("%s for constrained angles"), NULL); /* show distance in statusbar */ if (shell->unit == GIMP_UNIT_PIXEL) { dist = sqrt (SQR (dx) + SQR (dy)); gimp_tool_push_status (tool, display, "%.1f %s. %s", dist, _("pixels"), status_help); } else { gdouble xres; gdouble yres; gchar format_str[64]; gimp_image_get_resolution (image, &xres, &yres); g_snprintf (format_str, sizeof (format_str), "%%.%df %s. %%s", gimp_unit_get_digits (shell->unit), gimp_unit_get_symbol (shell->unit)); dist = (gimp_unit_get_factor (shell->unit) * sqrt (SQR (dx / xres) + SQR (dy / yres))); gimp_tool_push_status (tool, display, format_str, dist, status_help); } g_free (status_help); paint_tool->draw_line = TRUE; } else { gchar *status; GdkModifierType modifiers = 0; /* HACK: A paint tool may set status_ctrl to NULL to indicate that * it ignores the Ctrl modifier (temporarily or permanently), so * it should not be suggested. This is different from how * gimp_suggest_modifiers() would interpret this parameter. */ if (paint_tool->status_ctrl != NULL) modifiers |= constrain_mask; /* suggest drawing lines only after the first point is set */ if (display == tool->display) modifiers |= GIMP_PAINT_TOOL_LINE_MASK; status = gimp_suggest_modifiers (paint_tool->status, modifiers & ~state, _("%s for a straight line"), paint_tool->status_ctrl, NULL); gimp_tool_push_status (tool, display, "%s", status); g_free (status); paint_tool->draw_line = FALSE; } if (! gimp_draw_tool_is_active (draw_tool)) gimp_draw_tool_start (draw_tool, display); } else if (gimp_draw_tool_is_active (draw_tool)) { gimp_draw_tool_stop (draw_tool); } GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, proximity, display); gimp_draw_tool_resume (draw_tool); }
static void gimp_paint_tool_button_press (GimpTool *tool, const GimpCoords *coords, guint32 time, GdkModifierType state, GimpButtonPressType press_type, GimpDisplay *display) { GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool); GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool); GimpPaintOptions *paint_options = GIMP_PAINT_TOOL_GET_OPTIONS (tool); GimpPaintCore *core = paint_tool->core; GimpDisplayShell *shell = gimp_display_get_shell (display); GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); GimpCoords curr_coords; gint off_x, off_y; GError *error = NULL; if (gimp_color_tool_is_enabled (GIMP_COLOR_TOOL (tool))) { GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state, press_type, display); return; } if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable))) { gimp_tool_message_literal (tool, display, _("Cannot paint on layer groups.")); return; } if (gimp_item_is_content_locked (GIMP_ITEM (drawable))) { gimp_tool_message_literal (tool, display, _("The active layer's pixels are locked.")); return; } if (! gimp_item_is_visible (GIMP_ITEM (drawable))) { gimp_tool_message_literal (tool, display, _("The active layer is not visible.")); return; } curr_coords = *coords; gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y); curr_coords.x -= off_x; curr_coords.y -= off_y; if (gimp_draw_tool_is_active (draw_tool)) gimp_draw_tool_stop (draw_tool); if (tool->display && tool->display != display && gimp_display_get_image (tool->display) == image) { /* if this is a different display, but the same image, HACK around * in tool internals AFTER stopping the current draw_tool, so * straight line drawing works across different views of the * same image. */ tool->display = display; } if (! gimp_paint_core_start (core, drawable, paint_options, &curr_coords, &error)) { gimp_tool_message_literal (tool, display, error->message); g_clear_error (&error); return; } if ((display != tool->display) || ! paint_tool->draw_line) { /* if this is a new display, resest the "last stroke's endpoint" * because there is none */ if (display != tool->display) core->start_coords = core->cur_coords; core->last_coords = core->cur_coords; core->distance = 0.0; core->pixel_dist = 0.0; } else if (paint_tool->draw_line) { gboolean constrain = (state & gimp_get_constrain_behavior_mask ()) != 0; /* If shift is down and this is not the first paint * stroke, then draw a line from the last coords to the pointer */ gimp_paint_core_round_line (core, paint_options, constrain); } /* chain up to activate the tool */ GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state, press_type, display); /* pause the current selection */ gimp_display_shell_selection_pause (shell); /* Let the specific painting function initialize itself */ gimp_paint_core_paint (core, drawable, paint_options, GIMP_PAINT_STATE_INIT, time); /* Paint to the image */ if (paint_tool->draw_line) { gimp_paint_core_interpolate (core, drawable, paint_options, &core->cur_coords, time); } else { gimp_paint_core_paint (core, drawable, paint_options, GIMP_PAINT_STATE_MOTION, time); } gimp_projection_flush_now (gimp_image_get_projection (image)); gimp_display_flush_now (display); gimp_draw_tool_start (draw_tool, display); }