1997-11-24 22:05:25 +00: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 05:44:11 +00:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-24 22:05:25 +00:00
|
|
|
*/
|
2000-07-29 16:12:40 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
#include <stdlib.h>
|
2000-07-29 16:12:40 +00:00
|
|
|
|
2000-12-16 21:37:03 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
|
2001-05-21 13:58:46 +00:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2001-01-24 22:36:18 +00:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2001-05-09 22:34:59 +00:00
|
|
|
#include "tools-types.h"
|
2000-03-28 23:39:32 +00:00
|
|
|
|
2001-05-09 02:32:03 +00:00
|
|
|
#include "core/gimpchannel.h"
|
|
|
|
#include "core/gimpimage.h"
|
2001-11-10 14:17:01 +00:00
|
|
|
#include "core/gimpimage-crop.h"
|
2001-05-09 02:32:03 +00:00
|
|
|
#include "core/gimpimage-mask.h"
|
2001-10-22 12:13:44 +00:00
|
|
|
#include "core/gimpimage-mask-select.h"
|
2002-02-21 22:19:45 +00:00
|
|
|
#include "core/gimplayer-floating-sel.h"
|
2001-05-09 02:32:03 +00:00
|
|
|
#include "core/gimpmarshal.h"
|
2001-05-09 22:34:59 +00:00
|
|
|
#include "core/gimptoolinfo.h"
|
2001-05-09 02:32:03 +00:00
|
|
|
|
2001-09-25 23:23:09 +00:00
|
|
|
#include "display/gimpdisplay.h"
|
2003-02-25 02:13:03 +00:00
|
|
|
#include "display/gimpdisplayshell.h"
|
2001-09-25 23:23:09 +00:00
|
|
|
|
2001-03-08 04:15:32 +00:00
|
|
|
#include "gimpeditselectiontool.h"
|
|
|
|
#include "gimprectselecttool.h"
|
2003-02-08 21:12:03 +00:00
|
|
|
#include "gimpselectionoptions.h"
|
2003-04-15 16:05:52 +00:00
|
|
|
#include "gimptoolcontrol.h"
|
2000-07-29 16:12:40 +00:00
|
|
|
|
2003-03-25 16:38:19 +00:00
|
|
|
#include "gimp-intl.h"
|
Lots of ii8n stuff here and some additions to the de.po. Applied
Wed Oct 14 17:46:15 EDT 1998 Adrian Likins <adrian@gimp.org>
* app/*, po/de.po, de/POTFILES.in, libgimp/gimpintl.h:
Lots of ii8n stuff here and some additions to the de.po.
Applied gimp-egger-981005-1 ,gimp-egger-981006-1,
gimp-egger-981007-1, gimp-egger-981008-1,
gimp-egger-981009-1.patch, gimp-egger-981010-1.patch
* plug-in/guillotine/guillotine.c: added the coordinates
of the split images from the original image to the title.
ie foo.jpg (0,0) for the image in the topleft.
* plug-in/script-fu/scripts/neon-logo.scm,
perspective-shadow.scm, predator.scm,rendermap.scm,
ripply-anim.scm, select_to_image.scm,swirltile.scm,
xach-effect.scm: updated scripts to use new script-fu stuff
wooo boy! a big un!
in testing this, it looks like some of the po files are busted.
but the code stuff seems okay.
-adrian
1998-10-14 23:23:52 +00:00
|
|
|
|
2000-07-29 16:12:40 +00:00
|
|
|
|
2002-03-29 03:50:29 +00:00
|
|
|
|
|
|
|
|
2001-03-08 04:15:32 +00:00
|
|
|
static void gimp_rect_select_tool_class_init (GimpRectSelectToolClass *klass);
|
|
|
|
static void gimp_rect_select_tool_init (GimpRectSelectTool *rect_select);
|
|
|
|
|
2001-11-08 19:14:51 +00:00
|
|
|
static void gimp_rect_select_tool_button_press (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void gimp_rect_select_tool_button_release (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void gimp_rect_select_tool_motion (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
|
|
|
|
static void gimp_rect_select_tool_draw (GimpDrawTool *draw_tool);
|
2000-12-31 04:07:42 +00:00
|
|
|
|
2001-03-08 04:15:32 +00:00
|
|
|
static void gimp_rect_select_tool_real_rect_select (GimpRectSelectTool *rect_tool,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h);
|
2000-12-31 04:07:42 +00:00
|
|
|
|
2003-02-25 02:13:03 +00:00
|
|
|
static void gimp_rect_select_tool_update_options (GimpRectSelectTool *rect_sel,
|
|
|
|
GimpDisplay *display);
|
2001-03-08 04:15:32 +00:00
|
|
|
|
|
|
|
static GimpSelectionToolClass *parent_class = NULL;
|
2000-12-31 04:07:42 +00:00
|
|
|
|
|
|
|
|
2001-03-08 04:15:32 +00:00
|
|
|
/* public functions */
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-03-08 04:15:32 +00:00
|
|
|
void
|
2002-03-29 03:50:29 +00:00
|
|
|
gimp_rect_select_tool_register (GimpToolRegisterCallback callback,
|
2002-05-03 11:31:08 +00:00
|
|
|
gpointer data)
|
2001-03-08 04:15:32 +00:00
|
|
|
{
|
2002-03-29 03:50:29 +00:00
|
|
|
(* callback) (GIMP_TYPE_RECT_SELECT_TOOL,
|
2003-02-05 14:39:40 +00:00
|
|
|
GIMP_TYPE_SELECTION_OPTIONS,
|
|
|
|
gimp_selection_options_gui,
|
2001-11-20 23:00:47 +00:00
|
|
|
FALSE,
|
2002-03-21 12:17:17 +00:00
|
|
|
"gimp-rect-select-tool",
|
2001-11-20 23:00:47 +00:00
|
|
|
_("Rect Select"),
|
|
|
|
_("Select rectangular regions"),
|
2003-01-14 21:56:30 +00:00
|
|
|
N_("/Tools/Selection Tools/Rect Select"), "R",
|
2001-11-20 23:00:47 +00:00
|
|
|
NULL, "tools/rect_select.html",
|
2002-03-29 03:50:29 +00:00
|
|
|
GIMP_STOCK_TOOL_RECT_SELECT,
|
2002-05-03 11:31:08 +00:00
|
|
|
data);
|
2001-03-08 04:15:32 +00:00
|
|
|
}
|
|
|
|
|
2001-08-14 14:53:55 +00:00
|
|
|
GType
|
2001-03-08 04:15:32 +00:00
|
|
|
gimp_rect_select_tool_get_type (void)
|
|
|
|
{
|
2001-08-14 14:53:55 +00:00
|
|
|
static GtkType tool_type = 0;
|
2001-03-08 04:15:32 +00:00
|
|
|
|
2001-08-14 14:53:55 +00:00
|
|
|
if (! tool_type)
|
2001-03-08 04:15:32 +00:00
|
|
|
{
|
2001-08-14 14:53:55 +00:00
|
|
|
static const GTypeInfo tool_info =
|
2001-03-08 04:15:32 +00:00
|
|
|
{
|
|
|
|
sizeof (GimpRectSelectToolClass),
|
2001-08-14 14:53:55 +00:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_rect_select_tool_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpRectSelectTool),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_rect_select_tool_init,
|
2001-03-08 04:15:32 +00:00
|
|
|
};
|
|
|
|
|
2001-08-14 14:53:55 +00:00
|
|
|
tool_type = g_type_register_static (GIMP_TYPE_SELECTION_TOOL,
|
|
|
|
"GimpRectSelectTool",
|
|
|
|
&tool_info, 0);
|
2001-03-08 04:15:32 +00:00
|
|
|
}
|
|
|
|
|
2001-08-14 14:53:55 +00:00
|
|
|
return tool_type;
|
2001-03-08 04:15:32 +00:00
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-03-08 04:15:32 +00:00
|
|
|
|
2002-03-03 10:38:37 +00:00
|
|
|
/* private functions */
|
2001-03-08 04:15:32 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_rect_select_tool_class_init (GimpRectSelectToolClass *klass)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2001-03-08 04:15:32 +00:00
|
|
|
GimpToolClass *tool_class;
|
|
|
|
GimpDrawToolClass *draw_tool_class;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-08-14 14:53:55 +00:00
|
|
|
tool_class = GIMP_TOOL_CLASS (klass);
|
|
|
|
draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
|
2001-03-08 04:15:32 +00:00
|
|
|
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-24 21:27:11 +00:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
2001-03-08 04:15:32 +00:00
|
|
|
|
|
|
|
tool_class->button_press = gimp_rect_select_tool_button_press;
|
|
|
|
tool_class->button_release = gimp_rect_select_tool_button_release;
|
|
|
|
tool_class->motion = gimp_rect_select_tool_motion;
|
|
|
|
|
|
|
|
draw_tool_class->draw = gimp_rect_select_tool_draw;
|
|
|
|
|
|
|
|
klass->rect_select = gimp_rect_select_tool_real_rect_select;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_rect_select_tool_init (GimpRectSelectTool *rect_select)
|
|
|
|
{
|
2001-11-20 23:00:47 +00:00
|
|
|
GimpTool *tool;
|
2001-03-08 04:15:32 +00:00
|
|
|
|
2001-11-20 23:00:47 +00:00
|
|
|
tool = GIMP_TOOL (rect_select);
|
2001-03-08 04:15:32 +00:00
|
|
|
|
2002-06-05 09:04:34 +00:00
|
|
|
gimp_tool_control_set_tool_cursor (tool->control,
|
|
|
|
GIMP_RECT_SELECT_TOOL_CURSOR);
|
2001-03-08 04:15:32 +00:00
|
|
|
|
|
|
|
rect_select->x = rect_select->y = 0;
|
|
|
|
rect_select->w = rect_select->h = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-08 19:14:51 +00:00
|
|
|
gimp_rect_select_tool_button_press (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
2001-03-08 04:15:32 +00:00
|
|
|
{
|
2003-02-05 14:39:40 +00:00
|
|
|
GimpRectSelectTool *rect_sel;
|
|
|
|
GimpSelectionTool *sel_tool;
|
|
|
|
GimpSelectionOptions *options;
|
|
|
|
GimpUnit unit = GIMP_UNIT_PIXEL;
|
|
|
|
gdouble unit_factor;
|
2001-03-08 04:15:32 +00:00
|
|
|
|
|
|
|
rect_sel = GIMP_RECT_SELECT_TOOL (tool);
|
|
|
|
sel_tool = GIMP_SELECTION_TOOL (tool);
|
2003-02-05 14:39:40 +00:00
|
|
|
options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-11-12 14:45:58 +00:00
|
|
|
rect_sel->x = RINT (coords->x);
|
|
|
|
rect_sel->y = RINT (coords->y);
|
2002-02-03 12:10:23 +00:00
|
|
|
rect_sel->w = 0;
|
|
|
|
rect_sel->h = 0;
|
2001-03-08 04:15:32 +00:00
|
|
|
|
2003-02-05 14:39:40 +00:00
|
|
|
rect_sel->fixed_mode = options->fixed_mode;
|
|
|
|
rect_sel->fixed_width = options->fixed_width;
|
|
|
|
rect_sel->fixed_height = options->fixed_height;
|
|
|
|
unit = options->fixed_unit;
|
1998-12-19 23:59:04 +00:00
|
|
|
|
1999-04-06 12:13:54 +00:00
|
|
|
switch (unit)
|
|
|
|
{
|
2000-02-07 20:35:13 +00:00
|
|
|
case GIMP_UNIT_PIXEL:
|
1999-04-06 12:13:54 +00:00
|
|
|
break;
|
2000-02-07 20:35:13 +00:00
|
|
|
case GIMP_UNIT_PERCENT:
|
1999-04-06 12:13:54 +00:00
|
|
|
rect_sel->fixed_width =
|
|
|
|
gdisp->gimage->width * rect_sel->fixed_width / 100;
|
|
|
|
rect_sel->fixed_height =
|
|
|
|
gdisp->gimage->height * rect_sel->fixed_height / 100;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
unit_factor = gimp_unit_get_factor (unit);
|
|
|
|
rect_sel->fixed_width =
|
|
|
|
rect_sel->fixed_width * gdisp->gimage->xresolution / unit_factor;
|
|
|
|
rect_sel->fixed_height =
|
|
|
|
rect_sel->fixed_height * gdisp->gimage->yresolution / unit_factor;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-03-28 23:39:32 +00:00
|
|
|
rect_sel->fixed_width = MAX (1, rect_sel->fixed_width);
|
1999-04-06 12:13:54 +00:00
|
|
|
rect_sel->fixed_height = MAX (1, rect_sel->fixed_height);
|
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
rect_sel->center = FALSE;
|
|
|
|
|
2002-05-03 11:31:08 +00:00
|
|
|
gimp_tool_control_activate (tool->control);
|
2001-11-08 19:14:51 +00:00
|
|
|
tool->gdisp = gdisp;
|
|
|
|
|
2001-03-08 04:15:32 +00:00
|
|
|
switch (sel_tool->op)
|
2000-01-25 23:06:12 +00:00
|
|
|
{
|
|
|
|
case SELECTION_MOVE_MASK:
|
2001-11-08 19:14:51 +00:00
|
|
|
init_edit_selection (tool, gdisp, coords, EDIT_MASK_TRANSLATE);
|
2000-01-25 23:06:12 +00:00
|
|
|
return;
|
|
|
|
case SELECTION_MOVE:
|
2001-11-08 19:14:51 +00:00
|
|
|
init_edit_selection (tool, gdisp, coords, EDIT_MASK_TO_LAYER_TRANSLATE);
|
2000-01-25 23:06:12 +00:00
|
|
|
return;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1998-07-23 18:33:01 +00:00
|
|
|
|
2001-03-08 04:15:32 +00:00
|
|
|
switch (sel_tool->op)
|
1998-07-22 23:55:43 +00:00
|
|
|
{
|
1999-05-05 09:10:35 +00:00
|
|
|
case SELECTION_ADD:
|
2002-02-03 12:10:23 +00:00
|
|
|
gimp_tool_push_status (tool, _("Selection: ADD"));
|
1998-07-22 23:55:43 +00:00
|
|
|
break;
|
2002-03-17 22:54:26 +00:00
|
|
|
case SELECTION_SUBTRACT:
|
2002-02-03 12:10:23 +00:00
|
|
|
gimp_tool_push_status (tool, _("Selection: SUBTRACT"));
|
1998-07-22 23:55:43 +00:00
|
|
|
break;
|
1999-05-05 09:10:35 +00:00
|
|
|
case SELECTION_INTERSECT:
|
2002-02-03 12:10:23 +00:00
|
|
|
gimp_tool_push_status (tool, _("Selection: INTERSECT"));
|
1998-07-22 23:55:43 +00:00
|
|
|
break;
|
1999-05-05 09:10:35 +00:00
|
|
|
case SELECTION_REPLACE:
|
2002-02-03 12:10:23 +00:00
|
|
|
gimp_tool_push_status (tool, _("Selection: REPLACE"));
|
1998-07-22 23:55:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2001-03-08 04:15:32 +00:00
|
|
|
|
2002-02-03 12:10:23 +00:00
|
|
|
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), gdisp);
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2001-03-08 04:15:32 +00:00
|
|
|
static void
|
2001-11-08 19:14:51 +00:00
|
|
|
gimp_rect_select_tool_button_release (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2001-03-08 04:15:32 +00:00
|
|
|
GimpRectSelectTool *rect_sel;
|
|
|
|
GimpSelectionTool *sel_tool;
|
|
|
|
gint x1, y1;
|
|
|
|
gint x2, y2;
|
|
|
|
gint w, h;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-03-08 04:15:32 +00:00
|
|
|
rect_sel = GIMP_RECT_SELECT_TOOL (tool);
|
|
|
|
sel_tool = GIMP_SELECTION_TOOL (tool);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2002-02-03 12:10:23 +00:00
|
|
|
gimp_tool_pop_status (tool);
|
1998-07-23 18:33:01 +00:00
|
|
|
|
2001-03-08 04:15:32 +00:00
|
|
|
gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
|
2001-03-09 17:39:18 +00:00
|
|
|
|
2003-01-03 13:59:23 +00:00
|
|
|
gimp_tool_control_halt (tool->control);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
/* First take care of the case where the user "cancels" the action */
|
2001-11-08 19:14:51 +00:00
|
|
|
if (! (state & GDK_BUTTON3_MASK))
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
|
|
|
x1 = (rect_sel->w < 0) ? rect_sel->x + rect_sel->w : rect_sel->x;
|
|
|
|
y1 = (rect_sel->h < 0) ? rect_sel->y + rect_sel->h : rect_sel->y;
|
2001-03-08 04:15:32 +00:00
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
w = (rect_sel->w < 0) ? -rect_sel->w : rect_sel->w;
|
|
|
|
h = (rect_sel->h < 0) ? -rect_sel->h : rect_sel->h;
|
|
|
|
|
2003-01-06 16:25:04 +00:00
|
|
|
if ((! w || ! h) && rect_sel->fixed_mode == GIMP_RECT_SELECT_MODE_FREE)
|
2001-03-08 04:15:32 +00:00
|
|
|
{
|
|
|
|
/* If there is a floating selection, anchor it */
|
|
|
|
if (gimp_image_floating_sel (gdisp->gimage))
|
|
|
|
floating_sel_anchor (gimp_image_floating_sel (gdisp->gimage));
|
|
|
|
/* Otherwise, clear the selection mask */
|
|
|
|
else
|
2003-02-14 14:14:29 +00:00
|
|
|
gimp_image_mask_clear (gdisp->gimage, NULL);
|
2001-03-08 04:15:32 +00:00
|
|
|
|
2002-05-08 17:48:24 +00:00
|
|
|
gimp_image_flush (gdisp->gimage);
|
2001-03-08 04:15:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
x2 = x1 + w;
|
|
|
|
y2 = y1 + h;
|
|
|
|
|
2001-03-08 04:15:32 +00:00
|
|
|
gimp_rect_select_tool_rect_select (rect_sel,
|
|
|
|
x1, y1, (x2 - x1), (y2 - y1));
|
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
/* show selection on all views */
|
2002-05-08 17:48:24 +00:00
|
|
|
gimp_image_flush (gdisp->gimage);
|
2001-03-08 04:15:32 +00:00
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2001-03-08 04:15:32 +00:00
|
|
|
static void
|
2001-11-08 19:14:51 +00:00
|
|
|
gimp_rect_select_tool_motion (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2001-03-08 04:15:32 +00:00
|
|
|
GimpRectSelectTool *rect_sel;
|
|
|
|
GimpSelectionTool *sel_tool;
|
|
|
|
gint ox, oy;
|
|
|
|
gint w, h, s;
|
|
|
|
gint tw, th;
|
|
|
|
gdouble ratio;
|
|
|
|
|
|
|
|
rect_sel = GIMP_RECT_SELECT_TOOL (tool);
|
|
|
|
sel_tool = GIMP_SELECTION_TOOL (tool);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-03-08 04:15:32 +00:00
|
|
|
if (sel_tool->op == SELECTION_ANCHOR)
|
2000-07-29 16:12:40 +00:00
|
|
|
{
|
2001-03-08 04:15:32 +00:00
|
|
|
sel_tool->op = SELECTION_REPLACE;
|
2000-07-29 16:12:40 +00:00
|
|
|
|
2001-11-08 19:14:51 +00:00
|
|
|
gimp_tool_cursor_update (tool, coords, state, gdisp);
|
2000-07-29 16:12:40 +00:00
|
|
|
}
|
|
|
|
|
2001-03-08 04:15:32 +00:00
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
/* Calculate starting point */
|
|
|
|
|
|
|
|
if (rect_sel->center)
|
|
|
|
{
|
|
|
|
ox = rect_sel->x + rect_sel->w / 2;
|
|
|
|
oy = rect_sel->y + rect_sel->h / 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ox = rect_sel->x;
|
|
|
|
oy = rect_sel->y;
|
|
|
|
}
|
|
|
|
|
2003-01-06 16:25:04 +00:00
|
|
|
switch (rect_sel->fixed_mode)
|
2000-03-01 19:32:41 +00:00
|
|
|
{
|
2003-01-06 16:25:04 +00:00
|
|
|
case GIMP_RECT_SELECT_MODE_FIXED_SIZE:
|
|
|
|
w = (RINT (coords->x) - ox > 0 ?
|
|
|
|
rect_sel->fixed_width : -rect_sel->fixed_width);
|
2001-11-08 19:14:51 +00:00
|
|
|
|
2003-01-06 16:25:04 +00:00
|
|
|
h = (RINT (coords->y) - oy > 0 ?
|
|
|
|
rect_sel->fixed_height : -rect_sel->fixed_height);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_RECT_SELECT_MODE_FIXED_RATIO:
|
|
|
|
ratio = ((gdouble) rect_sel->fixed_height /
|
|
|
|
(gdouble) rect_sel->fixed_width);
|
|
|
|
tw = RINT (coords->x) - ox;
|
|
|
|
th = RINT (coords->y) - oy;
|
|
|
|
|
|
|
|
/* This is probably an inefficient way to do it, but it gives
|
|
|
|
* nicer, more predictable results than the original agorithm
|
|
|
|
*/
|
|
|
|
if ((abs (th) < (ratio * abs (tw))) &&
|
|
|
|
(abs (tw) > (abs (th) / ratio)))
|
|
|
|
{
|
|
|
|
w = tw;
|
|
|
|
h = (gint) (tw * ratio);
|
|
|
|
/* h should have the sign of th */
|
|
|
|
if ((th < 0 && h > 0) || (th > 0 && h < 0))
|
|
|
|
h = -h;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
h = th;
|
|
|
|
w = (gint) (th / ratio);
|
|
|
|
/* w should have the sign of tw */
|
|
|
|
if ((tw < 0 && w > 0) || (tw > 0 && w < 0))
|
|
|
|
w = -w;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-11-12 14:45:58 +00:00
|
|
|
w = (RINT (coords->x) - ox);
|
|
|
|
h = (RINT (coords->y) - oy);
|
2003-01-06 16:25:04 +00:00
|
|
|
break;
|
2000-03-01 19:32:41 +00:00
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-03-08 04:15:32 +00:00
|
|
|
/* If the shift key is down, then make the rectangle square (or
|
2001-11-08 19:14:51 +00:00
|
|
|
* ellipse circular)
|
|
|
|
*/
|
2003-01-06 16:25:04 +00:00
|
|
|
if ((state & GDK_SHIFT_MASK) &&
|
|
|
|
rect_sel->fixed_mode == GIMP_RECT_SELECT_MODE_FREE)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2000-01-25 23:06:12 +00:00
|
|
|
s = MAX (abs (w), abs (h));
|
2001-11-08 19:14:51 +00:00
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
if (w < 0)
|
2000-03-28 23:39:32 +00:00
|
|
|
w = -s;
|
1997-11-24 22:05:25 +00:00
|
|
|
else
|
2000-03-28 23:39:32 +00:00
|
|
|
w = s;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
|
|
|
if (h < 0)
|
2000-03-28 23:39:32 +00:00
|
|
|
h = -s;
|
1997-11-24 22:05:25 +00:00
|
|
|
else
|
2000-03-28 23:39:32 +00:00
|
|
|
h = s;
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2001-11-08 19:14:51 +00:00
|
|
|
/* If the control key is down, create the selection from the center out
|
|
|
|
*/
|
|
|
|
if (state & GDK_CONTROL_MASK)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2003-01-06 16:25:04 +00:00
|
|
|
rect_sel->center = TRUE;
|
|
|
|
|
|
|
|
switch (rect_sel->fixed_mode)
|
|
|
|
{
|
|
|
|
case GIMP_RECT_SELECT_MODE_FIXED_SIZE:
|
|
|
|
rect_sel->x = ox - w / 2;
|
|
|
|
rect_sel->y = oy - h / 2;
|
|
|
|
rect_sel->w = w;
|
|
|
|
rect_sel->h = h;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_RECT_SELECT_MODE_FIXED_RATIO:
|
|
|
|
rect_sel->x = ox - w;
|
|
|
|
rect_sel->y = oy - h;
|
|
|
|
rect_sel->w = w * 2;
|
|
|
|
rect_sel->h = h * 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-11-08 19:14:51 +00:00
|
|
|
w = abs (w);
|
|
|
|
h = abs (h);
|
|
|
|
|
1998-07-20 18:19:20 +00:00
|
|
|
rect_sel->x = ox - w;
|
|
|
|
rect_sel->y = oy - h;
|
|
|
|
rect_sel->w = 2 * w + 1;
|
|
|
|
rect_sel->h = 2 * h + 1;
|
2003-01-06 16:25:04 +00:00
|
|
|
break;
|
|
|
|
}
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-01-06 16:25:04 +00:00
|
|
|
rect_sel->center = FALSE;
|
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
rect_sel->x = ox;
|
|
|
|
rect_sel->y = oy;
|
|
|
|
rect_sel->w = w;
|
|
|
|
rect_sel->h = h;
|
|
|
|
}
|
1998-07-23 18:33:01 +00:00
|
|
|
|
2003-02-25 02:13:03 +00:00
|
|
|
gimp_rect_select_tool_update_options (rect_sel, gdisp);
|
|
|
|
|
2002-02-03 12:10:23 +00:00
|
|
|
gimp_tool_pop_status (tool);
|
2001-03-08 04:15:32 +00:00
|
|
|
|
2002-02-03 12:10:23 +00:00
|
|
|
gimp_tool_push_status_coords (tool,
|
|
|
|
_("Selection: "),
|
|
|
|
abs (rect_sel->w),
|
|
|
|
" x ",
|
|
|
|
abs (rect_sel->h));
|
1998-07-23 18:33:01 +00:00
|
|
|
|
2001-03-08 04:15:32 +00:00
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
2001-03-08 04:15:32 +00:00
|
|
|
static void
|
|
|
|
gimp_rect_select_tool_draw (GimpDrawTool *draw_tool)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2001-03-08 04:15:32 +00:00
|
|
|
GimpRectSelectTool *rect_sel;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-03-08 04:15:32 +00:00
|
|
|
rect_sel = GIMP_RECT_SELECT_TOOL (draw_tool);
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2001-11-12 14:45:58 +00:00
|
|
|
gimp_draw_tool_draw_rectangle (draw_tool,
|
|
|
|
FALSE,
|
|
|
|
rect_sel->x,
|
|
|
|
rect_sel->y,
|
|
|
|
rect_sel->w,
|
|
|
|
rect_sel->h,
|
|
|
|
FALSE);
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
1999-07-02 17:40:10 +00:00
|
|
|
static void
|
2001-03-08 04:15:32 +00:00
|
|
|
gimp_rect_select_tool_real_rect_select (GimpRectSelectTool *rect_tool,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
2000-01-19 19:06:13 +00:00
|
|
|
{
|
2003-02-05 14:39:40 +00:00
|
|
|
GimpTool *tool;
|
|
|
|
GimpSelectionTool *sel_tool;
|
|
|
|
GimpSelectionOptions *options;
|
2000-01-19 19:06:13 +00:00
|
|
|
|
2001-03-08 04:15:32 +00:00
|
|
|
tool = GIMP_TOOL (rect_tool);
|
|
|
|
sel_tool = GIMP_SELECTION_TOOL (rect_tool);
|
2003-02-05 14:39:40 +00:00
|
|
|
options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
|
2000-06-14 10:59:16 +00:00
|
|
|
|
2001-10-22 12:13:44 +00:00
|
|
|
gimp_image_mask_select_rectangle (tool->gdisp->gimage,
|
|
|
|
x, y, w, h,
|
|
|
|
sel_tool->op,
|
2003-02-05 14:39:40 +00:00
|
|
|
options->feather,
|
|
|
|
options->feather_radius,
|
|
|
|
options->feather_radius);
|
2000-01-19 19:06:13 +00:00
|
|
|
}
|
|
|
|
|
2000-03-01 23:22:43 +00:00
|
|
|
void
|
2001-03-08 04:15:32 +00:00
|
|
|
gimp_rect_select_tool_rect_select (GimpRectSelectTool *rect_tool,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
2000-03-01 23:22:43 +00:00
|
|
|
{
|
2003-02-05 14:39:40 +00:00
|
|
|
GimpTool *tool;
|
|
|
|
GimpSelectionOptions *options;
|
2001-11-10 14:17:01 +00:00
|
|
|
|
2001-03-08 04:15:32 +00:00
|
|
|
g_return_if_fail (GIMP_IS_RECT_SELECT_TOOL (rect_tool));
|
2000-03-01 23:22:43 +00:00
|
|
|
|
2003-02-05 14:39:40 +00:00
|
|
|
tool = GIMP_TOOL (rect_tool);
|
|
|
|
options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
|
2001-11-10 14:17:01 +00:00
|
|
|
|
2003-02-05 14:39:40 +00:00
|
|
|
if (options->auto_shrink)
|
2001-11-10 14:17:01 +00:00
|
|
|
{
|
|
|
|
gint x2, y2;
|
|
|
|
|
|
|
|
x = CLAMP (x, 0, tool->gdisp->gimage->width);
|
|
|
|
y = CLAMP (y, 0, tool->gdisp->gimage->height);
|
|
|
|
w = CLAMP (w, 0, tool->gdisp->gimage->width - x);
|
|
|
|
h = CLAMP (h, 0, tool->gdisp->gimage->height - y);
|
|
|
|
|
|
|
|
if (w < 1 || h < 1)
|
|
|
|
return;
|
|
|
|
|
2003-02-05 14:39:40 +00:00
|
|
|
if (! options->shrink_merged)
|
2001-11-10 14:17:01 +00:00
|
|
|
{
|
|
|
|
GimpDrawable *drawable;
|
2003-05-08 13:12:46 +00:00
|
|
|
GimpItem *item;
|
2001-11-10 14:17:01 +00:00
|
|
|
gint off_x, off_y;
|
|
|
|
gint width, height;
|
|
|
|
|
|
|
|
drawable = gimp_image_active_drawable (tool->gdisp->gimage);
|
2003-05-08 13:12:46 +00:00
|
|
|
item = GIMP_ITEM (drawable);
|
|
|
|
|
2003-05-08 14:06:03 +00:00
|
|
|
gimp_item_offsets (item, &off_x, &off_y);
|
2003-05-08 13:12:46 +00:00
|
|
|
width = gimp_item_width (item);
|
|
|
|
height = gimp_item_height (item);
|
2001-11-10 14:17:01 +00:00
|
|
|
|
|
|
|
x = CLAMP (x, off_x, off_x + width);
|
|
|
|
y = CLAMP (y, off_y, off_y + height);
|
|
|
|
w = CLAMP (w, 0, off_x + width - x);
|
|
|
|
h = CLAMP (h, 0, off_y + height - y);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gimp_image_crop_auto_shrink (tool->gdisp->gimage,
|
|
|
|
x, y,
|
|
|
|
x + w, y + h,
|
2003-02-05 14:39:40 +00:00
|
|
|
! options->shrink_merged,
|
2001-11-10 14:17:01 +00:00
|
|
|
&x, &y,
|
|
|
|
&x2, &y2))
|
|
|
|
{
|
|
|
|
w = x2 - x;
|
|
|
|
h = y2 - y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-20 14:20:17 +00:00
|
|
|
GIMP_RECT_SELECT_TOOL_GET_CLASS (rect_tool)->rect_select (rect_tool,
|
|
|
|
x, y, w, h);
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
2003-02-25 02:13:03 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_rect_select_tool_update_options (GimpRectSelectTool *rect_sel,
|
|
|
|
GimpDisplay *gdisp)
|
|
|
|
{
|
|
|
|
GimpUnit unit;
|
|
|
|
gdouble width;
|
|
|
|
gdouble height;
|
|
|
|
|
|
|
|
if (rect_sel->fixed_mode != GIMP_RECT_SELECT_MODE_FREE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (GIMP_DISPLAY_SHELL (gdisp->shell)->dot_for_dot)
|
|
|
|
{
|
|
|
|
width = abs (rect_sel->w);
|
|
|
|
height = abs (rect_sel->h);
|
|
|
|
unit = GIMP_UNIT_PIXEL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GimpImage *gimage;
|
|
|
|
gdouble unit_factor;
|
|
|
|
|
|
|
|
gimage = gdisp->gimage;
|
|
|
|
|
|
|
|
unit = gimage->unit;
|
|
|
|
unit_factor = gimp_unit_get_factor (unit);
|
|
|
|
width = (gdouble) abs (rect_sel->w) * unit_factor / gimage->xresolution;
|
|
|
|
height = (gdouble) abs (rect_sel->h) * unit_factor / gimage->yresolution;
|
|
|
|
}
|
|
|
|
|
2003-02-28 01:14:30 +00:00
|
|
|
g_object_set (GIMP_TOOL (rect_sel)->tool_info->tool_options,
|
2003-02-25 02:13:03 +00:00
|
|
|
"fixed-width", width,
|
|
|
|
"fixed-height", height,
|
|
|
|
"fixed-unit", unit,
|
|
|
|
NULL);
|
|
|
|
}
|