Commit acbdc4d5 authored by Michael Natterer's avatar Michael Natterer 😴

pdb: add gimp-item-transform-translate procedure

We were only able to translate selections and layers (bot not channels
and paths) via the PDB, this new procedure fixes that. Deprecation of
old API and some more transform consistency to follow...
parent 5b80d3d3
......@@ -28,7 +28,7 @@
#include "internal-procs.h"
/* 832 procedures registered total */
/* 833 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
......
......@@ -34,6 +34,7 @@
#include "core/gimpdrawable-transform.h"
#include "core/gimpdrawable.h"
#include "core/gimpimage.h"
#include "core/gimpitem-linked.h"
#include "core/gimpitem.h"
#include "core/gimpparamspecs.h"
#include "core/gimpprogress.h"
......@@ -47,6 +48,51 @@
#include "gimp-intl.h"
static GimpValueArray *
item_transform_translate_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
GimpItem *item;
gdouble off_x;
gdouble off_y;
item = gimp_value_get_item (gimp_value_array_index (args, 0), gimp);
off_x = g_value_get_double (gimp_value_array_index (args, 1));
off_y = g_value_get_double (gimp_value_array_index (args, 2));
if (success)
{
if (gimp_pdb_item_is_modifiable (item,
GIMP_PDB_ITEM_POSITION, error))
{
if (gimp_item_get_linked (item) && gimp_item_is_attached (item))
{
gimp_item_linked_translate (item, off_x, off_y, TRUE);
}
else
{
gimp_item_translate (item, off_x, off_y, TRUE);
}
}
else
success = FALSE;
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
gimp_value_set_item (gimp_value_array_index (return_vals, 1), item);
return return_vals;
}
static GimpValueArray *
item_transform_flip_simple_invoker (GimpProcedure *procedure,
Gimp *gimp,
......@@ -871,6 +917,49 @@ register_item_transform_procs (GimpPDB *pdb)
{
GimpProcedure *procedure;
/*
* gimp-item-transform-translate
*/
procedure = gimp_procedure_new (item_transform_translate_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-item-transform-translate");
gimp_procedure_set_static_strings (procedure,
"gimp-item-transform-translate",
"Translate the item by the specified offsets.",
"This procedure translates the item by the amounts specified in the off_x and off_y arguments. These can be negative, and are considered offsets from the current position. The offsets will be rounded to the nearest pixel unless the item is a path.\n"
"\n"
"If the item is attached to an image and has its linked flag set to TRUE, all additional items contained in the image which have the linked flag set to TRUE will also be translated by the specified offsets.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2018",
NULL);
gimp_procedure_add_argument (procedure,
gimp_param_spec_item_id ("item",
"item",
"The item",
pdb->gimp, FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
g_param_spec_double ("off-x",
"off x",
"Offset in x direction",
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
g_param_spec_double ("off-y",
"off y",
"Offset in y direction",
-G_MAXDOUBLE, G_MAXDOUBLE, 0,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
gimp_param_spec_item_id ("item",
"item",
"The translated item",
pdb->gimp, FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-item-transform-flip-simple
*/
......@@ -881,6 +970,7 @@ register_item_transform_procs (GimpPDB *pdb)
"gimp-item-transform-flip-simple",
"Flip the specified item either vertically or horizontally.",
"This procedure flips the specified item. If a selection exists and the item is a drawable, the portion of the drawable which lies under the selection is cut from the drawable and made into a floating selection which is then flipped. If auto_center is set to TRUE, the flip is around the selection's center. Otherwise, the coordinate of the axis needs to be specified. The return value is the ID of the flipped item. If there was no selection or the item is not a drawable, this will be equal to the item ID supplied as input. Otherwise, this will be the newly created and flipped drawable.\n"
"\n"
"This procedure is affected by the following context setters: 'gimp-context-set-transform-resize'.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
......@@ -932,6 +1022,7 @@ register_item_transform_procs (GimpPDB *pdb)
"gimp-item-transform-flip",
"Flip the specified item around a given line.",
"This procedure flips the specified item. If a selection exists and the item is a drawable , the portion of the drawable which lies under the selection is cut from the drawable and made into a floating selection which is then flipped. The axis to flip around is specified by specifying two points from that line. The return value is the ID of the flipped item. If there was no selection or the item is not a drawable, this will be equal to the item ID supplied as input. Otherwise, this will be the newly created and flipped drawable.\n"
"\n"
"This procedure is affected by the following context setters: 'gimp-context-set-interpolation', 'gimp-context-set-transform-direction', 'gimp-context-set-transform-resize'.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
......@@ -987,6 +1078,7 @@ register_item_transform_procs (GimpPDB *pdb)
"Perform a possibly non-affine transformation on the specified item.",
"This procedure performs a possibly non-affine transformation on the specified item by allowing the corners of the original bounding box to be arbitrarily remapped to any values. The specified item is remapped if no selection exists or it is not a drawable. However, if a selection exists and the item is a drawable, the portion of the drawable which lies under the selection is cut from the drawable and made into a floating selection which is then remapped as specified. The return value is the ID of the remapped item. If there was no selection or the item is not a drawable, this will be equal to the item ID supplied as input. Otherwise, this will be the newly created and remapped drawable. The 4 coordinates specify the new locations of each corner of the original bounding box. By specifying these values, any affine transformation (rotation, scaling, translation) can be affected. Additionally, these values can be specified such that the resulting transformed item will appear to have\n"
"been projected via a perspective transform.\n"
"\n"
"This procedure is affected by the following context setters: 'gimp-context-set-interpolation', 'gimp-context-set-transform-direction', 'gimp-context-set-transform-resize'.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
......@@ -1065,6 +1157,7 @@ register_item_transform_procs (GimpPDB *pdb)
"gimp-item-transform-rotate-simple",
"Rotate the specified item about given coordinates through the specified angle.",
"This function rotates the specified item. If a selection exists and the item is a drawable, the portion of the drawable which lies under the selection is cut from the drawable and made into a floating selection which is then rotated by the specified amount. The return value is the ID of the rotated item. If there was no selection or the item is not a drawable, this will be equal to the item ID supplied as input. Otherwise, this will be the newly created and rotated drawable.\n"
"\n"
"This procedure is affected by the following context setters: 'gimp-context-set-transform-resize'.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
......@@ -1120,6 +1213,7 @@ register_item_transform_procs (GimpPDB *pdb)
"gimp-item-transform-rotate",
"Rotate the specified item about given coordinates through the specified angle.",
"This function rotates the specified item. If a selection exists and the item is a drawable, the portion of the drawable which lies under the selection is cut from the drawable and made into a floating selection which is then rotated by the specified amount. The return value is the ID of the rotated item. If there was no selection or the item is not a drawable, this will be equal to the item ID supplied as input. Otherwise, this will be the newly created and rotated drawable.\n"
"\n"
"This procedure is affected by the following context setters: 'gimp-context-set-interpolation', 'gimp-context-set-transform-direction', 'gimp-context-set-transform-resize'.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
......@@ -1174,6 +1268,7 @@ register_item_transform_procs (GimpPDB *pdb)
"gimp-item-transform-scale",
"Scale the specified item.",
"This procedure scales the specified item. If a selection exists and the item is a drawable, the portion of the drawable which lies under the selection is cut from the drawable and made into a floating selection which is then scaled by the specified amount. The return value is the ID of the scaled item. If there was no selection or the item is not a drawable, this will be equal to the item ID supplied as input. Otherwise, this will be the newly created and scaled drawable.\n"
"\n"
"This procedure is affected by the following context setters: 'gimp-context-set-interpolation', 'gimp-context-set-transform-direction', 'gimp-context-set-transform-resize'.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
......@@ -1228,6 +1323,7 @@ register_item_transform_procs (GimpPDB *pdb)
"gimp-item-transform-shear",
"Shear the specified item about its center by the specified magnitude.",
"This procedure shears the specified item. If a selection exists and the item is a drawable, the portion of the drawable which lies under the selection is cut from the drawable and made into a floating selection which is then sheard by the specified amount. The return value is the ID of the sheard item. If there was no selection or the item is not a drawable, this will be equal to the item ID supplied as input. Otherwise, this will be the newly created and sheard drawable. The shear type parameter indicates whether the shear will be applied horizontally or vertically. The magnitude can be either positive or negative and indicates the extent (in pixels) to shear by.\n"
"\n"
"This procedure is affected by the following context setters: 'gimp-context-set-interpolation', 'gimp-context-set-transform-direction', 'gimp-context-set-transform-resize'.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
......@@ -1273,6 +1369,7 @@ register_item_transform_procs (GimpPDB *pdb)
"gimp-item-transform-2d",
"Transform the specified item in 2d.",
"This procedure transforms the specified item. If a selection exists and the item is a drawable, the portion of the drawable which lies under the selection is cut from the drawable and made into a floating selection which is then transformed. The transformation is done by scaling the image by the x and y scale factors about the point (source_x, source_y), then rotating around the same point, then translating that point to the new position (dest_x, dest_y). The return value is the ID of the rotated drawable. If there was no selection or the item is not a drawable, this will be equal to the item ID supplied as input. Otherwise, this will be the newly created and transformed drawable.\n"
"\n"
"This procedure is affected by the following context setters: 'gimp-context-set-interpolation', 'gimp-context-set-transform-direction', 'gimp-context-set-transform-resize'.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
......@@ -1345,6 +1442,7 @@ register_item_transform_procs (GimpPDB *pdb)
"gimp-item-transform-matrix",
"Transform the specified item in 2d.",
"This procedure transforms the specified item. If a selection exists and the item is a drawable, the portion of the drawable which lies under the selection is cut from the drawable and made into a floating selection which is then transformed. The transformation is done by assembling a 3x3 matrix from the coefficients passed. The return value is the ID of the transformed item. If there was no selection or the item is not a drawable, this will be equal to the item ID supplied as input. Otherwise, this will be the newly created and transformed drawable.\n"
"\n"
"This procedure is affected by the following context setters: 'gimp-context-set-interpolation', 'gimp-context-set-transform-direction', 'gimp-context-set-transform-resize'.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
......
......@@ -615,6 +615,7 @@ EXPORTS
gimp_item_transform_rotate_simple
gimp_item_transform_scale
gimp_item_transform_shear
gimp_item_transform_translate
gimp_layer_add_alpha
gimp_layer_add_mask
gimp_layer_color_space_get_type
......
......@@ -34,6 +34,52 @@
**/
/**
* gimp_item_transform_translate:
* @item_ID: The item.
* @off_x: Offset in x direction.
* @off_y: Offset in y direction.
*
* Translate the item by the specified offsets.
*
* This procedure translates the item by the amounts specified in the
* off_x and off_y arguments. These can be negative, and are considered
* offsets from the current position. The offsets will be rounded to
* the nearest pixel unless the item is a path.
*
* If the item is attached to an image and has its linked flag set to
* TRUE, all additional items contained in the image which have the
* linked flag set to TRUE will also be translated by the specified
* offsets.
*
* Returns: The translated item.
*
* Since: 2.10
**/
gint32
gimp_item_transform_translate (gint32 item_ID,
gdouble off_x,
gdouble off_y)
{
GimpParam *return_vals;
gint nreturn_vals;
gint32 ret_item_ID = -1;
return_vals = gimp_run_procedure ("gimp-item-transform-translate",
&nreturn_vals,
GIMP_PDB_ITEM, item_ID,
GIMP_PDB_FLOAT, off_x,
GIMP_PDB_FLOAT, off_y,
GIMP_PDB_END);
if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
ret_item_ID = return_vals[1].data.d_item;
gimp_destroy_params (return_vals, nreturn_vals);
return ret_item_ID;
}
/**
* gimp_item_transform_flip_simple:
* @item_ID: The affected item.
......@@ -52,6 +98,7 @@
* flipped item. If there was no selection or the item is not a
* drawable, this will be equal to the item ID supplied as input.
* Otherwise, this will be the newly created and flipped drawable.
*
* This procedure is affected by the following context setters:
* gimp_context_set_transform_resize().
*
......@@ -104,6 +151,7 @@ gimp_item_transform_flip_simple (gint32 item_ID,
* is not a drawable, this will be equal to the item ID supplied as
* input. Otherwise, this will be the newly created and flipped
* drawable.
*
* This procedure is affected by the following context setters:
* gimp_context_set_interpolation(),
* gimp_context_set_transform_direction(),
......@@ -171,6 +219,7 @@ gimp_item_transform_flip (gint32 item_ID,
* can be affected. Additionally, these values can be specified such
* that the resulting transformed item will appear to have been
* projected via a perspective transform.
*
* This procedure is affected by the following context setters:
* gimp_context_set_interpolation(),
* gimp_context_set_transform_direction(),
......@@ -235,6 +284,7 @@ gimp_item_transform_perspective (gint32 item_ID,
* the item is not a drawable, this will be equal to the item ID
* supplied as input. Otherwise, this will be the newly created and
* rotated drawable.
*
* This procedure is affected by the following context setters:
* gimp_context_set_transform_resize().
*
......@@ -289,6 +339,7 @@ gimp_item_transform_rotate_simple (gint32 item_ID,
* the item is not a drawable, this will be equal to the item ID
* supplied as input. Otherwise, this will be the newly created and
* rotated drawable.
*
* This procedure is affected by the following context setters:
* gimp_context_set_interpolation(),
* gimp_context_set_transform_direction(),
......@@ -344,6 +395,7 @@ gimp_item_transform_rotate (gint32 item_ID,
* item is not a drawable, this will be equal to the item ID supplied
* as input. Otherwise, this will be the newly created and scaled
* drawable.
*
* This procedure is affected by the following context setters:
* gimp_context_set_interpolation(),
* gimp_context_set_transform_direction(),
......@@ -401,6 +453,7 @@ gimp_item_transform_scale (gint32 item_ID,
* be applied horizontally or vertically. The magnitude can be either
* positive or negative and indicates the extent (in pixels) to shear
* by.
*
* This procedure is affected by the following context setters:
* gimp_context_set_interpolation(),
* gimp_context_set_transform_direction(),
......@@ -458,6 +511,7 @@ gimp_item_transform_shear (gint32 item_ID,
* selection or the item is not a drawable, this will be equal to the
* item ID supplied as input. Otherwise, this will be the newly created
* and transformed drawable.
*
* This procedure is affected by the following context setters:
* gimp_context_set_interpolation(),
* gimp_context_set_transform_direction(),
......@@ -525,6 +579,7 @@ gimp_item_transform_2d (gint32 item_ID,
* selection or the item is not a drawable, this will be equal to the
* item ID supplied as input. Otherwise, this will be the newly created
* and transformed drawable.
*
* This procedure is affected by the following context setters:
* gimp_context_set_interpolation(),
* gimp_context_set_transform_direction(),
......
......@@ -32,6 +32,9 @@ G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
gint32 gimp_item_transform_translate (gint32 item_ID,
gdouble off_x,
gdouble off_y);
gint32 gimp_item_transform_flip_simple (gint32 item_ID,
GimpOrientationType flip_type,
gboolean auto_center,
......
......@@ -98,6 +98,60 @@ CODE
# The defs
sub item_transform_translate {
$blurb = 'Translate the item by the specified offsets.';
$help = <<'HELP';
This procedure translates the item by the amounts specified in the
off_x and off_y arguments. These can be negative, and are considered
offsets from the current position. The offsets will be rounded to the
nearest pixel unless the item is a path.
If the item is attached to an image and has its linked flag set to
TRUE, all additional items contained in the image which have the
linked flag set to TRUE will also be translated by the specified
offsets.
HELP
&mitch_pdb_misc('2018', '2.10');
@inargs = (
{ name => 'item', type => 'item',
desc => 'The item' },
{ name => 'off_x', type => 'float',
desc => "Offset in x direction" },
{ name => 'off_y', type => 'float',
desc => "Offset in y direction" }
);
@outargs = (
{ name => 'item', type => 'item', no_declare => 1,
desc => 'The translated item' }
);
%invoke = (
code => <<'CODE'
{
if (gimp_pdb_item_is_modifiable (item,
GIMP_PDB_ITEM_POSITION, error))
{
if (gimp_item_get_linked (item) && gimp_item_is_attached (item))
{
gimp_item_linked_translate (item, off_x, off_y, TRUE);
}
else
{
gimp_item_translate (item, off_x, off_y, TRUE);
}
}
else
success = FALSE;
}
CODE
);
}
sub item_transform_flip_simple {
$blurb = <<'BLURB';
Flip the specified item either vertically or horizontally.
......@@ -114,6 +168,7 @@ item. If there was no selection or the item is not a drawable, this
will be equal to the item ID supplied as input. Otherwise, this will
be the newly created and flipped drawable.
This procedure is affected by the following context setters:
gimp_context_set_transform_resize().
HELP
......@@ -202,6 +257,7 @@ the flipped item. If there was no selection or the item is not a
drawable, this will be equal to the item ID supplied as input.
Otherwise, this will be the newly created and flipped drawable.
This procedure is affected by the following context setters:
gimp_context_set_interpolation(), gimp_context_set_transform_direction(),
gimp_context_set_transform_resize().
......@@ -257,6 +313,7 @@ translation) can be affected. Additionally, these values can be
specified such that the resulting transformed item will appear to
have been projected via a perspective transform.
This procedure is affected by the following context setters:
gimp_context_set_interpolation(), gimp_context_set_transform_direction(),
gimp_context_set_transform_resize().
......@@ -322,6 +379,7 @@ value is the ID of the rotated item. If there was no selection or the
item is not a drawable, this will be equal to the item ID supplied as
input. Otherwise, this will be the newly created and rotated drawable.
This procedure is affected by the following context setters:
gimp_context_set_transform_resize().
HELP
......@@ -414,6 +472,7 @@ value is the ID of the rotated item. If there was no selection or the
item is not a drawable, this will be equal to the item ID supplied as
input. Otherwise, this will be the newly created and rotated drawable.
This procedure is affected by the following context setters:
gimp_context_set_interpolation(), gimp_context_set_transform_direction(),
gimp_context_set_transform_resize().
......@@ -463,6 +522,7 @@ value is the ID of the scaled item. If there was no selection or the
item is not a drawable, this will be equal to the item ID supplied as
input. Otherwise, this will be the newly created and scaled drawable.
This procedure is affected by the following context setters:
gimp_context_set_interpolation(), gimp_context_set_transform_direction(),
gimp_context_set_transform_resize().
......@@ -518,6 +578,7 @@ drawable. The shear type parameter indicates whether the shear will be
applied horizontally or vertically. The magnitude can be either
positive or negative and indicates the extent (in pixels) to shear by.
This procedure is affected by the following context setters:
gimp_context_set_interpolation(), gimp_context_set_transform_direction(),
gimp_context_set_transform_resize().
......@@ -565,6 +626,7 @@ selection or the item is not a drawable, this will be equal to the
item ID supplied as input. Otherwise, this will be the newly created
and transformed drawable.
This procedure is affected by the following context setters:
gimp_context_set_interpolation(), gimp_context_set_transform_direction(),
gimp_context_set_transform_resize().
......@@ -620,6 +682,7 @@ the item is not a drawable, this will be equal to the item ID supplied
as input. Otherwise, this will be the newly created and transformed
drawable.
This procedure is affected by the following context setters:
gimp_context_set_interpolation(), gimp_context_set_transform_direction(),
gimp_context_set_transform_resize().
......@@ -675,12 +738,14 @@ CODE
"core/gimpdrawable.h"
"core/gimpdrawable-transform.h"
"core/gimpimage.h"
"core/gimpitem-linked.h"
"core/gimpprogress.h"
"gimppdb-utils.h"
"gimppdbcontext.h"
"gimp-intl.h");
@procs = qw(item_transform_flip_simple
@procs = qw(item_transform_translate
item_transform_flip_simple
item_transform_flip
item_transform_perspective
item_transform_rotate_simple
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment