2006-12-10 05:33:38 +08:00
|
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2005-03-03 02:18:19 +08:00
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
2007-11-24 17:09:26 +08:00
|
|
|
|
* Copyright (C) 2007 Martin Nordholts
|
2005-03-03 02:18:19 +08:00
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2005-03-03 02:18:19 +08:00
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2005-03-03 02:18:19 +08:00
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-01-18 06:28:01 +08:00
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-03-03 02:18:19 +08:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2006-11-05 06:39:37 +08:00
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
|
#include <gegl.h>
|
2005-03-03 02:18:19 +08:00
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
2007-03-09 21:00:01 +08:00
|
|
|
|
#include "libgimpmath/gimpmath.h"
|
2005-03-03 02:18:19 +08:00
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
|
|
#include "tools-types.h"
|
|
|
|
|
|
2007-09-02 04:01:38 +08:00
|
|
|
|
#include "core/gimp.h"
|
2005-03-03 02:18:19 +08:00
|
|
|
|
#include "core/gimpchannel.h"
|
2007-09-02 04:01:38 +08:00
|
|
|
|
#include "core/gimpcontext.h"
|
2006-09-24 04:45:06 +08:00
|
|
|
|
#include "core/gimpimage-crop.h"
|
2007-09-02 04:01:38 +08:00
|
|
|
|
#include "core/gimpimage.h"
|
2006-06-05 01:08:26 +08:00
|
|
|
|
#include "core/gimpmarshal.h"
|
2007-09-02 04:01:38 +08:00
|
|
|
|
#include "core/gimppickable.h"
|
|
|
|
|
#include "core/gimptoolinfo.h"
|
2006-08-08 19:51:04 +08:00
|
|
|
|
|
2005-03-03 02:18:19 +08:00
|
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
|
#include "display/gimpdisplayshell.h"
|
2008-07-11 04:19:17 +08:00
|
|
|
|
#include "display/gimpdisplayshell-scroll.h"
|
2005-03-03 02:18:19 +08:00
|
|
|
|
#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-11-05 03:21:15 +08:00
|
|
|
|
|
2006-06-05 01:08:26 +08:00
|
|
|
|
enum
|
|
|
|
|
{
|
2008-05-02 17:05:13 +08:00
|
|
|
|
RECTANGLE_CHANGE_COMPLETE,
|
2006-06-05 01:08:26 +08:00
|
|
|
|
LAST_SIGNAL
|
|
|
|
|
};
|
|
|
|
|
|
2005-03-03 02:18:19 +08:00
|
|
|
|
/* speed of key movement */
|
2006-11-06 16:16:31 +08:00
|
|
|
|
#define ARROW_VELOCITY 25
|
|
|
|
|
|
2007-11-04 22:10:56 +08:00
|
|
|
|
#define MAX_HANDLE_SIZE 50
|
2007-11-07 06:04:18 +08:00
|
|
|
|
#define MIN_HANDLE_SIZE 15
|
2007-11-04 22:10:56 +08:00
|
|
|
|
#define NARROW_MODE_HANDLE_SIZE 15
|
2007-11-07 06:04:18 +08:00
|
|
|
|
#define NARROW_MODE_THRESHOLD 45
|
2008-07-05 17:47:39 +08:00
|
|
|
|
#define CENTER_CROSS_SIZE 6
|
2007-11-04 22:10:56 +08:00
|
|
|
|
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2007-03-30 17:26:48 +08:00
|
|
|
|
#define SQRT5 2.236067977
|
|
|
|
|
|
2007-07-09 05:57:22 +08:00
|
|
|
|
typedef enum
|
|
|
|
|
{
|
|
|
|
|
CLAMPED_NONE = 0,
|
2007-10-26 04:28:23 +08:00
|
|
|
|
CLAMPED_LEFT = 1 << 0,
|
|
|
|
|
CLAMPED_RIGHT = 1 << 1,
|
|
|
|
|
CLAMPED_TOP = 1 << 2,
|
|
|
|
|
CLAMPED_BOTTOM = 1 << 3
|
2007-07-09 05:57:22 +08:00
|
|
|
|
} ClampedSide;
|
|
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
|
{
|
2007-07-11 13:09:50 +08:00
|
|
|
|
SIDE_TO_RESIZE_NONE,
|
|
|
|
|
SIDE_TO_RESIZE_LEFT,
|
|
|
|
|
SIDE_TO_RESIZE_RIGHT,
|
|
|
|
|
SIDE_TO_RESIZE_TOP,
|
|
|
|
|
SIDE_TO_RESIZE_BOTTOM,
|
|
|
|
|
SIDE_TO_RESIZE_LEFT_AND_RIGHT_SYMMETRICALLY,
|
|
|
|
|
SIDE_TO_RESIZE_TOP_AND_BOTTOM_SYMMETRICALLY,
|
2007-07-09 05:57:22 +08:00
|
|
|
|
} SideToResize;
|
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
2008-11-11 04:10:50 +08:00
|
|
|
|
#define FEQUAL(a,b) (fabs ((a) - (b)) < 0.0001)
|
|
|
|
|
#define PIXEL_FEQUAL(a,b) (fabs ((a) - (b)) < 0.5)
|
2008-04-24 13:55:59 +08:00
|
|
|
|
|
2006-06-05 19:18:43 +08:00
|
|
|
|
#define GIMP_RECTANGLE_TOOL_GET_PRIVATE(obj) \
|
2006-11-05 03:21:15 +08:00
|
|
|
|
(gimp_rectangle_tool_get_private (GIMP_RECTANGLE_TOOL (obj)))
|
2006-06-05 19:18:43 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
2008-08-28 20:54:14 +08:00
|
|
|
|
typedef struct _GimpRectangleToolPrivate GimpRectangleToolPrivate;
|
|
|
|
|
|
|
|
|
|
struct _GimpRectangleToolPrivate
|
2005-09-04 03:48:22 +08:00
|
|
|
|
{
|
2007-06-30 00:37:50 +08:00
|
|
|
|
/* The following members are "constants", that is, variables that are setup
|
|
|
|
|
* during gimp_rectangle_tool_button_press and then only read.
|
|
|
|
|
*/
|
|
|
|
|
|
2008-08-28 20:54:14 +08:00
|
|
|
|
/* Wether or not the rectangle currently being rubber-banded was
|
2007-12-13 05:11:56 +08:00
|
|
|
|
* created from scatch.
|
|
|
|
|
*/
|
|
|
|
|
gboolean is_new;
|
|
|
|
|
|
2007-07-09 05:57:22 +08:00
|
|
|
|
/* Holds the coordinate that should be used as the "other side" when
|
|
|
|
|
* fixed-center is turned off.
|
|
|
|
|
*/
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble other_side_x;
|
|
|
|
|
gdouble other_side_y;
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
2007-07-09 05:57:22 +08:00
|
|
|
|
/* Holds the coordinate to be used as center when fixed-center is used. */
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble center_x_on_fixed_center;
|
|
|
|
|
gdouble center_y_on_fixed_center;
|
|
|
|
|
|
2007-12-09 17:38:34 +08:00
|
|
|
|
/* True when the rectangle is being adjusted (moved or
|
|
|
|
|
* rubber-banded).
|
|
|
|
|
*/
|
|
|
|
|
gboolean rect_adjusting;
|
|
|
|
|
|
|
|
|
|
|
2007-06-30 00:37:50 +08:00
|
|
|
|
/* The rest of the members are internal state variables, that is, variables
|
|
|
|
|
* that might change during the manipulation session of the rectangle. Make
|
|
|
|
|
* sure these variables are in consistent states.
|
|
|
|
|
*/
|
|
|
|
|
|
2007-07-15 17:43:49 +08:00
|
|
|
|
/* Coordinates of upper left and lower right rectangle corners. */
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble x1, y1;
|
|
|
|
|
gdouble x2, y2;
|
|
|
|
|
|
|
|
|
|
/* Integer coordinats of upper left corner and size. We must
|
|
|
|
|
* calculate this separately from the gdouble ones because sometimes
|
|
|
|
|
* we don't want to affect the integer size (e.g. when moving the
|
|
|
|
|
* rectangle), but that will be the case if we always calculate the
|
|
|
|
|
* integer coordinates based on rounded values of the gdouble
|
|
|
|
|
* coordinates even if the gdouble width remains constant.
|
2008-03-08 21:14:32 +08:00
|
|
|
|
*
|
|
|
|
|
* TODO: Change the internal double-representation of the rectangle
|
|
|
|
|
* to x,y width,height instead of x1,y1 x2,y2. That way we don't
|
|
|
|
|
* need to keep a separate representation of the integer version of
|
|
|
|
|
* the rectangle; rounding width an height will yield consistant
|
|
|
|
|
* results and not depend on position of the rectangle.
|
2007-11-24 17:09:26 +08:00
|
|
|
|
*/
|
|
|
|
|
gint x1_int, y1_int;
|
|
|
|
|
gint width_int, height_int;
|
2006-06-01 03:45:38 +08:00
|
|
|
|
|
2007-07-15 17:43:49 +08:00
|
|
|
|
/* What modification state the rectangle is in. What corner are we resizing,
|
|
|
|
|
* or are we moving the rectangle? etc.
|
|
|
|
|
*/
|
|
|
|
|
guint function;
|
|
|
|
|
|
|
|
|
|
/* How to constrain the rectangle. */
|
|
|
|
|
GimpRectangleConstraint constraint;
|
2006-06-03 06:24:55 +08:00
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
/* What precision the rectangle will apear to have externally (it
|
|
|
|
|
* will always be double internally)
|
|
|
|
|
*/
|
|
|
|
|
GimpRectanglePrecision precision;
|
|
|
|
|
|
2007-07-15 17:43:49 +08:00
|
|
|
|
/* Previous coordinate applied to the rectangle. */
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble lastx;
|
|
|
|
|
gdouble lasty;
|
2006-06-03 06:24:55 +08:00
|
|
|
|
|
2007-07-15 17:43:49 +08:00
|
|
|
|
/* Width and height of corner handles. */
|
2007-10-27 05:07:45 +08:00
|
|
|
|
gint corner_handle_w;
|
|
|
|
|
gint corner_handle_h;
|
2006-06-05 04:34:46 +08:00
|
|
|
|
|
2007-07-15 17:43:49 +08:00
|
|
|
|
/* Width and height of side handles. */
|
2007-07-01 02:13:41 +08:00
|
|
|
|
gint top_and_bottom_handle_w;
|
|
|
|
|
gint left_and_right_handle_h;
|
|
|
|
|
|
2007-11-04 22:10:56 +08:00
|
|
|
|
/* Wether or not the rectangle is in a 'narrow situation' i.e. it is
|
|
|
|
|
* too small for reasonable sized handle to be inside. In this case
|
|
|
|
|
* we put handles on the outside.
|
|
|
|
|
*/
|
|
|
|
|
gboolean narrow_mode;
|
|
|
|
|
|
2008-04-08 02:57:32 +08:00
|
|
|
|
/* For what scale the handle sizes is calculated. We must cache this
|
|
|
|
|
* so that we can differentiate between when the tool is resumed
|
|
|
|
|
* because of zoom level just has changed or because the highlight
|
|
|
|
|
* has just been updated.
|
2007-07-15 17:43:49 +08:00
|
|
|
|
*/
|
|
|
|
|
gdouble scale_x_used_for_handle_size_calculations;
|
|
|
|
|
gdouble scale_y_used_for_handle_size_calculations;
|
|
|
|
|
|
|
|
|
|
/* For saving in case of cancelation. */
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble saved_x1;
|
|
|
|
|
gdouble saved_y1;
|
|
|
|
|
gdouble saved_x2;
|
|
|
|
|
gdouble saved_y2;
|
2006-06-07 05:06:06 +08:00
|
|
|
|
|
2007-01-24 16:40:24 +08:00
|
|
|
|
gint suppress_updates;
|
|
|
|
|
|
2007-07-15 17:43:49 +08:00
|
|
|
|
/* Synced with options->guide, only exists for drawing. */
|
|
|
|
|
GimpRectangleGuide guide;
|
2008-08-28 20:54:14 +08:00
|
|
|
|
};
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
|
|
|
|
|
2007-10-26 04:43:51 +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 *
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_get_private (GimpRectangleTool *rect_tool);
|
2007-10-26 04:43:51 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
static void gimp_rectangle_tool_start (GimpRectangleTool *rect_tool,
|
|
|
|
|
GimpDisplay *display);
|
|
|
|
|
static void gimp_rectangle_tool_halt (GimpRectangleTool *rect_tool);
|
|
|
|
|
static void gimp_rectangle_tool_draw_guides (GimpDrawTool *draw_tool);
|
2007-10-26 04:43:51 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
static void gimp_rectangle_tool_update_options (GimpRectangleTool *rect_tool,
|
2007-10-26 04:43:51 +08:00
|
|
|
|
GimpDisplay *display);
|
|
|
|
|
|
|
|
|
|
static void gimp_rectangle_tool_options_notify (GimpRectangleOptions *options,
|
|
|
|
|
GParamSpec *pspec,
|
2007-11-04 22:47:48 +08:00
|
|
|
|
GimpRectangleTool *rect_tool);
|
2007-10-26 04:43:51 +08:00
|
|
|
|
static void gimp_rectangle_tool_shell_scrolled (GimpDisplayShell *options,
|
2007-11-04 22:47:48 +08:00
|
|
|
|
GimpRectangleTool *rect_tool);
|
2007-10-26 04:43:51 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
static void gimp_rectangle_tool_check_function (GimpRectangleTool *rect_tool);
|
2007-10-26 04:43:51 +08:00
|
|
|
|
|
2008-05-02 17:05:13 +08:00
|
|
|
|
static void gimp_rectangle_tool_rectangle_change_complete
|
|
|
|
|
(GimpRectangleTool *rect_tool);
|
2007-10-26 04:43:51 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
static void gimp_rectangle_tool_auto_shrink (GimpRectangleTool *rect_tool);
|
2007-10-26 04:43:51 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
static gboolean gimp_rectangle_tool_coord_outside (GimpRectangleTool *rect_tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
|
const GimpCoords *coords);
|
2007-10-27 04:58:08 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
static gboolean gimp_rectangle_tool_coord_on_handle (GimpRectangleTool *rect_tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
|
const GimpCoords *coords,
|
2007-10-27 04:58:08 +08:00
|
|
|
|
GtkAnchorType anchor);
|
2007-10-26 04:43:51 +08:00
|
|
|
|
|
|
|
|
|
static GtkAnchorType gimp_rectangle_tool_get_anchor (GimpRectangleToolPrivate *private);
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
static void gimp_rectangle_tool_update_highlight (GimpRectangleTool *rect_tool);
|
2007-10-26 04:43:51 +08:00
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
static gboolean gimp_rectangle_tool_rect_rubber_banding_func
|
|
|
|
|
(GimpRectangleTool *rect_tool);
|
2007-11-06 04:17:56 +08:00
|
|
|
|
static gboolean gimp_rectangle_tool_rect_adjusting_func (GimpRectangleTool *rect_tool);
|
2007-11-05 05:26:01 +08:00
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
static void gimp_rectangle_tool_update_handle_sizes (GimpRectangleTool *rect_tool);
|
2007-10-26 04:43:51 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
static gboolean gimp_rectangle_tool_scale_has_changed (GimpRectangleTool *rect_tool);
|
2007-10-26 04:43:51 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
static void gimp_rectangle_tool_get_other_side (GimpRectangleTool *rect_tool,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble **other_x,
|
|
|
|
|
gdouble **other_y);
|
2007-11-04 22:47:48 +08:00
|
|
|
|
static void gimp_rectangle_tool_get_other_side_coord (GimpRectangleTool *rect_tool,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble *other_side_x,
|
|
|
|
|
gdouble *other_side_y);
|
2007-11-04 22:47:48 +08:00
|
|
|
|
static void gimp_rectangle_tool_set_other_side_coord (GimpRectangleTool *rect_tool,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble other_side_x,
|
|
|
|
|
gdouble other_side_y);
|
2007-10-26 04:43:51 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
static void gimp_rectangle_tool_apply_coord (GimpRectangleTool *rect_tool,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble coord_x,
|
|
|
|
|
gdouble coord_y);
|
|
|
|
|
static void gimp_rectangle_tool_setup_snap_offsets (GimpRectangleTool *rect_tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
|
const GimpCoords *coords);
|
2007-10-26 04:43:51 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
static void gimp_rectangle_tool_clamp (GimpRectangleTool *rect_tool,
|
2007-10-26 04:43:51 +08:00
|
|
|
|
ClampedSide *clamped_sides,
|
|
|
|
|
GimpRectangleConstraint constraint,
|
|
|
|
|
gboolean symmetrically);
|
2007-11-04 22:47:48 +08:00
|
|
|
|
static void gimp_rectangle_tool_clamp_width (GimpRectangleTool *rect_tool,
|
2007-10-26 04:43:51 +08:00
|
|
|
|
ClampedSide *clamped_sides,
|
|
|
|
|
GimpRectangleConstraint constraint,
|
|
|
|
|
gboolean symmetrically);
|
2007-11-04 22:47:48 +08:00
|
|
|
|
static void gimp_rectangle_tool_clamp_height (GimpRectangleTool *rect_tool,
|
2007-10-26 04:43:51 +08:00
|
|
|
|
ClampedSide *clamped_sides,
|
|
|
|
|
GimpRectangleConstraint constraint,
|
|
|
|
|
gboolean symmetrically);
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
static void gimp_rectangle_tool_keep_inside (GimpRectangleTool *rect_tool,
|
2007-10-26 04:43:51 +08:00
|
|
|
|
GimpRectangleConstraint constraint);
|
|
|
|
|
static void gimp_rectangle_tool_keep_inside_horizontally
|
2007-11-04 22:47:48 +08:00
|
|
|
|
(GimpRectangleTool *rect_tool,
|
2007-10-26 04:43:51 +08:00
|
|
|
|
GimpRectangleConstraint constraint);
|
|
|
|
|
static void gimp_rectangle_tool_keep_inside_vertically
|
2007-11-04 22:47:48 +08:00
|
|
|
|
(GimpRectangleTool *rect_tool,
|
2007-10-26 04:43:51 +08:00
|
|
|
|
GimpRectangleConstraint constraint);
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
static void gimp_rectangle_tool_apply_fixed_width (GimpRectangleTool *rect_tool,
|
2007-10-26 04:43:51 +08:00
|
|
|
|
GimpRectangleConstraint constraint,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble width);
|
2007-11-04 22:47:48 +08:00
|
|
|
|
static void gimp_rectangle_tool_apply_fixed_height (GimpRectangleTool *rect_tool,
|
2007-10-26 04:43:51 +08:00
|
|
|
|
GimpRectangleConstraint constraint,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble height);
|
2007-10-26 04:43:51 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
static void gimp_rectangle_tool_apply_aspect (GimpRectangleTool *rect_tool,
|
2007-10-26 04:43:51 +08:00
|
|
|
|
gdouble aspect,
|
|
|
|
|
gint clamped_sides);
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
static void gimp_rectangle_tool_update_with_coord (GimpRectangleTool *rect_tool,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble new_x,
|
|
|
|
|
gdouble new_y);
|
|
|
|
|
static void gimp_rectangle_tool_apply_fixed_rule (GimpRectangleTool *rect_tool);
|
2007-10-26 04:43:51 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
static void gimp_rectangle_tool_get_constraints (GimpRectangleTool *rect_tool,
|
2007-10-26 04:43:51 +08:00
|
|
|
|
gint *min_x,
|
|
|
|
|
gint *min_y,
|
|
|
|
|
gint *max_x,
|
|
|
|
|
gint *max_y,
|
|
|
|
|
GimpRectangleConstraint constraint);
|
|
|
|
|
|
|
|
|
|
static void gimp_rectangle_tool_handle_general_clamping
|
2007-11-04 22:47:48 +08:00
|
|
|
|
(GimpRectangleTool *rect_tool);
|
2007-11-24 17:09:26 +08:00
|
|
|
|
static void gimp_rectangle_tool_update_int_rect (GimpRectangleTool *rect_tool);
|
|
|
|
|
static void gimp_rectangle_tool_get_public_rect (GimpRectangleTool *rect_tool,
|
|
|
|
|
gdouble *pub_x1,
|
|
|
|
|
gdouble *pub_y1,
|
|
|
|
|
gdouble *pub_x2,
|
|
|
|
|
gdouble *pub_y2);
|
2008-03-09 18:40:42 +08:00
|
|
|
|
static void gimp_rectangle_tool_adjust_coord (GimpRectangleTool *rect_tool,
|
|
|
|
|
gdouble coord_x_input,
|
|
|
|
|
gdouble coord_y_input,
|
|
|
|
|
gdouble *coord_x_output,
|
|
|
|
|
gdouble *coord_y_output);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2006-11-05 03:21:15 +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-10-18 21:17:50 +08:00
|
|
|
|
if (! iface_type)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2006-10-18 21:17:50 +08:00
|
|
|
|
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)
|
|
|
|
|
{
|
2008-05-02 17:05:13 +08:00
|
|
|
|
gimp_rectangle_tool_signals[RECTANGLE_CHANGE_COMPLETE] =
|
|
|
|
|
g_signal_new ("rectangle-change-complete",
|
2006-06-05 01:08:26 +08:00
|
|
|
|
G_TYPE_FROM_INTERFACE (iface),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
2006-08-08 19:51:04 +08:00
|
|
|
|
G_STRUCT_OFFSET (GimpRectangleToolInterface,
|
2008-05-02 17:05:13 +08:00
|
|
|
|
rectangle_change_complete),
|
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 ("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-06-01 03:45:38 +08:00
|
|
|
|
g_object_interface_install_property (iface,
|
2006-12-14 05:49:09 +08:00
|
|
|
|
g_param_spec_enum ("constraint",
|
2006-09-07 06:51:54 +08:00
|
|
|
|
NULL, NULL,
|
2006-12-14 05:49:09 +08:00
|
|
|
|
GIMP_TYPE_RECTANGLE_CONSTRAINT,
|
2006-09-07 06:51:54 +08:00
|
|
|
|
GIMP_RECTANGLE_CONSTRAIN_NONE,
|
|
|
|
|
GIMP_PARAM_READWRITE));
|
2006-06-01 03:45:38 +08:00
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
g_object_interface_install_property (iface,
|
|
|
|
|
g_param_spec_enum ("precision",
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
GIMP_TYPE_RECTANGLE_PRECISION,
|
|
|
|
|
GIMP_RECTANGLE_PRECISION_INT,
|
|
|
|
|
GIMP_PARAM_READWRITE));
|
2008-10-27 01:39:55 +08:00
|
|
|
|
g_object_interface_install_property (iface,
|
|
|
|
|
g_param_spec_boolean ("narrow-mode",
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
FALSE,
|
|
|
|
|
GIMP_PARAM_READWRITE));
|
2007-11-24 17:09:26 +08:00
|
|
|
|
|
2008-05-02 17:05:13 +08:00
|
|
|
|
iface->execute = NULL;
|
|
|
|
|
iface->cancel = NULL;
|
|
|
|
|
iface->rectangle_change_complete = NULL;
|
2006-06-05 01:08:26 +08:00
|
|
|
|
|
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)
|
|
|
|
|
{
|
2007-05-23 21:49:06 +08:00
|
|
|
|
g_slice_free (GimpRectangleToolPrivate, private);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2007-05-23 21:49:06 +08:00
|
|
|
|
private = g_slice_new0 (GimpRectangleToolPrivate);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-09 17:38:34 +08:00
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_init:
|
|
|
|
|
* @rect_tool:
|
|
|
|
|
*
|
|
|
|
|
* Initializes the GimpRectangleTool.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
gimp_rectangle_tool_init (GimpRectangleTool *rect_tool)
|
|
|
|
|
{
|
2008-04-08 02:25:18 +08:00
|
|
|
|
/* No need to initialize anything yet. */
|
2007-12-09 17:38:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
/**
|
|
|
|
|
* 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_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");
|
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");
|
2007-11-24 17:09:26 +08:00
|
|
|
|
g_object_class_override_property (klass,
|
|
|
|
|
GIMP_RECTANGLE_TOOL_PROP_PRECISION,
|
|
|
|
|
"precision");
|
2008-10-27 01:39:55 +08:00
|
|
|
|
g_object_class_override_property (klass,
|
|
|
|
|
GIMP_RECTANGLE_TOOL_PROP_NARROW_MODE,
|
|
|
|
|
"narrow-mode");
|
2005-09-04 03:48:22 +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
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
2007-09-23 02:20:29 +08:00
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
gimp_rectangle_tool_clamp (tool,
|
|
|
|
|
NULL,
|
|
|
|
|
constraint,
|
|
|
|
|
FALSE);
|
2007-09-23 02:20:29 +08:00
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
gimp_rectangle_tool_update_highlight (tool);
|
|
|
|
|
gimp_rectangle_tool_update_handle_sizes (tool);
|
2007-09-23 02:20:29 +08:00
|
|
|
|
|
2008-05-02 17:05:13 +08:00
|
|
|
|
gimp_rectangle_tool_rectangle_change_complete (tool);
|
2007-09-23 02:20:29 +08:00
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
2007-09-23 02:20:29 +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
|
|
|
|
}
|
|
|
|
|
|
2007-09-02 04:01:38 +08:00
|
|
|
|
/**
|
2007-10-31 18:36:03 +08:00
|
|
|
|
* gimp_rectangle_tool_pending_size_set:
|
2007-09-02 04:01:38 +08:00
|
|
|
|
* @width_property: Option property to set to pending rectangle width.
|
|
|
|
|
* @height_property: Option property to set to pending rectangle height.
|
|
|
|
|
*
|
|
|
|
|
* Sets specified rectangle tool options properties to the width and
|
|
|
|
|
* height of the current pending rectangle.
|
|
|
|
|
*/
|
|
|
|
|
void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_pending_size_set (GimpRectangleTool *rect_tool,
|
2007-09-02 04:01:38 +08:00
|
|
|
|
GObject *object,
|
|
|
|
|
const gchar *width_property,
|
|
|
|
|
const gchar *height_property)
|
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (rect_tool));
|
2007-09-02 04:01:38 +08:00
|
|
|
|
g_return_if_fail (width_property != NULL);
|
|
|
|
|
g_return_if_fail (height_property != NULL);
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
private = gimp_rectangle_tool_get_private (rect_tool);
|
2007-09-02 04:01:38 +08:00
|
|
|
|
|
|
|
|
|
g_object_set (object,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
width_property, MAX (private->x2 - private->x1, 1.0),
|
|
|
|
|
height_property, MAX (private->y2 - private->y1, 1.0),
|
2007-09-02 04:01:38 +08:00
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2007-10-31 18:36:03 +08:00
|
|
|
|
* gimp_rectangle_tool_constraint_size_set:
|
2007-09-02 04:01:38 +08:00
|
|
|
|
* @width_property: Option property to set to current constraint width.
|
|
|
|
|
* @height_property: Option property to set to current constraint height.
|
|
|
|
|
*
|
|
|
|
|
* Sets specified rectangle tool options properties to the width and
|
|
|
|
|
* height of the current contraint size.
|
|
|
|
|
*/
|
|
|
|
|
void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_constraint_size_set (GimpRectangleTool *rect_tool,
|
2007-09-02 04:01:38 +08:00
|
|
|
|
GObject *object,
|
|
|
|
|
const gchar *width_property,
|
|
|
|
|
const gchar *height_property)
|
|
|
|
|
{
|
2007-10-31 18:36:03 +08:00
|
|
|
|
GimpTool *tool;
|
|
|
|
|
GimpContext *context;
|
|
|
|
|
GimpImage *image;
|
|
|
|
|
gdouble width;
|
|
|
|
|
gdouble height;
|
2007-09-02 04:01:38 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (rect_tool));
|
2007-10-31 18:36:03 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
tool = GIMP_TOOL (rect_tool);
|
2007-10-31 18:36:03 +08:00
|
|
|
|
context = gimp_get_user_context (tool->tool_info->gimp);
|
|
|
|
|
image = gimp_context_get_image (context);
|
2007-09-02 04:01:38 +08:00
|
|
|
|
|
2007-10-31 18:36:03 +08:00
|
|
|
|
if (! image)
|
2007-09-02 04:01:38 +08:00
|
|
|
|
{
|
|
|
|
|
width = 1.0;
|
|
|
|
|
height = 1.0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GimpRectangleConstraint constraint;
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
constraint = gimp_rectangle_tool_get_constraint (rect_tool);
|
2007-09-02 04:01:38 +08:00
|
|
|
|
|
|
|
|
|
switch (constraint)
|
|
|
|
|
{
|
|
|
|
|
case GIMP_RECTANGLE_CONSTRAIN_DRAWABLE:
|
|
|
|
|
{
|
|
|
|
|
GimpItem *item = GIMP_ITEM (gimp_image_get_active_layer (image));
|
|
|
|
|
|
2007-10-31 18:36:03 +08:00
|
|
|
|
if (! item)
|
2007-09-02 04:01:38 +08:00
|
|
|
|
{
|
|
|
|
|
width = 1.0;
|
|
|
|
|
height = 1.0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2008-11-03 08:09:01 +08:00
|
|
|
|
width = gimp_item_get_width (item);
|
|
|
|
|
height = gimp_item_get_height (item);
|
2007-09-02 04:01:38 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GIMP_RECTANGLE_CONSTRAIN_IMAGE:
|
|
|
|
|
default:
|
|
|
|
|
{
|
2007-12-26 00:21:40 +08:00
|
|
|
|
width = gimp_image_get_width (image);
|
|
|
|
|
height = gimp_image_get_height (image);
|
2007-09-02 04:01:38 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_set (object,
|
|
|
|
|
width_property, width,
|
|
|
|
|
height_property, height,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-13 05:11:56 +08:00
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_rectangle_is_new:
|
|
|
|
|
* @rect_tool:
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the user is creating a new rectangle from
|
|
|
|
|
* scratch, %FALSE if modifying n previously existing rectangle. This
|
|
|
|
|
* function is only meaningful in _motion and _button_release.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gimp_rectangle_tool_rectangle_is_new (GimpRectangleTool *rect_tool)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_RECTANGLE_TOOL (rect_tool), FALSE);
|
|
|
|
|
|
|
|
|
|
return GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool)->is_new;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_point_in_rectangle:
|
|
|
|
|
* @rect_tool:
|
|
|
|
|
* @x: X-coord of point to test (in image coordinates)
|
|
|
|
|
* @y: Y-coord of point to test (in image coordinates)
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the passed point was within the rectangle
|
|
|
|
|
**/
|
|
|
|
|
gboolean
|
|
|
|
|
gimp_rectangle_tool_point_in_rectangle (GimpRectangleTool *rect_tool,
|
|
|
|
|
gdouble x,
|
|
|
|
|
gdouble y)
|
|
|
|
|
{
|
|
|
|
|
gboolean inside = FALSE;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_RECTANGLE_TOOL (rect_tool), FALSE);
|
|
|
|
|
|
|
|
|
|
if (GIMP_TOOL (rect_tool)->display)
|
|
|
|
|
{
|
|
|
|
|
gdouble pub_x1, pub_y1, pub_x2, pub_y2;
|
|
|
|
|
|
|
|
|
|
gimp_rectangle_tool_get_public_rect (rect_tool,
|
|
|
|
|
&pub_x1, &pub_y1, &pub_x2, &pub_y2);
|
|
|
|
|
|
|
|
|
|
inside = x >= pub_x1 && x <= pub_x2 &&
|
|
|
|
|
y >= pub_y1 && y <= pub_y2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return inside;
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-28 00:21:03 +08:00
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_frame_item:
|
|
|
|
|
* @rect_tool: a #GimpRectangleTool interface
|
|
|
|
|
* @item: a #GimpItem attached to the image on which a
|
|
|
|
|
* rectangle is being shown.
|
|
|
|
|
*
|
|
|
|
|
* Convenience function to set the corners of the rectangle to
|
|
|
|
|
* match the bounds of the specified item. The rectangle interface
|
|
|
|
|
* must be active (i.e., showing a rectangle), and the item must be
|
|
|
|
|
* attached to the image on which the rectangle is active.
|
|
|
|
|
**/
|
|
|
|
|
void
|
|
|
|
|
gimp_rectangle_tool_frame_item (GimpRectangleTool *rect_tool,
|
|
|
|
|
GimpItem *item)
|
|
|
|
|
{
|
|
|
|
|
GimpDisplay *display = GIMP_TOOL (rect_tool)->display;
|
|
|
|
|
gint offset_x;
|
|
|
|
|
gint offset_y;
|
|
|
|
|
gint width;
|
|
|
|
|
gint height;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_ITEM (item));
|
|
|
|
|
g_return_if_fail (gimp_item_is_attached (item));
|
|
|
|
|
g_return_if_fail (display != NULL);
|
2008-12-28 08:09:33 +08:00
|
|
|
|
g_return_if_fail (display->image == gimp_item_get_image (item));
|
2008-10-28 00:21:03 +08:00
|
|
|
|
|
2008-11-03 08:09:01 +08:00
|
|
|
|
width = gimp_item_get_width (item);
|
|
|
|
|
height = gimp_item_get_height (item);
|
2008-10-28 00:21:03 +08:00
|
|
|
|
|
2008-11-03 07:03:29 +08:00
|
|
|
|
gimp_item_get_offset (item, &offset_x, &offset_y);
|
2008-10-28 00:21:03 +08:00
|
|
|
|
|
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (rect_tool));
|
|
|
|
|
|
|
|
|
|
gimp_rectangle_tool_set_function (rect_tool,
|
|
|
|
|
GIMP_RECTANGLE_TOOL_CREATING);
|
|
|
|
|
|
|
|
|
|
g_object_set (rect_tool,
|
|
|
|
|
"x1", offset_x,
|
|
|
|
|
"y1", offset_y,
|
|
|
|
|
"x2", offset_x + width,
|
|
|
|
|
"y2", offset_y + height,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
/* kludge to force handle sizes to update. This call may be
|
|
|
|
|
* harmful if this function is ever moved out of the text tool code.
|
|
|
|
|
*/
|
|
|
|
|
gimp_rectangle_tool_set_constraint (rect_tool,
|
|
|
|
|
GIMP_RECTANGLE_CONSTRAIN_NONE);
|
|
|
|
|
|
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (rect_tool));
|
|
|
|
|
}
|
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
void
|
|
|
|
|
gimp_rectangle_tool_set_property (GObject *object,
|
|
|
|
|
guint property_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
GimpRectangleTool *rect_tool = GIMP_RECTANGLE_TOOL (object);
|
2006-09-24 05:22:33 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
|
{
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_X1:
|
2006-09-24 05:22:33 +08:00
|
|
|
|
private->x1 = g_value_get_int (value);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
break;
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_Y1:
|
2006-09-24 05:22:33 +08:00
|
|
|
|
private->y1 = g_value_get_int (value);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
break;
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_X2:
|
2006-09-24 05:22:33 +08:00
|
|
|
|
private->x2 = g_value_get_int (value);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
break;
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_Y2:
|
2006-09-24 05:22:33 +08:00
|
|
|
|
private->y2 = g_value_get_int (value);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
break;
|
2006-09-07 06:51:54 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_CONSTRAINT:
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_set_constraint (rect_tool, g_value_get_enum (value));
|
2006-06-01 03:45:38 +08:00
|
|
|
|
break;
|
2007-11-24 17:09:26 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_PRECISION:
|
|
|
|
|
private->precision = g_value_get_enum (value);
|
|
|
|
|
break;
|
2008-10-27 01:39:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_NARROW_MODE:
|
|
|
|
|
private->narrow_mode = g_value_get_boolean (value);
|
|
|
|
|
break;
|
2007-10-31 18:36:03 +08:00
|
|
|
|
|
2005-09-04 03:48:22 +08:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-12-07 04:55:10 +08:00
|
|
|
|
|
|
|
|
|
gimp_rectangle_tool_update_int_rect (rect_tool);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gimp_rectangle_tool_get_property (GObject *object,
|
|
|
|
|
guint property_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
GimpRectangleTool *rect_tool = GIMP_RECTANGLE_TOOL (object);
|
2006-09-24 05:22:33 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
|
{
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_X1:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
g_value_set_int (value, private->x1_int);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
break;
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_Y1:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
g_value_set_int (value, private->y1_int);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
break;
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_X2:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
g_value_set_int (value, private->x1_int + private->width_int);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
break;
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_Y2:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
g_value_set_int (value, private->y1_int + private->height_int);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
break;
|
2006-09-07 06:51:54 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_CONSTRAINT:
|
2007-11-04 22:47:48 +08:00
|
|
|
|
g_value_set_enum (value, gimp_rectangle_tool_get_constraint (rect_tool));
|
2006-06-01 03:45:38 +08:00
|
|
|
|
break;
|
2007-11-24 17:09:26 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_PRECISION:
|
|
|
|
|
g_value_set_enum (value, private->precision);
|
|
|
|
|
break;
|
2008-10-27 01:39:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_PROP_NARROW_MODE:
|
|
|
|
|
g_value_set_boolean (value, private->narrow_mode);
|
|
|
|
|
break;
|
2007-10-31 18:36:03 +08:00
|
|
|
|
|
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)
|
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
GimpRectangleTool *rect_tool = GIMP_RECTANGLE_TOOL (object);
|
2006-11-05 22:11:34 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
GimpRectangleOptions *options;
|
2005-03-09 07:17:19 +08:00
|
|
|
|
|
2006-11-05 22:11:34 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (object);
|
|
|
|
|
options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (object);
|
2005-03-09 07:17:19 +08:00
|
|
|
|
|
2006-06-07 06:24:36 +08:00
|
|
|
|
g_object_get (options,
|
2006-09-27 04:55:40 +08:00
|
|
|
|
"guide", &private->guide,
|
2006-06-07 06:24:36 +08:00
|
|
|
|
NULL);
|
2005-03-09 07:17:19 +08:00
|
|
|
|
|
2006-11-05 22:11:34 +08:00
|
|
|
|
g_signal_connect_object (options, "notify",
|
|
|
|
|
G_CALLBACK (gimp_rectangle_tool_options_notify),
|
2007-11-04 22:47:48 +08:00
|
|
|
|
rect_tool, 0);
|
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)
|
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
GimpRectangleTool *rect_tool = GIMP_RECTANGLE_TOOL (tool);
|
2006-05-24 01:37:18 +08:00
|
|
|
|
|
|
|
|
|
switch (action)
|
|
|
|
|
{
|
|
|
|
|
case GIMP_TOOL_ACTION_PAUSE:
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GIMP_TOOL_ACTION_RESUME:
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_update_highlight (rect_tool);
|
2007-07-15 17:43:49 +08:00
|
|
|
|
|
|
|
|
|
/* When highlightning is on, the shell gets paused/unpaused which means we
|
|
|
|
|
* will get here, but we only want to recalculate handle sizes when the
|
|
|
|
|
* zoom has changed.
|
|
|
|
|
*/
|
2007-11-04 22:47:48 +08:00
|
|
|
|
if (gimp_rectangle_tool_scale_has_changed (rect_tool))
|
2007-12-15 01:22:46 +08:00
|
|
|
|
gimp_rectangle_tool_update_handle_sizes (rect_tool);
|
2007-07-15 17:43:49 +08:00
|
|
|
|
|
2006-05-24 01:37:18 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GIMP_TOOL_ACTION_HALT:
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_halt (rect_tool);
|
2006-05-24 01:37:18 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
void
|
2008-11-01 23:17:36 +08:00
|
|
|
|
gimp_rectangle_tool_button_press (GimpTool *tool,
|
|
|
|
|
const GimpCoords *coords,
|
|
|
|
|
guint32 time,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GimpDisplay *display)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
GimpRectangleTool *rect_tool;
|
2007-04-01 00:38:55 +08:00
|
|
|
|
GimpDrawTool *draw_tool;
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
GimpRectangleOptions *options;
|
|
|
|
|
GimpRectangleOptionsPrivate *options_private;
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble snapped_x, snapped_y;
|
2007-04-01 00:38:55 +08:00
|
|
|
|
gint snap_x, snap_y;
|
2006-06-11 00:49:07 +08:00
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (tool));
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
rect_tool = GIMP_RECTANGLE_TOOL (tool);
|
2007-04-01 00:38:55 +08:00
|
|
|
|
draw_tool = GIMP_DRAW_TOOL (tool);
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
|
|
|
|
options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (tool);
|
|
|
|
|
options_private = GIMP_RECTANGLE_OPTIONS_GET_PRIVATE (options);
|
2006-11-05 22:11:34 +08:00
|
|
|
|
|
2007-04-01 00:38:55 +08:00
|
|
|
|
gimp_draw_tool_pause (draw_tool);
|
2006-11-05 03:21:15 +08:00
|
|
|
|
|
2008-05-11 03:19:47 +08:00
|
|
|
|
gimp_tool_control_activate (tool->control);
|
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
if (display != tool->display)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
|
|
|
|
if (gimp_draw_tool_is_active (draw_tool))
|
2007-08-18 14:59:02 +08:00
|
|
|
|
{
|
2009-10-06 01:58:03 +08:00
|
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (draw_tool->display);
|
2008-04-08 02:25:18 +08:00
|
|
|
|
|
2009-10-06 01:58:03 +08:00
|
|
|
|
gimp_display_shell_set_highlight (shell, NULL);
|
2007-08-18 14:59:02 +08:00
|
|
|
|
gimp_draw_tool_stop (draw_tool);
|
|
|
|
|
}
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2008-04-08 02:25:18 +08:00
|
|
|
|
gimp_rectangle_tool_set_function (rect_tool,
|
|
|
|
|
GIMP_RECTANGLE_TOOL_CREATING);
|
2006-11-16 04:45:43 +08:00
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
private->x1 = private->x2 = coords->x;
|
|
|
|
|
private->y1 = private->y2 = coords->y;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_start (rect_tool, display);
|
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 */
|
2006-11-05 03:21:15 +08:00
|
|
|
|
private->saved_x1 = private->x1;
|
|
|
|
|
private->saved_y1 = private->y1;
|
|
|
|
|
private->saved_x2 = private->x2;
|
|
|
|
|
private->saved_y2 = private->y2;
|
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gimp_rectangle_tool_setup_snap_offsets (rect_tool,
|
|
|
|
|
coords);
|
2007-07-15 17:43:49 +08:00
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gimp_tool_control_get_snap_offsets (tool->control,
|
|
|
|
|
&snap_x, &snap_y, NULL, NULL);
|
2006-11-05 03:21:15 +08:00
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
snapped_x = coords->x + snap_x;
|
|
|
|
|
snapped_y = coords->y + snap_y;
|
2006-11-05 03:21:15 +08:00
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
private->lastx = snapped_x;
|
|
|
|
|
private->lasty = snapped_y;
|
2006-11-05 03:21:15 +08:00
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
if (private->function == GIMP_RECTANGLE_TOOL_CREATING)
|
2007-11-24 17:09:26 +08:00
|
|
|
|
{
|
2007-12-13 05:11:56 +08:00
|
|
|
|
/* Remember that this rectangle was created from scratch. */
|
|
|
|
|
private->is_new = TRUE;
|
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
private->x1 = private->x2 = snapped_x;
|
|
|
|
|
private->y1 = private->y2 = snapped_y;
|
2006-11-05 03:21:15 +08:00
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
gimp_rectangle_tool_update_handle_sizes (rect_tool);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2008-10-27 04:05:11 +08:00
|
|
|
|
/* Created rectangles should not be started in narrow-mode */
|
2008-04-08 02:57:32 +08:00
|
|
|
|
private->narrow_mode = FALSE;
|
2006-11-05 03:21:15 +08:00
|
|
|
|
|
2008-04-08 02:25:18 +08:00
|
|
|
|
/* If the rectangle is being modified we want the center on
|
|
|
|
|
* fixed_center to be at the center of the currently existing
|
|
|
|
|
* rectangle, otherwise we want the point where the user clicked
|
|
|
|
|
* to be the center on fixed_center.
|
2007-11-24 17:09:26 +08:00
|
|
|
|
*/
|
|
|
|
|
private->center_x_on_fixed_center = snapped_x;
|
|
|
|
|
private->center_y_on_fixed_center = snapped_y;
|
2006-11-05 03:21:15 +08:00
|
|
|
|
|
2008-04-08 02:25:18 +08:00
|
|
|
|
/* When the user toggles modifier keys, we want to keep track of
|
|
|
|
|
* what coordinates the "other side" should have. If we are
|
|
|
|
|
* creating a rectangle, use the current mouse coordinates as
|
|
|
|
|
* the coordinate of the "other side", otherwise use the
|
|
|
|
|
* immidiate "other side" for that.
|
2007-11-24 17:09:26 +08:00
|
|
|
|
*/
|
|
|
|
|
private->other_side_x = snapped_x;
|
|
|
|
|
private->other_side_y = snapped_y;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2007-05-02 17:14:35 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2007-12-13 05:11:56 +08:00
|
|
|
|
/* This rectangle was not created from scratch. */
|
|
|
|
|
private->is_new = FALSE;
|
|
|
|
|
|
2007-11-11 15:44:17 +08:00
|
|
|
|
private->center_x_on_fixed_center = (private->x1 + private->x2) / 2;
|
|
|
|
|
private->center_y_on_fixed_center = (private->y1 + private->y2) / 2;
|
2007-06-30 00:37:50 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_get_other_side_coord (rect_tool,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
&private->other_side_x,
|
|
|
|
|
&private->other_side_y);
|
2007-06-30 00:37:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gimp_rectangle_tool_update_int_rect (rect_tool);
|
|
|
|
|
|
2007-11-05 05:26:01 +08:00
|
|
|
|
/* Is the rectangle being rubber-banded? */
|
2007-11-06 04:17:56 +08:00
|
|
|
|
private->rect_adjusting = gimp_rectangle_tool_rect_adjusting_func (rect_tool);
|
2007-11-05 05:26:01 +08:00
|
|
|
|
|
|
|
|
|
gimp_rectangle_tool_update_highlight (rect_tool);
|
|
|
|
|
|
2007-04-01 00:38:55 +08:00
|
|
|
|
gimp_draw_tool_resume (draw_tool);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
void
|
2007-02-28 02:55:12 +08:00
|
|
|
|
gimp_rectangle_tool_button_release (GimpTool *tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
|
const GimpCoords *coords,
|
2007-02-28 02:55:12 +08:00
|
|
|
|
guint32 time,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GimpButtonReleaseType release_type,
|
|
|
|
|
GimpDisplay *display)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
GimpRectangleTool *rect_tool;
|
2006-06-03 06:24:55 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
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));
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
rect_tool = GIMP_RECTANGLE_TOOL (tool);
|
2006-11-05 22:11:34 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
|
|
|
|
options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (tool);
|
2006-06-11 00:49:07 +08:00
|
|
|
|
|
2006-11-05 03:21:15 +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-06-03 06:24:55 +08:00
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
if (private->function == GIMP_RECTANGLE_TOOL_EXECUTING)
|
2006-03-29 01:55:52 +08:00
|
|
|
|
gimp_tool_pop_status (tool, display);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2007-03-10 23:27:47 +08:00
|
|
|
|
switch (release_type)
|
2006-06-05 04:34:46 +08:00
|
|
|
|
{
|
2007-03-10 23:27:47 +08:00
|
|
|
|
case GIMP_BUTTON_RELEASE_NORMAL:
|
2008-05-02 17:05:13 +08:00
|
|
|
|
gimp_rectangle_tool_rectangle_change_complete (rect_tool);
|
2007-03-10 23:27:47 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GIMP_BUTTON_RELEASE_CANCEL:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
private->x1 = private->saved_x1;
|
|
|
|
|
private->y1 = private->saved_y1;
|
|
|
|
|
private->x2 = private->saved_x2;
|
|
|
|
|
private->y2 = private->saved_y2;
|
2008-05-10 18:34:03 +08:00
|
|
|
|
gimp_rectangle_tool_update_int_rect (rect_tool);
|
2007-08-11 16:27:00 +08:00
|
|
|
|
|
2007-08-11 16:42:59 +08:00
|
|
|
|
/* If the first created rectangle was canceled, halt the tool */
|
2007-12-14 04:14:41 +08:00
|
|
|
|
if (gimp_rectangle_tool_rectangle_is_new (rect_tool))
|
|
|
|
|
{
|
|
|
|
|
gimp_rectangle_tool_halt (rect_tool);
|
|
|
|
|
}
|
2007-08-11 16:42:59 +08:00
|
|
|
|
|
2007-03-10 23:27:47 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GIMP_BUTTON_RELEASE_CLICK:
|
2007-07-14 04:49:32 +08:00
|
|
|
|
|
|
|
|
|
/* When a dead area is clicked, don't execute. */
|
2007-12-15 01:22:46 +08:00
|
|
|
|
if (private->function == GIMP_RECTANGLE_TOOL_DEAD)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (gimp_rectangle_tool_execute (rect_tool))
|
|
|
|
|
gimp_rectangle_tool_halt (rect_tool);
|
2007-03-10 23:27:47 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GIMP_BUTTON_RELEASE_NO_MOTION:
|
|
|
|
|
break;
|
2006-06-05 04:34:46 +08:00
|
|
|
|
}
|
2006-11-05 03:21:15 +08:00
|
|
|
|
|
2007-07-09 05:57:22 +08:00
|
|
|
|
/* We must update this. */
|
|
|
|
|
private->center_x_on_fixed_center = (private->x1 + private->x2) / 2;
|
|
|
|
|
private->center_y_on_fixed_center = (private->y1 + private->y2) / 2;
|
|
|
|
|
|
2006-11-05 03:21:15 +08:00
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control, 0, 0, 0, 0);
|
|
|
|
|
|
2007-11-05 05:26:01 +08:00
|
|
|
|
/* On button release, we are not rubber-banding the rectangle any longer. */
|
2007-11-06 04:17:56 +08:00
|
|
|
|
private->rect_adjusting = FALSE;
|
2007-11-05 05:26:01 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_update_highlight (rect_tool);
|
2007-12-15 01:22:46 +08:00
|
|
|
|
gimp_rectangle_tool_update_handle_sizes (rect_tool);
|
2008-05-10 18:25:23 +08:00
|
|
|
|
gimp_rectangle_tool_update_options (rect_tool, display);
|
2007-07-15 00:03:13 +08:00
|
|
|
|
|
2006-11-05 03:21:15 +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
|
2008-11-01 23:17:36 +08:00
|
|
|
|
gimp_rectangle_tool_motion (GimpTool *tool,
|
|
|
|
|
const GimpCoords *coords,
|
|
|
|
|
guint32 time,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GimpDisplay *display)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
GimpRectangleTool *rect_tool;
|
2007-04-01 00:38:55 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
GimpRectangleOptions *options;
|
|
|
|
|
GimpRectangleOptionsPrivate *options_private;
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble snapped_x;
|
|
|
|
|
gdouble snapped_y;
|
2007-04-01 00:38:55 +08:00
|
|
|
|
gint snap_x, snap_y;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (tool));
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
rect_tool = GIMP_RECTANGLE_TOOL (tool);
|
2007-04-01 00:38:55 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
|
|
|
|
options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (tool);
|
|
|
|
|
options_private = GIMP_RECTANGLE_OPTIONS_GET_PRIVATE (options);
|
2006-06-03 06:24:55 +08:00
|
|
|
|
|
2007-11-06 04:24:11 +08:00
|
|
|
|
/* Motion events should be ignored when we're just waiting for the
|
|
|
|
|
* button release event to execute or if the user has grabbed a dead
|
|
|
|
|
* area of the rectangle.
|
2006-06-07 03:25:53 +08:00
|
|
|
|
*/
|
2007-11-24 17:27:55 +08:00
|
|
|
|
if (private->function == GIMP_RECTANGLE_TOOL_EXECUTING ||
|
|
|
|
|
private->function == GIMP_RECTANGLE_TOOL_DEAD)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2007-07-09 05:57:22 +08:00
|
|
|
|
/* Handle snapping. */
|
2006-11-05 03:21:15 +08:00
|
|
|
|
gimp_tool_control_get_snap_offsets (tool->control,
|
|
|
|
|
&snap_x, &snap_y, NULL, NULL);
|
2007-11-24 17:09:26 +08:00
|
|
|
|
snapped_x = coords->x + snap_x;
|
|
|
|
|
snapped_y = coords->y + snap_y;
|
2006-11-05 03:50:13 +08:00
|
|
|
|
|
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
|
|
|
|
|
2007-01-27 06:21:20 +08:00
|
|
|
|
|
2007-07-09 05:57:22 +08:00
|
|
|
|
/* This is the core rectangle shape updating function: */
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_update_with_coord (rect_tool,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
snapped_x,
|
|
|
|
|
snapped_y);
|
2006-06-05 19:18:43 +08:00
|
|
|
|
|
2007-11-06 04:17:56 +08:00
|
|
|
|
/* Update the highlight, but only if it is not being adjusted. If it
|
|
|
|
|
* is not being adjusted, the highlight is not shown anyway.
|
2007-11-05 05:26:01 +08:00
|
|
|
|
*/
|
2007-11-06 04:17:56 +08:00
|
|
|
|
if (gimp_rectangle_tool_rect_adjusting_func (rect_tool))
|
2007-11-05 05:26:01 +08:00
|
|
|
|
gimp_rectangle_tool_update_highlight (rect_tool);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
if (private->function != GIMP_RECTANGLE_TOOL_MOVING &&
|
|
|
|
|
private->function != GIMP_RECTANGLE_TOOL_EXECUTING)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble pub_x1, pub_y1, pub_x2, pub_y2;
|
2008-08-28 20:54:14 +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
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gimp_rectangle_tool_get_public_rect (rect_tool,
|
|
|
|
|
&pub_x1, &pub_y1, &pub_x2, &pub_y2);
|
|
|
|
|
w = pub_x2 - pub_x1;
|
|
|
|
|
h = pub_y2 - pub_y1;
|
2006-08-14 22:17:18 +08:00
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
if (w > 0.0 && h > 0.0)
|
2008-05-29 12:27:19 +08:00
|
|
|
|
{
|
|
|
|
|
gchar *aspect_text;
|
|
|
|
|
|
2008-06-14 01:36:26 +08:00
|
|
|
|
aspect_text = g_strdup_printf (" (%.2f:1)", w / (gdouble) h);
|
2008-05-29 12:27:19 +08:00
|
|
|
|
|
|
|
|
|
gimp_tool_push_status_coords (tool, display,
|
2008-09-05 20:15:24 +08:00
|
|
|
|
GIMP_CURSOR_PRECISION_PIXEL_BORDER,
|
2008-06-13 03:24:27 +08:00
|
|
|
|
_("Rectangle: "),
|
|
|
|
|
w, " × ", h, aspect_text);
|
2008-05-29 12:27:19 +08:00
|
|
|
|
g_free (aspect_text);
|
|
|
|
|
}
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
if (private->function == GIMP_RECTANGLE_TOOL_CREATING)
|
2005-06-03 06:48:43 +08:00
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
GimpRectangleFunction function = GIMP_RECTANGLE_TOOL_CREATING;
|
2008-08-28 20:54:14 +08:00
|
|
|
|
gdouble dx = snapped_x - private->lastx;
|
|
|
|
|
gdouble dy = snapped_y - private->lasty;
|
2006-11-05 03:21:15 +08:00
|
|
|
|
|
2007-07-31 23:39:26 +08:00
|
|
|
|
/* When the user starts to move the cursor, set the current
|
|
|
|
|
* function to one of the corner-grabbed functions, depending on
|
|
|
|
|
* in what direction the user starts dragging the rectangle.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*/
|
|
|
|
|
if (dx < 0)
|
|
|
|
|
{
|
2008-08-28 20:54:14 +08:00
|
|
|
|
function = (dy < 0 ?
|
|
|
|
|
GIMP_RECTANGLE_TOOL_RESIZING_UPPER_LEFT :
|
|
|
|
|
GIMP_RECTANGLE_TOOL_RESIZING_LOWER_LEFT);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
}
|
|
|
|
|
else if (dx > 0)
|
|
|
|
|
{
|
2008-08-28 20:54:14 +08:00
|
|
|
|
function = (dy < 0 ?
|
|
|
|
|
GIMP_RECTANGLE_TOOL_RESIZING_UPPER_RIGHT :
|
|
|
|
|
GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
}
|
|
|
|
|
else if (dy < 0)
|
|
|
|
|
{
|
2008-08-28 20:54:14 +08:00
|
|
|
|
function = (dx < 0 ?
|
|
|
|
|
GIMP_RECTANGLE_TOOL_RESIZING_UPPER_LEFT :
|
|
|
|
|
GIMP_RECTANGLE_TOOL_RESIZING_UPPER_RIGHT);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
}
|
|
|
|
|
else if (dy > 0)
|
|
|
|
|
{
|
2008-08-28 20:54:14 +08:00
|
|
|
|
function = (dx < 0 ?
|
|
|
|
|
GIMP_RECTANGLE_TOOL_RESIZING_LOWER_LEFT :
|
|
|
|
|
GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
}
|
2007-02-28 21:08:09 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_set_function (rect_tool, function);
|
2007-08-05 18:52:38 +08:00
|
|
|
|
|
|
|
|
|
if (gimp_rectangle_options_fixed_rule_active (options,
|
|
|
|
|
GIMP_RECTANGLE_TOOL_FIXED_SIZE))
|
|
|
|
|
{
|
|
|
|
|
/* For fixed size, set the function to moving immediately since the
|
|
|
|
|
* rectangle can not be resized anyway.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* We fake a coord update to get the right size. */
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_update_with_coord (rect_tool,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
snapped_x,
|
|
|
|
|
snapped_y);
|
2007-08-05 18:52:38 +08:00
|
|
|
|
|
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
|
|
|
|
-(private->x2 - private->x1) / 2,
|
|
|
|
|
-(private->y2 - private->y1) / 2,
|
|
|
|
|
private->x2 - private->x1,
|
|
|
|
|
private->y2 - private->y1);
|
|
|
|
|
|
2008-04-08 02:25:18 +08:00
|
|
|
|
gimp_rectangle_tool_set_function (rect_tool,
|
|
|
|
|
GIMP_RECTANGLE_TOOL_MOVING);
|
2007-08-05 18:52:38 +08:00
|
|
|
|
}
|
2005-06-03 06:48:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_update_options (rect_tool, display);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
private->lastx = snapped_x;
|
|
|
|
|
private->lasty = snapped_y;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2005-03-03 02:18:19 +08:00
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-24 06:32:35 +08:00
|
|
|
|
void
|
|
|
|
|
gimp_rectangle_tool_active_modifier_key (GimpTool *tool,
|
|
|
|
|
GdkModifierType key,
|
|
|
|
|
gboolean press,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GimpDisplay *display)
|
|
|
|
|
{
|
2007-07-09 05:57:22 +08:00
|
|
|
|
GimpDrawTool *draw_tool;
|
2007-11-04 22:47:48 +08:00
|
|
|
|
GimpRectangleTool *rect_tool;
|
2007-04-01 00:38:55 +08:00
|
|
|
|
GimpRectangleOptions *options;
|
|
|
|
|
GimpRectangleOptionsPrivate *options_private;
|
2007-06-30 00:37:50 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2008-05-02 03:29:15 +08:00
|
|
|
|
gboolean button1_down;
|
2006-11-05 22:11:34 +08:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (tool));
|
|
|
|
|
|
2007-07-09 05:57:22 +08:00
|
|
|
|
draw_tool = GIMP_DRAW_TOOL (tool);
|
2007-11-04 22:47:48 +08:00
|
|
|
|
rect_tool = GIMP_RECTANGLE_TOOL (tool);
|
|
|
|
|
private = gimp_rectangle_tool_get_private (rect_tool);
|
2007-04-01 00:38:55 +08:00
|
|
|
|
options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (tool);
|
|
|
|
|
options_private = GIMP_RECTANGLE_OPTIONS_GET_PRIVATE (options);
|
2008-05-02 03:29:15 +08:00
|
|
|
|
button1_down = state & GDK_BUTTON1_MASK;
|
2006-09-24 06:32:35 +08:00
|
|
|
|
|
2007-07-09 05:57:22 +08:00
|
|
|
|
gimp_draw_tool_pause (draw_tool);
|
|
|
|
|
|
2006-09-24 06:32:35 +08:00
|
|
|
|
if (key == GDK_SHIFT_MASK)
|
|
|
|
|
{
|
2007-07-08 21:38:58 +08:00
|
|
|
|
/* Here we want to handle manualy when to update the rectangle, so we
|
|
|
|
|
* don't want gimp_rectangle_tool_options_notify to do anything.
|
|
|
|
|
*/
|
|
|
|
|
g_signal_handlers_block_by_func (options,
|
|
|
|
|
gimp_rectangle_tool_options_notify,
|
2007-11-04 22:47:48 +08:00
|
|
|
|
rect_tool);
|
2007-07-08 21:38:58 +08:00
|
|
|
|
|
2006-09-24 06:32:35 +08:00
|
|
|
|
g_object_set (options,
|
2007-08-05 04:20:44 +08:00
|
|
|
|
"fixed-rule-active", ! options_private->fixed_rule_active,
|
2006-09-24 06:32:35 +08:00
|
|
|
|
NULL);
|
2007-07-08 21:38:58 +08:00
|
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (options,
|
|
|
|
|
gimp_rectangle_tool_options_notify,
|
2007-11-04 22:47:48 +08:00
|
|
|
|
rect_tool);
|
2006-09-24 06:32:35 +08:00
|
|
|
|
|
2007-07-09 05:57:22 +08:00
|
|
|
|
/* Only change the shape if the mouse is still down (i.e. the user is
|
|
|
|
|
* still editing the rectangle.
|
2007-06-30 00:37:50 +08:00
|
|
|
|
*/
|
2008-05-02 03:29:15 +08:00
|
|
|
|
if (button1_down)
|
2007-06-30 00:37:50 +08:00
|
|
|
|
{
|
2007-08-05 04:20:44 +08:00
|
|
|
|
if (!options_private->fixed_rule_active)
|
|
|
|
|
{
|
|
|
|
|
/* Reset anchor point */
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_set_other_side_coord (rect_tool,
|
2007-08-05 04:20:44 +08:00
|
|
|
|
private->other_side_x,
|
|
|
|
|
private->other_side_y);
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_update_with_coord (rect_tool,
|
2007-07-09 05:57:22 +08:00
|
|
|
|
private->lastx,
|
|
|
|
|
private->lasty);
|
2007-06-30 00:37:50 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_update_highlight (rect_tool);
|
2007-06-30 00:37:50 +08:00
|
|
|
|
}
|
2007-07-09 05:57:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (key == GDK_CONTROL_MASK)
|
|
|
|
|
{
|
2006-09-24 06:32:35 +08:00
|
|
|
|
g_object_set (options,
|
2007-04-01 00:38:55 +08:00
|
|
|
|
"fixed-center", ! options_private->fixed_center,
|
2006-09-24 06:32:35 +08:00
|
|
|
|
NULL);
|
|
|
|
|
|
2007-04-01 00:38:55 +08:00
|
|
|
|
if (options_private->fixed_center)
|
2006-09-24 06:32:35 +08:00
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_update_with_coord (rect_tool,
|
2007-07-09 05:57:22 +08:00
|
|
|
|
private->lastx,
|
|
|
|
|
private->lasty);
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_update_highlight (rect_tool);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2008-05-11 21:01:24 +08:00
|
|
|
|
/* Only emit the rectangle-changed signal if the button is
|
|
|
|
|
* not down. If it is down, the signal will and shall be
|
|
|
|
|
* emited on _button_release instead.
|
|
|
|
|
*/
|
|
|
|
|
if (! button1_down)
|
|
|
|
|
{
|
|
|
|
|
gimp_rectangle_tool_rectangle_change_complete (rect_tool);
|
|
|
|
|
}
|
2007-07-09 05:57:22 +08:00
|
|
|
|
}
|
2008-05-02 03:29:15 +08:00
|
|
|
|
else if (button1_down)
|
2007-07-09 05:57:22 +08:00
|
|
|
|
{
|
2007-07-20 21:18:43 +08:00
|
|
|
|
/* If we are leaving fixed_center mode we want to set the
|
|
|
|
|
* "other side" where it should be. Don't do anything if we
|
|
|
|
|
* came here by a mouse-click though, since then the user
|
|
|
|
|
* has confirmed the shape and we don't want to modify it
|
|
|
|
|
* afterwards.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*/
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_set_other_side_coord (rect_tool,
|
2007-07-09 05:57:22 +08:00
|
|
|
|
private->other_side_x,
|
|
|
|
|
private->other_side_y);
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_update_highlight (rect_tool);
|
2006-09-24 06:32:35 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
gimp_draw_tool_resume (draw_tool);
|
2007-08-05 04:20:44 +08:00
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
gimp_rectangle_tool_update_options (rect_tool, tool->display);
|
2006-09-24 06:32:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2007-10-31 18:36:03 +08:00
|
|
|
|
static void
|
2007-11-24 17:09:26 +08:00
|
|
|
|
swap_doubles (gdouble *i,
|
|
|
|
|
gdouble *j)
|
2007-01-27 06:21:20 +08:00
|
|
|
|
{
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble tmp;
|
2007-01-27 06:21:20 +08:00
|
|
|
|
|
|
|
|
|
tmp = *i;
|
|
|
|
|
*i = *j;
|
|
|
|
|
*j = tmp;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-01 00:38:55 +08:00
|
|
|
|
/* gimp_rectangle_tool_check_function() is needed to deal with
|
2006-06-12 07:59:33 +08:00
|
|
|
|
* situations where the user drags a corner or edge across one of the
|
|
|
|
|
* existing edges, thereby changing its function. Ugh.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_check_function (GimpRectangleTool *rect_tool)
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2006-06-12 07:59:33 +08:00
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
2006-11-16 04:45:43 +08:00
|
|
|
|
GimpRectangleFunction function;
|
2006-06-12 07:59:33 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
2006-06-12 07:59:33 +08:00
|
|
|
|
|
2006-11-05 03:21:15 +08:00
|
|
|
|
function = private->function;
|
2006-06-12 07:59:33 +08:00
|
|
|
|
|
2007-07-09 05:57:22 +08:00
|
|
|
|
if (private->x2 < private->x1)
|
2006-06-12 07:59:33 +08:00
|
|
|
|
{
|
2007-11-24 17:09:26 +08:00
|
|
|
|
swap_doubles (&private->x1, &private->x2);
|
2007-01-27 06:21:20 +08:00
|
|
|
|
switch (function)
|
2006-06-12 07:59:33 +08:00
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_LEFT:
|
|
|
|
|
function = GIMP_RECTANGLE_TOOL_RESIZING_UPPER_RIGHT;
|
2007-01-27 06:21:20 +08:00
|
|
|
|
break;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_RIGHT:
|
|
|
|
|
function = GIMP_RECTANGLE_TOOL_RESIZING_UPPER_LEFT;
|
2007-01-27 06:21:20 +08:00
|
|
|
|
break;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_LEFT:
|
|
|
|
|
function = GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT;
|
2007-01-27 06:21:20 +08:00
|
|
|
|
break;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT:
|
|
|
|
|
function = GIMP_RECTANGLE_TOOL_RESIZING_LOWER_LEFT;
|
2007-01-27 06:21:20 +08:00
|
|
|
|
break;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LEFT:
|
|
|
|
|
function = GIMP_RECTANGLE_TOOL_RESIZING_RIGHT;
|
2007-01-27 06:21:20 +08:00
|
|
|
|
break;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_RIGHT:
|
|
|
|
|
function = GIMP_RECTANGLE_TOOL_RESIZING_LEFT;
|
2007-01-27 06:21:20 +08:00
|
|
|
|
break;
|
|
|
|
|
/* avoid annoying warnings about unhandled enums */
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2006-06-12 07:59:33 +08:00
|
|
|
|
}
|
2007-01-27 06:21:20 +08:00
|
|
|
|
}
|
2006-06-12 07:59:33 +08:00
|
|
|
|
|
2007-07-09 05:57:22 +08:00
|
|
|
|
if (private->y2 < private->y1)
|
2007-01-27 06:21:20 +08:00
|
|
|
|
{
|
2007-11-24 17:09:26 +08:00
|
|
|
|
swap_doubles (&private->y1, &private->y2);
|
2007-01-27 06:21:20 +08:00
|
|
|
|
switch (function)
|
2006-06-12 07:59:33 +08:00
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_LEFT:
|
|
|
|
|
function = GIMP_RECTANGLE_TOOL_RESIZING_LOWER_LEFT;
|
2007-01-27 06:21:20 +08:00
|
|
|
|
break;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_RIGHT:
|
|
|
|
|
function = GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT;
|
2007-01-27 06:21:20 +08:00
|
|
|
|
break;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_LEFT:
|
|
|
|
|
function = GIMP_RECTANGLE_TOOL_RESIZING_UPPER_LEFT;
|
2007-01-27 06:21:20 +08:00
|
|
|
|
break;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT:
|
|
|
|
|
function = GIMP_RECTANGLE_TOOL_RESIZING_UPPER_RIGHT;
|
2007-01-27 06:21:20 +08:00
|
|
|
|
break;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_TOP:
|
|
|
|
|
function = GIMP_RECTANGLE_TOOL_RESIZING_BOTTOM;
|
2007-01-27 06:21:20 +08:00
|
|
|
|
break;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_BOTTOM:
|
|
|
|
|
function = GIMP_RECTANGLE_TOOL_RESIZING_TOP;
|
2007-01-27 06:21:20 +08:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2006-06-12 07:59:33 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_set_function (rect_tool, function);
|
2006-06-12 07:59:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
GimpRectangleTool *rect_tool;
|
2006-11-05 03:21:15 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2007-01-24 16:40:24 +08:00
|
|
|
|
gint dx = 0;
|
|
|
|
|
gint dy = 0;
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble new_x = 0;
|
|
|
|
|
gdouble new_y = 0;
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_RECTANGLE_TOOL (tool), FALSE);
|
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
if (display != tool->display)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
rect_tool = GIMP_RECTANGLE_TOOL (tool);
|
2007-01-24 16:40:24 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
|
|
|
|
|
2005-03-03 02:18:19 +08:00
|
|
|
|
switch (kevent->keyval)
|
|
|
|
|
{
|
|
|
|
|
case GDK_Up:
|
2007-01-24 16:40:24 +08:00
|
|
|
|
dy = -1;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
break;
|
|
|
|
|
case GDK_Left:
|
2007-01-24 16:40:24 +08:00
|
|
|
|
dx = -1;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
break;
|
|
|
|
|
case GDK_Right:
|
2007-01-24 16:40:24 +08:00
|
|
|
|
dx = 1;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
break;
|
|
|
|
|
case GDK_Down:
|
2007-01-24 16:40:24 +08:00
|
|
|
|
dy = 1;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
break;
|
2007-01-24 15:12:42 +08:00
|
|
|
|
|
2005-03-03 02:18:19 +08:00
|
|
|
|
case GDK_Return:
|
2008-02-17 01:51:02 +08:00
|
|
|
|
case GDK_KP_Enter:
|
|
|
|
|
case GDK_ISO_Enter:
|
2007-11-04 22:47:48 +08:00
|
|
|
|
if (gimp_rectangle_tool_execute (rect_tool))
|
|
|
|
|
gimp_rectangle_tool_halt (rect_tool);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
case GDK_Escape:
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_cancel (rect_tool);
|
|
|
|
|
gimp_rectangle_tool_halt (rect_tool);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If the shift key is down, move by an accelerated increment */
|
2007-01-24 15:12:42 +08:00
|
|
|
|
if (kevent->state & GDK_SHIFT_MASK)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2007-01-24 16:40:24 +08:00
|
|
|
|
dx *= ARROW_VELOCITY;
|
|
|
|
|
dy *= ARROW_VELOCITY;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_tool_control_set_snap_offsets (GIMP_TOOL (rect_tool)->control,
|
2007-07-09 05:57:22 +08:00
|
|
|
|
0, 0, 0, 0);
|
|
|
|
|
|
2007-01-24 16:40:24 +08:00
|
|
|
|
/* Resize the rectangle if the mouse is over a handle, otherwise move it */
|
|
|
|
|
switch (private->function)
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_MOVING:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_LEFT:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
new_x = private->x1 + dx;
|
|
|
|
|
new_y = private->y1 + dy;
|
|
|
|
|
private->lastx = new_x;
|
|
|
|
|
private->lasty = new_y;
|
2007-01-24 16:40:24 +08:00
|
|
|
|
break;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_RIGHT:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
new_x = private->x2 + dx;
|
|
|
|
|
new_y = private->y1 + dy;
|
|
|
|
|
private->lastx = new_x;
|
|
|
|
|
private->lasty = new_y;
|
2007-01-24 16:40:24 +08:00
|
|
|
|
break;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_LEFT:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
new_x = private->x1 + dx;
|
|
|
|
|
new_y = private->y2 + dy;
|
|
|
|
|
private->lastx = new_x;
|
|
|
|
|
private->lasty = new_y;
|
2007-01-24 16:40:24 +08:00
|
|
|
|
break;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
new_x = private->x2 + dx;
|
|
|
|
|
new_y = private->y2 + dy;
|
|
|
|
|
private->lastx = new_x;
|
|
|
|
|
private->lasty = new_y;
|
2007-01-24 16:40:24 +08:00
|
|
|
|
break;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LEFT:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
new_x = private->x1 + dx;
|
|
|
|
|
private->lastx = new_x;
|
2007-01-24 16:40:24 +08:00
|
|
|
|
break;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_RIGHT:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
new_x = private->x2 + dx;
|
|
|
|
|
private->lastx = new_x;
|
2007-01-24 16:40:24 +08:00
|
|
|
|
break;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_TOP:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
new_y = private->y1 + dy;
|
|
|
|
|
private->lasty = new_y;
|
2007-01-24 16:40:24 +08:00
|
|
|
|
break;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_BOTTOM:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
new_y = private->y2 + dy;
|
|
|
|
|
private->lasty = new_y;
|
2007-01-24 16:40:24 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
return TRUE;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tool));
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_update_with_coord (rect_tool,
|
2007-07-09 05:57:22 +08:00
|
|
|
|
new_x,
|
|
|
|
|
new_y);
|
2007-01-27 06:21:20 +08:00
|
|
|
|
|
2007-07-09 05:57:22 +08:00
|
|
|
|
private->center_x_on_fixed_center = (private->x1 + private->x2) / 2;
|
|
|
|
|
private->center_y_on_fixed_center = (private->y1 + private->y2) / 2;
|
2007-01-27 06:21:20 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_update_highlight (rect_tool);
|
2007-12-15 01:22:46 +08:00
|
|
|
|
gimp_rectangle_tool_update_handle_sizes (rect_tool);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
gimp_rectangle_tool_update_options (rect_tool, tool->display);
|
2007-03-09 15:16:18 +08:00
|
|
|
|
|
2005-03-03 02:18:19 +08:00
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tool));
|
|
|
|
|
|
2008-05-02 17:05:13 +08:00
|
|
|
|
gimp_rectangle_tool_rectangle_change_complete (rect_tool);
|
2007-03-08 14:52:41 +08:00
|
|
|
|
|
2007-01-24 16:40:24 +08:00
|
|
|
|
/* Evil hack to suppress oper updates. We do this because we don't
|
|
|
|
|
* want the rectangle tool to change function while the rectangle
|
|
|
|
|
* is being resized or moved using the keyboard.
|
|
|
|
|
*/
|
|
|
|
|
private->suppress_updates = 2;
|
|
|
|
|
|
2005-03-03 02:18:19 +08:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
void
|
2008-11-01 23:17:36 +08:00
|
|
|
|
gimp_rectangle_tool_oper_update (GimpTool *tool,
|
|
|
|
|
const GimpCoords *coords,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
gboolean proximity,
|
|
|
|
|
GimpDisplay *display)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2006-06-03 06:24:55 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2007-11-04 22:47:48 +08:00
|
|
|
|
GimpRectangleTool *rect_tool;
|
2006-11-05 03:21:15 +08:00
|
|
|
|
gint function;
|
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
|
|
|
|
|
2008-08-28 20:54:14 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2007-11-04 22:47:48 +08:00
|
|
|
|
rect_tool = GIMP_RECTANGLE_TOOL (tool);
|
2005-08-15 22:23:28 +08:00
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
if (tool->display != display)
|
2006-11-16 04:45:43 +08:00
|
|
|
|
return;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2007-01-24 16:40:24 +08:00
|
|
|
|
if (private->suppress_updates)
|
|
|
|
|
{
|
|
|
|
|
private->suppress_updates--;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
if (gimp_rectangle_tool_coord_outside (rect_tool, coords))
|
2005-03-10 06:22:38 +08:00
|
|
|
|
{
|
2007-10-27 04:58:08 +08:00
|
|
|
|
/* The cursor is outside of the rectangle, clicking should
|
|
|
|
|
* create a new rectangle.
|
|
|
|
|
*/
|
2007-11-24 17:27:55 +08:00
|
|
|
|
function = GIMP_RECTANGLE_TOOL_CREATING;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
}
|
2007-11-04 22:47:48 +08:00
|
|
|
|
else if (gimp_rectangle_tool_coord_on_handle (rect_tool,
|
2007-10-27 04:58:08 +08:00
|
|
|
|
coords,
|
|
|
|
|
GTK_ANCHOR_NORTH_WEST))
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
function = GIMP_RECTANGLE_TOOL_RESIZING_UPPER_LEFT;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
}
|
2007-11-04 22:47:48 +08:00
|
|
|
|
else if (gimp_rectangle_tool_coord_on_handle (rect_tool,
|
2007-10-27 04:58:08 +08:00
|
|
|
|
coords,
|
|
|
|
|
GTK_ANCHOR_SOUTH_EAST))
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
function = GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
}
|
2007-11-04 22:47:48 +08:00
|
|
|
|
else if (gimp_rectangle_tool_coord_on_handle (rect_tool,
|
2007-10-27 04:58:08 +08:00
|
|
|
|
coords,
|
|
|
|
|
GTK_ANCHOR_NORTH_EAST))
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
function = GIMP_RECTANGLE_TOOL_RESIZING_UPPER_RIGHT;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
}
|
2007-11-04 22:47:48 +08:00
|
|
|
|
else if (gimp_rectangle_tool_coord_on_handle (rect_tool,
|
2007-10-27 04:58:08 +08:00
|
|
|
|
coords,
|
|
|
|
|
GTK_ANCHOR_SOUTH_WEST))
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
function = GIMP_RECTANGLE_TOOL_RESIZING_LOWER_LEFT;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
}
|
2007-11-04 22:47:48 +08:00
|
|
|
|
else if (gimp_rectangle_tool_coord_on_handle (rect_tool,
|
2007-10-27 04:58:08 +08:00
|
|
|
|
coords,
|
|
|
|
|
GTK_ANCHOR_WEST))
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
function = GIMP_RECTANGLE_TOOL_RESIZING_LEFT;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
}
|
2007-11-04 22:47:48 +08:00
|
|
|
|
else if (gimp_rectangle_tool_coord_on_handle (rect_tool,
|
2007-10-27 04:58:08 +08:00
|
|
|
|
coords,
|
|
|
|
|
GTK_ANCHOR_EAST))
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
function = GIMP_RECTANGLE_TOOL_RESIZING_RIGHT;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
}
|
2007-11-04 22:47:48 +08:00
|
|
|
|
else if (gimp_rectangle_tool_coord_on_handle (rect_tool,
|
2007-10-27 04:58:08 +08:00
|
|
|
|
coords,
|
|
|
|
|
GTK_ANCHOR_NORTH))
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
function = GIMP_RECTANGLE_TOOL_RESIZING_TOP;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
}
|
2007-11-04 22:47:48 +08:00
|
|
|
|
else if (gimp_rectangle_tool_coord_on_handle (rect_tool,
|
2007-10-27 04:58:08 +08:00
|
|
|
|
coords,
|
|
|
|
|
GTK_ANCHOR_SOUTH))
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
function = GIMP_RECTANGLE_TOOL_RESIZING_BOTTOM;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
}
|
2007-11-04 22:47:48 +08:00
|
|
|
|
else if (gimp_rectangle_tool_coord_on_handle (rect_tool,
|
2007-10-27 04:58:08 +08:00
|
|
|
|
coords,
|
|
|
|
|
GTK_ANCHOR_CENTER))
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
function = GIMP_RECTANGLE_TOOL_MOVING;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
function = GIMP_RECTANGLE_TOOL_DEAD;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
2006-11-05 03:21:15 +08:00
|
|
|
|
|
2006-11-16 04:45:43 +08:00
|
|
|
|
gimp_rectangle_tool_set_function (GIMP_RECTANGLE_TOOL (tool), function);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
void
|
2008-11-01 23:17:36 +08:00
|
|
|
|
gimp_rectangle_tool_cursor_update (GimpTool *tool,
|
|
|
|
|
const GimpCoords *coords,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GimpDisplay *display)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
GimpRectangleTool *rect_tool;
|
2006-11-05 03:21:15 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2008-11-02 03:05:56 +08:00
|
|
|
|
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));
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
rect_tool = GIMP_RECTANGLE_TOOL (tool);
|
2006-11-05 03:21:15 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
if (tool->display == display)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2006-11-05 03:21:15 +08:00
|
|
|
|
switch (private->function)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_CREATING:
|
2006-06-02 23:23:47 +08:00
|
|
|
|
cursor = GIMP_CURSOR_CROSSHAIR_SMALL;
|
2005-03-15 04:44:18 +08:00
|
|
|
|
break;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_MOVING:
|
2008-11-02 03:05:56 +08:00
|
|
|
|
cursor = GIMP_CURSOR_MOVE;
|
|
|
|
|
modifier = GIMP_CURSOR_MODIFIER_MOVE;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
break;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_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;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_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;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_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;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_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;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LEFT:
|
2006-06-02 23:23:47 +08:00
|
|
|
|
cursor = GIMP_CURSOR_SIDE_LEFT;
|
2005-03-15 04:44:18 +08:00
|
|
|
|
break;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_RIGHT:
|
2006-06-02 23:23:47 +08:00
|
|
|
|
cursor = GIMP_CURSOR_SIDE_RIGHT;
|
2005-03-15 04:44:18 +08:00
|
|
|
|
break;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_TOP:
|
2006-06-02 23:23:47 +08:00
|
|
|
|
cursor = GIMP_CURSOR_SIDE_TOP;
|
2005-03-15 04:44:18 +08:00
|
|
|
|
break;
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-02 03:05:56 +08:00
|
|
|
|
gimp_tool_control_set_cursor (tool->control, cursor);
|
|
|
|
|
gimp_tool_control_set_cursor_modifier (tool->control, modifier);
|
2005-03-03 02:18:19 +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-11-05 03:21:15 +08:00
|
|
|
|
GimpTool *tool;
|
2006-06-03 06:24:55 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble pub_x1, pub_y1, pub_x2, pub_y2;
|
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-11-05 03:21:15 +08:00
|
|
|
|
tool = GIMP_TOOL (draw_tool);
|
2006-11-07 00:40:09 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2006-06-05 02:21:56 +08:00
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gimp_rectangle_tool_get_public_rect (GIMP_RECTANGLE_TOOL (draw_tool),
|
|
|
|
|
&pub_x1, &pub_y1, &pub_x2, &pub_y2);
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
if (private->function == GIMP_RECTANGLE_TOOL_INACTIVE)
|
2006-06-05 02:21:56 +08:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
gimp_draw_tool_draw_rectangle (draw_tool, FALSE,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
pub_x1,
|
|
|
|
|
pub_y1,
|
|
|
|
|
pub_x2 - pub_x1,
|
|
|
|
|
pub_y2 - pub_y1,
|
2006-11-05 03:50:13 +08:00
|
|
|
|
FALSE);
|
2006-06-06 04:48:58 +08:00
|
|
|
|
|
2006-11-07 01:09:07 +08:00
|
|
|
|
switch (private->function)
|
2006-09-15 08:01:59 +08:00
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_MOVING:
|
2008-07-05 17:47:39 +08:00
|
|
|
|
|
2006-11-07 22:08:14 +08:00
|
|
|
|
if (gimp_tool_control_is_active (tool->control))
|
2008-07-05 17:47:39 +08:00
|
|
|
|
{
|
|
|
|
|
/* Mark the center because we snap to it */
|
|
|
|
|
gimp_draw_tool_draw_cross_by_anchor (draw_tool,
|
2008-07-05 19:01:20 +08:00
|
|
|
|
(pub_x1 + pub_x2) / 2.0,
|
|
|
|
|
(pub_y1 + pub_y2) / 2.0,
|
2008-07-05 17:47:39 +08:00
|
|
|
|
CENTER_CROSS_SIZE,
|
|
|
|
|
CENTER_CROSS_SIZE,
|
|
|
|
|
GTK_ANCHOR_CENTER,
|
|
|
|
|
FALSE);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Fallthrough */
|
|
|
|
|
}
|
2006-11-07 22:08:14 +08:00
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_DEAD:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_CREATING:
|
2007-11-04 22:10:56 +08:00
|
|
|
|
gimp_draw_tool_draw_corner (draw_tool, FALSE, private->narrow_mode,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
pub_x1, pub_y1,
|
|
|
|
|
pub_x2, pub_y2,
|
2007-10-27 05:07:45 +08:00
|
|
|
|
private->corner_handle_w,
|
|
|
|
|
private->corner_handle_h,
|
2006-09-15 08:01:59 +08:00
|
|
|
|
GTK_ANCHOR_NORTH_WEST, FALSE);
|
2007-11-04 22:10:56 +08:00
|
|
|
|
gimp_draw_tool_draw_corner (draw_tool, FALSE, private->narrow_mode,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
pub_x1, pub_y1,
|
|
|
|
|
pub_x2, pub_y2,
|
2007-10-27 05:07:45 +08:00
|
|
|
|
private->corner_handle_w,
|
|
|
|
|
private->corner_handle_h,
|
2006-09-15 08:01:59 +08:00
|
|
|
|
GTK_ANCHOR_NORTH_EAST, FALSE);
|
2007-11-04 22:10:56 +08:00
|
|
|
|
gimp_draw_tool_draw_corner (draw_tool, FALSE, private->narrow_mode,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
pub_x1, pub_y1,
|
|
|
|
|
pub_x2, pub_y2,
|
2007-10-27 05:07:45 +08:00
|
|
|
|
private->corner_handle_w,
|
|
|
|
|
private->corner_handle_h,
|
2006-09-15 08:01:59 +08:00
|
|
|
|
GTK_ANCHOR_SOUTH_WEST, FALSE);
|
2007-11-04 22:10:56 +08:00
|
|
|
|
gimp_draw_tool_draw_corner (draw_tool, FALSE, private->narrow_mode,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
pub_x1, pub_y1,
|
|
|
|
|
pub_x2, pub_y2,
|
2007-10-27 05:07:45 +08:00
|
|
|
|
private->corner_handle_w,
|
|
|
|
|
private->corner_handle_h,
|
2006-09-15 08:01:59 +08:00
|
|
|
|
GTK_ANCHOR_SOUTH_EAST, FALSE);
|
2006-11-07 01:09:07 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_TOP:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_BOTTOM:
|
2007-07-01 02:13:41 +08:00
|
|
|
|
gimp_draw_tool_draw_corner (draw_tool,
|
2007-07-05 19:49:00 +08:00
|
|
|
|
! gimp_tool_control_is_active (tool->control),
|
2007-11-04 22:10:56 +08:00
|
|
|
|
private->narrow_mode,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
pub_x1, pub_y1,
|
|
|
|
|
pub_x2, pub_y2,
|
2007-07-05 19:49:00 +08:00
|
|
|
|
private->top_and_bottom_handle_w,
|
2007-10-27 05:07:45 +08:00
|
|
|
|
private->corner_handle_h,
|
2007-07-01 02:13:41 +08:00
|
|
|
|
gimp_rectangle_tool_get_anchor (private),
|
|
|
|
|
FALSE);
|
|
|
|
|
break;
|
2006-11-14 00:13:37 +08:00
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_RIGHT:
|
2007-07-01 02:13:41 +08:00
|
|
|
|
gimp_draw_tool_draw_corner (draw_tool,
|
2007-07-05 19:49:00 +08:00
|
|
|
|
! gimp_tool_control_is_active (tool->control),
|
2007-11-04 22:10:56 +08:00
|
|
|
|
private->narrow_mode,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
pub_x1, pub_y1,
|
|
|
|
|
pub_x2, pub_y2,
|
2007-10-27 05:07:45 +08:00
|
|
|
|
private->corner_handle_w,
|
2007-07-05 19:49:00 +08:00
|
|
|
|
private->left_and_right_handle_h,
|
2007-07-01 02:13:41 +08:00
|
|
|
|
gimp_rectangle_tool_get_anchor (private),
|
|
|
|
|
FALSE);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
gimp_draw_tool_draw_corner (draw_tool,
|
2007-07-05 19:49:00 +08:00
|
|
|
|
! gimp_tool_control_is_active (tool->control),
|
2007-11-04 22:10:56 +08:00
|
|
|
|
private->narrow_mode,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
pub_x1, pub_y1,
|
|
|
|
|
pub_x2, pub_y2,
|
2007-10-27 05:07:45 +08:00
|
|
|
|
private->corner_handle_w,
|
|
|
|
|
private->corner_handle_h,
|
2007-07-01 02:13:41 +08:00
|
|
|
|
gimp_rectangle_tool_get_anchor (private),
|
|
|
|
|
FALSE);
|
2006-11-07 01:09:07 +08:00
|
|
|
|
break;
|
2006-09-15 08:01:59 +08:00
|
|
|
|
}
|
2006-11-07 01:09:07 +08:00
|
|
|
|
|
|
|
|
|
gimp_rectangle_tool_draw_guides (draw_tool);
|
2006-06-07 03:14:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gimp_rectangle_tool_draw_guides (GimpDrawTool *draw_tool)
|
|
|
|
|
{
|
2009-03-14 20:59:34 +08:00
|
|
|
|
GimpTool *tool = GIMP_TOOL (draw_tool);
|
|
|
|
|
gdouble x1, y1;
|
|
|
|
|
gdouble x2, y2;
|
2006-06-07 03:25:53 +08:00
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gimp_rectangle_tool_get_public_rect (GIMP_RECTANGLE_TOOL (draw_tool),
|
2009-03-14 20:59:34 +08:00
|
|
|
|
&x1, &y1, &x2, &y2);
|
2008-08-28 20:54:14 +08:00
|
|
|
|
|
2009-03-14 20:59:34 +08:00
|
|
|
|
switch (GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool)->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,
|
2009-03-14 20:59:34 +08:00
|
|
|
|
x1, (y1 + y2) / 2,
|
|
|
|
|
x2, (y1 + y2) / 2, FALSE);
|
2006-06-06 04:48:58 +08:00
|
|
|
|
gimp_draw_tool_draw_line (draw_tool,
|
2009-03-14 20:59:34 +08:00
|
|
|
|
(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,
|
2009-03-14 20:59:34 +08:00
|
|
|
|
x1, (2 * y1 + y2) / 3,
|
|
|
|
|
x2, (2 * y1 + y2) / 3, FALSE);
|
2006-06-06 04:48:58 +08:00
|
|
|
|
gimp_draw_tool_draw_line (draw_tool,
|
2009-03-14 20:59:34 +08:00
|
|
|
|
x1, (y1 + 2 * y2) / 3,
|
|
|
|
|
x2, (y1 + 2 * y2) / 3, FALSE);
|
2006-06-06 04:48:58 +08:00
|
|
|
|
gimp_draw_tool_draw_line (draw_tool,
|
2009-03-14 20:59:34 +08:00
|
|
|
|
(2 * x1 + x2) / 3, y1,
|
|
|
|
|
(2 * x1 + x2) / 3, y2, FALSE);
|
2006-06-06 04:48:58 +08:00
|
|
|
|
gimp_draw_tool_draw_line (draw_tool,
|
2009-03-14 20:59:34 +08:00
|
|
|
|
(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,
|
2009-03-14 20:59:34 +08:00
|
|
|
|
x1,
|
|
|
|
|
(2 * y1 + (1 + SQRT5) * y2) / (3 + SQRT5),
|
|
|
|
|
x2,
|
|
|
|
|
(2 * y1 + (1 + SQRT5) * y2) / (3 + SQRT5),
|
2006-06-07 03:25:53 +08:00
|
|
|
|
FALSE);
|
2006-06-06 04:48:58 +08:00
|
|
|
|
gimp_draw_tool_draw_line (draw_tool,
|
2009-03-14 20:59:34 +08:00
|
|
|
|
x1,
|
|
|
|
|
((1 + SQRT5) * y1 + 2 * y2) / (3 + SQRT5),
|
|
|
|
|
x2,
|
|
|
|
|
((1 + SQRT5) * y1 + 2 * y2) / (3 + SQRT5),
|
2006-06-07 03:25:53 +08:00
|
|
|
|
FALSE);
|
2006-06-06 04:48:58 +08:00
|
|
|
|
gimp_draw_tool_draw_line (draw_tool,
|
2009-03-14 20:59:34 +08:00
|
|
|
|
(2 * x1 + (1 + SQRT5) * x2) / (3 + SQRT5),
|
|
|
|
|
y1,
|
|
|
|
|
(2 * x1 + (1 + SQRT5) * x2) / (3 + SQRT5),
|
|
|
|
|
y2,
|
2006-06-07 03:25:53 +08:00
|
|
|
|
FALSE);
|
2006-06-06 04:48:58 +08:00
|
|
|
|
gimp_draw_tool_draw_line (draw_tool,
|
2009-03-14 20:59:34 +08:00
|
|
|
|
((1 + SQRT5) * x1 + 2 * x2) / (3 + SQRT5),
|
|
|
|
|
y1,
|
|
|
|
|
((1 + SQRT5) * x1 + 2 * x2) / (3 + SQRT5),
|
|
|
|
|
y2, FALSE);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
/* This code implements the method of diagonals discovered by
|
|
|
|
|
* Edwin Westhoff - see http://www.diagonalmethod.info/
|
|
|
|
|
*/
|
|
|
|
|
case GIMP_RECTANGLE_GUIDE_DIAGONALS:
|
|
|
|
|
{
|
|
|
|
|
/* the side of the largest square that can be
|
|
|
|
|
* fitted in whole into the rectangle (x1, y1), (x2, y2)
|
|
|
|
|
*/
|
|
|
|
|
const gdouble square_side = MIN (x2 - x1, y2 - y1);
|
|
|
|
|
|
|
|
|
|
/* diagonal from the top-left edge */
|
|
|
|
|
gimp_draw_tool_draw_line (draw_tool,
|
|
|
|
|
x1, y1,
|
|
|
|
|
x1 + square_side, y1 + square_side,
|
|
|
|
|
FALSE);
|
|
|
|
|
/* diagonal from the top-right edge */
|
|
|
|
|
gimp_draw_tool_draw_line (draw_tool,
|
|
|
|
|
x2, y1,
|
|
|
|
|
x2 - square_side, y1 + square_side,
|
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
|
|
/* If user selected a square, we cannot draw from bottom points
|
|
|
|
|
* as we would erase the guides drawn from the top points
|
|
|
|
|
*/
|
|
|
|
|
if ((x1 + square_side != x2) || (y1 + square_side != y2))
|
|
|
|
|
{
|
|
|
|
|
/* diagonal from the bottom-left edge */
|
|
|
|
|
gimp_draw_tool_draw_line (draw_tool,
|
|
|
|
|
x1, y2,
|
|
|
|
|
x1 + square_side, y2 - square_side,
|
|
|
|
|
FALSE);
|
|
|
|
|
/* diagonal from the bottom-right edge */
|
|
|
|
|
gimp_draw_tool_draw_line (draw_tool,
|
|
|
|
|
x2, y2,
|
|
|
|
|
x2 - square_side, y2 - square_side,
|
|
|
|
|
FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-06-06 02:50:13 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2007-07-15 00:29:04 +08:00
|
|
|
|
static void
|
2007-12-15 01:22:46 +08:00
|
|
|
|
gimp_rectangle_tool_update_handle_sizes (GimpRectangleTool *rect_tool)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2007-11-24 17:09:26 +08:00
|
|
|
|
GimpTool *tool;
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
2006-09-06 02:25:31 +08:00
|
|
|
|
GimpDisplayShell *shell;
|
2007-08-11 17:42:16 +08:00
|
|
|
|
gint visible_rectangle_width;
|
|
|
|
|
gint visible_rectangle_height;
|
|
|
|
|
gint rectangle_width;
|
|
|
|
|
gint rectangle_height;
|
2009-03-14 20:59:34 +08:00
|
|
|
|
gdouble pub_x1, pub_y1;
|
|
|
|
|
gdouble pub_x2, pub_y2;
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
tool = GIMP_TOOL (rect_tool);
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
if (! (tool && tool->display))
|
2005-03-03 02:18:19 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2009-10-05 01:56:39 +08:00
|
|
|
|
shell = gimp_display_get_shell (tool->display);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gimp_rectangle_tool_get_public_rect (rect_tool,
|
|
|
|
|
&pub_x1, &pub_y1, &pub_x2, &pub_y2);
|
2007-08-11 17:42:16 +08:00
|
|
|
|
{
|
|
|
|
|
/* Calculate rectangles of the selection rectangle and the display shell,
|
|
|
|
|
* with origin at (0, 0) of image, and in screen coordinate scale.
|
|
|
|
|
*/
|
2008-07-11 04:19:17 +08:00
|
|
|
|
gint x1 = pub_x1 * shell->scale_x;
|
|
|
|
|
gint y1 = pub_y1 * shell->scale_y;
|
|
|
|
|
gint w1 = (pub_x2 - pub_x1) * shell->scale_x;
|
|
|
|
|
gint h1 = (pub_y2 - pub_y1) * shell->scale_y;
|
|
|
|
|
|
|
|
|
|
gint x2, y2, w2, h2;
|
|
|
|
|
|
2008-08-10 18:51:56 +08:00
|
|
|
|
gimp_display_shell_scroll_get_scaled_viewport (shell, &x2, &y2, &w2, &h2);
|
2007-08-11 17:42:16 +08:00
|
|
|
|
|
|
|
|
|
rectangle_width = w1;
|
|
|
|
|
rectangle_height = h1;
|
|
|
|
|
|
|
|
|
|
/* Handle size calculations shall be based on the visible part of the
|
|
|
|
|
* rectangle, so calculate the size for the visible rectangle by
|
|
|
|
|
* intersecting with the viewport rectangle.
|
|
|
|
|
*/
|
|
|
|
|
gimp_rectangle_intersect (x1, y1,
|
|
|
|
|
w1, h1,
|
|
|
|
|
x2, y2,
|
|
|
|
|
w2, h2,
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
&visible_rectangle_width,
|
|
|
|
|
&visible_rectangle_height);
|
2007-11-04 22:10:56 +08:00
|
|
|
|
|
2008-04-08 02:57:32 +08:00
|
|
|
|
/* Determine if we are in narrow-mode or not. */
|
|
|
|
|
private->narrow_mode = (visible_rectangle_width < NARROW_MODE_THRESHOLD ||
|
|
|
|
|
visible_rectangle_height < NARROW_MODE_THRESHOLD);
|
2007-08-11 17:42:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2007-11-04 22:10:56 +08:00
|
|
|
|
if (private->narrow_mode)
|
|
|
|
|
{
|
|
|
|
|
/* Corner handles always have the same (on-screen) size in
|
|
|
|
|
* narrow-mode.
|
|
|
|
|
*/
|
|
|
|
|
private->corner_handle_w = NARROW_MODE_HANDLE_SIZE;
|
|
|
|
|
private->corner_handle_h = NARROW_MODE_HANDLE_SIZE;
|
2007-08-11 17:42:16 +08:00
|
|
|
|
|
2007-11-07 06:04:18 +08:00
|
|
|
|
private->top_and_bottom_handle_w = CLAMP (rectangle_width,
|
|
|
|
|
MIN (rectangle_width - 2,
|
|
|
|
|
NARROW_MODE_HANDLE_SIZE),
|
2007-11-04 22:10:56 +08:00
|
|
|
|
G_MAXINT);
|
2007-11-07 06:04:18 +08:00
|
|
|
|
private->left_and_right_handle_h = CLAMP (rectangle_height,
|
|
|
|
|
MIN (rectangle_height - 2,
|
|
|
|
|
NARROW_MODE_HANDLE_SIZE),
|
2007-11-04 22:10:56 +08:00
|
|
|
|
G_MAXINT);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Calculate and clamp corner handle size. */
|
2007-08-11 17:42:16 +08:00
|
|
|
|
|
2007-11-04 22:10:56 +08:00
|
|
|
|
private->corner_handle_w = visible_rectangle_width / 4;
|
|
|
|
|
private->corner_handle_h = visible_rectangle_height / 4;
|
2007-08-11 17:42:16 +08:00
|
|
|
|
|
2007-11-04 22:10:56 +08:00
|
|
|
|
private->corner_handle_w = CLAMP (private->corner_handle_w,
|
|
|
|
|
MIN_HANDLE_SIZE,
|
|
|
|
|
MAX_HANDLE_SIZE);
|
|
|
|
|
private->corner_handle_h = CLAMP (private->corner_handle_h,
|
|
|
|
|
MIN_HANDLE_SIZE,
|
|
|
|
|
MAX_HANDLE_SIZE);
|
2007-08-11 17:42:16 +08:00
|
|
|
|
|
2007-11-04 22:10:56 +08:00
|
|
|
|
/* Calculate and clamp side handle size. */
|
2007-08-11 17:42:16 +08:00
|
|
|
|
|
2007-11-04 22:10:56 +08:00
|
|
|
|
private->top_and_bottom_handle_w = rectangle_width - 3 * private->corner_handle_w;
|
|
|
|
|
private->left_and_right_handle_h = rectangle_height - 3 * private->corner_handle_h;
|
2007-08-11 17:42:16 +08:00
|
|
|
|
|
2007-11-04 22:10:56 +08:00
|
|
|
|
private->top_and_bottom_handle_w = CLAMP (private->top_and_bottom_handle_w,
|
|
|
|
|
MIN_HANDLE_SIZE,
|
|
|
|
|
G_MAXINT);
|
|
|
|
|
private->left_and_right_handle_h = CLAMP (private->left_and_right_handle_h,
|
|
|
|
|
MIN_HANDLE_SIZE,
|
|
|
|
|
G_MAXINT);
|
|
|
|
|
}
|
2007-08-11 17:42:16 +08:00
|
|
|
|
|
|
|
|
|
/* Keep track of when we need to calculate handle sizes because of a display
|
|
|
|
|
* shell change.
|
|
|
|
|
*/
|
2007-07-15 17:43:49 +08:00
|
|
|
|
private->scale_x_used_for_handle_size_calculations = shell->scale_x;
|
|
|
|
|
private->scale_y_used_for_handle_size_calculations = shell->scale_y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_scale_has_changed:
|
2007-11-04 22:47:48 +08:00
|
|
|
|
* @rect_tool: A #GimpRectangleTool.
|
2007-07-15 17:43:49 +08:00
|
|
|
|
*
|
2007-10-09 23:59:04 +08:00
|
|
|
|
* Returns: %TRUE if the scale that was used to calculate handle sizes
|
|
|
|
|
* is not the same as the current shell scale.
|
2007-07-15 17:43:49 +08:00
|
|
|
|
*/
|
|
|
|
|
static gboolean
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_scale_has_changed (GimpRectangleTool *rect_tool)
|
2007-07-15 17:43:49 +08:00
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
GimpTool *tool = GIMP_TOOL (rect_tool);
|
2007-07-15 17:43:49 +08:00
|
|
|
|
GimpRectangleToolPrivate *private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
if (! tool->display)
|
2007-07-15 17:43:49 +08:00
|
|
|
|
return TRUE;
|
|
|
|
|
|
2009-10-05 01:56:39 +08:00
|
|
|
|
shell = gimp_display_get_shell (tool->display);
|
2007-07-15 17:43:49 +08:00
|
|
|
|
|
2008-07-12 17:07:04 +08:00
|
|
|
|
return (shell->scale_x != private->scale_x_used_for_handle_size_calculations
|
|
|
|
|
||
|
|
|
|
|
shell->scale_y != private->scale_y_used_for_handle_size_calculations);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_start (GimpRectangleTool *rect_tool,
|
2007-03-15 17:21:47 +08:00
|
|
|
|
GimpDisplay *display)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
GimpTool *tool = GIMP_TOOL (rect_tool);
|
2007-04-01 00:38:55 +08:00
|
|
|
|
GimpRectangleOptionsPrivate *options_private;
|
2007-11-04 22:10:56 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2007-12-27 01:33:41 +08:00
|
|
|
|
gdouble xres;
|
|
|
|
|
gdouble yres;
|
2007-04-01 00:38:55 +08:00
|
|
|
|
|
|
|
|
|
options_private =
|
|
|
|
|
GIMP_RECTANGLE_OPTIONS_GET_PRIVATE (gimp_tool_get_options (tool));
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
2007-11-04 22:10:56 +08:00
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
tool->display = display;
|
2007-07-15 00:03:13 +08:00
|
|
|
|
|
2009-10-06 01:58:03 +08:00
|
|
|
|
g_signal_connect_object (gimp_display_get_shell (tool->display), "scrolled",
|
2007-08-11 17:42:16 +08:00
|
|
|
|
G_CALLBACK (gimp_rectangle_tool_shell_scrolled),
|
2007-11-04 22:47:48 +08:00
|
|
|
|
rect_tool, 0);
|
2007-08-11 17:42:16 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_update_highlight (rect_tool);
|
2007-12-15 01:22:46 +08:00
|
|
|
|
gimp_rectangle_tool_update_handle_sizes (rect_tool);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
|
|
|
|
/* initialize the statusbar display */
|
2007-12-15 01:22:46 +08:00
|
|
|
|
gimp_tool_push_status_coords (tool, tool->display,
|
2008-09-05 20:15:24 +08:00
|
|
|
|
GIMP_CURSOR_PRECISION_PIXEL_BORDER,
|
2008-01-01 07:36:01 +08:00
|
|
|
|
_("Rectangle: "), 0, " × ", 0, NULL);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), tool->display);
|
2007-04-01 00:38:55 +08:00
|
|
|
|
|
2007-12-27 01:33:41 +08:00
|
|
|
|
gimp_image_get_resolution (display->image, &xres, &yres);
|
|
|
|
|
|
2007-10-15 02:51:58 +08:00
|
|
|
|
if (options_private->fixed_width_entry)
|
2007-10-16 23:39:56 +08:00
|
|
|
|
{
|
2008-04-08 02:25:18 +08:00
|
|
|
|
GtkWidget *entry = options_private->fixed_width_entry;
|
|
|
|
|
|
|
|
|
|
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (entry), 0, xres, FALSE);
|
|
|
|
|
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (entry), 0,
|
|
|
|
|
0, gimp_image_get_width (display->image));
|
2007-10-16 23:39:56 +08:00
|
|
|
|
}
|
2007-10-15 02:51:58 +08:00
|
|
|
|
|
|
|
|
|
if (options_private->fixed_height_entry)
|
2007-10-16 23:39:56 +08:00
|
|
|
|
{
|
2008-04-08 02:25:18 +08:00
|
|
|
|
GtkWidget *entry = options_private->fixed_height_entry;
|
|
|
|
|
|
|
|
|
|
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (entry), 0, yres, FALSE);
|
|
|
|
|
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (entry), 0,
|
|
|
|
|
0, gimp_image_get_height (display->image));
|
2007-10-16 23:39:56 +08:00
|
|
|
|
}
|
2007-10-15 02:51:58 +08:00
|
|
|
|
|
2007-10-16 00:26:05 +08:00
|
|
|
|
if (options_private->x_entry)
|
2007-10-16 23:39:56 +08:00
|
|
|
|
{
|
2008-04-08 02:25:18 +08:00
|
|
|
|
GtkWidget *entry = options_private->x_entry;
|
|
|
|
|
|
|
|
|
|
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (entry), 0, xres, FALSE);
|
|
|
|
|
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (entry), 0,
|
|
|
|
|
0, gimp_image_get_width (display->image));
|
2007-10-16 23:39:56 +08:00
|
|
|
|
}
|
2007-10-16 00:26:05 +08:00
|
|
|
|
|
|
|
|
|
if (options_private->y_entry)
|
2007-10-16 23:39:56 +08:00
|
|
|
|
{
|
2008-04-08 02:25:18 +08:00
|
|
|
|
GtkWidget *entry = options_private->y_entry;
|
|
|
|
|
|
|
|
|
|
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (entry), 0, yres, FALSE);
|
|
|
|
|
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (entry), 0,
|
|
|
|
|
0, gimp_image_get_height (display->image));
|
2007-10-16 23:39:56 +08:00
|
|
|
|
}
|
2007-10-16 00:26:05 +08:00
|
|
|
|
|
|
|
|
|
if (options_private->width_entry)
|
2007-10-16 23:39:56 +08:00
|
|
|
|
{
|
2008-04-08 02:25:18 +08:00
|
|
|
|
GtkWidget *entry = options_private->width_entry;
|
|
|
|
|
|
|
|
|
|
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (entry), 0, xres, FALSE);
|
|
|
|
|
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (entry), 0,
|
|
|
|
|
0, gimp_image_get_width (display->image));
|
2007-10-16 23:39:56 +08:00
|
|
|
|
}
|
2007-10-16 00:26:05 +08:00
|
|
|
|
|
|
|
|
|
if (options_private->height_entry)
|
2007-10-16 23:39:56 +08:00
|
|
|
|
{
|
2008-04-08 02:25:18 +08:00
|
|
|
|
GtkWidget *entry = options_private->height_entry;
|
|
|
|
|
|
|
|
|
|
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (entry), 0, yres, FALSE);
|
|
|
|
|
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (entry), 0,
|
|
|
|
|
0, gimp_image_get_height (display->image));
|
2007-10-16 23:39:56 +08:00
|
|
|
|
}
|
2007-10-16 00:26:05 +08:00
|
|
|
|
|
2007-04-01 00:38:55 +08:00
|
|
|
|
if (options_private->auto_shrink_button)
|
|
|
|
|
{
|
|
|
|
|
g_signal_connect_swapped (options_private->auto_shrink_button, "clicked",
|
|
|
|
|
G_CALLBACK (gimp_rectangle_tool_auto_shrink),
|
2007-11-04 22:47:48 +08:00
|
|
|
|
rect_tool);
|
2007-04-01 00:38:55 +08:00
|
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (options_private->auto_shrink_button, TRUE);
|
|
|
|
|
}
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2006-11-06 00:36:15 +08:00
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_halt (GimpRectangleTool *rect_tool)
|
2005-03-03 02:18:19 +08:00
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
GimpTool *tool = GIMP_TOOL (rect_tool);
|
2007-04-01 00:38:55 +08:00
|
|
|
|
GimpRectangleOptionsPrivate *options_private;
|
|
|
|
|
|
|
|
|
|
options_private =
|
|
|
|
|
GIMP_RECTANGLE_OPTIONS_GET_PRIVATE (gimp_tool_get_options (tool));
|
2005-04-10 02:08:47 +08:00
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
if (tool->display)
|
2007-08-11 17:42:16 +08:00
|
|
|
|
{
|
2009-10-05 01:56:39 +08:00
|
|
|
|
GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
|
2008-04-08 02:25:18 +08:00
|
|
|
|
|
|
|
|
|
gimp_display_shell_set_highlight (shell, NULL);
|
2007-08-11 17:42:16 +08:00
|
|
|
|
|
2008-04-08 02:25:18 +08:00
|
|
|
|
g_signal_handlers_disconnect_by_func (shell,
|
2007-08-11 17:42:16 +08:00
|
|
|
|
gimp_rectangle_tool_shell_scrolled,
|
2007-11-04 22:47:48 +08:00
|
|
|
|
rect_tool);
|
2007-08-11 17:42:16 +08:00
|
|
|
|
}
|
2005-03-03 02:18:19 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
if (gimp_draw_tool_is_active (GIMP_DRAW_TOOL (rect_tool)))
|
|
|
|
|
gimp_draw_tool_stop (GIMP_DRAW_TOOL (rect_tool));
|
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
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
tool->display = NULL;
|
|
|
|
|
tool->drawable = NULL;
|
2005-03-09 07:17:19 +08:00
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
gimp_rectangle_tool_set_function (rect_tool, GIMP_RECTANGLE_TOOL_INACTIVE);
|
2007-04-01 00:38:55 +08:00
|
|
|
|
|
|
|
|
|
if (options_private->auto_shrink_button)
|
|
|
|
|
{
|
|
|
|
|
gtk_widget_set_sensitive (options_private->auto_shrink_button, FALSE);
|
|
|
|
|
|
|
|
|
|
g_signal_handlers_disconnect_by_func (options_private->auto_shrink_button,
|
|
|
|
|
gimp_rectangle_tool_auto_shrink,
|
2007-11-04 22:47:48 +08:00
|
|
|
|
rect_tool);
|
2007-04-01 00:38:55 +08:00
|
|
|
|
}
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-08-15 22:23:28 +08:00
|
|
|
|
gboolean
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_execute (GimpRectangleTool *rect_tool)
|
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
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
iface = GIMP_RECTANGLE_TOOL_GET_INTERFACE (rect_tool);
|
2005-09-04 03:48:22 +08:00
|
|
|
|
|
2006-06-06 01:14:16 +08:00
|
|
|
|
if (iface->execute)
|
|
|
|
|
{
|
2006-11-05 03:21:15 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2008-04-08 02:25:18 +08:00
|
|
|
|
gdouble pub_x1, pub_y1;
|
|
|
|
|
gdouble pub_x2, pub_y2;
|
2007-11-24 17:09:26 +08:00
|
|
|
|
|
|
|
|
|
gimp_rectangle_tool_get_public_rect (rect_tool,
|
|
|
|
|
&pub_x1, &pub_y1, &pub_x2, &pub_y2);
|
2006-06-06 01:14:16 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
2006-06-06 01:14:16 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (rect_tool));
|
2006-06-06 01:14:16 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
retval = iface->execute (rect_tool,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
pub_x1,
|
|
|
|
|
pub_y1,
|
|
|
|
|
pub_x2 - pub_x1,
|
|
|
|
|
pub_y2 - pub_y1);
|
2006-06-06 01:14:16 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_update_highlight (rect_tool);
|
2006-06-06 01:14:16 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (rect_tool));
|
2006-06-06 01:14:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_cancel (GimpRectangleTool *rect_tool)
|
2006-06-06 01:14:16 +08:00
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolInterface *iface;
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
iface = GIMP_RECTANGLE_TOOL_GET_INTERFACE (rect_tool);
|
2005-04-10 02:08:47 +08:00
|
|
|
|
|
2006-06-06 01:14:16 +08:00
|
|
|
|
if (iface->cancel)
|
2007-11-04 22:47:48 +08:00
|
|
|
|
iface->cancel (rect_tool);
|
2005-03-03 02:18:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2005-03-09 07:17:19 +08:00
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_update_options (GimpRectangleTool *rect_tool,
|
2006-03-29 01:55:52 +08:00
|
|
|
|
GimpDisplay *display)
|
2005-03-09 07:17:19 +08:00
|
|
|
|
{
|
2007-10-31 18:36:03 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
GimpRectangleOptions *options;
|
2008-04-08 02:25:18 +08:00
|
|
|
|
gdouble pub_x1, pub_y1;
|
|
|
|
|
gdouble pub_x2, pub_y2;
|
2007-10-31 18:36:03 +08:00
|
|
|
|
gdouble width;
|
|
|
|
|
gdouble height;
|
2007-04-01 00:38:55 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
|
|
|
|
options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (rect_tool);
|
2005-03-11 07:55:24 +08:00
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gimp_rectangle_tool_get_public_rect (rect_tool,
|
|
|
|
|
&pub_x1, &pub_y1, &pub_x2, &pub_y2);
|
|
|
|
|
width = pub_x2 - pub_x1;
|
|
|
|
|
height = pub_y2 - pub_y1;
|
2005-03-09 07:17:19 +08:00
|
|
|
|
|
2006-11-05 06:39:37 +08:00
|
|
|
|
g_signal_handlers_block_by_func (options,
|
|
|
|
|
gimp_rectangle_tool_options_notify,
|
2007-11-04 22:47:48 +08:00
|
|
|
|
rect_tool);
|
2006-09-23 02:27:21 +08:00
|
|
|
|
|
|
|
|
|
g_object_set (options,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
"x", pub_x1,
|
|
|
|
|
"y", pub_y1,
|
2006-09-23 02:27:21 +08:00
|
|
|
|
NULL);
|
2005-03-11 07:55:24 +08:00
|
|
|
|
|
2007-08-05 04:20:44 +08:00
|
|
|
|
g_object_set (options,
|
|
|
|
|
"width", width,
|
|
|
|
|
NULL);
|
2005-11-30 07:32:55 +08:00
|
|
|
|
|
2007-08-05 04:20:44 +08:00
|
|
|
|
g_object_set (options,
|
|
|
|
|
"height", height,
|
|
|
|
|
NULL);
|
2005-11-30 07:32:55 +08:00
|
|
|
|
|
2007-07-09 05:57:22 +08:00
|
|
|
|
g_signal_handlers_unblock_by_func (options,
|
|
|
|
|
gimp_rectangle_tool_options_notify,
|
2007-11-04 22:47:48 +08:00
|
|
|
|
rect_tool);
|
2005-03-09 07:17:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-23 02:27:21 +08:00
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_synthesize_motion (GimpRectangleTool *rect_tool,
|
2007-04-01 00:38:55 +08:00
|
|
|
|
gint function,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble new_x,
|
|
|
|
|
gdouble new_y)
|
2006-09-23 02:27:21 +08:00
|
|
|
|
{
|
2008-07-28 03:06:10 +08:00
|
|
|
|
GimpTool *tool;
|
|
|
|
|
GimpDrawTool *draw_tool;
|
2006-09-23 02:27:21 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2006-12-31 02:18:53 +08:00
|
|
|
|
GimpRectangleFunction old_function;
|
2006-09-23 02:27:21 +08:00
|
|
|
|
|
2008-07-28 03:06:10 +08:00
|
|
|
|
tool = GIMP_TOOL (rect_tool);
|
|
|
|
|
draw_tool = GIMP_DRAW_TOOL (rect_tool);
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
|
|
|
|
|
2008-05-11 03:19:47 +08:00
|
|
|
|
/* We don't want to synthesize motions if the tool control is active
|
|
|
|
|
* since that means the mouse button is down and the rectangle will
|
|
|
|
|
* get updated in _motion anyway. The reason we want to prevent this
|
2008-07-28 03:06:10 +08:00
|
|
|
|
* function from executing is that is emits the
|
|
|
|
|
* rectangle-changed-complete signal which we don't want in the
|
|
|
|
|
* middle of a rectangle change.
|
|
|
|
|
*
|
|
|
|
|
* In addition to that, we don't want to synthesize a motion if
|
|
|
|
|
* there is no pending rectangle because that doesn't make any
|
|
|
|
|
* sense.
|
2008-05-11 03:19:47 +08:00
|
|
|
|
*/
|
2008-07-28 03:06:10 +08:00
|
|
|
|
if (gimp_tool_control_is_active (tool->control) ||
|
|
|
|
|
! tool->display)
|
2008-07-12 17:07:04 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2006-12-31 02:18:53 +08:00
|
|
|
|
old_function = private->function;
|
|
|
|
|
|
2008-07-28 03:06:10 +08:00
|
|
|
|
gimp_draw_tool_pause (draw_tool);
|
2006-11-16 04:45:43 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_set_function (rect_tool, function);
|
2006-12-31 02:18:53 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_update_with_coord (rect_tool,
|
2007-07-09 05:57:22 +08:00
|
|
|
|
new_x,
|
|
|
|
|
new_y);
|
2006-11-05 03:21:15 +08:00
|
|
|
|
|
2007-07-09 05:57:22 +08:00
|
|
|
|
/* We must update this. */
|
|
|
|
|
private->center_x_on_fixed_center = (private->x1 + private->x2) / 2;
|
|
|
|
|
private->center_y_on_fixed_center = (private->y1 + private->y2) / 2;
|
2006-09-23 02:27:21 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_update_options (rect_tool,
|
2008-07-28 03:06:10 +08:00
|
|
|
|
tool->display);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_set_function (rect_tool, old_function);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_update_highlight (rect_tool);
|
2007-12-15 01:22:46 +08:00
|
|
|
|
gimp_rectangle_tool_update_handle_sizes (rect_tool);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2008-07-28 03:06:10 +08:00
|
|
|
|
gimp_draw_tool_resume (draw_tool);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2008-05-02 17:05:13 +08:00
|
|
|
|
gimp_rectangle_tool_rectangle_change_complete (rect_tool);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2006-11-05 06:39:37 +08:00
|
|
|
|
gimp_rectangle_tool_options_notify (GimpRectangleOptions *options,
|
|
|
|
|
GParamSpec *pspec,
|
2007-11-04 22:47:48 +08:00
|
|
|
|
GimpRectangleTool *rect_tool)
|
2006-09-23 02:27:21 +08:00
|
|
|
|
{
|
2008-04-26 18:54:34 +08:00
|
|
|
|
GimpTool *tool;
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
2007-04-01 00:38:55 +08:00
|
|
|
|
GimpRectangleOptionsPrivate *options_private;
|
2006-09-23 02:27:21 +08:00
|
|
|
|
|
2008-04-26 19:14:19 +08:00
|
|
|
|
tool = GIMP_TOOL (rect_tool);
|
2008-04-26 18:54:34 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2007-04-01 00:38:55 +08:00
|
|
|
|
options_private = GIMP_RECTANGLE_OPTIONS_GET_PRIVATE (options);
|
2006-09-23 02:27:21 +08:00
|
|
|
|
|
2008-04-26 18:54:34 +08:00
|
|
|
|
if (strcmp (pspec->name, "guide") == 0)
|
2006-11-05 06:39:37 +08:00
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (rect_tool));
|
2006-09-23 02:27:21 +08:00
|
|
|
|
|
2007-04-01 00:38:55 +08:00
|
|
|
|
private->guide = options_private->guide;
|
2006-09-23 02:27:21 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (rect_tool));
|
2006-11-05 06:39:37 +08:00
|
|
|
|
}
|
2008-04-26 18:54:34 +08:00
|
|
|
|
else if (strcmp (pspec->name, "x") == 0 &&
|
2008-11-11 04:10:50 +08:00
|
|
|
|
!PIXEL_FEQUAL (private->x1, options_private->x))
|
2006-11-05 06:39:37 +08:00
|
|
|
|
{
|
2008-04-26 18:38:53 +08:00
|
|
|
|
gimp_rectangle_tool_synthesize_motion (rect_tool,
|
|
|
|
|
GIMP_RECTANGLE_TOOL_MOVING,
|
|
|
|
|
options_private->x,
|
|
|
|
|
private->y1);
|
2006-11-05 06:39:37 +08:00
|
|
|
|
}
|
2008-04-26 18:54:34 +08:00
|
|
|
|
else if (strcmp (pspec->name, "y") == 0 &&
|
2008-11-11 04:10:50 +08:00
|
|
|
|
!PIXEL_FEQUAL (private->y1, options_private->y))
|
2006-11-05 06:39:37 +08:00
|
|
|
|
{
|
2008-04-26 18:38:53 +08:00
|
|
|
|
gimp_rectangle_tool_synthesize_motion (rect_tool,
|
|
|
|
|
GIMP_RECTANGLE_TOOL_MOVING,
|
|
|
|
|
private->x1,
|
|
|
|
|
options_private->y);
|
2006-11-05 06:39:37 +08:00
|
|
|
|
}
|
2008-04-26 18:54:34 +08:00
|
|
|
|
else if (strcmp (pspec->name, "width") == 0 &&
|
2008-11-11 04:10:50 +08:00
|
|
|
|
!PIXEL_FEQUAL (private->x2 - private->x1, options_private->width))
|
2006-11-05 06:39:37 +08:00
|
|
|
|
{
|
2007-07-09 05:57:22 +08:00
|
|
|
|
/* Calculate x2, y2 that will create a rectangle of given width, for the
|
|
|
|
|
* current options.
|
|
|
|
|
*/
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble x2;
|
2005-10-22 04:17:19 +08:00
|
|
|
|
|
2008-04-26 18:38:53 +08:00
|
|
|
|
if (options_private->fixed_center)
|
2007-07-09 05:57:22 +08:00
|
|
|
|
{
|
2008-04-26 18:38:53 +08:00
|
|
|
|
x2 = private->center_x_on_fixed_center +
|
|
|
|
|
options_private->width / 2;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
x2 = private->x1 + options_private->width;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
}
|
2008-04-26 18:38:53 +08:00
|
|
|
|
|
|
|
|
|
gimp_rectangle_tool_synthesize_motion (rect_tool,
|
|
|
|
|
GIMP_RECTANGLE_TOOL_RESIZING_RIGHT,
|
|
|
|
|
x2,
|
|
|
|
|
private->y2);
|
2006-11-05 06:39:37 +08:00
|
|
|
|
}
|
2008-04-26 18:54:34 +08:00
|
|
|
|
else if (strcmp (pspec->name, "height") == 0 &&
|
2008-11-11 04:10:50 +08:00
|
|
|
|
!PIXEL_FEQUAL (private->y2 - private->y1, options_private->height))
|
2006-11-05 06:39:37 +08:00
|
|
|
|
{
|
2007-07-09 05:57:22 +08:00
|
|
|
|
/* Calculate x2, y2 that will create a rectangle of given height, for the
|
|
|
|
|
* current options.
|
|
|
|
|
*/
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble y2;
|
2006-03-25 17:38:59 +08:00
|
|
|
|
|
2008-04-26 18:38:53 +08:00
|
|
|
|
if (options_private->fixed_center)
|
2007-07-09 05:57:22 +08:00
|
|
|
|
{
|
2008-04-26 18:38:53 +08:00
|
|
|
|
y2 = private->center_y_on_fixed_center +
|
|
|
|
|
options_private->height / 2;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
}
|
2008-04-26 18:38:53 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
y2 = private->y1 + options_private->height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gimp_rectangle_tool_synthesize_motion (rect_tool,
|
|
|
|
|
GIMP_RECTANGLE_TOOL_RESIZING_BOTTOM,
|
|
|
|
|
private->x2,
|
|
|
|
|
y2);
|
2006-11-05 06:39:37 +08:00
|
|
|
|
}
|
2008-04-26 18:38:53 +08:00
|
|
|
|
else if (strcmp (pspec->name, "desired-fixed-size-width") == 0)
|
2007-10-14 16:26:18 +08:00
|
|
|
|
{
|
|
|
|
|
/* We are only interested in when width and height swaps, so
|
|
|
|
|
* it's enough to only check e.g. for width.
|
|
|
|
|
*/
|
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble width = private->x2 - private->x1;
|
|
|
|
|
gdouble height = private->y2 - private->y1;
|
2007-10-14 16:26:18 +08:00
|
|
|
|
|
|
|
|
|
/* Depending on a bunch of conditions, we might want to
|
|
|
|
|
* immedieately switch width and height of the pending
|
|
|
|
|
* rectangle.
|
|
|
|
|
*/
|
2008-04-24 13:55:59 +08:00
|
|
|
|
if (options_private->fixed_rule_active &&
|
|
|
|
|
tool->display != NULL &&
|
|
|
|
|
tool->button_press_state == 0 &&
|
|
|
|
|
tool->active_modifier_state == 0 &&
|
|
|
|
|
FEQUAL (options_private->desired_fixed_size_width, height) &&
|
|
|
|
|
FEQUAL (options_private->desired_fixed_size_height, width))
|
2007-10-14 16:26:18 +08:00
|
|
|
|
{
|
|
|
|
|
gdouble x = private->x1;
|
|
|
|
|
gdouble y = private->y1;
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_synthesize_motion (rect_tool,
|
2007-11-24 17:27:55 +08:00
|
|
|
|
GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT,
|
2007-10-14 16:26:18 +08:00
|
|
|
|
private->x2,
|
|
|
|
|
private->y2);
|
|
|
|
|
|
|
|
|
|
/* For some reason these needs to be set separately... */
|
|
|
|
|
g_object_set (options,
|
2007-10-15 03:48:56 +08:00
|
|
|
|
"x", x,
|
2007-10-14 16:26:18 +08:00
|
|
|
|
NULL);
|
|
|
|
|
g_object_set (options,
|
2007-10-15 03:48:56 +08:00
|
|
|
|
"y", y,
|
2007-10-14 16:26:18 +08:00
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-26 18:38:53 +08:00
|
|
|
|
else if (strcmp (pspec->name, "aspect-numerator") == 0)
|
2007-10-14 16:26:18 +08:00
|
|
|
|
{
|
|
|
|
|
/* We are only interested in when numerator and denominator
|
|
|
|
|
* swaps, so it's enough to only check e.g. for numerator.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
double width = private->x2 - private->x1;
|
|
|
|
|
double height = private->y2 - private->y1;
|
|
|
|
|
gdouble new_inverse_ratio = options_private->aspect_denominator /
|
|
|
|
|
options_private->aspect_numerator;
|
|
|
|
|
gdouble lower_ratio;
|
|
|
|
|
gdouble higher_ratio;
|
|
|
|
|
|
|
|
|
|
/* The ratio of the Fixed: Aspect ratio rule and the pending
|
|
|
|
|
* rectangle is very rarely exactly the same so use an
|
|
|
|
|
* interval. For small rectangles the below code will
|
|
|
|
|
* automatically yield a more generous accepted ratio interval
|
|
|
|
|
* which is exactly what we want.
|
|
|
|
|
*/
|
|
|
|
|
if (width > height && height > 1.0)
|
|
|
|
|
{
|
|
|
|
|
lower_ratio = width / (height + 1.0);
|
|
|
|
|
higher_ratio = width / (height - 1.0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
lower_ratio = (width - 1.0) / height;
|
|
|
|
|
higher_ratio = (width + 1.0) / height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Depending on a bunch of conditions, we might want to
|
|
|
|
|
* immedieately switch width and height of the pending
|
|
|
|
|
* rectangle.
|
|
|
|
|
*/
|
|
|
|
|
if (options_private->fixed_rule_active &&
|
2007-12-15 01:22:46 +08:00
|
|
|
|
tool->display != NULL &&
|
2007-10-14 16:26:18 +08:00
|
|
|
|
tool->button_press_state == 0 &&
|
|
|
|
|
tool->active_modifier_state == 0 &&
|
|
|
|
|
lower_ratio < new_inverse_ratio &&
|
|
|
|
|
higher_ratio > new_inverse_ratio)
|
|
|
|
|
{
|
|
|
|
|
gdouble new_x2 = private->x1 + private->y2 - private->y1;
|
|
|
|
|
gdouble new_y2 = private->y1 + private->x2 - private->x1;
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_synthesize_motion (rect_tool,
|
2007-11-24 17:27:55 +08:00
|
|
|
|
GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT,
|
2007-10-14 16:26:18 +08:00
|
|
|
|
new_x2,
|
|
|
|
|
new_y2);
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-04-26 18:38:53 +08:00
|
|
|
|
else if (strcmp (pspec->name, "highlight") == 0)
|
2006-06-07 02:07:04 +08:00
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_update_highlight (rect_tool);
|
2006-11-05 06:39:37 +08:00
|
|
|
|
}
|
2006-06-07 05:06:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
2007-08-11 17:42:16 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_rectangle_tool_shell_scrolled (GimpDisplayShell *shell,
|
2007-11-04 22:47:48 +08:00
|
|
|
|
GimpRectangleTool *rect_tool)
|
2007-08-11 17:42:16 +08:00
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (rect_tool);
|
2007-08-11 17:42:16 +08:00
|
|
|
|
|
|
|
|
|
gimp_draw_tool_pause (draw_tool);
|
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
gimp_rectangle_tool_update_handle_sizes (rect_tool);
|
2007-08-11 17:42:16 +08:00
|
|
|
|
|
|
|
|
|
gimp_draw_tool_resume (draw_tool);
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-16 04:45:43 +08:00
|
|
|
|
GimpRectangleFunction
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_get_function (GimpRectangleTool *rect_tool)
|
2006-11-16 04:45:43 +08:00
|
|
|
|
{
|
2008-04-08 02:25:18 +08:00
|
|
|
|
g_return_val_if_fail (GIMP_IS_RECTANGLE_TOOL (rect_tool),
|
|
|
|
|
GIMP_RECTANGLE_TOOL_INACTIVE);
|
2006-11-16 04:45:43 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
return GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool)->function;
|
2006-11-16 04:45:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_set_function (GimpRectangleTool *rect_tool,
|
2006-11-16 04:45:43 +08:00
|
|
|
|
GimpRectangleFunction function)
|
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (rect_tool));
|
2006-11-16 04:45:43 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
2006-11-16 04:45:43 +08:00
|
|
|
|
|
|
|
|
|
/* redraw the tool when the function changes */
|
|
|
|
|
/* FIXME: should also update the cursor */
|
|
|
|
|
if (private->function != function)
|
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (rect_tool);
|
2006-11-16 04:45:43 +08:00
|
|
|
|
|
|
|
|
|
gimp_draw_tool_pause (draw_tool);
|
|
|
|
|
|
|
|
|
|
private->function = function;
|
|
|
|
|
|
|
|
|
|
gimp_draw_tool_resume (draw_tool);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-28 21:08:09 +08:00
|
|
|
|
static void
|
2008-05-02 17:05:13 +08:00
|
|
|
|
gimp_rectangle_tool_rectangle_change_complete (GimpRectangleTool *rect_tool)
|
2007-02-28 21:08:09 +08:00
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
g_signal_emit (rect_tool,
|
2008-05-02 17:05:13 +08:00
|
|
|
|
gimp_rectangle_tool_signals[RECTANGLE_CHANGE_COMPLETE], 0);
|
2007-02-28 21:08:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-24 04:45:06 +08:00
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_auto_shrink (GimpRectangleTool *rect_tool)
|
2006-09-24 04:45:06 +08:00
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
GimpTool *tool = GIMP_TOOL (rect_tool);
|
2007-10-31 18:36:03 +08:00
|
|
|
|
GimpRectangleToolPrivate *private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
2007-12-15 01:22:46 +08:00
|
|
|
|
GimpDisplay *display = tool->display;
|
2006-11-05 03:21:15 +08:00
|
|
|
|
gint width;
|
|
|
|
|
gint height;
|
|
|
|
|
gint offset_x = 0;
|
|
|
|
|
gint offset_y = 0;
|
|
|
|
|
gint x1, y1;
|
|
|
|
|
gint x2, y2;
|
|
|
|
|
gint shrunk_x1;
|
|
|
|
|
gint shrunk_y1;
|
|
|
|
|
gint shrunk_x2;
|
|
|
|
|
gint shrunk_y2;
|
|
|
|
|
gboolean shrink_merged;
|
|
|
|
|
|
2006-09-24 04:45:06 +08:00
|
|
|
|
if (! display)
|
|
|
|
|
return;
|
|
|
|
|
|
2007-12-26 00:21:40 +08:00
|
|
|
|
width = gimp_image_get_width (display->image);
|
|
|
|
|
height = gimp_image_get_height (display->image);
|
2006-09-24 04:45:06 +08:00
|
|
|
|
|
|
|
|
|
g_object_get (gimp_tool_get_options (tool),
|
|
|
|
|
"shrink-merged", &shrink_merged,
|
|
|
|
|
NULL);
|
|
|
|
|
|
2006-11-05 03:21:15 +08:00
|
|
|
|
x1 = private->x1 - offset_x > 0 ? private->x1 - offset_x : 0;
|
|
|
|
|
x2 = private->x2 - offset_x < width ? private->x2 - offset_x : width;
|
|
|
|
|
y1 = private->y1 - offset_y > 0 ? private->y1 - offset_y : 0;
|
|
|
|
|
y2 = private->y2 - offset_y < height ? private->y2 - offset_y : height;
|
2006-09-24 04:45:06 +08:00
|
|
|
|
|
|
|
|
|
if (gimp_image_crop_auto_shrink (display->image,
|
|
|
|
|
x1, y1, x2, y2,
|
|
|
|
|
! shrink_merged,
|
|
|
|
|
&shrunk_x1,
|
|
|
|
|
&shrunk_y1,
|
|
|
|
|
&shrunk_x2,
|
|
|
|
|
&shrunk_y2))
|
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (rect_tool));
|
2006-09-24 04:45:06 +08:00
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
private->x1 = offset_x + shrunk_x1;
|
|
|
|
|
private->y1 = offset_x + shrunk_y1;
|
|
|
|
|
private->x2 = offset_x + shrunk_x2;
|
|
|
|
|
private->y2 = offset_x + shrunk_y2;
|
|
|
|
|
|
|
|
|
|
gimp_rectangle_tool_update_int_rect (rect_tool);
|
2006-09-24 04:45:06 +08:00
|
|
|
|
|
2008-05-02 17:05:13 +08:00
|
|
|
|
gimp_rectangle_tool_rectangle_change_complete (rect_tool);
|
2007-09-07 04:38:11 +08:00
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
gimp_rectangle_tool_update_handle_sizes (rect_tool);
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_update_highlight (rect_tool);
|
2006-09-24 04:45:06 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (rect_tool));
|
2006-09-24 04:45:06 +08:00
|
|
|
|
}
|
2007-08-05 18:28:19 +08:00
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
gimp_rectangle_tool_update_options (rect_tool, tool->display);
|
2006-09-24 04:45:06 +08:00
|
|
|
|
}
|
2006-11-07 00:40:09 +08:00
|
|
|
|
|
2007-10-27 04:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_coord_outside:
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the coord is outside the rectange bounds
|
|
|
|
|
* including any outside handles.
|
|
|
|
|
*/
|
|
|
|
|
static gboolean
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_coord_outside (GimpRectangleTool *rect_tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
|
const GimpCoords *coord)
|
2007-10-27 04:58:08 +08:00
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
2007-11-04 22:10:56 +08:00
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
|
gboolean narrow_mode;
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble pub_x1, pub_y1, pub_x2, pub_y2;
|
|
|
|
|
gdouble x1_b, y1_b, x2_b, y2_b;
|
2007-11-04 22:10:56 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
2007-11-04 22:10:56 +08:00
|
|
|
|
narrow_mode = private->narrow_mode;
|
2009-10-05 01:56:39 +08:00
|
|
|
|
shell = gimp_display_get_shell (GIMP_TOOL (rect_tool)->display);
|
2007-10-27 04:58:08 +08:00
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gimp_rectangle_tool_get_public_rect (rect_tool,
|
|
|
|
|
&pub_x1, &pub_y1, &pub_x2, &pub_y2);
|
2007-10-27 04:58:08 +08:00
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
x1_b = pub_x1 - (narrow_mode ? private->corner_handle_w / shell->scale_x : 0);
|
|
|
|
|
x2_b = pub_x2 + (narrow_mode ? private->corner_handle_w / shell->scale_x : 0);
|
|
|
|
|
y1_b = pub_y1 - (narrow_mode ? private->corner_handle_h / shell->scale_y : 0);
|
|
|
|
|
y2_b = pub_y2 + (narrow_mode ? private->corner_handle_h / shell->scale_y : 0);
|
|
|
|
|
|
2008-07-12 17:07:04 +08:00
|
|
|
|
return (coord->x < x1_b ||
|
|
|
|
|
coord->x > x2_b ||
|
|
|
|
|
coord->y < y1_b ||
|
|
|
|
|
coord->y > y2_b);
|
2007-10-27 04:58:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_coord_on_handle:
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the coord is on the handle that corresponds to
|
|
|
|
|
* @anchor.
|
|
|
|
|
*/
|
|
|
|
|
static gboolean
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_coord_on_handle (GimpRectangleTool *rect_tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
|
const GimpCoords *coords,
|
2007-10-27 04:58:08 +08:00
|
|
|
|
GtkAnchorType anchor)
|
|
|
|
|
{
|
2007-11-24 17:09:26 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
|
GimpDrawTool *draw_tool;
|
|
|
|
|
GimpTool *tool;
|
|
|
|
|
gdouble pub_x1, pub_y1, pub_x2, pub_y2;
|
|
|
|
|
gdouble rect_w, rect_h;
|
2007-11-28 03:28:38 +08:00
|
|
|
|
gdouble handle_x = 0;
|
|
|
|
|
gdouble handle_y = 0;
|
|
|
|
|
gdouble handle_width = 0;
|
|
|
|
|
gdouble handle_height = 0;
|
|
|
|
|
gint narrow_mode_x_dir = 0;
|
|
|
|
|
gint narrow_mode_y_dir = 0;
|
2007-11-24 17:09:26 +08:00
|
|
|
|
|
|
|
|
|
tool = GIMP_TOOL (rect_tool);
|
|
|
|
|
draw_tool = GIMP_DRAW_TOOL (tool);
|
2009-10-05 01:56:39 +08:00
|
|
|
|
shell = gimp_display_get_shell (tool->display);
|
2007-11-24 17:09:26 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
|
|
|
|
|
|
|
|
|
gimp_rectangle_tool_get_public_rect (rect_tool,
|
|
|
|
|
&pub_x1, &pub_y1, &pub_x2, &pub_y2);
|
2007-10-27 04:58:08 +08:00
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
rect_w = pub_x2 - pub_x1;
|
|
|
|
|
rect_h = pub_y2 - pub_y1;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
|
|
|
|
|
switch (anchor)
|
|
|
|
|
{
|
|
|
|
|
case GTK_ANCHOR_NORTH_WEST:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
handle_x = pub_x1;
|
|
|
|
|
handle_y = pub_y1;
|
2007-10-27 05:07:45 +08:00
|
|
|
|
handle_width = private->corner_handle_w;
|
|
|
|
|
handle_height = private->corner_handle_h;
|
2007-11-04 22:10:56 +08:00
|
|
|
|
|
|
|
|
|
narrow_mode_x_dir = -1;
|
|
|
|
|
narrow_mode_y_dir = -1;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GTK_ANCHOR_SOUTH_EAST:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
handle_x = pub_x2;
|
|
|
|
|
handle_y = pub_y2;
|
2007-10-27 05:07:45 +08:00
|
|
|
|
handle_width = private->corner_handle_w;
|
|
|
|
|
handle_height = private->corner_handle_h;
|
2007-11-04 22:10:56 +08:00
|
|
|
|
|
|
|
|
|
narrow_mode_x_dir = 1;
|
|
|
|
|
narrow_mode_y_dir = 1;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GTK_ANCHOR_NORTH_EAST:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
handle_x = pub_x2;
|
|
|
|
|
handle_y = pub_y1;
|
2007-10-27 05:07:45 +08:00
|
|
|
|
handle_width = private->corner_handle_w;
|
|
|
|
|
handle_height = private->corner_handle_h;
|
2007-11-04 22:10:56 +08:00
|
|
|
|
|
|
|
|
|
narrow_mode_x_dir = 1;
|
|
|
|
|
narrow_mode_y_dir = -1;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GTK_ANCHOR_SOUTH_WEST:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
handle_x = pub_x1;
|
|
|
|
|
handle_y = pub_y2;
|
2007-10-27 05:07:45 +08:00
|
|
|
|
handle_width = private->corner_handle_w;
|
|
|
|
|
handle_height = private->corner_handle_h;
|
2007-11-04 22:10:56 +08:00
|
|
|
|
|
|
|
|
|
narrow_mode_x_dir = -1;
|
|
|
|
|
narrow_mode_y_dir = 1;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GTK_ANCHOR_WEST:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
handle_x = pub_x1;
|
|
|
|
|
handle_y = pub_y1 + rect_h / 2;
|
2007-10-27 05:07:45 +08:00
|
|
|
|
handle_width = private->corner_handle_w;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
handle_height = private->left_and_right_handle_h;
|
2007-11-04 22:10:56 +08:00
|
|
|
|
|
|
|
|
|
narrow_mode_x_dir = -1;
|
|
|
|
|
narrow_mode_y_dir = 0;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GTK_ANCHOR_EAST:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
handle_x = pub_x2;
|
|
|
|
|
handle_y = pub_y1 + rect_h / 2;
|
2007-10-27 05:07:45 +08:00
|
|
|
|
handle_width = private->corner_handle_w;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
handle_height = private->left_and_right_handle_h;
|
2007-11-04 22:10:56 +08:00
|
|
|
|
|
|
|
|
|
narrow_mode_x_dir = 1;
|
|
|
|
|
narrow_mode_y_dir = 0;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GTK_ANCHOR_NORTH:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
handle_x = pub_x1 + rect_w / 2;
|
|
|
|
|
handle_y = pub_y1;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
handle_width = private->top_and_bottom_handle_w;
|
2007-10-27 05:07:45 +08:00
|
|
|
|
handle_height = private->corner_handle_h;
|
2007-11-04 22:10:56 +08:00
|
|
|
|
|
|
|
|
|
narrow_mode_x_dir = 0;
|
|
|
|
|
narrow_mode_y_dir = -1;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GTK_ANCHOR_SOUTH:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
handle_x = pub_x1 + rect_w / 2;
|
|
|
|
|
handle_y = pub_y2;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
handle_width = private->top_and_bottom_handle_w;
|
2007-10-27 05:07:45 +08:00
|
|
|
|
handle_height = private->corner_handle_h;
|
2007-11-04 22:10:56 +08:00
|
|
|
|
|
|
|
|
|
narrow_mode_x_dir = 0;
|
|
|
|
|
narrow_mode_y_dir = 1;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GTK_ANCHOR_CENTER:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
handle_x = pub_x1 + rect_w / 2;
|
|
|
|
|
handle_y = pub_y1 + rect_h / 2;
|
2007-11-04 22:10:56 +08:00
|
|
|
|
|
|
|
|
|
if (private->narrow_mode)
|
|
|
|
|
{
|
|
|
|
|
handle_width = rect_w * shell->scale_x;
|
|
|
|
|
handle_height = rect_h * shell->scale_y;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
handle_width = rect_w * shell->scale_x - private->corner_handle_w * 2;
|
|
|
|
|
handle_height = rect_h * shell->scale_y - private->corner_handle_h * 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
narrow_mode_x_dir = 0;
|
|
|
|
|
narrow_mode_y_dir = 0;
|
2007-10-27 04:58:08 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-04 22:10:56 +08:00
|
|
|
|
if (private->narrow_mode)
|
|
|
|
|
{
|
|
|
|
|
handle_x += narrow_mode_x_dir * handle_width / shell->scale_x;
|
|
|
|
|
handle_y += narrow_mode_y_dir * handle_height / shell->scale_y;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
return gimp_draw_tool_on_handle (draw_tool, shell->display,
|
2007-10-27 04:58:08 +08:00
|
|
|
|
coords->x, coords->y,
|
|
|
|
|
GIMP_HANDLE_SQUARE,
|
|
|
|
|
handle_x, handle_y,
|
|
|
|
|
handle_width, handle_height,
|
|
|
|
|
anchor,
|
|
|
|
|
FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
2006-11-07 00:40:09 +08:00
|
|
|
|
static GtkAnchorType
|
2007-07-01 02:13:41 +08:00
|
|
|
|
gimp_rectangle_tool_get_anchor (GimpRectangleToolPrivate *private)
|
2006-11-07 00:40:09 +08:00
|
|
|
|
{
|
|
|
|
|
switch (private->function)
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_LEFT:
|
2006-11-07 00:40:09 +08:00
|
|
|
|
return GTK_ANCHOR_NORTH_WEST;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_RIGHT:
|
2006-11-07 00:40:09 +08:00
|
|
|
|
return GTK_ANCHOR_NORTH_EAST;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_LEFT:
|
2006-11-07 00:40:09 +08:00
|
|
|
|
return GTK_ANCHOR_SOUTH_WEST;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT:
|
2006-11-07 00:40:09 +08:00
|
|
|
|
return GTK_ANCHOR_SOUTH_EAST;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LEFT:
|
2006-11-07 00:40:09 +08:00
|
|
|
|
return GTK_ANCHOR_WEST;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_RIGHT:
|
2006-11-07 00:40:09 +08:00
|
|
|
|
return GTK_ANCHOR_EAST;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_TOP:
|
2006-11-07 00:40:09 +08:00
|
|
|
|
return GTK_ANCHOR_NORTH;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_BOTTOM:
|
2006-11-07 00:40:09 +08:00
|
|
|
|
return GTK_ANCHOR_SOUTH;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return GTK_ANCHOR_CENTER;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-02-09 07:19:57 +08:00
|
|
|
|
|
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_update_highlight (GimpRectangleTool *rect_tool)
|
2007-02-09 07:19:57 +08:00
|
|
|
|
{
|
2007-11-05 05:26:01 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
GimpTool *tool;
|
|
|
|
|
GimpRectangleOptions *options;
|
|
|
|
|
GimpDisplayShell *shell;
|
|
|
|
|
gboolean highlight;
|
|
|
|
|
|
|
|
|
|
tool = GIMP_TOOL (rect_tool);
|
|
|
|
|
options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (tool);
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
|
|
|
|
highlight = FALSE;
|
2007-02-09 07:19:57 +08:00
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
if (! tool->display)
|
2007-07-15 04:15:08 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2009-10-05 01:56:39 +08:00
|
|
|
|
shell = gimp_display_get_shell (tool->display);
|
2007-07-15 04:15:08 +08:00
|
|
|
|
|
2007-02-09 07:19:57 +08:00
|
|
|
|
g_object_get (options, "highlight", &highlight, NULL);
|
|
|
|
|
|
2007-11-05 05:26:01 +08:00
|
|
|
|
/* Don't show the highlight when the mouse is down. */
|
2007-11-06 04:17:56 +08:00
|
|
|
|
if (! highlight || private->rect_adjusting)
|
2007-11-05 05:26:01 +08:00
|
|
|
|
{
|
|
|
|
|
gimp_display_shell_set_highlight (shell, NULL);
|
|
|
|
|
}
|
|
|
|
|
else
|
2007-02-09 07:19:57 +08:00
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
GdkRectangle rect;
|
2008-04-08 02:25:18 +08:00
|
|
|
|
gdouble pub_x1, pub_y1;
|
|
|
|
|
gdouble pub_x2, pub_y2;
|
2007-02-09 07:19:57 +08:00
|
|
|
|
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
|
|
|
|
|
2007-12-29 03:21:35 +08:00
|
|
|
|
gimp_rectangle_tool_get_public_rect (rect_tool,
|
|
|
|
|
&pub_x1, &pub_y1, &pub_x2, &pub_y2);
|
|
|
|
|
|
|
|
|
|
rect.x = pub_x1;
|
|
|
|
|
rect.y = pub_y1;
|
|
|
|
|
rect.width = pub_x2 - pub_x1;
|
|
|
|
|
rect.height = pub_y2 - pub_y1;
|
2007-02-09 07:19:57 +08:00
|
|
|
|
|
|
|
|
|
gimp_display_shell_set_highlight (shell, &rect);
|
|
|
|
|
}
|
2007-11-05 05:26:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gimp_rectangle_tool_rect_rubber_banding_func (GimpRectangleTool *rect_tool)
|
2007-11-05 05:26:01 +08:00
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gboolean rect_rubber_banding_func;
|
2007-11-05 05:26:01 +08:00
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
rect_rubber_banding_func = FALSE;
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
2007-11-05 05:26:01 +08:00
|
|
|
|
|
|
|
|
|
switch (private->function)
|
2007-02-09 07:19:57 +08:00
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_CREATING:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_RIGHT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_TOP:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_BOTTOM:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_RIGHT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
rect_rubber_banding_func = TRUE;
|
2007-11-05 05:26:01 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_MOVING:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_INACTIVE:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_DEAD:
|
2007-11-05 05:26:01 +08:00
|
|
|
|
default:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
rect_rubber_banding_func = FALSE;
|
2007-11-05 05:26:01 +08:00
|
|
|
|
break;
|
2007-02-09 07:19:57 +08:00
|
|
|
|
}
|
2007-11-05 05:26:01 +08:00
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
return rect_rubber_banding_func;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_rect_adjusting_func:
|
|
|
|
|
* @rect_tool:
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the current function is a rectangle adjusting
|
|
|
|
|
* function.
|
|
|
|
|
*/
|
|
|
|
|
static gboolean
|
|
|
|
|
gimp_rectangle_tool_rect_adjusting_func (GimpRectangleTool *rect_tool)
|
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
|
|
|
|
|
|
|
|
|
return (gimp_rectangle_tool_rect_rubber_banding_func (rect_tool) ||
|
2007-11-24 17:27:55 +08:00
|
|
|
|
private->function == GIMP_RECTANGLE_TOOL_MOVING);
|
2007-02-09 07:19:57 +08:00
|
|
|
|
}
|
2007-06-30 00:37:50 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_get_other_side:
|
2007-11-14 05:30:45 +08:00
|
|
|
|
* @rect_tool: A #GimpRectangleTool.
|
|
|
|
|
* @other_x: Pointer to double of the other-x double.
|
|
|
|
|
* @other_y: Pointer to double of the other-y double.
|
2007-06-30 00:37:50 +08:00
|
|
|
|
*
|
2007-11-14 05:30:45 +08:00
|
|
|
|
* Calculates pointers to member variables that hold the coordinates
|
|
|
|
|
* of the opposite side (either the opposite corner or literally the
|
|
|
|
|
* opposite side), based on the current function. The opposite of a
|
|
|
|
|
* corner needs two coordinates, the opposite of a side only needs
|
|
|
|
|
* one.
|
2007-06-30 00:37:50 +08:00
|
|
|
|
*/
|
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_get_other_side (GimpRectangleTool *rect_tool,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble **other_x,
|
|
|
|
|
gdouble **other_y)
|
2007-06-30 00:37:50 +08:00
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
2007-06-30 00:37:50 +08:00
|
|
|
|
|
|
|
|
|
switch (private->function)
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_RIGHT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_RIGHT:
|
2007-11-14 05:30:45 +08:00
|
|
|
|
*other_x = &private->x1;
|
2007-06-30 00:37:50 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LEFT:
|
2007-11-14 05:30:45 +08:00
|
|
|
|
*other_x = &private->x2;
|
2007-06-30 00:37:50 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_TOP:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_BOTTOM:
|
2007-06-30 00:37:50 +08:00
|
|
|
|
default:
|
|
|
|
|
*other_x = NULL;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (private->function)
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_BOTTOM:
|
2007-11-14 05:30:45 +08:00
|
|
|
|
*other_y = &private->y1;
|
2007-06-30 00:37:50 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_RIGHT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_TOP:
|
2007-11-14 05:30:45 +08:00
|
|
|
|
*other_y = &private->y2;
|
2007-06-30 00:37:50 +08:00
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_RIGHT:
|
2007-06-30 00:37:50 +08:00
|
|
|
|
default:
|
|
|
|
|
*other_y = NULL;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_get_other_side_coord (GimpRectangleTool *rect_tool,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble *other_side_x,
|
|
|
|
|
gdouble *other_side_y)
|
2007-06-30 00:37:50 +08:00
|
|
|
|
{
|
2007-11-14 05:30:45 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble *other_x;
|
|
|
|
|
gdouble *other_y;
|
2007-11-14 05:30:45 +08:00
|
|
|
|
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
|
|
|
|
|
|
|
|
|
other_x = NULL;
|
|
|
|
|
other_y = NULL;
|
2007-06-30 00:37:50 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_get_other_side (rect_tool,
|
2007-06-30 00:37:50 +08:00
|
|
|
|
&other_x,
|
|
|
|
|
&other_y);
|
|
|
|
|
if (other_x)
|
2007-11-14 05:30:45 +08:00
|
|
|
|
*other_side_x = *other_x;
|
2007-06-30 00:37:50 +08:00
|
|
|
|
if (other_y)
|
2007-11-14 05:30:45 +08:00
|
|
|
|
*other_side_y = *other_y;
|
2007-06-30 00:37:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_set_other_side_coord (GimpRectangleTool *rect_tool,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble other_side_x,
|
|
|
|
|
gdouble other_side_y)
|
2007-06-30 00:37:50 +08:00
|
|
|
|
{
|
2007-11-14 05:30:45 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble *other_x;
|
|
|
|
|
gdouble *other_y;
|
2007-11-14 05:30:45 +08:00
|
|
|
|
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
|
|
|
|
|
|
|
|
|
other_x = NULL;
|
|
|
|
|
other_y = NULL;
|
2007-06-30 00:37:50 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_get_other_side (rect_tool,
|
2007-06-30 00:37:50 +08:00
|
|
|
|
&other_x,
|
|
|
|
|
&other_y);
|
|
|
|
|
if (other_x)
|
2007-11-14 05:30:45 +08:00
|
|
|
|
*other_x = other_side_x;
|
2007-06-30 00:37:50 +08:00
|
|
|
|
if (other_y)
|
2007-11-14 05:30:45 +08:00
|
|
|
|
*other_y = other_side_y;
|
2007-11-14 05:15:57 +08:00
|
|
|
|
|
|
|
|
|
gimp_rectangle_tool_check_function (rect_tool);
|
2008-01-22 05:34:41 +08:00
|
|
|
|
|
|
|
|
|
gimp_rectangle_tool_update_int_rect (rect_tool);
|
2007-06-30 00:37:50 +08:00
|
|
|
|
}
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_apply_coord:
|
|
|
|
|
* @param: A #GimpRectangleTool.
|
|
|
|
|
* @coord_x: X of coord.
|
|
|
|
|
* @coord_y: Y of coord.
|
|
|
|
|
*
|
2008-04-08 02:25:18 +08:00
|
|
|
|
* Adjust the rectangle to the new position specified by passed
|
|
|
|
|
* coordinate, taking fixed_center into account, which means it
|
|
|
|
|
* expands the rectagle around the center point.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*/
|
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_apply_coord (GimpRectangleTool *rect_tool,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble coord_x,
|
|
|
|
|
gdouble coord_y)
|
2007-07-09 05:57:22 +08:00
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
GimpRectangleOptions *options;
|
|
|
|
|
GimpRectangleOptionsPrivate *options_private;
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
|
|
|
|
options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (rect_tool);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
options_private = GIMP_RECTANGLE_OPTIONS_GET_PRIVATE (options);
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
if (private->function == GIMP_RECTANGLE_TOOL_INACTIVE)
|
|
|
|
|
g_warning ("function is GIMP_RECTANGLE_TOOL_INACTIVE while mouse is moving");
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
if (private->function == GIMP_RECTANGLE_TOOL_MOVING)
|
2007-07-09 05:57:22 +08:00
|
|
|
|
{
|
|
|
|
|
/* Preserve width and height while moving the grab-point to where the
|
|
|
|
|
* cursor is.
|
|
|
|
|
*/
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble w = private->x2 - private->x1;
|
|
|
|
|
gdouble h = private->y2 - private->y1;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
private->x1 = coord_x;
|
|
|
|
|
private->y1 = coord_y;
|
|
|
|
|
|
|
|
|
|
private->x2 = private->x1 + w;
|
|
|
|
|
private->y2 = private->y1 + h;
|
|
|
|
|
|
|
|
|
|
/* We are done already. */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (private->function)
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LEFT:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
private->x1 = coord_x;
|
|
|
|
|
|
|
|
|
|
if (options_private->fixed_center)
|
|
|
|
|
private->x2 = 2 * private->center_x_on_fixed_center - private->x1;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_RIGHT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_RIGHT:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
private->x2 = coord_x;
|
|
|
|
|
|
|
|
|
|
if (options_private->fixed_center)
|
|
|
|
|
private->x1 = 2 * private->center_x_on_fixed_center - private->x2;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (private->function)
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_RIGHT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_TOP:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
private->y1 = coord_y;
|
|
|
|
|
|
|
|
|
|
if (options_private->fixed_center)
|
|
|
|
|
private->y2 = 2 * private->center_y_on_fixed_center - private->y1;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_BOTTOM:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
private->y2 = coord_y;
|
|
|
|
|
|
|
|
|
|
if (options_private->fixed_center)
|
|
|
|
|
private->y1 = 2 * private->center_y_on_fixed_center - private->y2;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
static void
|
|
|
|
|
gimp_rectangle_tool_setup_snap_offsets (GimpRectangleTool *rect_tool,
|
2008-11-01 23:17:36 +08:00
|
|
|
|
const GimpCoords *coords)
|
2007-11-24 17:09:26 +08:00
|
|
|
|
{
|
|
|
|
|
GimpTool *tool;
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
gdouble pub_x1, pub_y1, pub_x2, pub_y2;
|
2008-03-09 18:40:42 +08:00
|
|
|
|
gdouble pub_coord_x, pub_coord_y;
|
2007-11-24 17:09:26 +08:00
|
|
|
|
|
|
|
|
|
tool = GIMP_TOOL (rect_tool);
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
|
|
|
|
|
|
|
|
|
gimp_rectangle_tool_get_public_rect (rect_tool,
|
|
|
|
|
&pub_x1, &pub_y1, &pub_x2, &pub_y2);
|
2008-03-09 18:40:42 +08:00
|
|
|
|
gimp_rectangle_tool_adjust_coord (rect_tool,
|
|
|
|
|
coords->x, coords->y,
|
|
|
|
|
&pub_coord_x, &pub_coord_y);
|
2007-11-24 17:09:26 +08:00
|
|
|
|
|
|
|
|
|
switch (private->function)
|
|
|
|
|
{
|
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control, 0, 0, 0, 0);
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_LEFT:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2008-03-09 18:40:42 +08:00
|
|
|
|
pub_x1 - pub_coord_x,
|
|
|
|
|
pub_y1 - pub_coord_y,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
0, 0);
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_RIGHT:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2008-03-09 18:40:42 +08:00
|
|
|
|
pub_x2 - pub_coord_x,
|
|
|
|
|
pub_y1 - pub_coord_y,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
0, 0);
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_LEFT:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2008-03-09 18:40:42 +08:00
|
|
|
|
pub_x1 - pub_coord_x,
|
|
|
|
|
pub_y2 - pub_coord_y,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
0, 0);
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2008-03-09 18:40:42 +08:00
|
|
|
|
pub_x2 - pub_coord_x,
|
|
|
|
|
pub_y2 - pub_coord_y,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
0, 0);
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LEFT:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2008-03-09 18:40:42 +08:00
|
|
|
|
pub_x1 - pub_coord_x, 0,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
0, 0);
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_RIGHT:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2008-03-09 18:40:42 +08:00
|
|
|
|
pub_x2 - pub_coord_x, 0,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
0, 0);
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_TOP:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2008-03-09 18:40:42 +08:00
|
|
|
|
0, pub_y1 - pub_coord_y,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
0, 0);
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_BOTTOM:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2008-03-09 18:40:42 +08:00
|
|
|
|
0, pub_y2 - pub_coord_y,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
0, 0);
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_MOVING:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gimp_tool_control_set_snap_offsets (tool->control,
|
2008-03-09 18:40:42 +08:00
|
|
|
|
pub_x1 - pub_coord_x,
|
|
|
|
|
pub_y1 - pub_coord_y,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
pub_x2 - pub_x1,
|
|
|
|
|
pub_y2 - pub_y1);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-09 05:57:22 +08:00
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_clamp_width:
|
2007-11-04 22:47:48 +08:00
|
|
|
|
* @rect_tool: A #GimpRectangleTool.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
* @clamped_sides: Where to put contrainment information.
|
|
|
|
|
* @constraint: Constraint to use.
|
|
|
|
|
* @symmetrically: Whether or not to clamp symmetrically.
|
|
|
|
|
*
|
2008-04-08 02:25:18 +08:00
|
|
|
|
* Clamps rectangle inside specified bounds, providing information of
|
|
|
|
|
* where clamping was done. Can also clamp symmetrically.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*/
|
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_clamp (GimpRectangleTool *rect_tool,
|
2007-07-09 05:57:22 +08:00
|
|
|
|
ClampedSide *clamped_sides,
|
|
|
|
|
GimpRectangleConstraint constraint,
|
|
|
|
|
gboolean symmetrically)
|
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_clamp_width (rect_tool,
|
2007-07-09 05:57:22 +08:00
|
|
|
|
clamped_sides,
|
|
|
|
|
constraint,
|
|
|
|
|
symmetrically);
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_clamp_height (rect_tool,
|
2007-07-09 05:57:22 +08:00
|
|
|
|
clamped_sides,
|
|
|
|
|
constraint,
|
|
|
|
|
symmetrically);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_clamp_width:
|
2007-11-04 22:47:48 +08:00
|
|
|
|
* @rect_tool: A #GimpRectangleTool.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
* @clamped_sides: Where to put contrainment information.
|
|
|
|
|
* @constraint: Constraint to use.
|
|
|
|
|
* @symmetrically: Whether or not to clamp symmetrically.
|
|
|
|
|
*
|
2008-04-08 02:25:18 +08:00
|
|
|
|
* Clamps height of rectangle. Set symmetrically to true when using
|
|
|
|
|
* for fixed_center:ed rectangles, since that will clamp symmetrically
|
|
|
|
|
* which is just what is needed.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*
|
|
|
|
|
* When this function constrains, it puts what it constrains in
|
2008-04-08 02:25:18 +08:00
|
|
|
|
* @constraint. This information is essential when an aspect ratio is
|
|
|
|
|
* to be applied.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*/
|
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_clamp_width (GimpRectangleTool *rect_tool,
|
2007-07-09 05:57:22 +08:00
|
|
|
|
ClampedSide *clamped_sides,
|
|
|
|
|
GimpRectangleConstraint constraint,
|
|
|
|
|
gboolean symmetrically)
|
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
gint min_x;
|
|
|
|
|
gint max_x;
|
|
|
|
|
|
2007-08-18 17:44:18 +08:00
|
|
|
|
if (constraint == GIMP_RECTANGLE_CONSTRAIN_NONE)
|
|
|
|
|
return;
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_get_constraints (rect_tool,
|
2007-07-09 05:57:22 +08:00
|
|
|
|
&min_x,
|
|
|
|
|
NULL,
|
|
|
|
|
&max_x,
|
|
|
|
|
NULL,
|
|
|
|
|
constraint);
|
|
|
|
|
if (private->x1 < min_x)
|
|
|
|
|
{
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble dx = min_x - private->x1;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
private->x1 += dx;
|
|
|
|
|
|
|
|
|
|
if (symmetrically)
|
2007-07-14 18:01:46 +08:00
|
|
|
|
private->x2 -= dx;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2007-07-14 18:01:46 +08:00
|
|
|
|
if (private->x2 < min_x)
|
|
|
|
|
private->x2 = min_x;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2007-10-31 18:36:03 +08:00
|
|
|
|
if (clamped_sides)
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*clamped_sides |= CLAMPED_LEFT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (private->x2 > max_x)
|
|
|
|
|
{
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble dx = max_x - private->x2;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
private->x2 += dx;
|
|
|
|
|
|
|
|
|
|
if (symmetrically)
|
2007-07-14 18:01:46 +08:00
|
|
|
|
private->x1 -= dx;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2007-07-14 18:01:46 +08:00
|
|
|
|
if (private->x1 > max_x)
|
|
|
|
|
private->x1 = max_x;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2007-10-31 18:36:03 +08:00
|
|
|
|
if (clamped_sides)
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*clamped_sides |= CLAMPED_RIGHT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_clamp_height:
|
2007-11-04 22:47:48 +08:00
|
|
|
|
* @rect_tool: A #GimpRectangleTool.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
* @clamped_sides: Where to put contrainment information.
|
|
|
|
|
* @constraint: Constraint to use.
|
|
|
|
|
* @symmetrically: Whether or not to clamp symmetrically.
|
|
|
|
|
*
|
|
|
|
|
* Clamps height of rectangle. Set symmetrically to true when using for
|
|
|
|
|
* fixed_center:ed rectangles, since that will clamp symmetrically which is just
|
|
|
|
|
* what is needed.
|
|
|
|
|
*
|
|
|
|
|
* When this function constrains, it puts what it constrains in
|
|
|
|
|
* @constraint. This information is essential when an aspect ratio is to be
|
|
|
|
|
* applied.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_clamp_height (GimpRectangleTool *rect_tool,
|
2007-07-09 05:57:22 +08:00
|
|
|
|
ClampedSide *clamped_sides,
|
|
|
|
|
GimpRectangleConstraint constraint,
|
|
|
|
|
gboolean symmetrically)
|
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
gint min_y;
|
|
|
|
|
gint max_y;
|
|
|
|
|
|
2007-08-18 17:44:18 +08:00
|
|
|
|
if (constraint == GIMP_RECTANGLE_CONSTRAIN_NONE)
|
|
|
|
|
return;
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_get_constraints (rect_tool,
|
2007-10-31 18:36:03 +08:00
|
|
|
|
NULL,
|
|
|
|
|
&min_y,
|
|
|
|
|
NULL,
|
|
|
|
|
&max_y,
|
|
|
|
|
constraint);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
if (private->y1 < min_y)
|
|
|
|
|
{
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble dy = min_y - private->y1;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
private->y1 += dy;
|
|
|
|
|
|
|
|
|
|
if (symmetrically)
|
2007-07-14 18:01:46 +08:00
|
|
|
|
private->y2 -= dy;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2007-07-14 18:01:46 +08:00
|
|
|
|
if (private->y2 < min_y)
|
|
|
|
|
private->y2 = min_y;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2007-10-31 18:36:03 +08:00
|
|
|
|
if (clamped_sides)
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*clamped_sides |= CLAMPED_TOP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (private->y2 > max_y)
|
|
|
|
|
{
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble dy = max_y - private->y2;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
private->y2 += dy;
|
|
|
|
|
|
|
|
|
|
if (symmetrically)
|
2007-07-14 18:01:46 +08:00
|
|
|
|
private->y1 -= dy;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2007-07-14 18:01:46 +08:00
|
|
|
|
if (private->y1 > max_y)
|
|
|
|
|
private->y1 = max_y;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2007-10-31 18:36:03 +08:00
|
|
|
|
if (clamped_sides)
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*clamped_sides |= CLAMPED_BOTTOM;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_keep_inside:
|
2007-11-04 22:47:48 +08:00
|
|
|
|
* @rect_tool: A #GimpRectangleTool.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*
|
|
|
|
|
* If the rectangle is outside of the canvas, move it into it. If the rectangle is
|
|
|
|
|
* larger than the canvas in any direction, make it fill the canvas in that direction.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_keep_inside (GimpRectangleTool *rect_tool,
|
2007-07-09 05:57:22 +08:00
|
|
|
|
GimpRectangleConstraint constraint)
|
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_keep_inside_horizontally (rect_tool,
|
2007-07-09 05:57:22 +08:00
|
|
|
|
constraint);
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_keep_inside_vertically (rect_tool,
|
2007-07-09 05:57:22 +08:00
|
|
|
|
constraint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_keep_inside_horizontally:
|
2007-11-04 22:47:48 +08:00
|
|
|
|
* @rect_tool: A #GimpRectangleTool.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
* @constraint: Constraint to use.
|
|
|
|
|
*
|
|
|
|
|
* If the rectangle is outside of the given constraint horizontally, move it
|
|
|
|
|
* inside. If it is too big to fit inside, make it just as big as the width
|
|
|
|
|
* limit.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_keep_inside_horizontally (GimpRectangleTool *rect_tool,
|
2007-10-31 18:36:03 +08:00
|
|
|
|
GimpRectangleConstraint constraint)
|
2007-07-09 05:57:22 +08:00
|
|
|
|
{
|
2007-10-31 18:36:03 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
gint min_x;
|
|
|
|
|
gint max_x;
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2007-08-18 17:44:18 +08:00
|
|
|
|
if (constraint == GIMP_RECTANGLE_CONSTRAIN_NONE)
|
|
|
|
|
return;
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_get_constraints (rect_tool,
|
2007-10-31 18:36:03 +08:00
|
|
|
|
&min_x,
|
|
|
|
|
NULL,
|
|
|
|
|
&max_x,
|
|
|
|
|
NULL,
|
|
|
|
|
constraint);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
if (max_x - min_x < private->x2 - private->x1)
|
|
|
|
|
{
|
|
|
|
|
private->x1 = min_x;
|
|
|
|
|
private->x2 = max_x;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (private->x1 < min_x)
|
|
|
|
|
{
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble dx = min_x - private->x1;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
private->x1 += dx;
|
|
|
|
|
private->x2 += dx;
|
|
|
|
|
}
|
|
|
|
|
if (private->x2 > max_x)
|
|
|
|
|
{
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble dx = max_x - private->x2;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
private->x1 += dx;
|
|
|
|
|
private->x2 += dx;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_keep_inside_vertically:
|
2007-11-04 22:47:48 +08:00
|
|
|
|
* @rect_tool: A #GimpRectangleTool.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
* @constraint: Constraint to use.
|
|
|
|
|
*
|
2008-04-08 02:25:18 +08:00
|
|
|
|
* If the rectangle is outside of the given constraint vertically,
|
|
|
|
|
* move it inside. If it is too big to fit inside, make it just as big
|
|
|
|
|
* as the width limit.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*/
|
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_keep_inside_vertically (GimpRectangleTool *rect_tool,
|
2007-10-31 18:36:03 +08:00
|
|
|
|
GimpRectangleConstraint constraint)
|
2007-07-09 05:57:22 +08:00
|
|
|
|
{
|
2007-10-31 18:36:03 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
gint min_y;
|
|
|
|
|
gint max_y;
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2007-08-18 17:44:18 +08:00
|
|
|
|
if (constraint == GIMP_RECTANGLE_CONSTRAIN_NONE)
|
|
|
|
|
return;
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_get_constraints (rect_tool,
|
2007-10-31 18:36:03 +08:00
|
|
|
|
NULL,
|
|
|
|
|
&min_y,
|
|
|
|
|
NULL,
|
|
|
|
|
&max_y,
|
|
|
|
|
constraint);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
if (max_y - min_y < private->y2 - private->y1)
|
|
|
|
|
{
|
|
|
|
|
private->y1 = min_y;
|
|
|
|
|
private->y2 = max_y;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (private->y1 < min_y)
|
|
|
|
|
{
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble dy = min_y - private->y1;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
private->y1 += dy;
|
|
|
|
|
private->y2 += dy;
|
|
|
|
|
}
|
|
|
|
|
if (private->y2 > max_y)
|
|
|
|
|
{
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble dy = max_y - private->y2;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
private->y1 += dy;
|
|
|
|
|
private->y2 += dy;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_apply_fixed_width:
|
2007-11-04 22:47:48 +08:00
|
|
|
|
* @rect_tool: A #GimpRectangleTool.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
* @constraint: Constraint to use.
|
2007-08-08 14:10:00 +08:00
|
|
|
|
* @width:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*
|
2008-04-08 02:25:18 +08:00
|
|
|
|
* Makes the rectangle have a fixed_width, following the constrainment
|
|
|
|
|
* rules of fixed widths as well. Please refer to the rectangle tools
|
|
|
|
|
* spec.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*/
|
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_apply_fixed_width (GimpRectangleTool *rect_tool,
|
2007-08-08 14:10:00 +08:00
|
|
|
|
GimpRectangleConstraint constraint,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble width)
|
2007-07-09 05:57:22 +08:00
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
GimpRectangleOptions *options;
|
|
|
|
|
GimpRectangleOptionsPrivate *options_private;
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
|
|
|
|
options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (rect_tool);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
options_private = GIMP_RECTANGLE_OPTIONS_GET_PRIVATE (options);
|
|
|
|
|
|
|
|
|
|
switch (private->function)
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LEFT:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
/* We always want to center around fixed_center here, since we want the
|
|
|
|
|
* anchor point to be directly on the opposite side.
|
|
|
|
|
*/
|
|
|
|
|
private->x1 = private->center_x_on_fixed_center -
|
2007-08-08 14:10:00 +08:00
|
|
|
|
width / 2;
|
|
|
|
|
private->x2 = private->x1 + width;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_RIGHT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_RIGHT:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
/* We always want to center around fixed_center here, since we want the
|
|
|
|
|
* anchor point to be directly on the opposite side.
|
|
|
|
|
*/
|
|
|
|
|
private->x1 = private->center_x_on_fixed_center -
|
2007-08-08 14:10:00 +08:00
|
|
|
|
width / 2;
|
|
|
|
|
private->x2 = private->x1 + width;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Width shall be kept even after constraints, so we move the
|
|
|
|
|
* rectangle sideways rather than adjusting a side.
|
|
|
|
|
*/
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_keep_inside_horizontally (rect_tool,
|
2007-07-09 05:57:22 +08:00
|
|
|
|
constraint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_apply_fixed_height:
|
2007-11-04 22:47:48 +08:00
|
|
|
|
* @rect_tool: A #GimpRectangleTool.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
* @constraint: Constraint to use.
|
2007-08-08 14:10:00 +08:00
|
|
|
|
* @height:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*
|
2008-04-08 02:25:18 +08:00
|
|
|
|
* Makes the rectangle have a fixed_height, following the
|
|
|
|
|
* constrainment rules of fixed heights as well. Please refer to the
|
|
|
|
|
* rectangle tools spec.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*/
|
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_apply_fixed_height (GimpRectangleTool *rect_tool,
|
2007-08-08 14:10:00 +08:00
|
|
|
|
GimpRectangleConstraint constraint,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble height)
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
GimpRectangleOptions *options;
|
|
|
|
|
GimpRectangleOptionsPrivate *options_private;
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
|
|
|
|
options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (rect_tool);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
options_private = GIMP_RECTANGLE_OPTIONS_GET_PRIVATE (options);
|
|
|
|
|
|
|
|
|
|
switch (private->function)
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_RIGHT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_TOP:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2008-04-08 02:25:18 +08:00
|
|
|
|
/* We always want to center around fixed_center here, since we
|
|
|
|
|
* want the anchor point to be directly on the opposite side.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*/
|
|
|
|
|
private->y1 = private->center_y_on_fixed_center -
|
2007-08-08 14:10:00 +08:00
|
|
|
|
height / 2;
|
|
|
|
|
private->y2 = private->y1 + height;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_BOTTOM:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2008-04-08 02:25:18 +08:00
|
|
|
|
/* We always want to center around fixed_center here, since we
|
|
|
|
|
* want the anchor point to be directly on the opposite side.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*/
|
|
|
|
|
private->y1 = private->center_y_on_fixed_center -
|
2007-08-08 14:10:00 +08:00
|
|
|
|
height / 2;
|
|
|
|
|
private->y2 = private->y1 + height;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Width shall be kept even after constraints, so we move the
|
|
|
|
|
* rectangle sideways rather than adjusting a side.
|
|
|
|
|
*/
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_keep_inside_vertically (rect_tool,
|
2007-07-09 05:57:22 +08:00
|
|
|
|
constraint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_apply_aspect:
|
2007-11-04 22:47:48 +08:00
|
|
|
|
* @rect_tool: A #GimpRectangleTool.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
* @aspect: The desired aspect.
|
|
|
|
|
* @clamped_sides: Bitfield of sides that have been clamped.
|
|
|
|
|
*
|
|
|
|
|
* Adjust the rectangle to the desired aspect.
|
|
|
|
|
*
|
2008-04-08 02:25:18 +08:00
|
|
|
|
* Sometimes, a side must not be moved outwards, for example if a the
|
|
|
|
|
* RIGHT side has been clamped previously, we must not move the RIGHT
|
|
|
|
|
* side to the right, since that would violate the constraint
|
|
|
|
|
* again. The clamped_sides bitfield keeps track of sides that have
|
|
|
|
|
* previously been clamped.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*
|
2008-04-08 02:25:18 +08:00
|
|
|
|
* If fixed_center is used, the function adjusts the aspect by
|
|
|
|
|
* symmetrically adjusting the left and right, or top and bottom side.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*/
|
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_apply_aspect (GimpRectangleTool *rect_tool,
|
2007-07-09 05:57:22 +08:00
|
|
|
|
gdouble aspect,
|
|
|
|
|
gint clamped_sides)
|
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
GimpRectangleOptions *options;
|
|
|
|
|
GimpRectangleOptionsPrivate *options_private;
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble current_w;
|
|
|
|
|
gdouble current_h;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
gdouble current_aspect;
|
|
|
|
|
SideToResize side_to_resize = SIDE_TO_RESIZE_NONE;
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
|
|
|
|
options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (rect_tool);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
options_private = GIMP_RECTANGLE_OPTIONS_GET_PRIVATE (options);
|
|
|
|
|
|
|
|
|
|
current_w = private->x2 - private->x1;
|
|
|
|
|
current_h = private->y2 - private->y1;
|
|
|
|
|
|
|
|
|
|
current_aspect = current_w / (gdouble) current_h;
|
|
|
|
|
|
|
|
|
|
/* Do we have to do anything? */
|
|
|
|
|
if (current_aspect == aspect)
|
2007-10-31 18:36:03 +08:00
|
|
|
|
return;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
if (options_private->fixed_center)
|
|
|
|
|
{
|
|
|
|
|
/* We may only adjust the sides symmetrically to get desired aspect. */
|
|
|
|
|
if (current_aspect > aspect)
|
|
|
|
|
{
|
2008-04-08 02:25:18 +08:00
|
|
|
|
/* We prefer to use top and bottom (since that will make the
|
|
|
|
|
* cursor remain on the rectangle edge), unless that is what
|
|
|
|
|
* the user has grabbed.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*/
|
|
|
|
|
switch (private->function)
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_RIGHT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_RIGHT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
if (!(clamped_sides & CLAMPED_TOP) &&
|
|
|
|
|
!(clamped_sides & CLAMPED_BOTTOM))
|
|
|
|
|
{
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_TOP_AND_BOTTOM_SYMMETRICALLY;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_LEFT_AND_RIGHT_SYMMETRICALLY;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_TOP:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_BOTTOM:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
default:
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_LEFT_AND_RIGHT_SYMMETRICALLY;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else /* (current_aspect < aspect) */
|
|
|
|
|
{
|
2008-04-08 02:25:18 +08:00
|
|
|
|
/* We prefer to use left and right (since that will make the
|
|
|
|
|
* cursor remain on the rectangle edge), unless that is what
|
|
|
|
|
* the user has grabbed.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*/
|
|
|
|
|
switch (private->function)
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_TOP:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_BOTTOM:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_RIGHT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
if (!(clamped_sides & CLAMPED_LEFT) &&
|
|
|
|
|
!(clamped_sides & CLAMPED_RIGHT))
|
|
|
|
|
{
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_LEFT_AND_RIGHT_SYMMETRICALLY;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_TOP_AND_BOTTOM_SYMMETRICALLY;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_RIGHT:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
default:
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_TOP_AND_BOTTOM_SYMMETRICALLY;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (current_aspect > aspect)
|
|
|
|
|
{
|
2008-04-08 02:25:18 +08:00
|
|
|
|
/* We can safely pick LEFT or RIGHT, since using those sides
|
|
|
|
|
* will make the rectangle smaller, so we don't need to check
|
|
|
|
|
* for clamped_sides. We may only use TOP and BOTTOM if not
|
|
|
|
|
* those sides have been clamped, since using them will make the
|
|
|
|
|
* rectangle bigger.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*/
|
|
|
|
|
switch (private->function)
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_LEFT:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
if (!(clamped_sides & CLAMPED_TOP))
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_TOP;
|
|
|
|
|
else
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_LEFT;
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_RIGHT:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
if (!(clamped_sides & CLAMPED_TOP))
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_TOP;
|
|
|
|
|
else
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_RIGHT;
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_LEFT:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
if (!(clamped_sides & CLAMPED_BOTTOM))
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_BOTTOM;
|
|
|
|
|
else
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_LEFT;
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
if (!(clamped_sides & CLAMPED_BOTTOM))
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_BOTTOM;
|
|
|
|
|
else
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_RIGHT;
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LEFT:
|
2008-04-08 02:25:18 +08:00
|
|
|
|
if (!(clamped_sides & CLAMPED_TOP) &&
|
|
|
|
|
!(clamped_sides & CLAMPED_BOTTOM))
|
2007-07-09 05:57:22 +08:00
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_TOP_AND_BOTTOM_SYMMETRICALLY;
|
|
|
|
|
else
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_LEFT;
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_RIGHT:
|
2008-04-08 02:25:18 +08:00
|
|
|
|
if (!(clamped_sides & CLAMPED_TOP) &&
|
|
|
|
|
!(clamped_sides & CLAMPED_BOTTOM))
|
2007-07-09 05:57:22 +08:00
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_TOP_AND_BOTTOM_SYMMETRICALLY;
|
|
|
|
|
else
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_RIGHT;
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_BOTTOM:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_TOP:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_LEFT_AND_RIGHT_SYMMETRICALLY;
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_MOVING:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
default:
|
|
|
|
|
if (!(clamped_sides & CLAMPED_BOTTOM))
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_BOTTOM;
|
|
|
|
|
else if (!(clamped_sides & CLAMPED_RIGHT))
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_RIGHT;
|
|
|
|
|
else if (!(clamped_sides & CLAMPED_TOP))
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_TOP;
|
|
|
|
|
else if (!(clamped_sides & CLAMPED_LEFT))
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_LEFT;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else /* (current_aspect < aspect) */
|
|
|
|
|
{
|
2008-04-08 02:25:18 +08:00
|
|
|
|
/* We can safely pick TOP or BOTTOM, since using those sides
|
|
|
|
|
* will make the rectangle smaller, so we don't need to check
|
|
|
|
|
* for clamped_sides. We may only use LEFT and RIGHT if not
|
|
|
|
|
* those sides have been clamped, since using them will make the
|
|
|
|
|
* rectangle bigger.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*/
|
|
|
|
|
switch (private->function)
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_LEFT:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
if (!(clamped_sides & CLAMPED_LEFT))
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_LEFT;
|
|
|
|
|
else
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_TOP;
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_UPPER_RIGHT:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
if (!(clamped_sides & CLAMPED_RIGHT))
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_RIGHT;
|
|
|
|
|
else
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_TOP;
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_LEFT:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
if (!(clamped_sides & CLAMPED_LEFT))
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_LEFT;
|
|
|
|
|
else
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_BOTTOM;
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LOWER_RIGHT:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
if (!(clamped_sides & CLAMPED_RIGHT))
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_RIGHT;
|
|
|
|
|
else
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_BOTTOM;
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_TOP:
|
2008-04-08 02:25:18 +08:00
|
|
|
|
if (!(clamped_sides & CLAMPED_LEFT) &&
|
|
|
|
|
!(clamped_sides & CLAMPED_RIGHT))
|
2007-07-09 05:57:22 +08:00
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_LEFT_AND_RIGHT_SYMMETRICALLY;
|
|
|
|
|
else
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_TOP;
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_BOTTOM:
|
2008-04-08 02:25:18 +08:00
|
|
|
|
if (!(clamped_sides & CLAMPED_LEFT) &&
|
|
|
|
|
!(clamped_sides & CLAMPED_RIGHT))
|
2007-07-09 05:57:22 +08:00
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_LEFT_AND_RIGHT_SYMMETRICALLY;
|
|
|
|
|
else
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_BOTTOM;
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_LEFT:
|
|
|
|
|
case GIMP_RECTANGLE_TOOL_RESIZING_RIGHT:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_TOP_AND_BOTTOM_SYMMETRICALLY;
|
|
|
|
|
break;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
case GIMP_RECTANGLE_TOOL_MOVING:
|
2007-07-09 05:57:22 +08:00
|
|
|
|
default:
|
|
|
|
|
if (!(clamped_sides & CLAMPED_BOTTOM))
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_BOTTOM;
|
|
|
|
|
else if (!(clamped_sides & CLAMPED_RIGHT))
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_RIGHT;
|
|
|
|
|
else if (!(clamped_sides & CLAMPED_TOP))
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_TOP;
|
|
|
|
|
else if (!(clamped_sides & CLAMPED_LEFT))
|
|
|
|
|
side_to_resize = SIDE_TO_RESIZE_LEFT;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-08 02:25:18 +08:00
|
|
|
|
/* We now know what side(s) we should resize, so now we just solve
|
|
|
|
|
* the aspect equation for that side(s).
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*/
|
|
|
|
|
switch (side_to_resize)
|
|
|
|
|
{
|
|
|
|
|
case SIDE_TO_RESIZE_NONE:
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
case SIDE_TO_RESIZE_LEFT:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
private->x1 = private->x2 - aspect * current_h;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SIDE_TO_RESIZE_RIGHT:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
private->x2 = private->x1 + aspect * current_h;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SIDE_TO_RESIZE_TOP:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
private->y1 = private->y2 - current_w / aspect;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SIDE_TO_RESIZE_BOTTOM:
|
2007-11-24 17:09:26 +08:00
|
|
|
|
private->y2 = private->y1 + current_w / aspect;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SIDE_TO_RESIZE_TOP_AND_BOTTOM_SYMMETRICALLY:
|
|
|
|
|
{
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble correct_h = current_w / aspect;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
private->y1 = private->center_y_on_fixed_center - correct_h / 2;
|
|
|
|
|
private->y2 = private->y1 + correct_h;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case SIDE_TO_RESIZE_LEFT_AND_RIGHT_SYMMETRICALLY:
|
|
|
|
|
{
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble correct_w = current_h * aspect;
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
private->x1 = private->center_x_on_fixed_center - correct_w / 2;
|
|
|
|
|
private->x2 = private->x1 + correct_w;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_update_with_coord:
|
2007-11-04 22:47:48 +08:00
|
|
|
|
* @rect_tool: A #GimpRectangleTool.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
* @new_x: New X-coordinate in the context of the current function.
|
|
|
|
|
* @new_y: New Y-coordinate in the context of the current function.
|
|
|
|
|
*
|
2008-04-08 02:25:18 +08:00
|
|
|
|
* The core rectangle adjustment function. It updates the rectangle
|
|
|
|
|
* for the passed cursor coordinate, taking current function and tool
|
|
|
|
|
* options into account. It also updates the current
|
|
|
|
|
* private->function if necessary.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*/
|
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_update_with_coord (GimpRectangleTool *rect_tool,
|
2007-11-24 17:09:26 +08:00
|
|
|
|
gdouble new_x,
|
|
|
|
|
gdouble new_y)
|
2007-07-09 05:57:22 +08:00
|
|
|
|
{
|
2008-04-08 02:25:18 +08:00
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
|
|
|
|
/* Move the corner or edge the user currently has grabbed. */
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_apply_coord (rect_tool,
|
2007-07-09 05:57:22 +08:00
|
|
|
|
new_x,
|
|
|
|
|
new_y);
|
|
|
|
|
|
2007-11-11 15:59:51 +08:00
|
|
|
|
/* Update private->function. The function changes if the user
|
|
|
|
|
* "flips" the rectangle.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*/
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_check_function (rect_tool);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2007-11-11 15:59:51 +08:00
|
|
|
|
/* Clamp the rectangle if necessary */
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_handle_general_clamping (rect_tool);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2007-11-24 17:09:26 +08:00
|
|
|
|
/* If the rectangle is being moved, do not run through any further
|
|
|
|
|
* rectangle adjusting functions since it's shape should not change
|
|
|
|
|
* then.
|
|
|
|
|
*/
|
2007-11-24 17:27:55 +08:00
|
|
|
|
if (private->function != GIMP_RECTANGLE_TOOL_MOVING)
|
2007-11-24 17:09:26 +08:00
|
|
|
|
{
|
|
|
|
|
gimp_rectangle_tool_apply_fixed_rule (rect_tool);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gimp_rectangle_tool_update_int_rect (rect_tool);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gimp_rectangle_tool_apply_fixed_rule (GimpRectangleTool *rect_tool)
|
|
|
|
|
{
|
|
|
|
|
GimpTool *tool;
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
GimpRectangleOptions *options;
|
|
|
|
|
GimpRectangleOptionsPrivate *options_private;
|
|
|
|
|
GimpRectangleConstraint constraint_to_use;
|
|
|
|
|
|
|
|
|
|
tool = GIMP_TOOL (rect_tool);
|
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (tool);
|
|
|
|
|
options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (tool);
|
|
|
|
|
options_private = GIMP_RECTANGLE_OPTIONS_GET_PRIVATE (options);
|
|
|
|
|
|
2007-07-09 05:57:22 +08:00
|
|
|
|
/* Calculate what constraint to use when needed. */
|
2007-11-04 22:47:48 +08:00
|
|
|
|
constraint_to_use = gimp_rectangle_tool_get_constraint (rect_tool);
|
2007-08-08 14:10:00 +08:00
|
|
|
|
|
2007-08-05 04:20:44 +08:00
|
|
|
|
if (gimp_rectangle_options_fixed_rule_active (options,
|
|
|
|
|
GIMP_RECTANGLE_TOOL_FIXED_ASPECT))
|
2007-07-09 05:57:22 +08:00
|
|
|
|
{
|
|
|
|
|
gdouble aspect;
|
|
|
|
|
|
|
|
|
|
aspect = CLAMP (options_private->aspect_numerator /
|
|
|
|
|
options_private->aspect_denominator,
|
2007-12-26 00:21:40 +08:00
|
|
|
|
1.0 / gimp_image_get_height (tool->display->image),
|
|
|
|
|
gimp_image_get_width (tool->display->image));
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2007-08-18 17:44:18 +08:00
|
|
|
|
if (constraint_to_use == GIMP_RECTANGLE_CONSTRAIN_NONE)
|
2007-07-09 05:57:22 +08:00
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_apply_aspect (rect_tool,
|
2007-07-09 05:57:22 +08:00
|
|
|
|
aspect,
|
2007-08-18 17:44:18 +08:00
|
|
|
|
CLAMPED_NONE);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2007-11-24 17:27:55 +08:00
|
|
|
|
if (private->function != GIMP_RECTANGLE_TOOL_MOVING)
|
2007-08-18 17:44:18 +08:00
|
|
|
|
{
|
|
|
|
|
ClampedSide clamped_sides = CLAMPED_NONE;
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_apply_aspect (rect_tool,
|
2007-08-18 17:44:18 +08:00
|
|
|
|
aspect,
|
|
|
|
|
clamped_sides);
|
|
|
|
|
|
2007-10-31 18:36:03 +08:00
|
|
|
|
/* After we have applied aspect, we might have taken the
|
|
|
|
|
* rectangle outside of constraint, so clamp and apply
|
|
|
|
|
* aspect again. We will get the right result this time,
|
|
|
|
|
* since 'clamped_sides' will be setup correctly now.
|
2007-08-18 17:44:18 +08:00
|
|
|
|
*/
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_clamp (rect_tool,
|
2007-08-18 17:44:18 +08:00
|
|
|
|
&clamped_sides,
|
|
|
|
|
constraint_to_use,
|
|
|
|
|
options_private->fixed_center);
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_apply_aspect (rect_tool,
|
2007-08-18 17:44:18 +08:00
|
|
|
|
aspect,
|
|
|
|
|
clamped_sides);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_apply_aspect (rect_tool,
|
2007-08-18 17:44:18 +08:00
|
|
|
|
aspect,
|
|
|
|
|
CLAMPED_NONE);
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_keep_inside (rect_tool,
|
2007-08-18 17:44:18 +08:00
|
|
|
|
constraint_to_use);
|
|
|
|
|
}
|
2007-07-09 05:57:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-08-08 14:10:00 +08:00
|
|
|
|
else if (gimp_rectangle_options_fixed_rule_active (options,
|
|
|
|
|
GIMP_RECTANGLE_TOOL_FIXED_SIZE))
|
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_apply_fixed_width (rect_tool,
|
2007-08-08 14:10:00 +08:00
|
|
|
|
constraint_to_use,
|
|
|
|
|
options_private->desired_fixed_size_width);
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_apply_fixed_height (rect_tool,
|
2007-08-08 14:10:00 +08:00
|
|
|
|
constraint_to_use,
|
|
|
|
|
options_private->desired_fixed_size_height);
|
|
|
|
|
}
|
|
|
|
|
else if (gimp_rectangle_options_fixed_rule_active (options,
|
|
|
|
|
GIMP_RECTANGLE_TOOL_FIXED_WIDTH))
|
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_apply_fixed_width (rect_tool,
|
2007-08-08 14:10:00 +08:00
|
|
|
|
constraint_to_use,
|
|
|
|
|
options_private->desired_fixed_width);
|
|
|
|
|
}
|
|
|
|
|
else if (gimp_rectangle_options_fixed_rule_active (options,
|
|
|
|
|
GIMP_RECTANGLE_TOOL_FIXED_HEIGHT))
|
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_apply_fixed_height (rect_tool,
|
2007-08-08 14:10:00 +08:00
|
|
|
|
constraint_to_use,
|
|
|
|
|
options_private->desired_fixed_height);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_get_constraints:
|
2007-11-04 22:47:48 +08:00
|
|
|
|
* @rect_tool: A #GimpRectangleTool.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
* @min_x:
|
|
|
|
|
* @min_y:
|
|
|
|
|
* @max_x:
|
|
|
|
|
* @max_y: Pointers of where to put constraints. NULL allowed.
|
|
|
|
|
* @constraint: Wether to return image or layer constraints.
|
|
|
|
|
*
|
|
|
|
|
* Calculates constraint coordinates for image or layer.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_get_constraints (GimpRectangleTool *rect_tool,
|
2007-07-09 05:57:22 +08:00
|
|
|
|
gint *min_x,
|
|
|
|
|
gint *min_y,
|
|
|
|
|
gint *max_x,
|
|
|
|
|
gint *max_y,
|
|
|
|
|
GimpRectangleConstraint constraint)
|
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
GimpTool *tool = GIMP_TOOL (rect_tool);
|
2007-10-31 18:36:03 +08:00
|
|
|
|
gint min_x_dummy;
|
|
|
|
|
gint min_y_dummy;
|
|
|
|
|
gint max_x_dummy;
|
|
|
|
|
gint max_y_dummy;
|
|
|
|
|
|
|
|
|
|
if (! min_x) min_x = &min_x_dummy;
|
|
|
|
|
if (! min_y) min_y = &min_y_dummy;
|
|
|
|
|
if (! max_x) max_x = &max_x_dummy;
|
|
|
|
|
if (! max_y) max_y = &max_y_dummy;
|
|
|
|
|
|
|
|
|
|
*min_x = 0;
|
|
|
|
|
*min_y = 0;
|
|
|
|
|
*max_x = 0;
|
|
|
|
|
*max_y = 0;
|
|
|
|
|
|
2007-12-15 01:22:46 +08:00
|
|
|
|
if (! tool->display)
|
2007-09-23 02:20:29 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2007-07-09 05:57:22 +08:00
|
|
|
|
switch (constraint)
|
|
|
|
|
{
|
|
|
|
|
case GIMP_RECTANGLE_CONSTRAIN_IMAGE:
|
|
|
|
|
*min_x = 0;
|
|
|
|
|
*min_y = 0;
|
2007-12-26 00:21:40 +08:00
|
|
|
|
*max_x = gimp_image_get_width (tool->display->image);
|
|
|
|
|
*max_y = gimp_image_get_height (tool->display->image);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GIMP_RECTANGLE_CONSTRAIN_DRAWABLE:
|
|
|
|
|
{
|
|
|
|
|
GimpItem *item = GIMP_ITEM (tool->drawable);
|
|
|
|
|
|
2008-11-03 07:03:29 +08:00
|
|
|
|
gimp_item_get_offset (item, min_x, min_y);
|
2008-11-03 08:09:01 +08:00
|
|
|
|
*max_x = *min_x + gimp_item_get_width (item);
|
|
|
|
|
*max_y = *min_y + gimp_item_get_height (item);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
g_warning ("Invalid rectangle constraint.\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_handle_general_clamping:
|
2007-11-04 22:47:48 +08:00
|
|
|
|
* @rect_tool: A #GimpRectangleTool.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*
|
2008-04-08 02:25:18 +08:00
|
|
|
|
* Make sure that contraints are applied to the rectangle, either by
|
|
|
|
|
* manually doing it, or by looking at the rectangle tool options and
|
|
|
|
|
* concluding it will be done later.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*/
|
|
|
|
|
static void
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_handle_general_clamping (GimpRectangleTool *rect_tool)
|
2007-07-09 05:57:22 +08:00
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *private;
|
|
|
|
|
GimpRectangleOptions *options;
|
|
|
|
|
GimpRectangleOptionsPrivate *options_private;
|
|
|
|
|
GimpRectangleConstraint constraint;
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
|
|
|
|
options = GIMP_RECTANGLE_TOOL_GET_OPTIONS (rect_tool);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
options_private = GIMP_RECTANGLE_OPTIONS_GET_PRIVATE (options);
|
|
|
|
|
|
2007-11-04 22:47:48 +08:00
|
|
|
|
constraint = gimp_rectangle_tool_get_constraint (rect_tool);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
|
2007-10-31 18:36:03 +08:00
|
|
|
|
/* fixed_aspect takes care of clamping by it self, so just return in
|
|
|
|
|
* case that is in use. Also return if no constraints should be
|
|
|
|
|
* enforced.
|
2007-07-09 05:57:22 +08:00
|
|
|
|
*/
|
2007-08-18 17:44:18 +08:00
|
|
|
|
if (constraint == GIMP_RECTANGLE_CONSTRAIN_NONE)
|
2007-07-09 05:57:22 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2007-11-24 17:27:55 +08:00
|
|
|
|
if (private->function != GIMP_RECTANGLE_TOOL_MOVING)
|
2007-07-09 05:57:22 +08:00
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_clamp (rect_tool,
|
2007-08-18 17:44:18 +08:00
|
|
|
|
NULL,
|
|
|
|
|
constraint,
|
|
|
|
|
options_private->fixed_center);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
}
|
2007-08-18 17:44:18 +08:00
|
|
|
|
else
|
2007-07-09 05:57:22 +08:00
|
|
|
|
{
|
2007-11-04 22:47:48 +08:00
|
|
|
|
gimp_rectangle_tool_keep_inside (rect_tool,
|
2007-08-18 17:44:18 +08:00
|
|
|
|
constraint);
|
2007-07-09 05:57:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-11-24 17:09:26 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_update_int_rect:
|
|
|
|
|
* @rect_tool:
|
|
|
|
|
*
|
|
|
|
|
* Update integer representation of rectangle.
|
|
|
|
|
**/
|
|
|
|
|
static void
|
|
|
|
|
gimp_rectangle_tool_update_int_rect (GimpRectangleTool *rect_tool)
|
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *priv = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
|
|
|
|
|
2009-07-01 05:19:13 +08:00
|
|
|
|
priv->x1_int = RINT (priv->x1);
|
|
|
|
|
priv->y1_int = RINT (priv->y1);
|
2007-11-24 17:09:26 +08:00
|
|
|
|
|
|
|
|
|
if (gimp_rectangle_tool_rect_rubber_banding_func (rect_tool))
|
|
|
|
|
{
|
2009-07-01 05:19:13 +08:00
|
|
|
|
priv->width_int = (gint) RINT (priv->x2) - priv->x1_int;
|
|
|
|
|
priv->height_int = (gint) RINT (priv->y2) - priv->y1_int;
|
2007-11-24 17:09:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_get_public_rect:
|
|
|
|
|
* @rect_tool:
|
|
|
|
|
* @pub_x1:
|
|
|
|
|
* @pub_y1:
|
|
|
|
|
* @pub_x2:
|
|
|
|
|
* @pub_y2:
|
|
|
|
|
*
|
2008-06-05 00:09:57 +08:00
|
|
|
|
* This function returns the rectangle as it appears to be publicly
|
|
|
|
|
* (based on integer or double precision-mode).
|
2007-11-24 17:09:26 +08:00
|
|
|
|
**/
|
|
|
|
|
static void
|
|
|
|
|
gimp_rectangle_tool_get_public_rect (GimpRectangleTool *rect_tool,
|
|
|
|
|
gdouble *pub_x1,
|
|
|
|
|
gdouble *pub_y1,
|
|
|
|
|
gdouble *pub_x2,
|
|
|
|
|
gdouble *pub_y2)
|
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *priv;
|
|
|
|
|
|
|
|
|
|
priv = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
|
|
|
|
|
|
|
|
|
switch (priv->precision)
|
|
|
|
|
{
|
|
|
|
|
case GIMP_RECTANGLE_PRECISION_INT:
|
|
|
|
|
*pub_x1 = priv->x1_int;
|
|
|
|
|
*pub_y1 = priv->y1_int;
|
|
|
|
|
*pub_x2 = priv->x1_int + priv->width_int;
|
|
|
|
|
*pub_y2 = priv->y1_int + priv->height_int;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GIMP_RECTANGLE_PRECISION_DOUBLE:
|
|
|
|
|
default:
|
|
|
|
|
*pub_x1 = priv->x1;
|
|
|
|
|
*pub_y1 = priv->y1;
|
|
|
|
|
*pub_x2 = priv->x2;
|
|
|
|
|
*pub_y2 = priv->y2;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-03-09 18:40:42 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gimp_rectangle_tool_adjust_coord:
|
|
|
|
|
* @rect_tool:
|
|
|
|
|
* @ccoord_x_input:
|
|
|
|
|
* @ccoord_x_input:
|
|
|
|
|
* @ccoord_x_output:
|
|
|
|
|
* @ccoord_x_output:
|
|
|
|
|
*
|
|
|
|
|
* Transforms a coordinate to better fit the public behaviour of the
|
|
|
|
|
* rectangle.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
gimp_rectangle_tool_adjust_coord (GimpRectangleTool *rect_tool,
|
|
|
|
|
gdouble coord_x_input,
|
|
|
|
|
gdouble coord_y_input,
|
|
|
|
|
gdouble *coord_x_output,
|
|
|
|
|
gdouble *coord_y_output)
|
|
|
|
|
{
|
|
|
|
|
GimpRectangleToolPrivate *priv;
|
|
|
|
|
|
|
|
|
|
priv = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rect_tool);
|
|
|
|
|
|
|
|
|
|
switch (priv->precision)
|
|
|
|
|
{
|
|
|
|
|
case GIMP_RECTANGLE_PRECISION_INT:
|
2009-07-01 05:19:13 +08:00
|
|
|
|
*coord_x_output = RINT (coord_x_input);
|
|
|
|
|
*coord_y_output = RINT (coord_y_input);
|
2008-03-09 18:40:42 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case GIMP_RECTANGLE_PRECISION_DOUBLE:
|
|
|
|
|
default:
|
|
|
|
|
*coord_x_output = coord_x_input;
|
|
|
|
|
*coord_y_output = coord_y_input;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|