pdb: add gimp_image_insert_layer,channel,vectors()

which all take "parent" parameters and allow to insert items in a
tree. We don't have channel or vectors trees (yet) but API symmetry is
more important here than a currently useless parameter.
This commit is contained in:
Michael Natterer 2010-09-05 23:54:23 +02:00
parent 6af4cd6cff
commit a547c5d200
6 changed files with 533 additions and 8 deletions

View File

@ -930,6 +930,51 @@ image_add_layer_invoker (GimpProcedure *procedure,
error ? *error : NULL);
}
static GValueArray *
image_insert_layer_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpImage *image;
GimpLayer *layer;
GimpLayer *parent;
gint32 position;
image = gimp_value_get_image (&args->values[0], gimp);
layer = gimp_value_get_layer (&args->values[1], gimp);
parent = gimp_value_get_layer (&args->values[2], gimp);
position = g_value_get_int (&args->values[3]);
if (success)
{
if (gimp_pdb_item_is_floating (GIMP_ITEM (layer), image, error) &&
gimp_pdb_image_is_base_type (image,
GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (GIMP_DRAWABLE (layer))),
error) &&
(parent == NULL ||
(gimp_pdb_item_is_in_tree (GIMP_ITEM (parent), image, FALSE, error) &&
gimp_pdb_item_is_group (GIMP_ITEM (parent), error))))
{
if (position == -1 && parent == NULL)
parent = GIMP_IMAGE_ACTIVE_PARENT;
success = gimp_image_add_layer (image, layer,
parent, MAX (position, -1), TRUE);
}
else
{
success = FALSE;
}
}
return gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static GValueArray *
image_remove_layer_invoker (GimpProcedure *procedure,
Gimp *gimp,
@ -992,6 +1037,48 @@ image_add_channel_invoker (GimpProcedure *procedure,
error ? *error : NULL);
}
static GValueArray *
image_insert_channel_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpImage *image;
GimpChannel *channel;
GimpChannel *parent;
gint32 position;
image = gimp_value_get_image (&args->values[0], gimp);
channel = gimp_value_get_channel (&args->values[1], gimp);
parent = gimp_value_get_channel (&args->values[2], gimp);
position = g_value_get_int (&args->values[3]);
if (success)
{
if (gimp_pdb_item_is_floating (GIMP_ITEM (channel), image, error) &&
(parent == NULL ||
(gimp_pdb_item_is_in_tree (GIMP_ITEM (parent), image, FALSE, error) &&
gimp_pdb_item_is_group (GIMP_ITEM (parent), error))))
{
if (position == -1 && parent == NULL)
parent = GIMP_IMAGE_ACTIVE_PARENT;
success = gimp_image_add_channel (image, channel,
parent, MAX (position, -1), TRUE);
}
else
{
success = FALSE;
}
}
return gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static GValueArray *
image_remove_channel_invoker (GimpProcedure *procedure,
Gimp *gimp,
@ -1054,6 +1141,48 @@ image_add_vectors_invoker (GimpProcedure *procedure,
error ? *error : NULL);
}
static GValueArray *
image_insert_vectors_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpImage *image;
GimpVectors *vectors;
GimpVectors *parent;
gint32 position;
image = gimp_value_get_image (&args->values[0], gimp);
vectors = gimp_value_get_vectors (&args->values[1], gimp);
parent = gimp_value_get_vectors (&args->values[2], gimp);
position = g_value_get_int (&args->values[3]);
if (success)
{
if (gimp_pdb_item_is_floating (GIMP_ITEM (vectors), image, error) &&
(parent == NULL ||
(gimp_pdb_item_is_in_tree (GIMP_ITEM (parent), image, FALSE, error) &&
gimp_pdb_item_is_group (GIMP_ITEM (parent), error))))
{
if (position == -1 && parent == NULL)
parent = GIMP_IMAGE_ACTIVE_PARENT;
success = gimp_image_add_vectors (image, vectors,
parent, MAX (position, -1), TRUE);
}
else
{
success = FALSE;
}
}
return gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
}
static GValueArray *
image_remove_vectors_invoker (GimpProcedure *procedure,
Gimp *gimp,
@ -2803,7 +2932,7 @@ register_image_procs (GimpPDB *pdb)
gimp_procedure_set_static_strings (procedure,
"gimp-image-new",
"Creates a new image with the specified width, height, and type.",
"Creates a new image, undisplayed with the specified extents and type. A layer should be created and added before this image is displayed, or subsequent calls to 'gimp-display-new' with this image as an argument will fail. Layers can be created using the 'gimp-layer-new' commands. They can be added to an image using the 'gimp-image-add-layer' command.",
"Creates a new image, undisplayed with the specified extents and type. A layer should be created and added before this image is displayed, or subsequent calls to 'gimp-display-new' with this image as an argument will fail. Layers can be created using the 'gimp-layer-new' commands. They can be added to an image using the 'gimp-image-insert-layer' command.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
@ -3609,6 +3738,47 @@ register_image_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-image-insert-layer
*/
procedure = gimp_procedure_new (image_insert_layer_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-image-insert-layer");
gimp_procedure_set_static_strings (procedure,
"gimp-image-insert-layer",
"Add the specified layer to the image.",
"This procedure adds the specified layer to the image at the given position. If the position is specified as -1 and the parent is specified as NULL, then the layer is inserted above the active layer. The layer type must be compatible with the image base type.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
NULL);
gimp_procedure_add_argument (procedure,
gimp_param_spec_image_id ("image",
"image",
"The image",
pdb->gimp, FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_layer_id ("layer",
"layer",
"The layer",
pdb->gimp, FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_layer_id ("parent",
"parent",
"The parent layer",
pdb->gimp, FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_int32 ("position",
"position",
"The layer position",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-image-remove-layer
*/
@ -3673,6 +3843,47 @@ register_image_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-image-insert-channel
*/
procedure = gimp_procedure_new (image_insert_channel_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-image-insert-channel");
gimp_procedure_set_static_strings (procedure,
"gimp-image-insert-channel",
"Add the specified channel to the image.",
"This procedure adds the specified channel to the image at the given position. If the position is specified as -1 and the parent is specified as NULL, then the channel is inserted above the active channel.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
NULL);
gimp_procedure_add_argument (procedure,
gimp_param_spec_image_id ("image",
"image",
"The image",
pdb->gimp, FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_channel_id ("channel",
"channel",
"The channel",
pdb->gimp, FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_channel_id ("parent",
"parent",
"The parent channel",
pdb->gimp, FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_int32 ("position",
"position",
"The channel position",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-image-remove-channel
*/
@ -3737,6 +3948,47 @@ register_image_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-image-insert-vectors
*/
procedure = gimp_procedure_new (image_insert_vectors_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-image-insert-vectors");
gimp_procedure_set_static_strings (procedure,
"gimp-image-insert-vectors",
"Add the specified vectors to the image.",
"This procedure adds the specified vectors to the image at the given position. If the position is specified as -1 and the parent is specified as NULL, then the vectors is inserted above the active vectors.",
"Spencer Kimball & Peter Mattis",
"Spencer Kimball & Peter Mattis",
"1995-1996",
NULL);
gimp_procedure_add_argument (procedure,
gimp_param_spec_image_id ("image",
"image",
"The image",
pdb->gimp, FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_vectors_id ("vectors",
"vectors",
"The vectors",
pdb->gimp, FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_vectors_id ("parent",
"parent",
"The parent vectors",
pdb->gimp, FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_int32 ("position",
"position",
"The vectors position",
G_MININT32, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-image-remove-vectors
*/

View File

@ -28,7 +28,7 @@
#include "internal-procs.h"
/* 637 procedures registered total */
/* 640 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)

View File

@ -361,6 +361,9 @@ EXPORTS
gimp_image_grid_set_spacing
gimp_image_grid_set_style
gimp_image_height
gimp_image_insert_channel
gimp_image_insert_layer
gimp_image_insert_vectors
gimp_image_is_dirty
gimp_image_is_valid
gimp_image_list

View File

@ -123,7 +123,7 @@ gimp_image_list (gint *num_images)
* displayed, or subsequent calls to gimp_display_new() with this image
* as an argument will fail. Layers can be created using the
* gimp_layer_new() commands. They can be added to an image using the
* gimp_image_add_layer() command.
* gimp_image_insert_layer() command.
*
* Returns: The ID of the newly created image.
*/
@ -1006,6 +1006,47 @@ gimp_image_add_layer (gint32 image_ID,
return success;
}
/**
* gimp_image_insert_layer:
* @image_ID: The image.
* @layer_ID: The layer.
* @parent_ID: The parent layer.
* @position: The layer position.
*
* Add the specified layer to the image.
*
* This procedure adds the specified layer to the image at the given
* position. If the position is specified as -1 and the parent is
* specified as NULL, then the layer is inserted above the active
* layer. The layer type must be compatible with the image base type.
*
* Returns: TRUE on success.
*/
gboolean
gimp_image_insert_layer (gint32 image_ID,
gint32 layer_ID,
gint32 parent_ID,
gint position)
{
GimpParam *return_vals;
gint nreturn_vals;
gboolean success = TRUE;
return_vals = gimp_run_procedure ("gimp-image-insert-layer",
&nreturn_vals,
GIMP_PDB_IMAGE, image_ID,
GIMP_PDB_LAYER, layer_ID,
GIMP_PDB_LAYER, parent_ID,
GIMP_PDB_INT32, position,
GIMP_PDB_END);
success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
gimp_destroy_params (return_vals, nreturn_vals);
return success;
}
/**
* gimp_image_remove_layer:
* @image_ID: The image.
@ -1080,6 +1121,47 @@ gimp_image_add_channel (gint32 image_ID,
return success;
}
/**
* gimp_image_insert_channel:
* @image_ID: The image.
* @channel_ID: The channel.
* @parent_ID: The parent channel.
* @position: The channel position.
*
* Add the specified channel to the image.
*
* This procedure adds the specified channel to the image at the given
* position. If the position is specified as -1 and the parent is
* specified as NULL, then the channel is inserted above the active
* channel.
*
* Returns: TRUE on success.
*/
gboolean
gimp_image_insert_channel (gint32 image_ID,
gint32 channel_ID,
gint32 parent_ID,
gint position)
{
GimpParam *return_vals;
gint nreturn_vals;
gboolean success = TRUE;
return_vals = gimp_run_procedure ("gimp-image-insert-channel",
&nreturn_vals,
GIMP_PDB_IMAGE, image_ID,
GIMP_PDB_CHANNEL, channel_ID,
GIMP_PDB_CHANNEL, parent_ID,
GIMP_PDB_INT32, position,
GIMP_PDB_END);
success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
gimp_destroy_params (return_vals, nreturn_vals);
return success;
}
/**
* gimp_image_remove_channel:
* @image_ID: The image.
@ -1150,6 +1232,47 @@ gimp_image_add_vectors (gint32 image_ID,
return success;
}
/**
* gimp_image_insert_vectors:
* @image_ID: The image.
* @vectors_ID: The vectors.
* @parent_ID: The parent vectors.
* @position: The vectors position.
*
* Add the specified vectors to the image.
*
* This procedure adds the specified vectors to the image at the given
* position. If the position is specified as -1 and the parent is
* specified as NULL, then the vectors is inserted above the active
* vectors.
*
* Returns: TRUE on success.
*/
gboolean
gimp_image_insert_vectors (gint32 image_ID,
gint32 vectors_ID,
gint32 parent_ID,
gint position)
{
GimpParam *return_vals;
gint nreturn_vals;
gboolean success = TRUE;
return_vals = gimp_run_procedure ("gimp-image-insert-vectors",
&nreturn_vals,
GIMP_PDB_IMAGE, image_ID,
GIMP_PDB_VECTORS, vectors_ID,
GIMP_PDB_VECTORS, parent_ID,
GIMP_PDB_INT32, position,
GIMP_PDB_END);
success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
gimp_destroy_params (return_vals, nreturn_vals);
return success;
}
/**
* gimp_image_remove_vectors:
* @image_ID: The image.

View File

@ -87,16 +87,28 @@ gint32 gimp_image_pick_correlate_layer (gint32
gboolean gimp_image_add_layer (gint32 image_ID,
gint32 layer_ID,
gint position);
gboolean gimp_image_insert_layer (gint32 image_ID,
gint32 layer_ID,
gint32 parent_ID,
gint position);
gboolean gimp_image_remove_layer (gint32 image_ID,
gint32 layer_ID);
gboolean gimp_image_add_channel (gint32 image_ID,
gint32 channel_ID,
gint position);
gboolean gimp_image_insert_channel (gint32 image_ID,
gint32 channel_ID,
gint32 parent_ID,
gint position);
gboolean gimp_image_remove_channel (gint32 image_ID,
gint32 channel_ID);
gboolean gimp_image_add_vectors (gint32 image_ID,
gint32 vectors_ID,
gint position);
gboolean gimp_image_insert_vectors (gint32 image_ID,
gint32 vectors_ID,
gint32 parent_ID,
gint position);
gboolean gimp_image_remove_vectors (gint32 image_ID,
gint32 vectors_ID);
gint gimp_image_get_item_position (gint32 image_ID,

View File

@ -91,7 +91,7 @@ type. A layer should be created and added before this image is
displayed, or subsequent calls to gimp_display_new() with this image
as an argument will fail. Layers can be created using the
gimp_layer_new() commands. They can be added to an image using the
gimp_image_add_layer() command.
gimp_image_insert_layer() command.
HELP
&std_pdb_misc;
@ -1200,6 +1200,53 @@ HELP
CODE
}
sub image_insert_layer {
$blurb = 'Add the specified layer to the image.';
$help = <<'HELP';
This procedure adds the specified layer to the image at the given
position. If the position is specified as -1 and the parent is
specified as NULL, then the layer is inserted above the active
layer. The layer type must be compatible with the image base type.
HELP
&std_pdb_misc;
@inargs = (
{ name => 'image', type => 'image',
desc => 'The image' },
{ name => 'layer', type => 'layer',
desc => 'The layer' },
{ name => 'parent', type => 'layer',
desc => 'The parent layer' },
{ name => 'position', type => 'int32',
desc => 'The layer position' }
);
$invoke{code} = <<'CODE';
{
if (gimp_pdb_item_is_floating (GIMP_ITEM (layer), image, error) &&
gimp_pdb_image_is_base_type (image,
GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (GIMP_DRAWABLE (layer))),
error) &&
(parent == NULL ||
(gimp_pdb_item_is_in_tree (GIMP_ITEM (parent), image, FALSE, error) &&
gimp_pdb_item_is_group (GIMP_ITEM (parent), error))))
{
if (position == -1 && parent == NULL)
parent = GIMP_IMAGE_ACTIVE_PARENT;
success = gimp_image_add_layer (image, layer,
parent, MAX (position, -1), TRUE);
}
else
{
success = FALSE;
}
}
CODE
}
sub image_remove_layer {
$blurb = 'Remove the specified layer from the image.';
@ -1394,6 +1441,50 @@ CODE
);
}
sub image_insert_channel {
$blurb = 'Add the specified channel to the image.';
$help = <<'HELP';
This procedure adds the specified channel to the image at the given
position. If the position is specified as -1 and the parent is
specified as NULL, then the channel is inserted above the active
channel.
HELP
&std_pdb_misc;
@inargs = (
{ name => 'image', type => 'image',
desc => 'The image' },
{ name => 'channel', type => 'channel',
desc => 'The channel' },
{ name => 'parent', type => 'channel',
desc => 'The parent channel' },
{ name => 'position', type => 'int32',
desc => 'The channel position' }
);
$invoke{code} = <<'CODE';
{
if (gimp_pdb_item_is_floating (GIMP_ITEM (channel), image, error) &&
(parent == NULL ||
(gimp_pdb_item_is_in_tree (GIMP_ITEM (parent), image, FALSE, error) &&
gimp_pdb_item_is_group (GIMP_ITEM (parent), error))))
{
if (position == -1 && parent == NULL)
parent = GIMP_IMAGE_ACTIVE_PARENT;
success = gimp_image_add_channel (image, channel,
parent, MAX (position, -1), TRUE);
}
else
{
success = FALSE;
}
}
CODE
}
sub image_remove_channel {
$blurb = 'Remove the specified channel from the image.';
@ -1459,6 +1550,50 @@ HELP
CODE
}
sub image_insert_vectors {
$blurb = 'Add the specified vectors to the image.';
$help = <<'HELP';
This procedure adds the specified vectors to the image at the given
position. If the position is specified as -1 and the parent is
specified as NULL, then the vectors is inserted above the active
vectors.
HELP
&std_pdb_misc;
@inargs = (
{ name => 'image', type => 'image',
desc => 'The image' },
{ name => 'vectors', type => 'vectors',
desc => 'The vectors' },
{ name => 'parent', type => 'vectors',
desc => 'The parent vectors' },
{ name => 'position', type => 'int32',
desc => 'The vectors position' }
);
$invoke{code} = <<'CODE';
{
if (gimp_pdb_item_is_floating (GIMP_ITEM (vectors), image, error) &&
(parent == NULL ||
(gimp_pdb_item_is_in_tree (GIMP_ITEM (parent), image, FALSE, error) &&
gimp_pdb_item_is_group (GIMP_ITEM (parent), error))))
{
if (position == -1 && parent == NULL)
parent = GIMP_IMAGE_ACTIVE_PARENT;
success = gimp_image_add_vectors (image, vectors,
parent, MAX (position, -1), TRUE);
}
else
{
success = FALSE;
}
}
CODE
}
sub image_remove_vectors {
$blurb = 'Remove the specified path from the image.';
@ -2816,9 +2951,9 @@ CODE
image_floating_sel_attached_to
image_pick_color
image_pick_correlate_layer
image_add_layer image_remove_layer
image_add_channel image_remove_channel
image_add_vectors image_remove_vectors
image_add_layer image_insert_layer image_remove_layer
image_add_channel image_insert_channel image_remove_channel
image_add_vectors image_insert_vectors image_remove_vectors
image_get_item_position
image_raise_item image_lower_item
image_raise_item_to_top image_lower_item_to_bottom
@ -2852,7 +2987,7 @@ CODE
image_get_channel_by_tattoo
image_get_vectors_by_tattoo);
%exports = (app => [@procs], lib => [@procs[0..52,55..83]]);
%exports = (app => [@procs], lib => [@procs[0..55,58..86]]);
$desc = 'Image';
$doc_title = 'gimpimage';