[gimp] app, libgimp, libgimpbase: forgot to support GIMP_TYPE_UNIT on the wire



commit e36028d2aca4c6b50777db097fe2439bc87fb3d2
Author: Michael Natterer <mitch gimp org>
Date:   Tue Jul 30 15:04:06 2019 +0200

    app, libgimp, libgimpbase: forgot to support GIMP_TYPE_UNIT on the wire
    
    This commit can serve as an example how to add new types to
    GimpProtocol, note that zero public API changes.

 app/plug-in/gimpgpparams.c  |  9 +++++++++
 libgimp/gimpgpparams-body.c | 17 +++++++++++++++--
 libgimpbase/gimpprotocol.c  | 27 +++++++++++++++++++++++++++
 libgimpbase/gimpprotocol.h  | 12 +++++++++++-
 4 files changed, 62 insertions(+), 3 deletions(-)
---
diff --git a/app/plug-in/gimpgpparams.c b/app/plug-in/gimpgpparams.c
index b9d90db45f..e8e25e2a8e 100644
--- a/app/plug-in/gimpgpparams.c
+++ b/app/plug-in/gimpgpparams.c
@@ -104,6 +104,15 @@ _gimp_gp_param_def_to_param_spec (Gimp       *gimp,
                                      flags);
       break;
 
