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-10-23 17:05:45 +08:00
|
|
|
|
2000-02-16 21:52:33 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdlib.h>
|
1998-07-20 22:05:33 +08:00
|
|
|
#include <stdarg.h>
|
2000-02-29 03:25:42 +08:00
|
|
|
|
2000-12-17 05:37:03 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-02-29 03:25:42 +08:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
|
2001-01-24 07:56:18 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2001-05-21 21:58:46 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2001-01-24 07:56:18 +08:00
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "tools-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/boundary.h"
|
|
|
|
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpdrawable.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "core/gimpimage-mask.h"
|
|
|
|
#include "core/gimplayer.h"
|
|
|
|
#include "core/gimplist.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "floating_sel.h"
|
2001-02-02 02:44:22 +08:00
|
|
|
#include "gdisplay.h"
|
1998-12-06 05:48:37 +08:00
|
|
|
#include "gimprc.h"
|
2000-02-16 21:52:33 +08:00
|
|
|
#include "path_transform.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "selection.h"
|
|
|
|
#include "undo.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-03-08 09:07:03 +08:00
|
|
|
#include "gimpeditselectiontool.h"
|
2001-02-28 10:29:25 +08:00
|
|
|
#include "gimpdrawtool.h"
|
|
|
|
#include "tool_manager.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
|
1999-07-03 01:40:10 +08:00
|
|
|
#define EDIT_SELECT_SCROLL_LOCK FALSE
|
1997-11-25 06:05:25 +08:00
|
|
|
#define ARROW_VELOCITY 25
|
1998-07-27 05:49:42 +08:00
|
|
|
#define STATUSBAR_SIZE 128
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
#define GIMP_TYPE_EDIT_SELECTION_TOOL (gimp_edit_selection_tool_get_type ())
|
|
|
|
#define GIMP_EDIT_SELECTION_TOOL(obj) (GTK_CHECK_CAST ((obj), GIMP_TYPE_EDIT_SELECTION_TOOL, GimpEditSelectionTool))
|
|
|
|
#define GIMP_IS_EDIT_SELECTION_TOOL(obj) (GTK_CHECK_TYPE ((obj), GIMP_TYPE_EDIT_SELECTION_TOOL))
|
|
|
|
#define GIMP_EDIT_SELECTION_TOOL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GIMP_TYPE_EDIT_SELECTION_TOOL, GimpEditSelectionToolClass))
|
|
|
|
#define GIMP_IS_EDIT_SELECTION_TOOL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_EDIT_SELECTION_TOOL))
|
2000-12-29 23:22:01 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
|
|
|
|
typedef struct _GimpEditSelectionTool GimpEditSelectionTool;
|
|
|
|
typedef struct _GimpEditSelectionToolClass GimpEditSelectionToolClass;
|
|
|
|
|
|
|
|
struct _GimpEditSelectionTool
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-28 10:29:25 +08:00
|
|
|
GimpDrawTool parent_instance;
|
|
|
|
|
2000-02-10 22:23:11 +08:00
|
|
|
gint origx, origy; /* last x and y coords */
|
|
|
|
gint cumlx, cumly; /* cumulative changes to x and yed */
|
|
|
|
gint x, y; /* current x and y coords */
|
2000-06-17 06:48:10 +08:00
|
|
|
gint num_segs_in; /* Num seg in selection boundary */
|
|
|
|
gint num_segs_out; /* Num seg in selection boundary */
|
2000-10-23 17:05:45 +08:00
|
|
|
BoundSeg *segs_in; /* Pointer to the channel sel. segs */
|
|
|
|
BoundSeg *segs_out; /* Pointer to the channel sel. segs */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-02-10 22:23:11 +08:00
|
|
|
gint x1, y1; /* bounding box of selection mask */
|
|
|
|
gint x2, y2;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-02-07 23:16:45 +08:00
|
|
|
EditType edit_type; /* translate the mask or layer? */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-11-05 22:39:04 +08:00
|
|
|
gboolean first_move; /* we undo_freeze after the first */
|
|
|
|
|
1999-02-07 23:16:45 +08:00
|
|
|
guint context_id; /* for the statusbar */
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
struct _GimpEditSelectionToolClass
|
|
|
|
{
|
|
|
|
GimpDrawToolClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static GtkType gimp_edit_selection_tool_get_type (void);
|
|
|
|
static void gimp_edit_selection_tool_class_init (GimpEditSelectionToolClass *klass);
|
|
|
|
static void gimp_edit_selection_tool_init (GimpEditSelectionTool *edit_selection_tool);
|
|
|
|
|
|
|
|
static void gimp_edit_selection_tool_destroy (GtkObject *object);
|
|
|
|
|
|
|
|
static void gimp_edit_selection_tool_button_release (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GDisplay *gdisp);
|
|
|
|
static void gimp_edit_selection_tool_motion (GimpTool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
|
|
|
GDisplay *gdisp);
|
|
|
|
static void gimp_edit_selection_tool_control (GimpTool *tool,
|
|
|
|
ToolAction action,
|
|
|
|
GDisplay *gdisp);
|
|
|
|
static void gimp_edit_selection_tool_cursor_update (GimpTool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
|
|
|
GDisplay *gdisp);
|
2001-02-28 10:53:27 +08:00
|
|
|
void gimp_edit_selection_tool_arrow_key (GimpTool *tool,
|
2001-02-28 10:29:25 +08:00
|
|
|
GdkEventKey *kevent,
|
|
|
|
GDisplay *gdisp);
|
|
|
|
|
|
|
|
static void gimp_edit_selection_tool_draw (GimpDrawTool *tool);
|
|
|
|
|
|
|
|
|
|
|
|
static GimpDrawToolClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
GtkType
|
|
|
|
gimp_edit_selection_tool_get_type (void)
|
|
|
|
{
|
|
|
|
static GtkType tool_type = 0;
|
|
|
|
|
|
|
|
if (! tool_type)
|
|
|
|
{
|
|
|
|
GtkTypeInfo tool_info =
|
|
|
|
{
|
|
|
|
"GimpEditSelectionTool",
|
|
|
|
sizeof (GimpEditSelectionTool),
|
|
|
|
sizeof (GimpEditSelectionToolClass),
|
|
|
|
(GtkClassInitFunc) gimp_edit_selection_tool_class_init,
|
|
|
|
(GtkObjectInitFunc) gimp_edit_selection_tool_init,
|
|
|
|
/* reserved_1 */ NULL,
|
|
|
|
/* reserved_2 */ NULL,
|
|
|
|
(GtkClassInitFunc) NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
tool_type = gtk_type_unique (GIMP_TYPE_DRAW_TOOL, &tool_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return tool_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_edit_selection_tool_class_init (GimpEditSelectionToolClass *klass)
|
|
|
|
{
|
|
|
|
GtkObjectClass *object_class;
|
|
|
|
GimpToolClass *tool_class;
|
|
|
|
GimpDrawToolClass *draw_class;
|
|
|
|
|
|
|
|
object_class = (GtkObjectClass *) klass;
|
|
|
|
tool_class = (GimpToolClass *) klass;
|
|
|
|
draw_class = (GimpDrawToolClass *) klass;
|
|
|
|
|
|
|
|
parent_class = gtk_type_class (GIMP_TYPE_DRAW_TOOL);
|
|
|
|
|
|
|
|
object_class->destroy = gimp_edit_selection_tool_destroy;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
tool_class->control = gimp_edit_selection_tool_control;
|
|
|
|
tool_class->button_release = gimp_edit_selection_tool_button_release;
|
|
|
|
tool_class->motion = gimp_edit_selection_tool_motion;
|
|
|
|
tool_class->cursor_update = gimp_edit_selection_tool_cursor_update;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
draw_class->draw = gimp_edit_selection_tool_draw;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2001-02-28 10:29:25 +08:00
|
|
|
gimp_edit_selection_tool_init (GimpEditSelectionTool *edit_selection_tool)
|
|
|
|
{
|
|
|
|
GimpTool *tool;
|
|
|
|
|
|
|
|
tool = GIMP_TOOL (edit_selection_tool);
|
|
|
|
|
|
|
|
tool->scroll_lock = EDIT_SELECT_SCROLL_LOCK;
|
|
|
|
tool->auto_snap_to = FALSE;
|
|
|
|
|
|
|
|
edit_selection_tool->origx = 0;
|
|
|
|
edit_selection_tool->origy = 0;
|
|
|
|
|
|
|
|
edit_selection_tool->cumlx = 0;
|
|
|
|
edit_selection_tool->cumly = 0;
|
|
|
|
|
|
|
|
edit_selection_tool->first_move = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_edit_selection_tool_destroy (GtkObject *object)
|
|
|
|
{
|
|
|
|
if (GTK_OBJECT_CLASS (parent_class)->destroy)
|
|
|
|
GTK_OBJECT_CLASS (parent_class)->destroy (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_edit_selection_tool_snap (GimpEditSelectionTool *edit_select,
|
|
|
|
GDisplay *gdisp,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-02-10 22:23:11 +08:00
|
|
|
gdouble x1, y1;
|
|
|
|
gdouble x2, y2;
|
|
|
|
gdouble dx, dy;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-02-10 22:23:11 +08:00
|
|
|
gdisplay_untransform_coords_f (gdisp, x, y, &x, &y, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
dx = x - edit_select->origx;
|
|
|
|
dy = y - edit_select->origy;
|
2000-02-10 22:23:11 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
x1 = edit_select->x1 + dx;
|
|
|
|
y1 = edit_select->y1 + dy;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-02-10 22:23:11 +08:00
|
|
|
if (gdisp->draw_guides &&
|
|
|
|
gdisp->snap_to_guides &&
|
|
|
|
gdisp->gimage->guides)
|
|
|
|
{
|
2001-02-28 10:29:25 +08:00
|
|
|
x2 = edit_select->x2 + dx;
|
|
|
|
y2 = edit_select->y2 + dy;
|
2000-02-10 22:23:11 +08:00
|
|
|
|
|
|
|
gdisplay_transform_coords_f (gdisp, x1, y1, &x1, &y1, TRUE);
|
|
|
|
gdisplay_transform_coords_f (gdisp, x2, y2, &x2, &y2, TRUE);
|
|
|
|
|
|
|
|
gdisplay_snap_rectangle (gdisp, x1, y1, x2, y2, &x1, &y1);
|
|
|
|
|
|
|
|
gdisplay_untransform_coords_f (gdisp, x1, y1, &x1, &y1, TRUE);
|
|
|
|
}
|
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
edit_select->x = (gint) RINT (x1) - (edit_select->x1 - edit_select->origx);
|
|
|
|
edit_select->y = (gint) RINT (y1) - (edit_select->y1 - edit_select->origy);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-02-28 10:29:25 +08:00
|
|
|
init_edit_selection (GimpTool *tool,
|
2000-12-31 12:07:42 +08:00
|
|
|
GDisplay *gdisp,
|
1997-11-25 06:05:25 +08:00
|
|
|
GdkEventButton *bevent,
|
|
|
|
EditType edit_type)
|
|
|
|
{
|
2001-02-28 10:29:25 +08:00
|
|
|
GimpEditSelectionTool *edit_select;
|
|
|
|
gint x, y;
|
|
|
|
|
|
|
|
edit_select = gtk_type_new (GIMP_TYPE_EDIT_SELECTION_TOOL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
comment typo fix, plus add %D* to default image-title-format string, so
Fri Oct 1 12:46:12 1999 Austin Donnelly <austin@gimp.org>
* gimprc.in: comment typo fix, plus add %D* to default
image-title-format string, so people get a '*' in the titlebar
if their image is dirty.
* app/fileops.c: initialise filename before using it.
* app/gdisplay.c: empty parameter list () is K&R - should be
stronger (void) in ANSI C.
* app/gimpdrawable.c: gimp_drawable_{dirty,clean} functions
removed - no one uses them anyway. Parasite undo type is
proper parasite undo type, not MISC_UNDO.
* app/gimpdrawableP.h: drawable dirty bit removed.
* app/gimpimage.c: don't change the resolution if there's no
difference from the old one. Call gdisplay_shrink_wrap() to
re-calculate scale factors and refresh the display on
resolution change. Layer undo doesn't have sub-types
anymore, uses main UndoType instead.
* app/layer.h: Remove LayerUndoType
* app/qmask.c: fix qmask undo so it actually works.
* app/undo.h: new types for undo_push_layer{,_mask} and
undo_push_qmask.
* app/undo.c: change way group boundaries are represented:
each Undo has a group_boundary boolean set to TRUE if this is
the start or the end of a group, and the type of the Undo is
the group's type. Within a group, each Undo keeps its own
type. This allows pop funcs and free funcs to do
type-specific things (eg needed by layer and channel stuff).
Don't maintain per-drawable dirty flags anymore. Floating
sel to layer and layer rename now uses meaningful undo types.
* app/undo_types.h: more specific undo types:
LAYER_{ADD,REMOVE}_UNDO, LAYER_MASK_{ADD,REMOVE}_UNDO,
LAYER_RENAME_UNDO, and PARASITE_{ATTACH,DETACH}_UNDO.
* app/undo_history.c: oops - undo stack was being placed into gtk
list in wrong order.
* app/edit_selection.c: push more descriptive LAYER_DISPLACE_UNDO
rather than MISC_UNDO.
* app/layers_dialog.c: better tagging of undo types
1999-10-02 02:43:24 +08:00
|
|
|
undo_push_group_start (gdisp->gimage, LAYER_DISPLACE_UNDO);
|
1999-03-21 23:38:11 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Move the (x, y) point from screen to image space */
|
2000-10-23 17:05:45 +08:00
|
|
|
gdisplay_untransform_coords (gdisp,
|
|
|
|
bevent->x, bevent->y, &x, &y, FALSE, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
edit_select->x = edit_select->origx = x;
|
|
|
|
edit_select->y = edit_select->origy = y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
gimage_mask_boundary (gdisp->gimage,
|
|
|
|
&edit_select->segs_in,
|
|
|
|
&edit_select->segs_out,
|
|
|
|
&edit_select->num_segs_in,
|
|
|
|
&edit_select->num_segs_out);
|
2000-06-14 05:44:48 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Make a check to see if it should be a floating selection translation */
|
2000-12-29 23:22:01 +08:00
|
|
|
if (edit_type == EDIT_MASK_TO_LAYER_TRANSLATE &&
|
|
|
|
gimp_image_floating_sel (gdisp->gimage))
|
2001-02-28 10:29:25 +08:00
|
|
|
{
|
|
|
|
edit_type = EDIT_FLOATING_SEL_TRANSLATE;
|
|
|
|
}
|
1999-05-05 17:10:35 +08:00
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
if (edit_type == EDIT_LAYER_TRANSLATE)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-28 10:29:25 +08:00
|
|
|
GimpLayer *layer;
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
layer = gimp_image_get_active_layer (gdisp->gimage);
|
2001-02-28 10:29:25 +08:00
|
|
|
|
2001-01-29 07:25:25 +08:00
|
|
|
if (gimp_layer_is_floating_sel (layer))
|
2000-10-23 17:05:45 +08:00
|
|
|
edit_type = EDIT_FLOATING_SEL_TRANSLATE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
edit_select->edit_type = edit_type;
|
1999-11-05 22:39:04 +08:00
|
|
|
|
1999-03-21 23:38:11 +08:00
|
|
|
/* find the bounding box of the selection mask -
|
2000-10-23 17:05:45 +08:00
|
|
|
* this is used for the case of a EDIT_MASK_TO_LAYER_TRANSLATE,
|
1997-11-25 06:05:25 +08:00
|
|
|
* where the translation will result in floating the selection
|
|
|
|
* mask and translating the resulting layer
|
|
|
|
*/
|
2001-01-15 05:11:52 +08:00
|
|
|
gimp_drawable_mask_bounds (gimp_image_active_drawable (gdisp->gimage),
|
2001-02-28 10:29:25 +08:00
|
|
|
&edit_select->x1, &edit_select->y1,
|
|
|
|
&edit_select->x2, &edit_select->y2);
|
|
|
|
|
|
|
|
gimp_edit_selection_tool_snap (edit_select, gdisp, bevent->x, bevent->y);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
GIMP_TOOL (edit_select)->gdisp = gdisp;
|
|
|
|
GIMP_TOOL (edit_select)->state = ACTIVE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-07-25 08:27:41 +08:00
|
|
|
g_object_ref (G_OBJECT (edit_select));
|
2001-02-28 10:29:25 +08:00
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager_push_tool (gdisp->gimage->gimp,
|
|
|
|
GIMP_TOOL (edit_select));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* pause the current selection */
|
2001-06-18 21:10:03 +08:00
|
|
|
gdisplay_selection_visibility (gdisp, SELECTION_PAUSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-07-24 02:33:01 +08:00
|
|
|
/* initialize the statusbar display */
|
2001-02-28 10:29:25 +08:00
|
|
|
edit_select->context_id
|
2000-10-23 17:05:45 +08:00
|
|
|
= gtk_statusbar_get_context_id (GTK_STATUSBAR (gdisp->statusbar),
|
|
|
|
"edit_select");
|
|
|
|
gtk_statusbar_push (GTK_STATUSBAR (gdisp->statusbar),
|
2001-02-28 10:29:25 +08:00
|
|
|
edit_select->context_id,
|
2000-10-23 17:05:45 +08:00
|
|
|
_("Move: 0, 0"));
|
1998-07-24 02:33:01 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
gimp_draw_tool_start (GIMP_DRAW_TOOL (edit_select),
|
|
|
|
gdisp->canvas->window);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
static void
|
|
|
|
gimp_edit_selection_tool_button_release (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-28 10:29:25 +08:00
|
|
|
GimpEditSelectionTool *edit_select;
|
|
|
|
gint x;
|
|
|
|
gint y;
|
|
|
|
GimpLayer *layer;
|
|
|
|
|
|
|
|
edit_select = GIMP_EDIT_SELECTION_TOOL (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* resume the current selection and ungrab the pointer */
|
2001-06-18 21:10:03 +08:00
|
|
|
gdisplay_selection_visibility (gdisp, SELECTION_RESUME);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gdk_pointer_ungrab (bevent->time);
|
|
|
|
gdk_flush ();
|
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
gtk_statusbar_pop (GTK_STATUSBAR (gdisp->statusbar), edit_select->context_id);
|
1998-07-24 02:33:01 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Stop and free the selection core */
|
2001-02-28 10:29:25 +08:00
|
|
|
gimp_draw_tool_stop (GIMP_DRAW_TOOL (edit_select));
|
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager_pop_tool (gdisp->gimage->gimp);
|
2001-02-28 10:29:25 +08:00
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
tool_manager_get_active (gdisp->gimage->gimp)->state = INACTIVE;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
/* EDIT_MASK_TRANSLATE is performed here at movement end, not 'live' like
|
1999-12-18 04:59:37 +08:00
|
|
|
* the other translation types.
|
|
|
|
*/
|
2001-02-28 10:29:25 +08:00
|
|
|
if (edit_select->edit_type == EDIT_MASK_TRANSLATE)
|
2000-02-10 22:23:11 +08:00
|
|
|
{
|
2001-02-28 10:29:25 +08:00
|
|
|
gimp_edit_selection_tool_snap (edit_select, gdisp, bevent->x, bevent->y);
|
|
|
|
|
|
|
|
x = edit_select->x;
|
|
|
|
y = edit_select->y;
|
|
|
|
|
2000-02-10 22:23:11 +08:00
|
|
|
/* move the selection -- whether there has been net movement or not!
|
|
|
|
* (to ensure that there's something on the undo stack)
|
|
|
|
*/
|
|
|
|
gimage_mask_translate (gdisp->gimage,
|
2001-02-28 10:29:25 +08:00
|
|
|
edit_select->cumlx,
|
|
|
|
edit_select->cumly);
|
|
|
|
|
|
|
|
if (edit_select->first_move)
|
2000-02-10 22:23:11 +08:00
|
|
|
{
|
|
|
|
gimp_image_undo_freeze (gdisp->gimage);
|
2001-02-28 10:29:25 +08:00
|
|
|
edit_select->first_move = FALSE;
|
2000-02-10 22:23:11 +08:00
|
|
|
}
|
|
|
|
}
|
2001-02-28 10:29:25 +08:00
|
|
|
|
1999-11-05 22:39:04 +08:00
|
|
|
/* thaw the undo again */
|
|
|
|
gimp_image_undo_thaw (gdisp->gimage);
|
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
if (edit_select->cumlx == 0 && edit_select->cumly == 0)
|
1999-04-25 04:58:55 +08:00
|
|
|
{
|
|
|
|
/* The user either didn't actually move the selection,
|
|
|
|
or moved it around and eventually just put it back in
|
|
|
|
exactly the same spot. */
|
2000-02-10 22:23:11 +08:00
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
/* If no movement occured and the type is EDIT_FLOATING_SEL_TRANSLATE,
|
1999-04-25 04:58:55 +08:00
|
|
|
check if the layer is a floating selection. If so, anchor. */
|
2001-02-28 10:29:25 +08:00
|
|
|
if (edit_select->edit_type == EDIT_FLOATING_SEL_TRANSLATE)
|
1999-04-25 04:58:55 +08:00
|
|
|
{
|
2000-12-29 23:22:01 +08:00
|
|
|
layer = gimp_image_get_active_layer (gdisp->gimage);
|
2001-02-28 10:29:25 +08:00
|
|
|
|
2001-01-29 07:25:25 +08:00
|
|
|
if (gimp_layer_is_floating_sel (layer))
|
1999-04-25 04:58:55 +08:00
|
|
|
floating_sel_anchor (layer);
|
|
|
|
}
|
|
|
|
}
|
1999-10-19 04:55:25 +08:00
|
|
|
else
|
|
|
|
{
|
2001-02-28 10:29:25 +08:00
|
|
|
path_transform_xy (gdisp->gimage, edit_select->cumlx, edit_select->cumly);
|
2000-12-11 11:33:25 +08:00
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
layer = gimp_image_get_active_layer (gdisp->gimage);
|
2001-02-05 06:10:54 +08:00
|
|
|
|
|
|
|
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (layer));
|
1999-10-19 04:55:25 +08:00
|
|
|
}
|
2001-02-28 10:29:25 +08:00
|
|
|
|
1999-03-21 23:38:11 +08:00
|
|
|
undo_push_group_end (gdisp->gimage);
|
|
|
|
|
1999-11-05 22:39:04 +08:00
|
|
|
if (bevent->state & GDK_BUTTON3_MASK) /* OPERATION CANCELLED */
|
1999-03-21 23:38:11 +08:00
|
|
|
{
|
|
|
|
/* Operation cancelled - undo the undo-group! */
|
1999-11-05 22:39:04 +08:00
|
|
|
undo_pop (gdisp->gimage);
|
1999-03-21 23:38:11 +08:00
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
gdisplays_flush ();
|
2001-02-28 10:29:25 +08:00
|
|
|
|
2001-07-25 08:27:41 +08:00
|
|
|
g_object_unref (G_OBJECT (edit_select));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
static void
|
|
|
|
gimp_edit_selection_tool_motion (GimpTool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
|
|
|
GDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-28 10:29:25 +08:00
|
|
|
GimpEditSelectionTool *edit_select;
|
|
|
|
gchar offset[STATUSBAR_SIZE];
|
|
|
|
gdouble lastmotion_x, lastmotion_y;
|
|
|
|
|
|
|
|
edit_select = GIMP_EDIT_SELECTION_TOOL (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
if (tool->state != ACTIVE)
|
1999-03-21 23:38:11 +08:00
|
|
|
{
|
2000-02-29 03:25:42 +08:00
|
|
|
g_warning ("BUG: Tracking motion while !ACTIVE");
|
1999-03-21 23:38:11 +08:00
|
|
|
return;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
gdk_flush ();
|
1999-02-07 23:16:45 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-02-29 03:25:42 +08:00
|
|
|
/* Perform motion compression so that we don't lag and/or waste time. */
|
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
if (! gtkutil_compress_motion (gtk_get_event_widget ((GdkEvent *) mevent),
|
|
|
|
&lastmotion_x,
|
|
|
|
&lastmotion_y))
|
2000-02-29 03:25:42 +08:00
|
|
|
{
|
|
|
|
lastmotion_x = mevent->x;
|
|
|
|
lastmotion_y = mevent->y;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now do the actual move. */
|
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
gimp_edit_selection_tool_snap (edit_select,
|
|
|
|
gdisp,
|
|
|
|
RINT (lastmotion_x),
|
|
|
|
RINT (lastmotion_y));
|
2000-02-29 03:25:42 +08:00
|
|
|
|
|
|
|
/******************************************* adam's live move *******/
|
1999-03-21 23:38:11 +08:00
|
|
|
/********************************************************************/
|
|
|
|
{
|
2001-01-29 07:25:25 +08:00
|
|
|
gint x, y;
|
|
|
|
GimpLayer *layer;
|
|
|
|
GimpLayer *floating_layer;
|
2001-02-19 21:06:09 +08:00
|
|
|
GList *layer_list;
|
1999-03-21 23:38:11 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
x = edit_select->x;
|
|
|
|
y = edit_select->y;
|
1999-03-21 23:38:11 +08:00
|
|
|
|
|
|
|
/* if there has been movement, move the selection */
|
2001-02-28 10:29:25 +08:00
|
|
|
if (edit_select->origx != x || edit_select->origy != y)
|
1999-03-21 23:38:11 +08:00
|
|
|
{
|
|
|
|
gint xoffset, yoffset;
|
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
xoffset = x - edit_select->origx;
|
|
|
|
yoffset = y - edit_select->origy;
|
1999-03-21 23:38:11 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
edit_select->cumlx += xoffset;
|
|
|
|
edit_select->cumly += yoffset;
|
1999-03-21 23:38:11 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
switch (edit_select->edit_type)
|
1999-03-21 23:38:11 +08:00
|
|
|
{
|
2000-10-23 17:05:45 +08:00
|
|
|
case EDIT_MASK_TRANSLATE:
|
1999-12-18 04:59:37 +08:00
|
|
|
/* we don't do the actual edit selection move here. */
|
2001-02-28 10:29:25 +08:00
|
|
|
edit_select->origx = x;
|
|
|
|
edit_select->origy = y;
|
1999-03-21 23:38:11 +08:00
|
|
|
break;
|
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
case EDIT_LAYER_TRANSLATE:
|
2000-12-29 23:22:01 +08:00
|
|
|
if ((floating_layer = gimp_image_floating_sel (gdisp->gimage)))
|
1999-03-21 23:38:11 +08:00
|
|
|
floating_sel_relax (floating_layer, TRUE);
|
1999-02-07 23:16:45 +08:00
|
|
|
|
1999-03-21 23:38:11 +08:00
|
|
|
/* translate the layer--and any "linked" layers as well */
|
2001-02-19 21:06:09 +08:00
|
|
|
for (layer_list = GIMP_LIST (gdisp->gimage->layers)->list;
|
2000-10-23 17:05:45 +08:00
|
|
|
layer_list;
|
2001-02-19 21:06:09 +08:00
|
|
|
layer_list = g_list_next (layer_list))
|
1999-03-21 23:38:11 +08:00
|
|
|
{
|
2001-01-29 07:25:25 +08:00
|
|
|
layer = (GimpLayer *) layer_list->data;
|
2001-02-19 21:06:09 +08:00
|
|
|
|
1999-03-21 23:38:11 +08:00
|
|
|
if (layer == gdisp->gimage->active_layer ||
|
2001-03-12 01:24:47 +08:00
|
|
|
gimp_layer_get_linked (layer))
|
1999-03-21 23:38:11 +08:00
|
|
|
{
|
2001-01-29 07:25:25 +08:00
|
|
|
gimp_layer_translate (layer, xoffset, yoffset);
|
1999-03-21 23:38:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (floating_layer)
|
|
|
|
floating_sel_rigor (floating_layer, TRUE);
|
1999-11-05 22:39:04 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
if (edit_select->first_move)
|
1999-11-05 22:39:04 +08:00
|
|
|
{
|
|
|
|
gimp_image_undo_freeze (gdisp->gimage);
|
2001-02-28 10:29:25 +08:00
|
|
|
edit_select->first_move = FALSE;
|
1999-11-05 22:39:04 +08:00
|
|
|
}
|
1999-03-21 23:38:11 +08:00
|
|
|
break;
|
1999-04-25 04:58:55 +08:00
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
case EDIT_MASK_TO_LAYER_TRANSLATE:
|
2001-02-28 10:29:25 +08:00
|
|
|
if (! gimage_mask_float (gdisp->gimage,
|
|
|
|
gimp_image_active_drawable (gdisp->gimage),
|
|
|
|
0, 0))
|
2000-02-10 22:43:51 +08:00
|
|
|
{
|
|
|
|
/* no region to float, abort safely */
|
2001-02-28 10:29:25 +08:00
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
|
|
|
|
|
|
|
return;
|
2000-02-10 22:43:51 +08:00
|
|
|
}
|
2000-02-10 22:23:11 +08:00
|
|
|
|
2000-02-10 22:43:51 +08:00
|
|
|
/* this is always the first move, since we switch to
|
2000-10-23 17:05:45 +08:00
|
|
|
EDIT_FLOATING_SEL_TRANSLATE when finished here */
|
2000-02-10 22:23:11 +08:00
|
|
|
gimp_image_undo_freeze (gdisp->gimage);
|
2001-02-28 10:29:25 +08:00
|
|
|
edit_select->first_move = FALSE;
|
1999-04-25 04:58:55 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
edit_select->origx -= edit_select->x1;
|
|
|
|
edit_select->origy -= edit_select->y1;
|
|
|
|
edit_select->x2 -= edit_select->x1;
|
|
|
|
edit_select->y2 -= edit_select->y1;
|
|
|
|
edit_select->x1 = 0;
|
|
|
|
edit_select->y1 = 0;
|
2000-02-10 22:23:11 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
edit_select->edit_type = EDIT_FLOATING_SEL_TRANSLATE;
|
1999-04-25 04:58:55 +08:00
|
|
|
break;
|
1999-03-21 23:38:11 +08:00
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
case EDIT_FLOATING_SEL_TRANSLATE:
|
2000-12-29 23:22:01 +08:00
|
|
|
layer = gimp_image_get_active_layer (gdisp->gimage);
|
1999-03-21 23:38:11 +08:00
|
|
|
|
|
|
|
floating_sel_relax (layer, TRUE);
|
2001-01-29 07:25:25 +08:00
|
|
|
gimp_layer_translate (layer, xoffset, yoffset);
|
1999-03-21 23:38:11 +08:00
|
|
|
floating_sel_rigor (layer, TRUE);
|
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
if (edit_select->first_move)
|
1999-11-05 22:39:04 +08:00
|
|
|
{
|
|
|
|
gimp_image_undo_freeze (gdisp->gimage);
|
2001-02-28 10:29:25 +08:00
|
|
|
|
|
|
|
edit_select->first_move = FALSE;
|
1999-11-05 22:39:04 +08:00
|
|
|
}
|
1999-03-21 23:38:11 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_warning ("esm / BAD FALLTHROUGH");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
gdisplay_flush (gdisp);
|
1999-03-21 23:38:11 +08:00
|
|
|
}
|
|
|
|
/********************************************************************/
|
|
|
|
/********************************************************************/
|
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
gtk_statusbar_pop (GTK_STATUSBAR (gdisp->statusbar), edit_select->context_id);
|
1999-02-07 23:16:45 +08:00
|
|
|
|
1999-03-04 01:48:29 +08:00
|
|
|
if (gdisp->dot_for_dot)
|
|
|
|
{
|
|
|
|
g_snprintf (offset, STATUSBAR_SIZE, gdisp->cursor_format_str,
|
|
|
|
_("Move: "),
|
2001-02-28 10:29:25 +08:00
|
|
|
edit_select->cumlx,
|
1999-03-04 01:48:29 +08:00
|
|
|
", ",
|
2001-02-28 10:29:25 +08:00
|
|
|
edit_select->cumly);
|
1999-03-04 01:48:29 +08:00
|
|
|
}
|
|
|
|
else /* show real world units */
|
|
|
|
{
|
1999-05-23 01:56:35 +08:00
|
|
|
gdouble unit_factor = gimp_unit_get_factor (gdisp->gimage->unit);
|
1999-03-04 01:48:29 +08:00
|
|
|
|
|
|
|
g_snprintf (offset, STATUSBAR_SIZE, gdisp->cursor_format_str,
|
|
|
|
_("Move: "),
|
2001-02-28 10:29:25 +08:00
|
|
|
(edit_select->cumlx) * unit_factor /
|
1999-03-04 01:48:29 +08:00
|
|
|
gdisp->gimage->xresolution,
|
|
|
|
", ",
|
2001-02-28 10:29:25 +08:00
|
|
|
(edit_select->cumly) * unit_factor /
|
1999-03-04 01:48:29 +08:00
|
|
|
gdisp->gimage->yresolution);
|
|
|
|
}
|
2001-02-28 10:29:25 +08:00
|
|
|
|
|
|
|
gtk_statusbar_push (GTK_STATUSBAR (gdisp->statusbar), edit_select->context_id,
|
1999-03-04 01:48:29 +08:00
|
|
|
offset);
|
1998-07-24 02:33:01 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2000-06-17 06:48:10 +08:00
|
|
|
static void
|
2001-02-28 10:29:25 +08:00
|
|
|
selection_transform_segs (GimpEditSelectionTool *edit_select,
|
|
|
|
GDisplay *gdisp,
|
|
|
|
BoundSeg *src_segs,
|
|
|
|
GdkSegment *dest_segs,
|
|
|
|
gint num_segs)
|
2000-06-17 06:48:10 +08:00
|
|
|
{
|
2000-10-23 17:05:45 +08:00
|
|
|
gint x, y;
|
|
|
|
gint i;
|
2000-06-17 06:48:10 +08:00
|
|
|
|
|
|
|
for (i = 0; i < num_segs; i++)
|
|
|
|
{
|
2000-10-23 17:05:45 +08:00
|
|
|
gdisplay_transform_coords (gdisp,
|
2001-02-28 10:29:25 +08:00
|
|
|
src_segs[i].x1 + edit_select->cumlx,
|
|
|
|
src_segs[i].y1 + edit_select->cumly,
|
2000-10-23 17:05:45 +08:00
|
|
|
&x, &y, FALSE);
|
2000-06-17 06:48:10 +08:00
|
|
|
|
|
|
|
dest_segs[i].x1 = x;
|
|
|
|
dest_segs[i].y1 = y;
|
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
gdisplay_transform_coords (gdisp,
|
2001-02-28 10:29:25 +08:00
|
|
|
src_segs[i].x2 + edit_select->cumlx,
|
|
|
|
src_segs[i].y2 + edit_select->cumly,
|
2000-10-23 17:05:45 +08:00
|
|
|
&x, &y, FALSE);
|
2000-06-17 06:48:10 +08:00
|
|
|
|
|
|
|
dest_segs[i].x2 = x;
|
|
|
|
dest_segs[i].y2 = y;
|
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
static void
|
|
|
|
gimp_edit_selection_tool_draw (GimpDrawTool *draw_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-28 10:29:25 +08:00
|
|
|
GimpEditSelectionTool *edit_select;
|
|
|
|
GimpTool *tool;
|
|
|
|
GDisplay *gdisp;
|
|
|
|
Selection *select;
|
|
|
|
GimpLayer *layer;
|
|
|
|
GList *layer_list;
|
|
|
|
gboolean floating_sel;
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
gint x3, y3, x4, y4;
|
|
|
|
gint off_x, off_y;
|
|
|
|
GdkSegment *segs_copy;
|
|
|
|
|
|
|
|
edit_select = GIMP_EDIT_SELECTION_TOOL (draw_tool);
|
|
|
|
tool = GIMP_TOOL (draw_tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
gdisp = tool->gdisp;
|
1997-11-25 06:05:25 +08:00
|
|
|
select = gdisp->select;
|
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
switch (edit_select->edit_type)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-10-23 17:05:45 +08:00
|
|
|
case EDIT_MASK_TRANSLATE:
|
2001-02-28 10:29:25 +08:00
|
|
|
layer = gimp_image_get_active_layer (gdisp->gimage);
|
2001-01-29 07:25:25 +08:00
|
|
|
floating_sel = gimp_layer_is_floating_sel (layer);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
if (! floating_sel)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-28 10:29:25 +08:00
|
|
|
segs_copy = g_new (GdkSegment, edit_select->num_segs_in);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
selection_transform_segs (edit_select,
|
|
|
|
gdisp,
|
|
|
|
edit_select->segs_in,
|
2000-10-23 17:05:45 +08:00
|
|
|
segs_copy,
|
2001-02-28 10:29:25 +08:00
|
|
|
edit_select->num_segs_in);
|
2000-06-17 06:48:10 +08:00
|
|
|
|
|
|
|
/* Draw the items */
|
2001-02-28 10:29:25 +08:00
|
|
|
gdk_draw_segments (draw_tool->win, draw_tool->gc,
|
2000-06-17 06:48:10 +08:00
|
|
|
segs_copy, select->num_segs_in);
|
2001-02-28 10:29:25 +08:00
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
g_free (segs_copy);
|
2000-06-17 06:48:10 +08:00
|
|
|
}
|
1999-03-21 23:38:11 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
segs_copy = g_new (GdkSegment, edit_select->num_segs_out);
|
2000-06-17 06:48:10 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
selection_transform_segs (edit_select,
|
|
|
|
gdisp,
|
|
|
|
edit_select->segs_out,
|
2000-10-23 17:05:45 +08:00
|
|
|
segs_copy,
|
2001-02-28 10:29:25 +08:00
|
|
|
edit_select->num_segs_out);
|
|
|
|
|
2000-06-17 06:48:10 +08:00
|
|
|
/* Draw the items */
|
2001-02-28 10:29:25 +08:00
|
|
|
gdk_draw_segments (draw_tool->win, draw_tool->gc,
|
2000-06-17 06:48:10 +08:00
|
|
|
segs_copy, select->num_segs_out);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
g_free (segs_copy);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
case EDIT_MASK_TO_LAYER_TRANSLATE:
|
|
|
|
gdisplay_transform_coords (gdisp,
|
2001-02-28 10:29:25 +08:00
|
|
|
edit_select->x1, edit_select->y1,
|
2000-10-23 17:05:45 +08:00
|
|
|
&x1, &y1, TRUE);
|
|
|
|
gdisplay_transform_coords (gdisp,
|
2001-02-28 10:29:25 +08:00
|
|
|
edit_select->x2, edit_select->y2,
|
2000-10-23 17:05:45 +08:00
|
|
|
&x2, &y2, TRUE);
|
2001-02-28 10:29:25 +08:00
|
|
|
gdk_draw_rectangle (draw_tool->win,
|
|
|
|
draw_tool->gc, 0,
|
2000-02-10 22:23:11 +08:00
|
|
|
x1, y1,
|
|
|
|
x2 - x1 + 1, y2 - y1 + 1);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
case EDIT_LAYER_TRANSLATE:
|
1997-11-25 06:05:25 +08:00
|
|
|
gdisplay_transform_coords (gdisp, 0, 0, &x1, &y1, TRUE);
|
2001-01-15 05:11:52 +08:00
|
|
|
gdisplay_transform_coords
|
|
|
|
(gdisp,
|
|
|
|
gimp_drawable_width (GIMP_DRAWABLE (gdisp->gimage->active_layer)),
|
|
|
|
gimp_drawable_height (GIMP_DRAWABLE (gdisp->gimage->active_layer)),
|
|
|
|
&x2, &y2, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Now, expand the rectangle to include all linked layers as well */
|
2001-02-19 21:06:09 +08:00
|
|
|
for (layer_list= GIMP_LIST (gdisp->gimage->layers)->list;
|
2000-10-23 17:05:45 +08:00
|
|
|
layer_list;
|
2001-02-19 21:06:09 +08:00
|
|
|
layer_list = g_list_next (layer_list))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-29 07:25:25 +08:00
|
|
|
layer = (GimpLayer *) layer_list->data;
|
2001-02-19 21:06:09 +08:00
|
|
|
|
2001-01-29 07:25:25 +08:00
|
|
|
if (((layer) != gdisp->gimage->active_layer) &&
|
2001-03-12 01:24:47 +08:00
|
|
|
gimp_layer_get_linked (layer))
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-01-15 05:11:52 +08:00
|
|
|
gimp_drawable_offsets (GIMP_DRAWABLE (layer), &off_x, &off_y);
|
1998-01-22 15:02:57 +08:00
|
|
|
gdisplay_transform_coords (gdisp, off_x, off_y, &x3, &y3, FALSE);
|
2001-01-15 05:11:52 +08:00
|
|
|
gdisplay_transform_coords
|
|
|
|
(gdisp,
|
|
|
|
off_x + gimp_drawable_width (GIMP_DRAWABLE (layer)),
|
|
|
|
off_y + gimp_drawable_height (GIMP_DRAWABLE (layer)),
|
|
|
|
&x4, &y4, FALSE);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
if (x3 < x1)
|
|
|
|
x1 = x3;
|
|
|
|
if (y3 < y1)
|
|
|
|
y1 = y3;
|
|
|
|
if (x4 > x2)
|
|
|
|
x2 = x4;
|
|
|
|
if (y4 > y2)
|
|
|
|
y2 = y4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
gdk_draw_rectangle (draw_tool->win,
|
|
|
|
draw_tool->gc, 0,
|
2000-02-10 22:23:11 +08:00
|
|
|
x1, y1,
|
1999-11-05 22:39:04 +08:00
|
|
|
x2 - x1, y2 - y1);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
case EDIT_FLOATING_SEL_TRANSLATE:
|
2001-02-28 10:29:25 +08:00
|
|
|
segs_copy = g_new (GdkSegment, edit_select->num_segs_in);
|
2000-06-14 05:44:48 +08:00
|
|
|
|
2000-06-17 06:48:10 +08:00
|
|
|
/* The selection segs are in image space convert these
|
|
|
|
* to display space.
|
|
|
|
* Takes care of offset/zoom etc etc.
|
|
|
|
*/
|
2000-02-10 22:43:51 +08:00
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
selection_transform_segs (edit_select,
|
|
|
|
gdisp,
|
|
|
|
edit_select->segs_in,
|
2000-10-23 17:05:45 +08:00
|
|
|
segs_copy,
|
2001-02-28 10:29:25 +08:00
|
|
|
edit_select->num_segs_in);
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Draw the items */
|
2001-02-28 10:29:25 +08:00
|
|
|
gdk_draw_segments (draw_tool->win, draw_tool->gc,
|
2000-06-17 06:48:10 +08:00
|
|
|
segs_copy, select->num_segs_in);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
g_free (segs_copy);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
static void
|
|
|
|
gimp_edit_selection_tool_control (GimpTool *tool,
|
|
|
|
ToolAction action,
|
|
|
|
GDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
switch (action)
|
|
|
|
{
|
2000-06-14 18:59:16 +08:00
|
|
|
case PAUSE:
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
1999-06-22 06:12:07 +08:00
|
|
|
|
2000-06-14 18:59:16 +08:00
|
|
|
case RESUME:
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
1999-06-22 06:12:07 +08:00
|
|
|
|
2000-06-14 18:59:16 +08:00
|
|
|
case HALT:
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
1999-06-22 06:12:07 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2001-02-28 10:29:25 +08:00
|
|
|
|
|
|
|
if (GIMP_TOOL_CLASS (parent_class)->control)
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->control (tool, action, gdisp);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-28 10:29:25 +08:00
|
|
|
static void
|
|
|
|
gimp_edit_selection_tool_cursor_update (GimpTool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
|
|
|
GDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-25 03:29:47 +08:00
|
|
|
gdisplay_install_tool_cursor (gdisp,
|
|
|
|
GIMP_MOUSE_CURSOR,
|
|
|
|
GIMP_TOOL_CURSOR_NONE,
|
|
|
|
GIMP_CURSOR_MODIFIER_MOVE);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2000-02-10 22:23:11 +08:00
|
|
|
static gint
|
2000-10-23 17:05:45 +08:00
|
|
|
process_event_queue_keys (GdkEventKey *kevent,
|
|
|
|
...)
|
1998-07-20 22:05:33 +08:00
|
|
|
/* GdkKeyType, GdkModifierType, value ... 0
|
|
|
|
* could move this function to a more central location so it can be used
|
|
|
|
* by other tools? */
|
|
|
|
{
|
|
|
|
#define FILTER_MAX_KEYS 50
|
2000-12-29 23:22:01 +08:00
|
|
|
va_list argp;
|
|
|
|
GdkEvent *event;
|
|
|
|
GList *event_list = NULL;
|
|
|
|
GList *list;
|
|
|
|
guint keys[FILTER_MAX_KEYS];
|
|
|
|
GdkModifierType modifiers[FILTER_MAX_KEYS];
|
|
|
|
gint values[FILTER_MAX_KEYS];
|
|
|
|
gint i = 0, nkeys = 0, value = 0;
|
|
|
|
gboolean done = FALSE;
|
|
|
|
gboolean discard_event;
|
|
|
|
GtkWidget *orig_widget;
|
1998-07-20 22:05:33 +08:00
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
va_start (argp, kevent);
|
1998-07-20 22:05:33 +08:00
|
|
|
while (nkeys <FILTER_MAX_KEYS && (keys[nkeys] = va_arg (argp, guint)) != 0)
|
2000-10-23 17:05:45 +08:00
|
|
|
{
|
|
|
|
modifiers[nkeys] = va_arg (argp, GdkModifierType);
|
|
|
|
values[nkeys] = va_arg (argp, gint);
|
|
|
|
nkeys++;
|
|
|
|
}
|
1998-07-20 22:05:33 +08:00
|
|
|
va_end(argp);
|
|
|
|
|
|
|
|
for (i = 0; i < nkeys; i++)
|
2000-10-23 17:05:45 +08:00
|
|
|
{
|
|
|
|
if (kevent->keyval == keys[i] && kevent->state == modifiers[i])
|
|
|
|
value += values[i];
|
|
|
|
}
|
1998-07-20 22:05:33 +08:00
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
orig_widget = gtk_get_event_widget ((GdkEvent*) kevent);
|
1998-07-20 22:05:33 +08:00
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
while (gdk_events_pending () > 0 && !done)
|
1998-07-20 22:05:33 +08:00
|
|
|
{
|
2000-10-23 17:05:45 +08:00
|
|
|
discard_event = FALSE;
|
|
|
|
event = gdk_event_get ();
|
|
|
|
|
|
|
|
if (!event || orig_widget != gtk_get_event_widget (event))
|
|
|
|
{
|
|
|
|
done = TRUE;
|
|
|
|
}
|
1998-07-20 22:05:33 +08:00
|
|
|
else
|
|
|
|
{
|
2000-10-23 17:05:45 +08:00
|
|
|
if (event->any.type == GDK_KEY_PRESS)
|
1998-07-20 22:05:33 +08:00
|
|
|
{
|
2000-10-23 17:05:45 +08:00
|
|
|
for (i = 0; i < nkeys; i++)
|
|
|
|
if (event->key.keyval == keys[i] &&
|
|
|
|
event->key.state == modifiers[i])
|
|
|
|
{
|
|
|
|
discard_event = TRUE;
|
|
|
|
value += values[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!discard_event)
|
|
|
|
done = TRUE;
|
1998-07-20 22:05:33 +08:00
|
|
|
}
|
|
|
|
/* should there be more types here? */
|
2000-10-23 17:05:45 +08:00
|
|
|
else if (event->any.type != GDK_KEY_RELEASE &&
|
|
|
|
event->any.type != GDK_MOTION_NOTIFY &&
|
|
|
|
event->any.type != GDK_EXPOSE)
|
|
|
|
done = FALSE;
|
|
|
|
}
|
1998-07-20 22:05:33 +08:00
|
|
|
|
2000-03-09 02:32:31 +08:00
|
|
|
if (!event)
|
|
|
|
; /* Do nothing */
|
|
|
|
else if (!discard_event)
|
2000-10-23 17:05:45 +08:00
|
|
|
event_list = g_list_prepend (event_list, event);
|
1998-07-20 22:05:33 +08:00
|
|
|
else
|
2000-10-23 17:05:45 +08:00
|
|
|
gdk_event_free (event);
|
1998-07-20 22:05:33 +08:00
|
|
|
}
|
2000-10-23 17:05:45 +08:00
|
|
|
|
|
|
|
event_list = g_list_reverse (event_list);
|
|
|
|
|
|
|
|
/* unget the unused events and free the list */
|
|
|
|
for (list = event_list;
|
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
|
|
|
gdk_event_put ((GdkEvent*)list->data);
|
|
|
|
gdk_event_free ((GdkEvent*)list->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (event_list);
|
|
|
|
|
1998-07-20 22:05:33 +08:00
|
|
|
return value;
|
|
|
|
#undef FILTER_MAX_KEYS
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-02-28 10:53:27 +08:00
|
|
|
void
|
2001-02-28 10:29:25 +08:00
|
|
|
gimp_edit_selection_tool_arrow_key (GimpTool *tool,
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
GDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-28 10:53:27 +08:00
|
|
|
gint inc_x, inc_y, mask_inc_x, mask_inc_y;
|
|
|
|
GimpLayer *layer;
|
|
|
|
GimpLayer *floating_layer;
|
|
|
|
GList *layer_list;
|
|
|
|
EditType edit_type;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
layer = NULL;
|
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
inc_x =
|
|
|
|
process_event_queue_keys (kevent,
|
|
|
|
GDK_Left, 0, -1,
|
|
|
|
GDK_Left, GDK_SHIFT_MASK, -1 * ARROW_VELOCITY,
|
|
|
|
GDK_Right, 0, 1,
|
|
|
|
GDK_Right, GDK_SHIFT_MASK, 1 * ARROW_VELOCITY,
|
|
|
|
0);
|
|
|
|
inc_y =
|
|
|
|
process_event_queue_keys (kevent,
|
|
|
|
GDK_Up, 0, -1,
|
|
|
|
GDK_Up, GDK_SHIFT_MASK, -1 * ARROW_VELOCITY,
|
|
|
|
GDK_Down, 0, 1,
|
|
|
|
GDK_Down, GDK_SHIFT_MASK, 1 * ARROW_VELOCITY,
|
|
|
|
0);
|
|
|
|
|
|
|
|
mask_inc_x =
|
|
|
|
process_event_queue_keys (kevent,
|
|
|
|
GDK_Left, GDK_MOD1_MASK, -1,
|
|
|
|
GDK_Left, (GDK_MOD1_MASK | GDK_SHIFT_MASK), -1 * ARROW_VELOCITY,
|
|
|
|
GDK_Right, GDK_MOD1_MASK, 1,
|
|
|
|
GDK_Right, (GDK_MOD1_MASK | GDK_SHIFT_MASK), 1 * ARROW_VELOCITY,
|
|
|
|
0);
|
|
|
|
mask_inc_y =
|
|
|
|
process_event_queue_keys (kevent,
|
|
|
|
GDK_Up, GDK_MOD1_MASK, -1,
|
|
|
|
GDK_Up, (GDK_MOD1_MASK | GDK_SHIFT_MASK), -1 * ARROW_VELOCITY,
|
|
|
|
GDK_Down, GDK_MOD1_MASK, 1,
|
|
|
|
GDK_Down, (GDK_MOD1_MASK | GDK_SHIFT_MASK), 1 * ARROW_VELOCITY,
|
|
|
|
0);
|
|
|
|
|
1998-07-20 22:05:33 +08:00
|
|
|
if (inc_x == 0 && inc_y == 0 && mask_inc_x == 0 && mask_inc_y == 0)
|
|
|
|
return;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-11-05 22:39:04 +08:00
|
|
|
undo_push_group_start (gdisp->gimage, LAYER_DISPLACE_UNDO);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-07-20 22:05:33 +08:00
|
|
|
if (mask_inc_x != 0 || mask_inc_y != 0)
|
|
|
|
gimage_mask_translate (gdisp->gimage, mask_inc_x, mask_inc_y);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-07-20 22:05:33 +08:00
|
|
|
if (inc_x != 0 || inc_y != 0)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-12-29 23:22:01 +08:00
|
|
|
layer = gimp_image_get_active_layer (gdisp->gimage);
|
2000-10-23 17:05:45 +08:00
|
|
|
|
2001-01-29 07:25:25 +08:00
|
|
|
if (gimp_layer_is_floating_sel (layer))
|
2000-10-23 17:05:45 +08:00
|
|
|
edit_type = EDIT_FLOATING_SEL_TRANSLATE;
|
|
|
|
else
|
|
|
|
edit_type = EDIT_LAYER_TRANSLATE;
|
|
|
|
|
|
|
|
switch (edit_type)
|
|
|
|
{
|
|
|
|
case EDIT_MASK_TRANSLATE:
|
|
|
|
case EDIT_MASK_TO_LAYER_TRANSLATE:
|
|
|
|
/* this won't happen */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EDIT_LAYER_TRANSLATE:
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
if ((floating_layer = gimp_image_floating_sel (gdisp->gimage)))
|
2000-10-23 17:05:45 +08:00
|
|
|
floating_sel_relax (floating_layer, TRUE);
|
|
|
|
|
|
|
|
/* translate the layer -- and any "linked" layers as well */
|
2001-02-19 21:06:09 +08:00
|
|
|
for (layer_list = GIMP_LIST (gdisp->gimage->layers)->list;
|
2000-10-23 17:05:45 +08:00
|
|
|
layer_list;
|
2001-02-19 21:06:09 +08:00
|
|
|
layer_list = g_list_next (layer_list))
|
2000-10-23 17:05:45 +08:00
|
|
|
{
|
2001-01-29 07:25:25 +08:00
|
|
|
layer = (GimpLayer *) layer_list->data;
|
2001-02-19 21:06:09 +08:00
|
|
|
|
2000-10-23 17:05:45 +08:00
|
|
|
if (((layer) == gdisp->gimage->active_layer) ||
|
2001-03-12 01:24:47 +08:00
|
|
|
gimp_layer_get_linked (layer))
|
2000-10-23 17:05:45 +08:00
|
|
|
{
|
2001-01-29 07:25:25 +08:00
|
|
|
gimp_layer_translate (layer, inc_x, inc_y);
|
2000-10-23 17:05:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (floating_layer)
|
|
|
|
floating_sel_rigor (floating_layer, TRUE);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EDIT_FLOATING_SEL_TRANSLATE:
|
|
|
|
|
|
|
|
floating_sel_relax (layer, TRUE);
|
|
|
|
|
2001-01-29 07:25:25 +08:00
|
|
|
gimp_layer_translate (layer, inc_x, inc_y);
|
2000-10-23 17:05:45 +08:00
|
|
|
|
|
|
|
floating_sel_rigor (layer, TRUE);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2000-10-23 17:05:45 +08:00
|
|
|
|
1998-07-20 22:05:33 +08:00
|
|
|
undo_push_group_end (gdisp->gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
gdisplays_flush ();
|
|
|
|
}
|
2001-05-14 05:51:20 +08:00
|
|
|
|
|
|
|
/***************************************************************/
|
|
|
|
/* gtkutil_compress_motion:
|
|
|
|
|
|
|
|
This function walks the whole GDK event queue seeking motion events
|
|
|
|
corresponding to the widget 'widget'. If it finds any it will
|
|
|
|
remove them from the queue, write the most recent motion offset
|
|
|
|
to 'lastmotion_x' and 'lastmotion_y', then return TRUE. Otherwise
|
|
|
|
it will return FALSE and 'lastmotion_x' / 'lastmotion_y' will be
|
|
|
|
untouched.
|
|
|
|
*/
|
|
|
|
/* The gtkutil_compress_motion function source may be re-used under
|
|
|
|
the XFree86-style license. <adam@gimp.org> */
|
|
|
|
gboolean
|
|
|
|
gtkutil_compress_motion (GtkWidget *widget,
|
|
|
|
gdouble *lastmotion_x,
|
|
|
|
gdouble *lastmotion_y)
|
|
|
|
{
|
|
|
|
GdkEvent *event;
|
|
|
|
GList *requeued_events = NULL;
|
|
|
|
GList *list;
|
|
|
|
gboolean success = FALSE;
|
|
|
|
|
|
|
|
/* Move the entire GDK event queue to a private list, filtering
|
|
|
|
out any motion events for the desired widget. */
|
|
|
|
while (gdk_events_pending ())
|
|
|
|
{
|
|
|
|
event = gdk_event_get ();
|
|
|
|
|
|
|
|
if (!event)
|
|
|
|
{
|
|
|
|
/* Do nothing */
|
|
|
|
}
|
|
|
|
else if ((gtk_get_event_widget (event) == widget) &&
|
|
|
|
(event->any.type == GDK_MOTION_NOTIFY))
|
|
|
|
{
|
|
|
|
*lastmotion_x = event->motion.x;
|
|
|
|
*lastmotion_y = event->motion.y;
|
|
|
|
|
|
|
|
gdk_event_free (event);
|
|
|
|
success = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
requeued_events = g_list_prepend (requeued_events, event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Replay the remains of our private event list back into the
|
|
|
|
event queue in order. */
|
|
|
|
|
|
|
|
requeued_events = g_list_reverse (requeued_events);
|
|
|
|
|
|
|
|
for (list = requeued_events; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
gdk_event_put ((GdkEvent*) list->data);
|
|
|
|
gdk_event_free ((GdkEvent*) list->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (requeued_events);
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|