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-03-29 11:50:29 +08:00
|
|
|
#include "core/core-types.h"
|
|
|
|
#include "libgimptool/gimptooltypes.h"
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "gui/gui-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
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/gimpdrawable-transform-utils.h"
|
|
|
|
#include "core/gimptoolinfo.h"
|
2001-09-26 07:23:09 +08:00
|
|
|
|
|
|
|
#include "display/gimpdisplay.h"
|
2001-01-23 21:01:48 +08:00
|
|
|
|
2001-11-20 02:23:43 +08:00
|
|
|
#include "gui/info-dialog.h"
|
|
|
|
|
2001-04-25 02:43:31 +08:00
|
|
|
#include "gimpperspectivetool.h"
|
2001-04-29 04:14:32 +08:00
|
|
|
#include "transform_options.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1998-12-16 08:37:09 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-20 02:23:43 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
|
|
|
static void gimp_perspective_tool_class_init (GimpPerspectiveToolClass *klass);
|
|
|
|
static void gimp_perspective_tool_init (GimpPerspectiveTool *perspective_tool);
|
2001-04-25 02:43:31 +08:00
|
|
|
|
2001-11-20 02:23:43 +08:00
|
|
|
static TileManager * gimp_perspective_tool_transform (GimpTransformTool *transform_tool,
|
|
|
|
GimpDisplay *gdisp,
|
|
|
|
TransformState state);
|
|
|
|
|
|
|
|
static void perspective_tool_recalc (GimpTransformTool *tr_tool,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void perspective_tool_motion (GimpTransformTool *tr_tool,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void perspective_info_update (GimpTransformTool *tr_tool);
|
2000-12-31 12:07:42 +08:00
|
|
|
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* storage for information dialog fields */
|
2000-01-05 19:18:38 +08:00
|
|
|
static gchar matrix_row_buf [3][MAX_INFO_BUF];
|
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 */
|
|
|
|
|
|
|
|
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,
|
2001-11-21 07:00:47 +08:00
|
|
|
transform_options_new,
|
|
|
|
FALSE,
|
2002-03-21 20:17:17 +08:00
|
|
|
"gimp-perspective-tool",
|
2001-11-21 07:00:47 +08:00
|
|
|
_("Perspective Tool"),
|
|
|
|
_("Change perspective of the layer or selection"),
|
|
|
|
N_("/Tools/Transform Tools/Perspective"), "<shift>P",
|
|
|
|
NULL, "tools/perspective.html",
|
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),
|
2001-08-14 22:53:55 +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,
|
|
|
|
"GimpPerspectiveTool",
|
|
|
|
&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)
|
|
|
|
{
|
|
|
|
GimpTransformToolClass *trans_class;
|
|
|
|
|
|
|
|
trans_class = GIMP_TRANSFORM_TOOL_CLASS (klass);
|
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
|
|
|
trans_class->transform = gimp_perspective_tool_transform;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_perspective_tool_init (GimpPerspectiveTool *perspective_tool)
|
|
|
|
{
|
2001-11-21 07:00:47 +08:00
|
|
|
GimpTool *tool;
|
2001-08-14 22:53:55 +08:00
|
|
|
|
2001-11-21 07:00:47 +08:00
|
|
|
tool = GIMP_TOOL (perspective_tool);
|
2001-08-14 22:53:55 +08:00
|
|
|
|
2002-05-03 05:03:27 +08:00
|
|
|
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
|
|
|
|
gimp_tool_control_set_preserve (tool->control, FALSE);
|
|
|
|
gimp_tool_control_set_tool_cursor (tool->control, GIMP_PERSPECTIVE_TOOL_CURSOR);
|
2002-03-29 11:50:29 +08:00
|
|
|
|
2001-04-25 02:43:31 +08:00
|
|
|
}
|
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
static TileManager *
|
2001-04-25 02:43:31 +08:00
|
|
|
gimp_perspective_tool_transform (GimpTransformTool *transform_tool,
|
2001-10-29 19:47:11 +08:00
|
|
|
GimpDisplay *gdisp,
|
2001-04-25 02:43:31 +08:00
|
|
|
TransformState state)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
switch (state)
|
|
|
|
{
|
2000-12-29 23:22:01 +08:00
|
|
|
case TRANSFORM_INIT:
|
2001-11-22 21:01:26 +08:00
|
|
|
if (! transform_tool->info_dialog)
|
1998-08-14 04:19:09 +08:00
|
|
|
{
|
2001-11-22 21:01:26 +08:00
|
|
|
transform_tool->info_dialog =
|
1999-09-28 01:58:10 +08:00
|
|
|
info_dialog_new (_("Perspective Transform Information"),
|
2000-01-05 19:18:38 +08:00
|
|
|
gimp_standard_help_func,
|
|
|
|
"tools/transform_perspective.html");
|
2001-11-20 02:23:43 +08:00
|
|
|
|
2001-11-22 21:01:26 +08:00
|
|
|
gimp_transform_tool_info_dialog_connect (transform_tool,
|
2001-11-22 22:28:39 +08:00
|
|
|
GIMP_STOCK_TOOL_PERSPECTIVE);
|
2001-11-22 21:01:26 +08:00
|
|
|
|
|
|
|
info_dialog_add_label (transform_tool->info_dialog, _("Matrix:"),
|
1999-04-03 03:46:59 +08:00
|
|
|
matrix_row_buf[0]);
|
2001-11-22 21:01:26 +08:00
|
|
|
info_dialog_add_label (transform_tool->info_dialog, "",
|
|
|
|
matrix_row_buf[1]);
|
|
|
|
info_dialog_add_label (transform_tool->info_dialog, "",
|
|
|
|
matrix_row_buf[2]);
|
1998-08-14 04:19:09 +08:00
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-22 21:01:26 +08:00
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (transform_tool->info_dialog->shell),
|
|
|
|
TRUE);
|
|
|
|
|
|
|
|
transform_tool->trans_info[X0] = (gdouble) transform_tool->x1;
|
|
|
|
transform_tool->trans_info[Y0] = (gdouble) transform_tool->y1;
|
|
|
|
transform_tool->trans_info[X1] = (gdouble) transform_tool->x2;
|
|
|
|
transform_tool->trans_info[Y1] = (gdouble) transform_tool->y1;
|
|
|
|
transform_tool->trans_info[X2] = (gdouble) transform_tool->x1;
|
|
|
|
transform_tool->trans_info[Y2] = (gdouble) transform_tool->y2;
|
|
|
|
transform_tool->trans_info[X3] = (gdouble) transform_tool->x2;
|
|
|
|
transform_tool->trans_info[Y3] = (gdouble) transform_tool->y2;
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
case TRANSFORM_MOTION:
|
2001-11-20 02:23:43 +08:00
|
|
|
perspective_tool_motion (transform_tool, gdisp);
|
|
|
|
perspective_tool_recalc (transform_tool, gdisp);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
case TRANSFORM_RECALC:
|
2001-11-20 02:23:43 +08:00
|
|
|
perspective_tool_recalc (transform_tool, gdisp);
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
case TRANSFORM_FINISH:
|
2001-11-20 02:23:43 +08:00
|
|
|
return gimp_transform_tool_transform_tiles (transform_tool,
|
|
|
|
_("Perspective..."));
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-20 02:23:43 +08:00
|
|
|
perspective_info_update (GimpTransformTool *transform_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-11-20 02:23:43 +08:00
|
|
|
gint i;
|
1998-08-14 04:19:09 +08:00
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
{
|
2000-01-05 19:18:38 +08:00
|
|
|
gchar *p = matrix_row_buf[i];
|
|
|
|
gint j;
|
2001-11-20 02:23:43 +08:00
|
|
|
|
1998-08-14 04:19:09 +08:00
|
|
|
for (j = 0; j < 3; j++)
|
|
|
|
{
|
1999-04-05 20:48:48 +08:00
|
|
|
p += g_snprintf (p, MAX_INFO_BUF - (p - matrix_row_buf[i]),
|
2001-04-25 02:43:31 +08:00
|
|
|
"%10.3g", transform_tool->transform[i][j]);
|
1998-08-14 04:19:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-22 21:01:26 +08:00
|
|
|
info_dialog_update (transform_tool->info_dialog);
|
|
|
|
info_dialog_popup (transform_tool->info_dialog);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1998-03-19 06:35:31 +08:00
|
|
|
static void
|
2001-11-20 02:23:43 +08:00
|
|
|
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
|
2001-11-20 02:23:43 +08:00
|
|
|
perspective_tool_recalc (GimpTransformTool *transform_tool,
|
|
|
|
GimpDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-11-20 02:23:43 +08:00
|
|
|
gimp_drawable_transform_matrix_perspective (transform_tool->x1,
|
|
|
|
transform_tool->y1,
|
|
|
|
transform_tool->x2,
|
|
|
|
transform_tool->y2,
|
|
|
|
transform_tool->trans_info[X0],
|
|
|
|
transform_tool->trans_info[Y0],
|
|
|
|
transform_tool->trans_info[X1],
|
|
|
|
transform_tool->trans_info[Y1],
|
|
|
|
transform_tool->trans_info[X2],
|
|
|
|
transform_tool->trans_info[Y2],
|
|
|
|
transform_tool->trans_info[X3],
|
|
|
|
transform_tool->trans_info[Y3],
|
|
|
|
transform_tool->transform);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* transform the bounding box */
|
2001-04-25 02:43:31 +08:00
|
|
|
gimp_transform_tool_transform_bounding_box (transform_tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* update the information dialog */
|
2001-11-20 02:23:43 +08:00
|
|
|
perspective_info_update (transform_tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|