1
1
/* GIMP - The GNU Image Manipulation Program
2
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
* This program is free software; you can redistribute it and/or modify
4
* This program is free software: you can redistribute it and/or modify
5
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
6
* the Free Software Foundation; either version 3 of the License, or
7
7
* (at your option) any later version.
9
9
* This program is distributed in the hope that it will be useful,
12
12
* GNU General Public License for more details.
14
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
18
#include "config.h"
21
20
#include <string.h>
23
23
#include <gtk/gtk.h>
24
#include <gdk/gdkkeysyms.h>
26
25
#include "libgimpmath/gimpmath.h"
27
26
#include "libgimpwidgets/gimpwidgets.h"
35
34
#include "core/gimpguide.h"
36
35
#include "core/gimpimage.h"
37
36
#include "core/gimpimage-guides.h"
37
#include "core/gimpimage-pick-layer.h"
38
38
#include "core/gimplayer.h"
39
39
#include "core/gimpimage-undo.h"
40
40
#include "core/gimplayermask.h"
41
41
#include "core/gimplayer-floating-sel.h"
42
#include "core/gimpitem.h"
43
42
#include "core/gimpundostack.h"
45
44
#include "widgets/gimphelp-ids.h"
45
#include "widgets/gimpwidgets-utils.h"
47
#include "display/gimpcanvasitem.h"
47
48
#include "display/gimpdisplay.h"
48
49
#include "display/gimpdisplayshell.h"
49
50
#include "display/gimpdisplayshell-appearance.h"
50
#include "display/gimpdisplayshell-draw.h"
51
51
#include "display/gimpdisplayshell-selection.h"
52
52
#include "display/gimpdisplayshell-transform.h"
67
69
/* local function prototypes */
69
static void gimp_move_tool_control (GimpTool *tool,
70
GimpToolAction action,
71
GimpDisplay *display);
72
71
static void gimp_move_tool_button_press (GimpTool *tool,
72
const GimpCoords *coords,
75
74
GdkModifierType state,
75
GimpButtonPressType press_type,
76
76
GimpDisplay *display);
77
77
static void gimp_move_tool_button_release (GimpTool *tool,
78
const GimpCoords *coords,
80
80
GdkModifierType state,
81
81
GimpButtonReleaseType release_type,
82
82
GimpDisplay *display);
83
83
static void gimp_move_tool_motion (GimpTool *tool,
84
const GimpCoords *coords,
86
86
GdkModifierType state,
87
87
GimpDisplay *display);
156
155
GimpTool *tool = GIMP_TOOL (move_tool);
157
gimp_tool_control_set_motion_mode (tool->control,
158
GIMP_MOTION_MODE_COMPRESS);
159
gimp_tool_control_set_snap_to (tool->control, FALSE);
160
gimp_tool_control_set_handle_empty_image (tool->control, TRUE);
161
gimp_tool_control_set_tool_cursor (tool->control,
162
GIMP_TOOL_CURSOR_MOVE);
158
164
move_tool->floating_layer = NULL;
159
165
move_tool->guide = NULL;
161
167
move_tool->moving_guide = FALSE;
162
move_tool->guide_position = -1;
168
move_tool->guide_position = GUIDE_POSITION_INVALID;
163
169
move_tool->guide_orientation = GIMP_ORIENTATION_UNKNOWN;
165
171
move_tool->saved_type = GIMP_TRANSFORM_TYPE_LAYER;
167
173
move_tool->old_active_layer = NULL;
168
174
move_tool->old_active_vectors = NULL;
170
gimp_tool_control_set_snap_to (tool->control, FALSE);
171
gimp_tool_control_set_handle_empty_image (tool->control, TRUE);
172
gimp_tool_control_set_tool_cursor (tool->control,
173
GIMP_TOOL_CURSOR_MOVE);
177
gimp_move_tool_control (GimpTool *tool,
178
GimpToolAction action,
179
GimpDisplay *display)
181
GimpMoveTool *move = GIMP_MOVE_TOOL (tool);
182
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (display->shell);
186
case GIMP_TOOL_ACTION_PAUSE:
189
case GIMP_TOOL_ACTION_RESUME:
190
if (move->guide && gimp_display_shell_get_show_guides (shell))
191
gimp_display_shell_draw_guide (shell, move->guide, TRUE);
194
case GIMP_TOOL_ACTION_HALT:
195
if (move->guide && gimp_display_shell_get_show_guides (shell))
196
gimp_display_shell_draw_guide (shell, move->guide, FALSE);
200
GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
204
gimp_move_tool_button_press (GimpTool *tool,
207
GdkModifierType state,
208
GimpDisplay *display)
178
gimp_move_tool_button_press (GimpTool *tool,
179
const GimpCoords *coords,
181
GdkModifierType state,
182
GimpButtonPressType press_type,
183
GimpDisplay *display)
210
185
GimpMoveTool *move = GIMP_MOVE_TOOL (tool);
211
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (display->shell);
212
186
GimpMoveOptions *options = GIMP_MOVE_TOOL_GET_OPTIONS (tool);
187
GimpDisplayShell *shell = gimp_display_get_shell (display);
188
GimpImage *image = gimp_display_get_image (display);
214
190
tool->display = display;
244
220
else if (options->move_type == GIMP_TRANSFORM_TYPE_LAYER)
251
GIMP_DISPLAY_CONFIG (display->image->gimp->config)->snap_distance;
224
const gint snap_distance = display->config->snap_distance;
253
226
if (gimp_display_shell_get_show_guides (shell) &&
254
(guide = gimp_image_find_guide (display->image,
227
(guide = gimp_image_find_guide (image,
255
228
coords->x, coords->y,
256
229
FUNSCALEX (shell, snap_distance),
257
230
FUNSCALEY (shell, snap_distance))))
268
241
gimp_tool_control_activate (tool->control);
270
gimp_display_shell_selection_control (shell,
271
GIMP_SELECTION_PAUSE);
243
gimp_display_shell_selection_pause (shell);
273
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
245
if (! gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tool)))
246
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
275
248
gimp_tool_push_status_length (tool, display,
276
249
_("Move Guide: "),
283
else if ((layer = gimp_image_pick_correlate_layer (display->image,
256
else if ((layer = gimp_image_pick_layer (image,
287
if (gimp_image_floating_sel (display->image) &&
260
if (gimp_image_get_floating_selection (image) &&
288
261
! gimp_layer_is_floating_sel (layer))
290
263
/* If there is a floating selection, and this aint it,
291
264
* use the move tool to anchor it.
293
move->floating_layer = gimp_image_floating_sel (display->image);
266
move->floating_layer =
267
gimp_image_get_floating_selection (image);
294
269
gimp_tool_control_activate (tool->control);
300
move->old_active_layer =
301
gimp_image_get_active_layer (display->image);
275
move->old_active_layer = gimp_image_get_active_layer (image);
303
gimp_image_set_active_layer (display->image, layer);
277
gimp_image_set_active_layer (image, layer);
315
289
switch (options->move_type)
317
291
case GIMP_TRANSFORM_TYPE_PATH:
318
if (gimp_image_get_active_vectors (display->image))
319
gimp_edit_selection_tool_start (tool, display, coords,
320
GIMP_TRANSLATE_MODE_VECTORS, TRUE);
292
if (gimp_image_get_active_vectors (image))
294
gimp_tool_control_activate (tool->control);
295
gimp_edit_selection_tool_start (tool, display, coords,
296
GIMP_TRANSLATE_MODE_VECTORS, TRUE);
323
300
case GIMP_TRANSFORM_TYPE_SELECTION:
324
if (! gimp_channel_is_empty (gimp_image_get_mask (display->image)))
325
gimp_edit_selection_tool_start (tool, display, coords,
326
GIMP_TRANSLATE_MODE_MASK, TRUE);
301
if (! gimp_channel_is_empty (gimp_image_get_mask (image)))
303
gimp_tool_control_activate (tool->control);
304
gimp_edit_selection_tool_start (tool, display, coords,
305
GIMP_TRANSLATE_MODE_MASK, TRUE);
329
309
case GIMP_TRANSFORM_TYPE_LAYER:
331
GimpDrawable *drawable;
333
drawable = gimp_image_get_active_drawable (display->image);
311
GimpDrawable *drawable = gimp_image_get_active_drawable (image);
335
313
if (GIMP_IS_LAYER_MASK (drawable))
336
gimp_edit_selection_tool_start (tool, display, coords,
337
GIMP_TRANSLATE_MODE_LAYER_MASK, TRUE);
315
gimp_tool_control_activate (tool->control);
316
gimp_edit_selection_tool_start (tool, display, coords,
317
GIMP_TRANSLATE_MODE_LAYER_MASK, TRUE);
338
319
else if (GIMP_IS_CHANNEL (drawable))
339
gimp_edit_selection_tool_start (tool, display, coords,
340
GIMP_TRANSLATE_MODE_CHANNEL, TRUE);
321
gimp_tool_control_activate (tool->control);
322
gimp_edit_selection_tool_start (tool, display, coords,
323
GIMP_TRANSLATE_MODE_CHANNEL, TRUE);
341
325
else if (GIMP_IS_LAYER (drawable))
342
gimp_edit_selection_tool_start (tool, display, coords,
343
GIMP_TRANSLATE_MODE_LAYER, TRUE);
327
gimp_tool_control_activate (tool->control);
328
gimp_edit_selection_tool_start (tool, display, coords,
329
GIMP_TRANSLATE_MODE_LAYER, TRUE);
350
337
gimp_move_tool_button_release (GimpTool *tool,
338
const GimpCoords *coords,
353
340
GdkModifierType state,
354
341
GimpButtonReleaseType release_type,
355
342
GimpDisplay *display)
357
344
GimpMoveTool *move = GIMP_MOVE_TOOL (tool);
358
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (display->shell);
359
GimpGuiConfig *config = GIMP_GUI_CONFIG (display->image->gimp->config);
345
GimpGuiConfig *config = GIMP_GUI_CONFIG (display->gimp->config);
346
GimpDisplayShell *shell = gimp_display_get_shell (display);
347
GimpImage *image = gimp_display_get_image (display);
361
if (gimp_tool_control_is_active (tool->control))
362
gimp_tool_control_halt (tool->control);
349
gimp_tool_control_halt (tool->control);
364
351
if (move->moving_guide)
424
411
switch (move->guide_orientation)
426
413
case GIMP_ORIENTATION_HORIZONTAL:
427
move->guide = gimp_image_add_hguide (display->image,
414
move->guide = gimp_image_add_hguide (image,
428
415
move->guide_position,
432
419
case GIMP_ORIENTATION_VERTICAL:
433
move->guide = gimp_image_add_vguide (display->image,
420
move->guide = gimp_image_add_vguide (image,
434
421
move->guide_position,
444
gimp_display_shell_selection_control (shell, GIMP_SELECTION_RESUME);
445
gimp_image_flush (display->image);
448
gimp_display_shell_draw_guide (shell, move->guide, TRUE);
431
gimp_display_shell_selection_resume (shell);
432
gimp_image_flush (image);
450
434
move->moving_guide = FALSE;
451
move->guide_position = -1;
435
move->guide_position = GUIDE_POSITION_INVALID;
452
436
move->guide_orientation = GIMP_ORIENTATION_UNKNOWN;
439
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
491
gimp_image_flush (display->image);
476
gimp_image_flush (image);
496
gimp_move_tool_motion (GimpTool *tool,
499
GdkModifierType state,
500
GimpDisplay *display)
481
gimp_move_tool_motion (GimpTool *tool,
482
const GimpCoords *coords,
484
GdkModifierType state,
485
GimpDisplay *display)
503
488
GimpMoveTool *move = GIMP_MOVE_TOOL (tool);
504
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (display->shell);
489
GimpDisplayShell *shell = gimp_display_get_shell (display);
506
491
if (move->moving_guide)
646
gimp_move_tool_oper_update (GimpTool *tool,
648
GdkModifierType state,
650
GimpDisplay *display)
633
gimp_move_tool_oper_update (GimpTool *tool,
634
const GimpCoords *coords,
635
GdkModifierType state,
637
GimpDisplay *display)
652
639
GimpMoveTool *move = GIMP_MOVE_TOOL (tool);
653
640
GimpMoveOptions *options = GIMP_MOVE_TOOL_GET_OPTIONS (tool);
654
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (display->shell);
641
GimpDisplayShell *shell = gimp_display_get_shell (display);
642
GimpImage *image = gimp_display_get_image (display);
655
643
GimpGuide *guide = NULL;
657
645
if (options->move_type == GIMP_TRANSFORM_TYPE_LAYER &&
659
647
gimp_display_shell_get_show_guides (shell) &&
665
GIMP_DISPLAY_CONFIG (display->image->gimp->config)->snap_distance;
667
guide = gimp_image_find_guide (display->image, coords->x, coords->y,
650
gint snap_distance = display->config->snap_distance;
652
guide = gimp_image_find_guide (image, coords->x, coords->y,
668
653
FUNSCALEX (shell, snap_distance),
669
654
FUNSCALEY (shell, snap_distance));
672
if (move->guide && move->guide != guide)
673
gimp_display_shell_draw_guide (shell, move->guide, FALSE);
678
gimp_display_shell_draw_guide (shell, move->guide, TRUE);
657
if (move->guide != guide)
659
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
661
gimp_draw_tool_pause (draw_tool);
663
if (gimp_draw_tool_is_active (draw_tool) &&
664
draw_tool->display != display)
665
gimp_draw_tool_stop (draw_tool);
669
if (! gimp_draw_tool_is_active (draw_tool))
670
gimp_draw_tool_start (draw_tool, display);
672
gimp_draw_tool_resume (draw_tool);
682
gimp_move_tool_cursor_update (GimpTool *tool,
684
GdkModifierType state,
685
GimpDisplay *display)
677
gimp_move_tool_cursor_update (GimpTool *tool,
678
const GimpCoords *coords,
679
GdkModifierType state,
680
GimpDisplay *display)
687
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (display->shell);
688
682
GimpMoveOptions *options = GIMP_MOVE_TOOL_GET_OPTIONS (tool);
683
GimpDisplayShell *shell = gimp_display_get_shell (display);
684
GimpImage *image = gimp_display_get_image (display);
689
685
GimpCursorType cursor = GIMP_CURSOR_MOUSE;
690
686
GimpToolCursorType tool_cursor = GIMP_TOOL_CURSOR_MOVE;
691
687
GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_NONE;
719
715
tool_cursor = GIMP_TOOL_CURSOR_RECT_SELECT;
720
716
modifier = GIMP_CURSOR_MODIFIER_MOVE;
722
if (gimp_channel_is_empty (gimp_image_get_mask (display->image)))
718
if (gimp_channel_is_empty (gimp_image_get_mask (image)))
723
719
modifier = GIMP_CURSOR_MODIFIER_BAD;
725
721
else if (options->move_current)
727
if (! gimp_image_get_active_drawable (display->image))
723
if (! gimp_image_get_active_drawable (image))
728
724
modifier = GIMP_CURSOR_MODIFIER_BAD;
737
GIMP_DISPLAY_CONFIG (display->image->gimp->config)->snap_distance;
730
const gint snap_distance = display->config->snap_distance;
739
732
if (gimp_display_shell_get_show_guides (shell) &&
740
(guide = gimp_image_find_guide (display->image, coords->x, coords->y,
733
(guide = gimp_image_find_guide (image, coords->x, coords->y,
741
734
FUNSCALEX (shell, snap_distance),
742
735
FUNSCALEY (shell, snap_distance))))
744
737
tool_cursor = GIMP_TOOL_CURSOR_HAND;
745
738
modifier = GIMP_CURSOR_MODIFIER_MOVE;
747
else if ((layer = gimp_image_pick_correlate_layer (display->image,
748
coords->x, coords->y)))
740
else if ((layer = gimp_image_pick_layer (image,
741
coords->x, coords->y)))
750
743
/* if there is a floating selection, and this aint it... */
751
if (gimp_image_floating_sel (display->image) &&
744
if (gimp_image_get_floating_selection (image) &&
752
745
! gimp_layer_is_floating_sel (layer))
754
747
tool_cursor = GIMP_TOOL_CURSOR_MOVE;
755
748
modifier = GIMP_CURSOR_MODIFIER_ANCHOR;
757
else if (layer != gimp_image_get_active_layer (display->image))
750
else if (layer != gimp_image_get_active_layer (image))
759
752
tool_cursor = GIMP_TOOL_CURSOR_HAND;
760
753
modifier = GIMP_CURSOR_MODIFIER_MOVE;
779
772
GimpMoveTool *move = GIMP_MOVE_TOOL (draw_tool);
781
if (move->moving_guide && move->guide_position != -1)
783
gimp_draw_tool_draw_guide_line (draw_tool,
784
move->guide_orientation,
785
move->guide_position);
776
GimpCanvasItem *item;
778
item = gimp_draw_tool_add_guide (draw_tool,
779
gimp_guide_get_orientation (move->guide),
780
gimp_guide_get_position (move->guide),
782
gimp_canvas_item_set_highlight (item, TRUE);
785
if (move->moving_guide && move->guide_position != GUIDE_POSITION_INVALID)
787
gimp_draw_tool_add_guide (draw_tool,
788
move->guide_orientation,
789
move->guide_position,
816
821
GimpTool *tool = GIMP_TOOL (move);
818
gimp_display_shell_selection_control (GIMP_DISPLAY_SHELL (display->shell),
819
GIMP_SELECTION_PAUSE);
823
gimp_display_shell_selection_pause (gimp_display_get_shell (display));
821
825
tool->display = display;
822
826
gimp_tool_control_activate (tool->control);
823
827
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
826
gimp_display_shell_draw_guide (GIMP_DISPLAY_SHELL (display->shell),
829
if (gimp_draw_tool_is_active (GIMP_DRAW_TOOL (tool)))
830
gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
829
832
move->guide = NULL;
830
833
move->moving_guide = TRUE;
831
move->guide_position = -1;
834
move->guide_position = GUIDE_POSITION_INVALID;
832
835
move->guide_orientation = orientation;
834
837
gimp_tool_set_cursor (tool, display,