1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
#include <gtk/gtk.h>
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-01-24 07:56:18 +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-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpimage.h"
|
2001-11-20 02:23:43 +08:00
|
|
|
#include "core/gimpdrawable-transform.h"
|
|
|
|
#include "core/gimptoolinfo.h"
|
2001-09-26 07:23:09 +08:00
|
|
|
|
2003-08-22 09:42:57 +08:00
|
|
|
#include "widgets/gimphelp-ids.h"
|
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
2001-01-23 21:01:48 +08:00
|
|
|
|
2003-08-22 09:42:57 +08:00
|
|
|
#ifdef __GNUC__
|
2004-09-13 23:15:23 +08:00
|
|
|
#warning FIXME #include "dialogs/dialogs-types.h"
|
2003-08-22 09:42:57 +08:00
|
|
|
#endif
|
2004-09-13 23:15:23 +08:00
|
|
|
#include "dialogs/dialogs-types.h"
|
|
|
|
#include "dialogs/info-dialog.h"
|
2001-11-20 02:23:43 +08:00
|
|
|
|
2001-04-25 02:43:31 +08:00
|
|
|
#include "gimpperspectivetool.h"
|
2003-04-16 00:05:52 +08:00
|
|
|
#include "gimptoolcontrol.h"
|
2003-02-09 05:12:03 +08:00
|
|
|
#include "gimptransformoptions.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
1998-12-16 08:37:09 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-20 02:23:43 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2002-11-14 19:54:57 +08:00
|
|
|
static void gimp_perspective_tool_class_init (GimpPerspectiveToolClass *klass);
|
|
|
|
static void gimp_perspective_tool_init (GimpPerspectiveTool *tool);
|
2001-04-25 02:43:31 +08:00
|
|
|
|
2004-08-07 00:27:13 +08:00
|
|
|
static void gimp_perspective_tool_dialog (GimpTransformTool *tr_tool);
|
|
|
|
static void gimp_perspective_tool_dialog_update (GimpTransformTool *tr_tool);
|
|
|
|
static void gimp_perspective_tool_prepare (GimpTransformTool *tr_tool,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void gimp_perspective_tool_motion (GimpTransformTool *tr_tool,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void gimp_perspective_tool_recalc (GimpTransformTool *tr_tool,
|
|
|
|
GimpDisplay *gdisp);
|
2001-11-20 02:23:43 +08:00
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
|
2004-08-07 00:27:13 +08:00
|
|
|
/* private variables */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-04-25 02:43:31 +08:00
|
|
|
static GimpTransformToolClass *parent_class = NULL;
|
|
|
|
|
2001-07-07 20:17:23 +08:00
|
|
|
|
2001-04-25 02:43:31 +08:00
|
|
|
/* public functions */
|
|
|
|
|
2003-08-22 09:42:57 +08:00
|
|
|
void
|
2002-03-29 11:50:29 +08:00
|
|
|
gimp_perspective_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_PERSPECTIVE_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-perspective-tool",
|
2002-11-01 07:06:09 +08:00
|
|
|
_("Perspective"),
|
2001-11-21 07:00:47 +08:00
|
|
|
_("Change perspective of the layer or selection"),
|
2004-04-29 21:19:28 +08:00
|
|
|
N_("_Perspective"), "<shift>P",
|
2003-08-22 09:42:57 +08:00
|
|
|
NULL, GIMP_HELP_TOOL_PERSPECTIVE,
|
2002-03-29 11:50:29 +08:00
|
|
|
GIMP_STOCK_TOOL_PERSPECTIVE,
|
2002-05-03 19:31:08 +08:00
|
|
|
data);
|
2001-04-25 02:43:31 +08:00
|
|
|
}
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
GType
|
2001-04-25 02:43:31 +08:00
|
|
|
gimp_perspective_tool_get_type (void)
|
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
static GType tool_type = 0;
|
2001-04-25 02:43:31 +08:00
|
|
|
|
|
|
|
if (! tool_type)
|
|
|
|
{
|
2001-08-14 22:53:55 +08:00
|
|
|
static const GTypeInfo tool_info =
|
2001-04-25 02:43:31 +08:00
|
|
|
{
|
|
|
|
sizeof (GimpPerspectiveToolClass),
|
2004-06-14 18:48:00 +08:00
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_perspective_tool_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpPerspectiveTool),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_perspective_tool_init,
|
2001-04-25 02:43:31 +08:00
|
|
|
};
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
tool_type = g_type_register_static (GIMP_TYPE_TRANSFORM_TOOL,
|
2004-06-14 18:48:00 +08:00
|
|
|
"GimpPerspectiveTool",
|
2001-08-14 22:53:55 +08:00
|
|
|
&tool_info, 0);
|
2001-04-25 02:43:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return tool_type;
|
|
|
|
}
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
static void
|
|
|
|
gimp_perspective_tool_class_init (GimpPerspectiveToolClass *klass)
|
|
|
|
{
|
2004-06-14 18:48:00 +08:00
|
|
|
GimpTransformToolClass *trans_class = GIMP_TRANSFORM_TOOL_CLASS (klass);
|
2001-08-14 22:53:55 +08:00
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
2004-08-07 00:27:13 +08:00
|
|
|
trans_class->dialog = gimp_perspective_tool_dialog;
|
|
|
|
trans_class->dialog_update = gimp_perspective_tool_dialog_update;
|
|
|
|
trans_class->prepare = gimp_perspective_tool_prepare;
|
|
|
|
trans_class->motion = gimp_perspective_tool_motion;
|
|
|
|
trans_class->recalc = gimp_perspective_tool_recalc;
|
2001-08-14 22:53:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_perspective_tool_init (GimpPerspectiveTool *perspective_tool)
|
|
|
|
{
|
2003-10-21 05:27:34 +08:00
|
|
|
GimpTool *tool = GIMP_TOOL (perspective_tool);
|
|
|
|
GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (perspective_tool);
|
2001-08-14 22:53:55 +08:00
|
|
|
|
2002-06-17 01:13:39 +08:00
|
|
|
gimp_tool_control_set_tool_cursor (tool->control,
|
2004-06-05 07:08:29 +08:00
|
|
|
GIMP_TOOL_CURSOR_PERSPECTIVE);
|
2002-11-14 19:54:57 +08:00
|
|
|
|
2003-10-21 05:27:34 +08:00
|
|
|
tr_tool->shell_desc = _("Perspective Transform Information");
|
2005-10-01 01:50:50 +08:00
|
|
|
tr_tool->progress_text = _("Perspective");
|
2001-04-25 02:43:31 +08:00
|
|
|
}
|
|
|
|
|
2002-11-14 19:54:57 +08:00
|
|
|
static void
|
|
|
|
gimp_perspective_tool_dialog (GimpTransformTool *tr_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-08-07 00:27:13 +08:00
|
|
|
GimpPerspectiveTool *perspective = GIMP_PERSPECTIVE_TOOL (tr_tool);
|
|
|
|
|
2002-11-14 19:54:57 +08:00
|
|
|
info_dialog_add_label (tr_tool->info_dialog, _("Matrix:"),
|
2004-08-07 00:27:13 +08:00
|
|
|
perspective->matrix_row_buf[0]);
|
2002-11-14 19:54:57 +08:00
|
|
|
info_dialog_add_label (tr_tool->info_dialog, "",
|
2004-08-07 00:27:13 +08:00
|
|
|
perspective->matrix_row_buf[1]);
|
2002-11-14 19:54:57 +08:00
|
|
|
info_dialog_add_label (tr_tool->info_dialog, "",
|
2004-08-07 00:27:13 +08:00
|
|
|
perspective->matrix_row_buf[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_perspective_tool_dialog_update (GimpTransformTool *tr_tool)
|
|
|
|
{
|
|
|
|
GimpPerspectiveTool *perspective = GIMP_PERSPECTIVE_TOOL (tr_tool);
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
gchar *p = perspective->matrix_row_buf[i];
|
|
|
|
gint j;
|
|
|
|
|
|
|
|
for (j = 0; j < 3; j++)
|
|
|
|
{
|
|
|
|
p += g_snprintf (p,
|
|
|
|
MAX_INFO_BUF - (p - perspective->matrix_row_buf[i]),
|
|
|
|
"%10.3g", tr_tool->transform.coeff[i][j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
info_dialog_update (tr_tool->info_dialog);
|
|
|
|
info_dialog_show (tr_tool->info_dialog);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-11-14 19:54:57 +08:00
|
|
|
gimp_perspective_tool_prepare (GimpTransformTool *tr_tool,
|
|
|
|
GimpDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-11-14 19:54:57 +08:00
|
|
|
tr_tool->trans_info[X0] = (gdouble) tr_tool->x1;
|
|
|
|
tr_tool->trans_info[Y0] = (gdouble) tr_tool->y1;
|
|
|
|
tr_tool->trans_info[X1] = (gdouble) tr_tool->x2;
|
|
|
|
tr_tool->trans_info[Y1] = (gdouble) tr_tool->y1;
|
|
|
|
tr_tool->trans_info[X2] = (gdouble) tr_tool->x1;
|
|
|
|
tr_tool->trans_info[Y2] = (gdouble) tr_tool->y2;
|
|
|
|
tr_tool->trans_info[X3] = (gdouble) tr_tool->x2;
|
|
|
|
tr_tool->trans_info[Y3] = (gdouble) tr_tool->y2;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-03-19 06:35:31 +08:00
|
|
|
static void
|
2002-11-14 19:54:57 +08:00
|
|
|
gimp_perspective_tool_motion (GimpTransformTool *transform_tool,
|
|
|
|
GimpDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-02-20 17:59:50 +08:00
|
|
|
gdouble diff_x, diff_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-04-25 02:43:31 +08:00
|
|
|
diff_x = transform_tool->curx - transform_tool->lastx;
|
|
|
|
diff_y = transform_tool->cury - transform_tool->lasty;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-04-25 02:43:31 +08:00
|
|
|
switch (transform_tool->function)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-12-29 23:22:01 +08:00
|
|
|
case TRANSFORM_HANDLE_1:
|
2001-11-22 22:28:39 +08:00
|
|
|
transform_tool->trans_info[X0] += diff_x;
|
|
|
|
transform_tool->trans_info[Y0] += diff_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
2000-12-29 23:22:01 +08:00
|
|
|
case TRANSFORM_HANDLE_2:
|
2001-11-22 22:28:39 +08:00
|
|
|
transform_tool->trans_info[X1] += diff_x;
|
|
|
|
transform_tool->trans_info[Y1] += diff_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
2000-12-29 23:22:01 +08:00
|
|
|
case TRANSFORM_HANDLE_3:
|
2001-11-22 22:28:39 +08:00
|
|
|
transform_tool->trans_info[X2] += diff_x;
|
|
|
|
transform_tool->trans_info[Y2] += diff_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
2000-12-29 23:22:01 +08:00
|
|
|
case TRANSFORM_HANDLE_4:
|
2001-11-22 22:28:39 +08:00
|
|
|
transform_tool->trans_info[X3] += diff_x;
|
|
|
|
transform_tool->trans_info[Y3] += diff_y;
|
|
|
|
break;
|
|
|
|
case TRANSFORM_HANDLE_CENTER:
|
|
|
|
transform_tool->trans_info[X0] += diff_x;
|
|
|
|
transform_tool->trans_info[Y0] += diff_y;
|
|
|
|
transform_tool->trans_info[X1] += diff_x;
|
|
|
|
transform_tool->trans_info[Y1] += diff_y;
|
|
|
|
transform_tool->trans_info[X2] += diff_x;
|
|
|
|
transform_tool->trans_info[Y2] += diff_y;
|
|
|
|
transform_tool->trans_info[X3] += diff_x;
|
|
|
|
transform_tool->trans_info[Y3] += diff_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
2000-01-05 19:18:38 +08:00
|
|
|
default:
|
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-05 19:18:38 +08:00
|
|
|
static void
|
2002-11-14 19:54:57 +08:00
|
|
|
gimp_perspective_tool_recalc (GimpTransformTool *tr_tool,
|
|
|
|
GimpDisplay *gdisp)
|
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_perspective (&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[X0],
|
|
|
|
tr_tool->trans_info[Y0],
|
|
|
|
tr_tool->trans_info[X1],
|
|
|
|
tr_tool->trans_info[Y1],
|
|
|
|
tr_tool->trans_info[X2],
|
|
|
|
tr_tool->trans_info[Y2],
|
|
|
|
tr_tool->trans_info[X3],
|
2005-03-22 03:10:11 +08:00
|
|
|
tr_tool->trans_info[Y3]);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|