static void gimp_move_tool_motion (GimpTool *tool, const GimpCoords *coords, guint32 time, GdkModifierType state, GimpDisplay *display) { GimpMoveTool *move = GIMP_MOVE_TOOL (tool); GimpDisplayShell *shell = gimp_display_get_shell (display); if (move->moving_guide) { gint tx, ty; gboolean delete_guide = FALSE; gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool)); gimp_display_shell_transform_xy (shell, coords->x, coords->y, &tx, &ty); if (tx < 0 || tx >= shell->disp_width || ty < 0 || ty >= shell->disp_height) { move->guide_position = GUIDE_POSITION_INVALID; delete_guide = TRUE; } else { gint x, y, width, height; if (move->guide_orientation == GIMP_ORIENTATION_HORIZONTAL) move->guide_position = RINT (coords->y); else move->guide_position = RINT (coords->x); 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; } } gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool)); gimp_tool_pop_status (tool, display); if (delete_guide) { gimp_tool_push_status (tool, display, move->guide ? _("Remove Guide") : _("Cancel Guide")); } else { gimp_tool_push_status_length (tool, display, move->guide ? _("Move Guide: ") : _("Add Guide: "), SWAP_ORIENT (move->guide_orientation), move->guide_position, 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_guide_tool_motion (GimpTool *tool, const GimpCoords *coords, guint32 time, GdkModifierType state, GimpDisplay *display) { GimpGuideTool *guide_tool = GIMP_GUIDE_TOOL (tool); GimpDisplayShell *shell = gimp_display_get_shell (display); GimpImage *image = gimp_display_get_image (display); gboolean delete_guide = FALSE; gint max_position; gint tx, ty; gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool)); gimp_display_shell_transform_xy (shell, coords->x, coords->y, &tx, &ty); if (guide_tool->guide_orientation == GIMP_ORIENTATION_HORIZONTAL) max_position = gimp_image_get_height (image); else max_position = gimp_image_get_width (image); if (tx < 0 || tx >= shell->disp_width || ty < 0 || ty >= shell->disp_height) { guide_tool->guide_position = GIMP_GUIDE_POSITION_UNDEFINED; delete_guide = TRUE; } else { if (guide_tool->guide_orientation == GIMP_ORIENTATION_HORIZONTAL) guide_tool->guide_position = RINT (coords->y); else guide_tool->guide_position = RINT (coords->x); if (guide_tool->guide_position < 0 || guide_tool->guide_position > max_position) { delete_guide = TRUE; } } gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool)); gimp_tool_pop_status (tool, display); /* custom guides are moved live */ if (guide_tool->guide_custom && guide_tool->guide_position != GIMP_GUIDE_POSITION_UNDEFINED) { gimp_image_move_guide (image, guide_tool->guide, CLAMP (guide_tool->guide_position, 0, max_position), TRUE); } if (delete_guide) { gimp_tool_push_status (tool, display, guide_tool->guide ? _("Remove Guide") : _("Cancel Guide")); } else 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); } }