[gimp] libgimp, libgimpconfig: recognize RGB boxed args containing GimpRGB.



commit 5d210667c5a4d9af64f414da5d358a353e6f70c3
Author: Jehan <jehan girinstud io>
Date:   Tue Apr 20 14:10:37 2021 +0200

    libgimp, libgimpconfig: recognize RGB boxed args containing GimpRGB.
    
    Still the same problem as ever with the Python binding where we have a
    hard time creating GParamSpec, hence we make them from object
    properties.
    See: https://gitlab.gnome.org/GNOME/pygobject/-/issues/227#note_570031
    
    But then again, the Python binding way to create GObject properties does
    not seem to give us a way to use our custom param types (or I didn't
    find how). So when I create a property with Gimp.RGB type in Python, it
    doesn't appear as a GIMP_PARAM_SPEC_RGB to our C code, but as a
    G_PARAM_SPEC_BOXED. So my trick is to check the value type instead.
    Note that I check the default value, but in reality it doesn't seem to
    work much either. Better than no support at all anyway.

 libgimp/gimpgpparams-body.c       |  5 +++++
 libgimpconfig/gimpconfig-params.c | 18 ++++++++++++++++++
 2 files changed, 23 insertions(+)
---
diff --git a/libgimp/gimpgpparams-body.c b/libgimp/gimpgpparams-body.c
index f79d274dfe..9c1a063ae4 100644
--- a/libgimp/gimpgpparams-body.c
+++ b/libgimp/gimpgpparams-body.c
@@ -64,6 +64,11 @@ _gimp_gp_param_def_to_param_spec (const GPParamDef *param_def)
       if (! strcmp (param_def->type_name, "GParamObject") &&
           ! strcmp (param_def->value_type_name, "GFile"))
         return g_param_spec_object (name, nick, blurb, G_TYPE_FILE, flags);
+
+      if (! strcmp (param_def->type_name, "GParamBoxed") &&
+          ! strcmp (param_def->value_type_name, "GimpRGB"))
+        /* Unfortunately this type loses default and alpha info. */
+        return gimp_param_spec_rgb (name, nick, blurb, TRUE, NULL, flags);
       break;
 
     case GP_PARAM_DEF_TYPE_INT:
diff --git a/libgimpconfig/gimpconfig-params.c b/libgimpconfig/gimpconfig-params.c
index 861be8ccf5..7f87ea0285 100644
--- a/libgimpconfig/gimpconfig-params.c
+++ b/libgimpconfig/gimpconfig-params.c
@@ -251,6 +251,24 @@ gimp_config_param_spec_duplicate (GParamSpec *pspec)
                                   &color,
                                   flags);
     }
+  /* In some cases, such as some GIR bindings, creating a GimpRGB
+   * argument is impossible (or at least I have not found how, at least
+   * in the Python binding which is doing some weird shortcuts when
+   * handling GValue and param specs. So instead, the parameter appears
+   * as a Boxed param with a GimpRGB value type.
+   */
+  else if (G_IS_PARAM_SPEC_BOXED (pspec) &&
+           G_PARAM_SPEC_VALUE_TYPE (pspec) == GIMP_TYPE_RGB)
+    {
+      GValue  *value;
+      GimpRGB  color;
+
+      value = (GValue *) g_param_spec_get_default_value (pspec);
+      gimp_value_get_rgb (value, &color);
+
+      copy = gimp_param_spec_rgb (name, nick, blurb,
+                                  TRUE, &color, flags);
+    }
   else if (GEGL_IS_PARAM_SPEC_COLOR (pspec))
     {
       GeglColor *gegl_color;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]