gimp/app/tools/gimpmovetool.c
Michael Natterer 02fde14c95 build display/ before tools/.
2001-11-08  Michael Natterer  <mitch@gimp.org>

	* app/Makefile.am: build display/ before tools/.

	* app/devices.c: devices_check_change(): added all events
	which have a GdkDevice pointer.

	* app/gimpprogress.c: include "display-types.h" instead of
	"core-types.h".

	* app/core/Makefile.am
	* app/core/gimpdrawable-bucket-fill.[ch]: new files: the bucket_fill
	stuff taken from tools/gimpbucketfilltool.[ch].

	* app/core/core-types.h: added "BucketFillMode".

	* app/core/gimpimage-mask-select.[ch]: cleanup.

	* app/core/gimpmarshal.list: added more marshallers for GimpTool's
	new signal signatures.

	* app/core/gimpmarshal.[ch]: regenerated.

	* app/display/Makefile.am
	* app/display/gimpdisplayshell-dnd.[ch]
	* app/display/gimpdisplayshell-layer-select.[ch]: new files: the
	canvas drop callbacks from gimpdisplayshell-callbacks.[ch] and
	the stuff formerly knows as gui/layer-select.[ch].

	* app/display/gimpdisplay.h: don't include "gui/gui-types.h".

	* app/display/gximage.c: include "display-types.h".

	* app/display/gimpdisplay-foreach.c
	* app/display/gimpdisplayshell.[ch]: call gdsplay_delete(), don't
	destroy the shell widget.

	* app/gui/Makefile.am
	* app/gui/layer-select.[ch]: removed.

	* app/gui/gradients-commands.c: fixed "Save as POV" fprintf()s.

	* app/gui/preferences-dialog.c: removed the layer_select stuff
	because it is useless with the new preview system.

	* app/gui/tool-options-dialog.c: send the correct data to the
	close_callback.

	* app/gui/tools-commands.c: changed to follow the new
	gimp_tool_initialize() semantics (see below).

	Tool & canvas event handling chainsawing:

	* app/tools/tools-types.h: new struct GimpCoords which contains
	x, y, pressure, tilt etc.

	* app/display/gimpdisplayshell-callbacks.[ch]: added utility
	functions which transparently retreive the current event's
	GimpCoords or take it from the device directly if the event has
	none. Pass GimpCoords _in_image_coordinates_ to all tool
	functions.

	Most important: don't pass GdkEvents and display coordinates to
	tools any more.

	* app/tools/gimptool.[ch]: changed virtual functions to take
	GimpCoords, time and state separately instead of GdkEvents.

	* app/tools/gimpbezierselecttool.c
	* app/tools/gimpblendtool.c
	* app/tools/gimpbucketfilltool.[ch]
	* app/tools/gimpbycolorselecttool.c
	* app/tools/gimpclonetool.c
	* app/tools/gimpcolorpickertool.c
	* app/tools/gimpconvolvetool.c
	* app/tools/gimpcroptool.[ch]
	* app/tools/gimpcurvestool.c
	* app/tools/gimpdodgeburntool.c
	* app/tools/gimpdrawtool.c
	* app/tools/gimpeditselectiontool.[ch]
	* app/tools/gimperasertool.c
	* app/tools/gimpfliptool.c
	* app/tools/gimpfreeselecttool.[ch]
	* app/tools/gimpfuzzyselecttool.c
	* app/tools/gimpinktool.c
	* app/tools/gimpiscissorstool.c
	* app/tools/gimpmagnifytool.c
	* app/tools/gimpmeasuretool.c
	* app/tools/gimpmovetool.c
	* app/tools/gimppainttool.c
	* app/tools/gimppathtool.[ch]
	* app/tools/gimprectselecttool.c
	* app/tools/gimprotatetool.c
	* app/tools/gimpselectiontool.[ch]
	* app/tools/gimpsmudgetool.c
	* app/tools/gimptexttool.c
	* app/tools/gimptransformtool.[ch]
	* app/tools/path_tool.[ch]
	* app/tools/selection_options.c: tons and tons of changes:

	- changed to use the new virtual function parameters.
	- removed zillions of gdisplay_untransform_coords().
	- get the active drawable's offsets manually in many cases.
	  (questionable, but IMHO ok because it's obvious and not simply a
	  "TRUE" passed to some function)
	- reordered some functions to be consistent across tools.
	- some tools had to be changed to work on image coords, not
	  display ones (esp. crop).
	- fixed strange rotate tool behaviour which should be backported
	  to stable.
	- some stuff i came across.
	- indentation and other paranoia.
	- rounding of coordinated may be broken in some tools.
	- new bugs guaranteed.

	* app/tools/tool_manager.[ch]: new semantic of
	tool_manager_initialize_active() (looked at the places where it
	was used from and put common code together). Should be a bit
	better now :)

	* app/tools/gimpblendtool.c
	* app/tools/transform_options.c: use the new GTK+ feature that a
	widget (toggle button) can be a frame's title for this tools' tool
	options.

	* app/widgets/widgets-types.h: stuff.

	* themes/Default/gtkrc: s/GtkDialog/GimpDialog/.

	* tools/pdbgen/Makefile.am: don't scan tools/gimpbucketfilltool.h
	any more.

	* tools/pdbgen/enums.pl: regenerated.

	* tools/pdbgen/pdb/tools.pdb: changed bucket_fill wrapper.

	* app/pdb/tools_cmds.c: regenerated.
