1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdlib.h>
|
2000-03-05 08:06:11 +08:00
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-08-06 00:08:19 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "tools-types.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "core/gimpimage-mask.h"
|
|
|
|
#include "core/gimplayer.h"
|
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
2001-10-13 20:52:30 +08:00
|
|
|
#include "display/gimpdisplay-foreach.h"
|
2001-11-01 05:20:09 +08:00
|
|
|
#include "display/gimpdisplayshell.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
|
2001-03-08 09:07:03 +08:00
|
|
|
#include "gimpeditselectiontool.h"
|
|
|
|
#include "gimpmovetool.h"
|
2001-02-22 05:56:39 +08:00
|
|
|
#include "tool_manager.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "tool_options.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
#include "colormaps.h"
|
|
|
|
#include "floating_sel.h"
|
|
|
|
#include "undo.h"
|
|
|
|
|
1998-12-16 08:37:09 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2001-02-22 05:56:39 +08:00
|
|
|
static void gimp_move_tool_class_init (GimpMoveToolClass *klass);
|
|
|
|
static void gimp_move_tool_init (GimpMoveTool *move_tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-22 05:56:39 +08:00
|
|
|
static void move_tool_button_press (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
2001-10-29 19:47:11 +08:00
|
|
|
GimpDisplay *gdisp);
|
2001-02-22 05:56:39 +08:00
|
|
|
static void move_tool_button_release (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
2001-10-29 19:47:11 +08:00
|
|
|
GimpDisplay *gdisp);
|
2001-02-22 05:56:39 +08:00
|
|
|
static void move_tool_motion (GimpTool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
2001-10-29 19:47:11 +08:00
|
|
|
GimpDisplay *gdisp);
|
2001-02-22 05:56:39 +08:00
|
|
|
static void move_tool_cursor_update (GimpTool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
2001-10-29 19:47:11 +08:00
|
|
|
GimpDisplay *gdisp);
|
2001-02-22 05:56:39 +08:00
|
|
|
static void move_tool_control (GimpTool *tool,
|
|
|
|
ToolAction tool_action,
|
2001-10-29 19:47:11 +08:00
|
|
|
GimpDisplay *gdisp);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2001-10-29 19:47:11 +08:00
|
|
|
static void move_create_gc (GimpDisplay *gdisp);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
/* the move tool options */
|
2001-07-18 04:50:01 +08:00
|
|
|
static GimpToolOptions *move_options = NULL;
|
1999-04-09 06:25:54 +08:00
|
|
|
|
|
|
|
/* local variables */
|
|
|
|
static GdkGC *move_gc = NULL;
|
|
|
|
|
2001-02-22 05:56:39 +08:00
|
|
|
static GimpToolClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2001-07-07 20:17:23 +08:00
|
|
|
gimp_move_tool_register (Gimp *gimp)
|
2001-02-22 05:56:39 +08:00
|
|
|
{
|
2001-07-07 20:17:23 +08:00
|
|
|
tool_manager_register_tool (gimp,
|
|
|
|
GIMP_TYPE_MOVE_TOOL,
|
2001-02-28 07:20:51 +08:00
|
|
|
FALSE,
|
2001-02-24 05:32:47 +08:00
|
|
|
"gimp:move_tool",
|
|
|
|
_("Move Tool"),
|
|
|
|
_("Move layers & selections"),
|
2001-02-22 05:56:39 +08:00
|
|
|
N_("/Tools/Transform Tools/Move"), "M",
|
|
|
|
NULL, "tools/move.html",
|
2001-08-06 00:08:19 +08:00
|
|
|
GIMP_STOCK_TOOL_MOVE);
|
2001-02-22 05:56:39 +08:00
|
|
|
}
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
GType
|
2001-02-22 05:56:39 +08:00
|
|
|
gimp_move_tool_get_type (void)
|
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
static GType tool_type = 0;
|
2001-02-22 05:56:39 +08:00
|
|
|
|
|
|
|
if (! tool_type)
|
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
static const GTypeInfo tool_info =
|
2001-02-22 05:56:39 +08:00
|
|
|
{
|
|
|
|
sizeof (GimpMoveToolClass),
|
2001-08-14 22:53:55 +08:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_move_tool_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpMoveTool),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_move_tool_init,
|
2001-02-22 05:56:39 +08:00
|
|
|
};
|
2001-08-14 22:53:55 +08:00
|
|
|
|
|
|
|
tool_type = g_type_register_static (GIMP_TYPE_TOOL,
|
|
|
|
"GimpMoveTool",
|
|
|
|
&tool_info, 0);
|
2001-02-22 05:56:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return tool_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_move_tool_class_init (GimpMoveToolClass *klass)
|
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
GimpToolClass *tool_class;
|
2001-02-22 05:56:39 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
tool_class = GIMP_TOOL_CLASS (klass);
|
2001-02-22 05:56:39 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-02-22 05:56:39 +08:00
|
|
|
|
|
|
|
tool_class->control = move_tool_control;
|
|
|
|
tool_class->button_press = move_tool_button_press;
|
|
|
|
tool_class->button_release = move_tool_button_release;
|
|
|
|
tool_class->motion = move_tool_motion;
|
|
|
|
tool_class->cursor_update = move_tool_cursor_update;
|
2001-02-28 10:53:27 +08:00
|
|
|
tool_class->arrow_key = gimp_edit_selection_tool_arrow_key;
|
2001-02-22 05:56:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_move_tool_init (GimpMoveTool *move_tool)
|
|
|
|
{
|
|
|
|
GimpTool *tool;
|
|
|
|
|
|
|
|
tool = GIMP_TOOL (move_tool);
|
|
|
|
|
|
|
|
/* The tool options */
|
|
|
|
if (! move_options)
|
|
|
|
{
|
2001-02-24 05:32:47 +08:00
|
|
|
move_options = tool_options_new ();
|
2001-02-22 05:56:39 +08:00
|
|
|
|
2001-02-24 05:32:47 +08:00
|
|
|
tool_manager_register_tool_options (GIMP_TYPE_MOVE_TOOL,
|
2001-07-18 04:50:01 +08:00
|
|
|
(GimpToolOptions *) move_options);
|
2001-02-22 05:56:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
move_tool->layer = NULL;
|
|
|
|
move_tool->guide = NULL;
|
|
|
|
move_tool->disp = NULL;
|
|
|
|
|
|
|
|
tool->auto_snap_to = FALSE; /* Don't snap to guides */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-10-29 19:47:11 +08:00
|
|
|
move_tool_control (GimpTool *tool,
|
|
|
|
ToolAction action,
|
|
|
|
GimpDisplay *gdisp)
|
2001-02-22 05:56:39 +08:00
|
|
|
{
|
|
|
|
GimpMoveTool *move_tool;
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
move_tool = GIMP_MOVE_TOOL (tool);
|
2001-02-22 05:56:39 +08:00
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
switch (action)
|
2001-02-22 05:56:39 +08:00
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
case PAUSE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RESUME:
|
2001-02-22 05:56:39 +08:00
|
|
|
if (move_tool->guide)
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_display_shell_draw_guide (GIMP_DISPLAY_SHELL (gdisp->shell),
|
|
|
|
move_tool->guide, TRUE);
|
2001-08-14 22:53:55 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case HALT:
|
|
|
|
if (move_tool->guide)
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_display_shell_draw_guide (GIMP_DISPLAY_SHELL (gdisp->shell),
|
|
|
|
move_tool->guide, FALSE);
|
2001-08-14 22:53:55 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2001-02-22 05:56:39 +08:00
|
|
|
}
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
if (GIMP_TOOL_CLASS (parent_class)->control)
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->control (tool, action, gdisp);
|
2001-02-22 05:56:39 +08:00
|
|
|
}
|
1999-04-09 06:25:54 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2001-02-22 05:56:39 +08:00
|
|
|
move_tool_button_press (GimpTool *tool,
|
1997-11-25 06:05:25 +08:00
|
|
|
GdkEventButton *bevent,
|
2001-10-29 19:47:11 +08:00
|
|
|
GimpDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
GimpMoveTool *move;
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
GimpLayer *layer;
|
|
|
|
GimpGuide *guide;
|
|
|
|
gint x, y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-22 05:56:39 +08:00
|
|
|
move = GIMP_MOVE_TOOL (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
|
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
tool->gdisp = gdisp;
|
1997-11-25 06:05:25 +08:00
|
|
|
move->layer = NULL;
|
|
|
|
move->guide = NULL;
|
1999-10-14 07:07:45 +08:00
|
|
|
move->disp = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
gdisplay_untransform_coords (gdisp, bevent->x, bevent->y, &x, &y,
|
|
|
|
FALSE, FALSE);
|
2000-03-29 07:39:32 +08:00
|
|
|
|
|
|
|
if (bevent->state & GDK_MOD1_MASK &&
|
|
|
|
!gimage_mask_is_empty (gdisp->gimage))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-12-31 12:07:42 +08:00
|
|
|
init_edit_selection (tool, gdisp, bevent, EDIT_MASK_TRANSLATE);
|
1997-11-25 06:05:25 +08:00
|
|
|
tool->state = ACTIVE;
|
|
|
|
}
|
|
|
|
else if (bevent->state & GDK_SHIFT_MASK)
|
|
|
|
{
|
2000-12-31 12:07:42 +08:00
|
|
|
init_edit_selection (tool, gdisp, bevent, EDIT_LAYER_TRANSLATE);
|
1997-11-25 06:05:25 +08:00
|
|
|
tool->state = ACTIVE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-03-29 07:39:32 +08:00
|
|
|
if (gdisp->draw_guides &&
|
2001-11-01 05:20:09 +08:00
|
|
|
(guide = gimp_image_find_guide (gdisp->gimage, x, y)))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
undo_push_guide (gdisp->gimage, guide);
|
|
|
|
|
1998-06-29 08:24:44 +08:00
|
|
|
gdisplays_expose_guide (gdisp->gimage, guide);
|
2000-12-29 23:22:01 +08:00
|
|
|
gimp_image_remove_guide (gdisp->gimage, guide);
|
1997-11-25 06:05:25 +08:00
|
|
|
gdisplay_flush (gdisp);
|
2000-12-29 23:22:01 +08:00
|
|
|
gimp_image_add_guide (gdisp->gimage, guide);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
move->guide = guide;
|
2000-03-29 07:39:32 +08:00
|
|
|
move->disp = gdisp;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
tool->scroll_lock = TRUE;
|
2000-03-29 07:39:32 +08:00
|
|
|
tool->state = ACTIVE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
move_tool_motion (tool, NULL, gdisp);
|
|
|
|
}
|
2000-12-29 23:22:01 +08:00
|
|
|
else if ((layer = gimp_image_pick_correlate_layer (gdisp->gimage, x, y)))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-03-29 07:39:32 +08:00
|
|
|
/* If there is a floating selection, and this aint it,
|
|
|
|
* use the move tool
|
|
|
|
*/
|
2000-12-29 23:22:01 +08:00
|
|
|
if (gimp_image_floating_sel (gdisp->gimage) &&
|
2001-01-29 07:25:25 +08:00
|
|
|
! gimp_layer_is_floating_sel (layer))
|
2000-03-29 07:39:32 +08:00
|
|
|
{
|
2000-12-29 23:22:01 +08:00
|
|
|
move->layer = gimp_image_floating_sel (gdisp->gimage);
|
2000-03-29 07:39:32 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Otherwise, init the edit selection */
|
|
|
|
else
|
|
|
|
{
|
2000-12-29 23:22:01 +08:00
|
|
|
gimp_image_set_active_layer (gdisp->gimage, layer);
|
2000-12-31 12:07:42 +08:00
|
|
|
init_edit_selection (tool, gdisp, bevent, EDIT_LAYER_TRANSLATE);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
tool->state = ACTIVE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if we've got an active tool grab the pointer */
|
|
|
|
if (tool->state == ACTIVE)
|
2000-02-29 03:25:42 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
gdk_pointer_grab (shell->canvas->window, FALSE,
|
2000-03-29 07:39:32 +08:00
|
|
|
GDK_POINTER_MOTION_HINT_MASK |
|
|
|
|
GDK_BUTTON1_MOTION_MASK |
|
2000-02-29 03:25:42 +08:00
|
|
|
GDK_BUTTON_RELEASE_MASK,
|
|
|
|
NULL, NULL, bevent->time);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-03-16 19:13:24 +08:00
|
|
|
static void
|
2001-10-29 19:47:11 +08:00
|
|
|
move_draw_guide (GimpDisplay *gdisp,
|
|
|
|
GimpGuide *guide)
|
1998-03-16 19:13:24 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
GimpDisplayShell *shell;
|
|
|
|
gint x1, y1;
|
|
|
|
gint x2, y2;
|
|
|
|
gint w, h;
|
|
|
|
gint x, y;
|
|
|
|
|
|
|
|
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
|
1998-03-16 19:13:24 +08:00
|
|
|
|
|
|
|
if (!move_gc)
|
|
|
|
move_create_gc (gdisp);
|
|
|
|
|
|
|
|
if (guide->position == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gdisplay_transform_coords (gdisp, gdisp->gimage->width,
|
|
|
|
gdisp->gimage->height, &x2, &y2, FALSE);
|
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
w = shell->canvas->allocation.width;
|
|
|
|
h = shell->canvas->allocation.height;
|
1998-03-16 19:13:24 +08:00
|
|
|
|
2000-03-29 07:39:32 +08:00
|
|
|
switch (guide->orientation)
|
|
|
|
{
|
|
|
|
case ORIENTATION_HORIZONTAL:
|
|
|
|
gdisplay_transform_coords (gdisp, 0, guide->position, &x1, &y, FALSE);
|
|
|
|
if (x1 < 0) x1 = 0;
|
|
|
|
if (x2 > w) x2 = w;
|
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
gdk_draw_line (shell->canvas->window, move_gc, x1, y, x2, y);
|
2000-03-29 07:39:32 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ORIENTATION_VERTICAL:
|
|
|
|
gdisplay_transform_coords (gdisp, guide->position, 0, &x, &y1, FALSE);
|
|
|
|
if (y1 < 0) y1 = 0;
|
|
|
|
if (y2 > h) y2 = h;
|
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
gdk_draw_line (shell->canvas->window, move_gc, x, y1, x, y2);
|
2000-03-29 07:39:32 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_warning ("mdg / BAD FALLTHROUGH");
|
2000-12-29 00:19:55 +08:00
|
|
|
break;
|
2000-03-29 07:39:32 +08:00
|
|
|
}
|
1998-03-16 19:13:24 +08:00
|
|
|
}
|
|
|
|
|
1998-03-19 06:35:31 +08:00
|
|
|
static void
|
2001-02-22 05:56:39 +08:00
|
|
|
move_tool_button_release (GimpTool *tool,
|
1997-11-25 06:05:25 +08:00
|
|
|
GdkEventButton *bevent,
|
2001-10-29 19:47:11 +08:00
|
|
|
GimpDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-22 05:56:39 +08:00
|
|
|
GimpMoveTool *move;
|
|
|
|
gboolean delete_guide;
|
|
|
|
gint x1, y1;
|
|
|
|
gint x2, y2;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-22 05:56:39 +08:00
|
|
|
move = GIMP_MOVE_TOOL (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gdk_flush ();
|
|
|
|
|
|
|
|
tool->state = INACTIVE;
|
|
|
|
gdk_pointer_ungrab (bevent->time);
|
|
|
|
|
|
|
|
if (move->guide)
|
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
GimpDisplayShell *shell;
|
|
|
|
|
|
|
|
shell = GIMP_DISPLAY_SHELL (tool->gdisp->shell);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
tool->scroll_lock = FALSE;
|
|
|
|
|
1999-10-14 07:07:45 +08:00
|
|
|
delete_guide = FALSE;
|
2001-11-01 05:20:09 +08:00
|
|
|
gdisplay_untransform_coords (gdisp,
|
|
|
|
0, 0,
|
|
|
|
&x1, &y1,
|
|
|
|
FALSE, FALSE);
|
|
|
|
gdisplay_untransform_coords (gdisp,
|
2001-11-02 17:31:21 +08:00
|
|
|
shell->disp_width, shell->disp_height,
|
2001-11-01 05:20:09 +08:00
|
|
|
&x2, &y2,
|
|
|
|
FALSE, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (x1 < 0) x1 = 0;
|
|
|
|
if (y1 < 0) y1 = 0;
|
2000-03-29 07:39:32 +08:00
|
|
|
if (x2 > gdisp->gimage->width) x2 = gdisp->gimage->width;
|
1997-11-25 06:05:25 +08:00
|
|
|
if (y2 > gdisp->gimage->height) y2 = gdisp->gimage->height;
|
|
|
|
|
|
|
|
switch (move->guide->orientation)
|
|
|
|
{
|
1999-07-29 07:00:08 +08:00
|
|
|
case ORIENTATION_HORIZONTAL:
|
1997-11-25 06:05:25 +08:00
|
|
|
if ((move->guide->position < y1) || (move->guide->position > y2))
|
1999-10-14 07:07:45 +08:00
|
|
|
delete_guide = TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
2000-12-29 00:19:55 +08:00
|
|
|
|
1999-07-29 07:00:08 +08:00
|
|
|
case ORIENTATION_VERTICAL:
|
1997-11-25 06:05:25 +08:00
|
|
|
if ((move->guide->position < x1) || (move->guide->position > x2))
|
1999-10-14 07:07:45 +08:00
|
|
|
delete_guide = TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
2000-12-29 00:19:55 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-06-29 08:24:44 +08:00
|
|
|
gdisplays_expose_guide (gdisp->gimage, move->guide);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-10-14 07:07:45 +08:00
|
|
|
if (delete_guide)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-03-16 19:13:24 +08:00
|
|
|
move_draw_guide (gdisp, move->guide);
|
1999-10-14 07:07:45 +08:00
|
|
|
gimp_image_delete_guide (gdisp->gimage, move->guide);
|
1997-11-25 06:05:25 +08:00
|
|
|
move->guide = NULL;
|
1998-06-30 09:14:36 +08:00
|
|
|
move->disp = NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-12-31 12:07:42 +08:00
|
|
|
move_tool_motion (tool, NULL, gdisp);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-09-26 01:44:03 +08:00
|
|
|
gdisplay_selection_visibility (gdisp, GIMP_SELECTION_RESUME);
|
1997-11-25 06:05:25 +08:00
|
|
|
gdisplays_flush ();
|
|
|
|
|
|
|
|
if (move->guide)
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_display_shell_draw_guide (shell, move->guide, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-10-14 07:07:45 +08:00
|
|
|
/* Take care of the case where the user "cancels" the action */
|
1997-11-25 06:05:25 +08:00
|
|
|
if (! (bevent->state & GDK_BUTTON3_MASK))
|
|
|
|
{
|
|
|
|
if (move->layer)
|
|
|
|
{
|
|
|
|
floating_sel_anchor (move->layer);
|
|
|
|
gdisplays_flush ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-03-19 06:35:31 +08:00
|
|
|
static void
|
2001-02-22 05:56:39 +08:00
|
|
|
move_tool_motion (GimpTool *tool,
|
1997-11-25 06:05:25 +08:00
|
|
|
GdkEventMotion *mevent,
|
2001-10-29 19:47:11 +08:00
|
|
|
GimpDisplay *gdisp)
|
1998-03-16 19:13:24 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-22 05:56:39 +08:00
|
|
|
GimpMoveTool *move;
|
|
|
|
gint x, y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-22 05:56:39 +08:00
|
|
|
move = GIMP_MOVE_TOOL (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-03-29 07:39:32 +08:00
|
|
|
if (move->guide)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
GimpDisplayShell *shell;
|
|
|
|
|
|
|
|
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
|
|
|
|
|
2000-03-29 07:39:32 +08:00
|
|
|
move_draw_guide (gdisp, move->guide);
|
1999-04-06 07:33:50 +08:00
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
if (mevent && mevent->window != shell->canvas->window)
|
1999-04-06 07:33:50 +08:00
|
|
|
{
|
2000-03-29 07:39:32 +08:00
|
|
|
move->guide->position = -1;
|
1999-04-06 07:33:50 +08:00
|
|
|
return;
|
|
|
|
}
|
1998-03-16 19:13:24 +08:00
|
|
|
|
|
|
|
if (mevent)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
1998-03-16 19:13:24 +08:00
|
|
|
gdisplay_untransform_coords (gdisp, mevent->x, mevent->y,
|
|
|
|
&x, &y, TRUE, FALSE);
|
2000-03-29 07:39:32 +08:00
|
|
|
|
|
|
|
if (move->guide->orientation == ORIENTATION_HORIZONTAL)
|
|
|
|
move->guide->position = y;
|
1998-03-16 19:13:24 +08:00
|
|
|
else
|
2000-03-29 07:39:32 +08:00
|
|
|
move->guide->position = x;
|
1998-03-16 19:13:24 +08:00
|
|
|
|
2000-03-29 07:39:32 +08:00
|
|
|
move_draw_guide (gdisp, move->guide);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-03-19 06:35:31 +08:00
|
|
|
static void
|
2001-02-22 05:56:39 +08:00
|
|
|
move_tool_cursor_update (GimpTool *tool,
|
1997-11-25 06:05:25 +08:00
|
|
|
GdkEventMotion *mevent,
|
2001-10-29 19:47:11 +08:00
|
|
|
GimpDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
GimpMoveTool *move;
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
GimpGuide *guide;
|
|
|
|
GimpLayer *layer;
|
|
|
|
gint x, y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-22 05:56:39 +08:00
|
|
|
move = GIMP_MOVE_TOOL (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
|
|
|
|
|
2000-03-29 07:39:32 +08:00
|
|
|
gdisplay_untransform_coords (gdisp, mevent->x, mevent->y, &x, &y,
|
|
|
|
FALSE, FALSE);
|
|
|
|
|
|
|
|
if (mevent->state & GDK_MOD1_MASK &&
|
2001-02-22 05:56:39 +08:00
|
|
|
! gimage_mask_is_empty (gdisp->gimage))
|
2000-03-29 07:39:32 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_display_shell_install_tool_cursor (shell,
|
|
|
|
GIMP_MOUSE_CURSOR,
|
|
|
|
GIMP_RECT_SELECT_TOOL_CURSOR,
|
|
|
|
GIMP_CURSOR_MODIFIER_MOVE);
|
2000-03-29 07:39:32 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else if (mevent->state & GDK_SHIFT_MASK)
|
2000-03-29 07:39:32 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_display_shell_install_tool_cursor (shell,
|
|
|
|
GIMP_MOUSE_CURSOR,
|
|
|
|
GIMP_MOVE_TOOL_CURSOR,
|
|
|
|
GIMP_CURSOR_MODIFIER_NONE);
|
2000-03-29 07:39:32 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
|
|
|
{
|
2000-03-29 07:39:32 +08:00
|
|
|
if (gdisp->draw_guides &&
|
2001-11-01 05:20:09 +08:00
|
|
|
(guide = gimp_image_find_guide (gdisp->gimage, x, y)))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-12-31 12:07:42 +08:00
|
|
|
tool->gdisp = gdisp;
|
2001-11-01 05:20:09 +08:00
|
|
|
|
|
|
|
gimp_display_shell_install_tool_cursor (shell,
|
|
|
|
GDK_HAND2,
|
|
|
|
GIMP_TOOL_CURSOR_NONE,
|
|
|
|
GIMP_CURSOR_MODIFIER_HAND);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (tool->state != ACTIVE)
|
|
|
|
{
|
|
|
|
if (move->guide)
|
|
|
|
{
|
1999-10-14 07:07:45 +08:00
|
|
|
gdisp = gdisplays_check_valid (move->disp, move->disp->gimage);
|
2001-11-01 05:20:09 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (gdisp)
|
2001-11-01 05:20:09 +08:00
|
|
|
{
|
|
|
|
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
|
|
|
|
|
|
|
|
gimp_display_shell_draw_guide (shell, move->guide, FALSE);
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_display_shell_draw_guide (shell, guide, TRUE);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
move->guide = guide;
|
2000-12-31 12:07:42 +08:00
|
|
|
move->disp = gdisp;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
2000-12-29 23:22:01 +08:00
|
|
|
else if ((layer = gimp_image_pick_correlate_layer (gdisp->gimage, x, y)))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
/* if there is a floating selection, and this aint it... */
|
2000-12-29 23:22:01 +08:00
|
|
|
if (gimp_image_floating_sel (gdisp->gimage) &&
|
2001-01-29 07:25:25 +08:00
|
|
|
! gimp_layer_is_floating_sel (layer))
|
2001-02-25 03:29:47 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_display_shell_install_tool_cursor (shell,
|
|
|
|
GIMP_MOUSE_CURSOR,
|
|
|
|
GIMP_RECT_SELECT_TOOL_CURSOR,
|
|
|
|
GIMP_CURSOR_MODIFIER_ANCHOR);
|
2001-02-25 03:29:47 +08:00
|
|
|
}
|
2001-02-25 22:37:12 +08:00
|
|
|
else if (layer == gimp_image_get_active_layer (gdisp->gimage))
|
2001-02-25 03:29:47 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_display_shell_install_tool_cursor (shell,
|
|
|
|
GIMP_MOUSE_CURSOR,
|
|
|
|
GIMP_MOVE_TOOL_CURSOR,
|
|
|
|
GIMP_CURSOR_MODIFIER_NONE);
|
2001-02-25 03:29:47 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
2001-02-25 03:29:47 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_display_shell_install_tool_cursor (shell,
|
|
|
|
GDK_HAND2,
|
|
|
|
GIMP_TOOL_CURSOR_NONE,
|
|
|
|
GIMP_CURSOR_MODIFIER_HAND);
|
2001-02-25 03:29:47 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
else
|
2000-03-29 07:39:32 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_display_shell_install_tool_cursor (shell,
|
|
|
|
GIMP_BAD_CURSOR,
|
|
|
|
GIMP_MOVE_TOOL_CURSOR,
|
|
|
|
GIMP_CURSOR_MODIFIER_NONE);
|
2000-03-29 07:39:32 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-10-29 19:47:11 +08:00
|
|
|
move_create_gc (GimpDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
if (! move_gc)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-11-01 05:20:09 +08:00
|
|
|
GimpDisplayShell *shell;
|
|
|
|
GdkGCValues values;
|
|
|
|
|
|
|
|
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-01 05:20:09 +08:00
|
|
|
values.foreground.pixel = g_white_pixel;
|
|
|
|
values.function = GDK_INVERT;
|
|
|
|
move_gc = gdk_gc_new_with_values (shell->canvas->window, &values,
|
2000-03-29 07:39:32 +08:00
|
|
|
GDK_GC_FUNCTION);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-10-29 19:47:11 +08:00
|
|
|
gimp_move_tool_start_hguide (GimpTool *tool,
|
|
|
|
GimpDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-22 05:56:39 +08:00
|
|
|
GimpMoveTool *move;
|
|
|
|
|
|
|
|
move = GIMP_MOVE_TOOL (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-09-26 01:44:03 +08:00
|
|
|
gdisplay_selection_visibility (gdisp, GIMP_SELECTION_PAUSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
tool->gdisp = gdisp;
|
1997-11-25 06:05:25 +08:00
|
|
|
tool->scroll_lock = TRUE;
|
|
|
|
|
2001-02-22 05:56:39 +08:00
|
|
|
if (move->guide && move->disp && move->disp->gimage)
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_display_shell_draw_guide (GIMP_DISPLAY_SHELL (move->disp->shell),
|
|
|
|
move->guide, FALSE);
|
1999-10-14 07:07:45 +08:00
|
|
|
|
2001-02-22 05:56:39 +08:00
|
|
|
move->guide = gimp_image_add_hguide (gdisp->gimage);
|
|
|
|
move->disp = gdisp;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
tool->state = ACTIVE;
|
|
|
|
|
2001-02-22 05:56:39 +08:00
|
|
|
undo_push_guide (gdisp->gimage, move->guide);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-10-29 19:47:11 +08:00
|
|
|
gimp_move_tool_start_vguide (GimpTool *tool,
|
|
|
|
GimpDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-22 05:56:39 +08:00
|
|
|
GimpMoveTool *move;
|
|
|
|
|
|
|
|
move = GIMP_MOVE_TOOL (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-09-26 01:44:03 +08:00
|
|
|
gdisplay_selection_visibility (gdisp, GIMP_SELECTION_PAUSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
tool->gdisp = gdisp;
|
1997-11-25 06:05:25 +08:00
|
|
|
tool->scroll_lock = TRUE;
|
|
|
|
|
2001-02-22 05:56:39 +08:00
|
|
|
if (move->guide && move->disp && move->disp->gimage)
|
2001-11-01 05:20:09 +08:00
|
|
|
gimp_display_shell_draw_guide (GIMP_DISPLAY_SHELL (move->disp->shell),
|
|
|
|
move->guide, FALSE);
|
1999-10-14 07:07:45 +08:00
|
|
|
|
2001-02-22 05:56:39 +08:00
|
|
|
move->guide = gimp_image_add_vguide (gdisp->gimage);
|
|
|
|
move->disp = gdisp;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
tool->state = ACTIVE;
|
|
|
|
|
2001-02-22 05:56:39 +08:00
|
|
|
undo_push_guide (gdisp->gimage, move->guide);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|