+    case GP_PARAM_DEF_TYPE_UNIT:
+      if (! strcmp (param_def->type_name, "GimpParamUnit"))
+        return gimp_param_spec_unit (name, nick, blurb,
+                                     param_def->meta.m_unit.allow_pixels,
+                                     param_def->meta.m_unit.allow_percent,
+                                     param_def->meta.m_unit.default_val,
+                                     flags);
+      break;
+
     case GP_PARAM_DEF_TYPE_ENUM:
       if (! strcmp (param_def->type_name, "GParamEnum"))
         return g_param_spec_enum (name, nick, blurb,
diff --git a/libgimp/gimpgpparams-body.c b/libgimp/gimpgpparams-body.c
index 8fd115d285..63f8e0b93d 100644
--- a/libgimp/gimpgpparams-body.c
+++ b/libgimp/gimpgpparams-body.c
@@ -59,6 +59,17 @@ _gimp_param_spec_to_gp_param_def (GParamSpec *pspec,
       param_def->meta.m_int.max_val     = uspec->maximum;
       param_def->meta.m_int.default_val = uspec->default_value;
     }
+  else if (pspec_type == GIMP_TYPE_PARAM_UNIT)
+    {
+      GParamSpecInt     *ispec = G_PARAM_SPEC_INT (pspec);
+      GimpParamSpecUnit *uspec = GIMP_PARAM_SPEC_UNIT (pspec);
+
+      param_def->param_def_type = GP_PARAM_DEF_TYPE_UNIT;
+
+      param_def->meta.m_unit.allow_pixels  = (ispec->minimum < GIMP_UNIT_INCH);
+      param_def->meta.m_unit.allow_percent = uspec->allow_percent;
+      param_def->meta.m_unit.default_val   = ispec->default_value;
+    }
   else if (pspec_type == G_TYPE_PARAM_ENUM)
     {
       GParamSpecEnum *espec     = G_PARAM_SPEC_ENUM (pspec);
@@ -211,7 +222,8 @@ _gimp_gp_params_to_value_array (GParamSpec **pspecs,
 
       if (type == G_TYPE_INT      ||
           type == GIMP_TYPE_INT32 ||
-          type == GIMP_TYPE_INT16)
+          type == GIMP_TYPE_INT16 ||
+          type == GIMP_TYPE_UNIT)
         {
           g_value_set_int (&value, params[i].data.d_int);
         }
@@ -379,7 +391,8 @@ _gimp_value_array_to_gp_params (GimpValueArray  *args,
 
       if (type == G_TYPE_INT      ||
           type == GIMP_TYPE_INT32 ||
-          type == GIMP_TYPE_INT16)
+          type == GIMP_TYPE_INT16 ||
+          type == GIMP_TYPE_UNIT)
         {
           params[i].param_type = GP_PARAM_TYPE_INT;
 
diff --git a/libgimpbase/gimpprotocol.c b/libgimpbase/gimpprotocol.c
index 9515ed189c..e0979ecf47 100644
--- a/libgimpbase/gimpprotocol.c
+++ b/libgimpbase/gimpprotocol.c
@@ -1076,6 +1076,19 @@ _gp_param_def_read (GIOChannel *channel,
         return FALSE;
       break;
 
+    case GP_PARAM_DEF_TYPE_UNIT:
+      if (! _gimp_wire_read_int32 (channel,
+                                   (guint32 *) &param_def->meta.m_unit.allow_pixels, 1,
+                                   user_data) ||
+          ! _gimp_wire_read_int32 (channel,
+                                   (guint32 *) &param_def->meta.m_unit.allow_percent, 1,
+                                   user_data) ||
+          ! _gimp_wire_read_int32 (channel,
+                                   (guint32 *) &param_def->meta.m_unit.default_val, 1,
+                                   user_data))
+        return FALSE;
+      break;
+
     case GP_PARAM_DEF_TYPE_ENUM:
       if (! _gimp_wire_read_string (channel,
                                     &param_def->meta.m_enum.type_name, 1,
@@ -1155,6 +1168,7 @@ _gp_param_def_destroy (GPParamDef *param_def)
     {
     case GP_PARAM_DEF_TYPE_DEFAULT:
     case GP_PARAM_DEF_TYPE_INT:
+    case GP_PARAM_DEF_TYPE_UNIT:
       break;
 
     case GP_PARAM_DEF_TYPE_ENUM:
@@ -1329,6 +1343,19 @@ _gp_param_def_write (GIOChannel *channel,
         return FALSE;
       break;
 
+    case GP_PARAM_DEF_TYPE_UNIT:
+      if (! _gimp_wire_write_int32 (channel,
+                                    (guint32 *) &param_def->meta.m_unit.allow_pixels, 1,
+                                    user_data) ||
+          ! _gimp_wire_write_int32 (channel,
+                                    (guint32 *) &param_def->meta.m_unit.allow_percent, 1,
+                                    user_data) ||
+          ! _gimp_wire_write_int32 (channel,
+                                    (guint32 *) &param_def->meta.m_unit.default_val, 1,
+                                    user_data))
+        return FALSE;
+      break;
+
     case GP_PARAM_DEF_TYPE_ENUM:
       if (! _gimp_wire_write_string (channel,
                                      &param_def->meta.m_enum.type_name, 1,
diff --git a/libgimpbase/gimpprotocol.h b/libgimpbase/gimpprotocol.h
index c45a5aa5ad..20b7ae5eae 100644
--- a/libgimpbase/gimpprotocol.h
+++ b/libgimpbase/gimpprotocol.h
@@ -26,7 +26,7 @@ G_BEGIN_DECLS
 
 /* Increment every time the protocol changes
  */
-#define GIMP_PROTOCOL_VERSION  0x0105
+#define GIMP_PROTOCOL_VERSION  0x0106
 
 
 enum
@@ -61,6 +61,7 @@ typedef enum
 {
   GP_PARAM_DEF_TYPE_DEFAULT,
   GP_PARAM_DEF_TYPE_INT,
+  GP_PARAM_DEF_TYPE_UNIT,
   GP_PARAM_DEF_TYPE_ENUM,
   GP_PARAM_DEF_TYPE_BOOLEAN,
   GP_PARAM_DEF_TYPE_FLOAT,
@@ -79,6 +80,7 @@ typedef struct _GPParamArray       GPParamArray;
 typedef struct _GPParamStringArray GPParamStringArray;
 typedef struct _GPParamDef         GPParamDef;
 typedef struct _GPParamDefInt      GPParamDefInt;
+typedef struct _GPParamDefUnit     GPParamDefUnit;
 typedef struct _GPParamDefEnum     GPParamDefEnum;
 typedef struct _GPParamDefBoolean  GPParamDefBoolean;
 typedef struct _GPParamDefFloat    GPParamDefFloat;
@@ -172,6 +174,13 @@ struct _GPParamDefInt
   gint32 default_val;
 };
 
+struct _GPParamDefUnit
+{
+  gint32 allow_pixels;
+  gint32 allow_percent;
+  gint32 default_val;
+};
+
 struct _GPParamDefEnum
 {
   gchar  *type_name;
@@ -220,6 +229,7 @@ struct _GPParamDef
   union
   {
     GPParamDefInt     m_int;
+    GPParamDefUnit    m_unit;
     GPParamDefEnum    m_enum;
     GPParamDefBoolean m_boolean;
     GPParamDefFloat   m_float;


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