2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2005-02-01 02:43:28 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2005-02-01 02:43:28 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2005-02-01 02:43:28 +08:00
|
|
|
* (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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-02-01 02:43:28 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2005-02-01 02:43:28 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2007-11-11 22:00:48 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2005-02-01 02:43:28 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "tools-types.h"
|
|
|
|
|
2005-10-21 05:33:40 +08:00
|
|
|
#include "base/boundary.h"
|
|
|
|
|
2005-02-01 02:43:28 +08:00
|
|
|
#include "core/gimpchannel.h"
|
|
|
|
#include "core/gimpchannel-select.h"
|
2005-04-10 02:08:47 +08:00
|
|
|
#include "core/gimplayer-floating-sel.h"
|
2005-02-01 02:43:28 +08:00
|
|
|
#include "core/gimpimage.h"
|
2006-06-03 03:39:28 +08:00
|
|
|
#include "core/gimpimage-undo.h"
|
2005-07-12 03:21:52 +08:00
|
|
|
#include "core/gimppickable.h"
|
2005-02-01 02:43:28 +08:00
|
|
|
#include "core/gimp-utils.h"
|
2006-06-03 03:39:28 +08:00
|
|
|
#include "core/gimpundostack.h"
|
2005-02-01 02:43:28 +08:00
|
|
|
|
|
|
|
#include "widgets/gimpdialogfactory.h"
|
|
|
|
#include "widgets/gimphelp-ids.h"
|
|
|
|
#include "widgets/gimpviewabledialog.h"
|
|
|
|
#include "widgets/gimpwidgets-utils.h"
|
|
|
|
|
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
#include "display/gimpdisplayshell.h"
|
|
|
|
#include "display/gimpdisplayshell-transform.h"
|
2006-08-11 03:03:46 +08:00
|
|
|
#include "display/gimpdisplayshell-appearance.h"
|
2005-02-01 02:43:28 +08:00
|
|
|
|
2007-05-03 01:15:03 +08:00
|
|
|
#include "gimpeditselectiontool.h"
|
2005-02-01 02:43:28 +08:00
|
|
|
#include "gimpselectiontool.h"
|
|
|
|
#include "gimpselectionoptions.h"
|
2005-03-03 02:18:19 +08:00
|
|
|
#include "gimprectangletool.h"
|
|
|
|
#include "gimprectangleoptions.h"
|
2006-06-11 05:34:12 +08:00
|
|
|
#include "gimprectangleselecttool.h"
|
|
|
|
#include "gimprectangleselectoptions.h"
|
2005-02-01 02:43:28 +08:00
|
|
|
#include "gimptoolcontrol.h"
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
typedef struct GimpRectangleSelectToolPrivate
|
2007-11-11 19:45:07 +08:00
|
|
|
{
|
|
|
|
GimpChannelOps operation; /* remember for use when modifying */
|
|
|
|
gboolean use_saved_op; /* use operation or get from options */
|
|
|
|
gboolean saved_show_selection; /* used to remember existing value */
|
|
|
|
GimpUndo *undo;
|
|
|
|
GimpUndo *redo;
|
|
|
|
|
|
|
|
gboolean round_corners;
|
|
|
|
gdouble corner_radius;
|
2007-11-11 22:00:48 +08:00
|
|
|
|
|
|
|
gdouble press_x;
|
|
|
|
gdouble press_y;
|
2008-03-09 23:38:25 +08:00
|
|
|
} GimpRectangleSelectToolPrivate;
|
2007-11-11 19:45:07 +08:00
|
|
|
|
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
#define GIMP_RECTANGLE_SELECT_TOOL_GET_PRIVATE(obj) \
|
|
|
|
((GimpRectangleSelectToolPrivate *) ((GimpRectangleSelectTool *) (obj))->priv)
|
2007-11-11 19:45:07 +08:00
|
|
|
|
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
static void gimp_rectangle_select_tool_rectangle_tool_iface_init (GimpRectangleToolInterface *iface);
|
2006-06-11 02:24:58 +08:00
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
static GObject *gimp_rectangle_select_tool_constructor (GType type,
|
2007-11-19 05:26:52 +08:00
|
|
|
guint n_params,
|
2006-09-13 02:41:09 +08:00
|
|
|
GObjectConstructParam *params);
|
2008-03-09 23:38:25 +08:00
|
|
|
static void gimp_rectangle_select_tool_control (GimpTool *tool,
|
2007-11-19 05:26:52 +08:00
|
|
|
GimpToolAction action,
|
|
|
|
GimpDisplay *display);
|
2008-03-09 23:38:25 +08:00
|
|
|
static void gimp_rectangle_select_tool_button_press (GimpTool *tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
const GimpCoords *coords,
|
2007-11-19 05:26:52 +08:00
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
2009-06-20 23:37:31 +08:00
|
|
|
GimpButtonPressType press_type,
|
2007-11-19 05:26:52 +08:00
|
|
|
GimpDisplay *display);
|
2008-03-09 23:38:25 +08:00
|
|
|
static void gimp_rectangle_select_tool_button_release (GimpTool *tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
const GimpCoords *coords,
|
2007-11-19 05:26:52 +08:00
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpButtonReleaseType release_type,
|
|
|
|
GimpDisplay *display);
|
2008-03-09 23:38:25 +08:00
|
|
|
static void gimp_rectangle_select_tool_active_modifier_key
|
|
|
|
(GimpTool *tool,
|
2007-11-19 05:26:52 +08:00
|
|
|
GdkModifierType key,
|
|
|
|
gboolean press,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display);
|
2008-03-09 23:38:25 +08:00
|
|
|
static gboolean gimp_rectangle_select_tool_key_press (GimpTool *tool,
|
2007-11-19 05:26:52 +08:00
|
|
|
GdkEventKey *kevent,
|
|
|
|
GimpDisplay *display);
|
2008-03-09 23:38:25 +08:00
|
|
|
static void gimp_rectangle_select_tool_oper_update (GimpTool *tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
const GimpCoords *coords,
|
2007-11-19 05:26:52 +08:00
|
|
|
GdkModifierType state,
|
|
|
|
gboolean proximity,
|
|
|
|
GimpDisplay *display);
|
2008-03-09 23:38:25 +08:00
|
|
|
static void gimp_rectangle_select_tool_cursor_update (GimpTool *tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
const GimpCoords *coords,
|
2007-11-19 05:26:52 +08:00
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display);
|
2008-03-09 23:38:25 +08:00
|
|
|
static void gimp_rectangle_select_tool_draw (GimpDrawTool *draw_tool);
|
|
|
|
static gboolean gimp_rectangle_select_tool_select (GimpRectangleTool *rect_tool,
|
2007-11-19 05:26:52 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h);
|
2008-03-09 23:38:25 +08:00
|
|
|
static gboolean gimp_rectangle_select_tool_execute (GimpRectangleTool *rect_tool,
|
2007-11-19 05:26:52 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h);
|
2008-03-09 23:38:25 +08:00
|
|
|
static void gimp_rectangle_select_tool_cancel (GimpRectangleTool *rect_tool);
|
2008-05-02 17:05:13 +08:00
|
|
|
static gboolean gimp_rectangle_select_tool_rectangle_change_complete
|
2008-03-09 23:38:25 +08:00
|
|
|
(GimpRectangleTool *rect_tool);
|
|
|
|
static void gimp_rectangle_select_tool_real_select (GimpRectangleSelectTool *rect_sel_tool,
|
2007-11-19 05:26:52 +08:00
|
|
|
GimpChannelOps operation,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h);
|
2008-09-25 04:55:55 +08:00
|
|
|
static GimpChannelOps
|
|
|
|
gimp_rectangle_select_tool_get_operation (GimpRectangleSelectTool *rect_sel_tool);
|
2008-03-09 23:38:25 +08:00
|
|
|
static void gimp_rectangle_select_tool_update_option_defaults
|
|
|
|
(GimpRectangleSelectTool *rect_sel_tool,
|
|
|
|
gboolean ignore_pending);
|
2006-09-13 02:41:09 +08:00
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
static void gimp_rectangle_select_tool_round_corners_notify
|
|
|
|
(GimpRectangleSelectOptions *options,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GimpRectangleSelectTool *rect_sel_tool);
|
2006-09-13 02:41:09 +08:00
|
|
|
|
2006-06-11 02:24:58 +08:00
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GimpRectangleSelectTool, gimp_rectangle_select_tool,
|
2005-12-13 17:13:50 +08:00
|
|
|
GIMP_TYPE_SELECTION_TOOL,
|
|
|
|
G_IMPLEMENT_INTERFACE (GIMP_TYPE_RECTANGLE_TOOL,
|
2008-03-09 23:38:25 +08:00
|
|
|
gimp_rectangle_select_tool_rectangle_tool_iface_init))
|
2005-12-13 17:13:50 +08:00
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
#define parent_class gimp_rectangle_select_tool_parent_class
|
2005-02-01 02:43:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2008-03-09 23:38:25 +08:00
|
|
|
gimp_rectangle_select_tool_register (GimpToolRegisterCallback callback,
|
|
|
|
gpointer data)
|
2005-02-01 02:43:28 +08:00
|
|
|
{
|
2008-03-09 23:38:25 +08:00
|
|
|
(* callback) (GIMP_TYPE_RECTANGLE_SELECT_TOOL,
|
|
|
|
GIMP_TYPE_RECTANGLE_SELECT_OPTIONS,
|
|
|
|
gimp_rectangle_select_options_gui,
|
2005-02-01 02:43:28 +08:00
|
|
|
0,
|
2006-06-11 02:24:58 +08:00
|
|
|
"gimp-rect-select-tool",
|
2006-09-19 02:00:22 +08:00
|
|
|
_("Rectangle Select"),
|
|
|
|
_("Rectangle Select Tool: Select a rectangular region"),
|
|
|
|
N_("_Rectangle Select"), "R",
|
2005-02-01 02:43:28 +08:00
|
|
|
NULL, GIMP_HELP_TOOL_RECT_SELECT,
|
2005-02-01 04:43:46 +08:00
|
|
|
GIMP_STOCK_TOOL_RECT_SELECT,
|
2005-02-01 02:43:28 +08:00
|
|
|
data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-03-09 23:38:25 +08:00
|
|
|
gimp_rectangle_select_tool_class_init (GimpRectangleSelectToolClass *klass)
|
2005-02-01 02:43:28 +08:00
|
|
|
{
|
2005-08-15 22:23:28 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
|
|
|
|
GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
|
2005-02-01 02:43:28 +08:00
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
g_type_class_add_private (klass, sizeof (GimpRectangleSelectToolPrivate));
|
2007-11-11 19:45:07 +08:00
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
object_class->constructor = gimp_rectangle_select_tool_constructor;
|
2006-11-05 20:35:59 +08:00
|
|
|
object_class->set_property = gimp_rectangle_tool_set_property;
|
|
|
|
object_class->get_property = gimp_rectangle_tool_get_property;
|
2005-12-13 17:13:50 +08:00
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
gimp_rectangle_tool_install_properties (object_class);
|
2005-08-15 22:23:28 +08:00
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
tool_class->control = gimp_rectangle_select_tool_control;
|
|
|
|
tool_class->button_press = gimp_rectangle_select_tool_button_press;
|
|
|
|
tool_class->button_release = gimp_rectangle_select_tool_button_release;
|
2006-09-13 02:41:09 +08:00
|
|
|
tool_class->motion = gimp_rectangle_tool_motion;
|
2008-03-09 23:38:25 +08:00
|
|
|
tool_class->key_press = gimp_rectangle_select_tool_key_press;
|
|
|
|
tool_class->active_modifier_key = gimp_rectangle_select_tool_active_modifier_key;
|
|
|
|
tool_class->oper_update = gimp_rectangle_select_tool_oper_update;
|
|
|
|
tool_class->cursor_update = gimp_rectangle_select_tool_cursor_update;
|
2005-02-01 02:43:28 +08:00
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
draw_tool_class->draw = gimp_rectangle_select_tool_draw;
|
2006-03-26 21:50:13 +08:00
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
klass->select = gimp_rectangle_select_tool_real_select;
|
2005-02-01 02:43:28 +08:00
|
|
|
}
|
|
|
|
|
2006-11-05 20:35:59 +08:00
|
|
|
static void
|
2008-03-09 23:38:25 +08:00
|
|
|
gimp_rectangle_select_tool_rectangle_tool_iface_init (GimpRectangleToolInterface *iface)
|
2006-11-05 20:35:59 +08:00
|
|
|
{
|
2008-05-02 17:05:13 +08:00
|
|
|
iface->execute = gimp_rectangle_select_tool_execute;
|
|
|
|
iface->cancel = gimp_rectangle_select_tool_cancel;
|
|
|
|
iface->rectangle_change_complete = gimp_rectangle_select_tool_rectangle_change_complete;
|
2006-11-05 20:35:59 +08:00
|
|
|
}
|
|
|
|
|
2005-02-01 02:43:28 +08:00
|
|
|
static void
|
2008-03-09 23:38:25 +08:00
|
|
|
gimp_rectangle_select_tool_init (GimpRectangleSelectTool *rect_sel_tool)
|
2005-02-01 02:43:28 +08:00
|
|
|
{
|
2008-03-09 23:38:25 +08:00
|
|
|
GimpTool *tool = GIMP_TOOL (rect_sel_tool);
|
|
|
|
GimpRectangleSelectToolPrivate *priv;
|
2007-11-11 19:45:07 +08:00
|
|
|
|
2007-12-09 17:38:34 +08:00
|
|
|
gimp_rectangle_tool_init (GIMP_RECTANGLE_TOOL (rect_sel_tool));
|
|
|
|
|
2007-11-19 05:26:52 +08:00
|
|
|
rect_sel_tool->priv = G_TYPE_INSTANCE_GET_PRIVATE (rect_sel_tool,
|
2008-03-09 23:38:25 +08:00
|
|
|
GIMP_TYPE_RECTANGLE_SELECT_TOOL,
|
|
|
|
GimpRectangleSelectToolPrivate);
|
2007-11-11 19:45:07 +08:00
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
priv = GIMP_RECTANGLE_SELECT_TOOL_GET_PRIVATE (rect_sel_tool);
|
2005-02-01 02:43:28 +08:00
|
|
|
|
2007-02-28 05:11:35 +08:00
|
|
|
gimp_tool_control_set_wants_click (tool->control, TRUE);
|
2008-08-21 00:22:09 +08:00
|
|
|
gimp_tool_control_set_precision (tool->control,
|
|
|
|
GIMP_CURSOR_PRECISION_PIXEL_BORDER);
|
2006-09-13 02:41:09 +08:00
|
|
|
gimp_tool_control_set_tool_cursor (tool->control,
|
|
|
|
GIMP_TOOL_CURSOR_RECT_SELECT);
|
2006-06-15 00:25:19 +08:00
|
|
|
gimp_tool_control_set_dirty_mask (tool->control,
|
|
|
|
GIMP_DIRTY_IMAGE_SIZE |
|
|
|
|
GIMP_DIRTY_SELECTION);
|
|
|
|
|
2007-11-11 22:00:48 +08:00
|
|
|
priv->undo = NULL;
|
|
|
|
priv->redo = NULL;
|
|
|
|
|
|
|
|
priv->press_x = 0.0;
|
|
|
|
priv->press_y = 0.0;
|
2005-02-01 02:43:28 +08:00
|
|
|
}
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
static GObject *
|
2008-03-09 23:38:25 +08:00
|
|
|
gimp_rectangle_select_tool_constructor (GType type,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params)
|
2005-08-15 22:23:28 +08:00
|
|
|
{
|
2008-03-09 23:38:25 +08:00
|
|
|
GObject *object;
|
|
|
|
GimpRectangleSelectTool *rect_sel_tool;
|
|
|
|
GimpRectangleSelectOptions *options;
|
|
|
|
GimpRectangleSelectToolPrivate *priv;
|
2005-04-10 02:08:47 +08:00
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
|
|
|
|
|
2006-11-05 22:11:34 +08:00
|
|
|
gimp_rectangle_tool_constructor (object);
|
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
rect_sel_tool = GIMP_RECTANGLE_SELECT_TOOL (object);
|
|
|
|
options = GIMP_RECTANGLE_SELECT_TOOL_GET_OPTIONS (rect_sel_tool);
|
|
|
|
priv = GIMP_RECTANGLE_SELECT_TOOL_GET_PRIVATE (rect_sel_tool);
|
2006-11-05 21:45:04 +08:00
|
|
|
|
2007-11-11 19:45:07 +08:00
|
|
|
priv->round_corners = options->round_corners;
|
|
|
|
priv->corner_radius = options->corner_radius;
|
2006-11-05 21:45:04 +08:00
|
|
|
|
|
|
|
g_signal_connect_object (options, "notify::round-corners",
|
2008-03-09 23:38:25 +08:00
|
|
|
G_CALLBACK (gimp_rectangle_select_tool_round_corners_notify),
|
2006-11-05 21:45:04 +08:00
|
|
|
object, 0);
|
|
|
|
g_signal_connect_object (options, "notify::corner-radius",
|
2008-03-09 23:38:25 +08:00
|
|
|
G_CALLBACK (gimp_rectangle_select_tool_round_corners_notify),
|
2006-11-05 21:45:04 +08:00
|
|
|
object, 0);
|
2005-08-15 22:23:28 +08:00
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
gimp_rectangle_select_tool_update_option_defaults (rect_sel_tool, FALSE);
|
2007-09-02 12:39:17 +08:00
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
return object;
|
2005-04-10 02:08:47 +08:00
|
|
|
}
|
|
|
|
|
2005-02-01 02:43:28 +08:00
|
|
|
static void
|
2008-03-09 23:38:25 +08:00
|
|
|
gimp_rectangle_select_tool_control (GimpTool *tool,
|
|
|
|
GimpToolAction action,
|
|
|
|
GimpDisplay *display)
|
2005-02-01 02:43:28 +08:00
|
|
|
{
|
2006-05-24 01:37:18 +08:00
|
|
|
gimp_rectangle_tool_control (tool, action, display);
|
2005-08-15 22:23:28 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
|
2005-08-15 22:23:28 +08:00
|
|
|
}
|
|
|
|
|
2006-10-19 02:54:28 +08:00
|
|
|
static void
|
2008-03-09 23:38:25 +08:00
|
|
|
gimp_rectangle_select_tool_draw (GimpDrawTool *draw_tool)
|
2006-10-19 02:54:28 +08:00
|
|
|
{
|
2008-03-09 23:38:25 +08:00
|
|
|
GimpRectangleSelectTool *rect_sel_tool;
|
|
|
|
GimpRectangleSelectToolPrivate *priv;
|
2007-11-11 19:45:07 +08:00
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
rect_sel_tool = GIMP_RECTANGLE_SELECT_TOOL (draw_tool);
|
|
|
|
priv = GIMP_RECTANGLE_SELECT_TOOL_GET_PRIVATE (rect_sel_tool);
|
2006-11-05 21:45:04 +08:00
|
|
|
|
|
|
|
gimp_rectangle_tool_draw (draw_tool);
|
|
|
|
|
2007-11-11 19:45:07 +08:00
|
|
|
if (priv->round_corners)
|
2006-10-19 02:54:28 +08:00
|
|
|
{
|
2006-11-05 21:45:04 +08:00
|
|
|
gint x1, y1, x2, y2;
|
2006-10-19 02:54:28 +08:00
|
|
|
gdouble radius;
|
2006-11-05 20:35:59 +08:00
|
|
|
gint square_size;
|
2006-10-19 02:54:28 +08:00
|
|
|
|
2007-11-19 05:26:52 +08:00
|
|
|
g_object_get (rect_sel_tool,
|
2006-11-05 21:45:04 +08:00
|
|
|
"x1", &x1,
|
|
|
|
"y1", &y1,
|
|
|
|
"x2", &x2,
|
|
|
|
"y2", &y2,
|
|
|
|
NULL);
|
|
|
|
|
2007-11-11 19:45:07 +08:00
|
|
|
radius = MIN (priv->corner_radius,
|
2006-10-19 02:54:28 +08:00
|
|
|
MIN ((x2 - x1) / 2.0, (y2 - y1) / 2.0));
|
|
|
|
|
2006-11-05 20:35:59 +08:00
|
|
|
square_size = (int) (radius * 2);
|
2006-10-19 02:54:28 +08:00
|
|
|
|
|
|
|
gimp_draw_tool_draw_arc (draw_tool, FALSE,
|
|
|
|
x1, y1,
|
2006-11-05 20:35:59 +08:00
|
|
|
square_size, square_size,
|
2006-10-19 02:54:28 +08:00
|
|
|
90 * 64, 90 * 64,
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
gimp_draw_tool_draw_arc (draw_tool, FALSE,
|
2006-11-05 20:35:59 +08:00
|
|
|
x2 - square_size, y1,
|
|
|
|
square_size, square_size,
|
2006-10-19 02:54:28 +08:00
|
|
|
0, 90 * 64,
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
gimp_draw_tool_draw_arc (draw_tool, FALSE,
|
2006-11-05 20:35:59 +08:00
|
|
|
x2 - square_size, y2 - square_size,
|
|
|
|
square_size, square_size,
|
2006-10-19 02:54:28 +08:00
|
|
|
270 * 64, 90 * 64,
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
gimp_draw_tool_draw_arc (draw_tool, FALSE,
|
2006-11-05 20:35:59 +08:00
|
|
|
x1, y2 - square_size,
|
|
|
|
square_size, square_size,
|
2006-10-19 02:54:28 +08:00
|
|
|
180 * 64, 90 * 64,
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-31 02:46:38 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_rectangle_select_tool_delegate_button_press (GimpRectangleSelectTool *rect_sel_tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
const GimpCoords *coords,
|
2008-05-31 02:46:38 +08:00
|
|
|
GimpDisplay *display)
|
|
|
|
{
|
|
|
|
GimpTool *tool = GIMP_TOOL (rect_sel_tool);
|
|
|
|
gboolean button_press_delegated = FALSE;
|
|
|
|
GimpDisplay *old_display = tool->display;
|
|
|
|
|
|
|
|
tool->display = display;
|
|
|
|
if (! gimp_tool_control_is_active (tool->control))
|
|
|
|
{
|
|
|
|
gimp_tool_control_activate (tool->control);
|
|
|
|
}
|
|
|
|
|
|
|
|
button_press_delegated
|
|
|
|
= gimp_selection_tool_start_edit (GIMP_SELECTION_TOOL (tool),
|
|
|
|
coords);
|
|
|
|
|
|
|
|
if (gimp_tool_control_is_active (tool->control))
|
|
|
|
{
|
|
|
|
gimp_tool_control_halt (tool->control);
|
|
|
|
}
|
|
|
|
tool->display = old_display;
|
|
|
|
|
|
|
|
return button_press_delegated;
|
|
|
|
}
|
|
|
|
|
2005-10-20 05:13:25 +08:00
|
|
|
static void
|
2009-06-20 23:37:31 +08:00
|
|
|
gimp_rectangle_select_tool_button_press (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpButtonPressType press_type,
|
|
|
|
GimpDisplay *display)
|
2005-10-20 05:13:25 +08:00
|
|
|
{
|
2008-03-09 23:38:25 +08:00
|
|
|
GimpRectangleTool *rectangle;
|
|
|
|
GimpRectangleSelectTool *rect_sel_tool;
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
GimpRectangleSelectToolPrivate *priv;
|
|
|
|
GimpRectangleFunction function;
|
2007-11-11 19:45:07 +08:00
|
|
|
|
2007-11-19 05:26:52 +08:00
|
|
|
rectangle = GIMP_RECTANGLE_TOOL (tool);
|
2008-03-09 23:38:25 +08:00
|
|
|
rect_sel_tool = GIMP_RECTANGLE_SELECT_TOOL (tool);
|
2009-10-05 01:56:39 +08:00
|
|
|
shell = gimp_display_get_shell (display);
|
2008-03-09 23:38:25 +08:00
|
|
|
priv = GIMP_RECTANGLE_SELECT_TOOL_GET_PRIVATE (rect_sel_tool);
|
2006-06-02 23:23:47 +08:00
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
if (tool->display && display != tool->display)
|
2006-06-02 23:23:47 +08:00
|
|
|
{
|
2008-05-31 02:46:38 +08:00
|
|
|
gimp_rectangle_tool_cancel (GIMP_RECTANGLE_TOOL (tool));
|
|
|
|
}
|
2006-06-02 23:23:47 +08:00
|
|
|
|
2008-05-31 02:46:38 +08:00
|
|
|
if (gimp_rectangle_select_tool_delegate_button_press (rect_sel_tool,
|
|
|
|
coords,
|
|
|
|
display))
|
|
|
|
{
|
|
|
|
/* In some cases we want to finnish the rectangle select tool
|
|
|
|
* and hand over responsability to the selection tool
|
|
|
|
*/
|
|
|
|
gimp_rectangle_tool_execute (rectangle);
|
|
|
|
gimp_rectangle_tool_control (tool, GIMP_TOOL_ACTION_HALT, display);
|
|
|
|
gimp_rectangle_select_tool_update_option_defaults (rect_sel_tool,
|
|
|
|
TRUE);
|
|
|
|
return;
|
|
|
|
}
|
2007-07-31 23:39:26 +08:00
|
|
|
|
2008-05-31 02:46:38 +08:00
|
|
|
function = gimp_rectangle_tool_get_function (rectangle);
|
2006-06-02 23:23:47 +08:00
|
|
|
|
2008-05-31 02:46:38 +08:00
|
|
|
priv->saved_show_selection = gimp_display_shell_get_show_selection (shell);
|
2006-06-02 23:23:47 +08:00
|
|
|
|
2006-06-13 05:15:22 +08:00
|
|
|
/* if the shift or ctrl keys are down, we don't want to adjust, we
|
|
|
|
* want to create a new rectangle, regardless of pointer loc */
|
|
|
|
if (state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))
|
2007-11-24 17:27:55 +08:00
|
|
|
gimp_rectangle_tool_set_function (rectangle, GIMP_RECTANGLE_TOOL_CREATING);
|
2006-06-13 05:15:22 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
gimp_rectangle_tool_button_press (tool, coords, time, state, display);
|
2006-06-11 00:49:07 +08:00
|
|
|
|
2007-11-11 22:00:48 +08:00
|
|
|
priv->press_x = coords->x;
|
|
|
|
priv->press_y = coords->y;
|
|
|
|
|
2006-06-11 00:49:07 +08:00
|
|
|
/* if we have an existing rectangle in the current display, then
|
|
|
|
* we have already "executed", and need to undo at this point,
|
|
|
|
* unless the user has done something in the meantime
|
|
|
|
*/
|
2006-11-16 04:45:43 +08:00
|
|
|
function = gimp_rectangle_tool_get_function (rectangle);
|
2006-06-11 00:49:07 +08:00
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
if (function == GIMP_RECTANGLE_TOOL_CREATING)
|
2006-06-11 00:49:07 +08:00
|
|
|
{
|
2007-11-11 19:45:07 +08:00
|
|
|
priv->use_saved_op = FALSE;
|
2006-06-11 00:49:07 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-02-05 03:06:49 +08:00
|
|
|
GimpImage *image = gimp_display_get_image (tool->display);
|
|
|
|
GimpUndoStack *undo_stack = gimp_image_get_undo_stack (image);
|
|
|
|
GimpUndoStack *redo_stack = gimp_image_get_redo_stack (image);
|
2008-09-25 04:55:55 +08:00
|
|
|
GimpUndo *undo;
|
|
|
|
GimpChannelOps operation;
|
2006-06-11 00:49:07 +08:00
|
|
|
|
2010-02-05 03:06:49 +08:00
|
|
|
undo = gimp_undo_stack_peek (undo_stack);
|
2006-06-11 00:49:07 +08:00
|
|
|
|
2007-11-11 19:45:07 +08:00
|
|
|
if (undo && priv->undo == undo)
|
2006-06-11 00:49:07 +08:00
|
|
|
{
|
2006-06-15 00:25:19 +08:00
|
|
|
/* prevent this change from halting the tool */
|
|
|
|
gimp_tool_control_set_preserve (tool->control, TRUE);
|
|
|
|
|
2006-06-11 00:49:07 +08:00
|
|
|
gimp_image_undo (image);
|
|
|
|
|
2006-06-15 00:25:19 +08:00
|
|
|
gimp_tool_control_set_preserve (tool->control, FALSE);
|
|
|
|
|
2006-06-11 02:24:58 +08:00
|
|
|
/* we will need to redo if the user cancels or executes */
|
2010-02-05 03:06:49 +08:00
|
|
|
priv->redo = gimp_undo_stack_peek (redo_stack);
|
2006-06-11 00:49:07 +08:00
|
|
|
}
|
2006-08-11 03:03:46 +08:00
|
|
|
|
|
|
|
/* if the operation is "Replace", turn off the marching ants,
|
|
|
|
because they are confusing */
|
2008-09-25 04:55:55 +08:00
|
|
|
operation = gimp_rectangle_select_tool_get_operation (rect_sel_tool);
|
|
|
|
|
2006-10-18 05:53:22 +08:00
|
|
|
if (operation == GIMP_CHANNEL_OP_REPLACE)
|
2007-07-31 23:39:26 +08:00
|
|
|
gimp_display_shell_set_show_selection (shell, FALSE);
|
2006-06-11 00:49:07 +08:00
|
|
|
}
|
|
|
|
|
2007-11-11 19:45:07 +08:00
|
|
|
priv->undo = NULL;
|
2005-10-20 05:13:25 +08:00
|
|
|
}
|
|
|
|
|
2005-10-09 03:20:31 +08:00
|
|
|
static void
|
2008-03-09 23:38:25 +08:00
|
|
|
gimp_rectangle_select_tool_button_release (GimpTool *tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
const GimpCoords *coords,
|
2008-03-09 23:38:25 +08:00
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpButtonReleaseType release_type,
|
|
|
|
GimpDisplay *display)
|
2005-10-09 03:20:31 +08:00
|
|
|
{
|
2008-03-09 23:38:25 +08:00
|
|
|
GimpRectangleSelectTool *rect_sel_tool;
|
|
|
|
GimpRectangleSelectToolPrivate *priv;
|
2009-10-07 01:20:44 +08:00
|
|
|
GimpImage *image;
|
2007-11-11 19:45:07 +08:00
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
rect_sel_tool = GIMP_RECTANGLE_SELECT_TOOL (tool);
|
|
|
|
priv = GIMP_RECTANGLE_SELECT_TOOL_GET_PRIVATE (rect_sel_tool);
|
2006-06-11 00:49:07 +08:00
|
|
|
|
2009-10-07 01:20:44 +08:00
|
|
|
image = gimp_display_get_image (tool->display);
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
gimp_tool_pop_status (tool, display);
|
2009-10-05 01:56:39 +08:00
|
|
|
gimp_display_shell_set_show_selection (gimp_display_get_shell (display),
|
2007-11-11 19:45:07 +08:00
|
|
|
priv->saved_show_selection);
|
2005-10-09 03:20:31 +08:00
|
|
|
|
2006-06-11 02:24:58 +08:00
|
|
|
/*
|
|
|
|
* if the user has not moved the mouse, we need to redo the operation
|
|
|
|
* that was undone on button press.
|
|
|
|
*/
|
2007-02-28 05:11:35 +08:00
|
|
|
if (release_type == GIMP_BUTTON_RELEASE_CLICK)
|
2006-06-11 02:24:58 +08:00
|
|
|
{
|
2010-02-05 03:06:49 +08:00
|
|
|
GimpUndoStack *redo_stack = gimp_image_get_redo_stack (image);
|
|
|
|
GimpUndo *redo = gimp_undo_stack_peek (redo_stack);
|
2006-06-11 02:24:58 +08:00
|
|
|
|
2007-11-11 19:45:07 +08:00
|
|
|
if (redo && priv->redo == redo)
|
2006-06-11 02:24:58 +08:00
|
|
|
{
|
2006-06-15 00:25:19 +08:00
|
|
|
/* prevent this from halting the tool */
|
|
|
|
gimp_tool_control_set_preserve (tool->control, TRUE);
|
|
|
|
|
2006-06-11 02:24:58 +08:00
|
|
|
gimp_image_redo (image);
|
2007-11-11 19:45:07 +08:00
|
|
|
priv->redo = NULL;
|
2006-06-15 00:25:19 +08:00
|
|
|
|
|
|
|
gimp_tool_control_set_preserve (tool->control, FALSE);
|
2006-06-11 02:24:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-28 02:55:12 +08:00
|
|
|
gimp_rectangle_tool_button_release (tool, coords, time, state, release_type,
|
|
|
|
display);
|
2006-06-11 00:49:07 +08:00
|
|
|
|
2007-02-28 02:55:12 +08:00
|
|
|
if (release_type == GIMP_BUTTON_RELEASE_CANCEL)
|
2006-06-11 00:49:07 +08:00
|
|
|
{
|
2007-11-11 19:45:07 +08:00
|
|
|
if (priv->redo)
|
2006-06-11 00:49:07 +08:00
|
|
|
{
|
2006-06-15 00:25:19 +08:00
|
|
|
/* prevent this from halting the tool */
|
|
|
|
gimp_tool_control_set_preserve (tool->control, TRUE);
|
|
|
|
|
2009-10-07 01:20:44 +08:00
|
|
|
gimp_image_redo (image);
|
2006-06-15 00:25:19 +08:00
|
|
|
|
|
|
|
gimp_tool_control_set_preserve (tool->control, FALSE);
|
2006-06-11 00:49:07 +08:00
|
|
|
}
|
|
|
|
|
2007-11-11 19:45:07 +08:00
|
|
|
priv->use_saved_op = TRUE; /* is this correct? */
|
2006-06-11 00:49:07 +08:00
|
|
|
}
|
|
|
|
|
2007-11-11 19:45:07 +08:00
|
|
|
priv->redo = NULL;
|
2005-10-09 03:20:31 +08:00
|
|
|
}
|
|
|
|
|
2006-09-24 06:32:35 +08:00
|
|
|
static void
|
2008-03-09 23:38:25 +08:00
|
|
|
gimp_rectangle_select_tool_active_modifier_key (GimpTool *tool,
|
|
|
|
GdkModifierType key,
|
|
|
|
gboolean press,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display)
|
2006-09-24 06:32:35 +08:00
|
|
|
{
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->active_modifier_key (tool, key, press, state,
|
|
|
|
display);
|
|
|
|
|
|
|
|
gimp_rectangle_tool_active_modifier_key (tool, key, press, state, display);
|
|
|
|
}
|
|
|
|
|
2007-04-13 04:07:38 +08:00
|
|
|
static gboolean
|
2008-03-09 23:38:25 +08:00
|
|
|
gimp_rectangle_select_tool_key_press (GimpTool *tool,
|
|
|
|
GdkEventKey *kevent,
|
|
|
|
GimpDisplay *display)
|
2007-04-13 04:07:38 +08:00
|
|
|
{
|
|
|
|
return (gimp_rectangle_tool_key_press (tool, kevent, display) ||
|
|
|
|
gimp_edit_selection_tool_key_press (tool, kevent, display));
|
|
|
|
}
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
static void
|
2008-11-01 23:17:36 +08:00
|
|
|
gimp_rectangle_select_tool_oper_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
gboolean proximity,
|
|
|
|
GimpDisplay *display)
|
2005-08-15 22:23:28 +08:00
|
|
|
{
|
2006-11-16 04:45:43 +08:00
|
|
|
GimpRectangleFunction function;
|
2006-06-02 23:23:47 +08:00
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
gimp_rectangle_tool_oper_update (tool, coords, state, proximity, display);
|
2005-02-01 02:43:28 +08:00
|
|
|
|
2006-11-16 04:45:43 +08:00
|
|
|
function = gimp_rectangle_tool_get_function (GIMP_RECTANGLE_TOOL (tool));
|
2006-06-02 23:23:47 +08:00
|
|
|
|
2006-03-25 22:23:09 +08:00
|
|
|
GIMP_TOOL_CLASS (parent_class)->oper_update (tool, coords, state, proximity,
|
2006-03-29 01:55:52 +08:00
|
|
|
display);
|
2005-02-01 02:43:28 +08:00
|
|
|
}
|
|
|
|
|
2006-06-02 23:23:47 +08:00
|
|
|
static void
|
2008-11-01 23:17:36 +08:00
|
|
|
gimp_rectangle_select_tool_cursor_update (GimpTool *tool,
|
|
|
|
const GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *display)
|
2006-06-02 23:23:47 +08:00
|
|
|
{
|
|
|
|
gimp_rectangle_tool_cursor_update (tool, coords, state, display);
|
|
|
|
|
2006-06-22 04:55:06 +08:00
|
|
|
/* override the previous if shift or ctrl are down */
|
|
|
|
if (state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))
|
|
|
|
gimp_tool_control_set_cursor (tool->control, GIMP_CURSOR_CROSSHAIR_SMALL);
|
|
|
|
|
2006-06-02 23:23:47 +08:00
|
|
|
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-08 17:54:09 +08:00
|
|
|
static gboolean
|
2008-03-09 23:38:25 +08:00
|
|
|
gimp_rectangle_select_tool_select (GimpRectangleTool *rectangle,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
2005-02-01 02:43:28 +08:00
|
|
|
{
|
2008-09-25 04:55:55 +08:00
|
|
|
GimpTool *tool;
|
|
|
|
GimpRectangleSelectTool *rect_sel_tool;
|
|
|
|
GimpImage *image;
|
|
|
|
gboolean rectangle_exists;
|
|
|
|
GimpChannelOps operation;
|
2007-11-11 19:45:07 +08:00
|
|
|
|
2007-11-19 05:26:52 +08:00
|
|
|
tool = GIMP_TOOL (rectangle);
|
2008-03-09 23:38:25 +08:00
|
|
|
rect_sel_tool = GIMP_RECTANGLE_SELECT_TOOL (rectangle);
|
2007-11-11 19:45:07 +08:00
|
|
|
|
2009-10-07 01:20:44 +08:00
|
|
|
image = gimp_display_get_image (tool->display);
|
2007-12-15 01:22:46 +08:00
|
|
|
|
|
|
|
gimp_tool_pop_status (tool, tool->display);
|
2005-10-09 03:20:31 +08:00
|
|
|
|
2007-12-26 00:21:40 +08:00
|
|
|
rectangle_exists = (x <= gimp_image_get_width (image) &&
|
|
|
|
y <= gimp_image_get_height (image) &&
|
|
|
|
x + w >= 0 &&
|
|
|
|
y + h >= 0 &&
|
|
|
|
w > 0 &&
|
|
|
|
h > 0);
|
2005-09-25 21:40:53 +08:00
|
|
|
|
2008-09-25 04:55:55 +08:00
|
|
|
operation = gimp_rectangle_select_tool_get_operation (rect_sel_tool);
|
2009-10-07 01:20:44 +08:00
|
|
|
|
2005-04-10 02:08:47 +08:00
|
|
|
/* if rectangle exists, turn it into a selection */
|
|
|
|
if (rectangle_exists)
|
2008-03-09 23:38:25 +08:00
|
|
|
GIMP_RECTANGLE_SELECT_TOOL_GET_CLASS (rect_sel_tool)->select (rect_sel_tool,
|
|
|
|
operation,
|
|
|
|
x, y, w, h);
|
2007-02-08 17:54:09 +08:00
|
|
|
|
|
|
|
return rectangle_exists;
|
2006-06-06 01:14:16 +08:00
|
|
|
}
|
2006-03-26 21:50:13 +08:00
|
|
|
|
2006-06-06 01:14:16 +08:00
|
|
|
static void
|
2008-03-09 23:38:25 +08:00
|
|
|
gimp_rectangle_select_tool_real_select (GimpRectangleSelectTool *rect_sel_tool,
|
|
|
|
GimpChannelOps operation,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
2006-06-06 01:14:16 +08:00
|
|
|
{
|
2008-03-09 23:38:25 +08:00
|
|
|
GimpTool *tool = GIMP_TOOL (rect_sel_tool);
|
|
|
|
GimpSelectionOptions *options = GIMP_SELECTION_TOOL_GET_OPTIONS (tool);
|
|
|
|
GimpRectangleSelectOptions *rect_select_options;
|
|
|
|
GimpChannel *channel;
|
2006-10-19 02:54:28 +08:00
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
rect_select_options = GIMP_RECTANGLE_SELECT_TOOL_GET_OPTIONS (tool);
|
2006-10-19 02:54:28 +08:00
|
|
|
|
2009-10-07 01:20:44 +08:00
|
|
|
channel = gimp_image_get_mask (gimp_display_get_image (tool->display));
|
2007-07-31 23:39:26 +08:00
|
|
|
|
2006-10-19 02:54:28 +08:00
|
|
|
if (rect_select_options->round_corners)
|
|
|
|
{
|
2007-07-31 23:39:26 +08:00
|
|
|
/* To prevent elliptification of the rectangle,
|
|
|
|
* we must cap the corner radius.
|
|
|
|
*/
|
|
|
|
gdouble max = MIN (w / 2.0, h / 2.0);
|
|
|
|
gdouble radius = MIN (rect_select_options->corner_radius, max);
|
2006-10-19 02:54:28 +08:00
|
|
|
|
2007-07-31 23:39:26 +08:00
|
|
|
gimp_channel_select_round_rect (channel,
|
2006-10-19 02:54:28 +08:00
|
|
|
x, y, w, h,
|
|
|
|
radius, radius,
|
|
|
|
operation,
|
|
|
|
options->antialias,
|
|
|
|
options->feather,
|
|
|
|
options->feather_radius,
|
|
|
|
options->feather_radius,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-07-31 23:39:26 +08:00
|
|
|
gimp_channel_select_rectangle (channel,
|
2006-10-19 02:54:28 +08:00
|
|
|
x, y, w, h,
|
|
|
|
operation,
|
|
|
|
options->feather,
|
|
|
|
options->feather_radius,
|
|
|
|
options->feather_radius,
|
|
|
|
TRUE);
|
|
|
|
}
|
2006-06-06 01:14:16 +08:00
|
|
|
}
|
2005-04-10 02:08:47 +08:00
|
|
|
|
2008-09-25 04:55:55 +08:00
|
|
|
static GimpChannelOps
|
|
|
|
gimp_rectangle_select_tool_get_operation (GimpRectangleSelectTool *rect_sel_tool)
|
|
|
|
{
|
|
|
|
GimpRectangleSelectToolPrivate *priv;
|
|
|
|
GimpSelectionOptions *options;
|
|
|
|
|
|
|
|
priv = GIMP_RECTANGLE_SELECT_TOOL_GET_PRIVATE (rect_sel_tool);
|
|
|
|
options = GIMP_SELECTION_TOOL_GET_OPTIONS (rect_sel_tool);
|
|
|
|
|
|
|
|
if (priv->use_saved_op)
|
|
|
|
return priv->operation;
|
|
|
|
else
|
|
|
|
return options->operation;
|
|
|
|
}
|
|
|
|
|
2007-09-02 12:39:17 +08:00
|
|
|
/**
|
2008-03-09 23:38:25 +08:00
|
|
|
* gimp_rectangle_select_tool_update_option_defaults:
|
2007-09-02 12:39:17 +08:00
|
|
|
* @crop_tool:
|
|
|
|
* @ignore_pending: %TRUE to ignore any pending crop rectangle.
|
|
|
|
*
|
|
|
|
* Sets the default Fixed: Aspect ratio and Fixed: Size option
|
|
|
|
* properties.
|
|
|
|
*/
|
|
|
|
static void
|
2008-03-09 23:38:25 +08:00
|
|
|
gimp_rectangle_select_tool_update_option_defaults (GimpRectangleSelectTool *rect_sel_tool,
|
|
|
|
gboolean ignore_pending)
|
2007-09-02 12:39:17 +08:00
|
|
|
{
|
|
|
|
GimpTool *tool;
|
|
|
|
GimpRectangleTool *rectangle_tool;
|
|
|
|
GimpRectangleOptions *rectangle_options;
|
|
|
|
|
2007-11-19 05:26:52 +08:00
|
|
|
tool = GIMP_TOOL (rect_sel_tool);
|
2007-09-02 12:39:17 +08:00
|
|
|
rectangle_tool = GIMP_RECTANGLE_TOOL (tool);
|
|
|
|
rectangle_options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (rectangle_tool);
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
if (tool->display != NULL && !ignore_pending)
|
2007-09-02 12:39:17 +08:00
|
|
|
{
|
|
|
|
/* There is a pending rectangle and we should not ignore it, so
|
|
|
|
* set default Fixed: Size to the same as the current pending
|
|
|
|
* rectangle width/height.
|
|
|
|
*/
|
|
|
|
|
|
|
|
gimp_rectangle_tool_pending_size_set (rectangle_tool,
|
|
|
|
G_OBJECT (rectangle_options),
|
2007-10-10 04:54:07 +08:00
|
|
|
"default-aspect-numerator",
|
|
|
|
"default-aspect-denominator");
|
|
|
|
|
|
|
|
g_object_set (G_OBJECT (rectangle_options),
|
|
|
|
"use-string-current", TRUE,
|
|
|
|
NULL);
|
2007-09-02 12:39:17 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-10 04:54:07 +08:00
|
|
|
g_object_set (G_OBJECT (rectangle_options),
|
|
|
|
"default-aspect-numerator", 1.0,
|
|
|
|
"default-aspect-denominator", 1.0,
|
|
|
|
NULL);
|
2007-09-02 12:39:17 +08:00
|
|
|
|
|
|
|
g_object_set (G_OBJECT (rectangle_options),
|
2007-10-10 04:54:07 +08:00
|
|
|
"use-string-current", FALSE,
|
2007-09-02 12:39:17 +08:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-21 23:25:10 +08:00
|
|
|
/*
|
|
|
|
* This function is called if the user clicks and releases the left
|
|
|
|
* button without moving it. There are the things we might want
|
|
|
|
* to do here:
|
|
|
|
* 1) If there is an existing rectangle and we are inside it, we
|
|
|
|
* convert it into a selection.
|
|
|
|
* 2) If there is an existing rectangle and we are outside it, we
|
|
|
|
* clear it.
|
|
|
|
* 3) If there is no rectangle and there is a floating selection,
|
|
|
|
* we anchor it.
|
|
|
|
* 4) If there is no rectangle and we are inside the selection, we
|
|
|
|
* create a rectangle from the selection bounds.
|
|
|
|
* 5) If there is no rectangle and we are outside the selection,
|
|
|
|
* we clear the selection.
|
|
|
|
*/
|
2006-06-06 01:14:16 +08:00
|
|
|
static gboolean
|
2008-03-09 23:38:25 +08:00
|
|
|
gimp_rectangle_select_tool_execute (GimpRectangleTool *rectangle,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint w,
|
|
|
|
gint h)
|
2006-06-06 01:14:16 +08:00
|
|
|
{
|
2008-05-31 02:46:38 +08:00
|
|
|
GimpTool *tool = GIMP_TOOL (rectangle);
|
2008-03-09 23:38:25 +08:00
|
|
|
GimpRectangleSelectTool *rect_sel_tool;
|
|
|
|
GimpRectangleSelectToolPrivate *priv;
|
2007-11-11 22:00:48 +08:00
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
rect_sel_tool = GIMP_RECTANGLE_SELECT_TOOL (rectangle);
|
|
|
|
priv = GIMP_RECTANGLE_SELECT_TOOL_GET_PRIVATE (rect_sel_tool);
|
2007-11-11 22:00:48 +08:00
|
|
|
|
2008-05-31 02:46:38 +08:00
|
|
|
if (w == 0 && h == 0 && tool->display != NULL)
|
2005-04-10 02:08:47 +08:00
|
|
|
{
|
2009-10-07 01:20:44 +08:00
|
|
|
GimpImage *image = gimp_display_get_image (tool->display);
|
2007-12-15 01:22:46 +08:00
|
|
|
GimpChannel *selection = gimp_image_get_mask (image);
|
2006-06-08 04:07:54 +08:00
|
|
|
gint pressx;
|
|
|
|
gint pressy;
|
2005-10-21 05:33:40 +08:00
|
|
|
|
2008-11-14 23:01:44 +08:00
|
|
|
if (gimp_image_get_floating_selection (image))
|
2006-06-21 23:25:10 +08:00
|
|
|
{
|
2008-11-14 23:01:44 +08:00
|
|
|
floating_sel_anchor (gimp_image_get_floating_selection (image));
|
2006-10-14 16:59:25 +08:00
|
|
|
gimp_image_flush (image);
|
2006-06-21 23:25:10 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-11-11 22:00:48 +08:00
|
|
|
pressx = ROUND (priv->press_x);
|
|
|
|
pressy = ROUND (priv->press_y);
|
2005-10-21 05:33:40 +08:00
|
|
|
|
2006-06-06 01:14:16 +08:00
|
|
|
/* if the click was inside the marching ants */
|
|
|
|
if (gimp_pickable_get_opacity_at (GIMP_PICKABLE (selection),
|
2007-03-06 05:03:02 +08:00
|
|
|
pressx, pressy) > BOUNDARY_HALF_WAY)
|
2006-06-06 01:14:16 +08:00
|
|
|
{
|
2007-03-06 05:03:02 +08:00
|
|
|
gint x1, y1, x2, y2;
|
2006-06-06 01:14:16 +08:00
|
|
|
|
2007-03-06 05:03:02 +08:00
|
|
|
if (gimp_channel_bounds (selection, &x1, &y1, &x2, &y2))
|
|
|
|
{
|
2006-06-06 01:14:16 +08:00
|
|
|
g_object_set (rectangle,
|
|
|
|
"x1", x1,
|
|
|
|
"y1", y1,
|
|
|
|
"x2", x2,
|
|
|
|
"y2", y2,
|
|
|
|
NULL);
|
2005-10-21 05:33:40 +08:00
|
|
|
}
|
2006-06-06 01:14:16 +08:00
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
gimp_rectangle_tool_set_function (rectangle,
|
|
|
|
GIMP_RECTANGLE_TOOL_MOVING);
|
2005-10-21 05:33:40 +08:00
|
|
|
|
2006-06-06 01:14:16 +08:00
|
|
|
return FALSE;
|
2005-08-15 22:23:28 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-09-25 05:15:54 +08:00
|
|
|
GimpTool *tool = GIMP_TOOL (rectangle);
|
|
|
|
GimpChannelOps operation;
|
2006-06-15 04:19:49 +08:00
|
|
|
|
|
|
|
/* prevent this change from halting the tool */
|
|
|
|
gimp_tool_control_set_preserve (tool->control, TRUE);
|
|
|
|
|
2008-09-25 05:15:54 +08:00
|
|
|
/* We can conceptually think of a click outside of the
|
|
|
|
* selection as adding a 0px selection. Behave intuitivly
|
|
|
|
* for the current selection mode
|
|
|
|
*/
|
|
|
|
operation = gimp_rectangle_select_tool_get_operation (rect_sel_tool);
|
|
|
|
switch (operation)
|
|
|
|
{
|
|
|
|
case GIMP_CHANNEL_OP_REPLACE:
|
|
|
|
case GIMP_CHANNEL_OP_INTERSECT:
|
|
|
|
gimp_channel_clear (selection, NULL, TRUE);
|
|
|
|
gimp_image_flush (image);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_CHANNEL_OP_ADD:
|
|
|
|
case GIMP_CHANNEL_OP_SUBTRACT:
|
|
|
|
default:
|
|
|
|
/* Do nothing */
|
|
|
|
break;
|
|
|
|
}
|
2006-06-15 04:19:49 +08:00
|
|
|
|
|
|
|
gimp_tool_control_set_preserve (tool->control, FALSE);
|
2005-04-10 02:08:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
gimp_rectangle_select_tool_update_option_defaults (rect_sel_tool, FALSE);
|
2007-09-02 12:39:17 +08:00
|
|
|
|
2008-01-24 04:43:44 +08:00
|
|
|
/* Reset the automatic undo/redo mechanism */
|
|
|
|
priv->undo = NULL;
|
|
|
|
priv->redo = NULL;
|
|
|
|
|
2005-04-10 02:08:47 +08:00
|
|
|
return TRUE;
|
2005-02-01 02:43:28 +08:00
|
|
|
}
|
2006-03-26 21:50:13 +08:00
|
|
|
|
|
|
|
static void
|
2008-03-09 23:38:25 +08:00
|
|
|
gimp_rectangle_select_tool_cancel (GimpRectangleTool *rectangle)
|
2006-03-26 21:50:13 +08:00
|
|
|
{
|
2008-03-09 23:38:25 +08:00
|
|
|
GimpTool *tool;
|
|
|
|
GimpRectangleSelectTool *rect_sel_tool;
|
|
|
|
GimpRectangleSelectToolPrivate *priv;
|
2007-11-11 19:45:07 +08:00
|
|
|
|
2007-11-19 05:26:52 +08:00
|
|
|
tool = GIMP_TOOL (rectangle);
|
2008-03-09 23:38:25 +08:00
|
|
|
rect_sel_tool = GIMP_RECTANGLE_SELECT_TOOL (rectangle);
|
|
|
|
priv = GIMP_RECTANGLE_SELECT_TOOL_GET_PRIVATE (rect_sel_tool);
|
2006-03-26 21:50:13 +08:00
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
if (tool->display)
|
2006-06-06 01:14:16 +08:00
|
|
|
{
|
2010-02-05 03:06:49 +08:00
|
|
|
GimpImage *image = gimp_display_get_image (tool->display);
|
|
|
|
GimpUndoStack *undo_stack = gimp_image_get_undo_stack (image);
|
|
|
|
GimpUndo *undo = gimp_undo_stack_peek (undo_stack);
|
2006-03-26 21:50:13 +08:00
|
|
|
|
2006-06-06 01:14:16 +08:00
|
|
|
/* if we have an existing rectangle in the current display, then
|
|
|
|
* we have already "executed", and need to undo at this point,
|
|
|
|
* unless the user has done something in the meantime
|
|
|
|
*/
|
2007-11-11 19:45:07 +08:00
|
|
|
if (undo && priv->undo == undo)
|
2006-06-06 01:14:16 +08:00
|
|
|
{
|
2006-06-15 04:19:49 +08:00
|
|
|
/* prevent this change from halting the tool */
|
|
|
|
gimp_tool_control_set_preserve (tool->control, TRUE);
|
|
|
|
|
2006-06-06 01:14:16 +08:00
|
|
|
gimp_image_undo (image);
|
2006-06-06 16:04:49 +08:00
|
|
|
gimp_image_flush (image);
|
2006-06-15 04:19:49 +08:00
|
|
|
|
|
|
|
gimp_tool_control_set_preserve (tool->control, FALSE);
|
2006-06-06 01:14:16 +08:00
|
|
|
}
|
|
|
|
}
|
2006-06-06 16:04:49 +08:00
|
|
|
|
2008-05-10 20:44:04 +08:00
|
|
|
gimp_rectangle_select_tool_update_option_defaults (rect_sel_tool, TRUE);
|
|
|
|
|
2007-11-11 19:45:07 +08:00
|
|
|
priv->undo = NULL;
|
|
|
|
priv->redo = NULL;
|
2006-03-26 21:50:13 +08:00
|
|
|
}
|
2006-06-05 01:08:26 +08:00
|
|
|
|
|
|
|
static gboolean
|
2008-05-02 17:05:13 +08:00
|
|
|
gimp_rectangle_select_tool_rectangle_change_complete (GimpRectangleTool *rectangle)
|
2006-06-05 01:08:26 +08:00
|
|
|
{
|
2008-03-09 23:38:25 +08:00
|
|
|
GimpTool *tool;
|
|
|
|
GimpRectangleSelectTool *rect_sel_tool;
|
|
|
|
GimpRectangleSelectToolPrivate *priv;
|
2007-11-11 19:45:07 +08:00
|
|
|
|
2007-11-19 05:26:52 +08:00
|
|
|
tool = GIMP_TOOL (rectangle);
|
2008-03-09 23:38:25 +08:00
|
|
|
rect_sel_tool = GIMP_RECTANGLE_SELECT_TOOL (tool);
|
|
|
|
priv = GIMP_RECTANGLE_SELECT_TOOL_GET_PRIVATE (rect_sel_tool);
|
2006-06-05 01:08:26 +08:00
|
|
|
|
2006-06-15 00:25:19 +08:00
|
|
|
/* prevent change in selection from halting the tool */
|
|
|
|
gimp_tool_control_set_preserve (tool->control, TRUE);
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
if (tool->display && ! gimp_tool_control_is_active (tool->control))
|
2006-06-05 01:08:26 +08:00
|
|
|
{
|
2010-02-05 03:06:49 +08:00
|
|
|
GimpImage *image = gimp_display_get_image (tool->display);
|
|
|
|
GimpUndoStack *undo_stack = gimp_image_get_undo_stack (image);
|
|
|
|
GimpUndo *undo = gimp_undo_stack_peek (undo_stack);
|
|
|
|
gint x1, y1, x2, y2;
|
2006-06-05 01:08:26 +08:00
|
|
|
|
2006-06-11 00:49:07 +08:00
|
|
|
/* if we got here via button release, we have already undone the
|
|
|
|
* previous operation. But if we got here by some other means,
|
|
|
|
* we need to undo it now.
|
2006-06-06 01:14:16 +08:00
|
|
|
*/
|
2007-11-11 19:45:07 +08:00
|
|
|
if (undo && priv->undo == undo)
|
2006-06-05 01:08:26 +08:00
|
|
|
{
|
|
|
|
gimp_image_undo (image);
|
2007-11-11 19:45:07 +08:00
|
|
|
priv->undo = NULL;
|
2006-06-05 01:08:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_get (rectangle,
|
|
|
|
"x1", &x1,
|
|
|
|
"y1", &y1,
|
|
|
|
"x2", &x2,
|
|
|
|
"y2", &y2,
|
|
|
|
NULL);
|
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
if (gimp_rectangle_select_tool_select (rectangle, x1, y1, x2 - x1, y2 - y1))
|
2007-02-08 17:54:09 +08:00
|
|
|
{
|
|
|
|
/* save the undo that we got when executing, but only if
|
|
|
|
* we actually selected something
|
|
|
|
*/
|
2010-02-05 03:06:49 +08:00
|
|
|
priv->undo = gimp_undo_stack_peek (undo_stack);
|
2007-11-11 19:45:07 +08:00
|
|
|
priv->redo = NULL;
|
2007-02-08 17:54:09 +08:00
|
|
|
}
|
2006-06-11 00:49:07 +08:00
|
|
|
|
2007-11-11 19:45:07 +08:00
|
|
|
if (! priv->use_saved_op)
|
2006-06-11 00:49:07 +08:00
|
|
|
{
|
2007-07-31 23:39:26 +08:00
|
|
|
GimpSelectionOptions *options;
|
|
|
|
|
|
|
|
options = GIMP_SELECTION_TOOL_GET_OPTIONS (tool);
|
2007-04-01 00:22:57 +08:00
|
|
|
|
2006-06-11 00:49:07 +08:00
|
|
|
/* remember the operation now in case we modify the rectangle */
|
2007-11-11 19:45:07 +08:00
|
|
|
priv->operation = options->operation;
|
|
|
|
priv->use_saved_op = TRUE;
|
2006-06-11 00:49:07 +08:00
|
|
|
}
|
2006-06-06 16:04:49 +08:00
|
|
|
|
|
|
|
gimp_image_flush (image);
|
2006-06-05 01:08:26 +08:00
|
|
|
}
|
|
|
|
|
2006-06-15 00:25:19 +08:00
|
|
|
gimp_tool_control_set_preserve (tool->control, FALSE);
|
|
|
|
|
2008-05-11 21:01:24 +08:00
|
|
|
gimp_rectangle_select_tool_update_option_defaults (rect_sel_tool, FALSE);
|
|
|
|
|
2006-06-05 01:08:26 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
2006-11-05 21:45:04 +08:00
|
|
|
|
|
|
|
static void
|
2008-03-09 23:38:25 +08:00
|
|
|
gimp_rectangle_select_tool_round_corners_notify (GimpRectangleSelectOptions *options,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GimpRectangleSelectTool *rect_sel_tool)
|
2006-11-05 21:45:04 +08:00
|
|
|
{
|
2008-03-09 23:38:25 +08:00
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (rect_sel_tool);
|
|
|
|
GimpRectangleTool *rect_tool = GIMP_RECTANGLE_TOOL (rect_sel_tool);
|
|
|
|
GimpRectangleSelectToolPrivate *priv;
|
2007-11-11 19:45:07 +08:00
|
|
|
|
2008-03-09 23:38:25 +08:00
|
|
|
priv = GIMP_RECTANGLE_SELECT_TOOL_GET_PRIVATE (rect_sel_tool);
|
2007-10-31 01:13:10 +08:00
|
|
|
|
|
|
|
gimp_draw_tool_pause (draw_tool);
|
2006-11-05 21:45:04 +08:00
|
|
|
|
2007-11-11 19:45:07 +08:00
|
|
|
priv->round_corners = options->round_corners;
|
|
|
|
priv->corner_radius = options->corner_radius;
|
2006-11-05 21:45:04 +08:00
|
|
|
|
2008-05-02 17:05:13 +08:00
|
|
|
gimp_rectangle_select_tool_rectangle_change_complete (rect_tool);
|
2007-10-31 01:13:10 +08:00
|
|
|
|
|
|
|
gimp_draw_tool_resume (draw_tool);
|
2006-11-05 21:45:04 +08:00
|
|
|
}
|