2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-03-01 06:56:57 +00:00
|
|
|
* Copyright (C) 1995-2001 Spencer Kimball, Peter Mattis, and others
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-03-01 06:56:57 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-03-01 06:56:57 +00: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-17 22:28:01 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2001-03-01 06:56:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-10-09 20:24:04 +00:00
|
|
|
#include <gegl.h>
|
2001-03-01 06:56:57 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2007-03-09 13:00:01 +00:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2001-03-01 06:56:57 +00:00
|
|
|
|
2001-05-09 22:34:59 +00:00
|
|
|
#include "tools-types.h"
|
2002-05-03 12:45:22 +00:00
|
|
|
|
2006-09-28 11:07:55 +00:00
|
|
|
#include "core/gimp.h"
|
2001-11-19 18:23:43 +00:00
|
|
|
#include "core/gimpdrawable-transform.h"
|
2009-08-20 17:05:23 +02:00
|
|
|
#include "core/gimperror.h"
|
2001-05-09 02:32:03 +00:00
|
|
|
#include "core/gimpimage.h"
|
2003-02-13 11:23:50 +00:00
|
|
|
#include "core/gimpimage-undo.h"
|
2003-05-12 15:56:36 +00:00
|
|
|
#include "core/gimpitem-linked.h"
|
2001-05-09 02:32:03 +00:00
|
|
|
#include "core/gimplayer.h"
|
2017-04-06 00:29:30 +02:00
|
|
|
#include "core/gimplayermask.h"
|
2004-08-10 18:47:21 +00:00
|
|
|
#include "core/gimpprogress.h"
|
2001-05-09 02:32:03 +00:00
|
|
|
|
2003-07-16 14:08:24 +00:00
|
|
|
#include "vectors/gimpvectors.h"
|
|
|
|
|
2001-09-25 23:23:09 +00:00
|
|
|
#include "display/gimpdisplay.h"
|
2001-03-01 06:56:57 +00:00
|
|
|
|
2003-04-15 16:05:52 +00:00
|
|
|
#include "gimptoolcontrol.h"
|
2003-02-08 21:12:03 +00:00
|
|
|
#include "gimptransformoptions.h"
|
2003-02-14 14:14:29 +00:00
|
|
|
#include "gimptransformtool.h"
|
2001-03-15 04:57:24 +00:00
|
|
|
|
2003-03-25 16:38:19 +00:00
|
|
|
#include "gimp-intl.h"
|
2001-03-01 06:56:57 +00:00
|
|
|
|
2001-04-17 21:43:29 +00:00
|
|
|
|
2018-06-09 16:25:03 -04:00
|
|
|
static GeglBuffer * gimp_transform_tool_real_transform (GimpTransformTool *tr_tool,
|
|
|
|
GimpItem *item,
|
|
|
|
GeglBuffer *orig_buffer,
|
|
|
|
gint orig_offset_x,
|
|
|
|
gint orig_offset_y,
|
|
|
|
GimpColorProfile **buffer_profile,
|
|
|
|
gint *new_offset_x,
|
|
|
|
gint *new_offset_y);
|
2017-04-03 12:39:33 +02:00
|
|
|
|
2001-03-31 14:10:22 +00:00
|
|
|
|
2006-05-15 09:46:31 +00:00
|
|
|
G_DEFINE_TYPE (GimpTransformTool, gimp_transform_tool, GIMP_TYPE_DRAW_TOOL)
|
2005-12-13 09:13:50 +00:00
|
|
|
|
|
|
|
#define parent_class gimp_transform_tool_parent_class
|
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
2001-07-24 Michael Natterer <mitch@gimp.org>
Port to glib/gtk+ 2.0 episode I (every segfault has it's beginning)
* configure.in: require glib/gtk+ >= 1.3.7, commented out the
gtkxmhtml stuff.
From now on, you will need glib, pango, atk and gtk+ HEAD from CVS
to hack or use GIMP HEAD.
Beware, it crashes randomly :)
* app/core/Makefile.am
* app/core/gimpmarshal.list: new file plus rules to generate
gimpmarshal.[ch] from it.
* app/core/*
* app/tools/*
* app/widgets/*
* libgimpwidgets/*: started to use the glib object system. All
core/ objects are still gtk objects however. All signals are
created using g_signal_new(). There are many gtk+ artefacts left.
Finally, we will _not_ use the gtk_signal_foo() wrappers and
friends any more.
* app/colormaps.c
* app/devices.[ch]
* app/disp_callbacks.c
* app/errorconsole.c
* app/file-save.[ch]
* app/interface.c
* app/module_db.c
* app/nav_window.c
* app/ops_buttons.c
* app/scroll.c
* app/user_install.c
* app/gui/about-dialog.c
* app/gui/brush-editor.c
* app/gui/brushes-commands.c
* app/gui/color-notebook.c
* app/gui/colormap-dialog.c
* app/gui/dialogs-commands.c
* app/gui/dialogs-constructors.c
* app/gui/file-commands.c
* app/gui/file-dialog-utils.c
* app/gui/file-new-dialog.c
* app/gui/file-open-dialog.[ch]
* app/gui/file-save-dialog.c
* app/gui/gradient-editor.c
* app/gui/gradients-commands.c
* app/gui/image-commands.c
* app/gui/info-dialog.[ch]
* app/gui/layer-select.c
* app/gui/layers-commands.c
* app/gui/menus.c
* app/gui/offset-dialog.c
* app/gui/palette-editor.c
* app/gui/palettes-commands.c
* app/gui/patterns-commands.c
* app/gui/preferences-dialog.c
* app/gui/resize-dialog.[ch]
* app/gui/splash.c
* app/gui/tips-dialog.c
* app/gui/tool-options-dialog.c
* app/gui/toolbox.c
* app/gui/tools-commands.c
* libgimp/gimpbrushmenu.c
* libgimp/gimpmenu.c
* libgimp/gimppatternmenu.c
* libgimp/gimpui.c
* libgimpbase/gimpenv.c: tons and tons of changes like "const
gchar*", switch from GdkDeviceInfo to GdkDevice (very incomplete
and currently disables), lots of s/gtk_signal/g_signal/,
removal/replacement of deprecated stuff,
s/GtkSignalFunc/GCallback/ and lots of small changes and fixes
while I was on it, zillions of warnings left...
* modules/Makefile.am: disabled the water color selector
temporarily (XInput issues).
* plug-ins/Makefile.am
* plug-ins/common/.cvsignore
* plug-ins/common/Makefile.am
* plug-ins/common/plugin-defs.pl: simply excluded all plug-ins
which did not build (including Script-Fu). They are trivial to
fix.
2001-07-24 21:27:11 +00:00
|
|
|
|
2001-03-01 06:56:57 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_transform_tool_class_init (GimpTransformToolClass *klass)
|
|
|
|
{
|
2018-06-09 16:25:03 -04:00
|
|
|
klass->recalc_matrix = NULL;
|
|
|
|
klass->get_undo_desc = NULL;
|
|
|
|
klass->transform = gimp_transform_tool_real_transform;
|
|
|
|
|
|
|
|
klass->progress_text = _("Transforming");
|
2001-03-01 06:56:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-11-14 11:54:57 +00:00
|
|
|
gimp_transform_tool_init (GimpTransformTool *tr_tool)
|
2001-03-01 06:56:57 +00:00
|
|
|
{
|
2003-07-07 13:50:48 +00:00
|
|
|
gimp_matrix3_identity (&tr_tool->transform);
|
2018-01-27 04:29:03 -05:00
|
|
|
tr_tool->transform_valid = TRUE;
|
2001-03-01 06:56:57 +00:00
|
|
|
}
|
|
|
|
|
2012-03-21 14:30:47 +01:00
|
|
|
static GeglBuffer *
|
2002-11-18 13:10:04 +00:00
|
|
|
gimp_transform_tool_real_transform (GimpTransformTool *tr_tool,
|
2003-05-30 23:52:24 +00:00
|
|
|
GimpItem *active_item,
|
2012-03-21 14:30:47 +01:00
|
|
|
GeglBuffer *orig_buffer,
|
2011-03-26 18:45:58 +01:00
|
|
|
gint orig_offset_x,
|
|
|
|
gint orig_offset_y,
|
2016-05-08 18:35:40 +02:00
|
|
|
GimpColorProfile **buffer_profile,
|
2011-03-26 08:30:15 +01:00
|
|
|
gint *new_offset_x,
|
|
|
|
gint *new_offset_y)
|
2002-11-18 13:10:04 +00:00
|
|
|
{
|
2018-06-09 16:25:03 -04:00
|
|
|
GimpTransformToolClass *klass = GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool);
|
|
|
|
GimpTool *tool = GIMP_TOOL (tr_tool);
|
|
|
|
GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tool);
|
|
|
|
GimpContext *context = GIMP_CONTEXT (options);
|
|
|
|
GeglBuffer *ret = NULL;
|
|
|
|
GimpTransformResize clip = options->clip;
|
|
|
|
GimpProgress *progress;
|
2002-11-18 13:10:04 +00:00
|
|
|
|
2014-07-12 23:45:20 +02:00
|
|
|
progress = gimp_progress_start (GIMP_PROGRESS (tool), FALSE,
|
2018-06-09 16:25:03 -04:00
|
|
|
"%s", klass->progress_text);
|
2002-11-18 13:10:04 +00:00
|
|
|
|
2012-03-21 14:30:47 +01:00
|
|
|
if (orig_buffer)
|
2003-05-30 23:52:24 +00:00
|
|
|
{
|
2011-03-28 10:16:00 +02:00
|
|
|
/* this happens when transforming a selection cut out of a
|
|
|
|
* normal drawable, or the selection
|
2011-03-17 21:52:43 +01:00
|
|
|
*/
|
|
|
|
|
2018-03-24 16:49:01 -04:00
|
|
|
/* always clip the selection and unfloated channels
|
2011-03-17 21:52:43 +01:00
|
|
|
* so they keep their size
|
|
|
|
*/
|
|
|
|
if (GIMP_IS_CHANNEL (active_item) &&
|
2012-04-22 15:15:22 +02:00
|
|
|
! babl_format_has_alpha (gegl_buffer_get_format (orig_buffer)))
|
2012-04-21 22:42:53 +02:00
|
|
|
clip = GIMP_TRANSFORM_RESIZE_CLIP;
|
2011-03-17 21:52:43 +01:00
|
|
|
|
2012-03-21 14:30:47 +01:00
|
|
|
ret = gimp_drawable_transform_buffer_affine (GIMP_DRAWABLE (active_item),
|
|
|
|
context,
|
|
|
|
orig_buffer,
|
|
|
|
orig_offset_x,
|
|
|
|
orig_offset_y,
|
|
|
|
&tr_tool->transform,
|
|
|
|
options->direction,
|
|
|
|
options->interpolation,
|
|
|
|
clip,
|
2016-05-08 18:35:40 +02:00
|
|
|
buffer_profile,
|
2012-03-21 14:30:47 +01:00
|
|
|
new_offset_x,
|
|
|
|
new_offset_y,
|
|
|
|
progress);
|
2011-03-17 21:52:43 +01:00
|
|
|
}
|
2018-06-09 16:25:03 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* this happens for entire drawables, paths and layer groups */
|
2003-05-30 23:52:24 +00:00
|
|
|
|
2018-06-09 16:25:03 -04:00
|
|
|
if (gimp_item_get_linked (active_item))
|
2003-05-30 23:52:24 +00:00
|
|
|
{
|
2018-06-09 16:25:03 -04:00
|
|
|
gimp_item_linked_transform (active_item, context,
|
|
|
|
&tr_tool->transform,
|
|
|
|
options->direction,
|
|
|
|
options->interpolation,
|
|
|
|
clip,
|
|
|
|
progress);
|
2003-05-30 23:52:24 +00:00
|
|
|
}
|
2018-06-09 16:25:03 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* always clip layer masks so they keep their size
|
|
|
|
*/
|
|
|
|
if (GIMP_IS_CHANNEL (active_item))
|
|
|
|
clip = GIMP_TRANSFORM_RESIZE_CLIP;
|
2003-05-30 23:52:24 +00:00
|
|
|
|
2018-06-09 16:25:03 -04:00
|
|
|
gimp_item_transform (active_item, context,
|
|
|
|
&tr_tool->transform,
|
|
|
|
options->direction,
|
|
|
|
options->interpolation,
|
|
|
|
clip,
|
|
|
|
progress);
|
|
|
|
}
|
2001-11-19 18:23:43 +00:00
|
|
|
}
|
|
|
|
|
2018-06-09 16:25:03 -04:00
|
|
|
if (progress)
|
|
|
|
gimp_progress_end (progress);
|
2001-11-19 18:23:43 +00:00
|
|
|
|
2018-06-09 16:25:03 -04:00
|
|
|
return ret;
|
2001-11-19 18:23:43 +00:00
|
|
|
}
|
|
|
|
|
2018-06-09 16:25:03 -04:00
|
|
|
gboolean
|
2001-03-31 14:10:22 +00:00
|
|
|
gimp_transform_tool_bounds (GimpTransformTool *tr_tool,
|
2006-03-28 17:55:52 +00:00
|
|
|
GimpDisplay *display)
|
2001-03-01 06:56:57 +00:00
|
|
|
{
|
2018-06-09 16:25:03 -04:00
|
|
|
GimpTransformOptions *options;
|
|
|
|
GimpImage *image;
|
2015-05-02 00:00:39 -04:00
|
|
|
gboolean non_empty = TRUE;
|
2006-06-27 18:52:24 +00:00
|
|
|
|
2018-06-09 16:25:03 -04:00
|
|
|
g_return_val_if_fail (GIMP_IS_TRANSFORM_TOOL (tr_tool), FALSE);
|
|
|
|
|
|
|
|
options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool);
|
|
|
|
image = gimp_display_get_image (display);
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
|
|
|
|
|
2011-03-26 18:45:58 +01:00
|
|
|
switch (options->type)
|
2001-03-01 06:56:57 +00:00
|
|
|
{
|
2011-03-26 18:45:58 +01:00
|
|
|
case GIMP_TRANSFORM_TYPE_LAYER:
|
|
|
|
{
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
2015-05-02 00:00:39 -04:00
|
|
|
gint x, y;
|
|
|
|
gint width, height;
|
2003-05-30 23:52:24 +00:00
|
|
|
|
2011-03-26 18:45:58 +01:00
|
|
|
drawable = gimp_image_get_active_drawable (image);
|
|
|
|
|
|
|
|
gimp_item_get_offset (GIMP_ITEM (drawable), &offset_x, &offset_y);
|
|
|
|
|
2015-05-02 00:00:39 -04:00
|
|
|
non_empty = gimp_item_mask_intersect (GIMP_ITEM (drawable),
|
|
|
|
&x, &y, &width, &height);
|
|
|
|
tr_tool->x1 = x + offset_x;
|
|
|
|
tr_tool->y1 = y + offset_y;
|
|
|
|
tr_tool->x2 = x + width + offset_x;
|
|
|
|
tr_tool->y2 = y + height + offset_y;
|
2011-03-26 18:45:58 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_TRANSFORM_TYPE_SELECTION:
|
2017-05-13 22:52:20 +02:00
|
|
|
{
|
|
|
|
gimp_item_bounds (GIMP_ITEM (gimp_image_get_mask (image)),
|
|
|
|
&tr_tool->x1, &tr_tool->y1,
|
|
|
|
&tr_tool->x2, &tr_tool->y2);
|
|
|
|
tr_tool->x2 += tr_tool->x1;
|
|
|
|
tr_tool->y2 += tr_tool->y1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-03-26 18:45:58 +01:00
|
|
|
case GIMP_TRANSFORM_TYPE_PATH:
|
2017-05-13 22:52:20 +02:00
|
|
|
{
|
|
|
|
GimpChannel *selection = gimp_image_get_mask (image);
|
|
|
|
|
|
|
|
/* if selection is not empty, use its bounds to perform the
|
|
|
|
* transformation of the path
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (! gimp_channel_is_empty (selection))
|
|
|
|
{
|
|
|
|
gimp_item_bounds (GIMP_ITEM (selection),
|
|
|
|
&tr_tool->x1, &tr_tool->y1,
|
|
|
|
&tr_tool->x2, &tr_tool->y2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* without selection, test the emptiness of the path bounds :
|
|
|
|
* if empty, use the canvas bounds
|
|
|
|
* else use the path bounds
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (! gimp_item_bounds (GIMP_ITEM (gimp_image_get_active_vectors (image)),
|
|
|
|
&tr_tool->x1, &tr_tool->y1,
|
|
|
|
&tr_tool->x2, &tr_tool->y2))
|
|
|
|
{
|
|
|
|
tr_tool->x1 = 0;
|
|
|
|
tr_tool->y1 = 0;
|
|
|
|
tr_tool->x2 = gimp_image_get_width (image);
|
|
|
|
tr_tool->y2 = gimp_image_get_height (image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tr_tool->x2 += tr_tool->x1;
|
|
|
|
tr_tool->y2 += tr_tool->y1;
|
|
|
|
}
|
|
|
|
|
2011-03-26 18:45:58 +01:00
|
|
|
break;
|
2001-03-01 06:56:57 +00:00
|
|
|
}
|
2001-03-09 07:09:12 +00:00
|
|
|
|
2015-05-02 00:00:39 -04:00
|
|
|
return non_empty;
|
2001-03-01 06:56:57 +00:00
|
|
|
}
|
|
|
|
|
2004-08-06 16:27:13 +00:00
|
|
|
void
|
2017-06-17 03:02:01 +02:00
|
|
|
gimp_transform_tool_recalc_matrix (GimpTransformTool *tr_tool,
|
2018-06-09 16:25:03 -04:00
|
|
|
GimpDisplay *display)
|
2001-03-01 06:56:57 +00:00
|
|
|
{
|
2011-03-27 17:38:49 +02:00
|
|
|
g_return_if_fail (GIMP_IS_TRANSFORM_TOOL (tr_tool));
|
2018-06-09 16:25:03 -04:00
|
|
|
g_return_if_fail (GIMP_IS_DISPLAY (display));
|
2011-08-13 17:42:41 +02:00
|
|
|
|
2018-06-09 16:25:03 -04:00
|
|
|
gimp_transform_tool_bounds (tr_tool, display);
|
2011-08-13 17:42:41 +02:00
|
|
|
|
2018-06-09 16:25:03 -04:00
|
|
|
if (GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->recalc_matrix)
|
|
|
|
GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->recalc_matrix (tr_tool);
|
2011-08-13 17:42:41 +02:00
|
|
|
}
|
2014-02-05 00:54:39 +01:00
|
|
|
|
2018-06-09 16:25:03 -04:00
|
|
|
GimpItem *
|
|
|
|
gimp_transform_tool_get_active_item (GimpTransformTool *tr_tool,
|
2018-06-10 03:48:30 -04:00
|
|
|
GimpDisplay *display)
|
2014-02-05 00:54:39 +01:00
|
|
|
{
|
2018-06-09 16:25:03 -04:00
|
|
|
GimpTransformOptions *options;
|
|
|
|
GimpImage *image;
|
2018-06-10 03:48:30 -04:00
|
|
|
GimpItem *item = NULL;
|
2014-02-05 00:54:39 +01:00
|
|
|
|
2018-06-09 16:25:03 -04:00
|
|
|
g_return_val_if_fail (GIMP_IS_TRANSFORM_TOOL (tr_tool), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_DISPLAY (display), NULL);
|
2014-02-05 00:54:39 +01:00
|
|
|
|
2018-06-09 16:25:03 -04:00
|
|
|
options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool);
|
2014-02-05 00:54:39 +01:00
|
|
|
|
2018-06-09 16:25:03 -04:00
|
|
|
image = gimp_display_get_image (display);
|
2014-02-05 00:54:39 +01:00
|
|
|
|
2018-06-09 16:25:03 -04:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
2014-02-05 00:54:39 +01:00
|
|
|
|
|
|
|
switch (options->type)
|
|
|
|
{
|
|
|
|
case GIMP_TRANSFORM_TYPE_LAYER:
|
2018-06-10 03:48:30 -04:00
|
|
|
item = GIMP_ITEM (gimp_image_get_active_drawable (image));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_TRANSFORM_TYPE_SELECTION:
|
|
|
|
item = GIMP_ITEM (gimp_image_get_mask (image));
|
|
|
|
|
|
|
|
if (gimp_channel_is_empty (GIMP_CHANNEL (item)))
|
|
|
|
item = NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_TRANSFORM_TYPE_PATH:
|
|
|
|
item = GIMP_ITEM (gimp_image_get_active_vectors (image));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpItem *
|
|
|
|
gimp_transform_tool_check_active_item (GimpTransformTool *tr_tool,
|
|
|
|
GimpDisplay *display,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GimpTransformOptions *options;
|
|
|
|
GimpItem *item;
|
|
|
|
const gchar *null_message = NULL;
|
|
|
|
const gchar *locked_message = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_TRANSFORM_TOOL (tr_tool), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_DISPLAY (display), NULL);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
|
|
|
options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool);
|
|
|
|
|
|
|
|
item = gimp_transform_tool_get_active_item (tr_tool, display);
|
|
|
|
|
|
|
|
switch (options->type)
|
|
|
|
{
|
|
|
|
case GIMP_TRANSFORM_TYPE_LAYER:
|
2014-02-05 00:54:39 +01:00
|
|
|
null_message = _("There is no layer to transform.");
|
|
|
|
|
2017-04-03 12:39:33 +02:00
|
|
|
if (item)
|
2014-02-05 00:54:39 +01:00
|
|
|
{
|
2017-04-03 12:39:33 +02:00
|
|
|
if (gimp_item_is_content_locked (item))
|
|
|
|
locked_message = _("The active layer's pixels are locked.");
|
|
|
|
else if (gimp_item_is_position_locked (item))
|
|
|
|
locked_message = _("The active layer's position and size are locked.");
|
|
|
|
|
2018-06-10 03:48:30 -04:00
|
|
|
if (! gimp_item_is_visible (item))
|
2017-04-03 12:39:33 +02:00
|
|
|
{
|
|
|
|
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
|
|
|
_("The active layer is not visible."));
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-06-09 16:25:03 -04:00
|
|
|
|
|
|
|
if (! gimp_transform_tool_bounds (tr_tool, display))
|
|
|
|
{
|
|
|
|
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
|
|
|
_("The selection does not intersect with the layer."));
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-02-05 00:54:39 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_TRANSFORM_TYPE_SELECTION:
|
2014-11-27 08:30:56 +01:00
|
|
|
null_message = _("There is no selection to transform.");
|
2014-02-05 00:54:39 +01:00
|
|
|
|
2017-04-03 12:39:33 +02:00
|
|
|
if (item)
|
|
|
|
{
|
|
|
|
/* cannot happen, so don't translate these messages */
|
|
|
|
if (gimp_item_is_content_locked (item))
|
|
|
|
locked_message = "The selection's pixels are locked.";
|
|
|
|
else if (gimp_item_is_position_locked (item))
|
|
|
|
locked_message = "The selection's position and size are locked.";
|
|
|
|
}
|
2014-02-05 00:54:39 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_TRANSFORM_TYPE_PATH:
|
|
|
|
null_message = _("There is no path to transform.");
|
|
|
|
|
2017-04-03 12:39:33 +02:00
|
|
|
if (item)
|
|
|
|
{
|
|
|
|
if (gimp_item_is_content_locked (item))
|
|
|
|
locked_message = _("The active path's strokes are locked.");
|
|
|
|
else if (gimp_item_is_position_locked (item))
|
|
|
|
locked_message = _("The active path's position is locked.");
|
2017-05-13 22:52:20 +02:00
|
|
|
else if (! gimp_vectors_get_n_strokes (GIMP_VECTORS (item)))
|
|
|
|
locked_message = _("The active path has no strokes.");
|
2017-04-03 12:39:33 +02:00
|
|
|
}
|
2014-02-05 00:54:39 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! item)
|
|
|
|
{
|
|
|
|
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, null_message);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-04-03 12:39:33 +02:00
|
|
|
if (locked_message)
|
2014-02-05 00:54:39 +01:00
|
|
|
{
|
|
|
|
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED, locked_message);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
2017-04-03 12:39:33 +02:00
|
|
|
|
2018-06-09 16:25:03 -04:00
|
|
|
gboolean
|
|
|
|
gimp_transform_tool_transform (GimpTransformTool *tr_tool,
|
|
|
|
GimpDisplay *display)
|
2017-04-06 00:15:42 +02:00
|
|
|
{
|
2018-06-09 16:25:03 -04:00
|
|
|
GimpTool *tool;
|
|
|
|
GimpTransformOptions *options;
|
|
|
|
GimpContext *context;
|
|
|
|
GimpImage *image;
|
|
|
|
GimpItem *active_item;
|
|
|
|
GeglBuffer *orig_buffer = NULL;
|
|
|
|
gint orig_offset_x = 0;
|
|
|
|
gint orig_offset_y = 0;
|
|
|
|
GeglBuffer *new_buffer;
|
|
|
|
gint new_offset_x;
|
|
|
|
gint new_offset_y;
|
|
|
|
GimpColorProfile *buffer_profile;
|
|
|
|
gchar *undo_desc = NULL;
|
|
|
|
gboolean new_layer = FALSE;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_TRANSFORM_TOOL (tr_tool), FALSE);
|
|
|
|
g_return_val_if_fail (GIMP_IS_DISPLAY (display), FALSE);
|
|
|
|
|
|
|
|
tool = GIMP_TOOL (tr_tool);
|
|
|
|
options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tool);
|
|
|
|
context = GIMP_CONTEXT (options);
|
|
|
|
image = gimp_display_get_image (display);
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
|
|
|
|
|
2018-06-10 03:48:30 -04:00
|
|
|
active_item = gimp_transform_tool_check_active_item (tr_tool, display,
|
|
|
|
&error);
|
2018-06-09 16:25:03 -04:00
|
|
|
|
|
|
|
if (! active_item)
|
2017-04-06 00:15:42 +02:00
|
|
|
{
|
2018-06-09 16:25:03 -04:00
|
|
|
gimp_tool_message_literal (tool, display, error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_transform_tool_recalc_matrix (tr_tool, display);
|
2017-04-06 00:15:42 +02:00
|
|
|
|
2018-06-09 16:25:03 -04:00
|
|
|
if (! tr_tool->transform_valid)
|
|
|
|
{
|
|
|
|
gimp_tool_message_literal (tool, display,
|
|
|
|
_("The current transform is invalid"));
|
|
|
|
return FALSE;
|
2017-04-06 00:15:42 +02:00
|
|
|
}
|
|
|
|
|
2018-06-09 16:25:03 -04:00
|
|
|
if (GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->recalc_matrix &&
|
|
|
|
gimp_matrix3_is_identity (&tr_tool->transform))
|
|
|
|
{
|
|
|
|
/* No need to commit an identity transformation! */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_set_busy (display->gimp);
|
|
|
|
|
|
|
|
/* We're going to dirty this image, but we want to keep the tool around */
|
|
|
|
gimp_tool_control_push_preserve (tool->control, TRUE);
|
|
|
|
|
|
|
|
undo_desc = GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->get_undo_desc (tr_tool);
|
|
|
|
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_TRANSFORM, undo_desc);
|
|
|
|
g_free (undo_desc);
|
|
|
|
|
|
|
|
switch (options->type)
|
|
|
|
{
|
|
|
|
case GIMP_TRANSFORM_TYPE_LAYER:
|
|
|
|
if (! gimp_viewable_get_children (GIMP_VIEWABLE (tool->drawable)) &&
|
|
|
|
! gimp_channel_is_empty (gimp_image_get_mask (image)))
|
|
|
|
{
|
|
|
|
orig_buffer = gimp_drawable_transform_cut (tool->drawable,
|
|
|
|
context,
|
|
|
|
&orig_offset_x,
|
|
|
|
&orig_offset_y,
|
|
|
|
&new_layer);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_TRANSFORM_TYPE_SELECTION:
|
|
|
|
orig_buffer = g_object_ref (gimp_drawable_get_buffer (GIMP_DRAWABLE (active_item)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_TRANSFORM_TYPE_PATH:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send the request for the transformation to the tool...
|
|
|
|
*/
|
|
|
|
new_buffer = GIMP_TRANSFORM_TOOL_GET_CLASS (tr_tool)->transform (tr_tool,
|
|
|
|
active_item,
|
|
|
|
orig_buffer,
|
|
|
|
orig_offset_x,
|
|
|
|
orig_offset_y,
|
|
|
|
&buffer_profile,
|
|
|
|
&new_offset_x,
|
|
|
|
&new_offset_y);
|
|
|
|
|
|
|
|
if (orig_buffer)
|
|
|
|
g_object_unref (orig_buffer);
|
|
|
|
|
|
|
|
switch (options->type)
|
2017-04-06 00:15:42 +02:00
|
|
|
{
|
2018-06-09 16:25:03 -04:00
|
|
|
case GIMP_TRANSFORM_TYPE_LAYER:
|
|
|
|
if (new_buffer)
|
|
|
|
{
|
|
|
|
/* paste the new transformed image to the image...also implement
|
|
|
|
* undo...
|
|
|
|
*/
|
|
|
|
gimp_drawable_transform_paste (tool->drawable,
|
|
|
|
new_buffer, buffer_profile,
|
|
|
|
new_offset_x, new_offset_y,
|
|
|
|
new_layer);
|
|
|
|
g_object_unref (new_buffer);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_TRANSFORM_TYPE_SELECTION:
|
|
|
|
if (new_buffer)
|
|
|
|
{
|
|
|
|
gimp_channel_push_undo (GIMP_CHANNEL (active_item), NULL);
|
2017-04-06 00:15:42 +02:00
|
|
|
|
2018-06-09 16:25:03 -04:00
|
|
|
gimp_drawable_set_buffer (GIMP_DRAWABLE (active_item),
|
|
|
|
FALSE, NULL, new_buffer);
|
|
|
|
g_object_unref (new_buffer);
|
|
|
|
}
|
|
|
|
break;
|
2017-04-06 00:15:42 +02:00
|
|
|
|
2018-06-09 16:25:03 -04:00
|
|
|
case GIMP_TRANSFORM_TYPE_PATH:
|
|
|
|
/* Nothing to be done */
|
|
|
|
break;
|
2017-04-06 00:15:42 +02:00
|
|
|
}
|
|
|
|
|
2018-06-09 16:25:03 -04:00
|
|
|
gimp_image_undo_group_end (image);
|
2017-04-03 12:39:33 +02:00
|
|
|
|
2018-06-09 16:25:03 -04:00
|
|
|
/* We're done dirtying the image, and would like to be restarted if
|
|
|
|
* the image gets dirty while the tool exists
|
|
|
|
*/
|
|
|
|
gimp_tool_control_pop_preserve (tool->control);
|
|
|
|
|
|
|
|
gimp_unset_busy (display->gimp);
|
|
|
|
|
|
|
|
gimp_image_flush (image);
|
|
|
|
|
|
|
|
return TRUE;
|
2017-04-03 12:39:33 +02:00
|
|
|
}
|