static void gimp_color_tool_button_press (GimpTool *tool, const GimpCoords *coords, guint32 time, GdkModifierType state, GimpButtonPressType press_type, GimpDisplay *display) { GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool); GimpDisplayShell *shell = gimp_display_get_shell (display); /* Chain up to activate the tool */ GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state, press_type, display); if (! color_tool->enabled) return; if (color_tool->sample_point) { color_tool->moving_sample_point = TRUE; gimp_sample_point_get_position (color_tool->sample_point, &color_tool->sample_point_x, &color_tool->sample_point_y); gimp_tool_control_set_scroll_lock (tool->control, TRUE); gimp_display_shell_selection_pause (shell); if (! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tool))) gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display); gimp_tool_push_status_coords (tool, display, gimp_tool_control_get_precision (tool->control), _("Move Sample Point: "), color_tool->sample_point_x, ", ", color_tool->sample_point_y, NULL); } else { color_tool->center_x = coords->x; color_tool->center_y = coords->y; gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display); gimp_color_tool_pick (color_tool, GIMP_COLOR_PICK_STATE_START, coords->x, coords->y); } }
static void gimp_color_tool_button_press (GimpTool *tool, GimpCoords *coords, guint32 time, GdkModifierType state, GimpDisplay *display) { GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool); GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (display->shell); /* Chain up to activate the tool */ GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state, display); if (! color_tool->enabled) return; if (color_tool->sample_point) { color_tool->moving_sample_point = TRUE; color_tool->sample_point_x = color_tool->sample_point->x; color_tool->sample_point_y = color_tool->sample_point->y; gimp_display_shell_selection_control (shell, GIMP_SELECTION_PAUSE); gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display); gimp_tool_push_status_coords (tool, display, _("Move Sample Point: "), color_tool->sample_point_x, ", ", color_tool->sample_point_y, NULL); } else { gint off_x, off_y; /* Keep the coordinates of the target */ gimp_item_offsets (GIMP_ITEM (tool->drawable), &off_x, &off_y); color_tool->center_x = coords->x - off_x; color_tool->center_y = coords->y - off_y; gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display); gimp_color_tool_pick (color_tool, GIMP_COLOR_PICK_STATE_NEW, coords->x, coords->y); } }
static void gimp_align_tool_button_press (GimpTool *tool, GimpCoords *coords, guint32 time, GdkModifierType state, GimpDisplay *display) { GimpAlignTool *align_tool = GIMP_ALIGN_TOOL (tool); gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool)); /* If the tool was being used in another image... reset it */ if (display != tool->display) { if (gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tool))) gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool)); gimp_tool_pop_status (tool, display); clear_all_selected_objects (align_tool); } if (! gimp_tool_control_is_active (tool->control)) gimp_tool_control_activate (tool->control); tool->display = display; align_tool->x1 = align_tool->x0 = coords->x; align_tool->y1 = align_tool->y0 = coords->y; if (! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tool))) gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display); gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool)); }
void gimp_color_tool_start_sample_point (GimpTool *tool, GimpDisplay *display) { GimpColorTool *color_tool; g_return_if_fail (GIMP_IS_COLOR_TOOL (tool)); g_return_if_fail (GIMP_IS_DISPLAY (display)); color_tool = GIMP_COLOR_TOOL (tool); gimp_display_shell_selection_pause (gimp_display_get_shell (display)); tool->display = display; gimp_tool_control_activate (tool->control); gimp_tool_control_set_scroll_lock (tool->control, TRUE); if (gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tool))) gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool)); color_tool->sample_point = NULL; color_tool->moving_sample_point = TRUE; color_tool->sample_point_x = SAMPLE_POINT_POSITION_INVALID; color_tool->sample_point_y = SAMPLE_POINT_POSITION_INVALID; gimp_tool_set_cursor (tool, display, GIMP_CURSOR_MOUSE, GIMP_TOOL_CURSOR_COLOR_PICKER, GIMP_CURSOR_MODIFIER_MOVE); gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display); }
static void gimp_warp_tool_oper_update (GimpTool *tool, const GimpCoords *coords, GdkModifierType state, gboolean proximity, GimpDisplay *display) { GimpWarpTool *wt = GIMP_WARP_TOOL (tool); GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool); if (proximity) { gimp_draw_tool_pause (draw_tool); if (! tool->display || display == tool->display) { wt->cursor_x = coords->x; wt->cursor_y = coords->y; } if (! gimp_draw_tool_is_active (draw_tool)) gimp_draw_tool_start (draw_tool, display); gimp_draw_tool_resume (draw_tool); } else if (gimp_draw_tool_is_active (draw_tool)) { gimp_draw_tool_stop (draw_tool); } }
static void gimp_warp_tool_start (GimpWarpTool *wt, GimpDisplay *display) { GimpTool *tool = GIMP_TOOL (wt); GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); const Babl *format; GeglRectangle bbox; tool->display = display; tool->drawable = drawable; /* Create the coords buffer, with the size of the selection */ format = babl_format_n (babl_type ("float"), 2); gimp_item_mask_intersect (GIMP_ITEM (drawable), &bbox.x, &bbox.y, &bbox.width, &bbox.height); #ifdef WARP_DEBUG g_printerr ("Initialize coordinate buffer (%d,%d) at %d,%d\n", bbox.width, bbox.height, bbox.x, bbox.y); #endif wt->coords_buffer = gegl_buffer_new (&bbox, format); gimp_warp_tool_create_image_map (wt, drawable); if (! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (wt))) gimp_draw_tool_start (GIMP_DRAW_TOOL (wt), display); }
void gimp_color_tool_start_sample_point (GimpTool *tool, GimpDisplay *display) { GimpColorTool *color_tool; g_return_if_fail (GIMP_IS_COLOR_TOOL (tool)); g_return_if_fail (GIMP_IS_DISPLAY (display)); color_tool = GIMP_COLOR_TOOL (tool); gimp_display_shell_selection_control (GIMP_DISPLAY_SHELL (display->shell), GIMP_SELECTION_PAUSE); tool->display = display; gimp_tool_control_activate (tool->control); if (color_tool->sample_point) gimp_display_shell_draw_sample_point (GIMP_DISPLAY_SHELL (display->shell), color_tool->sample_point, FALSE); color_tool->sample_point = NULL; color_tool->moving_sample_point = TRUE; color_tool->sample_point_x = -1; color_tool->sample_point_y = -1; gimp_tool_set_cursor (tool, display, GIMP_CURSOR_MOUSE, GIMP_TOOL_CURSOR_COLOR_PICKER, GIMP_CURSOR_MODIFIER_MOVE); gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display); }
static void gimp_align_tool_button_press (GimpTool *tool, const GimpCoords *coords, guint32 time, GdkModifierType state, GimpButtonPressType press_type, GimpDisplay *display) { GimpAlignTool *align_tool = GIMP_ALIGN_TOOL (tool); gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool)); /* If the tool was being used in another image... reset it */ if (display != tool->display) gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display); tool->display = display; gimp_tool_control_activate (tool->control); align_tool->x2 = align_tool->x1 = coords->x; align_tool->y2 = align_tool->y1 = coords->y; if (! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tool))) gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display); gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool)); }
static void gimp_move_tool_start_guide (GimpMoveTool *move, GimpDisplay *display, GimpOrientationType orientation) { GimpTool *tool = GIMP_TOOL (move); gimp_display_shell_selection_pause (gimp_display_get_shell (display)); tool->display = display; gimp_tool_control_activate (tool->control); gimp_tool_control_set_scroll_lock (tool->control, TRUE); if (gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tool))) gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool)); move->guide = NULL; move->moving_guide = TRUE; move->guide_position = GUIDE_POSITION_INVALID; move->guide_orientation = orientation; gimp_tool_set_cursor (tool, display, GIMP_CURSOR_MOUSE, GIMP_TOOL_CURSOR_HAND, GIMP_CURSOR_MODIFIER_MOVE); gimp_draw_tool_start (GIMP_DRAW_TOOL (move), display); }
static void gimp_region_select_tool_button_press (GimpTool *tool, GimpCoords *coords, guint32 time, GdkModifierType state, GimpDisplay *display) { GimpRegionSelectTool *region_sel = GIMP_REGION_SELECT_TOOL (tool); GimpRegionSelectOptions *options = GIMP_REGION_SELECT_TOOL_GET_OPTIONS (tool); region_sel->x = coords->x; region_sel->y = coords->y; region_sel->saved_threshold = options->threshold; gimp_tool_control_activate (tool->control); tool->display = display; if (gimp_selection_tool_start_edit (GIMP_SELECTION_TOOL (region_sel), coords)) return; gimp_tool_push_status (tool, display, _("Move the mouse to change threshold")); /* calculate the region boundary */ region_sel->segs = gimp_region_select_tool_calculate (region_sel, display, ®ion_sel->num_segs); gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display); }
static void gimp_blend_tool_start_preview (GimpBlendTool *blend_tool, GimpDisplay *display) { GimpTool *tool = GIMP_TOOL (blend_tool); GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); GimpBlendOptions *options = GIMP_BLEND_TOOL_GET_OPTIONS (blend_tool); GimpContext *context = GIMP_CONTEXT (options); tool->display = display; tool->drawable = drawable; if (blend_tool->grabbed_point != POINT_FILL_MODE) { gimp_blend_tool_create_image_map (blend_tool, drawable); /* Initially sync all of the properties */ gimp_gegl_config_proxy_sync (GIMP_OBJECT (options), blend_tool->render_node); /* Connect signal handlers for the gradient */ gimp_blend_tool_set_gradient (blend_tool, context->gradient); } if (! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (blend_tool))) gimp_draw_tool_start (GIMP_DRAW_TOOL (blend_tool), display); }
static void gimp_cage_tool_start (GimpCageTool *ct, GimpDisplay *display) { GimpTool *tool = GIMP_TOOL (ct); GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); gint off_x; gint off_y; gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display); tool->display = display; if (ct->config) { g_object_unref (ct->config); ct->config = NULL; } if (ct->coef) { g_object_unref (ct->coef); ct->dirty_coef = TRUE; ct->coef = NULL; } if (ct->image_map) { gimp_image_map_abort (ct->image_map); g_object_unref (ct->image_map); ct->image_map = NULL; } if (ct->render_node) { g_object_unref (ct->render_node); ct->render_node = NULL; ct->coef_node = NULL; ct->cage_node = NULL; } ct->config = g_object_new (GIMP_TYPE_CAGE_CONFIG, NULL); ct->hovering_handle = -1; ct->hovering_edge = -1; ct->cage_complete = FALSE; ct->tool_state = CAGE_STATE_INIT; /* Setting up cage offset to convert the cage point coords to * drawable coords */ gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y); ct->offset_x = off_x; ct->offset_y = off_y; gimp_draw_tool_start (GIMP_DRAW_TOOL (ct), display); }
static void gimp_flip_tool_oper_update (GimpTool *tool, const GimpCoords *coords, GdkModifierType state, gboolean proximity, GimpDisplay *display) { GimpFlipTool *flip = GIMP_FLIP_TOOL (tool); GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool); GimpFlipOptions *options = GIMP_FLIP_TOOL_GET_OPTIONS (tool); GimpDisplayShell *shell = gimp_display_get_shell (display); GimpImage *image = gimp_display_get_image (display); GimpGuide *guide = NULL; if (gimp_display_shell_get_show_guides (shell) && proximity) { gint snap_distance = display->config->snap_distance; guide = gimp_image_pick_guide (image, coords->x, coords->y, FUNSCALEX (shell, snap_distance), FUNSCALEY (shell, snap_distance)); } if (flip->guide != guide || (guide && ! gimp_draw_tool_is_active (draw_tool))) { gimp_draw_tool_pause (draw_tool); if (gimp_draw_tool_is_active (draw_tool) && draw_tool->display != display) gimp_draw_tool_stop (draw_tool); flip->guide = guide; if (! gimp_draw_tool_is_active (draw_tool)) gimp_draw_tool_start (draw_tool, display); gimp_draw_tool_resume (draw_tool); } gtk_widget_set_sensitive (options->direction_frame, guide == NULL); GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, proximity, display); }
static void gimp_perspective_clone_tool_options_notify (GimpTool *tool, GimpToolOptions *options, const GParamSpec *pspec) { GimpPerspectiveCloneTool *clone_tool = GIMP_PERSPECTIVE_CLONE_TOOL (tool); GimpPaintTool *paint_tool = GIMP_PAINT_TOOL (tool); GimpPerspectiveCloneOptions *clone_options; clone_options = GIMP_PERSPECTIVE_CLONE_OPTIONS (options); GIMP_TOOL_CLASS (parent_class)->options_notify (tool, options, pspec); if (! strcmp (pspec->name, "clone-mode")) { GimpPerspectiveClone *clone; clone = GIMP_PERSPECTIVE_CLONE (GIMP_PAINT_TOOL (tool)->core); gimp_draw_tool_pause (GIMP_DRAW_TOOL (clone_tool)); if (clone_options->clone_mode == GIMP_PERSPECTIVE_CLONE_MODE_PAINT) { gimp_perspective_clone_set_transform (clone, &clone_tool->transform); gimp_paint_tool_set_active (paint_tool, TRUE); } else { gimp_paint_tool_set_active (paint_tool, FALSE); gimp_tool_control_set_precision (tool->control, GIMP_CURSOR_PRECISION_SUBPIXEL); /* start drawing the bounding box and handles... */ if (tool->display && ! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (clone_tool))) { gimp_draw_tool_start (GIMP_DRAW_TOOL (clone_tool), tool->display); } } gimp_draw_tool_resume (GIMP_DRAW_TOOL (clone_tool)); } }
static void gimp_color_tool_oper_update (GimpTool *tool, const GimpCoords *coords, GdkModifierType state, gboolean proximity, GimpDisplay *display) { GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool); GimpDisplayShell *shell = gimp_display_get_shell (display); GimpImage *image = gimp_display_get_image (display); GimpSamplePoint *sample_point = NULL; if (color_tool->enabled && gimp_display_shell_get_show_sample_points (shell) && proximity) { gint snap_distance = display->config->snap_distance; sample_point = gimp_image_find_sample_point (image, coords->x, coords->y, FUNSCALEX (shell, snap_distance), FUNSCALEY (shell, snap_distance)); } if (color_tool->sample_point != sample_point) { GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool); gimp_draw_tool_pause (draw_tool); if (gimp_draw_tool_is_active (draw_tool) && draw_tool->display != display) gimp_draw_tool_stop (draw_tool); color_tool->sample_point = sample_point; if (! gimp_draw_tool_is_active (draw_tool)) gimp_draw_tool_start (draw_tool, display); gimp_draw_tool_resume (draw_tool); } }
static void gimp_move_tool_oper_update (GimpTool *tool, const GimpCoords *coords, GdkModifierType state, gboolean proximity, GimpDisplay *display) { GimpMoveTool *move = GIMP_MOVE_TOOL (tool); GimpMoveOptions *options = GIMP_MOVE_TOOL_GET_OPTIONS (tool); GimpDisplayShell *shell = gimp_display_get_shell (display); GimpImage *image = gimp_display_get_image (display); GimpGuide *guide = NULL; if (options->move_type == GIMP_TRANSFORM_TYPE_LAYER && ! options->move_current && gimp_display_shell_get_show_guides (shell) && proximity) { const gint snap_distance = display->config->snap_distance; guide = gimp_image_find_guide (image, coords->x, coords->y, FUNSCALEX (shell, snap_distance), FUNSCALEY (shell, snap_distance)); } if (move->guide != guide) { GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool); gimp_draw_tool_pause (draw_tool); if (gimp_draw_tool_is_active (draw_tool) && draw_tool->display != display) gimp_draw_tool_stop (draw_tool); move->guide = guide; if (! gimp_draw_tool_is_active (draw_tool)) gimp_draw_tool_start (draw_tool, display); gimp_draw_tool_resume (draw_tool); } }
static void gimp_foreground_select_tool_button_press (GimpTool *tool, const GimpCoords *coords, guint32 time, GdkModifierType state, GimpButtonPressType press_type, GimpDisplay *display) { GimpForegroundSelectTool *fg_select = GIMP_FOREGROUND_SELECT_TOOL (tool); GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool); if ((fg_select->state == MATTING_STATE_PAINT_TRIMAP) || (fg_select->state == MATTING_STATE_PREVIEW_MASK)) { GimpVector2 point = gimp_vector2_new (coords->x, coords->y); 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_control_activate (tool->control); fg_select->last_coords = *coords; g_return_if_fail (fg_select->stroke == NULL); fg_select->stroke = g_array_new (FALSE, FALSE, sizeof (GimpVector2)); g_array_append_val (fg_select->stroke, point); if (!gimp_draw_tool_is_active (draw_tool)) gimp_draw_tool_start (draw_tool, display); gimp_draw_tool_resume (draw_tool); } else if (fg_select->state == MATTING_STATE_FREE_SELECT) { GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state, press_type, display); } }
/** * gimp_seamless_clone_tool_start: * @sc: The GimpSeamlessCloneTool to initialize for usage on the given * display * @display: The display to initialize the tool for * * A utility function to initialize a tool for working on a given * display. At the beginning of each function, we can check if the event's * display is the same as the tool's one, and if not call this. This is * not required by the gimptool interface or anything like that, but * this is a convenient way to do all the initialization work in one * place, and this is how the base class (GimpDrawTool) does that */ static void gimp_seamless_clone_tool_start (GimpSeamlessCloneTool *sc, GimpDisplay *display) { GimpTool *tool = GIMP_TOOL (sc); GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); /* First handle the paste - we need to make sure we have one in order * to do anything else. */ if (sc->paste == NULL) { GimpBuffer *buffer = gimp_clipboard_get_buffer (tool->tool_info->gimp); if (! buffer) { gimp_tool_push_status (tool, display, "%s", _("There is no image data in the clipboard to paste.")); return; } sc->paste = gegl_buffer_dup (gimp_buffer_get_buffer (buffer)); g_object_unref (buffer); sc->width = gegl_buffer_get_width (sc->paste); sc->height = gegl_buffer_get_height (sc->paste); } /* Free resources which are relevant only for the previous display */ gimp_seamless_clone_tool_stop (sc, TRUE); tool->display = display; gimp_seamless_clone_tool_create_filter (sc, drawable); gimp_draw_tool_start (GIMP_DRAW_TOOL (sc), display); sc->tool_state = SC_STATE_RENDER_WAIT; }
static void gimp_warp_tool_start (GimpWarpTool *wt, GimpDisplay *display) { GimpTool *tool = GIMP_TOOL (wt); GimpWarpOptions *options = GIMP_WARP_TOOL_GET_OPTIONS (wt); GimpImage *image = gimp_display_get_image (display); GimpDrawable *drawable = gimp_image_get_active_drawable (image); const Babl *format; GeglRectangle bbox; tool->display = display; tool->drawable = drawable; /* Create the coords buffer, with the size of the selection */ format = babl_format_n (babl_type ("float"), 2); gimp_item_mask_intersect (GIMP_ITEM (drawable), &bbox.x, &bbox.y, &bbox.width, &bbox.height); #ifdef WARP_DEBUG g_printerr ("Initialize coordinate buffer (%d,%d) at %d,%d\n", bbox.width, bbox.height, bbox.x, bbox.y); #endif wt->coords_buffer = gegl_buffer_new (&bbox, format); gimp_warp_tool_create_image_map (wt, drawable); if (! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (wt))) gimp_draw_tool_start (GIMP_DRAW_TOOL (wt), display); if (options->animate_button) { g_signal_connect_swapped (options->animate_button, "clicked", G_CALLBACK (gimp_warp_tool_animate), wt); gtk_widget_set_sensitive (options->animate_button, TRUE); } }
static void gimp_perspective_clone_tool_mode_notify (GimpPerspectiveCloneOptions *options, GParamSpec *pspec, GimpPerspectiveCloneTool *clone_tool) { GimpTool *tool = GIMP_TOOL (clone_tool); GimpPerspectiveClone *clone; clone = GIMP_PERSPECTIVE_CLONE (GIMP_PAINT_TOOL (clone_tool)->core); gimp_draw_tool_pause (GIMP_DRAW_TOOL (clone_tool)); if (options->clone_mode == GIMP_PERSPECTIVE_CLONE_MODE_PAINT) { /* GimpPaintTool's notify callback will set the right precision */ g_object_notify (G_OBJECT (options), "hard"); gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_CLONE); gimp_perspective_clone_set_transform (clone, &clone_tool->transform); } else { gimp_tool_control_set_precision (tool->control, GIMP_CURSOR_PRECISION_SUBPIXEL); gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_PERSPECTIVE); /* start drawing the bounding box and handles... */ if (tool->display && ! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (clone_tool))) { gimp_draw_tool_start (GIMP_DRAW_TOOL (clone_tool), tool->display); } } gimp_draw_tool_resume (GIMP_DRAW_TOOL (clone_tool)); }
static gboolean gimp_perspective_clone_tool_initialize (GimpTool *tool, GimpDisplay *display, GError **error) { GimpPerspectiveCloneTool *clone_tool = GIMP_PERSPECTIVE_CLONE_TOOL (tool); if (! GIMP_TOOL_CLASS (parent_class)->initialize (tool, display, error)) { return FALSE; } if (display != tool->display) { GimpImage *image = gimp_display_get_image (display); gint i; tool->display = display; tool->drawable = gimp_image_get_active_drawable (image); /* Find the transform bounds initializing */ gimp_perspective_clone_tool_bounds (clone_tool, display); gimp_perspective_clone_tool_prepare (clone_tool); /* Recalculate the transform tool */ gimp_perspective_clone_tool_recalc_matrix (clone_tool); /* start drawing the bounding box and handles... */ gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display); clone_tool->function = TRANSFORM_CREATING; /* Save the current transformation info */ for (i = 0; i < TRANS_INFO_SIZE; i++) clone_tool->old_trans_info[i] = clone_tool->trans_info[i]; } return TRUE; }
static void gimp_color_tool_button_press (GimpTool *tool, const GimpCoords *coords, guint32 time, GdkModifierType state, GimpButtonPressType press_type, GimpDisplay *display) { GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool); /* Chain up to activate the tool */ GIMP_TOOL_CLASS (parent_class)->button_press (tool, coords, time, state, press_type, display); if (! color_tool->enabled) return; if (color_tool->sample_point) { gimp_tool_control_halt (tool->control); gimp_sample_point_tool_start_edit (tool, display, color_tool->sample_point); } else { color_tool->center_x = coords->x; color_tool->center_y = coords->y; if (! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tool))) gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display); gimp_color_tool_pick (color_tool, GIMP_COLOR_PICK_STATE_START, coords->x, coords->y); } }
static void gimp_blend_tool_button_press (GimpTool *tool, const GimpCoords *coords, guint32 time, GdkModifierType state, GimpButtonPressType press_type, GimpDisplay *display) { GimpBlendTool *blend_tool = GIMP_BLEND_TOOL (tool); blend_tool->start_x = blend_tool->end_x = coords->x; blend_tool->start_y = blend_tool->end_y = coords->y; blend_tool->last_x = blend_tool->mouse_x = coords->x; blend_tool->last_y = blend_tool->mouse_y = coords->y; tool->display = display; gimp_tool_control_activate (tool->control); gimp_blend_tool_push_status (blend_tool, state, display); gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display); }
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); }
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_color_tool_button_release (GimpTool *tool, const GimpCoords *coords, guint32 time, GdkModifierType state, GimpButtonReleaseType release_type, GimpDisplay *display) { GimpColorTool *color_tool = GIMP_COLOR_TOOL (tool); GimpDisplayShell *shell = gimp_display_get_shell (display); /* Chain up to halt the tool */ GIMP_TOOL_CLASS (parent_class)->button_release (tool, coords, time, state, release_type, display); if (! color_tool->enabled) return; if (color_tool->moving_sample_point) { GimpImage *image = gimp_display_get_image (display); gint width = gimp_image_get_width (image); gint height = gimp_image_get_height (image); gimp_tool_pop_status (tool, display); gimp_tool_control_set_scroll_lock (tool->control, FALSE); gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool)); if (release_type == GIMP_BUTTON_RELEASE_CANCEL) { color_tool->moving_sample_point = FALSE; color_tool->sample_point_x = SAMPLE_POINT_POSITION_INVALID; color_tool->sample_point_y = SAMPLE_POINT_POSITION_INVALID; gimp_display_shell_selection_resume (shell); return; } if (color_tool->sample_point_x == SAMPLE_POINT_POSITION_INVALID || color_tool->sample_point_x < 0 || color_tool->sample_point_x >= width || color_tool->sample_point_y == SAMPLE_POINT_POSITION_INVALID || color_tool->sample_point_y < 0 || color_tool->sample_point_y >= height) { if (color_tool->sample_point) { gimp_image_remove_sample_point (image, color_tool->sample_point, TRUE); color_tool->sample_point = NULL; } } else { if (color_tool->sample_point) { gimp_image_move_sample_point (image, color_tool->sample_point, color_tool->sample_point_x, color_tool->sample_point_y, TRUE); } else { color_tool->sample_point = gimp_image_add_sample_point_at_pos (image, color_tool->sample_point_x, color_tool->sample_point_y, TRUE); } } gimp_display_shell_selection_resume (shell); gimp_image_flush (image); color_tool->moving_sample_point = FALSE; color_tool->sample_point_x = SAMPLE_POINT_POSITION_INVALID; color_tool->sample_point_y = SAMPLE_POINT_POSITION_INVALID; if (color_tool->sample_point) gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display); } else { gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool)); } }
static void gimp_n_point_deformation_tool_start (GimpNPointDeformationTool *npd_tool, GimpDisplay *display) { GimpTool *tool = GIMP_TOOL (npd_tool); GimpNPointDeformationOptions *npd_options; GimpImage *image; GeglBuffer *source_buffer; GeglBuffer *preview_buffer; NPDModel *model; npd_options = GIMP_N_POINT_DEFORMATION_TOOL_GET_OPTIONS (npd_tool); gimp_tool_control (tool, GIMP_TOOL_ACTION_HALT, display); image = gimp_display_get_image (display); tool->display = display; tool->drawable = gimp_image_get_active_drawable (image); npd_tool->active = TRUE; /* create GEGL graph */ source_buffer = gimp_drawable_get_buffer (tool->drawable); preview_buffer = gegl_buffer_new (gegl_buffer_get_extent (source_buffer), babl_format ("cairo-ARGB32")); npd_tool->graph = gegl_node_new (); npd_tool->source = gegl_node_new_child (npd_tool->graph, "operation", "gegl:buffer-source", "buffer", source_buffer, NULL); npd_tool->npd_node = gegl_node_new_child (npd_tool->graph, "operation", "gegl:npd", NULL); npd_tool->sink = gegl_node_new_child (npd_tool->graph, "operation", "gegl:write-buffer", "buffer", preview_buffer, NULL); gegl_node_link_many (npd_tool->source, npd_tool->npd_node, npd_tool->sink, NULL); /* initialize some options */ g_object_set (G_OBJECT (npd_options), "mesh-visible", TRUE, NULL); gimp_n_point_deformation_options_set_sensitivity (npd_options, TRUE); /* compute and get model */ gegl_node_process (npd_tool->npd_node); gegl_node_get (npd_tool->npd_node, "model", &model, NULL); npd_tool->model = model; npd_tool->preview_buffer = preview_buffer; npd_tool->selected_cp = NULL; npd_tool->hovering_cp = NULL; npd_tool->selected_cps = NULL; npd_tool->rubber_band = FALSE; npd_tool->lattice_points = g_new (GimpVector2, 5 * model->hidden_model->num_of_bones); gimp_item_get_offset (GIMP_ITEM (tool->drawable), &npd_tool->offset_x, &npd_tool->offset_y); gimp_npd_debug (("offset: %f %f\n", npd_tool->offset_x, npd_tool->offset_y)); gimp_draw_tool_start (GIMP_DRAW_TOOL (npd_tool), display); gimp_n_point_deformation_tool_perform_deformation (npd_tool); /* hide original image */ gimp_item_set_visible (GIMP_ITEM (tool->drawable), FALSE, FALSE); gimp_image_flush (image); /* create and start a deformation thread */ npd_tool->deform_thread = g_thread_new ("deform thread", (GThreadFunc) gimp_n_point_deformation_tool_deform_thread_func, npd_tool); /* create and start canvas update timeout */ npd_tool->draw_timeout_id = gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT_IDLE, GIMP_NPD_DRAW_INTERVAL, (GSourceFunc) gimp_n_point_deformation_tool_canvas_update_timeout, npd_tool, NULL); }
static void gimp_guide_tool_start (GimpTool *parent_tool, GimpDisplay *display, GimpGuide *guide, GimpOrientationType orientation) { GimpGuideTool *guide_tool; GimpTool *tool; guide_tool = g_object_new (GIMP_TYPE_GUIDE_TOOL, "tool-info", parent_tool->tool_info, NULL); tool = GIMP_TOOL (guide_tool); gimp_display_shell_selection_pause (gimp_display_get_shell (display)); if (guide) { guide_tool->guide = guide; guide_tool->guide_old_position = gimp_guide_get_position (guide); guide_tool->guide_position = gimp_guide_get_position (guide); guide_tool->guide_orientation = gimp_guide_get_orientation (guide); guide_tool->guide_custom = gimp_guide_is_custom (guide); } else { guide_tool->guide = NULL; guide_tool->guide_old_position = 0; guide_tool->guide_position = GIMP_GUIDE_POSITION_UNDEFINED; guide_tool->guide_orientation = orientation; guide_tool->guide_custom = FALSE; } gimp_tool_set_cursor (tool, display, GIMP_CURSOR_MOUSE, GIMP_TOOL_CURSOR_HAND, GIMP_CURSOR_MODIFIER_MOVE); tool_manager_push_tool (display->gimp, tool); tool->display = display; gimp_tool_control_activate (tool->control); gimp_draw_tool_start (GIMP_DRAW_TOOL (guide_tool), display); if (guide_tool->guide) { gimp_tool_push_status_length (tool, display, _("Move Guide: "), SWAP_ORIENT (guide_tool->guide_orientation), guide_tool->guide_position - guide_tool->guide_old_position, NULL); } else { gimp_tool_push_status_length (tool, display, _("Add Guide: "), SWAP_ORIENT (guide_tool->guide_orientation), guide_tool->guide_position, NULL); } }
static void gimp_move_tool_button_press (GimpTool *tool, const GimpCoords *coords, guint32 time, GdkModifierType state, GimpButtonPressType press_type, GimpDisplay *display) { GimpMoveTool *move = GIMP_MOVE_TOOL (tool); GimpMoveOptions *options = GIMP_MOVE_TOOL_GET_OPTIONS (tool); GimpDisplayShell *shell = gimp_display_get_shell (display); GimpImage *image = gimp_display_get_image (display); tool->display = display; move->floating_layer = NULL; move->guide = NULL; move->moving_guide = FALSE; move->old_active_layer = NULL; move->old_active_vectors = NULL; if (! options->move_current) { if (options->move_type == GIMP_TRANSFORM_TYPE_PATH) { GimpVectors *vectors; if (gimp_draw_tool_on_vectors (GIMP_DRAW_TOOL (tool), display, coords, 7, 7, NULL, NULL, NULL, NULL, NULL, &vectors)) { move->old_active_vectors = gimp_image_get_active_vectors (image); gimp_image_set_active_vectors (image, vectors); } else { /* no path picked */ return; } } else if (options->move_type == GIMP_TRANSFORM_TYPE_LAYER) { GimpGuide *guide; GimpLayer *layer; const gint snap_distance = display->config->snap_distance; if (gimp_display_shell_get_show_guides (shell) && (guide = gimp_image_find_guide (image, coords->x, coords->y, FUNSCALEX (shell, snap_distance), FUNSCALEY (shell, snap_distance)))) { move->guide = guide; move->moving_guide = TRUE; move->guide_position = gimp_guide_get_position (guide); move->guide_orientation = gimp_guide_get_orientation (guide); gimp_tool_control_set_scroll_lock (tool->control, TRUE); gimp_tool_control_set_precision (tool->control, GIMP_CURSOR_PRECISION_PIXEL_BORDER); gimp_tool_control_activate (tool->control); gimp_display_shell_selection_pause (shell); gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display); gimp_tool_push_status_length (tool, display, _("Move Guide: "), SWAP_ORIENT (move->guide_orientation), move->guide_position, NULL); return; } else if ((layer = gimp_image_pick_layer (image, coords->x, coords->y))) { if (gimp_image_get_floating_selection (image) && ! gimp_layer_is_floating_sel (layer)) { /* If there is a floating selection, and this aint it, * use the move tool to anchor it. */ move->floating_layer = gimp_image_get_floating_selection (image); gimp_tool_control_activate (tool->control); return; } else { move->old_active_layer = gimp_image_get_active_layer (image); gimp_image_set_active_layer (image, layer); } } else { /* no guide and no layer picked */ return; } } } switch (options->move_type) { case GIMP_TRANSFORM_TYPE_PATH: if (gimp_image_get_active_vectors (image)) gimp_edit_selection_tool_start (tool, display, coords, GIMP_TRANSLATE_MODE_VECTORS, TRUE); break; case GIMP_TRANSFORM_TYPE_SELECTION: if (! gimp_channel_is_empty (gimp_image_get_mask (image))) gimp_edit_selection_tool_start (tool, display, coords, GIMP_TRANSLATE_MODE_MASK, TRUE); break; case GIMP_TRANSFORM_TYPE_LAYER: { GimpDrawable *drawable = gimp_image_get_active_drawable (image); if (GIMP_IS_LAYER_MASK (drawable)) gimp_edit_selection_tool_start (tool, display, coords, GIMP_TRANSLATE_MODE_LAYER_MASK, TRUE); else if (GIMP_IS_CHANNEL (drawable)) gimp_edit_selection_tool_start (tool, display, coords, GIMP_TRANSLATE_MODE_CHANNEL, TRUE); else if (GIMP_IS_LAYER (drawable)) gimp_edit_selection_tool_start (tool, display, coords, GIMP_TRANSLATE_MODE_LAYER, TRUE); } break; } }
static void gimp_move_tool_button_release (GimpTool *tool, const GimpCoords *coords, guint32 time, GdkModifierType state, GimpButtonReleaseType release_type, GimpDisplay *display) { GimpMoveTool *move = GIMP_MOVE_TOOL (tool); GimpGuiConfig *config = GIMP_GUI_CONFIG (display->gimp->config); GimpDisplayShell *shell = gimp_display_get_shell (display); GimpImage *image = gimp_display_get_image (display); if (gimp_tool_control_is_active (tool->control)) gimp_tool_control_halt (tool->control); if (move->moving_guide) { gboolean delete_guide = FALSE; gint x, y, width, height; gimp_tool_pop_status (tool, display); gimp_tool_control_set_scroll_lock (tool->control, FALSE); gimp_tool_control_set_precision (tool->control, GIMP_CURSOR_PRECISION_PIXEL_CENTER); gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool)); if (release_type == GIMP_BUTTON_RELEASE_CANCEL) { move->moving_guide = FALSE; move->guide_position = GUIDE_POSITION_INVALID; move->guide_orientation = GIMP_ORIENTATION_UNKNOWN; gimp_display_shell_selection_resume (shell); return; } gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height); switch (move->guide_orientation) { case GIMP_ORIENTATION_HORIZONTAL: if ((move->guide_position < y) || (move->guide_position > (y + height))) delete_guide = TRUE; break; case GIMP_ORIENTATION_VERTICAL: if ((move->guide_position < x) || (move->guide_position > (x + width))) delete_guide = TRUE; break; default: break; } if (delete_guide) { if (move->guide) { gimp_image_remove_guide (image, move->guide, TRUE); move->guide = NULL; } } else { if (move->guide) { gimp_image_move_guide (image, move->guide, move->guide_position, TRUE); } else { switch (move->guide_orientation) { case GIMP_ORIENTATION_HORIZONTAL: move->guide = gimp_image_add_hguide (image, move->guide_position, TRUE); break; case GIMP_ORIENTATION_VERTICAL: move->guide = gimp_image_add_vguide (image, move->guide_position, TRUE); break; default: g_assert_not_reached (); } } } gimp_display_shell_selection_resume (shell); gimp_image_flush (image); move->moving_guide = FALSE; move->guide_position = GUIDE_POSITION_INVALID; move->guide_orientation = GIMP_ORIENTATION_UNKNOWN; if (move->guide) gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display); } else { gboolean flush = FALSE; if (! config->move_tool_changes_active || (release_type == GIMP_BUTTON_RELEASE_CANCEL)) { if (move->old_active_layer) { gimp_image_set_active_layer (image, move->old_active_layer); move->old_active_layer = NULL; flush = TRUE; } if (move->old_active_vectors) { gimp_image_set_active_vectors (image, move->old_active_vectors); move->old_active_vectors = NULL; flush = TRUE; } } if (release_type != GIMP_BUTTON_RELEASE_CANCEL) { if (move->floating_layer) { floating_sel_anchor (move->floating_layer); flush = TRUE; } } if (flush) gimp_image_flush (image); } }