gimp/app/tools/gimpmovetool.c

513 lines
12 KiB
C
Raw Normal View History

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
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1997-11-25 06:05:25 +08:00
*/
#include <stdlib.h>
1997-11-25 06:05:25 +08:00
#include "appenv.h"
#include "cursorutil.h"
1997-11-25 06:05:25 +08:00
#include "draw_core.h"
#include "edit_selection.h"
#include "floating_sel.h"
#include "gimage_mask.h"
#include "gdisplay.h"
#include "gdisplay_ops.h"
#include "move.h"
#include "undo.h"
2000-02-01 07:59:05 +08:00
#include "config.h"
#include "libgimp/gimpintl.h"
/* the move structures */
1997-11-25 06:05:25 +08:00
typedef struct _MoveTool MoveTool;
1997-11-25 06:05:25 +08:00
struct _MoveTool
{
Layer *layer;
Guide *guide;
GDisplay *disp;
1997-11-25 06:05:25 +08:00
};
app/airbrush.c app/bezier_select.c app/blend.c app/brightness_contrast.c 1999-04-12 Michael Natterer <mitschel@cs.tu-berlin.de> * app/airbrush.c * app/bezier_select.c * app/blend.c * app/brightness_contrast.c * app/bucket_fill.c * app/by_color_select.c * app/clone.c * app/color_balance.c * app/color_picker.c * app/convolve.c * app/crop.c * app/curves.c * app/ellipse_select.c * app/eraser.c * app/flip_tool.c * app/free_select.c * app/fuzzy_select.c * app/histogram_tool.c * app/hue_saturation.c * app/ink.c * app/iscissors.c * app/levels.c * app/magnify.c * app/move.c * app/paintbrush.c * app/pencil.c * app/posterize.c * app/rect_select.[ch] * app/text_tool.c * app/threshold.c * app/transform_tool.c * app/tools.[ch] * app/toolsF.h: again: all tools :( * app/Makefile.am * app/tool_options.[ch] * app/selection_options.h * app/tool_options_ui.h: new files. Ok, this time it's general enough for future extensions: - The tool options structures are organized like the gtk object system to allow derived tool options. - Renamed all create and reset functions to *_options_new() and *_options_reset() to reflect this. - Changed tools_register() again. Now it takes just a pointer to a ToolOptions structure. - Moved almost the entire tool options gui code to tool_options.c. - Visually separated the common selection options from the tool-specific ones. I'd like to do the same with opacity/paint mode in all paint tool options but I think this needs some more discussion. * app/histogram_tool.c: changed packing boxes, label alignments. * app/paintbrush.c: some more sensitive settings. The gradient feature can now be toggled with a button. Hopefully didn't break anything.
1999-04-13 01:55:06 +08:00
/* the move tool options */
static ToolOptions *move_options = NULL;
/* local variables */
static GdkGC *move_gc = NULL;
1997-11-25 06:05:25 +08:00
/* move tool action functions */
static void move_tool_button_press (Tool *, GdkEventButton *, gpointer);
static void move_tool_button_release (Tool *, GdkEventButton *, gpointer);
static void move_tool_motion (Tool *, GdkEventMotion *, gpointer);
static void move_tool_cursor_update (Tool *, GdkEventMotion *, gpointer);
static void move_tool_control (Tool *, ToolAction, gpointer);
namespace cleanups. 1999-06-21 Michael Natterer <mitschel@cs.tu-berlin.de> * app/context_manager.c: namespace cleanups. * app/commands.[ch] * app/menus.c: moved the "Toggle Selection" menu entry to "View", sprinkled some separators and made the layers/channels/paths popup menus consistent with Tigert's last ops buttons change. * app/fileops.c * app/plug_in.c: check for gdisplay_active() returning NULL in some more places. * app/[all tool related files]: - Turned the ToolAction and ToolState #define's into typedef'ed enums, so the compiler can do some more sanity checking. - Removed one more unused global variable "active_tool_layer". - Removed some #include's from tools.c. - Standardized the individual tools' structure names. - Moved showing/hiding the tool options to separate functions. - Stuff... * app/commands.c * app/disp_callbacks.c * app/gdisplay.c * app/tools.c: fixed the segfaults which happened when the image of one of the tools which have dialogs (levels/posterize/...) was deleted. My approach was to do stricter sanity checking and to set some gdisplay pointers correctly where appropriate, so I can't tell exactly where the bug was. The curves tool now(??) updates on every _second_ display change only, which is really obscure. Finding/changing the display to operate on should definitely be done by connecting to the user context's "display_changed" signal. * app/gimpset.c: emit the "remove" signal _after_ removing the pointer from the set. If this was not a bug but a feature, please let me know, we'll need two signals then.
1999-06-22 06:12:07 +08:00
static void move_create_gc (GDisplay *gdisp);
1997-11-25 06:05:25 +08:00
/* move action functions */
static void
move_tool_button_press (Tool *tool,
GdkEventButton *bevent,
gpointer gdisp_ptr)
{
GDisplay *gdisp;
MoveTool *move;
Layer *layer;
Guide *guide;
gint x, y;
1997-11-25 06:05:25 +08:00
gdisp = (GDisplay *) gdisp_ptr;
move = (MoveTool *) tool->private;
tool->gdisp_ptr = gdisp_ptr;
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
gdisplay_untransform_coords (gdisp, bevent->x, bevent->y, &x, &y, FALSE, FALSE);
if (bevent->state & GDK_MOD1_MASK &&
!gimage_mask_is_empty (gdisp->gimage))
1997-11-25 06:05:25 +08:00
{
init_edit_selection (tool, gdisp_ptr, bevent, MaskTranslate);
tool->state = ACTIVE;
}
else if (bevent->state & GDK_SHIFT_MASK)
{
init_edit_selection (tool, gdisp_ptr, bevent, LayerTranslate);
tool->state = ACTIVE;
}
else
{
if (gdisp->draw_guides &&
(guide = gdisplay_find_guide (gdisp, bevent->x, bevent->y)))
1997-11-25 06:05:25 +08:00
{
undo_push_guide (gdisp->gimage, guide);
gdisplays_expose_guide (gdisp->gimage, guide);
1997-11-25 06:05:25 +08:00
gimage_remove_guide (gdisp->gimage, guide);
gdisplay_flush (gdisp);
gimage_add_guide (gdisp->gimage, guide);
move->guide = guide;
move->disp = gdisp;
1997-11-25 06:05:25 +08:00
tool->scroll_lock = TRUE;
tool->state = ACTIVE;
1997-11-25 06:05:25 +08:00
move_tool_motion (tool, NULL, gdisp);
}
else if ((layer = gimage_pick_correlate_layer (gdisp->gimage, x, y)))
{
/* If there is a floating selection, and this aint it,
* use the move tool
*/
if (gimage_floating_sel (gdisp->gimage) &&
!layer_is_floating_sel (layer))
{
move->layer = gimage_floating_sel (gdisp->gimage);
}
1997-11-25 06:05:25 +08:00
/* Otherwise, init the edit selection */
else
{
gimage_set_active_layer (gdisp->gimage, layer);
1997-11-25 06:05:25 +08:00
init_edit_selection (tool, gdisp_ptr, bevent, LayerTranslate);
}
tool->state = ACTIVE;
}
}
/* if we've got an active tool grab the pointer */
if (tool->state == ACTIVE)
{
gdk_pointer_grab (gdisp->canvas->window, FALSE,
GDK_POINTER_MOTION_HINT_MASK |
GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK,
NULL, NULL, bevent->time);
}
1997-11-25 06:05:25 +08:00
}
static void
1999-10-14 07:07:45 +08:00
move_draw_guide (GDisplay *gdisp,
Guide *guide)
{
gint x1, y1;
gint x2, y2;
gint w, h;
gint x, y;
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);
gdk_window_get_size (gdisp->canvas->window, &w, &h);
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 (gdisp->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 (gdisp->canvas->window, move_gc, x, y1, x, y2);
break;
default:
g_warning ("mdg / BAD FALLTHROUGH");
}
}
static void
1997-11-25 06:05:25 +08:00
move_tool_button_release (Tool *tool,
GdkEventButton *bevent,
gpointer gdisp_ptr)
{
MoveTool *move;
GDisplay *gdisp;
gboolean delete_guide;
gint x1, y1;
gint x2, y2;
1997-11-25 06:05:25 +08:00
gdisp = (GDisplay *) gdisp_ptr;
move = (MoveTool *) tool->private;
gdk_flush ();
tool->state = INACTIVE;
gdk_pointer_ungrab (bevent->time);
if (move->guide)
{
tool->scroll_lock = FALSE;
1999-10-14 07:07:45 +08:00
delete_guide = FALSE;
1997-11-25 06:05:25 +08:00
gdisplay_untransform_coords (gdisp, 0, 0, &x1, &y1, FALSE, FALSE);
gdisplay_untransform_coords (gdisp, gdisp->disp_width, gdisp->disp_height,
&x2, &y2, FALSE, FALSE);
1997-11-25 06:05:25 +08:00
if (x1 < 0) x1 = 0;
if (y1 < 0) y1 = 0;
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)
{
add sample_colorize and curve_bend defs * plug-ins/common/plugin-defs.pl: add sample_colorize and curve_bend defs * libgimp/color_selector.h: minor consistency cleanup * libgimp/gimpchainbutton.[ch]: use new style gtk object helper macros * libgimp/gimpfileselection.c * libgimp/gimpmatrix.h: minor cleanup * libgimp/gimpintl.h: resync with gnome-i18n.h * libgimp/color_display.h * app/gimp.sym * app/gdisplay_color.[ch] * app/app_procs.c * app/gdisplay.h * app/image_render.c: color display transformation code. Still unfinished, so it's not activated yet. * app/buildmenu.h: remove unused defines (PULLDOWN, POPUP, OPTION) * app/colormaps.[ch] * app/image_render.c: remove vestigal dithering stuff * app/convolve.h * app/gimpdrawable.h * app/gimpimage.h * app/lut_funcs.h * app/paint_funcs.h * app/plug_in.h: enum nick changes from Marc * app/channel_ops.c * app/crop.c * app/gdisplay.c * app/gimpimage.[ch] * app/move.c: s/([A-Z]+)_GUIDE/ORIENTATION_$1/ * app/flip_tool.[ch] * app/shear_tool.[ch]: use ORIENTATION_* constants instead of our own * app/disp_callbacks.c: remove HORIZONTAL and VERTICAL #defines * app/general.h: enumified TOKEN_* symbols * app/lc_dialog.c * app/paint_funcs.c: remove unused variables * tools/pdbgen/lib.pl: autogen gimpenums.h (unfinished) * tools/pdbgen/stddefs.pdb: new std_orientation_enum, remove layer_mode shortcut since we've skipped it in app/ * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/drawable.pdb * tools/pdbgen/pdb/gimage.pdb * tools/pdbgen/pdb/guides.pdb * tools/pdbgen/pdb/layer.pdb * tools/pdbgen/pdb/tools.pdb: reflect above enum changes, whitespace cleanups * tools/pdbgen/enums.pl * app/brush_select_cmds.c * app/brushes_cmds.c * app/color_cmds.c * app/drawable_cmds.c * app/gimage_cmds.c * app/layer_cmds.c * app/procedural_db_cmds.c * app/tools_cmds.c: reflect pdb and enum nick changes above -Yosh
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;
add sample_colorize and curve_bend defs * plug-ins/common/plugin-defs.pl: add sample_colorize and curve_bend defs * libgimp/color_selector.h: minor consistency cleanup * libgimp/gimpchainbutton.[ch]: use new style gtk object helper macros * libgimp/gimpfileselection.c * libgimp/gimpmatrix.h: minor cleanup * libgimp/gimpintl.h: resync with gnome-i18n.h * libgimp/color_display.h * app/gimp.sym * app/gdisplay_color.[ch] * app/app_procs.c * app/gdisplay.h * app/image_render.c: color display transformation code. Still unfinished, so it's not activated yet. * app/buildmenu.h: remove unused defines (PULLDOWN, POPUP, OPTION) * app/colormaps.[ch] * app/image_render.c: remove vestigal dithering stuff * app/convolve.h * app/gimpdrawable.h * app/gimpimage.h * app/lut_funcs.h * app/paint_funcs.h * app/plug_in.h: enum nick changes from Marc * app/channel_ops.c * app/crop.c * app/gdisplay.c * app/gimpimage.[ch] * app/move.c: s/([A-Z]+)_GUIDE/ORIENTATION_$1/ * app/flip_tool.[ch] * app/shear_tool.[ch]: use ORIENTATION_* constants instead of our own * app/disp_callbacks.c: remove HORIZONTAL and VERTICAL #defines * app/general.h: enumified TOKEN_* symbols * app/lc_dialog.c * app/paint_funcs.c: remove unused variables * tools/pdbgen/lib.pl: autogen gimpenums.h (unfinished) * tools/pdbgen/stddefs.pdb: new std_orientation_enum, remove layer_mode shortcut since we've skipped it in app/ * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/drawable.pdb * tools/pdbgen/pdb/gimage.pdb * tools/pdbgen/pdb/guides.pdb * tools/pdbgen/pdb/layer.pdb * tools/pdbgen/pdb/tools.pdb: reflect above enum changes, whitespace cleanups * tools/pdbgen/enums.pl * app/brush_select_cmds.c * app/brushes_cmds.c * app/color_cmds.c * app/drawable_cmds.c * app/gimage_cmds.c * app/layer_cmds.c * app/procedural_db_cmds.c * app/tools_cmds.c: reflect pdb and enum nick changes above -Yosh
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;
}
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
{
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;
move->disp = NULL;
1997-11-25 06:05:25 +08:00
}
else
{
move_tool_motion (tool, NULL, gdisp_ptr);
}
selection_resume (gdisp->select);
gdisplays_flush ();
if (move->guide)
gdisplay_draw_guide (gdisp, move->guide, TRUE);
}
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 ();
}
}
}
}
static void
1997-11-25 06:05:25 +08:00
move_tool_motion (Tool *tool,
GdkEventMotion *mevent,
gpointer gdisp_ptr)
1997-11-25 06:05:25 +08:00
{
MoveTool *move;
1997-11-25 06:05:25 +08:00
GDisplay *gdisp;
gint x, y;
1997-11-25 06:05:25 +08:00
move = (MoveTool *) tool->private;
gdisp = (GDisplay *) gdisp_ptr;
1997-11-25 06:05:25 +08:00
if (move->guide)
1997-11-25 06:05:25 +08:00
{
move_draw_guide (gdisp, move->guide);
if (mevent && mevent->window != gdisp->canvas->window)
{
move->guide->position = -1;
return;
}
if (mevent)
1997-11-25 06:05:25 +08:00
{
gdisplay_untransform_coords (gdisp, mevent->x, mevent->y,
&x, &y, TRUE, FALSE);
if (move->guide->orientation == ORIENTATION_HORIZONTAL)
move->guide->position = y;
else
move->guide->position = x;
move_draw_guide (gdisp, move->guide);
1997-11-25 06:05:25 +08:00
}
}
}
static void
1997-11-25 06:05:25 +08:00
move_tool_cursor_update (Tool *tool,
GdkEventMotion *mevent,
gpointer gdisp_ptr)
{
MoveTool *move;
GDisplay *gdisp;
Guide *guide;
Layer *layer;
gint x, y;
1997-11-25 06:05:25 +08:00
move = (MoveTool *) tool->private;
1997-11-25 06:05:25 +08:00
gdisp = (GDisplay *) gdisp_ptr;
gdisplay_untransform_coords (gdisp, mevent->x, mevent->y, &x, &y,
FALSE, FALSE);
if (mevent->state & GDK_MOD1_MASK &&
!gimage_mask_is_empty (gdisp->gimage))
{
gdisplay_install_tool_cursor (gdisp, GIMP_SELECTION_MOVE_CURSOR);
}
1997-11-25 06:05:25 +08:00
else if (mevent->state & GDK_SHIFT_MASK)
{
gdisplay_install_tool_cursor (gdisp, GDK_FLEUR);
}
1997-11-25 06:05:25 +08:00
else
{
if (gdisp->draw_guides &&
(guide = gdisplay_find_guide (gdisp, mevent->x, mevent->y)))
1997-11-25 06:05:25 +08:00
{
tool->gdisp_ptr = gdisp_ptr;
gdisplay_install_tool_cursor (gdisp, GDK_HAND2);
if (tool->state != ACTIVE)
{
if (move->guide)
{
1999-10-14 07:07:45 +08:00
gdisp = gdisplays_check_valid (move->disp, move->disp->gimage);
1997-11-25 06:05:25 +08:00
if (gdisp)
gdisplay_draw_guide (gdisp, move->guide, FALSE);
}
gdisp = gdisp_ptr;
gdisplay_draw_guide (gdisp, guide, TRUE);
move->guide = guide;
move->disp = gdisp;
1997-11-25 06:05:25 +08:00
}
}
else if ((layer = gimage_pick_correlate_layer (gdisp->gimage, x, y)))
{
/* if there is a floating selection, and this aint it... */
if (gimage_floating_sel (gdisp->gimage) &&
!layer_is_floating_sel (layer))
1997-11-25 06:05:25 +08:00
gdisplay_install_tool_cursor (gdisp, GDK_SB_DOWN_ARROW);
else if (layer == gdisp->gimage->active_layer)
1997-11-25 06:05:25 +08:00
gdisplay_install_tool_cursor (gdisp, GDK_FLEUR);
else
gdisplay_install_tool_cursor (gdisp, GDK_HAND2);
}
else
{
gdisplay_install_tool_cursor (gdisp, GDK_TOP_LEFT_ARROW);
}
1997-11-25 06:05:25 +08:00
}
}
static void
namespace cleanups. 1999-06-21 Michael Natterer <mitschel@cs.tu-berlin.de> * app/context_manager.c: namespace cleanups. * app/commands.[ch] * app/menus.c: moved the "Toggle Selection" menu entry to "View", sprinkled some separators and made the layers/channels/paths popup menus consistent with Tigert's last ops buttons change. * app/fileops.c * app/plug_in.c: check for gdisplay_active() returning NULL in some more places. * app/[all tool related files]: - Turned the ToolAction and ToolState #define's into typedef'ed enums, so the compiler can do some more sanity checking. - Removed one more unused global variable "active_tool_layer". - Removed some #include's from tools.c. - Standardized the individual tools' structure names. - Moved showing/hiding the tool options to separate functions. - Stuff... * app/commands.c * app/disp_callbacks.c * app/gdisplay.c * app/tools.c: fixed the segfaults which happened when the image of one of the tools which have dialogs (levels/posterize/...) was deleted. My approach was to do stricter sanity checking and to set some gdisplay pointers correctly where appropriate, so I can't tell exactly where the bug was. The curves tool now(??) updates on every _second_ display change only, which is really obscure. Finding/changing the display to operate on should definitely be done by connecting to the user context's "display_changed" signal. * app/gimpset.c: emit the "remove" signal _after_ removing the pointer from the set. If this was not a bug but a feature, please let me know, we'll need two signals then.
1999-06-22 06:12:07 +08:00
move_tool_control (Tool *tool,
ToolAction action,
gpointer gdisp_ptr)
1997-11-25 06:05:25 +08:00
{
MoveTool *move;
move = tool->private;
switch (action)
{
namespace cleanups. 1999-06-21 Michael Natterer <mitschel@cs.tu-berlin.de> * app/context_manager.c: namespace cleanups. * app/commands.[ch] * app/menus.c: moved the "Toggle Selection" menu entry to "View", sprinkled some separators and made the layers/channels/paths popup menus consistent with Tigert's last ops buttons change. * app/fileops.c * app/plug_in.c: check for gdisplay_active() returning NULL in some more places. * app/[all tool related files]: - Turned the ToolAction and ToolState #define's into typedef'ed enums, so the compiler can do some more sanity checking. - Removed one more unused global variable "active_tool_layer". - Removed some #include's from tools.c. - Standardized the individual tools' structure names. - Moved showing/hiding the tool options to separate functions. - Stuff... * app/commands.c * app/disp_callbacks.c * app/gdisplay.c * app/tools.c: fixed the segfaults which happened when the image of one of the tools which have dialogs (levels/posterize/...) was deleted. My approach was to do stricter sanity checking and to set some gdisplay pointers correctly where appropriate, so I can't tell exactly where the bug was. The curves tool now(??) updates on every _second_ display change only, which is really obscure. Finding/changing the display to operate on should definitely be done by connecting to the user context's "display_changed" signal. * app/gimpset.c: emit the "remove" signal _after_ removing the pointer from the set. If this was not a bug but a feature, please let me know, we'll need two signals then.
1999-06-22 06:12:07 +08:00
case PAUSE:
1997-11-25 06:05:25 +08:00
break;
namespace cleanups. 1999-06-21 Michael Natterer <mitschel@cs.tu-berlin.de> * app/context_manager.c: namespace cleanups. * app/commands.[ch] * app/menus.c: moved the "Toggle Selection" menu entry to "View", sprinkled some separators and made the layers/channels/paths popup menus consistent with Tigert's last ops buttons change. * app/fileops.c * app/plug_in.c: check for gdisplay_active() returning NULL in some more places. * app/[all tool related files]: - Turned the ToolAction and ToolState #define's into typedef'ed enums, so the compiler can do some more sanity checking. - Removed one more unused global variable "active_tool_layer". - Removed some #include's from tools.c. - Standardized the individual tools' structure names. - Moved showing/hiding the tool options to separate functions. - Stuff... * app/commands.c * app/disp_callbacks.c * app/gdisplay.c * app/tools.c: fixed the segfaults which happened when the image of one of the tools which have dialogs (levels/posterize/...) was deleted. My approach was to do stricter sanity checking and to set some gdisplay pointers correctly where appropriate, so I can't tell exactly where the bug was. The curves tool now(??) updates on every _second_ display change only, which is really obscure. Finding/changing the display to operate on should definitely be done by connecting to the user context's "display_changed" signal. * app/gimpset.c: emit the "remove" signal _after_ removing the pointer from the set. If this was not a bug but a feature, please let me know, we'll need two signals then.
1999-06-22 06:12:07 +08:00
case RESUME:
1997-11-25 06:05:25 +08:00
if (move->guide)
gdisplay_draw_guide (gdisp_ptr, move->guide, TRUE);
break;
namespace cleanups. 1999-06-21 Michael Natterer <mitschel@cs.tu-berlin.de> * app/context_manager.c: namespace cleanups. * app/commands.[ch] * app/menus.c: moved the "Toggle Selection" menu entry to "View", sprinkled some separators and made the layers/channels/paths popup menus consistent with Tigert's last ops buttons change. * app/fileops.c * app/plug_in.c: check for gdisplay_active() returning NULL in some more places. * app/[all tool related files]: - Turned the ToolAction and ToolState #define's into typedef'ed enums, so the compiler can do some more sanity checking. - Removed one more unused global variable "active_tool_layer". - Removed some #include's from tools.c. - Standardized the individual tools' structure names. - Moved showing/hiding the tool options to separate functions. - Stuff... * app/commands.c * app/disp_callbacks.c * app/gdisplay.c * app/tools.c: fixed the segfaults which happened when the image of one of the tools which have dialogs (levels/posterize/...) was deleted. My approach was to do stricter sanity checking and to set some gdisplay pointers correctly where appropriate, so I can't tell exactly where the bug was. The curves tool now(??) updates on every _second_ display change only, which is really obscure. Finding/changing the display to operate on should definitely be done by connecting to the user context's "display_changed" signal. * app/gimpset.c: emit the "remove" signal _after_ removing the pointer from the set. If this was not a bug but a feature, please let me know, we'll need two signals then.
1999-06-22 06:12:07 +08:00
case HALT:
break;
default:
1997-11-25 06:05:25 +08:00
break;
}
}
static void
move_create_gc (GDisplay *gdisp)
{
if (!move_gc)
{
GdkGCValues values;
values.foreground.pixel = gdisplay_white_pixel (gdisp);
values.function = GDK_INVERT;
move_gc = gdk_gc_new_with_values (gdisp->canvas->window, &values,
GDK_GC_FUNCTION);
1997-11-25 06:05:25 +08:00
}
}
void
move_tool_start_hguide (Tool *tool,
GDisplay *gdisp)
1997-11-25 06:05:25 +08:00
{
MoveTool *private;
selection_pause (gdisp->select);
tool->gdisp_ptr = gdisp;
tool->scroll_lock = TRUE;
private = tool->private;
1999-10-14 07:07:45 +08:00
if (private->guide && private->disp && private->disp->gimage)
gdisplay_draw_guide (private->disp, private->guide, FALSE);
1997-11-25 06:05:25 +08:00
private->guide = gimage_add_hguide (gdisp->gimage);
1999-10-14 07:07:45 +08:00
private->disp = gdisp;
1997-11-25 06:05:25 +08:00
tool->state = ACTIVE;
undo_push_guide (gdisp->gimage, private->guide);
}
void
move_tool_start_vguide (Tool *tool,
GDisplay *gdisp)
1997-11-25 06:05:25 +08:00
{
MoveTool *private;
selection_pause (gdisp->select);
tool->gdisp_ptr = gdisp;
tool->scroll_lock = TRUE;
private = tool->private;
1999-10-14 07:07:45 +08:00
if (private->guide && private->disp && private->disp->gimage)
gdisplay_draw_guide (private->disp, private->guide, FALSE);
1997-11-25 06:05:25 +08:00
private->guide = gimage_add_vguide (gdisp->gimage);
1999-10-14 07:07:45 +08:00
private->disp = gdisp;
1997-11-25 06:05:25 +08:00
tool->state = ACTIVE;
undo_push_guide (gdisp->gimage, private->guide);
}
Tool *
tools_new_move_tool (void)
1997-11-25 06:05:25 +08:00
{
Tool *tool;
MoveTool *private;
1997-11-25 06:05:25 +08:00
app/airbrush.c app/bezier_select.c app/blend.c app/brightness_contrast.c 1999-04-12 Michael Natterer <mitschel@cs.tu-berlin.de> * app/airbrush.c * app/bezier_select.c * app/blend.c * app/brightness_contrast.c * app/bucket_fill.c * app/by_color_select.c * app/clone.c * app/color_balance.c * app/color_picker.c * app/convolve.c * app/crop.c * app/curves.c * app/ellipse_select.c * app/eraser.c * app/flip_tool.c * app/free_select.c * app/fuzzy_select.c * app/histogram_tool.c * app/hue_saturation.c * app/ink.c * app/iscissors.c * app/levels.c * app/magnify.c * app/move.c * app/paintbrush.c * app/pencil.c * app/posterize.c * app/rect_select.[ch] * app/text_tool.c * app/threshold.c * app/transform_tool.c * app/tools.[ch] * app/toolsF.h: again: all tools :( * app/Makefile.am * app/tool_options.[ch] * app/selection_options.h * app/tool_options_ui.h: new files. Ok, this time it's general enough for future extensions: - The tool options structures are organized like the gtk object system to allow derived tool options. - Renamed all create and reset functions to *_options_new() and *_options_reset() to reflect this. - Changed tools_register() again. Now it takes just a pointer to a ToolOptions structure. - Moved almost the entire tool options gui code to tool_options.c. - Visually separated the common selection options from the tool-specific ones. I'd like to do the same with opacity/paint mode in all paint tool options but I think this needs some more discussion. * app/histogram_tool.c: changed packing boxes, label alignments. * app/paintbrush.c: some more sensitive settings. The gradient feature can now be toggled with a button. Hopefully didn't break anything.
1999-04-13 01:55:06 +08:00
/* The tool options */
1997-11-25 06:05:25 +08:00
if (! move_options)
{
move_options = tool_options_new (_("Move Tool"));
app/airbrush.c app/bezier_select.c app/blend.c app/brightness_contrast.c 1999-04-12 Michael Natterer <mitschel@cs.tu-berlin.de> * app/airbrush.c * app/bezier_select.c * app/blend.c * app/brightness_contrast.c * app/bucket_fill.c * app/by_color_select.c * app/clone.c * app/color_balance.c * app/color_picker.c * app/convolve.c * app/crop.c * app/curves.c * app/ellipse_select.c * app/eraser.c * app/flip_tool.c * app/free_select.c * app/fuzzy_select.c * app/histogram_tool.c * app/hue_saturation.c * app/ink.c * app/iscissors.c * app/levels.c * app/magnify.c * app/move.c * app/paintbrush.c * app/pencil.c * app/posterize.c * app/rect_select.[ch] * app/text_tool.c * app/threshold.c * app/transform_tool.c * app/tools.[ch] * app/toolsF.h: again: all tools :( * app/Makefile.am * app/tool_options.[ch] * app/selection_options.h * app/tool_options_ui.h: new files. Ok, this time it's general enough for future extensions: - The tool options structures are organized like the gtk object system to allow derived tool options. - Renamed all create and reset functions to *_options_new() and *_options_reset() to reflect this. - Changed tools_register() again. Now it takes just a pointer to a ToolOptions structure. - Moved almost the entire tool options gui code to tool_options.c. - Visually separated the common selection options from the tool-specific ones. I'd like to do the same with opacity/paint mode in all paint tool options but I think this needs some more discussion. * app/histogram_tool.c: changed packing boxes, label alignments. * app/paintbrush.c: some more sensitive settings. The gradient feature can now be toggled with a button. Hopefully didn't break anything.
1999-04-13 01:55:06 +08:00
tools_register (MOVE, (ToolOptions *) move_options);
}
1997-11-25 06:05:25 +08:00
tool = tools_new_tool (MOVE);
private = g_new (MoveTool, 1);
1997-11-25 06:05:25 +08:00
private->layer = NULL;
private->guide = NULL;
private->disp = NULL;
tool->auto_snap_to = FALSE; /* Don't snap to guides */
tool->private = (void *) private;
tool->button_press_func = move_tool_button_press;
1997-11-25 06:05:25 +08:00
tool->button_release_func = move_tool_button_release;
tool->motion_func = move_tool_motion;
tool->arrow_keys_func = edit_sel_arrow_keys_func;
tool->cursor_update_func = move_tool_cursor_update;
tool->control_func = move_tool_control;
1997-11-25 06:05:25 +08:00
return tool;
}
void
tools_free_move_tool (Tool *tool)
{
MoveTool *move;
1997-11-25 06:05:25 +08:00
move = (MoveTool *) tool->private;
if (tool->gdisp_ptr)
{
if (move->guide)
gdisplay_draw_guide (tool->gdisp_ptr, move->guide, FALSE);
}
g_free (move);
}