2001-11-08 19:14:51 +00:00

637 lines
17 KiB
C

/* 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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <stdlib.h>
#include <gtk/gtk.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "tools-types.h"
#include "core/gimpimage.h"
#include "core/gimpimage-mask.h"
#include "core/gimplayer.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplay-foreach.h"
#include "display/gimpdisplayshell.h"
#include "gimpeditselectiontool.h"
#include "gimpmovetool.h"
#include "tool_manager.h"
#include "tool_options.h"
#include "colormaps.h"
#include "floating_sel.h"
#include "undo.h"
#include "libgimp/gimpintl.h"
static void gimp_move_tool_class_init (GimpMoveToolClass *klass);
static void gimp_move_tool_init (GimpMoveTool *move_tool);
static void move_tool_control (GimpTool *tool,
ToolAction tool_action,
GimpDisplay *gdisp);
static void move_tool_button_press (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp);
static void move_tool_button_release (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp);
static void move_tool_motion (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp);
static void move_tool_cursor_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
GimpDisplay *gdisp);
static void move_create_gc (GimpDisplay *gdisp);
static void move_draw_guide (GimpDisplay *gdisp,
GimpGuide *guide);
/* the move tool options */
static GimpToolOptions *move_options = NULL;
/* local variables */
static GdkGC *move_gc = NULL;
static GimpToolClass *parent_class = NULL;
void
gimp_move_tool_register (Gimp *gimp)
{
tool_manager_register_tool (gimp,
GIMP_TYPE_MOVE_TOOL,
FALSE,
"gimp:move_tool",
_("Move Tool"),
_("Move layers & selections"),
N_("/Tools/Transform Tools/Move"), "M",
NULL, "tools/move.html",
GIMP_STOCK_TOOL_MOVE);
}
GType
gimp_move_tool_get_type (void)
{
static GType tool_type = 0;
if (! tool_type)
{
static const GTypeInfo tool_info =
{
sizeof (GimpMoveToolClass),
(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,
};
tool_type = g_type_register_static (GIMP_TYPE_TOOL,
"GimpMoveTool",
&tool_info, 0);
}
return tool_type;
}
static void
gimp_move_tool_class_init (GimpMoveToolClass *klass)
{
GimpToolClass *tool_class;
tool_class = GIMP_TOOL_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
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->arrow_key = gimp_edit_selection_tool_arrow_key;
tool_class->cursor_update = move_tool_cursor_update;
}
static void
gimp_move_tool_init (GimpMoveTool *move_tool)
{
GimpTool *tool;
tool = GIMP_TOOL (move_tool);
/* The tool options */
if (! move_options)
{
move_options = tool_options_new ();
tool_manager_register_tool_options (GIMP_TYPE_MOVE_TOOL,
(GimpToolOptions *) move_options);
}
move_tool->layer = NULL;
move_tool->guide = NULL;
move_tool->disp = NULL;
tool->tool_cursor = GIMP_MOVE_TOOL_CURSOR;
tool->auto_snap_to = FALSE; /* Don't snap to guides */
}
static void
move_tool_control (GimpTool *tool,
ToolAction action,
GimpDisplay *gdisp)
{
GimpMoveTool *move_tool;
move_tool = GIMP_MOVE_TOOL (tool);
switch (action)
{
case PAUSE:
break;
case RESUME:
if (move_tool->guide)
gimp_display_shell_draw_guide (GIMP_DISPLAY_SHELL (gdisp->shell),
move_tool->guide, TRUE);
break;
case HALT:
if (move_tool->guide)
gimp_display_shell_draw_guide (GIMP_DISPLAY_SHELL (gdisp->shell),
move_tool->guide, FALSE);
break;
default:
break;
}
if (GIMP_TOOL_CLASS (parent_class)->control)
GIMP_TOOL_CLASS (parent_class)->control (tool, action, gdisp);
}
static void
move_tool_button_press (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp)
{
GimpMoveTool *move;
GimpDisplayShell *shell;
GimpLayer *layer;
GimpGuide *guide;
move = GIMP_MOVE_TOOL (tool);
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
tool->gdisp = gdisp;
move->layer = NULL;
move->guide = NULL;
move->disp = NULL;
if ((state & GDK_MOD1_MASK) && ! gimage_mask_is_empty (gdisp->gimage))
{
init_edit_selection (tool, gdisp, coords, EDIT_MASK_TRANSLATE);
tool->state = ACTIVE;
}
else if (state & GDK_SHIFT_MASK)
{
init_edit_selection (tool, gdisp, coords, EDIT_LAYER_TRANSLATE);
tool->state = ACTIVE;
}
else
{
if (gdisp->draw_guides &&
(guide = gimp_image_find_guide (gdisp->gimage, coords->x, coords->y)))
{
undo_push_guide (gdisp->gimage, guide);
gdisplays_expose_guide (gdisp->gimage, guide);
gimp_image_remove_guide (gdisp->gimage, guide);
gdisplay_flush (gdisp);
gimp_image_add_guide (gdisp->gimage, guide);
move->guide = guide;
move->disp = gdisp;
tool->scroll_lock = TRUE;
tool->state = ACTIVE;
move_draw_guide (gdisp, move->guide);
}
else if ((layer = gimp_image_pick_correlate_layer (gdisp->gimage,
coords->x,
coords->y)))
{
/* If there is a floating selection, and this aint it,
* use the move tool
*/
if (gimp_image_floating_sel (gdisp->gimage) &&
! gimp_layer_is_floating_sel (layer))
{
move->layer = gimp_image_floating_sel (gdisp->gimage);
}
/* Otherwise, init the edit selection */
else
{
gimp_image_set_active_layer (gdisp->gimage, layer);
init_edit_selection (tool, gdisp, coords, EDIT_LAYER_TRANSLATE);
}
tool->state = ACTIVE;
}
}
/* if we've got an active tool grab the pointer */
if (tool->state == ACTIVE)
{
gdk_pointer_grab (shell->canvas->window, FALSE,
GDK_POINTER_MOTION_HINT_MASK |
GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK,
NULL, NULL, time);
}
}
static void
move_tool_button_release (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp)
{
GimpMoveTool *move;
gboolean delete_guide;
gint x1, y1;
gint x2, y2;
move = GIMP_MOVE_TOOL (tool);
tool->state = INACTIVE;
gdk_pointer_ungrab (time);
gdk_flush ();
if (move->guide)
{
GimpDisplayShell *shell;
shell = GIMP_DISPLAY_SHELL (tool->gdisp->shell);
tool->scroll_lock = FALSE;
delete_guide = FALSE;
gdisplay_untransform_coords (gdisp,
0, 0,
&x1, &y1,
FALSE, FALSE);
gdisplay_untransform_coords (gdisp,
shell->disp_width, shell->disp_height,
&x2, &y2,
FALSE, FALSE);
if (x1 < 0) x1 = 0;
if (y1 < 0) y1 = 0;
if (x2 > gdisp->gimage->width) x2 = gdisp->gimage->width;
if (y2 > gdisp->gimage->height) y2 = gdisp->gimage->height;
switch (move->guide->orientation)
{
case ORIENTATION_HORIZONTAL:
if ((move->guide->position < y1) || (move->guide->position > y2))
delete_guide = TRUE;
break;
case ORIENTATION_VERTICAL:
if ((move->guide->position < x1) || (move->guide->position > x2))
delete_guide = TRUE;
break;
default:
break;
}
gdisplays_expose_guide (gdisp->gimage, move->guide);
move_draw_guide (gdisp, move->guide);
if (delete_guide)
{
gimp_image_delete_guide (gdisp->gimage, move->guide);
move->guide = NULL;
move->disp = NULL;
}
gdisplay_selection_visibility (gdisp, GIMP_SELECTION_RESUME);
gdisplays_flush ();
if (move->guide)
gimp_display_shell_draw_guide (shell, move->guide, TRUE);
}
else
{
/* Take care of the case where the user "cancels" the action */
if (! (state & GDK_BUTTON3_MASK))
{
if (move->layer)
{
floating_sel_anchor (move->layer);
gdisplays_flush ();
}
}
}
}
static void
move_tool_motion (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp)
{
GimpMoveTool *move;
move = GIMP_MOVE_TOOL (tool);
if (move->guide)
{
GimpDisplayShell *shell;
gint tx, ty;
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
move_draw_guide (gdisp, move->guide);
gdisplay_transform_coords (gdisp,
coords->x, coords->y,
&tx, &ty,
FALSE);
if (tx < 0 ||
ty < 0 ||
tx >= shell->disp_width ||
ty >= shell->disp_height)
{
move->guide->position = -1;
}
else
{
if (move->guide->orientation == ORIENTATION_HORIZONTAL)
move->guide->position = ROUND (coords->y);
else
move->guide->position = ROUND (coords->x);
move_draw_guide (gdisp, move->guide);
}
}
}
static void
move_tool_cursor_update (GimpTool *tool,
GimpCoords *coords,
GdkModifierType state,
GimpDisplay *gdisp)
{
GimpMoveTool *move;
GimpDisplayShell *shell;
GimpGuide *guide;
GimpLayer *layer;
move = GIMP_MOVE_TOOL (tool);
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
if ((state & GDK_MOD1_MASK) && ! gimage_mask_is_empty (gdisp->gimage))
{
gimp_display_shell_install_tool_cursor (shell,
GIMP_MOUSE_CURSOR,
GIMP_RECT_SELECT_TOOL_CURSOR,
GIMP_CURSOR_MODIFIER_MOVE);
}
else if (state & GDK_SHIFT_MASK)
{
gimp_display_shell_install_tool_cursor (shell,
GIMP_MOUSE_CURSOR,
GIMP_MOVE_TOOL_CURSOR,
GIMP_CURSOR_MODIFIER_NONE);
}
else
{
if (gdisp->draw_guides &&
(guide = gimp_image_find_guide (gdisp->gimage, coords->x, coords->y)))
{
tool->gdisp = gdisp;
gimp_display_shell_install_tool_cursor (shell,
GDK_HAND2,
GIMP_TOOL_CURSOR_NONE,
GIMP_CURSOR_MODIFIER_HAND);
if (tool->state != ACTIVE)
{
if (move->guide)
{
gdisp = gdisplays_check_valid (move->disp, move->disp->gimage);
if (gdisp)
{
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
gimp_display_shell_draw_guide (shell, move->guide, FALSE);
}
}
gimp_display_shell_draw_guide (shell, guide, TRUE);
move->guide = guide;
move->disp = gdisp;
}
}
else if ((layer = gimp_image_pick_correlate_layer (gdisp->gimage,
coords->x, coords->y)))
{
/* if there is a floating selection, and this aint it... */
if (gimp_image_floating_sel (gdisp->gimage) &&
! gimp_layer_is_floating_sel (layer))
{
gimp_display_shell_install_tool_cursor (shell,
GIMP_MOUSE_CURSOR,
GIMP_RECT_SELECT_TOOL_CURSOR,
GIMP_CURSOR_MODIFIER_ANCHOR);
}
else if (layer == gimp_image_get_active_layer (gdisp->gimage))
{
gimp_display_shell_install_tool_cursor (shell,
GIMP_MOUSE_CURSOR,
GIMP_MOVE_TOOL_CURSOR,
GIMP_CURSOR_MODIFIER_NONE);
}
else
{
gimp_display_shell_install_tool_cursor (shell,
GDK_HAND2,
GIMP_TOOL_CURSOR_NONE,
GIMP_CURSOR_MODIFIER_HAND);
}
}
else
{
gimp_display_shell_install_tool_cursor (shell,
GIMP_BAD_CURSOR,
GIMP_MOVE_TOOL_CURSOR,
GIMP_CURSOR_MODIFIER_NONE);
}
}
}
static void
move_create_gc (GimpDisplay *gdisp)
{
if (! move_gc)
{
GimpDisplayShell *shell;
GdkGCValues values;
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
values.foreground.pixel = g_white_pixel;
values.function = GDK_INVERT;
move_gc = gdk_gc_new_with_values (shell->canvas->window, &values,
GDK_GC_FUNCTION);
}
}
static void
move_draw_guide (GimpDisplay *gdisp,
GimpGuide *guide)
{
GimpDisplayShell *shell;
gint x1, y1;
gint x2, y2;
gint w, h;
gint x, y;
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
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);
w = shell->canvas->allocation.width;
h = shell->canvas->allocation.height;
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;
gdk_draw_line (shell->canvas->window, move_gc, x1, y, x2, y);
break;
case ORIENTATION_VERTICAL:
gdisplay_transform_coords (gdisp, guide->position, 0, &x, &y1, FALSE);
if (y1 < 0) y1 = 0;
if (y2 > h) y2 = h;
gdk_draw_line (shell->canvas->window, move_gc, x, y1, x, y2);
break;
default:
g_warning ("mdg / BAD FALLTHROUGH");
break;
}
}
void
gimp_move_tool_start_hguide (GimpTool *tool,
GimpDisplay *gdisp)
{
GimpMoveTool *move;
move = GIMP_MOVE_TOOL (tool);
gdisplay_selection_visibility (gdisp, GIMP_SELECTION_PAUSE);
tool->gdisp = gdisp;
tool->scroll_lock = TRUE;
if (move->guide && move->disp && move->disp->gimage)
gimp_display_shell_draw_guide (GIMP_DISPLAY_SHELL (move->disp->shell),
move->guide, FALSE);
move->guide = gimp_image_add_hguide (gdisp->gimage);
move->disp = gdisp;
tool->state = ACTIVE;
undo_push_guide (gdisp->gimage, move->guide);
}
void
gimp_move_tool_start_vguide (GimpTool *tool,
GimpDisplay *gdisp)
{
GimpMoveTool *move;
move = GIMP_MOVE_TOOL (tool);
gdisplay_selection_visibility (gdisp, GIMP_SELECTION_PAUSE);
tool->gdisp = gdisp;
tool->scroll_lock = TRUE;
if (move->guide && move->disp && move->disp->gimage)
gimp_display_shell_draw_guide (GIMP_DISPLAY_SHELL (move->disp->shell),
move->guide, FALSE);
move->guide = gimp_image_add_vguide (gdisp->gimage);
move->disp = gdisp;
tool->state = ACTIVE;
undo_push_guide (gdisp->gimage, move->guide);
}