[gimp] libgimp, pdb, app: new gimp_image_get_selected_drawables() function.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimp, pdb, app: new gimp_image_get_selected_drawables() function.
- Date: Tue, 19 Jul 2022 20:52:14 +0000 (UTC)
commit bd199fa0c27f923ace476b0643bdd0b1d775ab3d
Author: Jehan <jehan girinstud io>
Date: Tue Jul 19 22:38:28 2022 +0200
libgimp, pdb, app: new gimp_image_get_selected_drawables() function.
app/pdb/image-cmds.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++
app/pdb/internal-procs.c | 2 +-
libgimp/gimp.def | 1 +
libgimp/gimpimage_pdb.c | 51 ++++++++++++++++++++++++++++++
libgimp/gimpimage_pdb.h | 2 ++
pdb/groups/image.pdb | 49 +++++++++++++++++++++++++++++
6 files changed, 185 insertions(+), 1 deletion(-)
---
diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c
index 6a34e6d9a4..6279fb21d9 100644
--- a/app/pdb/image-cmds.c
+++ b/app/pdb/image-cmds.c
@@ -2027,6 +2027,51 @@ image_set_selected_layers_invoker (GimpProcedure *procedure,
error ? *error : NULL);
}
+static GimpValueArray *
+image_get_selected_drawables_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GimpValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GimpValueArray *return_vals;
+ GimpImage *image;
+ gint num_drawables = 0;
+ GimpItem **drawables = NULL;
+
+ image = g_value_get_object (gimp_value_array_index (args, 0));
+
+ if (success)
+ {
+ GList *list = gimp_image_get_selected_drawables (image);
+
+ num_drawables = g_list_length (list);
+
+ if (num_drawables)
+ {
+ gint i;
+
+ drawables = g_new (GimpItem *, num_drawables);
+
+ for (i = 0; i < num_drawables; i++, list = g_list_next (list))
+ drawables[i] = g_object_ref (list->data);
+ }
+ }
+
+ return_vals = gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+
+ if (success)
+ {
+ g_value_set_int (gimp_value_array_index (return_vals, 1), num_drawables);
+ gimp_value_take_object_array (gimp_value_array_index (return_vals, 2), GIMP_TYPE_ITEM, (GObject **)
drawables, num_drawables);
+ }
+
+ return return_vals;
+}
+
static GimpValueArray *
image_get_selection_invoker (GimpProcedure *procedure,
Gimp *gimp,
@@ -4774,6 +4819,42 @@ register_image_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
+ /*
+ * gimp-image-get-selected-drawables
+ */
+ procedure = gimp_procedure_new (image_get_selected_drawables_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-image-get-selected-drawables");
+ gimp_procedure_set_static_help (procedure,
+ "Get the image's selected drawables",
+ "This procedure returns the list of selected drawable in the specified
image. This can be either layers, channels, or a layer mask.\n"
+ "The active drawables are the active image channels. If there are none,
these are the active image layers. If the active image layer has a layer mask and the layer mask is in edit
mode, then the layer mask is the active drawable.",
+ NULL);
+ gimp_procedure_set_static_attribution (procedure,
+ "Jehan",
+ "Jehan",
+ "2022");
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_image ("image",
+ "image",
+ "The image",
+ FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_return_value (procedure,
+ g_param_spec_int ("num-drawables",
+ "num drawables",
+ "The number of selected drawables in the image",
+ 0, G_MAXINT32, 0,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_return_value (procedure,
+ gimp_param_spec_object_array ("drawables",
+ "drawables",
+ "The list of selected drawables in the
image.",
+ GIMP_TYPE_ITEM,
+ GIMP_PARAM_READWRITE));
+ 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 67aeef98ff..1fa6c26fde 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -30,7 +30,7 @@
#include "internal-procs.h"
-/* 764 procedures registered total */
+/* 765 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index 0cde15376d..d4157e7619 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -418,6 +418,7 @@ EXPORTS
gimp_image_get_precision
gimp_image_get_resolution
gimp_image_get_sample_point_position
+ gimp_image_get_selected_drawables
gimp_image_get_selected_layers
gimp_image_get_selection
gimp_image_get_simulation_profile
diff --git a/libgimp/gimpimage_pdb.c b/libgimp/gimpimage_pdb.c
index 5d3d5ffddd..2ba5995bf7 100644
--- a/libgimp/gimpimage_pdb.c
+++ b/libgimp/gimpimage_pdb.c
@@ -2396,6 +2396,57 @@ gimp_image_set_selected_layers (GimpImage *image,
return success;
}
+/**
+ * gimp_image_get_selected_drawables:
+ * @image: The image.
+ * @num_drawables: (out): The number of selected drawables in the image.
+ *
+ * Get the image's selected drawables
+ *
+ * This procedure returns the list of selected drawable in the
+ * specified image. This can be either layers, channels, or a layer
+ * mask.
+ * The active drawables are the active image channels. If there are
+ * none, these are the active image layers. If the active image layer
+ * has a layer mask and the layer mask is in edit mode, then the layer
+ * mask is the active drawable.
+ *
+ * Returns: (array length=num_drawables) (element-type GimpItem) (transfer container):
+ * The list of selected drawables in the image.
+ * The returned value must be freed with g_free().
+ *
+ * Since: 3.0.0
+ **/
+GimpItem **
+gimp_image_get_selected_drawables (GimpImage *image,
+ gint *num_drawables)
+{
+ GimpValueArray *args;
+ GimpValueArray *return_vals;
+ GimpItem **drawables = NULL;
+
+ args = gimp_value_array_new_from_types (NULL,
+ GIMP_TYPE_IMAGE, image,
+ G_TYPE_NONE);
+
+ return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
+ "gimp-image-get-selected-drawables",
+ args);
+ gimp_value_array_unref (args);
+
+ *num_drawables = 0;
+
+ if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
+ {
+ *num_drawables = GIMP_VALUES_GET_INT (return_vals, 1);
+ { GimpObjectArray *a = g_value_get_boxed (gimp_value_array_index (return_vals, 2)); if (a) drawables =
g_memdup2 (a->data, a->length * sizeof (gpointer)); };
+ }
+
+ gimp_value_array_unref (return_vals);
+
+ return drawables;
+}
+
/**
* gimp_image_get_selection:
* @image: The image.
diff --git a/libgimp/gimpimage_pdb.h b/libgimp/gimpimage_pdb.h
index 90d74f6b08..14a0579073 100644
--- a/libgimp/gimpimage_pdb.h
+++ b/libgimp/gimpimage_pdb.h
@@ -148,6 +148,8 @@ GimpLayer** gimp_image_get_selected_layers (GimpImage
gboolean gimp_image_set_selected_layers (GimpImage *image,
gint num_layers,
const GimpLayer **layers);
+GimpItem** gimp_image_get_selected_drawables (GimpImage *image,
+ gint *num_drawables);
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 328cd2b24c..dc8cbd95d0 100644
--- a/pdb/groups/image.pdb
+++ b/pdb/groups/image.pdb
@@ -2086,6 +2086,54 @@ CODE
);
}
+sub image_get_selected_drawables {
+ $blurb = "Get the image's selected drawables";
+
+ $help = <<'HELP';
+This procedure returns the list of selected drawable in the specified image.
+This can be either layers, channels, or a layer mask.
+
+The active drawables are the active image channels. If there are none,
+these are the active image layers. If the active image layer has a layer
+mask and the layer mask is in edit mode, then the layer mask is the
+active drawable.
+HELP
+
+ &jehan_pdb_misc('2022', '3.0.0');
+
+ @inargs = (
+ { name => 'image', type => 'image',
+ desc => 'The image' }
+ );
+
+ @outargs = (
+ { name => 'drawables', type => 'itemarray',
+ desc => 'The list of selected drawables in the image.',
+ array => { name => 'num_drawables',
+ desc => 'The number of selected drawables in the image' } }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ GList *list = gimp_image_get_selected_drawables (image);
+
+ num_drawables = g_list_length (list);
+
+ if (num_drawables)
+ {
+ gint i;
+
+ drawables = g_new (GimpItem *, num_drawables);
+
+ for (i = 0; i < num_drawables; i++, list = g_list_next (list))
+ drawables[i] = g_object_ref (list->data);
+ }
+}
+CODE
+ );
+}
+
sub image_get_selection {
$blurb = "Returns the specified image's selection.";
@@ -3173,6 +3221,7 @@ CODE
image_get_active_channel image_set_active_channel
image_get_active_vectors image_set_active_vectors
image_get_selected_layers image_set_selected_layers
+ image_get_selected_drawables
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]