2005-03-03 02:18:19 +08:00
|
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
2005-03-03 02:18:19 +08:00
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
|
|
#include "tools-types.h"
|
|
|
|
|
|
|
|
|
|
#include "core/gimpchannel.h"
|
|
|
|
|
#include "core/gimpimage.h"
|
2005-07-12 03:21:52 +08:00
|
|
|
|
#include "core/gimppickable.h"
|
2006-06-05 01:08:26 +08:00
|
|
|
|
#include "core/gimpmarshal.h"
|
2006-08-08 19:51:04 +08:00
|
|
|
|
|
2005-03-03 02:18:19 +08:00
|
|
|
|
#include "display/gimpcanvas.h"
|
|
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
|
#include "display/gimpdisplayshell.h"
|
|
|
|
|
#include "display/gimpdisplayshell-transform.h"
|
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
#include "gimpdrawtool.h"
|
2005-03-03 02:18:19 +08:00
|
|
|
|
#include "gimprectangleoptions.h"
|
2005-08-15 22:23:28 +08:00
|
|
|
|
#include "gimprectangletool.h"
|
2005-03-03 02:18:19 +08:00
|
|
|
|
#include "gimptoolcontrol.h"
|
|
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
2006-06-05 01:08:26 +08:00
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
RECTANGLE_CHANGED,
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
|
};
|
|
|
|
|
|
2005-03-03 02:18:19 +08:00
|
|
|
|
/* speed of key movement */
|
|
|
|
|
#define ARROW_VELOCITY 25
|
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
2006-06-05 19:18:43 +08:00
|
|
|
|
#define GIMP_RECTANGLE_TOOL_GET_PRIVATE(obj) \
|
|
|
|
|
(gimp_rectangle_tool_get_private ((GimpRectangleTool *) (obj)))
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
|
|
|
|
typedef struct _GimpRectangleToolPrivate GimpRectangleToolPrivate;
|
|
|
|
|
|
|
|
|
|
struct _GimpRectangleToolPrivate
|
|
|
|
|
{
|
2006-09-07 06:51:54 +08:00
|
|
|
|
gint pressx; /* x where button pressed */
|
|
|
|
|
gint pressy; /* y where button pressed */
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
2006-09-07 06:51:54 +08:00
|
|
|
|
gint x1, y1; /* upper left hand coordinate */
|
|
|
|
|
gint x2, y2; /* lower right hand coords */
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
2006-09-07 06:51:54 +08:00
|
|
|
|
guint function; /* moving or resizing */
|
2006-06-01 03:45:38 +08:00
|
|
|
|
|
2006-09-07 06:51:54 +08:00
|
|
|
|
GimpRectangleConstraint constraint; /* how to constrain rectangle */
|
2006-06-03 06:24:55 +08:00
|
|
|
|
|
|
|
|
|
/* Internal state */
|
2006-09-07 06:51:54 +08:00
|
|
|
|
gint startx; /* starting x coord */
|
|
|
|
|
gint starty; /* starting y coord */
|
2006-06-03 06:24:55 +08:00
|
|
|
|
|
2006-09-07 06:51:54 +08:00
|
|
|
|
gint lastx; /* previous x coord */
|
|
|
|
|
gint lasty; /* previous y coord */
|
2006-06-03 06:24:55 +08:00
|
|
|
|
|
2006-09-07 06:51:54 +08:00
|
|
|
|
gint dx1, dy1; /* display coords */
|
|
|
|
|
gint dx2, dy2; /* */
|
2006-06-03 06:24:55 +08:00
|
|
|
|
|
2006-09-07 06:51:54 +08:00
|
|
|
|
gint dcw, dch; /* width and height of edges */
|
2006-06-05 04:34:46 +08:00
|
|
|
|
|
2006-09-07 06:51:54 +08:00
|
|
|
|
gint saved_x1; /* for saving in case action is canceled */
|
|
|
|
|
gint saved_y1;
|
|
|
|
|
gint saved_x2;
|
|
|
|
|
gint saved_y2;
|
|
|
|
|
gdouble saved_center_x;
|
|
|
|
|
gdouble saved_center_y;
|
2006-06-07 05:06:06 +08:00
|
|
|
|
|
2006-09-07 06:51:54 +08:00
|
|
|
|
GimpRectangleGuide guide; /* synced with options->guide, only exists for drawing */
|
2005-09-04 03:48:22 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2006-03-22 01:37:24 +08:00
|
|
|
|
static void gimp_rectangle_tool_iface_base_init (GimpRectangleToolInterface *iface);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
static GimpRectangleToolPrivate *
|
2006-03-22 01:37:24 +08:00
|
|
|
|
gimp_rectangle_tool_get_private (GimpRectangleTool *tool);
|
|
|
|
|
|
|
|
|
|
void gimp_rectangle_tool_set_pressx (GimpRectangleTool *tool,
|
|
|
|
|
gint pressx);
|
|
|
|
|
gint gimp_rectangle_tool_get_pressx (GimpRectangleTool *tool);
|
|
|
|
|
void gimp_rectangle_tool_set_pressy (GimpRectangleTool *tool,
|
|
|
|
|
gint pressy);
|
|
|
|
|
gint gimp_rectangle_tool_get_pressy (GimpRectangleTool *tool);
|
|
|
|
|
|
|
|
|
|
void gimp_rectangle_tool_set_x1 (GimpRectangleTool *tool,
|
|
|
|
|
gint x1);
|
|
|
|
|
gint gimp_rectangle_tool_get_x1 (GimpRectangleTool *tool);
|
|
|
|
|
void gimp_rectangle_tool_set_y1 (GimpRectangleTool *tool,
|
|
|
|
|
gint y1);
|
|
|
|
|
gint gimp_rectangle_tool_get_y1 (GimpRectangleTool *tool);
|
|
|
|
|
void gimp_rectangle_tool_set_x2 (GimpRectangleTool *tool,
|
|
|
|
|
gint x2);
|
|
|
|
|
gint gimp_rectangle_tool_get_x2 (GimpRectangleTool *tool);
|
|
|
|
|
void gimp_rectangle_tool_set_y2 (GimpRectangleTool *tool,
|
|
|
|
|
gint y2);
|
|
|
|
|
gint gimp_rectangle_tool_get_y2 (GimpRectangleTool *tool);
|
|
|
|
|
|
|
|
|
|
void gimp_rectangle_tool_set_function (GimpRectangleTool *tool,
|
|
|
|
|
guint function);
|
|
|
|
|
guint gimp_rectangle_tool_get_function (GimpRectangleTool *tool);
|
2006-09-07 06:51:54 +08:00
|
|
|
|
|
|
|
|
|
GimpRectangleConstraint
|
|
|
|
|
gimp_rectangle_tool_get_constraint (GimpRectangleTool *tool);
|
2006-03-22 01:37:24 +08:00
|
|
|
|
|
2005-03-03 02:18:19 +08:00
|
|
|
|
/* Rectangle helper functions */
|
2006-01-22 02:20:26 +08:00
|
|
|
|
static void rectangle_tool_start (GimpRectangleTool *rectangle);
|
2006-06-07 03:14:25 +08:00
|
|
|
|
static void gimp_rectangle_tool_draw_guides (GimpDrawTool *draw_tool);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
|
|
|
|
/* Rectangle dialog functions */
|
2006-01-22 02:20:26 +08:00
|
|
|
|
static void gimp_rectangle_tool_update_options (GimpRectangleTool *rectangle,
|
2006-03-29 01:55:52 +08:00
|
|
|
|
GimpDisplay *display);
|
2006-03-26 21:50:13 +08:00
|
|
|
|
|
2006-09-23 02:27:21 +08:00
|
|
|
|
static void gimp_rectangle_tool_notify_x (GimpRectangleOptions *options,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
GimpRectangleTool *rectangle);
|
|
|
|
|
static void gimp_rectangle_tool_notify_y (GimpRectangleOptions *options,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
GimpRectangleTool *rectangle);
|
2006-03-26 21:50:13 +08:00
|
|
|
|
static void gimp_rectangle_tool_notify_width (GimpRectangleOptions *options,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
GimpRectangleTool *rectangle);
|
|
|
|
|
static void gimp_rectangle_tool_notify_height (GimpRectangleOptions *options,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
GimpRectangleTool *rectangle);
|
|
|
|
|
static void gimp_rectangle_tool_notify_aspect (GimpRectangleOptions *options,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
GimpRectangleTool *rectangle);
|
|
|
|
|
static void gimp_rectangle_tool_notify_highlight (GimpRectangleOptions *options,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
GimpRectangleTool *rectangle);
|
2006-06-07 05:06:06 +08:00
|
|
|
|
static void gimp_rectangle_tool_notify_guide (GimpRectangleOptions *options,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
GimpRectangleTool *rectangle);
|
2006-06-12 07:59:33 +08:00
|
|
|
|
static void gimp_rectangle_tool_check_function (GimpRectangleTool *rectangle,
|
|
|
|
|
gint curx,
|
|
|
|
|
gint cury);
|
2006-09-07 06:51:54 +08:00
|
|
|
|
gboolean gimp_rectangle_tool_constraint_violated (GimpRectangleTool *rectangle,
|
|
|
|
|
gint x1,
|
|
|
|
|
gint y1,
|
|
|
|
|
gint x2,
|
|
|
|
|
gint y2,
|
2006-09-15 05:51:35 +08:00
|
|
|
|
gdouble *alpha,
|
|
|
|
|
gdouble *beta);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2006-06-05 19:18:43 +08:00
|
|
|
|
static guint gimp_rectangle_tool_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
|
|
|
2005-03-03 02:18:19 +08:00
|
|
|
|
GType
|
2005-08-15 22:23:28 +08:00
|
|
|
|
gimp_rectangle_tool_interface_get_type (void)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2006-08-08 19:51:04 +08:00
|
|
|
|
static GType iface_type = 0;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2006-08-08 19:51:04 +08:00
|
|
|
|
if (!iface_type)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2006-08-08 19:51:04 +08:00
|
|
|
|
static const GTypeInfo iface_info =
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2005-08-15 22:23:28 +08:00
|
|
|
|
sizeof (GimpRectangleToolInterface),
|
2005-09-04 03:48:22 +08:00
|
|
|
|
(GBaseInitFunc) gimp_rectangle_tool_iface_base_init,
|
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
2005-03-03 02:18:19 +08:00
|
|
|
|
};
|
|
|
|
|
|
2006-08-08 19:51:04 +08:00
|
|
|
|
iface_type = g_type_register_static (G_TYPE_INTERFACE,
|
|
|
|
|
"GimpRectangleToolInterface",
|
|
|
|
|
&iface_info, 0);
|
|
|
|
|
|
|
|
|
|
g_type_interface_add_prerequisite (iface_type, GIMP_TYPE_DRAW_TOOL);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2006-08-08 19:51:04 +08:00
|
|
|
|
return iface_type;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2006-02-04 03:29:11 +08:00
|
|
|
|
gimp_rectangle_tool_iface_base_init (GimpRectangleToolInterface *iface)
|
2005-08-15 22:23:28 +08:00
|
|
|
|
{
|
|
|
|
|
static gboolean initialized = FALSE;
|
|
|
|
|
|
|
|
|
|
if (! initialized)
|
|
|
|
|
{
|
2006-06-05 01:08:26 +08:00
|
|
|
|
gimp_rectangle_tool_signals[RECTANGLE_CHANGED] =
|
|
|
|
|
g_signal_new ("rectangle-changed",
|
|
|
|
|
G_TYPE_FROM_INTERFACE (iface),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
2006-08-08 19:51:04 +08:00
|
|
|
|
G_STRUCT_OFFSET (GimpRectangleToolInterface,
|
|
|
|
|
rectangle_changed),
|
2006-06-05 01:08:26 +08:00
|
|
|
|
NULL, NULL,
|
|
|
|
|
gimp_marshal_VOID__VOID,
|
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
2006-02-04 03:29:11 +08:00
|
|
|
|
g_object_interface_install_property (iface,
|
2006-01-19 04:29:40 +08:00
|
|
|
|
g_param_spec_int ("pressx",
|
|
|
|
|
NULL, NULL,
|
2006-08-14 22:06:38 +08:00
|
|
|
|
G_MININT, G_MAXINT,
|
2006-01-19 04:29:40 +08:00
|
|
|
|
0,
|
|
|
|
|
GIMP_PARAM_READWRITE));
|
|
|
|
|
|
2006-02-04 03:29:11 +08:00
|
|
|
|
g_object_interface_install_property (iface,
|
2006-01-19 04:29:40 +08:00
|
|
|
|
g_param_spec_int ("pressy",
|
|
|
|
|
NULL, NULL,
|
2006-08-14 22:06:38 +08:00
|
|
|
|
G_MININT, G_MAXINT,
|
2006-01-19 04:29:40 +08:00
|
|
|
|
0,
|
|
|
|
|
GIMP_PARAM_READWRITE));
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
2006-02-04 03:29:11 +08:00
|
|
|
|
g_object_interface_install_property (iface,
|
2006-01-19 04:29:40 +08:00
|
|
|
|
g_param_spec_int ("x1",
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
-GIMP_MAX_IMAGE_SIZE,
|
|
|
|
|
GIMP_MAX_IMAGE_SIZE,
|
|
|
|
|
0,
|
|
|
|
|
GIMP_PARAM_READWRITE));
|
|
|
|
|
|
2006-02-04 03:29:11 +08:00
|
|
|
|
g_object_interface_install_property (iface,
|
2006-01-19 04:29:40 +08:00
|
|
|
|
g_param_spec_int ("y1",
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
-GIMP_MAX_IMAGE_SIZE,
|
|
|
|
|
GIMP_MAX_IMAGE_SIZE,
|
|
|
|
|
0,
|
|
|
|
|
GIMP_PARAM_READWRITE));
|
|
|
|
|
|
2006-02-04 03:29:11 +08:00
|
|
|
|
g_object_interface_install_property (iface,
|
2006-01-19 04:29:40 +08:00
|
|
|
|
g_param_spec_int ("x2",
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
-GIMP_MAX_IMAGE_SIZE,
|
|
|
|
|
GIMP_MAX_IMAGE_SIZE,
|
|
|
|
|
0,
|
|
|
|
|
GIMP_PARAM_READWRITE));
|
|
|
|
|
|
2006-02-04 03:29:11 +08:00
|
|
|
|
g_object_interface_install_property (iface,
|
2006-01-19 04:29:40 +08:00
|
|
|
|
g_param_spec_int ("y2",
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
-GIMP_MAX_IMAGE_SIZE,
|
|
|
|
|
GIMP_MAX_IMAGE_SIZE,
|
|
|
|
|
0,
|
|
|
|
|
GIMP_PARAM_READWRITE));
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
2006-02-04 03:29:11 +08:00
|
|
|
|
g_object_interface_install_property (iface,
|
2006-01-19 04:29:40 +08:00
|
|
|
|
g_param_spec_uint ("function",
|
|
|
|
|
NULL, NULL,
|
2006-06-03 03:34:47 +08:00
|
|
|
|
RECT_INACTIVE,
|
2006-01-19 04:29:40 +08:00
|
|
|
|
RECT_EXECUTING,
|
2006-06-03 03:34:47 +08:00
|
|
|
|
RECT_INACTIVE,
|
2006-01-19 04:29:40 +08:00
|
|
|
|
GIMP_PARAM_READWRITE));
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
2006-06-01 03:45:38 +08:00
|
|
|
|
g_object_interface_install_property (iface,
|
2006-09-07 06:51:54 +08:00
|
|
|
|
g_param_spec_uint ("constraint",
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
GIMP_RECTANGLE_CONSTRAIN_NONE,
|
|
|
|
|
GIMP_RECTANGLE_CONSTRAIN_DRAWABLE,
|
|
|
|
|
GIMP_RECTANGLE_CONSTRAIN_NONE,
|
|
|
|
|
GIMP_PARAM_READWRITE));
|
2006-06-01 03:45:38 +08:00
|
|
|
|
|
2006-06-05 01:08:26 +08:00
|
|
|
|
iface->rectangle_changed = NULL;
|
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
initialized = TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_rectangle_tool_private_finalize (GimpRectangleToolPrivate *private)
|
|
|
|
|
{
|
|
|
|
|
g_free (private);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GimpRectangleToolPrivate *
|
|
|
|
|
gimp_rectangle_tool_get_private (GimpRectangleTool *tool)
|
|
|
|
|
{
|
|
|
|
|
static GQuark private_key = 0;
|
|
|
|
|
|
2006-06-05 19:18:43 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
2006-06-05 19:18:43 +08:00
|
|
|
|
if (G_UNLIKELY (private_key == 0))
|
2005-09-04 03:48:22 +08:00
|
|
|
|
private_key = g_quark_from_static_string ("gimp-rectangle-tool-private");
|
|
|
|
|
|
2006-06-05 19:18:43 +08:00
|
|
|
|
private = g_object_get_qdata (G_OBJECT (tool), private_key);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
|
|
|
|
if (! private)
|
|
|
|
|
{
|
|
|
|
|
private = g_new0 (GimpRectangleToolPrivate, 1);
|
|
|
|
|
|
2006-06-05 19:18:43 +08:00
|
|
|
|
g_object_set_qdata_full (G_OBJECT (tool), private_key, private,
|
2006-06-07 03:14:25 +08:00
|
|
|
|
(GDestroyNotify)
|
|
|
|
|
gimp_rectangle_tool_private_finalize);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return private;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_install_properties:
|
|
|
|
|
* @klass: the class structure for a type deriving from #GObject
|
|
|
|
|
*
|
|
|
|
|
* Installs the necessary properties for a class implementing
|
|
|
|
|
* #GimpToolOptions. A #GimpRectangleToolProp property is installed
|
|
|
|
|
* for each property, using the values from the #GimpRectangleToolProp
|
|
|
|
|
* enumeration. The caller must make sure itself that the enumeration
|
|
|
|
|
* values don't collide with some other property values they
|
|
|
|
|
* are using (that's what %GIMP_RECTANGLE_TOOL_PROP_LAST is good for).
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
gimp_rectangle_tool_install_properties (GObjectClass *klass)
|
|
|
|
|
{
|
|
|
|
|
g_object_class_override_property (klass,
|
|
|
|
|
GIMP_RECTANGLE_TOOL_PROP_PRESSX,
|
|
|
|
|
"pressx");
|
|
|
|
|
g_object_class_override_property (klass,
|
|
|
|
|
GIMP_RECTANGLE_TOOL_PROP_PRESSY,
|
|
|
|
|
"pressy");
|
|
|
|
|
g_object_class_override_property (klass,
|
|
|
|
|
GIMP_RECTANGLE_TOOL_PROP_X1,
|
|
|
|
|
"x1");
|
|
|
|
|
g_object_class_override_property (klass,
|
|
|
|
|
GIMP_RECTANGLE_TOOL_PROP_Y1,
|
|
|
|
|
"y1");
|
|
|
|
|
g_object_class_override_property (klass,
|
|
|
|
|
GIMP_RECTANGLE_TOOL_PROP_X2,
|
|
|
|
|
"x2");
|
|
|
|
|
g_object_class_override_property (klass,
|
|
|
|
|
GIMP_RECTANGLE_TOOL_PROP_Y2,
|
|
|
|
|
"y2");
|
|
|
|
|
g_object_class_override_property (klass,
|
|
|
|
|
GIMP_RECTANGLE_TOOL_PROP_FUNCTION,
|
|
|
|
|
"function");
|
2006-06-01 03:45:38 +08:00
|
|
|
|
g_object_class_override_property (klass,
|
2006-09-07 06:51:54 +08:00
|
|
|
|
GIMP_RECTANGLE_TOOL_PROP_CONSTRAINT,
|
|
|
|
|
"constraint");
|
2005-09-04 03:48:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
void
|
|
|
|
|
gimp_rectangle_tool_set_pressx (GimpRectangleTool *tool,
|
|
|
|
|
gint pressx)
|
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (tool));
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
private->pressx = pressx;
|
2006-06-05 19:18:43 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_notify (G_OBJECT (tool), "pressx");
|
2005-08-15 22:23:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gint
|
|
|
|
|
gimp_rectangle_tool_get_pressx (GimpRectangleTool *tool)
|
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_RECTANGLE_TOOL (tool), 0);
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
return private->pressx;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gimp_rectangle_tool_set_pressy (GimpRectangleTool *tool,
|
|
|
|
|
gint pressy)
|
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (tool));
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
private->pressy = pressy;
|
2006-06-05 19:18:43 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_notify (G_OBJECT (tool), "pressy");
|
2005-08-15 22:23:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gint
|
|
|
|
|
gimp_rectangle_tool_get_pressy (GimpRectangleTool *tool)
|
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_RECTANGLE_TOOL (tool), 0);
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
return private->pressy;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gimp_rectangle_tool_set_x1 (GimpRectangleTool *tool,
|
|
|
|
|
gint x1)
|
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (tool));
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
private->x1 = x1;
|
2006-06-05 19:18:43 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_notify (G_OBJECT (tool), "x1");
|
2005-08-15 22:23:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gint
|
|
|
|
|
gimp_rectangle_tool_get_x1 (GimpRectangleTool *tool)
|
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_RECTANGLE_TOOL (tool), 0);
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
return private->x1;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gimp_rectangle_tool_set_y1 (GimpRectangleTool *tool,
|
|
|
|
|
gint y1)
|
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (tool));
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
private->y1 = y1;
|
2006-06-05 19:18:43 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_notify (G_OBJECT (tool), "y1");
|
2005-08-15 22:23:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gint
|
|
|
|
|
gimp_rectangle_tool_get_y1 (GimpRectangleTool *tool)
|
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_RECTANGLE_TOOL (tool), 0);
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
return private->y1;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gimp_rectangle_tool_set_x2 (GimpRectangleTool *tool,
|
|
|
|
|
gint x2)
|
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (tool));
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
private->x2 = x2;
|
2006-06-05 19:18:43 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_notify (G_OBJECT (tool), "x2");
|
2005-08-15 22:23:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gint
|
|
|
|
|
gimp_rectangle_tool_get_x2 (GimpRectangleTool *tool)
|
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_RECTANGLE_TOOL (tool), 0);
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
return private->x2;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gimp_rectangle_tool_set_y2 (GimpRectangleTool *tool,
|
|
|
|
|
gint y2)
|
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (tool));
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
private->y2 = y2;
|
2006-06-05 19:18:43 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_notify (G_OBJECT (tool), "y2");
|
2005-08-15 22:23:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gint
|
|
|
|
|
gimp_rectangle_tool_get_y2 (GimpRectangleTool *tool)
|
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_RECTANGLE_TOOL (tool), 0);
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
return private->y2;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gimp_rectangle_tool_set_function (GimpRectangleTool *tool,
|
|
|
|
|
guint function)
|
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (tool));
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
private->function = function;
|
2006-06-05 19:18:43 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_notify (G_OBJECT (tool), "function");
|
2005-08-15 22:23:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
guint
|
|
|
|
|
gimp_rectangle_tool_get_function (GimpRectangleTool *tool)
|
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_RECTANGLE_TOOL (tool), 0);
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
return private->function;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-01 03:45:38 +08:00
|
|
|
|
void
|
2006-09-07 06:51:54 +08:00
|
|
|
|
gimp_rectangle_tool_set_constraint (GimpRectangleTool *tool,
|
|
|
|
|
GimpRectangleConstraint constraint)
|
2006-06-01 03:45:38 +08:00
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (tool));
|
|
|
|
|
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
|
|
|
|
|
2006-09-07 06:51:54 +08:00
|
|
|
|
private->constraint = constraint;
|
2006-06-05 19:18:43 +08:00
|
|
|
|
|
2006-09-07 06:51:54 +08:00
|
|
|
|
g_object_notify (G_OBJECT (tool), "constraint");
|
2006-06-01 03:45:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-07 06:51:54 +08:00
|
|
|
|
GimpRectangleConstraint
|
|
|
|
|
gimp_rectangle_tool_get_constraint (GimpRectangleTool *tool)
|
2006-06-01 03:45:38 +08:00
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_RECTANGLE_TOOL (tool), 0);
|
|
|
|
|
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
|
|
|
|
|
2006-09-07 06:51:54 +08:00
|
|
|
|
return private->constraint;
|
2006-06-01 03:45:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
void
|
|
|
|
|
gimp_rectangle_tool_set_property (GObject *object,
|
|
|
|
|
guint property_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GimpRectangleTool *tool = GIMP_RECTANGLE_TOOL (object);
|
|
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
|
{
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_PRESSX:
|
|
|
|
|
gimp_rectangle_tool_set_pressx (tool, g_value_get_int (value));
|
|
|
|
|
break;
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_PRESSY:
|
|
|
|
|
gimp_rectangle_tool_set_pressy (tool, g_value_get_int (value));
|
|
|
|
|
break;
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_X1:
|
|
|
|
|
gimp_rectangle_tool_set_x1 (tool, g_value_get_int (value));
|
|
|
|
|
break;
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_Y1:
|
|
|
|
|
gimp_rectangle_tool_set_y1 (tool, g_value_get_int (value));
|
|
|
|
|
break;
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_X2:
|
|
|
|
|
gimp_rectangle_tool_set_x2 (tool, g_value_get_int (value));
|
|
|
|
|
break;
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_Y2:
|
|
|
|
|
gimp_rectangle_tool_set_y2 (tool, g_value_get_int (value));
|
|
|
|
|
break;
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_FUNCTION:
|
|
|
|
|
gimp_rectangle_tool_set_function (tool, g_value_get_uint (value));
|
|
|
|
|
break;
|
2006-09-07 06:51:54 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_CONSTRAINT:
|
|
|
|
|
gimp_rectangle_tool_set_constraint (tool, g_value_get_uint (value));
|
2006-06-01 03:45:38 +08:00
|
|
|
|
break;
|
2005-09-04 03:48:22 +08:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gimp_rectangle_tool_get_property (GObject *object,
|
|
|
|
|
guint property_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GimpRectangleTool *tool = GIMP_RECTANGLE_TOOL (object);
|
|
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
|
{
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_PRESSX:
|
|
|
|
|
g_value_set_int (value, gimp_rectangle_tool_get_pressx (tool));
|
|
|
|
|
break;
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_PRESSY:
|
|
|
|
|
g_value_set_int (value, gimp_rectangle_tool_get_pressy (tool));
|
|
|
|
|
break;
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_X1:
|
|
|
|
|
g_value_set_int (value, gimp_rectangle_tool_get_x1 (tool));
|
|
|
|
|
break;
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_Y1:
|
|
|
|
|
g_value_set_int (value, gimp_rectangle_tool_get_y1 (tool));
|
|
|
|
|
break;
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_X2:
|
|
|
|
|
g_value_set_int (value, gimp_rectangle_tool_get_x2 (tool));
|
|
|
|
|
break;
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_Y2:
|
|
|
|
|
g_value_set_int (value, gimp_rectangle_tool_get_y2 (tool));
|
|
|
|
|
break;
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_FUNCTION:
|
|
|
|
|
g_value_set_uint (value, gimp_rectangle_tool_get_function (tool));
|
|
|
|
|
break;
|
2006-09-07 06:51:54 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_CONSTRAINT:
|
|
|
|
|
g_value_set_uint (value, gimp_rectangle_tool_get_constraint (tool));
|
2006-06-01 03:45:38 +08:00
|
|
|
|
break;
|
2005-09-04 03:48:22 +08:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2005-08-15 22:23:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gimp_rectangle_tool_constructor (GObject *object)
|
|
|
|
|
{
|
2006-06-05 19:18:43 +08:00
|
|
|
|
GimpTool *tool = GIMP_TOOL (object);
|
|
|
|
|
GimpRectangleTool *rectangle = GIMP_RECTANGLE_TOOL (object);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
GObject *options;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
|
tool->display = NULL;
|
2005-03-09 07:17:19 +08:00
|
|
|
|
|
2006-09-06 02:25:31 +08:00
|
|
|
|
options = G_OBJECT (gimp_tool_get_options (tool));
|
2005-03-09 07:17:19 +08:00
|
|
|
|
|
2006-09-23 02:27:21 +08:00
|
|
|
|
g_signal_connect_object (options, "notify::x0",
|
|
|
|
|
G_CALLBACK (gimp_rectangle_tool_notify_x),
|
|
|
|
|
rectangle, 0);
|
|
|
|
|
g_signal_connect_object (options, "notify::y0",
|
|
|
|
|
G_CALLBACK (gimp_rectangle_tool_notify_y),
|
|
|
|
|
rectangle, 0);
|
2005-10-22 04:17:19 +08:00
|
|
|
|
g_signal_connect_object (options, "notify::width",
|
|
|
|
|
G_CALLBACK (gimp_rectangle_tool_notify_width),
|
|
|
|
|
rectangle, 0);
|
|
|
|
|
g_signal_connect_object (options, "notify::height",
|
|
|
|
|
G_CALLBACK (gimp_rectangle_tool_notify_height),
|
|
|
|
|
rectangle, 0);
|
2006-09-22 04:16:25 +08:00
|
|
|
|
g_signal_connect_object (options, "notify::fixed-aspect",
|
|
|
|
|
G_CALLBACK (gimp_rectangle_tool_notify_aspect),
|
|
|
|
|
rectangle, 0);
|
2006-09-15 01:11:24 +08:00
|
|
|
|
g_signal_connect_object (options, "notify::aspect-numerator",
|
|
|
|
|
G_CALLBACK (gimp_rectangle_tool_notify_aspect),
|
|
|
|
|
rectangle, 0);
|
|
|
|
|
g_signal_connect_object (options, "notify::aspect-denominator",
|
2005-10-22 04:17:19 +08:00
|
|
|
|
G_CALLBACK (gimp_rectangle_tool_notify_aspect),
|
|
|
|
|
rectangle, 0);
|
2006-03-25 17:38:59 +08:00
|
|
|
|
g_signal_connect_object (options, "notify::highlight",
|
|
|
|
|
G_CALLBACK (gimp_rectangle_tool_notify_highlight),
|
|
|
|
|
rectangle, 0);
|
2006-06-07 05:06:06 +08:00
|
|
|
|
g_signal_connect_object (options, "notify::guide",
|
|
|
|
|
G_CALLBACK (gimp_rectangle_tool_notify_guide),
|
|
|
|
|
rectangle, 0);
|
2006-09-07 06:51:54 +08:00
|
|
|
|
|
|
|
|
|
gimp_rectangle_tool_set_constraint (rectangle, GIMP_RECTANGLE_CONSTRAIN_NONE);
|
2005-03-09 07:17:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
void
|
2005-09-04 03:48:22 +08:00
|
|
|
|
gimp_rectangle_tool_dispose (GObject *object)
|
2005-03-09 07:17:19 +08:00
|
|
|
|
{
|
2005-11-29 06:30:24 +08:00
|
|
|
|
GimpTool *tool = GIMP_TOOL (object);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
GimpRectangleTool *rectangle = GIMP_RECTANGLE_TOOL (object);
|
2006-09-06 02:25:31 +08:00
|
|
|
|
GObject *options = G_OBJECT (gimp_tool_get_options (tool));
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
2006-09-23 02:27:21 +08:00
|
|
|
|
g_signal_handlers_disconnect_by_func (options,
|
|
|
|
|
G_CALLBACK (gimp_rectangle_tool_notify_x),
|
|
|
|
|
rectangle);
|
|
|
|
|
g_signal_handlers_disconnect_by_func (options,
|
|
|
|
|
G_CALLBACK (gimp_rectangle_tool_notify_y),
|
|
|
|
|
rectangle);
|
2005-11-29 06:30:24 +08:00
|
|
|
|
g_signal_handlers_disconnect_by_func (options,
|
|
|
|
|
G_CALLBACK (gimp_rectangle_tool_notify_width),
|
|
|
|
|
rectangle);
|
|
|
|
|
g_signal_handlers_disconnect_by_func (options,
|
|
|
|
|
G_CALLBACK (gimp_rectangle_tool_notify_height),
|
|
|
|
|
rectangle);
|
2005-11-30 07:32:55 +08:00
|
|
|
|
g_signal_handlers_disconnect_by_func (options,
|
|
|
|
|
G_CALLBACK (gimp_rectangle_tool_notify_aspect),
|
|
|
|
|
rectangle);
|
2006-03-25 17:38:59 +08:00
|
|
|
|
g_signal_handlers_disconnect_by_func (options,
|
|
|
|
|
G_CALLBACK (gimp_rectangle_tool_notify_highlight),
|
|
|
|
|
rectangle);
|
2005-03-09 07:17:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
gboolean
|
2005-03-09 07:17:19 +08:00
|
|
|
|
gimp_rectangle_tool_initialize (GimpTool *tool,
|
2006-03-29 01:55:52 +08:00
|
|
|
|
GimpDisplay *display)
|
2005-03-09 07:17:19 +08:00
|
|
|
|
{
|
2006-06-07 06:24:36 +08:00
|
|
|
|
GimpRectangleToolPrivate *private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2006-09-06 02:25:31 +08:00
|
|
|
|
GObject *options = G_OBJECT (gimp_tool_get_options (tool));
|
2005-03-09 07:17:19 +08:00
|
|
|
|
|
2006-06-07 06:24:36 +08:00
|
|
|
|
g_object_get (options,
|
|
|
|
|
"guide", &private->guide,
|
|
|
|
|
NULL);
|
2005-03-09 07:17:19 +08:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2006-05-24 01:37:18 +08:00
|
|
|
|
void
|
|
|
|
|
gimp_rectangle_tool_control (GimpTool *tool,
|
|
|
|
|
GimpToolAction action,
|
|
|
|
|
GimpDisplay *display)
|
|
|
|
|
{
|
|
|
|
|
GimpRectangleTool *rectangle = GIMP_RECTANGLE_TOOL (tool);
|
|
|
|
|
|
|
|
|
|
switch (action)
|
|
|
|
|
{
|
|
|
|
|
case GIMP_TOOL_ACTION_PAUSE:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GIMP_TOOL_ACTION_RESUME:
|
|
|
|
|
gimp_rectangle_tool_configure (rectangle);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GIMP_TOOL_ACTION_HALT:
|
2006-06-06 01:14:16 +08:00
|
|
|
|
gimp_rectangle_tool_halt (rectangle);
|
2006-05-24 01:37:18 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
void
|
2005-03-03 02:18:19 +08:00
|
|
|
|
gimp_rectangle_tool_button_press (GimpTool *tool,
|
|
|
|
|
GimpCoords *coords,
|
|
|
|
|
guint32 time,
|
|
|
|
|
GdkModifierType state,
|
2006-03-29 01:55:52 +08:00
|
|
|
|
GimpDisplay *display)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2006-06-03 06:24:55 +08:00
|
|
|
|
GimpRectangleTool *rectangle = GIMP_RECTANGLE_TOOL (tool);
|
|
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
|
|
|
|
guint function;
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
2006-06-11 00:49:07 +08:00
|
|
|
|
gint x = ROUND (coords->x);
|
|
|
|
|
gint y = ROUND (coords->y);
|
|
|
|
|
GimpRectangleOptions *options;
|
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (tool));
|
|
|
|
|
|
2006-09-06 02:25:31 +08:00
|
|
|
|
options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (tool);
|
2006-06-11 00:49:07 +08:00
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
|
if (display != tool->display)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
|
|
|
|
if (gimp_draw_tool_is_active (draw_tool))
|
|
|
|
|
gimp_draw_tool_stop (draw_tool);
|
|
|
|
|
|
2006-06-03 03:34:47 +08:00
|
|
|
|
function = RECT_CREATING;
|
2006-06-05 04:34:46 +08:00
|
|
|
|
g_object_set (rectangle, "function", function,
|
2006-06-11 00:49:07 +08:00
|
|
|
|
"x1", x,
|
|
|
|
|
"y1", y,
|
|
|
|
|
"x2", x,
|
|
|
|
|
"y2", y,
|
2006-06-05 04:34:46 +08:00
|
|
|
|
NULL);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control, 0, 0, 0, 0);
|
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
|
tool->display = display;
|
2006-06-05 04:34:46 +08:00
|
|
|
|
rectangle_tool_start (rectangle);
|
2006-06-03 00:12:31 +08:00
|
|
|
|
}
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2006-06-05 04:34:46 +08:00
|
|
|
|
/* save existing shape in case of cancellation */
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
|
|
|
|
g_object_get (rectangle,
|
|
|
|
|
"x1", &private->saved_x1,
|
|
|
|
|
"y1", &private->saved_y1,
|
|
|
|
|
"x2", &private->saved_x2,
|
|
|
|
|
"y2", &private->saved_y2,
|
|
|
|
|
NULL);
|
2006-06-11 00:49:07 +08:00
|
|
|
|
g_object_get (options,
|
|
|
|
|
"center-x", &private->saved_center_x,
|
|
|
|
|
"center-y", &private->saved_center_y,
|
|
|
|
|
NULL);
|
2006-06-05 04:34:46 +08:00
|
|
|
|
|
|
|
|
|
g_object_get (rectangle,
|
|
|
|
|
"function", &function,
|
|
|
|
|
NULL);
|
|
|
|
|
|
2006-06-03 00:12:31 +08:00
|
|
|
|
if (function == RECT_CREATING)
|
|
|
|
|
{
|
2006-06-11 00:49:07 +08:00
|
|
|
|
g_object_set (options,
|
|
|
|
|
"center-x", (gdouble) x,
|
|
|
|
|
"center-y", (gdouble) y,
|
|
|
|
|
NULL);
|
|
|
|
|
|
2006-06-05 04:34:46 +08:00
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_set (rectangle,
|
2006-06-11 00:49:07 +08:00
|
|
|
|
"x1", x,
|
|
|
|
|
"y1", y,
|
|
|
|
|
"x2", x,
|
|
|
|
|
"y2", y,
|
2006-01-22 02:20:26 +08:00
|
|
|
|
NULL);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2006-06-05 04:34:46 +08:00
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_set (rectangle,
|
2006-06-11 00:49:07 +08:00
|
|
|
|
"pressx", x,
|
|
|
|
|
"pressy", y,
|
2006-01-22 02:20:26 +08:00
|
|
|
|
NULL);
|
2006-06-03 06:24:55 +08:00
|
|
|
|
|
2006-06-11 00:49:07 +08:00
|
|
|
|
private->startx = x;
|
|
|
|
|
private->starty = y;
|
|
|
|
|
private->lastx = x;
|
|
|
|
|
private->lasty = y;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2006-09-15 08:01:59 +08:00
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
2005-03-03 02:18:19 +08:00
|
|
|
|
gimp_tool_control_activate (tool->control);
|
2006-09-15 08:01:59 +08:00
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
void
|
2005-03-03 02:18:19 +08:00
|
|
|
|
gimp_rectangle_tool_button_release (GimpTool *tool,
|
|
|
|
|
GimpCoords *coords,
|
|
|
|
|
guint32 time,
|
|
|
|
|
GdkModifierType state,
|
2006-03-29 01:55:52 +08:00
|
|
|
|
GimpDisplay *display)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2006-06-03 06:24:55 +08:00
|
|
|
|
GimpRectangleTool *rectangle = GIMP_RECTANGLE_TOOL (tool);
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
guint function;
|
2006-06-11 00:49:07 +08:00
|
|
|
|
GimpRectangleOptions *options;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (tool));
|
|
|
|
|
|
2006-09-06 02:25:31 +08:00
|
|
|
|
options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (tool);
|
2006-06-11 00:49:07 +08:00
|
|
|
|
|
2006-09-15 08:01:59 +08:00
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
2005-03-03 02:18:19 +08:00
|
|
|
|
gimp_tool_control_halt (tool->control);
|
2006-09-15 08:01:59 +08:00
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
2005-10-09 03:20:31 +08:00
|
|
|
|
|
2006-06-03 06:24:55 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2005-10-09 03:20:31 +08:00
|
|
|
|
g_object_get (rectangle, "function", &function, NULL);
|
2006-06-03 06:24:55 +08:00
|
|
|
|
|
2005-10-09 03:20:31 +08:00
|
|
|
|
if (function == RECT_EXECUTING)
|
2006-03-29 01:55:52 +08:00
|
|
|
|
gimp_tool_pop_status (tool, display);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
|
|
|
|
if (! (state & GDK_BUTTON3_MASK))
|
|
|
|
|
{
|
2006-06-11 02:24:58 +08:00
|
|
|
|
if (gimp_rectangle_tool_no_movement (rectangle))
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2006-06-06 01:14:16 +08:00
|
|
|
|
if (gimp_rectangle_tool_execute (rectangle))
|
|
|
|
|
gimp_rectangle_tool_halt (rectangle);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
2006-06-12 02:52:42 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_signal_emit_by_name (rectangle, "rectangle-changed", NULL);
|
|
|
|
|
}
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
2006-06-05 04:34:46 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
2006-06-11 00:49:07 +08:00
|
|
|
|
g_object_set (options,
|
2006-08-14 22:06:38 +08:00
|
|
|
|
"center-x", private->saved_center_x,
|
|
|
|
|
"center-y", private->saved_center_y,
|
|
|
|
|
NULL);
|
2006-06-11 00:49:07 +08:00
|
|
|
|
|
2006-06-05 04:34:46 +08:00
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
|
|
|
|
|
|
|
|
|
g_object_set (rectangle,
|
2006-08-14 22:06:38 +08:00
|
|
|
|
"x1", private->saved_x1,
|
|
|
|
|
"y1", private->saved_y1,
|
|
|
|
|
"x2", private->saved_x2,
|
|
|
|
|
"y2", private->saved_y2,
|
|
|
|
|
NULL);
|
2006-06-05 04:34:46 +08:00
|
|
|
|
|
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
|
|
|
|
}
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
void
|
2005-03-03 02:18:19 +08:00
|
|
|
|
gimp_rectangle_tool_motion (GimpTool *tool,
|
|
|
|
|
GimpCoords *coords,
|
|
|
|
|
guint32 time,
|
|
|
|
|
GdkModifierType state,
|
2006-03-29 01:55:52 +08:00
|
|
|
|
GimpDisplay *display)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2006-06-03 06:24:55 +08:00
|
|
|
|
GimpRectangleTool *rectangle = GIMP_RECTANGLE_TOOL (tool);
|
2006-09-06 02:25:31 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2006-06-03 06:24:55 +08:00
|
|
|
|
GimpRectangleOptions *options;
|
|
|
|
|
guint function;
|
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
|
gint curx, cury;
|
|
|
|
|
gint inc_x, inc_y;
|
|
|
|
|
gint rx1, ry1, rx2, ry2;
|
|
|
|
|
gboolean fixed_width;
|
|
|
|
|
gboolean fixed_height;
|
|
|
|
|
gboolean fixed_aspect;
|
|
|
|
|
gboolean fixed_center;
|
|
|
|
|
gdouble width, height;
|
|
|
|
|
gdouble center_x, center_y;
|
2006-09-07 06:51:54 +08:00
|
|
|
|
gdouble alpha;
|
2006-09-15 05:51:35 +08:00
|
|
|
|
gdouble beta;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (tool));
|
|
|
|
|
|
2006-06-03 06:24:55 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2006-09-06 02:25:31 +08:00
|
|
|
|
options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (tool);
|
2006-06-03 06:24:55 +08:00
|
|
|
|
|
2006-06-07 03:25:53 +08:00
|
|
|
|
/* This is the only case when the motion events should be ignored --
|
|
|
|
|
* we're just waiting for the button release event to execute.
|
|
|
|
|
*/
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_get (rectangle, "function", &function, NULL);
|
2006-06-07 03:25:53 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
if (function == RECT_EXECUTING)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
curx = ROUND (coords->x);
|
|
|
|
|
cury = ROUND (coords->y);
|
|
|
|
|
|
2006-06-12 07:59:33 +08:00
|
|
|
|
/* fix function, startx, starty if user has "flipped" the rectangle */
|
|
|
|
|
gimp_rectangle_tool_check_function (rectangle, curx, cury);
|
|
|
|
|
|
2006-06-03 06:24:55 +08:00
|
|
|
|
inc_x = curx - private->startx;
|
|
|
|
|
inc_y = cury - private->starty;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
|
|
|
|
/* If there have been no changes... return */
|
2006-06-03 06:24:55 +08:00
|
|
|
|
if (private->lastx == curx && private->lasty == cury)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_get (options,
|
2006-09-22 04:16:25 +08:00
|
|
|
|
"fixed-width", &fixed_width,
|
|
|
|
|
"fixed-height", &fixed_height,
|
2006-06-11 00:49:07 +08:00
|
|
|
|
"fixed-aspect", &fixed_aspect,
|
|
|
|
|
"fixed-center", &fixed_center,
|
2006-01-22 02:20:26 +08:00
|
|
|
|
NULL);
|
2005-03-11 07:55:24 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_get (options,
|
2006-01-22 02:20:26 +08:00
|
|
|
|
"width", &width,
|
|
|
|
|
"height", &height,
|
|
|
|
|
"center-x", ¢er_x,
|
|
|
|
|
"center-y", ¢er_y,
|
|
|
|
|
NULL);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
|
|
|
|
g_object_get (rectangle,
|
2006-01-22 02:20:26 +08:00
|
|
|
|
"x1", &rx1,
|
|
|
|
|
"y1", &ry1,
|
|
|
|
|
"x2", &rx2,
|
|
|
|
|
"y2", &ry2,
|
|
|
|
|
NULL);
|
2006-04-03 04:58:07 +08:00
|
|
|
|
x1 = rx1;
|
|
|
|
|
y1 = ry1;
|
|
|
|
|
x2 = rx2;
|
|
|
|
|
y2 = ry2;
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
|
|
|
|
switch (function)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2006-06-03 03:34:47 +08:00
|
|
|
|
case RECT_INACTIVE:
|
2006-06-05 19:18:43 +08:00
|
|
|
|
g_warning ("function is RECT_INACTIVE while mouse is moving");
|
2006-06-03 03:34:47 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2005-03-03 02:18:19 +08:00
|
|
|
|
case RECT_CREATING:
|
|
|
|
|
break;
|
|
|
|
|
|
2005-03-10 06:22:38 +08:00
|
|
|
|
case RECT_RESIZING_UPPER_LEFT:
|
|
|
|
|
case RECT_RESIZING_LOWER_LEFT:
|
2005-03-03 02:18:19 +08:00
|
|
|
|
case RECT_RESIZING_LEFT:
|
2005-09-16 04:31:49 +08:00
|
|
|
|
x1 = rx1 + inc_x;
|
2005-03-11 07:55:24 +08:00
|
|
|
|
if (fixed_width)
|
2006-08-22 23:58:14 +08:00
|
|
|
|
x2 = x1 + width;
|
2006-06-11 00:49:07 +08:00
|
|
|
|
else if (fixed_center)
|
2006-08-22 23:58:14 +08:00
|
|
|
|
x2 = x1 + 2 * (center_x - x1);
|
2005-03-11 07:55:24 +08:00
|
|
|
|
else
|
2006-08-22 23:58:14 +08:00
|
|
|
|
x2 = MAX (x1, rx2);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2005-03-10 06:22:38 +08:00
|
|
|
|
case RECT_RESIZING_UPPER_RIGHT:
|
|
|
|
|
case RECT_RESIZING_LOWER_RIGHT:
|
2005-03-03 02:18:19 +08:00
|
|
|
|
case RECT_RESIZING_RIGHT:
|
2005-09-16 04:31:49 +08:00
|
|
|
|
x2 = rx2 + inc_x;
|
2005-03-11 07:55:24 +08:00
|
|
|
|
if (fixed_width)
|
2006-08-22 23:58:14 +08:00
|
|
|
|
x1 = x2 - width;
|
2006-06-11 00:49:07 +08:00
|
|
|
|
else if (fixed_center)
|
2006-08-22 23:58:14 +08:00
|
|
|
|
x1 = x2 - 2 * (x2 - center_x);
|
2005-03-11 07:55:24 +08:00
|
|
|
|
else
|
2006-08-22 23:58:14 +08:00
|
|
|
|
x1 = MIN (rx1, x2);
|
2005-03-10 06:22:38 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_BOTTOM:
|
|
|
|
|
case RECT_RESIZING_TOP:
|
2005-09-04 03:48:22 +08:00
|
|
|
|
x1 = rx1;
|
|
|
|
|
x2 = rx2;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_MOVING:
|
2005-09-16 04:31:49 +08:00
|
|
|
|
x1 = rx1 + inc_x;
|
|
|
|
|
x2 = rx2 + inc_x;
|
2005-03-10 06:22:38 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
switch (function)
|
2005-03-10 06:22:38 +08:00
|
|
|
|
{
|
|
|
|
|
case RECT_CREATING:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_UPPER_LEFT:
|
|
|
|
|
case RECT_RESIZING_UPPER_RIGHT:
|
|
|
|
|
case RECT_RESIZING_TOP:
|
2005-09-16 04:31:49 +08:00
|
|
|
|
y1 = ry1 + inc_y;
|
2005-03-11 07:55:24 +08:00
|
|
|
|
if (fixed_height)
|
2006-08-22 23:58:14 +08:00
|
|
|
|
y2 = y1 + height;
|
2006-06-11 00:49:07 +08:00
|
|
|
|
else if (fixed_center)
|
2006-08-22 23:58:14 +08:00
|
|
|
|
y2 = y1 + 2 * (center_y - y1);
|
2005-03-11 07:55:24 +08:00
|
|
|
|
else
|
2006-08-22 23:58:14 +08:00
|
|
|
|
y2 = MAX (y1, ry2);
|
2005-03-10 06:22:38 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_LOWER_LEFT:
|
|
|
|
|
case RECT_RESIZING_LOWER_RIGHT:
|
|
|
|
|
case RECT_RESIZING_BOTTOM:
|
2005-09-16 04:31:49 +08:00
|
|
|
|
y2 = ry2 + inc_y;
|
2005-03-11 07:55:24 +08:00
|
|
|
|
if (fixed_height)
|
2006-08-22 23:58:14 +08:00
|
|
|
|
y1 = y2 - height;
|
2006-06-11 00:49:07 +08:00
|
|
|
|
else if (fixed_center)
|
2006-08-22 23:58:14 +08:00
|
|
|
|
y1 = y2 - 2 * (y2 - center_y);
|
2005-03-11 07:55:24 +08:00
|
|
|
|
else
|
2006-08-22 23:58:14 +08:00
|
|
|
|
y1 = MIN (ry1, y2);
|
2005-03-10 06:22:38 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_RIGHT:
|
|
|
|
|
case RECT_RESIZING_LEFT:
|
2005-09-04 03:48:22 +08:00
|
|
|
|
y1 = ry1;
|
|
|
|
|
y2 = ry2;
|
2005-03-10 06:22:38 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_MOVING:
|
2005-09-16 04:31:49 +08:00
|
|
|
|
y1 = ry1 + inc_y;
|
|
|
|
|
y2 = ry2 + inc_y;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-22 04:16:25 +08:00
|
|
|
|
if (fixed_aspect)
|
2005-03-11 07:55:24 +08:00
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
gdouble aspect;
|
2006-09-22 04:16:25 +08:00
|
|
|
|
gdouble numerator, denominator;
|
2006-06-05 19:18:43 +08:00
|
|
|
|
|
2006-09-22 04:16:25 +08:00
|
|
|
|
g_object_get (options,
|
|
|
|
|
"aspect-numerator", &numerator,
|
|
|
|
|
"aspect-denominator", &denominator,
|
|
|
|
|
NULL);
|
|
|
|
|
aspect = CLAMP (numerator / denominator,
|
|
|
|
|
1.0 / display->image->height,
|
|
|
|
|
display->image->width);
|
2005-03-11 07:55:24 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
switch (function)
|
2006-08-06 17:17:28 +08:00
|
|
|
|
{
|
2005-03-11 07:55:24 +08:00
|
|
|
|
case RECT_RESIZING_UPPER_LEFT:
|
2006-08-06 17:17:28 +08:00
|
|
|
|
/*
|
2006-08-14 22:06:38 +08:00
|
|
|
|
* The same basically happens for each corner, just with a
|
|
|
|
|
* different fixed corner. To keep within aspect ratio and
|
|
|
|
|
* at the same time keep the cursor on one edge if not the
|
|
|
|
|
* corner itself: - calculate the two positions of the
|
|
|
|
|
* corner in question on the base of the current mouse
|
|
|
|
|
* cursor position and the fixed corner opposite the one
|
|
|
|
|
* selected. - decide on which egde we are inside the
|
|
|
|
|
* rectangle dimension - if we are on the inside of the
|
|
|
|
|
* vertical edge then we use the x position of the cursor,
|
|
|
|
|
* otherwise we are on the inside (or close enough) of the
|
|
|
|
|
* horizontal edge and then we use the y position of the
|
|
|
|
|
* cursor for the base of our new corner.
|
2006-08-06 17:17:28 +08:00
|
|
|
|
*/
|
2006-08-01 04:46:40 +08:00
|
|
|
|
x1 = rx2 - (ry2 - cury) * aspect + .5;
|
|
|
|
|
y1 = ry2 - (rx2 - curx) / aspect + .5;
|
2006-08-06 17:17:28 +08:00
|
|
|
|
if ((y1 < cury) && (cury < y2))
|
2006-08-01 04:46:40 +08:00
|
|
|
|
x1 = curx;
|
2005-09-04 03:48:22 +08:00
|
|
|
|
else
|
2006-08-01 04:46:40 +08:00
|
|
|
|
y1 = cury;
|
2006-08-23 00:16:36 +08:00
|
|
|
|
if (fixed_center)
|
|
|
|
|
{
|
|
|
|
|
x2 = x1 + 2 * (center_x - x1);
|
|
|
|
|
y2 = y1 + 2 * (center_y - y1);
|
|
|
|
|
}
|
2005-03-11 07:55:24 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_UPPER_RIGHT:
|
2006-08-01 04:46:40 +08:00
|
|
|
|
x2 = rx1 + (ry2 - cury) * aspect + .5;
|
|
|
|
|
y1 = ry2 - (curx - rx1) / aspect + .5;
|
2006-08-06 17:17:28 +08:00
|
|
|
|
if ((y1 < cury) && (cury < y2))
|
2006-08-01 04:46:40 +08:00
|
|
|
|
x2 = curx;
|
2005-09-04 03:48:22 +08:00
|
|
|
|
else
|
2006-08-01 04:46:40 +08:00
|
|
|
|
y1 = cury;
|
2006-08-23 00:16:36 +08:00
|
|
|
|
if (fixed_center)
|
|
|
|
|
{
|
|
|
|
|
x1 = x2 - 2 * (x2 - center_x);
|
|
|
|
|
y2 = y1 + 2 * (center_y - y1);
|
|
|
|
|
}
|
2005-03-11 07:55:24 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_LOWER_LEFT:
|
2006-08-01 04:46:40 +08:00
|
|
|
|
x1 = rx2 - (cury - ry1) * aspect + .5;
|
|
|
|
|
y2 = ry1 + (rx2 - curx) / aspect + .5;
|
2006-08-06 17:17:28 +08:00
|
|
|
|
if ((y1 < cury) && (cury < y2))
|
2006-08-01 04:46:40 +08:00
|
|
|
|
x1 = curx;
|
2005-09-04 03:48:22 +08:00
|
|
|
|
else
|
2006-08-01 04:46:40 +08:00
|
|
|
|
y2 = cury;
|
2006-08-23 00:16:36 +08:00
|
|
|
|
if (fixed_center)
|
|
|
|
|
{
|
|
|
|
|
x2 = x1 + 2 * (center_x - x1);
|
|
|
|
|
y1 = y2 - 2 * (y2 - center_y);
|
|
|
|
|
}
|
2005-03-11 07:55:24 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_LOWER_RIGHT:
|
2006-08-01 04:46:40 +08:00
|
|
|
|
x2 = rx1 + (cury - ry1) * aspect + .5;
|
|
|
|
|
y2 = ry1 + (curx - rx1) / aspect + .5;
|
2006-08-06 17:17:28 +08:00
|
|
|
|
if ((y1 < cury) && (cury < y2))
|
2006-08-01 04:46:40 +08:00
|
|
|
|
x2 = curx;
|
2005-09-04 03:48:22 +08:00
|
|
|
|
else
|
2006-08-01 04:46:40 +08:00
|
|
|
|
y2 = cury;
|
2006-08-23 00:16:36 +08:00
|
|
|
|
if (fixed_center)
|
|
|
|
|
{
|
|
|
|
|
x1 = x2 - 2 * (x2 - center_x);
|
|
|
|
|
y1 = y2 - 2 * (y2 - center_y);
|
|
|
|
|
}
|
2006-08-01 04:46:40 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_TOP:
|
|
|
|
|
x2 = rx1 + (ry2 - y1) * aspect + .5;
|
2006-08-23 00:16:36 +08:00
|
|
|
|
if (fixed_center)
|
|
|
|
|
x1 = x2 - 2 * (x2 - center_x);
|
2006-08-01 04:46:40 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_LEFT:
|
2006-08-14 22:06:38 +08:00
|
|
|
|
/* When resizing the left hand delimiter then the aspect
|
|
|
|
|
* dictates the height of the result, any inc_y is redundant
|
|
|
|
|
* and not relevant to the result
|
2006-08-01 04:46:40 +08:00
|
|
|
|
*/
|
|
|
|
|
y2 = ry1 + (rx2 - x1) / aspect + .5;
|
2006-08-23 00:16:36 +08:00
|
|
|
|
if (fixed_center)
|
|
|
|
|
y1 = y2 - 2 * (y2 - center_y);
|
2006-08-01 04:46:40 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_BOTTOM:
|
|
|
|
|
x2 = rx1 + (y2 - ry1) * aspect + .5;
|
2006-08-23 00:16:36 +08:00
|
|
|
|
if (fixed_center)
|
|
|
|
|
x1 = x2 - 2 * (x2 - center_x);
|
2006-08-01 04:46:40 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_RIGHT:
|
2006-08-14 22:06:38 +08:00
|
|
|
|
/* When resizing the right hand delimiter then the aspect
|
|
|
|
|
* dictates the height of the result, any inc_y is redundant
|
|
|
|
|
* and not relevant to the result
|
2006-08-01 04:46:40 +08:00
|
|
|
|
*/
|
|
|
|
|
y2 = ry1 + (x2 - rx1) / aspect + 0.5;
|
2006-08-23 00:16:36 +08:00
|
|
|
|
if (fixed_center)
|
|
|
|
|
y1 = y2 - 2 * (y2 - center_y);
|
2005-03-11 07:55:24 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-09-07 06:51:54 +08:00
|
|
|
|
|
|
|
|
|
private->lastx = curx;
|
|
|
|
|
private->lasty = cury;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Check to see whether the new rectangle obeys the boundary constraints, if any.
|
|
|
|
|
* If not, see whether we can downscale the mouse movement and call this
|
|
|
|
|
* motion handler again recursively. The reason for the recursive call is
|
|
|
|
|
* to avoid leaving the rectangle edge hanging some pixels away from the
|
|
|
|
|
* constraining boundary if the user moves the pointer quickly.
|
|
|
|
|
*/
|
2006-09-15 05:51:35 +08:00
|
|
|
|
if (gimp_rectangle_tool_constraint_violated (rectangle, x1, y1, x2, y2, &alpha, &beta))
|
2006-09-07 06:51:54 +08:00
|
|
|
|
{
|
|
|
|
|
GimpCoords new_coords;
|
|
|
|
|
|
|
|
|
|
inc_x *= alpha;
|
2006-09-15 05:51:35 +08:00
|
|
|
|
inc_y *= beta;
|
2006-09-07 06:51:54 +08:00
|
|
|
|
|
|
|
|
|
if (inc_x != 0 || inc_y != 0)
|
|
|
|
|
{
|
|
|
|
|
new_coords.x = private->startx + inc_x;
|
|
|
|
|
new_coords.y = private->starty + inc_y;
|
|
|
|
|
|
|
|
|
|
gimp_rectangle_tool_motion (tool, &new_coords, time, state, display);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* set startx, starty according to function, to keep rect on cursor */
|
|
|
|
|
switch (function)
|
|
|
|
|
{
|
|
|
|
|
case RECT_RESIZING_UPPER_LEFT:
|
|
|
|
|
private->startx = x1;
|
|
|
|
|
private->starty = y1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_UPPER_RIGHT:
|
|
|
|
|
private->startx = x2;
|
|
|
|
|
private->starty = y1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_LOWER_LEFT:
|
|
|
|
|
private->startx = x1;
|
|
|
|
|
private->starty = y2;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_LOWER_RIGHT:
|
|
|
|
|
private->startx = x2;
|
|
|
|
|
private->starty = y2;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_TOP:
|
|
|
|
|
private->startx = curx;
|
|
|
|
|
private->starty = y1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_LEFT:
|
|
|
|
|
private->startx = x1;
|
|
|
|
|
private->starty = cury;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_BOTTOM:
|
|
|
|
|
private->startx = curx;
|
|
|
|
|
private->starty = y2;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_RIGHT:
|
|
|
|
|
private->startx = x2;
|
|
|
|
|
private->starty = cury;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_MOVING:
|
|
|
|
|
private->startx = curx;
|
|
|
|
|
private->starty = cury;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
|
|
|
|
|
2005-11-10 04:47:57 +08:00
|
|
|
|
/* make sure that the coords are in bounds */
|
|
|
|
|
g_object_set (rectangle,
|
2006-01-22 02:20:26 +08:00
|
|
|
|
"x1", MIN (x1, x2),
|
|
|
|
|
"y1", MIN (y1, y2),
|
|
|
|
|
"x2", MAX (x1, x2),
|
|
|
|
|
"y2", MAX (y1, y2),
|
|
|
|
|
NULL);
|
2006-06-05 19:18:43 +08:00
|
|
|
|
|
2005-03-03 02:18:19 +08:00
|
|
|
|
/* recalculate the coordinates for rectangle_draw based on the new values */
|
2005-10-20 05:13:25 +08:00
|
|
|
|
gimp_rectangle_tool_configure (rectangle);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_get (rectangle,
|
2006-01-22 02:20:26 +08:00
|
|
|
|
"x1", &rx1,
|
|
|
|
|
"y1", &ry1,
|
|
|
|
|
"x2", &rx2,
|
|
|
|
|
"y2", &ry2,
|
|
|
|
|
NULL);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
|
|
|
|
switch (function)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2005-03-10 06:22:38 +08:00
|
|
|
|
case RECT_RESIZING_UPPER_LEFT:
|
2005-03-03 02:18:19 +08:00
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
rx1 - coords->x,
|
|
|
|
|
ry1 - coords->y,
|
2005-03-03 02:18:19 +08:00
|
|
|
|
0, 0);
|
|
|
|
|
break;
|
|
|
|
|
|
2005-03-10 06:22:38 +08:00
|
|
|
|
case RECT_RESIZING_UPPER_RIGHT:
|
2005-03-03 02:18:19 +08:00
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
rx2 - coords->x,
|
|
|
|
|
ry1 - coords->y,
|
2005-03-10 06:22:38 +08:00
|
|
|
|
0, 0);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_LOWER_LEFT:
|
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
rx1 - coords->x,
|
|
|
|
|
ry2 - coords->y,
|
2005-03-03 02:18:19 +08:00
|
|
|
|
0, 0);
|
|
|
|
|
break;
|
|
|
|
|
|
2005-03-10 06:22:38 +08:00
|
|
|
|
case RECT_RESIZING_LOWER_RIGHT:
|
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
rx2 - coords->x,
|
|
|
|
|
ry2 - coords->y,
|
2005-03-10 06:22:38 +08:00
|
|
|
|
0, 0);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_LEFT:
|
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
rx1 - coords->x, 0, 0, 0);
|
2005-03-10 06:22:38 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_RIGHT:
|
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
rx2 - coords->x, 0, 0, 0);
|
2005-03-10 06:22:38 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_TOP:
|
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
0, ry1 - coords->y, 0, 0);
|
2005-03-10 06:22:38 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_BOTTOM:
|
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
0, ry2 - coords->y, 0, 0);
|
2005-03-10 06:22:38 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2005-03-03 02:18:19 +08:00
|
|
|
|
case RECT_MOVING:
|
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
rx1 - coords->x,
|
|
|
|
|
ry1 - coords->y,
|
|
|
|
|
rx2 - rx1,
|
|
|
|
|
ry2 - ry1);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
|
gimp_rectangle_tool_update_options (rectangle, display);
|
2005-03-09 07:17:19 +08:00
|
|
|
|
|
2006-08-14 22:17:18 +08:00
|
|
|
|
if (function != RECT_MOVING && function != RECT_EXECUTING)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2006-08-14 22:17:18 +08:00
|
|
|
|
gint w, h;
|
2006-06-01 03:45:38 +08:00
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
|
gimp_tool_pop_status (tool, display);
|
2006-08-14 22:17:18 +08:00
|
|
|
|
|
2006-09-07 06:51:54 +08:00
|
|
|
|
w = rx2 - rx1;
|
|
|
|
|
h = ry2 - ry1;
|
2006-08-14 22:17:18 +08:00
|
|
|
|
|
|
|
|
|
if (w > 0 && h > 0)
|
|
|
|
|
gimp_tool_push_status_coords (tool, display,
|
|
|
|
|
_("Rectangle: "), w, " × ", h);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
if (function == RECT_CREATING)
|
2005-06-03 06:48:43 +08:00
|
|
|
|
{
|
|
|
|
|
if (inc_x < 0 && inc_y < 0)
|
2005-09-05 18:11:19 +08:00
|
|
|
|
function = RECT_RESIZING_UPPER_LEFT;
|
2005-06-03 06:48:43 +08:00
|
|
|
|
else if (inc_x < 0 && inc_y > 0)
|
2005-09-05 18:11:19 +08:00
|
|
|
|
function = RECT_RESIZING_LOWER_LEFT;
|
2005-06-03 06:48:43 +08:00
|
|
|
|
else if (inc_x > 0 && inc_y < 0)
|
2005-09-05 18:11:19 +08:00
|
|
|
|
function = RECT_RESIZING_UPPER_RIGHT;
|
2005-06-03 06:48:43 +08:00
|
|
|
|
else if (inc_x > 0 && inc_y > 0)
|
2005-09-05 18:11:19 +08:00
|
|
|
|
function = RECT_RESIZING_LOWER_RIGHT;
|
|
|
|
|
|
|
|
|
|
g_object_set (rectangle, "function", function, NULL);
|
2005-06-03 06:48:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-03 02:18:19 +08:00
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-22 01:10:29 +08:00
|
|
|
|
void
|
2006-09-13 02:41:09 +08:00
|
|
|
|
gimp_rectangle_tool_active_modifier_key (GimpTool *tool,
|
|
|
|
|
GdkModifierType key,
|
|
|
|
|
gboolean press,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GimpDisplay *display)
|
2006-08-22 01:10:29 +08:00
|
|
|
|
{
|
2006-09-06 02:25:31 +08:00
|
|
|
|
GimpRectangleTool *rectangle = GIMP_RECTANGLE_TOOL (tool);
|
|
|
|
|
GimpRectangleOptions *options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (tool);
|
|
|
|
|
|
2006-09-13 02:41:09 +08:00
|
|
|
|
if (key == GDK_SHIFT_MASK)
|
2006-08-22 01:10:29 +08:00
|
|
|
|
{
|
2006-09-22 04:16:25 +08:00
|
|
|
|
gboolean fixed_aspect;
|
2006-08-22 01:10:29 +08:00
|
|
|
|
|
2006-09-13 02:41:09 +08:00
|
|
|
|
g_object_get (options,
|
2006-09-22 04:16:25 +08:00
|
|
|
|
"fixed-aspect", &fixed_aspect,
|
2006-09-13 02:41:09 +08:00
|
|
|
|
NULL);
|
2006-08-22 01:10:29 +08:00
|
|
|
|
|
2006-09-13 02:41:09 +08:00
|
|
|
|
g_object_set (options,
|
2006-09-22 04:16:25 +08:00
|
|
|
|
"fixed-aspect", ! fixed_aspect,
|
2006-09-13 02:41:09 +08:00
|
|
|
|
NULL);
|
|
|
|
|
}
|
2006-08-22 01:10:29 +08:00
|
|
|
|
|
2006-09-13 02:41:09 +08:00
|
|
|
|
if (key == GDK_CONTROL_MASK)
|
|
|
|
|
{
|
|
|
|
|
gboolean fixed_center;
|
2006-08-22 01:10:29 +08:00
|
|
|
|
|
2006-09-13 02:41:09 +08:00
|
|
|
|
g_object_get (options,
|
|
|
|
|
"fixed-center", &fixed_center,
|
|
|
|
|
NULL);
|
2006-08-22 01:10:29 +08:00
|
|
|
|
|
2006-09-13 02:41:09 +08:00
|
|
|
|
g_object_set (options,
|
|
|
|
|
"fixed-center", ! fixed_center,
|
|
|
|
|
NULL);
|
2006-08-22 01:10:29 +08:00
|
|
|
|
|
2006-09-13 02:41:09 +08:00
|
|
|
|
if (! fixed_center)
|
|
|
|
|
{
|
|
|
|
|
gdouble center_x = gimp_rectangle_tool_get_pressx (rectangle);
|
|
|
|
|
gdouble center_y = gimp_rectangle_tool_get_pressy (rectangle);
|
2006-08-22 01:10:29 +08:00
|
|
|
|
|
2006-09-13 02:41:09 +08:00
|
|
|
|
g_object_set (options,
|
|
|
|
|
"center-x", center_x,
|
|
|
|
|
"center-y", center_y,
|
|
|
|
|
NULL);
|
2006-08-22 01:10:29 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-12 07:59:33 +08:00
|
|
|
|
/*
|
|
|
|
|
* gimp_rectangle_tool_check_function() is needed to deal with
|
|
|
|
|
* situations where the user drags a corner or edge across one of the
|
|
|
|
|
* existing edges, thereby changing its function. Ugh.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
gimp_rectangle_tool_check_function (GimpRectangleTool *rectangle,
|
|
|
|
|
gint curx,
|
|
|
|
|
gint cury)
|
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
guint function;
|
|
|
|
|
guint new_function;
|
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
|
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rectangle);
|
|
|
|
|
|
|
|
|
|
g_object_get (rectangle,
|
|
|
|
|
"function", &function,
|
|
|
|
|
"x1", &x1,
|
|
|
|
|
"y1", &y1,
|
|
|
|
|
"x2", &x2,
|
|
|
|
|
"y2", &y2,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
new_function = function;
|
|
|
|
|
|
|
|
|
|
switch (function)
|
|
|
|
|
{
|
|
|
|
|
case RECT_RESIZING_LEFT:
|
|
|
|
|
if (curx > x2)
|
|
|
|
|
{
|
|
|
|
|
new_function = RECT_RESIZING_RIGHT;
|
|
|
|
|
private->startx = x2;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_RIGHT:
|
|
|
|
|
if (curx < x1)
|
|
|
|
|
{
|
|
|
|
|
new_function = RECT_RESIZING_LEFT;
|
|
|
|
|
private->startx = x1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_TOP:
|
|
|
|
|
if (cury > y2)
|
|
|
|
|
{
|
|
|
|
|
new_function = RECT_RESIZING_BOTTOM;
|
|
|
|
|
private->starty = y2;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_BOTTOM:
|
|
|
|
|
if (cury < y1)
|
|
|
|
|
{
|
|
|
|
|
new_function = RECT_RESIZING_TOP;
|
|
|
|
|
private->starty = y1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_UPPER_LEFT:
|
|
|
|
|
if (curx > x2 && cury > y2)
|
|
|
|
|
{
|
|
|
|
|
new_function = RECT_RESIZING_LOWER_RIGHT;
|
|
|
|
|
private->startx = x2;
|
|
|
|
|
private->starty = y2;
|
|
|
|
|
}
|
|
|
|
|
else if (curx > x2)
|
|
|
|
|
{
|
|
|
|
|
new_function = RECT_RESIZING_UPPER_RIGHT;
|
|
|
|
|
private->startx = x2;
|
|
|
|
|
}
|
|
|
|
|
else if (cury > y2)
|
|
|
|
|
{
|
|
|
|
|
new_function = RECT_RESIZING_LOWER_LEFT;
|
|
|
|
|
private->starty = y2;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_UPPER_RIGHT:
|
|
|
|
|
if (curx < x1 && cury > y2)
|
|
|
|
|
{
|
|
|
|
|
new_function = RECT_RESIZING_LOWER_LEFT;
|
|
|
|
|
private->startx = x1;
|
|
|
|
|
private->starty = y2;
|
|
|
|
|
}
|
|
|
|
|
else if (curx < x1)
|
|
|
|
|
{
|
|
|
|
|
new_function = RECT_RESIZING_UPPER_LEFT;
|
|
|
|
|
private->startx = x1;
|
|
|
|
|
}
|
|
|
|
|
else if (cury > y2)
|
|
|
|
|
{
|
|
|
|
|
new_function = RECT_RESIZING_LOWER_RIGHT;
|
|
|
|
|
private->starty = y2;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_LOWER_LEFT:
|
|
|
|
|
if (curx > x2 && cury < y1)
|
|
|
|
|
{
|
|
|
|
|
new_function = RECT_RESIZING_UPPER_RIGHT;
|
|
|
|
|
private->startx = x2;
|
|
|
|
|
private->starty = y1;
|
|
|
|
|
}
|
|
|
|
|
else if (curx > x2)
|
|
|
|
|
{
|
|
|
|
|
new_function = RECT_RESIZING_LOWER_RIGHT;
|
|
|
|
|
private->startx = x2;
|
|
|
|
|
}
|
|
|
|
|
else if (cury < y1)
|
|
|
|
|
{
|
|
|
|
|
new_function = RECT_RESIZING_UPPER_LEFT;
|
|
|
|
|
private->starty = y1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_LOWER_RIGHT:
|
|
|
|
|
if (curx < x1 && cury < y1)
|
|
|
|
|
{
|
|
|
|
|
new_function = RECT_RESIZING_UPPER_LEFT;
|
|
|
|
|
private->startx = x1;
|
|
|
|
|
private->starty = y1;
|
|
|
|
|
}
|
|
|
|
|
else if (curx < x1)
|
|
|
|
|
{
|
|
|
|
|
new_function = RECT_RESIZING_LOWER_LEFT;
|
|
|
|
|
private->startx = x1;
|
|
|
|
|
}
|
|
|
|
|
else if (cury < y1)
|
|
|
|
|
{
|
|
|
|
|
new_function = RECT_RESIZING_UPPER_RIGHT;
|
|
|
|
|
private->starty = y1;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (new_function != function)
|
|
|
|
|
g_object_set (rectangle, "function", new_function, NULL);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
gboolean
|
2005-03-03 02:18:19 +08:00
|
|
|
|
gimp_rectangle_tool_key_press (GimpTool *tool,
|
|
|
|
|
GdkEventKey *kevent,
|
2006-03-29 01:55:52 +08:00
|
|
|
|
GimpDisplay *display)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
GimpRectangleTool *rectangle = GIMP_RECTANGLE_TOOL (tool);
|
|
|
|
|
gint inc_x, inc_y;
|
|
|
|
|
gint min_x, min_y;
|
|
|
|
|
gint max_x, max_y;
|
|
|
|
|
gint x1, y1, x2, y2;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_RECTANGLE_TOOL (tool), FALSE);
|
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
|
if (display != tool->display)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
inc_x = inc_y = 0;
|
|
|
|
|
|
|
|
|
|
switch (kevent->keyval)
|
|
|
|
|
{
|
|
|
|
|
case GDK_Up:
|
|
|
|
|
inc_y = -1;
|
|
|
|
|
break;
|
|
|
|
|
case GDK_Left:
|
|
|
|
|
inc_x = -1;
|
|
|
|
|
break;
|
|
|
|
|
case GDK_Right:
|
|
|
|
|
inc_x = 1;
|
|
|
|
|
break;
|
|
|
|
|
case GDK_Down:
|
|
|
|
|
inc_y = 1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GDK_KP_Enter:
|
|
|
|
|
case GDK_Return:
|
2006-06-06 01:14:16 +08:00
|
|
|
|
if (gimp_rectangle_tool_execute (rectangle))
|
|
|
|
|
gimp_rectangle_tool_halt (rectangle);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
case GDK_Escape:
|
2006-06-06 01:14:16 +08:00
|
|
|
|
gimp_rectangle_tool_cancel (rectangle);
|
|
|
|
|
gimp_rectangle_tool_halt (rectangle);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
default:
|
2006-09-19 02:00:22 +08:00
|
|
|
|
g_print ("Key %d pressed\n", kevent->keyval);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If the shift key is down, move by an accelerated increment */
|
|
|
|
|
if (kevent->state & GDK_SHIFT_MASK)
|
|
|
|
|
{
|
|
|
|
|
inc_y *= ARROW_VELOCITY;
|
|
|
|
|
inc_x *= ARROW_VELOCITY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
|
|
|
|
|
|
|
|
|
min_x = min_y = 0;
|
2006-03-29 01:55:52 +08:00
|
|
|
|
max_x = display->image->width;
|
|
|
|
|
max_y = display->image->height;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_get (rectangle,
|
2006-01-22 02:20:26 +08:00
|
|
|
|
"x1", &x1,
|
|
|
|
|
"y1", &y1,
|
|
|
|
|
"x2", &x2,
|
|
|
|
|
"y2", &y2,
|
|
|
|
|
NULL);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
|
|
|
|
g_object_set (rectangle,
|
2006-01-22 02:20:26 +08:00
|
|
|
|
"x1", x1 + inc_x,
|
|
|
|
|
"y1", y1 + inc_y,
|
|
|
|
|
"x2", x2 + inc_x,
|
|
|
|
|
"y2", y2 + inc_y,
|
|
|
|
|
NULL);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2005-10-20 05:13:25 +08:00
|
|
|
|
gimp_rectangle_tool_configure (rectangle);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
|
|
|
|
|
2006-06-13 05:15:22 +08:00
|
|
|
|
g_signal_emit_by_name (rectangle, "rectangle-changed", NULL);
|
|
|
|
|
|
2005-03-03 02:18:19 +08:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
void
|
2005-03-03 02:18:19 +08:00
|
|
|
|
gimp_rectangle_tool_oper_update (GimpTool *tool,
|
|
|
|
|
GimpCoords *coords,
|
|
|
|
|
GdkModifierType state,
|
2006-03-25 22:23:09 +08:00
|
|
|
|
gboolean proximity,
|
2006-03-29 01:55:52 +08:00
|
|
|
|
GimpDisplay *display)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2006-06-03 06:24:55 +08:00
|
|
|
|
GimpRectangleTool *rectangle = GIMP_RECTANGLE_TOOL (tool);
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
|
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
|
gboolean inside_x;
|
|
|
|
|
gboolean inside_y;
|
2006-06-13 05:15:22 +08:00
|
|
|
|
gdouble handle_w, handle_h;
|
|
|
|
|
GimpDisplayShell *shell;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (tool));
|
2006-06-05 19:18:43 +08:00
|
|
|
|
|
2006-06-03 06:24:55 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
|
if (tool->display != display)
|
2006-01-22 02:20:26 +08:00
|
|
|
|
return;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2006-06-13 05:15:22 +08:00
|
|
|
|
shell = GIMP_DISPLAY_SHELL (tool->display->shell);
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_get (rectangle,
|
2006-01-22 02:20:26 +08:00
|
|
|
|
"x1", &x1,
|
|
|
|
|
"y1", &y1,
|
|
|
|
|
"x2", &x2,
|
|
|
|
|
"y2", &y2,
|
|
|
|
|
NULL);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
2006-06-13 05:15:22 +08:00
|
|
|
|
handle_w = private->dcw / SCALEFACTOR_X (shell);
|
|
|
|
|
handle_h = private->dch / SCALEFACTOR_Y (shell);
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
inside_x = coords->x > x1 && coords->x < x2;
|
|
|
|
|
inside_y = coords->y > y1 && coords->y < y2;
|
2005-03-10 06:22:38 +08:00
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
|
if (gimp_draw_tool_on_handle (draw_tool, display,
|
2005-03-03 02:18:19 +08:00
|
|
|
|
coords->x, coords->y,
|
|
|
|
|
GIMP_HANDLE_SQUARE,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
x1, y1,
|
2006-06-21 23:25:10 +08:00
|
|
|
|
private->dcw, private->dch,
|
2005-03-03 02:18:19 +08:00
|
|
|
|
GTK_ANCHOR_NORTH_WEST,
|
|
|
|
|
FALSE))
|
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_set (rectangle, "function", RECT_RESIZING_UPPER_LEFT, NULL);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
x1 - coords->x,
|
|
|
|
|
y1 - coords->y,
|
2005-03-03 02:18:19 +08:00
|
|
|
|
0, 0);
|
|
|
|
|
}
|
2006-03-29 01:55:52 +08:00
|
|
|
|
else if (gimp_draw_tool_on_handle (draw_tool, display,
|
2005-03-03 02:18:19 +08:00
|
|
|
|
coords->x, coords->y,
|
|
|
|
|
GIMP_HANDLE_SQUARE,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
x2, y2,
|
2006-06-21 23:25:10 +08:00
|
|
|
|
private->dcw, private->dch,
|
2005-03-03 02:18:19 +08:00
|
|
|
|
GTK_ANCHOR_SOUTH_EAST,
|
|
|
|
|
FALSE))
|
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_set (rectangle, "function", RECT_RESIZING_LOWER_RIGHT, NULL);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
x2 - coords->x,
|
|
|
|
|
y2 - coords->y,
|
2005-03-03 02:18:19 +08:00
|
|
|
|
0, 0);
|
|
|
|
|
}
|
2006-03-29 01:55:52 +08:00
|
|
|
|
else if (gimp_draw_tool_on_handle (draw_tool, display,
|
2005-03-03 02:18:19 +08:00
|
|
|
|
coords->x, coords->y,
|
|
|
|
|
GIMP_HANDLE_SQUARE,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
x2, y1,
|
2006-06-21 23:25:10 +08:00
|
|
|
|
private->dcw, private->dch,
|
2005-03-03 02:18:19 +08:00
|
|
|
|
GTK_ANCHOR_NORTH_EAST,
|
|
|
|
|
FALSE))
|
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_set (rectangle, "function", RECT_RESIZING_UPPER_RIGHT, NULL);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
x2 - coords->x,
|
|
|
|
|
y1 - coords->y,
|
2005-03-10 06:22:38 +08:00
|
|
|
|
0, 0);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
2006-03-29 01:55:52 +08:00
|
|
|
|
else if (gimp_draw_tool_on_handle (draw_tool, display,
|
2005-03-10 06:22:38 +08:00
|
|
|
|
coords->x, coords->y,
|
|
|
|
|
GIMP_HANDLE_SQUARE,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
x1, y2,
|
2006-06-21 23:25:10 +08:00
|
|
|
|
private->dcw, private->dch,
|
2005-03-10 06:22:38 +08:00
|
|
|
|
GTK_ANCHOR_SOUTH_WEST,
|
|
|
|
|
FALSE))
|
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_set (rectangle, "function", RECT_RESIZING_LOWER_LEFT, NULL);
|
2005-03-10 06:22:38 +08:00
|
|
|
|
|
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
x1 - coords->x,
|
|
|
|
|
y2 - coords->y,
|
2005-03-10 06:22:38 +08:00
|
|
|
|
0, 0);
|
|
|
|
|
}
|
2006-06-13 05:15:22 +08:00
|
|
|
|
else if ( (fabs (coords->x - x1) < handle_w) && inside_y)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_set (rectangle, "function", RECT_RESIZING_LEFT, NULL);
|
2005-03-10 06:22:38 +08:00
|
|
|
|
|
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
x1 - coords->x, 0, 0, 0);
|
2005-03-10 06:22:38 +08:00
|
|
|
|
|
|
|
|
|
}
|
2006-06-13 05:15:22 +08:00
|
|
|
|
else if ( (fabs (coords->x - x2) < handle_w) && inside_y)
|
2005-03-10 06:22:38 +08:00
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_set (rectangle, "function", RECT_RESIZING_RIGHT, NULL);
|
2005-03-10 06:22:38 +08:00
|
|
|
|
|
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
x2 - coords->x, 0, 0, 0);
|
2005-03-10 06:22:38 +08:00
|
|
|
|
|
|
|
|
|
}
|
2006-06-13 05:15:22 +08:00
|
|
|
|
else if ( (fabs (coords->y - y1) < handle_h) && inside_x)
|
2005-03-10 06:22:38 +08:00
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_set (rectangle, "function", RECT_RESIZING_TOP, NULL);
|
2005-03-10 06:22:38 +08:00
|
|
|
|
|
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
0, y1 - coords->y, 0, 0);
|
2005-03-10 06:22:38 +08:00
|
|
|
|
|
|
|
|
|
}
|
2006-06-13 05:15:22 +08:00
|
|
|
|
else if ( (fabs (coords->y - y2) < handle_h) && inside_x)
|
2005-03-10 06:22:38 +08:00
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_set (rectangle, "function", RECT_RESIZING_BOTTOM, NULL);
|
2005-03-10 06:22:38 +08:00
|
|
|
|
|
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
0, y2 - coords->y, 0, 0);
|
2005-03-10 06:22:38 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else if (inside_x && inside_y)
|
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_set (rectangle, "function", RECT_MOVING, NULL);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
/* otherwise, the new function will be creating, since we want
|
2005-03-10 06:22:38 +08:00
|
|
|
|
* to start a new rectangle
|
2005-03-03 02:18:19 +08:00
|
|
|
|
*/
|
|
|
|
|
else
|
|
|
|
|
{
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_set (rectangle, "function", RECT_CREATING, NULL);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control, 0, 0, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
void
|
2005-03-03 02:18:19 +08:00
|
|
|
|
gimp_rectangle_tool_cursor_update (GimpTool *tool,
|
|
|
|
|
GimpCoords *coords,
|
|
|
|
|
GdkModifierType state,
|
2006-03-29 01:55:52 +08:00
|
|
|
|
GimpDisplay *display)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2006-06-02 23:23:47 +08:00
|
|
|
|
GimpRectangleTool *rectangle;
|
|
|
|
|
GimpCursorType cursor = GIMP_CURSOR_CROSSHAIR_SMALL;
|
|
|
|
|
GimpCursorModifier modifier = GIMP_CURSOR_MODIFIER_NONE;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (tool));
|
|
|
|
|
|
2006-06-02 23:23:47 +08:00
|
|
|
|
rectangle = GIMP_RECTANGLE_TOOL (tool);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2006-09-12 16:33:30 +08:00
|
|
|
|
if (tool->display == display)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2006-06-02 23:23:47 +08:00
|
|
|
|
guint function;
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_get (rectangle, "function", &function, NULL);
|
|
|
|
|
|
|
|
|
|
switch (function)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2005-03-15 04:44:18 +08:00
|
|
|
|
case RECT_CREATING:
|
2006-06-02 23:23:47 +08:00
|
|
|
|
cursor = GIMP_CURSOR_CROSSHAIR_SMALL;
|
2005-03-15 04:44:18 +08:00
|
|
|
|
break;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
case RECT_MOVING:
|
2006-06-02 23:23:47 +08:00
|
|
|
|
cursor = GIMP_CURSOR_CROSSHAIR_SMALL;
|
|
|
|
|
modifier = GIMP_CURSOR_MODIFIER_MOVE;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
break;
|
2005-03-10 06:22:38 +08:00
|
|
|
|
case RECT_RESIZING_UPPER_LEFT:
|
2006-06-02 23:23:47 +08:00
|
|
|
|
cursor = GIMP_CURSOR_CORNER_TOP_LEFT;
|
2005-03-15 04:44:18 +08:00
|
|
|
|
break;
|
2005-03-10 06:22:38 +08:00
|
|
|
|
case RECT_RESIZING_UPPER_RIGHT:
|
2006-06-02 23:23:47 +08:00
|
|
|
|
cursor = GIMP_CURSOR_CORNER_TOP_RIGHT;
|
2005-03-15 04:44:18 +08:00
|
|
|
|
break;
|
2005-03-10 06:22:38 +08:00
|
|
|
|
case RECT_RESIZING_LOWER_LEFT:
|
2006-06-02 23:23:47 +08:00
|
|
|
|
cursor = GIMP_CURSOR_CORNER_BOTTOM_LEFT;
|
2005-03-15 04:44:18 +08:00
|
|
|
|
break;
|
2005-03-10 06:22:38 +08:00
|
|
|
|
case RECT_RESIZING_LOWER_RIGHT:
|
2006-06-02 23:23:47 +08:00
|
|
|
|
cursor = GIMP_CURSOR_CORNER_BOTTOM_RIGHT;
|
2005-03-15 04:44:18 +08:00
|
|
|
|
break;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
case RECT_RESIZING_LEFT:
|
2006-06-02 23:23:47 +08:00
|
|
|
|
cursor = GIMP_CURSOR_SIDE_LEFT;
|
2005-03-15 04:44:18 +08:00
|
|
|
|
break;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
case RECT_RESIZING_RIGHT:
|
2006-06-02 23:23:47 +08:00
|
|
|
|
cursor = GIMP_CURSOR_SIDE_RIGHT;
|
2005-03-15 04:44:18 +08:00
|
|
|
|
break;
|
2005-03-10 06:22:38 +08:00
|
|
|
|
case RECT_RESIZING_TOP:
|
2006-06-02 23:23:47 +08:00
|
|
|
|
cursor = GIMP_CURSOR_SIDE_TOP;
|
2005-03-15 04:44:18 +08:00
|
|
|
|
break;
|
2005-03-10 06:22:38 +08:00
|
|
|
|
case RECT_RESIZING_BOTTOM:
|
2006-06-02 23:23:47 +08:00
|
|
|
|
cursor = GIMP_CURSOR_SIDE_BOTTOM;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gimp_tool_control_set_cursor (tool->control, cursor);
|
|
|
|
|
gimp_tool_control_set_cursor_modifier (tool->control, modifier);
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-21 04:23:49 +08:00
|
|
|
|
#define ANCHOR_SIZE 14
|
2006-06-05 02:21:56 +08:00
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
void
|
2006-06-05 02:21:56 +08:00
|
|
|
|
gimp_rectangle_tool_draw (GimpDrawTool *draw_tool)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2006-06-03 06:24:55 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2006-06-05 02:21:56 +08:00
|
|
|
|
gint x1, x2, y1, y2;
|
|
|
|
|
guint function;
|
2006-09-15 08:01:59 +08:00
|
|
|
|
gboolean button1_down;
|
|
|
|
|
GimpTool *tool;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
2006-06-06 04:48:58 +08:00
|
|
|
|
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (draw_tool));
|
|
|
|
|
|
2006-09-15 08:01:59 +08:00
|
|
|
|
tool = GIMP_TOOL (draw_tool);
|
|
|
|
|
|
2006-06-06 04:48:58 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (draw_tool);
|
2006-06-05 02:21:56 +08:00
|
|
|
|
|
2006-06-07 03:25:53 +08:00
|
|
|
|
g_object_get (GIMP_RECTANGLE_TOOL (draw_tool), "function", &function, NULL);
|
2006-06-05 19:18:43 +08:00
|
|
|
|
|
2006-06-05 02:21:56 +08:00
|
|
|
|
if (function == RECT_INACTIVE)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
x1 = private->x1;
|
|
|
|
|
x2 = private->x2;
|
|
|
|
|
y1 = private->y1;
|
|
|
|
|
y2 = private->y2;
|
|
|
|
|
|
|
|
|
|
gimp_draw_tool_draw_rectangle (draw_tool, FALSE,
|
|
|
|
|
x1, y1, x2 - x1, y2 - y1, FALSE);
|
2006-06-06 04:48:58 +08:00
|
|
|
|
|
2006-09-15 08:01:59 +08:00
|
|
|
|
|
|
|
|
|
button1_down = gimp_tool_control_is_active (tool->control);
|
|
|
|
|
|
|
|
|
|
if (button1_down)
|
|
|
|
|
{
|
|
|
|
|
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (tool->display->shell);
|
|
|
|
|
gdouble handle_w;
|
|
|
|
|
gdouble handle_h;
|
2006-09-21 04:23:49 +08:00
|
|
|
|
gint X1 = x1;
|
|
|
|
|
gint Y1 = y1;
|
|
|
|
|
gint X2 = x2;
|
|
|
|
|
gint Y2 = y2;
|
2006-09-15 08:01:59 +08:00
|
|
|
|
gboolean do_it = TRUE;
|
|
|
|
|
|
|
|
|
|
handle_w = private->dcw / SCALEFACTOR_X (shell);
|
|
|
|
|
handle_h = private->dch / SCALEFACTOR_Y (shell);
|
|
|
|
|
|
|
|
|
|
switch (private->function)
|
|
|
|
|
{
|
|
|
|
|
case RECT_RESIZING_LEFT:
|
2006-09-21 04:23:49 +08:00
|
|
|
|
X2 = x1 + handle_w / 3;
|
2006-09-15 08:01:59 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_RIGHT:
|
2006-09-21 04:23:49 +08:00
|
|
|
|
X1 = x2 - handle_w / 3;
|
2006-09-15 08:01:59 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_TOP:
|
2006-09-21 04:23:49 +08:00
|
|
|
|
Y2 = y1 + handle_h / 3;
|
2006-09-15 08:01:59 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_BOTTOM:
|
2006-09-21 04:23:49 +08:00
|
|
|
|
Y1 = y2 - handle_h / 3;
|
2006-09-15 08:01:59 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
do_it = FALSE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (do_it)
|
2006-09-21 04:23:49 +08:00
|
|
|
|
{
|
|
|
|
|
gimp_draw_tool_draw_rectangle (draw_tool, TRUE,
|
|
|
|
|
X1, Y1, X2 - X1, Y2 - Y1,
|
|
|
|
|
FALSE);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GimpCoords coords[3];
|
|
|
|
|
|
|
|
|
|
do_it = TRUE;
|
|
|
|
|
|
|
|
|
|
switch (private->function)
|
|
|
|
|
{
|
|
|
|
|
case RECT_RESIZING_UPPER_LEFT:
|
|
|
|
|
coords[0].x = x1;
|
|
|
|
|
coords[0].y = y1;
|
|
|
|
|
coords[1].x = x1;
|
|
|
|
|
coords[1].y = y1 + handle_h;
|
|
|
|
|
coords[2].x = x1 + handle_w;
|
|
|
|
|
coords[2].y = y1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_UPPER_RIGHT:
|
|
|
|
|
coords[0].x = x2;
|
|
|
|
|
coords[0].y = y1;
|
|
|
|
|
coords[1].x = x2;
|
|
|
|
|
coords[1].y = y1 + handle_h;
|
|
|
|
|
coords[2].x = x2 - handle_w;
|
|
|
|
|
coords[2].y = y1;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_LOWER_LEFT:
|
|
|
|
|
coords[0].x = x1;
|
|
|
|
|
coords[0].y = y2;
|
|
|
|
|
coords[1].x = x1;
|
|
|
|
|
coords[1].y = y2 - handle_h;
|
|
|
|
|
coords[2].x = x1 + handle_w;
|
|
|
|
|
coords[2].y = y2;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case RECT_RESIZING_LOWER_RIGHT:
|
|
|
|
|
coords[0].x = x2;
|
|
|
|
|
coords[0].y = y2;
|
|
|
|
|
coords[1].x = x2;
|
|
|
|
|
coords[1].y = y2 - handle_h;
|
|
|
|
|
coords[2].x = x2 - handle_w;
|
|
|
|
|
coords[2].y = y2;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
do_it = FALSE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (do_it)
|
|
|
|
|
{
|
|
|
|
|
gimp_draw_tool_draw_strokes (draw_tool, coords, 3, TRUE, FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-09-15 08:01:59 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
gimp_draw_tool_draw_handle (draw_tool, GIMP_HANDLE_FILLED_SQUARE,
|
|
|
|
|
x1, y1, ANCHOR_SIZE, ANCHOR_SIZE,
|
|
|
|
|
GTK_ANCHOR_NORTH_WEST, FALSE);
|
|
|
|
|
gimp_draw_tool_draw_handle (draw_tool, GIMP_HANDLE_FILLED_SQUARE,
|
|
|
|
|
x2, y1, ANCHOR_SIZE, ANCHOR_SIZE,
|
|
|
|
|
GTK_ANCHOR_NORTH_EAST, FALSE);
|
|
|
|
|
gimp_draw_tool_draw_handle (draw_tool, GIMP_HANDLE_FILLED_SQUARE,
|
|
|
|
|
x1, y2, ANCHOR_SIZE, ANCHOR_SIZE,
|
|
|
|
|
GTK_ANCHOR_SOUTH_WEST, FALSE);
|
|
|
|
|
gimp_draw_tool_draw_handle (draw_tool, GIMP_HANDLE_FILLED_SQUARE,
|
|
|
|
|
x2, y2, ANCHOR_SIZE, ANCHOR_SIZE,
|
|
|
|
|
GTK_ANCHOR_SOUTH_EAST, FALSE);
|
|
|
|
|
}
|
2006-06-06 02:50:13 +08:00
|
|
|
|
|
2006-06-07 03:14:25 +08:00
|
|
|
|
gimp_rectangle_tool_draw_guides (draw_tool);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gimp_rectangle_tool_draw_guides (GimpDrawTool *draw_tool)
|
|
|
|
|
{
|
|
|
|
|
GimpTool *tool;
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
gint x1, x2, y1, y2;
|
|
|
|
|
|
|
|
|
|
tool = GIMP_TOOL (draw_tool);
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (draw_tool);
|
|
|
|
|
|
|
|
|
|
x1 = private->x1;
|
|
|
|
|
x2 = private->x2;
|
|
|
|
|
y1 = private->y1;
|
|
|
|
|
y2 = private->y2;
|
2006-06-07 03:25:53 +08:00
|
|
|
|
|
2006-06-07 05:06:06 +08:00
|
|
|
|
switch (private->guide)
|
2006-06-06 02:50:13 +08:00
|
|
|
|
{
|
|
|
|
|
case GIMP_RECTANGLE_GUIDE_NONE:
|
|
|
|
|
break;
|
2006-06-06 04:48:58 +08:00
|
|
|
|
|
2006-06-06 02:50:13 +08:00
|
|
|
|
case GIMP_RECTANGLE_GUIDE_CENTER_LINES:
|
2006-06-06 04:48:58 +08:00
|
|
|
|
gimp_draw_tool_draw_line (draw_tool,
|
|
|
|
|
x1, (y1 + y2) / 2,
|
|
|
|
|
x2, (y1 + y2) / 2, FALSE);
|
|
|
|
|
gimp_draw_tool_draw_line (draw_tool,
|
|
|
|
|
(x1 + x2) / 2, y1,
|
|
|
|
|
(x1 + x2) / 2, y2, FALSE);
|
2006-06-06 02:50:13 +08:00
|
|
|
|
break;
|
2006-06-06 04:48:58 +08:00
|
|
|
|
|
2006-06-06 02:50:13 +08:00
|
|
|
|
case GIMP_RECTANGLE_GUIDE_THIRDS:
|
2006-06-06 04:48:58 +08:00
|
|
|
|
gimp_draw_tool_draw_line (draw_tool,
|
|
|
|
|
x1, (2 * y1 + y2) / 3,
|
|
|
|
|
x2, (2 * y1 + y2) / 3, FALSE);
|
|
|
|
|
gimp_draw_tool_draw_line (draw_tool,
|
|
|
|
|
x1, (y1 + 2 * y2) / 3,
|
|
|
|
|
x2, (y1 + 2 * y2) / 3, FALSE);
|
|
|
|
|
gimp_draw_tool_draw_line (draw_tool,
|
|
|
|
|
(2 * x1 + x2) / 3, y1,
|
|
|
|
|
(2 * x1 + x2) / 3, y2, FALSE);
|
|
|
|
|
gimp_draw_tool_draw_line (draw_tool,
|
|
|
|
|
(x1 + 2 * x2) / 3, y1,
|
|
|
|
|
(x1 + 2 * x2) / 3, y2, FALSE);
|
2006-06-06 02:50:13 +08:00
|
|
|
|
break;
|
2006-06-06 04:48:58 +08:00
|
|
|
|
|
2006-06-06 02:50:13 +08:00
|
|
|
|
case GIMP_RECTANGLE_GUIDE_GOLDEN:
|
2006-06-06 04:48:58 +08:00
|
|
|
|
gimp_draw_tool_draw_line (draw_tool,
|
2006-06-07 03:25:53 +08:00
|
|
|
|
x1,
|
|
|
|
|
(2 * y1 + (1 + sqrt(5)) * y2) / (3 + sqrt(5)),
|
|
|
|
|
x2,
|
|
|
|
|
(2 * y1 + (1 + sqrt(5)) * y2) / (3 + sqrt(5)),
|
|
|
|
|
FALSE);
|
2006-06-06 04:48:58 +08:00
|
|
|
|
gimp_draw_tool_draw_line (draw_tool,
|
2006-06-07 03:25:53 +08:00
|
|
|
|
x1,
|
|
|
|
|
((1 + sqrt(5)) * y1 + 2 * y2) / (3 + sqrt(5)),
|
|
|
|
|
x2,
|
|
|
|
|
((1 + sqrt(5)) * y1 + 2 * y2) / (3 + sqrt(5)),
|
|
|
|
|
FALSE);
|
2006-06-06 04:48:58 +08:00
|
|
|
|
gimp_draw_tool_draw_line (draw_tool,
|
2006-06-07 03:25:53 +08:00
|
|
|
|
(2 * x1 + (1 + sqrt(5)) * x2) / (3 + sqrt(5)),
|
|
|
|
|
y1,
|
|
|
|
|
(2 * x1 + (1 + sqrt(5)) * x2) / (3 + sqrt(5)),
|
|
|
|
|
y2,
|
|
|
|
|
FALSE);
|
2006-06-06 04:48:58 +08:00
|
|
|
|
gimp_draw_tool_draw_line (draw_tool,
|
2006-06-07 03:25:53 +08:00
|
|
|
|
((1 + sqrt(5)) * x1 + 2 * x2) / (3 + sqrt(5)),
|
|
|
|
|
y1,
|
|
|
|
|
((1 + sqrt(5)) * x1 + 2 * x2) / (3 + sqrt(5)),
|
|
|
|
|
y2, FALSE);
|
2006-06-06 02:50:13 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-20 05:13:25 +08:00
|
|
|
|
void
|
|
|
|
|
gimp_rectangle_tool_configure (GimpRectangleTool *rectangle)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2006-09-06 02:25:31 +08:00
|
|
|
|
GimpTool *tool = GIMP_TOOL (rectangle);
|
2006-06-03 06:24:55 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
GimpRectangleOptions *options;
|
2006-09-06 02:25:31 +08:00
|
|
|
|
GimpDisplayShell *shell;
|
2006-06-03 06:24:55 +08:00
|
|
|
|
gboolean highlight;
|
|
|
|
|
gint x1, y1;
|
|
|
|
|
gint x2, y2;
|
|
|
|
|
gint dx1, dx2, dy1, dy2, dcw, dch;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2006-09-06 02:25:31 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
|
|
|
|
options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (tool);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
|
if (! tool->display)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2006-09-06 02:25:31 +08:00
|
|
|
|
shell = GIMP_DISPLAY_SHELL (tool->display->shell);
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_get (options, "highlight", &highlight, NULL);
|
|
|
|
|
|
|
|
|
|
g_object_get (rectangle,
|
2006-01-22 02:20:26 +08:00
|
|
|
|
"x1", &x1,
|
|
|
|
|
"y1", &y1,
|
|
|
|
|
"x2", &x2,
|
|
|
|
|
"y2", &y2,
|
|
|
|
|
NULL);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
|
|
|
|
if (highlight)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
|
|
|
|
GdkRectangle rect;
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
rect.x = x1;
|
|
|
|
|
rect.y = y1;
|
|
|
|
|
rect.width = x2 - x1;
|
|
|
|
|
rect.height = y2 - y1;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
|
|
|
|
gimp_display_shell_set_highlight (shell, &rect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gimp_display_shell_transform_xy (shell,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
x1, y1,
|
2005-08-15 22:23:28 +08:00
|
|
|
|
&dx1, &dy1,
|
2005-03-03 02:18:19 +08:00
|
|
|
|
FALSE);
|
|
|
|
|
gimp_display_shell_transform_xy (shell,
|
2005-09-04 03:48:22 +08:00
|
|
|
|
x2, y2,
|
2005-08-15 22:23:28 +08:00
|
|
|
|
&dx2, &dy2,
|
2005-03-03 02:18:19 +08:00
|
|
|
|
FALSE);
|
|
|
|
|
|
2006-09-15 08:01:59 +08:00
|
|
|
|
#define SRW 20
|
|
|
|
|
#define SRH 20
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2006-03-22 03:40:32 +08:00
|
|
|
|
dcw = ((dx2 - dx1) < SRW) ? (dx2 - dx1) : SRW;
|
|
|
|
|
dch = ((dy2 - dy1) < SRH) ? (dy2 - dy1) : SRH;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
|
|
|
|
#undef SRW
|
|
|
|
|
#undef SRH
|
2006-06-03 06:24:55 +08:00
|
|
|
|
|
|
|
|
|
private->dx1 = dx1;
|
|
|
|
|
private->dx2 = dx2;
|
|
|
|
|
private->dy1 = dy1;
|
|
|
|
|
private->dy2 = dy2;
|
|
|
|
|
private->dcw = dcw;
|
|
|
|
|
private->dch = dch;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
rectangle_tool_start (GimpRectangleTool *rectangle)
|
|
|
|
|
{
|
2005-05-07 21:24:47 +08:00
|
|
|
|
GimpTool *tool = GIMP_TOOL (rectangle);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2005-10-20 05:13:25 +08:00
|
|
|
|
gimp_rectangle_tool_configure (rectangle);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
|
|
|
|
/* initialize the statusbar display */
|
2006-03-29 01:55:52 +08:00
|
|
|
|
gimp_tool_push_status_coords (tool, tool->display,
|
2005-05-07 21:24:47 +08:00
|
|
|
|
_("Rectangle: "), 0, " x ", 0);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
|
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), tool->display);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-20 05:13:25 +08:00
|
|
|
|
void
|
2006-06-06 01:14:16 +08:00
|
|
|
|
gimp_rectangle_tool_halt (GimpRectangleTool *rectangle)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2006-06-06 01:14:16 +08:00
|
|
|
|
GimpTool *tool = GIMP_TOOL (rectangle);
|
2005-04-10 02:08:47 +08:00
|
|
|
|
|
2006-06-06 01:14:16 +08:00
|
|
|
|
gimp_display_shell_set_highlight (GIMP_DISPLAY_SHELL (tool->display->shell),
|
|
|
|
|
NULL);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2006-06-06 01:14:16 +08:00
|
|
|
|
if (gimp_draw_tool_is_active (GIMP_DRAW_TOOL (rectangle)))
|
|
|
|
|
gimp_draw_tool_stop (GIMP_DRAW_TOOL (rectangle));
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2006-06-06 01:14:16 +08:00
|
|
|
|
if (gimp_tool_control_is_active (tool->control))
|
|
|
|
|
gimp_tool_control_halt (tool->control);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2006-06-06 01:14:16 +08:00
|
|
|
|
tool->display = NULL;
|
|
|
|
|
tool->drawable = NULL;
|
2005-03-09 07:17:19 +08:00
|
|
|
|
|
2006-06-06 01:14:16 +08:00
|
|
|
|
g_object_set (rectangle, "function", RECT_INACTIVE, NULL);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
gboolean
|
2006-06-06 01:14:16 +08:00
|
|
|
|
gimp_rectangle_tool_execute (GimpRectangleTool *rectangle)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2006-06-06 01:14:16 +08:00
|
|
|
|
GimpRectangleToolInterface *iface;
|
|
|
|
|
gboolean retval = FALSE;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
2006-06-06 01:14:16 +08:00
|
|
|
|
iface = GIMP_RECTANGLE_TOOL_GET_INTERFACE (rectangle);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
2006-06-06 01:14:16 +08:00
|
|
|
|
if (iface->execute)
|
|
|
|
|
{
|
|
|
|
|
gint x1, y1, x2, y2;
|
|
|
|
|
|
|
|
|
|
g_object_get (rectangle,
|
|
|
|
|
"x1", &x1,
|
|
|
|
|
"y1", &y1,
|
|
|
|
|
"x2", &x2,
|
|
|
|
|
"y2", &y2,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (rectangle));
|
|
|
|
|
|
|
|
|
|
retval = iface->execute (rectangle, x1, y1, x2 - x1, y2 - y1);
|
|
|
|
|
|
|
|
|
|
gimp_rectangle_tool_configure (rectangle);
|
|
|
|
|
|
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (rectangle));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gimp_rectangle_tool_cancel (GimpRectangleTool *rectangle)
|
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolInterface *iface;
|
|
|
|
|
|
|
|
|
|
iface = GIMP_RECTANGLE_TOOL_GET_INTERFACE (rectangle);
|
2005-04-10 02:08:47 +08:00
|
|
|
|
|
2006-06-06 01:14:16 +08:00
|
|
|
|
if (iface->cancel)
|
|
|
|
|
iface->cancel (rectangle);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-09 07:17:19 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_rectangle_tool_update_options (GimpRectangleTool *rectangle,
|
2006-03-29 01:55:52 +08:00
|
|
|
|
GimpDisplay *display)
|
2005-03-09 07:17:19 +08:00
|
|
|
|
{
|
2006-09-06 02:25:31 +08:00
|
|
|
|
GimpRectangleOptions *options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (rectangle);
|
2006-09-23 02:27:21 +08:00
|
|
|
|
gdouble x;
|
|
|
|
|
gdouble y;
|
2005-09-04 03:48:22 +08:00
|
|
|
|
gdouble width;
|
|
|
|
|
gdouble height;
|
|
|
|
|
gdouble center_x, center_y;
|
|
|
|
|
gint x1, y1, x2, y2;
|
2005-11-30 07:32:55 +08:00
|
|
|
|
gboolean fixed_width;
|
|
|
|
|
gboolean fixed_height;
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
|
|
|
|
g_object_get (rectangle,
|
2005-11-30 07:32:55 +08:00
|
|
|
|
"x1", &x1,
|
|
|
|
|
"y1", &y1,
|
|
|
|
|
"x2", &x2,
|
|
|
|
|
"y2", &y2,
|
|
|
|
|
NULL);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
2005-11-30 07:32:55 +08:00
|
|
|
|
g_object_get (options,
|
2006-09-22 04:16:25 +08:00
|
|
|
|
"fixed-width", &fixed_width,
|
|
|
|
|
"fixed-height", &fixed_height,
|
2005-11-30 07:32:55 +08:00
|
|
|
|
NULL);
|
2005-03-11 07:55:24 +08:00
|
|
|
|
|
2006-09-23 02:27:21 +08:00
|
|
|
|
x = x1;
|
|
|
|
|
y = y1;
|
2005-09-04 03:48:22 +08:00
|
|
|
|
width = x2 - x1;
|
|
|
|
|
height = y2 - y1;
|
2005-03-09 07:17:19 +08:00
|
|
|
|
|
2006-02-07 19:38:17 +08:00
|
|
|
|
center_x = (x1 + x2) / 2.0;
|
|
|
|
|
center_y = (y1 + y2) / 2.0;
|
2005-03-10 06:22:38 +08:00
|
|
|
|
|
2006-09-23 02:27:21 +08:00
|
|
|
|
/* need to block "notify" handlers for the options */
|
|
|
|
|
g_signal_handlers_block_matched (options, G_SIGNAL_MATCH_DATA,
|
|
|
|
|
0, 0, NULL, NULL, rectangle);
|
|
|
|
|
|
|
|
|
|
g_object_set (options,
|
|
|
|
|
"x0", x,
|
|
|
|
|
"y0", y,
|
|
|
|
|
NULL);
|
2005-03-11 07:55:24 +08:00
|
|
|
|
|
2005-11-30 07:32:55 +08:00
|
|
|
|
if (! fixed_width)
|
|
|
|
|
g_object_set (options,
|
|
|
|
|
"width", width,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
if (! fixed_height)
|
|
|
|
|
g_object_set (options,
|
|
|
|
|
"height", height,
|
|
|
|
|
NULL);
|
|
|
|
|
|
2006-09-23 02:27:21 +08:00
|
|
|
|
g_signal_handlers_unblock_matched (options, G_SIGNAL_MATCH_DATA,
|
|
|
|
|
0, 0, NULL, NULL, rectangle);
|
|
|
|
|
|
2005-03-11 07:55:24 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
g_object_set (options,
|
|
|
|
|
"center-x", center_x,
|
|
|
|
|
"center-y", center_y,
|
|
|
|
|
NULL);
|
2005-03-10 06:22:38 +08:00
|
|
|
|
|
2005-03-09 07:17:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-22 04:17:19 +08:00
|
|
|
|
/*
|
|
|
|
|
* we handle changes in width by treating them as movement of the right edge
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
gimp_rectangle_tool_notify_width (GimpRectangleOptions *options,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
GimpRectangleTool *rectangle)
|
|
|
|
|
{
|
2006-06-03 06:24:55 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
gint rx1, rx2, ry1, ry2;
|
|
|
|
|
GimpCoords coords;
|
|
|
|
|
gdouble width;
|
|
|
|
|
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rectangle);
|
2005-10-22 04:17:19 +08:00
|
|
|
|
|
2005-11-29 06:30:24 +08:00
|
|
|
|
/* make sure a rectangle exists */
|
2006-03-29 01:55:52 +08:00
|
|
|
|
if (! GIMP_TOOL (rectangle)->display)
|
2005-11-29 06:30:24 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2006-03-22 01:37:24 +08:00
|
|
|
|
g_object_get (options,
|
|
|
|
|
"width", &width,
|
|
|
|
|
NULL);
|
2005-10-22 04:17:19 +08:00
|
|
|
|
g_object_get (rectangle,
|
|
|
|
|
"x1", &rx1,
|
|
|
|
|
"y1", &ry1,
|
|
|
|
|
"x2", &rx2,
|
|
|
|
|
"y2", &ry2,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
coords.x = rx1 + width;
|
|
|
|
|
coords.y = ry2;
|
|
|
|
|
|
|
|
|
|
g_object_set (rectangle,
|
|
|
|
|
"function", RECT_RESIZING_RIGHT,
|
|
|
|
|
NULL);
|
2006-06-03 06:24:55 +08:00
|
|
|
|
private->startx = rx2;
|
|
|
|
|
private->starty = ry2;
|
2005-10-22 04:17:19 +08:00
|
|
|
|
|
|
|
|
|
gimp_rectangle_tool_motion (GIMP_TOOL (rectangle), &coords, 0, 0,
|
2006-03-29 01:55:52 +08:00
|
|
|
|
GIMP_TOOL (rectangle)->display);
|
2006-06-05 01:08:26 +08:00
|
|
|
|
|
|
|
|
|
g_signal_emit_by_name (rectangle, "rectangle-changed", NULL);
|
2005-10-22 04:17:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-23 02:27:21 +08:00
|
|
|
|
/*
|
|
|
|
|
* we handle changes in x by treating them as movement of the left edge
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
gimp_rectangle_tool_notify_x (GimpRectangleOptions *options,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
GimpRectangleTool *rectangle)
|
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
gint rx1, rx2, ry1, ry2;
|
|
|
|
|
GimpCoords coords;
|
|
|
|
|
gdouble x;
|
|
|
|
|
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rectangle);
|
|
|
|
|
|
|
|
|
|
/* make sure a rectangle exists */
|
|
|
|
|
if (! GIMP_TOOL (rectangle)->display)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
g_object_get (options,
|
|
|
|
|
"x0", &x,
|
|
|
|
|
NULL);
|
|
|
|
|
g_object_get (rectangle,
|
|
|
|
|
"x1", &rx1,
|
|
|
|
|
"y1", &ry1,
|
|
|
|
|
"x2", &rx2,
|
|
|
|
|
"y2", &ry2,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
coords.x = x;
|
|
|
|
|
coords.y = ry2;
|
|
|
|
|
|
|
|
|
|
g_object_set (rectangle,
|
|
|
|
|
"function", RECT_RESIZING_LEFT,
|
|
|
|
|
NULL);
|
|
|
|
|
private->startx = rx1;
|
|
|
|
|
private->starty = ry1;
|
|
|
|
|
|
|
|
|
|
gimp_rectangle_tool_motion (GIMP_TOOL (rectangle), &coords, 0, 0,
|
|
|
|
|
GIMP_TOOL (rectangle)->display);
|
|
|
|
|
|
|
|
|
|
g_signal_emit_by_name (rectangle, "rectangle-changed", NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* we handle changes in y by treating them as movement of the top edge
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
gimp_rectangle_tool_notify_y (GimpRectangleOptions *options,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
GimpRectangleTool *rectangle)
|
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
gint rx1, rx2, ry1, ry2;
|
|
|
|
|
GimpCoords coords;
|
|
|
|
|
gdouble y;
|
|
|
|
|
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rectangle);
|
|
|
|
|
|
|
|
|
|
/* make sure a rectangle exists */
|
|
|
|
|
if (! GIMP_TOOL (rectangle)->display)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
g_object_get (options,
|
|
|
|
|
"y0", &y,
|
|
|
|
|
NULL);
|
|
|
|
|
g_object_get (rectangle,
|
|
|
|
|
"x1", &rx1,
|
|
|
|
|
"y1", &ry1,
|
|
|
|
|
"x2", &rx2,
|
|
|
|
|
"y2", &ry2,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
coords.x = rx1;
|
|
|
|
|
coords.y = y;
|
|
|
|
|
|
|
|
|
|
g_object_set (rectangle,
|
|
|
|
|
"function", RECT_RESIZING_TOP,
|
|
|
|
|
NULL);
|
|
|
|
|
private->startx = rx1;
|
|
|
|
|
private->starty = ry1;
|
|
|
|
|
|
|
|
|
|
gimp_rectangle_tool_motion (GIMP_TOOL (rectangle), &coords, 0, 0,
|
|
|
|
|
GIMP_TOOL (rectangle)->display);
|
|
|
|
|
|
|
|
|
|
g_signal_emit_by_name (rectangle, "rectangle-changed", NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2005-10-22 04:17:19 +08:00
|
|
|
|
/*
|
|
|
|
|
* we handle changes in height by treating them as movement of the bottom edge
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
gimp_rectangle_tool_notify_height (GimpRectangleOptions *options,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
GimpRectangleTool *rectangle)
|
|
|
|
|
{
|
2006-06-03 06:24:55 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
gint rx1, rx2, ry1, ry2;
|
|
|
|
|
GimpCoords coords;
|
|
|
|
|
gdouble height;
|
|
|
|
|
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rectangle);
|
2005-10-22 04:17:19 +08:00
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
|
if (! GIMP_TOOL (rectangle)->display)
|
2005-11-29 06:30:24 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2006-03-22 01:37:24 +08:00
|
|
|
|
g_object_get (options,
|
|
|
|
|
"height", &height,
|
|
|
|
|
NULL);
|
2005-10-22 04:17:19 +08:00
|
|
|
|
g_object_get (rectangle,
|
|
|
|
|
"x1", &rx1,
|
|
|
|
|
"y1", &ry1,
|
|
|
|
|
"x2", &rx2,
|
|
|
|
|
"y2", &ry2,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
coords.x = rx2;
|
|
|
|
|
coords.y = ry1 + height;
|
|
|
|
|
|
|
|
|
|
g_object_set (rectangle,
|
|
|
|
|
"function", RECT_RESIZING_BOTTOM,
|
|
|
|
|
NULL);
|
2006-06-03 06:24:55 +08:00
|
|
|
|
private->startx = rx2;
|
|
|
|
|
private->starty = ry2;
|
2005-10-22 04:17:19 +08:00
|
|
|
|
|
|
|
|
|
gimp_rectangle_tool_motion (GIMP_TOOL (rectangle), &coords, 0, 0,
|
2006-03-29 01:55:52 +08:00
|
|
|
|
GIMP_TOOL (rectangle)->display);
|
2006-06-05 01:08:26 +08:00
|
|
|
|
|
|
|
|
|
g_signal_emit_by_name (rectangle, "rectangle-changed", NULL);
|
2005-10-22 04:17:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* we handle changes in aspect by treating them as movement of the bottom edge
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
gimp_rectangle_tool_notify_aspect (GimpRectangleOptions *options,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
GimpRectangleTool *rectangle)
|
|
|
|
|
{
|
2006-06-03 06:24:55 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
gint rx1, rx2, ry1, ry2;
|
|
|
|
|
GimpCoords coords;
|
|
|
|
|
gdouble aspect;
|
2006-09-15 01:11:24 +08:00
|
|
|
|
gdouble numerator, denominator;
|
2006-09-23 02:27:21 +08:00
|
|
|
|
gboolean fixed_aspect;
|
2006-06-03 06:24:55 +08:00
|
|
|
|
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rectangle);
|
2005-10-22 04:17:19 +08:00
|
|
|
|
|
2006-03-29 01:55:52 +08:00
|
|
|
|
if (! GIMP_TOOL (rectangle)->display)
|
2005-11-30 07:32:55 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2006-03-22 01:37:24 +08:00
|
|
|
|
g_object_get (options,
|
2006-09-15 01:11:24 +08:00
|
|
|
|
"aspect-numerator", &numerator,
|
|
|
|
|
"aspect-denominator", &denominator,
|
2006-09-23 02:27:21 +08:00
|
|
|
|
"fixed-aspect", &fixed_aspect,
|
2006-03-22 01:37:24 +08:00
|
|
|
|
NULL);
|
2006-09-23 02:27:21 +08:00
|
|
|
|
|
|
|
|
|
if (! fixed_aspect)
|
|
|
|
|
return;
|
|
|
|
|
|
2006-09-15 01:11:24 +08:00
|
|
|
|
aspect = numerator / denominator;
|
|
|
|
|
|
2005-10-22 04:17:19 +08:00
|
|
|
|
g_object_get (rectangle,
|
|
|
|
|
"x1", &rx1,
|
|
|
|
|
"y1", &ry1,
|
|
|
|
|
"x2", &rx2,
|
|
|
|
|
"y2", &ry2,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
coords.x = rx2;
|
2006-02-04 03:29:11 +08:00
|
|
|
|
coords.y = ry1 + (rx2 - rx1) / aspect;
|
2005-10-22 04:17:19 +08:00
|
|
|
|
|
|
|
|
|
g_object_set (rectangle,
|
|
|
|
|
"function", RECT_RESIZING_BOTTOM,
|
|
|
|
|
NULL);
|
2006-06-03 06:24:55 +08:00
|
|
|
|
private->startx = rx2;
|
|
|
|
|
private->starty = ry2;
|
2005-10-22 04:17:19 +08:00
|
|
|
|
|
|
|
|
|
gimp_rectangle_tool_motion (GIMP_TOOL (rectangle), &coords, 0, 0,
|
2006-03-29 01:55:52 +08:00
|
|
|
|
GIMP_TOOL (rectangle)->display);
|
2006-06-05 01:08:26 +08:00
|
|
|
|
|
|
|
|
|
g_signal_emit_by_name (rectangle, "rectangle-changed", NULL);
|
2005-10-22 04:17:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2006-03-25 17:38:59 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_rectangle_tool_notify_highlight (GimpRectangleOptions *options,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
GimpRectangleTool *rectangle)
|
|
|
|
|
{
|
2006-06-07 03:25:53 +08:00
|
|
|
|
GimpTool *tool = GIMP_TOOL (rectangle);
|
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
|
gboolean highlight;
|
2006-03-25 17:38:59 +08:00
|
|
|
|
|
2006-05-17 01:21:07 +08:00
|
|
|
|
if (! tool->display)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
shell = GIMP_DISPLAY_SHELL (tool->display->shell);
|
|
|
|
|
|
2006-03-25 17:38:59 +08:00
|
|
|
|
g_object_get (options, "highlight", &highlight, NULL);
|
|
|
|
|
|
|
|
|
|
if (highlight)
|
|
|
|
|
{
|
|
|
|
|
GdkRectangle rect;
|
2006-06-07 02:07:04 +08:00
|
|
|
|
gint x1, y1;
|
|
|
|
|
gint x2, y2;
|
|
|
|
|
|
|
|
|
|
g_object_get (rectangle,
|
2006-06-07 03:14:25 +08:00
|
|
|
|
"x1", &x1,
|
|
|
|
|
"y1", &y1,
|
|
|
|
|
"x2", &x2,
|
|
|
|
|
"y2", &y2,
|
|
|
|
|
NULL);
|
2006-03-25 17:38:59 +08:00
|
|
|
|
|
|
|
|
|
rect.x = x1;
|
|
|
|
|
rect.y = y1;
|
|
|
|
|
rect.width = x2 - x1;
|
|
|
|
|
rect.height = y2 - y1;
|
|
|
|
|
|
|
|
|
|
gimp_display_shell_set_highlight (shell, &rect);
|
|
|
|
|
}
|
|
|
|
|
else
|
2006-06-07 02:07:04 +08:00
|
|
|
|
{
|
|
|
|
|
gimp_display_shell_set_highlight (shell, NULL);
|
|
|
|
|
}
|
2006-03-25 17:38:59 +08:00
|
|
|
|
}
|
2006-03-26 21:50:13 +08:00
|
|
|
|
|
2006-06-07 05:06:06 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_rectangle_tool_notify_guide (GimpRectangleOptions *options,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
GimpRectangleTool *rectangle)
|
|
|
|
|
{
|
|
|
|
|
GimpTool *tool = GIMP_TOOL (rectangle);
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rectangle);
|
|
|
|
|
|
2006-06-07 06:24:36 +08:00
|
|
|
|
if (tool->display)
|
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (rectangle));
|
2006-06-07 05:06:06 +08:00
|
|
|
|
|
2006-06-07 06:24:36 +08:00
|
|
|
|
g_object_get (options,
|
|
|
|
|
"guide", &private->guide,
|
|
|
|
|
NULL);
|
2006-06-07 05:06:06 +08:00
|
|
|
|
|
2006-06-07 06:24:36 +08:00
|
|
|
|
if (tool->display)
|
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (rectangle));
|
2006-06-07 05:06:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-11 02:24:58 +08:00
|
|
|
|
gboolean
|
|
|
|
|
gimp_rectangle_tool_no_movement (GimpRectangleTool *rectangle)
|
|
|
|
|
{
|
|
|
|
|
gint pressx, pressy;
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rectangle);
|
|
|
|
|
|
|
|
|
|
g_object_get (rectangle,
|
|
|
|
|
"pressx", &pressx,
|
|
|
|
|
"pressy", &pressy,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
return (private->lastx == pressx && private->lasty == pressy);
|
|
|
|
|
}
|
2006-09-07 06:51:54 +08:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* check whether the coordinates extend outside the bounds of the image
|
|
|
|
|
* or active drawable, if it is constrained not to. If it does,
|
|
|
|
|
* caculate how much the current movement needs to be downscaled in
|
|
|
|
|
* order to obey the constraint.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gimp_rectangle_tool_constraint_violated (GimpRectangleTool *rectangle,
|
|
|
|
|
gint x1,
|
|
|
|
|
gint y1,
|
|
|
|
|
gint x2,
|
|
|
|
|
gint y2,
|
2006-09-15 05:51:35 +08:00
|
|
|
|
gdouble *alpha,
|
|
|
|
|
gdouble *beta)
|
2006-09-07 06:51:54 +08:00
|
|
|
|
{
|
|
|
|
|
GimpRectangleConstraint constraint = gimp_rectangle_tool_get_constraint (rectangle);
|
|
|
|
|
GimpTool *tool = GIMP_TOOL (rectangle);
|
|
|
|
|
GimpImage *image = tool->display->image;
|
|
|
|
|
gint min_x, min_y;
|
|
|
|
|
gint max_x, max_y;
|
|
|
|
|
|
2006-09-15 05:51:35 +08:00
|
|
|
|
*alpha = *beta = 1;
|
|
|
|
|
|
2006-09-07 06:51:54 +08:00
|
|
|
|
switch (constraint)
|
|
|
|
|
{
|
|
|
|
|
case GIMP_RECTANGLE_CONSTRAIN_NONE:
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
case GIMP_RECTANGLE_CONSTRAIN_IMAGE:
|
|
|
|
|
min_x = 0;
|
|
|
|
|
min_y = 0;
|
|
|
|
|
max_x = image->width;
|
|
|
|
|
max_y = image->height;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GIMP_RECTANGLE_CONSTRAIN_DRAWABLE:
|
|
|
|
|
{
|
|
|
|
|
GimpItem *item = GIMP_ITEM (tool->drawable);
|
|
|
|
|
|
|
|
|
|
gimp_item_offsets (item, &min_x, &min_y);
|
|
|
|
|
max_x = min_x + gimp_item_width (item);
|
|
|
|
|
max_y = min_y + gimp_item_height (item);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
g_warning ("Invalid rectangle constraint.\n");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (x1 < min_x)
|
|
|
|
|
{
|
|
|
|
|
gint rx1;
|
|
|
|
|
|
|
|
|
|
g_object_get (rectangle,
|
|
|
|
|
"x1", &rx1,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
*alpha = (rx1 - min_x) / (gdouble) (rx1 - x1);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (y1 < min_y)
|
|
|
|
|
{
|
|
|
|
|
gint ry1;
|
|
|
|
|
|
|
|
|
|
g_object_get (rectangle,
|
|
|
|
|
"y1", &ry1,
|
|
|
|
|
NULL);
|
|
|
|
|
|
2006-09-15 05:51:35 +08:00
|
|
|
|
*beta = (ry1 - min_y) / (gdouble) (ry1 - y1);
|
2006-09-07 06:51:54 +08:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (x2 > max_x)
|
|
|
|
|
{
|
|
|
|
|
gint rx2;
|
|
|
|
|
|
|
|
|
|
g_object_get (rectangle,
|
|
|
|
|
"x2", &rx2,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
*alpha = (max_x - rx2) / (gdouble) (x2 - rx2);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (y2 > max_y)
|
|
|
|
|
{
|
|
|
|
|
gint ry2;
|
|
|
|
|
|
|
|
|
|
g_object_get (rectangle,
|
|
|
|
|
"y2", &ry2,
|
|
|
|
|
NULL);
|
|
|
|
|
|
2006-09-15 05:51:35 +08:00
|
|
|
|
*beta = (max_y - ry2) / (gdouble) (y2 - ry2);
|
2006-09-07 06:51:54 +08:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|