2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1997-11-25 06:05:25 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1997-11-25 06:05:25 +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
|
1997-11-25 06:05:25 +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/>.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2001-02-04 12:51:17 +08:00
|
|
|
#include <stdlib.h>
|
2008-05-23 22:09:55 +08:00
|
|
|
#include <string.h>
|
2001-02-04 12:51:17 +08:00
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2011-04-28 20:23:33 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
2001-01-24 07:56:18 +08:00
|
|
|
|
2002-05-03 20:45:22 +08:00
|
|
|
#include "tools-types.h"
|
|
|
|
|
2003-09-16 01:41:18 +08:00
|
|
|
#include "core/gimp-transform-utils.h"
|
2001-04-25 02:43:31 +08:00
|
|
|
|
2003-08-22 09:42:57 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
|
|
|
|
2001-04-25 02:43:31 +08:00
|
|
|
#include "gimpsheartool.h"
|
2003-04-16 00:05:52 +08:00
|
|
|
#include "gimptoolcontrol.h"
|
2003-02-09 05:12:03 +08:00
|
|
|
#include "gimptransformoptions.h"
|
1998-01-22 15:02:57 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2000-12-29 23:22:01 +08:00
|
|
|
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* index into trans_info array */
|
2011-03-28 06:50:46 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
HORZ_OR_VERT,
|
|
|
|
XSHEAR,
|
|
|
|
YSHEAR
|
|
|
|
};
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* the minimum movement before direction of shear can be determined (pixels) */
|
2000-01-05 19:18:38 +08:00
|
|
|
#define MIN_MOVE 5
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2006-03-31 21:36:34 +08:00
|
|
|
#define SB_WIDTH 10
|
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2004-08-06 21:56:34 +08:00
|
|
|
/* local function prototypes */
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2004-08-07 00:27:13 +08:00
|
|
|
static void gimp_shear_tool_dialog (GimpTransformTool *tr_tool);
|
|
|
|
static void gimp_shear_tool_dialog_update (GimpTransformTool *tr_tool);
|
2001-04-25 02:43:31 +08:00
|
|
|
|
2011-03-28 04:39:31 +08:00
|
|
|
static void gimp_shear_tool_prepare (GimpTransformTool *tr_tool);
|
|
|
|
static void gimp_shear_tool_motion (GimpTransformTool *tr_tool);
|
2011-03-28 05:12:11 +08:00
|
|
|
static void gimp_shear_tool_recalc_matrix (GimpTransformTool *tr_tool);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2006-03-31 21:36:34 +08:00
|
|
|
static void shear_x_mag_changed (GtkAdjustment *adj,
|
2004-08-07 00:27:13 +08:00
|
|
|
GimpTransformTool *tr_tool);
|
2006-03-31 21:36:34 +08:00
|
|
|
static void shear_y_mag_changed (GtkAdjustment *adj,
|
2004-08-07 00:27:13 +08:00
|
|
|
GimpTransformTool *tr_tool);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
|
|
|
|
2006-05-15 17:46:31 +08:00
|
|
|
G_DEFINE_TYPE (GimpShearTool, gimp_shear_tool, GIMP_TYPE_TRANSFORM_TOOL)
|
1998-08-15 21:34:54 +08:00
|
|
|
|
2001-04-25 02:43:31 +08:00
|
|
|
|
2003-08-22 09:42:57 +08:00
|
|
|
void
|
2002-03-29 11:50:29 +08:00
|
|
|
gimp_shear_tool_register (GimpToolRegisterCallback callback,
|
2002-05-03 19:31:08 +08:00
|
|
|
gpointer data)
|
2001-04-25 02:43:31 +08:00
|
|
|
{
|
2002-03-29 11:50:29 +08:00
|
|
|
(* callback) (GIMP_TYPE_SHEAR_TOOL,
|
2003-02-05 22:39:40 +08:00
|
|
|
GIMP_TYPE_TRANSFORM_OPTIONS,
|
|
|
|
gimp_transform_options_gui,
|
2003-06-28 19:20:37 +08:00
|
|
|
0,
|
2002-03-21 20:17:17 +08:00
|
|
|
"gimp-shear-tool",
|
2002-11-01 07:06:09 +08:00
|
|
|
_("Shear"),
|
2006-10-17 17:38:51 +08:00
|
|
|
_("Shear Tool: Shear the layer, selection or path"),
|
2004-04-29 21:19:28 +08:00
|
|
|
N_("S_hear"), "<shift>S",
|
2003-08-22 09:42:57 +08:00
|
|
|
NULL, GIMP_HELP_TOOL_SHEAR,
|
2002-03-29 11:50:29 +08:00
|
|
|
GIMP_STOCK_TOOL_SHEAR,
|
2002-05-03 19:31:08 +08:00
|
|
|
data);
|
2001-04-25 02:43:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_shear_tool_class_init (GimpShearToolClass *klass)
|
|
|
|
{
|
2004-06-05 07:08:29 +08:00
|
|
|
GimpTransformToolClass *trans_class = GIMP_TRANSFORM_TOOL_CLASS (klass);
|
2001-04-25 02:43:31 +08:00
|
|
|
|
2004-08-07 00:27:13 +08:00
|
|
|
trans_class->dialog = gimp_shear_tool_dialog;
|
|
|
|
trans_class->dialog_update = gimp_shear_tool_dialog_update;
|
|
|
|
trans_class->prepare = gimp_shear_tool_prepare;
|
|
|
|
trans_class->motion = gimp_shear_tool_motion;
|
2011-03-28 05:12:11 +08:00
|
|
|
trans_class->recalc_matrix = gimp_shear_tool_recalc_matrix;
|
2001-04-25 02:43:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_shear_tool_init (GimpShearTool *shear_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2003-10-21 05:27:34 +08:00
|
|
|
GimpTool *tool = GIMP_TOOL (shear_tool);
|
|
|
|
GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (shear_tool);
|
2001-04-29 04:14:32 +08:00
|
|
|
|
2004-06-05 07:08:29 +08:00
|
|
|
gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_SHEAR);
|
2002-06-17 01:13:39 +08:00
|
|
|
|
2008-05-23 22:09:55 +08:00
|
|
|
tr_tool->undo_desc = C_("command", "Shear");
|
2005-10-01 01:50:50 +08:00
|
|
|
tr_tool->progress_text = _("Shearing");
|
2006-06-20 16:22:39 +08:00
|
|
|
|
|
|
|
tr_tool->use_grid = TRUE;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-11-14 19:54:57 +08:00
|
|
|
gimp_shear_tool_dialog (GimpTransformTool *tr_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-08-06 21:56:34 +08:00
|
|
|
GimpShearTool *shear = GIMP_SHEAR_TOOL (tr_tool);
|
2006-03-31 21:36:34 +08:00
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *button;
|
|
|
|
|
|
|
|
table = gtk_table_new (2, 2, FALSE);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (table), 6);
|
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
|
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
|
2009-07-15 22:19:32 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (tr_tool->dialog))),
|
|
|
|
table, FALSE, FALSE, 0);
|
2006-03-31 21:36:34 +08:00
|
|
|
gtk_widget_show (table);
|
|
|
|
|
2010-10-19 18:27:33 +08:00
|
|
|
button = gimp_spin_button_new ((GtkObject **) &shear->x_adj,
|
2008-08-27 03:32:14 +08:00
|
|
|
0, -65536, 65536, 1, 15, 0, 1, 0);
|
2006-03-31 21:36:34 +08:00
|
|
|
gtk_entry_set_width_chars (GTK_ENTRY (button), SB_WIDTH);
|
2006-10-18 18:29:16 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0, _("Shear magnitude _X:"),
|
2006-03-31 21:36:34 +08:00
|
|
|
0.0, 0.5, button, 1, TRUE);
|
|
|
|
|
|
|
|
g_signal_connect (shear->x_adj, "value-changed",
|
2006-04-12 20:49:29 +08:00
|
|
|
G_CALLBACK (shear_x_mag_changed),
|
2006-03-31 21:36:34 +08:00
|
|
|
tr_tool);
|
|
|
|
|
2010-10-19 18:27:33 +08:00
|
|
|
button = gimp_spin_button_new ((GtkObject **) &shear->y_adj,
|
2008-08-27 03:32:14 +08:00
|
|
|
0, -65536, 65536, 1, 15, 0, 1, 0);
|
2006-03-31 21:36:34 +08:00
|
|
|
gtk_entry_set_width_chars (GTK_ENTRY (button), SB_WIDTH);
|
2006-10-18 18:29:16 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1, _("Shear magnitude _Y:"),
|
2006-03-31 21:36:34 +08:00
|
|
|
0.0, 0.5, button, 1, TRUE);
|
|
|
|
|
|
|
|
g_signal_connect (shear->y_adj, "value-changed",
|
2006-04-12 20:49:29 +08:00
|
|
|
G_CALLBACK (shear_y_mag_changed),
|
2006-03-31 21:36:34 +08:00
|
|
|
tr_tool);
|
1998-08-15 21:34:54 +08:00
|
|
|
}
|
|
|
|
|
2004-08-07 00:27:13 +08:00
|
|
|
static void
|
|
|
|
gimp_shear_tool_dialog_update (GimpTransformTool *tr_tool)
|
|
|
|
{
|
|
|
|
GimpShearTool *shear = GIMP_SHEAR_TOOL (tr_tool);
|
|
|
|
|
2010-10-19 18:27:33 +08:00
|
|
|
gtk_adjustment_set_value (shear->x_adj, tr_tool->trans_info[XSHEAR]);
|
|
|
|
gtk_adjustment_set_value (shear->y_adj, tr_tool->trans_info[YSHEAR]);
|
2004-08-07 00:27:13 +08:00
|
|
|
}
|
|
|
|
|
1998-08-15 21:34:54 +08:00
|
|
|
static void
|
2011-03-28 04:39:31 +08:00
|
|
|
gimp_shear_tool_prepare (GimpTransformTool *tr_tool)
|
1998-08-15 21:34:54 +08:00
|
|
|
{
|
2003-02-08 01:12:21 +08:00
|
|
|
tr_tool->trans_info[HORZ_OR_VERT] = GIMP_ORIENTATION_UNKNOWN;
|
2002-11-14 19:54:57 +08:00
|
|
|
tr_tool->trans_info[XSHEAR] = 0.0;
|
|
|
|
tr_tool->trans_info[YSHEAR] = 0.0;
|
1998-08-15 21:34:54 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
static void
|
2011-03-28 04:39:31 +08:00
|
|
|
gimp_shear_tool_motion (GimpTransformTool *tr_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-06-20 16:22:39 +08:00
|
|
|
gdouble diffx = tr_tool->curx - tr_tool->lastx;
|
|
|
|
gdouble diffy = tr_tool->cury - tr_tool->lasty;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* If we haven't yet decided on which way to control shearing
|
|
|
|
* decide using the maximum differential
|
|
|
|
*/
|
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
if (tr_tool->trans_info[HORZ_OR_VERT] == GIMP_ORIENTATION_UNKNOWN)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-01-05 19:18:38 +08:00
|
|
|
if (abs (diffx) > MIN_MOVE || abs (diffy) > MIN_MOVE)
|
2004-08-06 21:56:34 +08:00
|
|
|
{
|
|
|
|
if (abs (diffx) > abs (diffy))
|
|
|
|
{
|
|
|
|
tr_tool->trans_info[HORZ_OR_VERT] = GIMP_ORIENTATION_HORIZONTAL;
|
|
|
|
tr_tool->trans_info[XSHEAR] = 0.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tr_tool->trans_info[HORZ_OR_VERT] = GIMP_ORIENTATION_VERTICAL;
|
|
|
|
tr_tool->trans_info[XSHEAR] = 0.0;
|
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
/* set the current coords to the last ones */
|
|
|
|
else
|
2004-08-06 21:56:34 +08:00
|
|
|
{
|
|
|
|
tr_tool->curx = tr_tool->lastx;
|
|
|
|
tr_tool->cury = tr_tool->lasty;
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if the direction is known, keep track of the magnitude */
|
2006-06-20 16:22:39 +08:00
|
|
|
if (tr_tool->trans_info[HORZ_OR_VERT] == GIMP_ORIENTATION_HORIZONTAL)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-06-20 16:22:39 +08:00
|
|
|
if (tr_tool->cury > (tr_tool->ty1 + tr_tool->ty3) / 2)
|
|
|
|
tr_tool->trans_info[XSHEAR] += diffx;
|
|
|
|
else
|
|
|
|
tr_tool->trans_info[XSHEAR] -= diffx;
|
|
|
|
}
|
|
|
|
else if (tr_tool->trans_info[HORZ_OR_VERT] == GIMP_ORIENTATION_VERTICAL)
|
|
|
|
{
|
|
|
|
if (tr_tool->curx > (tr_tool->tx1 + tr_tool->tx2) / 2)
|
|
|
|
tr_tool->trans_info[YSHEAR] += diffy;
|
|
|
|
else
|
|
|
|
tr_tool->trans_info[YSHEAR] -= diffy;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-05 19:18:38 +08:00
|
|
|
static void
|
2011-03-28 05:12:11 +08:00
|
|
|
gimp_shear_tool_recalc_matrix (GimpTransformTool *tr_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-11-20 02:23:43 +08:00
|
|
|
gdouble amount;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-08-06 21:56:34 +08:00
|
|
|
if (tr_tool->trans_info[XSHEAR] == 0.0 &&
|
|
|
|
tr_tool->trans_info[YSHEAR] == 0.0)
|
2006-06-20 16:22:39 +08:00
|
|
|
{
|
|
|
|
tr_tool->trans_info[HORZ_OR_VERT] = GIMP_ORIENTATION_UNKNOWN;
|
|
|
|
}
|
2004-08-06 21:56:34 +08:00
|
|
|
|
2003-02-08 01:12:21 +08:00
|
|
|
if (tr_tool->trans_info[HORZ_OR_VERT] == GIMP_ORIENTATION_HORIZONTAL)
|
2002-11-14 19:54:57 +08:00
|
|
|
amount = tr_tool->trans_info[XSHEAR];
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
2002-11-14 19:54:57 +08:00
|
|
|
amount = tr_tool->trans_info[YSHEAR];
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-03-22 03:10:11 +08:00
|
|
|
gimp_matrix3_identity (&tr_tool->transform);
|
|
|
|
gimp_transform_matrix_shear (&tr_tool->transform,
|
|
|
|
tr_tool->x1,
|
2003-09-16 01:41:18 +08:00
|
|
|
tr_tool->y1,
|
app/core/gimp-transform-utils.[ch]. switch from x1,y1,x2,y2 bounding boxes
2004-10-27 Michael Natterer <mitch@gimp.org>
* app/core/gimp-transform-utils.[ch]. switch from x1,y1,x2,y2
bounding boxes to x,y,width,height ones. Added
gimp_transform_matrix_flip_free(). Renamed some parameters to be
consistent with others. Some internal cleanup.
* app/tools/gimpperspectivetool.c
* app/tools/gimpscaletool.c
* app/tools/gimpsheartool.c
* tools/pdbgen/pdb/drawable_transform.pdb
* tools/pdbgen/pdb/transform_tools.pdb: changed accordingly.
* tools/pdbgen/pdb/drawable_transform.pdb
* tools/pdbgen/pdb/transform_tools.pdb: guard all transform
wrappers with if(gimp_drawable_mask_intersect(...)), also the
ones which don't need the returned bounding box.
* tools/pdbgen/pdb/drawable_transform.pdb: renamed some parameters
and added gimp_drawable_transform_matrix() which takes the 9
coefficients of a 3x3 matrix for ultimate flexibility ;)
* app/pdb/drawable_transform_cmds.c
* app/pdb/internal_procs.c
* app/pdb/transform_tools_cmds.c
* libgimp/gimpdrawabletransform_pdb.[ch]: regenerated.
2004-10-28 01:56:02 +08:00
|
|
|
tr_tool->x2 - tr_tool->x1,
|
|
|
|
tr_tool->y2 - tr_tool->y1,
|
2003-09-16 01:41:18 +08:00
|
|
|
tr_tool->trans_info[HORZ_OR_VERT],
|
2005-03-22 03:10:11 +08:00
|
|
|
amount);
|
2002-11-14 19:54:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-03-31 21:36:34 +08:00
|
|
|
shear_x_mag_changed (GtkAdjustment *adj,
|
2002-11-18 21:10:04 +08:00
|
|
|
GimpTransformTool *tr_tool)
|
2002-11-14 19:54:57 +08:00
|
|
|
{
|
2006-03-31 21:36:34 +08:00
|
|
|
gdouble value = gtk_adjustment_get_value (adj);
|
2002-11-14 19:54:57 +08:00
|
|
|
|
|
|
|
if (value != tr_tool->trans_info[XSHEAR])
|
|
|
|
{
|
2002-11-18 21:10:04 +08:00
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tr_tool));
|
2002-11-14 19:54:57 +08:00
|
|
|
|
2004-08-06 21:56:34 +08:00
|
|
|
if (tr_tool->trans_info[HORZ_OR_VERT] == GIMP_ORIENTATION_UNKNOWN)
|
|
|
|
tr_tool->trans_info[HORZ_OR_VERT] = GIMP_ORIENTATION_HORIZONTAL;
|
|
|
|
|
2002-11-14 19:54:57 +08:00
|
|
|
tr_tool->trans_info[XSHEAR] = value;
|
|
|
|
|
2011-03-28 05:12:11 +08:00
|
|
|
gimp_transform_tool_recalc_matrix (tr_tool);
|
2004-08-07 00:27:13 +08:00
|
|
|
|
2002-11-18 21:10:04 +08:00
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tr_tool));
|
2002-11-14 19:54:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-03-31 21:36:34 +08:00
|
|
|
shear_y_mag_changed (GtkAdjustment *adj,
|
2002-11-18 21:10:04 +08:00
|
|
|
GimpTransformTool *tr_tool)
|
2002-11-14 19:54:57 +08:00
|
|
|
{
|
2006-03-31 21:36:34 +08:00
|
|
|
gdouble value = gtk_adjustment_get_value (adj);
|
2002-11-14 19:54:57 +08:00
|
|
|
|
|
|
|
if (value != tr_tool->trans_info[YSHEAR])
|
|
|
|
{
|
2002-11-18 21:10:04 +08:00
|
|
|
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tr_tool));
|
2002-11-14 19:54:57 +08:00
|
|
|
|
2004-08-06 21:56:34 +08:00
|
|
|
if (tr_tool->trans_info[HORZ_OR_VERT] == GIMP_ORIENTATION_UNKNOWN)
|
|
|
|
tr_tool->trans_info[HORZ_OR_VERT] = GIMP_ORIENTATION_VERTICAL;
|
|
|
|
|
2002-11-14 19:54:57 +08:00
|
|
|
tr_tool->trans_info[YSHEAR] = value;
|
|
|
|
|
2011-03-28 05:12:11 +08:00
|
|
|
gimp_transform_tool_recalc_matrix (tr_tool);
|
2004-08-07 00:27:13 +08:00
|
|
|
|
2002-11-18 21:10:04 +08:00
|
|
|
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tr_tool));
|
2002-11-14 19:54:57 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|