[gimp] app, pdb, libgimp: new PDB call gimp-image-set-selected-layers.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app, pdb, libgimp: new PDB call gimp-image-set-selected-layers.
- Date: Sun, 21 Feb 2021 23:12:14 +0000 (UTC)
commit c800b262b0db4f0a02840ee2b8107279eb68dbc1
Author: Jehan <jehan girinstud io>
Date: Sun Feb 21 23:17:30 2021 +0100
app, pdb, libgimp: new PDB call gimp-image-set-selected-layers.
app/pdb/image-cmds.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++
app/pdb/internal-procs.c | 2 +-
libgimp/gimp.def | 1 +
libgimp/gimpimage_pdb.c | 47 ++++++++++++++++++++++++++++++++-
libgimp/gimpimage_pdb.h | 3 +++
pdb/groups/image.pdb | 44 ++++++++++++++++++++++++++++--
6 files changed, 162 insertions(+), 4 deletions(-)
---
diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c
index eb3f3f7d19..81a610d1d0 100644
--- a/app/pdb/image-cmds.c
+++ b/app/pdb/image-cmds.c
@@ -1991,6 +1991,40 @@ image_get_selected_layers_invoker (GimpProcedure *procedure,
return return_vals;
}
+static GimpValueArray *
+image_set_selected_layers_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GimpValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GimpImage *image;
+ gint num_layers;
+ const GimpLayer **layers;
+
+ image = g_value_get_object (gimp_value_array_index (args, 0));
+ num_layers = g_value_get_int (gimp_value_array_index (args, 1));
+ layers = (const GimpLayer **) gimp_value_get_object_array (gimp_value_array_index (args, 2));
+
+ if (success)
+ {
+ GList *selected_layers = NULL;
+ gint i;
+
+ for (i = 0; i < num_layers; i++)
+ selected_layers = g_list_prepend (selected_layers,
+ GIMP_LAYER (layers[i]));
+
+ gimp_image_set_selected_layers (image, selected_layers);
+ g_list_free (selected_layers);
+ }
+
+ return gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+}
+
static GimpValueArray *
image_get_selection_invoker (GimpProcedure *procedure,
Gimp *gimp,
@@ -4706,6 +4740,41 @@ register_image_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
+ /*
+ * gimp-image-set-selected-layers
+ */
+ procedure = gimp_procedure_new (image_set_selected_layers_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-image-set-selected-layers");
+ gimp_procedure_set_static_help (procedure,
+ "Sets the specified image's selected layers.",
+ "The layers are set as the selected layers in the image. Any previous
selected layers or channels are unselected. An exception is a previously existing floating selection, in
which case this procedure will return an execution error.",
+ NULL);
+ gimp_procedure_set_static_attribution (procedure,
+ "Jehan",
+ "Jehan",
+ "2021");
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_image ("image",
+ "image",
+ "The image",
+ FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_argument (procedure,
+ g_param_spec_int ("num-layers",
+ "num layers",
+ "The number of layers to select",
+ 0, G_MAXINT32, 0,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_object_array ("layers",
+ "layers",
+ "The list of layers to select",
+ GIMP_TYPE_LAYER,
+ GIMP_PARAM_READWRITE | GIMP_PARAM_NO_VALIDATE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
+
/*
* gimp-image-get-selection
*/
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index e869958ce5..075987c886 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
#include "internal-procs.h"
-/* 755 procedures registered total */
+/* 756 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index 65a2765079..11bc920960 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -485,6 +485,7 @@ EXPORTS
gimp_image_set_file
gimp_image_set_metadata
gimp_image_set_resolution
+ gimp_image_set_selected_layers
gimp_image_set_tattoo_state
gimp_image_set_unit
gimp_image_thaw_channels
diff --git a/libgimp/gimpimage_pdb.c b/libgimp/gimpimage_pdb.c
index 24480f8727..7999385334 100644
--- a/libgimp/gimpimage_pdb.c
+++ b/libgimp/gimpimage_pdb.c
@@ -2311,7 +2311,7 @@ gimp_image_set_active_vectors (GimpImage *image,
* The list of selected layers in the image.
* The returned value must be freed with g_free().
*
- * Since: 2.10.20
+ * Since: 3.0.0
**/
GimpLayer **
gimp_image_get_selected_layers (GimpImage *image,
@@ -2343,6 +2343,51 @@ gimp_image_get_selected_layers (GimpImage *image,
return layers;
}
+/**
+ * gimp_image_set_selected_layers:
+ * @image: The image.
+ * @num_layers: The number of layers to select.
+ * @layers: (array length=num_layers) (element-type GimpLayer): The list of layers to select.
+ *
+ * Sets the specified image's selected layers.
+ *
+ * The layers are set as the selected layers in the image. Any previous
+ * selected layers or channels are unselected. An exception is a
+ * previously existing floating selection, in which case this procedure
+ * will return an execution error.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: 3.0.0
+ **/
+gboolean
+gimp_image_set_selected_layers (GimpImage *image,
+ gint num_layers,
+ const GimpLayer **layers)
+{
+ GimpValueArray *args;
+ GimpValueArray *return_vals;
+ gboolean success = TRUE;
+
+ args = gimp_value_array_new_from_types (NULL,
+ GIMP_TYPE_IMAGE, image,
+ G_TYPE_INT, num_layers,
+ GIMP_TYPE_OBJECT_ARRAY, NULL,
+ G_TYPE_NONE);
+ gimp_value_set_object_array (gimp_value_array_index (args, 2), GIMP_TYPE_LAYER, (GObject **) layers,
num_layers);
+
+ return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
+ "gimp-image-set-selected-layers",
+ args);
+ gimp_value_array_unref (args);
+
+ success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
+
+ gimp_value_array_unref (return_vals);
+
+ return success;
+}
+
/**
* gimp_image_get_selection:
* @image: The image.
diff --git a/libgimp/gimpimage_pdb.h b/libgimp/gimpimage_pdb.h
index 4fcf0aa40c..ddeae7578c 100644
--- a/libgimp/gimpimage_pdb.h
+++ b/libgimp/gimpimage_pdb.h
@@ -145,6 +145,9 @@ gboolean gimp_image_set_active_vectors (GimpImage
GimpVectors *active_vectors);
GimpLayer** gimp_image_get_selected_layers (GimpImage *image,
gint *num_layers);
+gboolean gimp_image_set_selected_layers (GimpImage *image,
+ gint num_layers,
+ const GimpLayer **layers);
GimpSelection* gimp_image_get_selection (GimpImage *image);
gboolean gimp_image_get_component_active (GimpImage *image,
GimpChannelType component);
diff --git a/pdb/groups/image.pdb b/pdb/groups/image.pdb
index e1005af05e..24ef1d72d7 100644
--- a/pdb/groups/image.pdb
+++ b/pdb/groups/image.pdb
@@ -1824,7 +1824,7 @@ sub image_get_selected_layers {
This procedure returns the list of selected layers in the specified image.
HELP
- &jehan_pdb_misc('2020', '2.10.20');
+ &jehan_pdb_misc('2020', '3.0.0');
@inargs = (
{ name => 'image', type => 'image',
@@ -1889,6 +1889,46 @@ CODE
);
}
+sub image_set_selected_layers {
+ $blurb = "Sets the specified image's selected layers.";
+
+ $help = <<'HELP';
+The layers are set as the selected layers in the image. Any previous
+selected layers or channels are unselected. An exception is a previously
+existing floating selection, in which case this procedure will return an
+execution error.
+HELP
+
+ &jehan_pdb_misc('2021', '3.0.0');
+
+ @inargs = (
+ { name => 'image', type => 'image',
+ desc => 'The image' },
+ { name => 'layers', type => 'layerarray',
+ desc => 'The list of layers to select',
+ no_validate => 1,
+ array => { name => 'num_layers',
+ type => '0 <= int32',
+ desc => 'The number of layers to select' } }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ GList *selected_layers = NULL;
+ gint i;
+
+ for (i = 0; i < num_layers; i++)
+ selected_layers = g_list_prepend (selected_layers,
+ GIMP_LAYER (layers[i]));
+
+ gimp_image_set_selected_layers (image, selected_layers);
+ g_list_free (selected_layers);
+}
+CODE
+ );
+}
+
sub image_set_active_layer {
$blurb = "Sets the specified image's active layer.";
@@ -3116,7 +3156,7 @@ CODE
image_get_active_layer image_set_active_layer
image_get_active_channel image_set_active_channel
image_get_active_vectors image_set_active_vectors
- image_get_selected_layers
+ image_get_selected_layers image_set_selected_layers
image_get_selection
image_get_component_active image_set_component_active
image_get_component_visible image_set_component_visible
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]