1997-11-24 14: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-12 22:44:11 -07:00
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-24 14:05:25 -08:00
|
|
|
|
*/
|
2000-07-29 09:12:40 -07:00
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
1997-11-24 14:05:25 -08:00
|
|
|
|
#include <stdlib.h>
|
2000-07-29 09:12:40 -07:00
|
|
|
|
|
2000-12-16 13:37:03 -08:00
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
2001-01-24 14:36:18 -08:00
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
2001-05-09 15:34:59 -07:00
|
|
|
|
#include "tools-types.h"
|
2000-03-28 15:39:32 -08:00
|
|
|
|
|
2004-02-05 03:11:22 -08:00
|
|
|
|
#include "core/gimp-utils.h"
|
2001-05-08 19:32:03 -07:00
|
|
|
|
#include "core/gimpchannel.h"
|
2003-10-06 05:17:11 -07:00
|
|
|
|
#include "core/gimpchannel-select.h"
|
2001-05-08 19:32:03 -07:00
|
|
|
|
#include "core/gimpimage.h"
|
2001-11-10 06:17:01 -08:00
|
|
|
|
#include "core/gimpimage-crop.h"
|
2002-02-21 14:19:45 -08:00
|
|
|
|
#include "core/gimplayer-floating-sel.h"
|
2001-05-08 19:32:03 -07:00
|
|
|
|
#include "core/gimpmarshal.h"
|
2001-05-09 15:34:59 -07:00
|
|
|
|
#include "core/gimptoolinfo.h"
|
2003-10-01 10:32:14 -07:00
|
|
|
|
#include "core/gimpunit.h"
|
2001-05-08 19:32:03 -07:00
|
|
|
|
|
2003-08-21 18:42:57 -07:00
|
|
|
|
#include "widgets/gimphelp-ids.h"
|
|
|
|
|
|
|
2001-09-25 16:23:09 -07:00
|
|
|
|
#include "display/gimpdisplay.h"
|
2003-02-24 18:13:03 -08:00
|
|
|
|
#include "display/gimpdisplayshell.h"
|
2001-09-25 16:23:09 -07:00
|
|
|
|
|
2001-03-07 20:15:32 -08:00
|
|
|
|
#include "gimprectselecttool.h"
|
2003-02-08 13:12:03 -08:00
|
|
|
|
#include "gimpselectionoptions.h"
|
2003-04-15 09:05:52 -07:00
|
|
|
|
#include "gimptoolcontrol.h"
|
2000-07-29 09:12:40 -07:00
|
|
|
|
|
2003-03-25 08:38:19 -08: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 16:23:52 -07:00
|
|
|
|
|
2000-07-29 09:12:40 -07:00
|
|
|
|
|
2001-11-08 11:14:51 -08:00
|
|
|
|
static void gimp_rect_select_tool_button_press (GimpTool *tool,
|
|
|
|
|
|
GimpCoords *coords,
|
|
|
|
|
|
guint32 time,
|
|
|
|
|
|
GdkModifierType state,
|
2006-03-28 09:55:52 -08:00
|
|
|
|
GimpDisplay *display);
|
2001-11-08 11:14:51 -08:00
|
|
|
|
static void gimp_rect_select_tool_button_release (GimpTool *tool,
|
|
|
|
|
|
GimpCoords *coords,
|
|
|
|
|
|
guint32 time,
|
|
|
|
|
|
GdkModifierType state,
|
2006-03-28 09:55:52 -08:00
|
|
|
|
GimpDisplay *display);
|
2001-11-08 11:14:51 -08:00
|
|
|
|
static void gimp_rect_select_tool_motion (GimpTool *tool,
|
|
|
|
|
|
GimpCoords *coords,
|
|
|
|
|
|
guint32 time,
|
|
|
|
|
|
GdkModifierType state,
|
2006-03-28 09:55:52 -08:00
|
|
|
|
GimpDisplay *display);
|
2001-11-08 11:14:51 -08:00
|
|
|
|
|
|
|
|
|
|
static void gimp_rect_select_tool_draw (GimpDrawTool *draw_tool);
|
2000-12-30 20:07:42 -08:00
|
|
|
|
|
2001-03-07 20:15:32 -08:00
|
|
|
|
static void gimp_rect_select_tool_real_rect_select (GimpRectSelectTool *rect_tool,
|
|
|
|
|
|
gint x,
|
|
|
|
|
|
gint y,
|
|
|
|
|
|
gint w,
|
|
|
|
|
|
gint h);
|
2000-12-30 20:07:42 -08:00
|
|
|
|
|
2003-02-24 18:13:03 -08:00
|
|
|
|
static void gimp_rect_select_tool_update_options (GimpRectSelectTool *rect_sel,
|
|
|
|
|
|
GimpDisplay *display);
|
2001-03-07 20:15:32 -08:00
|
|
|
|
|
2000-12-30 20:07:42 -08:00
|
|
|
|
|
2005-12-13 01:13:50 -08:00
|
|
|
|
G_DEFINE_TYPE (GimpRectSelectTool, gimp_rect_select_tool,
|
|
|
|
|
|
GIMP_TYPE_SELECTION_TOOL);
|
|
|
|
|
|
|
|
|
|
|
|
#define parent_class gimp_rect_select_tool_parent_class
|
2000-12-30 20:07:42 -08:00
|
|
|
|
|
1997-11-24 14:05:25 -08:00
|
|
|
|
|
2001-03-07 20:15:32 -08:00
|
|
|
|
void
|
2002-03-28 19:50:29 -08:00
|
|
|
|
gimp_rect_select_tool_register (GimpToolRegisterCallback callback,
|
2002-05-03 04:31:08 -07:00
|
|
|
|
gpointer data)
|
2001-03-07 20:15:32 -08:00
|
|
|
|
{
|
2002-03-28 19:50:29 -08:00
|
|
|
|
(* callback) (GIMP_TYPE_RECT_SELECT_TOOL,
|
2003-02-05 06:39:40 -08:00
|
|
|
|
GIMP_TYPE_SELECTION_OPTIONS,
|
|
|
|
|
|
gimp_selection_options_gui,
|
2003-06-28 04:20:37 -07:00
|
|
|
|
0,
|
2002-03-21 04:17:17 -08:00
|
|
|
|
"gimp-rect-select-tool",
|
2006-03-24 00:15:01 -08:00
|
|
|
|
_("Rectangle Select"),
|
2001-11-20 15:00:47 -08:00
|
|
|
|
_("Select rectangular regions"),
|
2006-03-24 00:15:01 -08:00
|
|
|
|
N_("_Rectangle Select"), "R",
|
2003-08-21 18:42:57 -07:00
|
|
|
|
NULL, GIMP_HELP_TOOL_RECT_SELECT,
|
2002-03-28 19:50:29 -08:00
|
|
|
|
GIMP_STOCK_TOOL_RECT_SELECT,
|
2002-05-03 04:31:08 -07:00
|
|
|
|
data);
|
2001-03-07 20:15:32 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
|
gimp_rect_select_tool_class_init (GimpRectSelectToolClass *klass)
|
1997-11-24 14:05:25 -08:00
|
|
|
|
{
|
2004-06-04 16:08:29 -07:00
|
|
|
|
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
|
|
|
|
|
GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
|
2001-03-07 20:15:32 -08: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)
|
|
|
|
|
|
{
|
2003-11-15 15:39:37 -08:00
|
|
|
|
GimpTool *tool = GIMP_TOOL (rect_select);
|
2001-03-07 20:15:32 -08:00
|
|
|
|
|
2002-06-05 02:04:34 -07:00
|
|
|
|
gimp_tool_control_set_tool_cursor (tool->control,
|
2004-06-04 16:08:29 -07:00
|
|
|
|
GIMP_TOOL_CURSOR_RECT_SELECT);
|
2001-03-07 20:15:32 -08:00
|
|
|
|
|
2005-03-07 13:31:22 -08:00
|
|
|
|
rect_select->sx = rect_select->sy = 0;
|
|
|
|
|
|
rect_select->x = rect_select->y = 0;
|
|
|
|
|
|
rect_select->w = rect_select->h = 0;
|
2001-03-07 20:15:32 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2001-11-08 11:14:51 -08:00
|
|
|
|
gimp_rect_select_tool_button_press (GimpTool *tool,
|
|
|
|
|
|
GimpCoords *coords,
|
|
|
|
|
|
guint32 time,
|
|
|
|
|
|
GdkModifierType state,
|
2006-03-28 09:55:52 -08:00
|
|
|
|
GimpDisplay *display)
|
2001-03-07 20:15:32 -08:00
|
|
|
|
{
|
2004-06-04 16:08:29 -07:00
|
|
|
|
GimpRectSelectTool *rect_sel = GIMP_RECT_SELECT_TOOL (tool);
|
|
|
|
|
|
GimpSelectionTool *sel_tool = GIMP_SELECTION_TOOL (tool);
|
2003-02-05 06:39:40 -08:00
|
|
|
|
GimpSelectionOptions *options;
|
2004-06-04 16:08:29 -07:00
|
|
|
|
GimpUnit unit = GIMP_UNIT_PIXEL;
|
2003-02-05 06:39:40 -08:00
|
|
|
|
gdouble unit_factor;
|
2001-03-07 20:15:32 -08:00
|
|
|
|
|
2004-06-04 16:08:29 -07:00
|
|
|
|
options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
|
1997-11-24 14:05:25 -08:00
|
|
|
|
|
2005-03-07 13:31:22 -08:00
|
|
|
|
rect_sel->sx = RINT(coords->x);
|
|
|
|
|
|
rect_sel->sy = RINT(coords->y);
|
|
|
|
|
|
rect_sel->x = 0;
|
|
|
|
|
|
rect_sel->y = 0;
|
|
|
|
|
|
rect_sel->w = 0;
|
|
|
|
|
|
rect_sel->h = 0;
|
|
|
|
|
|
rect_sel->lx = RINT(coords->x);
|
|
|
|
|
|
rect_sel->ly = RINT(coords->y);
|
2003-05-27 04:52:03 -07:00
|
|
|
|
rect_sel->center = FALSE;
|
2001-03-07 20:15:32 -08:00
|
|
|
|
|
2003-02-05 06:39:40 -08: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 15:59:04 -08:00
|
|
|
|
|
1999-04-06 05:13:54 -07:00
|
|
|
|
switch (unit)
|
|
|
|
|
|
{
|
2000-02-07 12:35:13 -08:00
|
|
|
|
case GIMP_UNIT_PIXEL:
|
1999-04-06 05:13:54 -07:00
|
|
|
|
break;
|
2000-02-07 12:35:13 -08:00
|
|
|
|
case GIMP_UNIT_PERCENT:
|
1999-04-06 05:13:54 -07:00
|
|
|
|
rect_sel->fixed_width =
|
2006-03-28 09:55:52 -08:00
|
|
|
|
display->image->width * rect_sel->fixed_width / 100;
|
1999-04-06 05:13:54 -07:00
|
|
|
|
rect_sel->fixed_height =
|
2006-03-28 09:55:52 -08:00
|
|
|
|
display->image->height * rect_sel->fixed_height / 100;
|
1999-04-06 05:13:54 -07:00
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2003-10-01 10:32:14 -07:00
|
|
|
|
unit_factor = _gimp_unit_get_factor (tool->tool_info->gimp, unit);
|
1999-04-06 05:13:54 -07:00
|
|
|
|
rect_sel->fixed_width =
|
2006-03-28 09:55:52 -08:00
|
|
|
|
rect_sel->fixed_width * display->image->xresolution / unit_factor;
|
1999-04-06 05:13:54 -07:00
|
|
|
|
rect_sel->fixed_height =
|
2006-03-28 09:55:52 -08:00
|
|
|
|
rect_sel->fixed_height * display->image->yresolution / unit_factor;
|
1999-04-06 05:13:54 -07:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2000-03-28 15:39:32 -08:00
|
|
|
|
rect_sel->fixed_width = MAX (1, rect_sel->fixed_width);
|
1999-04-06 05:13:54 -07:00
|
|
|
|
rect_sel->fixed_height = MAX (1, rect_sel->fixed_height);
|
|
|
|
|
|
|
2002-05-03 04:31:08 -07:00
|
|
|
|
gimp_tool_control_activate (tool->control);
|
2006-03-28 09:55:52 -08:00
|
|
|
|
tool->display = display;
|
2001-11-08 11:14:51 -08:00
|
|
|
|
|
2004-07-26 07:50:51 -07:00
|
|
|
|
if (gimp_selection_tool_start_edit (sel_tool, coords))
|
|
|
|
|
|
return;
|
1998-07-23 11:33:01 -07:00
|
|
|
|
|
2006-03-28 09:55:52 -08:00
|
|
|
|
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), display);
|
1997-11-24 14:05:25 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2001-03-07 20:15:32 -08:00
|
|
|
|
static void
|
2001-11-08 11:14:51 -08:00
|
|
|
|
gimp_rect_select_tool_button_release (GimpTool *tool,
|
|
|
|
|
|
GimpCoords *coords,
|
|
|
|
|
|
guint32 time,
|
|
|
|
|
|
GdkModifierType state,
|
2006-03-28 09:55:52 -08:00
|
|
|
|
GimpDisplay *display)
|
1997-11-24 14:05:25 -08:00
|
|
|
|
{
|
2004-06-04 16:08:29 -07:00
|
|
|
|
GimpRectSelectTool *rect_sel = GIMP_RECT_SELECT_TOOL (tool);
|
1997-11-24 14:05:25 -08:00
|
|
|
|
|
2006-03-28 09:55:52 -08:00
|
|
|
|
gimp_tool_pop_status (tool, display);
|
1998-07-23 11:33:01 -07:00
|
|
|
|
|
2001-03-07 20:15:32 -08:00
|
|
|
|
gimp_draw_tool_stop (GIMP_DRAW_TOOL (tool));
|
2001-03-09 09:39:18 -08:00
|
|
|
|
|
2003-01-03 05:59:23 -08:00
|
|
|
|
gimp_tool_control_halt (tool->control);
|
1997-11-24 14:05:25 -08:00
|
|
|
|
|
|
|
|
|
|
/* First take care of the case where the user "cancels" the action */
|
2001-11-08 11:14:51 -08:00
|
|
|
|
if (! (state & GDK_BUTTON3_MASK))
|
2005-05-07 06:24:47 -07:00
|
|
|
|
{
|
2005-03-07 13:31:22 -08:00
|
|
|
|
if (rect_sel->w == 0 || rect_sel->h == 0)
|
2001-03-07 20:15:32 -08:00
|
|
|
|
{
|
|
|
|
|
|
/* If there is a floating selection, anchor it */
|
2006-03-28 09:55:52 -08:00
|
|
|
|
if (gimp_image_floating_sel (display->image))
|
|
|
|
|
|
floating_sel_anchor (gimp_image_floating_sel (display->image));
|
2001-03-07 20:15:32 -08:00
|
|
|
|
/* Otherwise, clear the selection mask */
|
|
|
|
|
|
else
|
2006-03-28 09:55:52 -08:00
|
|
|
|
gimp_channel_clear (gimp_image_get_mask (display->image), NULL,
|
2003-09-03 07:22:38 -07:00
|
|
|
|
TRUE);
|
2001-03-07 20:15:32 -08:00
|
|
|
|
|
2006-03-28 09:55:52 -08:00
|
|
|
|
gimp_image_flush (display->image);
|
2001-03-07 20:15:32 -08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gimp_rect_select_tool_rect_select (rect_sel,
|
2005-03-07 13:31:22 -08:00
|
|
|
|
rect_sel->x, rect_sel->y,
|
|
|
|
|
|
rect_sel->w, rect_sel->h);
|
2005-05-07 06:24:47 -07:00
|
|
|
|
|
1997-11-24 14:05:25 -08:00
|
|
|
|
/* show selection on all views */
|
2006-03-28 09:55:52 -08:00
|
|
|
|
gimp_image_flush (display->image);
|
2001-03-07 20:15:32 -08:00
|
|
|
|
}
|
1997-11-24 14:05:25 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2001-03-07 20:15:32 -08:00
|
|
|
|
static void
|
2001-11-08 11:14:51 -08:00
|
|
|
|
gimp_rect_select_tool_motion (GimpTool *tool,
|
|
|
|
|
|
GimpCoords *coords,
|
|
|
|
|
|
guint32 time,
|
|
|
|
|
|
GdkModifierType state,
|
2006-03-28 09:55:52 -08:00
|
|
|
|
GimpDisplay *display)
|
1997-11-24 14:05:25 -08:00
|
|
|
|
{
|
2004-06-04 16:08:29 -07:00
|
|
|
|
GimpRectSelectTool *rect_sel = GIMP_RECT_SELECT_TOOL (tool);
|
|
|
|
|
|
GimpSelectionTool *sel_tool = GIMP_SELECTION_TOOL (tool);
|
2005-03-07 13:31:22 -08:00
|
|
|
|
gint mx, my;
|
2001-03-07 20:15:32 -08:00
|
|
|
|
gdouble ratio;
|
2004-04-05 01:08:23 -07:00
|
|
|
|
|
2001-03-07 20:15:32 -08:00
|
|
|
|
if (sel_tool->op == SELECTION_ANCHOR)
|
2000-07-29 09:12:40 -07:00
|
|
|
|
{
|
2001-03-07 20:15:32 -08:00
|
|
|
|
sel_tool->op = SELECTION_REPLACE;
|
2000-07-29 09:12:40 -07:00
|
|
|
|
|
2006-03-28 09:55:52 -08:00
|
|
|
|
gimp_tool_cursor_update (tool, coords, state, display);
|
2000-07-29 09:12:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2001-03-07 20:15:32 -08:00
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
1997-11-24 14:05:25 -08:00
|
|
|
|
|
2005-05-07 06:24:47 -07:00
|
|
|
|
|
2003-05-27 04:52:03 -07:00
|
|
|
|
if (state & GDK_MOD1_MASK)
|
1997-11-24 14:05:25 -08:00
|
|
|
|
{
|
2003-05-27 04:52:03 -07:00
|
|
|
|
/* Just move the selection rectangle around */
|
2005-05-07 06:24:47 -07:00
|
|
|
|
|
2005-03-07 13:31:22 -08:00
|
|
|
|
mx = RINT(coords->x) - rect_sel->lx;
|
|
|
|
|
|
my = RINT(coords->y) - rect_sel->ly;
|
|
|
|
|
|
|
|
|
|
|
|
rect_sel->sx += mx;
|
|
|
|
|
|
rect_sel->sy += my;
|
|
|
|
|
|
rect_sel->x += mx;
|
|
|
|
|
|
rect_sel->y += my;
|
1997-11-24 14:05:25 -08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2005-05-07 06:24:47 -07:00
|
|
|
|
/* Change the selection rectangle's size, first calculate absolute
|
2005-03-07 13:31:22 -08:00
|
|
|
|
* width and height, then take care of quadrants.
|
|
|
|
|
|
*/
|
2001-11-08 11:14:51 -08:00
|
|
|
|
|
2005-03-07 13:31:22 -08:00
|
|
|
|
if (rect_sel->fixed_mode == GIMP_RECT_SELECT_MODE_FIXED_SIZE)
|
2003-01-06 08:25:04 -08:00
|
|
|
|
{
|
2005-03-07 13:31:22 -08:00
|
|
|
|
rect_sel->w = RINT(rect_sel->fixed_width);
|
|
|
|
|
|
rect_sel->h = RINT(rect_sel->fixed_height);
|
2003-01-06 08:25:04 -08:00
|
|
|
|
}
|
2003-05-27 04:52:03 -07:00
|
|
|
|
else
|
2003-01-06 08:25:04 -08:00
|
|
|
|
{
|
2005-03-07 13:31:22 -08:00
|
|
|
|
rect_sel->w = abs(RINT(coords->x) - rect_sel->sx);
|
|
|
|
|
|
rect_sel->h = abs(RINT(coords->y) - rect_sel->sy);
|
2003-01-06 08:25:04 -08:00
|
|
|
|
}
|
2005-05-07 06:24:47 -07:00
|
|
|
|
|
2005-03-07 13:31:22 -08:00
|
|
|
|
if (rect_sel->fixed_mode == GIMP_RECT_SELECT_MODE_FIXED_RATIO)
|
2003-01-06 08:25:04 -08:00
|
|
|
|
{
|
2005-03-07 13:31:22 -08:00
|
|
|
|
ratio = rect_sel->fixed_height / rect_sel->fixed_width;
|
|
|
|
|
|
if ( ( (gdouble) rect_sel->h) / ( (gdouble) rect_sel->w ) > ratio)
|
2003-05-27 04:52:03 -07:00
|
|
|
|
{
|
2005-03-07 13:31:22 -08:00
|
|
|
|
rect_sel->w = RINT(rect_sel->h / ratio);
|
2003-05-27 04:52:03 -07:00
|
|
|
|
}
|
2003-08-21 18:42:57 -07:00
|
|
|
|
else
|
2003-05-27 04:52:03 -07:00
|
|
|
|
{
|
2005-03-07 13:31:22 -08:00
|
|
|
|
rect_sel->h = RINT(rect_sel->w * ratio);
|
2003-05-27 04:52:03 -07:00
|
|
|
|
}
|
2003-01-06 08:25:04 -08:00
|
|
|
|
}
|
2005-05-07 06:24:47 -07:00
|
|
|
|
|
2003-01-06 08:25:04 -08:00
|
|
|
|
|
2003-05-27 04:52:03 -07:00
|
|
|
|
/* If the shift key is down, then make the rectangle square (or
|
|
|
|
|
|
* ellipse circular)
|
|
|
|
|
|
*/
|
|
|
|
|
|
if ((state & GDK_SHIFT_MASK) &&
|
|
|
|
|
|
rect_sel->fixed_mode == GIMP_RECT_SELECT_MODE_FREE)
|
|
|
|
|
|
{
|
2005-03-07 13:31:22 -08:00
|
|
|
|
if (rect_sel->w > rect_sel->h)
|
|
|
|
|
|
{
|
|
|
|
|
|
rect_sel->h = rect_sel->w;
|
|
|
|
|
|
}
|
2003-05-27 04:52:03 -07:00
|
|
|
|
else
|
2005-03-07 13:31:22 -08:00
|
|
|
|
{
|
|
|
|
|
|
rect_sel->w = rect_sel->h;
|
|
|
|
|
|
}
|
2003-05-27 04:52:03 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (state & GDK_CONTROL_MASK)
|
|
|
|
|
|
{
|
2005-03-07 13:31:22 -08:00
|
|
|
|
/* If the control key is down, create the selection from the center out */
|
|
|
|
|
|
if (rect_sel->fixed_mode == GIMP_RECT_SELECT_MODE_FIXED_SIZE)
|
2003-05-27 04:52:03 -07:00
|
|
|
|
{
|
2005-03-07 13:31:22 -08:00
|
|
|
|
/* Fixed size selection is simply centered over start point */
|
|
|
|
|
|
rect_sel->x = RINT(rect_sel->sx - rect_sel->w / 2.0);
|
|
|
|
|
|
rect_sel->y = RINT(rect_sel->sy - rect_sel->h / 2.0);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
/* Non-fixed size is mirrored over starting point */
|
|
|
|
|
|
rect_sel->x = rect_sel->sx - rect_sel->w;
|
|
|
|
|
|
rect_sel->y = rect_sel->sy - rect_sel->h;
|
|
|
|
|
|
rect_sel->w = rect_sel->w * 2;
|
|
|
|
|
|
rect_sel->h = rect_sel->h * 2;
|
2003-05-27 04:52:03 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2005-03-07 13:31:22 -08:00
|
|
|
|
/* Make (rect->x, rect->y) upper left hand point of selection */
|
|
|
|
|
|
if (coords->x > rect_sel->sx)
|
|
|
|
|
|
{
|
|
|
|
|
|
rect_sel->x = rect_sel->sx;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
rect_sel->x = rect_sel->sx - rect_sel->w;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (coords->y > rect_sel->sy)
|
|
|
|
|
|
{
|
|
|
|
|
|
rect_sel->y = rect_sel->sy;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
rect_sel->y = rect_sel->sy - rect_sel->h;
|
|
|
|
|
|
}
|
2003-05-27 04:52:03 -07:00
|
|
|
|
}
|
1997-11-24 14:05:25 -08:00
|
|
|
|
}
|
1998-07-23 11:33:01 -07:00
|
|
|
|
|
2005-03-07 13:31:22 -08:00
|
|
|
|
rect_sel->lx = RINT(coords->x);
|
|
|
|
|
|
rect_sel->ly = RINT(coords->y);
|
2003-02-24 18:13:03 -08:00
|
|
|
|
|
2006-03-28 09:55:52 -08:00
|
|
|
|
gimp_rect_select_tool_update_options (rect_sel, display);
|
2001-03-07 20:15:32 -08:00
|
|
|
|
|
2006-03-28 09:55:52 -08:00
|
|
|
|
gimp_tool_pop_status (tool, display);
|
|
|
|
|
|
gimp_tool_push_status_coords (tool, display,
|
2002-02-03 04:10:23 -08:00
|
|
|
|
_("Selection: "),
|
2006-02-28 04:15:51 -08:00
|
|
|
|
rect_sel->w, " × ", rect_sel->h);
|
1998-07-23 11:33:01 -07:00
|
|
|
|
|
2001-03-07 20:15:32 -08:00
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
1997-11-24 14:05:25 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2001-03-07 20:15:32 -08:00
|
|
|
|
static void
|
|
|
|
|
|
gimp_rect_select_tool_draw (GimpDrawTool *draw_tool)
|
1997-11-24 14:05:25 -08:00
|
|
|
|
{
|
2003-11-15 15:39:37 -08:00
|
|
|
|
GimpRectSelectTool *rect_sel = GIMP_RECT_SELECT_TOOL (draw_tool);
|
2005-03-07 13:31:22 -08:00
|
|
|
|
|
2001-11-12 06:45:58 -08:00
|
|
|
|
gimp_draw_tool_draw_rectangle (draw_tool,
|
|
|
|
|
|
FALSE,
|
2005-03-07 13:31:22 -08:00
|
|
|
|
rect_sel->x, rect_sel->y,
|
|
|
|
|
|
rect_sel->w, rect_sel->h,
|
2001-11-12 06:45:58 -08:00
|
|
|
|
FALSE);
|
1997-11-24 14:05:25 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
1999-07-02 10:40:10 -07:00
|
|
|
|
static void
|
2001-03-07 20:15:32 -08:00
|
|
|
|
gimp_rect_select_tool_real_rect_select (GimpRectSelectTool *rect_tool,
|
|
|
|
|
|
gint x,
|
|
|
|
|
|
gint y,
|
|
|
|
|
|
gint w,
|
|
|
|
|
|
gint h)
|
2000-01-19 11:06:13 -08:00
|
|
|
|
{
|
2004-06-04 16:08:29 -07:00
|
|
|
|
GimpTool *tool = GIMP_TOOL (rect_tool);
|
|
|
|
|
|
GimpSelectionTool *sel_tool = GIMP_SELECTION_TOOL (rect_tool);
|
2003-02-05 06:39:40 -08:00
|
|
|
|
GimpSelectionOptions *options;
|
2000-01-19 11:06:13 -08:00
|
|
|
|
|
2004-06-04 16:08:29 -07:00
|
|
|
|
options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
|
2000-06-14 03:59:16 -07:00
|
|
|
|
|
2006-03-28 09:55:52 -08:00
|
|
|
|
gimp_channel_select_rectangle (gimp_image_get_mask (tool->display->image),
|
2003-10-06 05:17:11 -07:00
|
|
|
|
x, y, w, h,
|
|
|
|
|
|
sel_tool->op,
|
|
|
|
|
|
options->feather,
|
|
|
|
|
|
options->feather_radius,
|
|
|
|
|
|
options->feather_radius);
|
2000-01-19 11:06:13 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2000-03-01 15:22:43 -08:00
|
|
|
|
void
|
2001-03-07 20:15:32 -08:00
|
|
|
|
gimp_rect_select_tool_rect_select (GimpRectSelectTool *rect_tool,
|
|
|
|
|
|
gint x,
|
|
|
|
|
|
gint y,
|
|
|
|
|
|
gint w,
|
|
|
|
|
|
gint h)
|
2000-03-01 15:22:43 -08:00
|
|
|
|
{
|
2003-02-05 06:39:40 -08:00
|
|
|
|
GimpTool *tool;
|
|
|
|
|
|
GimpSelectionOptions *options;
|
2001-11-10 06:17:01 -08:00
|
|
|
|
|
2001-03-07 20:15:32 -08:00
|
|
|
|
g_return_if_fail (GIMP_IS_RECT_SELECT_TOOL (rect_tool));
|
2000-03-01 15:22:43 -08:00
|
|
|
|
|
2003-02-05 06:39:40 -08:00
|
|
|
|
tool = GIMP_TOOL (rect_tool);
|
|
|
|
|
|
options = GIMP_SELECTION_OPTIONS (tool->tool_info->tool_options);
|
2001-11-10 06:17:01 -08:00
|
|
|
|
|
2003-02-05 06:39:40 -08:00
|
|
|
|
if (options->auto_shrink)
|
2001-11-10 06:17:01 -08:00
|
|
|
|
{
|
2004-02-05 03:11:22 -08:00
|
|
|
|
gint off_x = 0;
|
|
|
|
|
|
gint off_y = 0;
|
2001-11-10 06:17:01 -08:00
|
|
|
|
gint x2, y2;
|
|
|
|
|
|
|
2004-02-05 03:11:22 -08:00
|
|
|
|
if (! gimp_rectangle_intersect (x, y, w, h,
|
|
|
|
|
|
0, 0,
|
2006-03-28 09:55:52 -08:00
|
|
|
|
tool->display->image->width,
|
|
|
|
|
|
tool->display->image->height,
|
2004-02-05 03:11:22 -08:00
|
|
|
|
&x, &y, &w, &h))
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2001-11-10 06:17:01 -08:00
|
|
|
|
|
2003-02-05 06:39:40 -08:00
|
|
|
|
if (! options->shrink_merged)
|
2001-11-10 06:17:01 -08:00
|
|
|
|
{
|
2004-02-05 03:11:22 -08:00
|
|
|
|
GimpItem *item;
|
|
|
|
|
|
gint width, height;
|
2001-11-10 06:17:01 -08:00
|
|
|
|
|
2006-03-28 09:55:52 -08:00
|
|
|
|
item = GIMP_ITEM (gimp_image_active_drawable (tool->display->image));
|
2003-05-08 06:12:46 -07:00
|
|
|
|
|
2003-05-08 07:06:03 -07:00
|
|
|
|
gimp_item_offsets (item, &off_x, &off_y);
|
2003-05-08 06:12:46 -07:00
|
|
|
|
width = gimp_item_width (item);
|
|
|
|
|
|
height = gimp_item_height (item);
|
2001-11-10 06:17:01 -08:00
|
|
|
|
|
2004-02-05 03:11:22 -08:00
|
|
|
|
if (! gimp_rectangle_intersect (x, y, w, h,
|
|
|
|
|
|
off_x, off_y, width, height,
|
|
|
|
|
|
&x, &y, &w, &h))
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
x -= off_x;
|
|
|
|
|
|
y -= off_y;
|
2001-11-10 06:17:01 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2006-03-28 09:55:52 -08:00
|
|
|
|
if (gimp_image_crop_auto_shrink (tool->display->image,
|
2001-11-10 06:17:01 -08:00
|
|
|
|
x, y,
|
|
|
|
|
|
x + w, y + h,
|
2003-02-05 06:39:40 -08:00
|
|
|
|
! options->shrink_merged,
|
2001-11-10 06:17:01 -08:00
|
|
|
|
&x, &y,
|
|
|
|
|
|
&x2, &y2))
|
|
|
|
|
|
{
|
|
|
|
|
|
w = x2 - x;
|
|
|
|
|
|
h = y2 - y;
|
|
|
|
|
|
}
|
2004-02-05 03:11:22 -08:00
|
|
|
|
|
|
|
|
|
|
x += off_x;
|
|
|
|
|
|
y += off_y;
|
2001-11-10 06:17:01 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2001-11-20 06:20:17 -08:00
|
|
|
|
GIMP_RECT_SELECT_TOOL_GET_CLASS (rect_tool)->rect_select (rect_tool,
|
|
|
|
|
|
x, y, w, h);
|
1997-11-24 14:05:25 -08:00
|
|
|
|
}
|
2003-08-21 18:42:57 -07:00
|
|
|
|
|
2003-02-24 18:13:03 -08:00
|
|
|
|
static void
|
|
|
|
|
|
gimp_rect_select_tool_update_options (GimpRectSelectTool *rect_sel,
|
2006-03-28 09:55:52 -08:00
|
|
|
|
GimpDisplay *display)
|
2003-02-24 18:13:03 -08:00
|
|
|
|
{
|
2004-06-01 15:04:20 -07:00
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
|
|
gdouble width;
|
|
|
|
|
|
gdouble height;
|
2003-02-24 18:13:03 -08:00
|
|
|
|
|
|
|
|
|
|
if (rect_sel->fixed_mode != GIMP_RECT_SELECT_MODE_FREE)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2006-03-28 09:55:52 -08:00
|
|
|
|
shell = GIMP_DISPLAY_SHELL (display->shell);
|
2004-06-01 15:04:20 -07:00
|
|
|
|
|
|
|
|
|
|
if (shell->unit == GIMP_UNIT_PIXEL)
|
2003-02-24 18:13:03 -08:00
|
|
|
|
{
|
2005-03-07 13:31:22 -08:00
|
|
|
|
width = rect_sel->w;
|
|
|
|
|
|
height = rect_sel->h;
|
2003-02-24 18:13:03 -08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2006-03-28 09:55:52 -08:00
|
|
|
|
GimpImage *image = display->image;
|
2003-10-01 10:32:14 -07:00
|
|
|
|
|
2005-03-07 13:31:22 -08:00
|
|
|
|
width = (rect_sel->w *
|
2004-06-01 15:04:20 -07:00
|
|
|
|
_gimp_unit_get_factor (image->gimp,
|
|
|
|
|
|
shell->unit) / image->xresolution);
|
2005-03-07 13:31:22 -08:00
|
|
|
|
height = (rect_sel->h *
|
2004-06-01 15:04:20 -07:00
|
|
|
|
_gimp_unit_get_factor (image->gimp,
|
|
|
|
|
|
shell->unit) / image->yresolution);
|
2003-02-24 18:13:03 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-02-27 17:14:30 -08:00
|
|
|
|
g_object_set (GIMP_TOOL (rect_sel)->tool_info->tool_options,
|
2003-02-24 18:13:03 -08:00
|
|
|
|
"fixed-width", width,
|
|
|
|
|
|
"fixed-height", height,
|
2004-06-01 15:04:20 -07:00
|
|
|
|
"fixed-unit", shell->unit,
|
2003-02-24 18:13:03 -08:00
|
|
|
|
NULL);
|
|
|
|
|
|
}
|