From 353c73457aabadce6a0ed330084db50ea2476517 Mon Sep 17 00:00:00 2001 From: Jehan Date: Fri, 2 Apr 2021 01:04:07 +0200 Subject: [PATCH] =?UTF-8?q?app,=20libgimp,=20libgimpconfig,=20extensions:?= =?UTF-8?q?=20image=20procedures=20now=20with=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … drawable array instead of a single drawable. Instead of expecting a single drawable, GimpImageProcedure's run() function will now have an array of drawable as parameter. As a consequence, all existing plug-ins are broken again. I am going to fix them in the next commit so that this change can be easily reviewed and examined if needed later. I only fix the Vala demo plug-in now (or rather, I just use the first layer in the array for now) because otherwise the build fails. --- app/actions/procedure-commands.c | 43 +++++++++++++++++-- .../goat-exercises/goat-exercise-vala.vala | 4 +- libgimp/gimpimageprocedure.c | 28 +++++++----- libgimp/gimpimageprocedure.h | 24 ++++++----- libgimpconfig/gimpconfig-register.c | 5 ++- 5 files changed, 76 insertions(+), 28 deletions(-) diff --git a/app/actions/procedure-commands.c b/app/actions/procedure-commands.c index c96c5b918a..5a0a745730 100644 --- a/app/actions/procedure-commands.c +++ b/app/actions/procedure-commands.c @@ -26,6 +26,7 @@ #include "core/gimp.h" #include "core/gimpimage.h" +#include "core/gimpdrawable.h" #include "core/gimpparamspecs.h" #include "core/gimpprogress.h" @@ -243,27 +244,61 @@ procedure_commands_get_display_args (GimpProcedure *procedure, if (image) { + GList *drawables_list = gimp_image_get_selected_drawables (image); + g_value_set_object (gimp_value_array_index (args, n_args), image); n_args++; if (gimp_value_array_length (args) > n_args && GIMP_IS_PARAM_SPEC_DRAWABLE (procedure->args[n_args])) { - GimpDrawable *drawable = gimp_image_get_active_drawable (image); - - if (drawable) + if (drawables_list) { + g_warning ("%s: plug-in procedures expecting a single drawable are deprecated!", + G_STRFUNC); g_value_set_object (gimp_value_array_index (args, n_args), - drawable); + drawables_list->data); n_args++; } else { g_warning ("Uh-oh, no active drawable for the plug-in!"); + gimp_value_array_unref (args); + g_list_free (drawables_list); + return NULL; } } + else if (gimp_value_array_length (args) > n_args + 1 && + G_IS_PARAM_SPEC_INT (procedure->args[n_args]) && + GIMP_IS_PARAM_SPEC_OBJECT_ARRAY (procedure->args[n_args + 1])) + { + GimpDrawable **drawables = NULL; + gint n_drawables; + + n_drawables = g_list_length (drawables_list); + + g_value_set_int (gimp_value_array_index (args, n_args++), + n_drawables); + + if (drawables_list) + { + GList *iter; + gint i; + + drawables = g_new (GimpDrawable *, n_drawables); + for (iter = drawables_list, i = 0; iter; iter = iter->next, i++) + drawables[i] = iter->data; + } + + gimp_value_set_object_array (gimp_value_array_index (args, n_args++), + GIMP_TYPE_DRAWABLE, + (GObject **) drawables, n_drawables); + + g_free (drawables); + } + g_list_free (drawables_list); } } diff --git a/extensions/goat-exercises/goat-exercise-vala.vala b/extensions/goat-exercises/goat-exercise-vala.vala index 51353b6b38..68ac500411 100755 --- a/extensions/goat-exercises/goat-exercise-vala.vala +++ b/extensions/goat-exercises/goat-exercise-vala.vala @@ -55,8 +55,10 @@ public class Goat : Gimp.PlugIn { public Gimp.ValueArray run(Gimp.Procedure procedure, Gimp.RunMode run_mode, Gimp.Image image, - Gimp.Drawable drawable, + Gimp.Drawable[] drawables, Gimp.ValueArray args) { + var drawable = drawables[0]; + if (run_mode == Gimp.RunMode.INTERACTIVE) { GimpUi.init(PLUG_IN_BINARY); diff --git a/libgimp/gimpimageprocedure.c b/libgimp/gimpimageprocedure.c index 36111f48b1..4709c57886 100644 --- a/libgimp/gimpimageprocedure.c +++ b/libgimp/gimpimageprocedure.c @@ -90,11 +90,17 @@ gimp_image_procedure_constructed (GObject *object) FALSE, G_PARAM_READWRITE); - GIMP_PROC_ARG_DRAWABLE (procedure, "drawable", - "Drawable", - "The input drawable", - TRUE, - G_PARAM_READWRITE); + GIMP_PROC_ARG_INT (procedure, "num-drawables", + "Number of drawables", + "Number of input drawables", + 0, G_MAXINT, 1, + G_PARAM_READWRITE); + + GIMP_PROC_ARG_OBJECT_ARRAY (procedure, "drawables", + "Drawables", + "The input drawables", + GIMP_TYPE_DRAWABLE, + G_PARAM_READWRITE | GIMP_PARAM_NO_VALIDATE); } static void @@ -119,12 +125,14 @@ gimp_image_procedure_run (GimpProcedure *procedure, GimpValueArray *return_values; GimpRunMode run_mode; GimpImage *image; - GimpDrawable *drawable; + GimpDrawable **drawables; + gint n_drawables; gint i; - run_mode = GIMP_VALUES_GET_ENUM (args, 0); - image = GIMP_VALUES_GET_IMAGE (args, 1); - drawable = GIMP_VALUES_GET_DRAWABLE (args, 2); + run_mode = GIMP_VALUES_GET_ENUM (args, 0); + image = GIMP_VALUES_GET_IMAGE (args, 1); + n_drawables = GIMP_VALUES_GET_INT (args, 2); + drawables = GIMP_VALUES_GET_OBJECT_ARRAY (args, 3); remaining = gimp_value_array_new (gimp_value_array_length (args) - ARG_OFFSET); @@ -137,7 +145,7 @@ gimp_image_procedure_run (GimpProcedure *procedure, return_values = image_proc->priv->run_func (procedure, run_mode, - image, drawable, + image, n_drawables, drawables, remaining, image_proc->priv->run_data); diff --git a/libgimp/gimpimageprocedure.h b/libgimp/gimpimageprocedure.h index f57f26dcb7..99597fd3fd 100644 --- a/libgimp/gimpimageprocedure.h +++ b/libgimp/gimpimageprocedure.h @@ -31,11 +31,12 @@ G_BEGIN_DECLS /** * GimpRunImageFunc: - * @procedure: the #GimpProcedure that runs. - * @run_mode: the #GimpRunMode. - * @image: the #GimpImage. - * @drawable: the #GimpDrawable. - * @args: the @procedure's remaining arguments. + * @procedure: the #GimpProcedure that runs. + * @run_mode: the #GimpRunMode. + * @image: the #GimpImage. + * @n_drawables: the number of #GimpDrawable-s. + * @drawables: (array length=n_drawables): the input #GimpDrawable-s. + * @args: the @procedure's remaining arguments. * @run_data: (closure): the run_data given in gimp_image_procedure_new(). * * The image function is run during the lifetime of the GIMP session, @@ -45,12 +46,13 @@ G_BEGIN_DECLS * * Since: 3.0 **/ -typedef GimpValueArray * (* GimpRunImageFunc) (GimpProcedure *procedure, - GimpRunMode run_mode, - GimpImage *image, - GimpDrawable *drawable, - const GimpValueArray *args, - gpointer run_data); +typedef GimpValueArray * (* GimpRunImageFunc) (GimpProcedure *procedure, + GimpRunMode run_mode, + GimpImage *image, + gint n_drawables, + GimpDrawable **drawables, + const GimpValueArray *args, + gpointer run_data); #define GIMP_TYPE_IMAGE_PROCEDURE (gimp_image_procedure_get_type ()) diff --git a/libgimpconfig/gimpconfig-register.c b/libgimpconfig/gimpconfig-register.c index f783a60149..214e91da2e 100644 --- a/libgimpconfig/gimpconfig-register.c +++ b/libgimpconfig/gimpconfig-register.c @@ -141,8 +141,9 @@ gimp_config_class_init (GObjectClass *klass, { g_object_class_install_property (klass, i + 1, copy); } - else if (! G_IS_PARAM_SPEC_OBJECT (pspec) && - ! G_IS_PARAM_SPEC_POINTER (pspec)) + else if (! G_IS_PARAM_SPEC_OBJECT (pspec) && + ! G_IS_PARAM_SPEC_POINTER (pspec) && + ! GIMP_IS_PARAM_SPEC_OBJECT_ARRAY (pspec)) { /* silently ignore object properties */