[gimp] pdb: add new procedure gimp-item-to-selection



commit e7475c1d52e1275dc7e34f0af7eba8490d49f24b
Author: Michael Natterer <mitch gimp org>
Date:   Sun Sep 5 22:38:07 2010 +0200

    pdb: add new procedure gimp-item-to-selection
    
    and deprecate all old to-selection APIs. The new procedure uses the
    newly added GimpPDBContext properties, so it only has an "operation"
    parameter.

 app/pdb/internal-procs.c       |    2 +-
 app/pdb/item-cmds.c            |   66 ++++++++++++++++++++++++++++++++++++++++
 app/pdb/selection-cmds.c       |   36 +++++++++++-----------
 app/pdb/vectors-cmds.c         |    6 ++--
 libgimp/gimp.def               |    1 +
 libgimp/gimpitem_pdb.c         |   37 ++++++++++++++++++++++
 libgimp/gimpitem_pdb.h         |   58 ++++++++++++++++++-----------------
 libgimp/gimpselection_pdb.c    |   21 ++++---------
 libgimp/gimpselection_pdb.h    |    4 ++
 libgimp/gimpvectors_pdb.c      |    5 +--
 libgimp/gimpvectors_pdb.h      |    2 +
 tools/pdbgen/pdb/item.pdb      |   44 ++++++++++++++++++++++++++-
 tools/pdbgen/pdb/selection.pdb |   32 ++-----------------
 tools/pdbgen/pdb/vectors.pdb   |    8 +----
 14 files changed, 216 insertions(+), 106 deletions(-)
---
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index 593cfac..a597c96 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
 #include "internal-procs.h"
 
 
-/* 630 procedures registered total */
+/* 631 procedures registered total */
 
 void
 internal_procs_init (GimpPDB *pdb)
diff --git a/app/pdb/item-cmds.c b/app/pdb/item-cmds.c
index 81999d9..1644a29 100644
--- a/app/pdb/item-cmds.c
+++ b/app/pdb/item-cmds.c
@@ -34,6 +34,7 @@
 
 #include "gimppdb.h"
 #include "gimppdb-utils.h"
+#include "gimppdbcontext.h"
 #include "gimpprocedure.h"
 #include "internal-procs.h"
 
@@ -676,6 +677,41 @@ item_set_tattoo_invoker (GimpProcedure      *procedure,
                                            error ? *error : NULL);
 }
 
+static GValueArray *
+item_to_selection_invoker (GimpProcedure      *procedure,
+                           Gimp               *gimp,
+                           GimpContext        *context,
+                           GimpProgress       *progress,
+                           const GValueArray  *args,
+                           GError            **error)
+{
+  gboolean success = TRUE;
+  GimpItem *item;
+  gint32 operation;
+
+  item = gimp_value_get_item (&args->values[0], gimp);
+  operation = g_value_get_enum (&args->values[1]);
+
+  if (success)
+    {
+      if (gimp_pdb_item_is_attached (item, NULL, FALSE, error))
+        {
+          GimpPDBContext *pdb_context = GIMP_PDB_CONTEXT (context);
+
+          gimp_item_to_selection (item, operation,
+                                  pdb_context->antialias,
+                                  pdb_context->feather,
+                                  pdb_context->feather_radius_x,
+                                  pdb_context->feather_radius_y);
+        }
+      else
+        success = FALSE;
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
 void
 register_item_procs (GimpPDB *pdb)
 {
@@ -1319,4 +1355,34 @@ register_item_procs (GimpPDB *pdb)
                                                   GIMP_PARAM_READWRITE));
   gimp_pdb_register_procedure (pdb, procedure);
   g_object_unref (procedure);
+
+  /*
+   * gimp-item-to-selection
+   */
+  procedure = gimp_procedure_new (item_to_selection_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-item-to-selection");
+  gimp_procedure_set_static_strings (procedure,
+                                     "gimp-item-to-selection",
+                                     "Transforms the specified item into a selection",
+                                     "This procedure renders the item's outline into the current selection of the image the item belongs to. What exactly the item's outline is depends on the item type: for layers, it's the layer's alpha channel, for vectors the vector's shape.",
+                                     "Michael Natterer <mitch gimp org>",
+                                     "Michael Natterer",
+                                     "2010",
+                                     NULL);
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_item_id ("item",
+                                                        "item",
+                                                        "The item to render to the selection",
+                                                        pdb->gimp, FALSE,
+                                                        GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_enum ("operation",
+                                                  "operation",
+                                                  "The desired operation with current selection",
+                                                  GIMP_TYPE_CHANNEL_OPS,
+                                                  GIMP_CHANNEL_OP_ADD,
+                                                  GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
 }
diff --git a/app/pdb/selection-cmds.c b/app/pdb/selection-cmds.c
index a78aad2..34cc84a 100644
--- a/app/pdb/selection-cmds.c
+++ b/app/pdb/selection-cmds.c
@@ -937,12 +937,12 @@ register_selection_procs (GimpPDB *pdb)
                                "gimp-selection-layer-alpha");
   gimp_procedure_set_static_strings (procedure,
                                      "gimp-selection-layer-alpha",
-                                     "Transfer the specified layer's alpha channel to the selection mask.",
-                                     "The alpha channel information is used to create a selection mask such that for any pixel in the image defined in the specified layer, that layer pixel's alpha value is transferred to the selection mask. If the layer is undefined at a particular image pixel, the associated selection mask value is set to 0. A layer without an alpha channel is considered opaque.",
-                                     "Spencer Kimball & Peter Mattis",
-                                     "Spencer Kimball & Peter Mattis",
-                                     "1995-1996",
-                                     NULL);
+                                     "Deprecated: Use 'gimp-item-to-selection' instead.",
+                                     "Deprecated: Use 'gimp-item-to-selection' instead.",
+                                     "",
+                                     "",
+                                     "",
+                                     "gimp-item-to-selection");
   gimp_procedure_add_argument (procedure,
                                gimp_param_spec_layer_id ("layer",
                                                          "layer",
@@ -960,12 +960,12 @@ register_selection_procs (GimpPDB *pdb)
                                "gimp-selection-load");
   gimp_procedure_set_static_strings (procedure,
                                      "gimp-selection-load",
-                                     "Transfer the specified channel to the selection mask.",
-                                     "This procedure loads the specified channel into the selection mask.",
-                                     "Spencer Kimball & Peter Mattis",
-                                     "Spencer Kimball & Peter Mattis",
-                                     "1995-1996",
-                                     NULL);
+                                     "Deprecated: Use 'gimp-item-to-selection' instead.",
+                                     "Deprecated: Use 'gimp-item-to-selection' instead.",
+                                     "",
+                                     "",
+                                     "",
+                                     "gimp-item-to-selection");
   gimp_procedure_add_argument (procedure,
                                gimp_param_spec_channel_id ("channel",
                                                            "channel",
@@ -1012,12 +1012,12 @@ register_selection_procs (GimpPDB *pdb)
                                "gimp-selection-combine");
   gimp_procedure_set_static_strings (procedure,
                                      "gimp-selection-combine",
-                                     "Combines the specified channel with the selection mask.",
-                                     "This procedure combines the specified channel into the selection mask.",
-                                     "Spencer Kimball & Peter Mattis",
-                                     "Spencer Kimball & Peter Mattis",
-                                     "1995-1996",
-                                     NULL);
+                                     "Deprecated: Use 'gimp-item-to-selection' instead.",
+                                     "Deprecated: Use 'gimp-item-to-selection' instead.",
+                                     "",
+                                     "",
+                                     "",
+                                     "gimp-item-to-selection");
   gimp_procedure_add_argument (procedure,
                                gimp_param_spec_channel_id ("channel",
                                                            "channel",
diff --git a/app/pdb/vectors-cmds.c b/app/pdb/vectors-cmds.c
index f788b21..f63c912 100644
--- a/app/pdb/vectors-cmds.c
+++ b/app/pdb/vectors-cmds.c
@@ -2787,12 +2787,12 @@ register_vectors_procs (GimpPDB *pdb)
                                "gimp-vectors-to-selection");
   gimp_procedure_set_static_strings (procedure,
                                      "gimp-vectors-to-selection",
-                                     "Transforms the specified vectors object into a selection",
-                                     "This procedure renders the desired vectors object into the current selection of the image the vectors object belongs to.",
+                                     "Deprecated: Use 'gimp-item-to-selection' instead.",
+                                     "Deprecated: Use 'gimp-item-to-selection' instead.",
                                      "Simon Budig",
                                      "Simon Budig",
                                      "2006",
-                                     NULL);
+                                     "gimp-item-to-selection");
   gimp_procedure_add_argument (procedure,
                                gimp_param_spec_vectors_id ("vectors",
                                                            "vectors",
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index b658939..60c5174 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -440,6 +440,7 @@ EXPORTS
 	gimp_item_set_name
 	gimp_item_set_tattoo
 	gimp_item_set_visible
+	gimp_item_to_selection
 	gimp_layer_add_alpha
 	gimp_layer_add_mask
 	gimp_layer_copy
diff --git a/libgimp/gimpitem_pdb.c b/libgimp/gimpitem_pdb.c
index 228a9b8..20b2b39 100644
--- a/libgimp/gimpitem_pdb.c
+++ b/libgimp/gimpitem_pdb.c
@@ -769,3 +769,40 @@ gimp_item_set_tattoo (gint32 item_ID,
 
   return success;
 }
+
+/**
+ * gimp_item_to_selection:
+ * @item_ID: The item to render to the selection.
+ * @operation: The desired operation with current selection.
+ *
+ * Transforms the specified item into a selection
+ *
+ * This procedure renders the item's outline into the current selection
+ * of the image the item belongs to. What exactly the item's outline is
+ * depends on the item type: for layers, it's the layer's alpha
+ * channel, for vectors the vector's shape.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: GIMP 2.8
+ */
+gboolean
+gimp_item_to_selection (gint32         item_ID,
+                        GimpChannelOps operation)
+{
+  GimpParam *return_vals;
+  gint nreturn_vals;
+  gboolean success = TRUE;
+
+  return_vals = gimp_run_procedure ("gimp-item-to-selection",
+                                    &nreturn_vals,
+                                    GIMP_PDB_ITEM, item_ID,
+                                    GIMP_PDB_INT32, operation,
+                                    GIMP_PDB_END);
+
+  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
+
+  gimp_destroy_params (return_vals, nreturn_vals);
+
+  return success;
+}
diff --git a/libgimp/gimpitem_pdb.h b/libgimp/gimpitem_pdb.h
index 8396306..1f5d3c1 100644
--- a/libgimp/gimpitem_pdb.h
+++ b/libgimp/gimpitem_pdb.h
@@ -28,34 +28,36 @@ G_BEGIN_DECLS
 /* For information look into the C source or the html documentation */
 
 
-gboolean gimp_item_is_valid         (gint32       item_ID);
-gint32   gimp_item_get_image        (gint32       item_ID);
-gboolean gimp_item_delete           (gint32       item_ID);
-gboolean gimp_item_is_drawable      (gint32       item_ID);
-gboolean gimp_item_is_layer         (gint32       item_ID);
-gboolean gimp_item_is_channel       (gint32       item_ID);
-gboolean gimp_item_is_layer_mask    (gint32       item_ID);
-gboolean gimp_item_is_selection     (gint32       item_ID);
-gboolean gimp_item_is_vectors       (gint32       item_ID);
-gboolean gimp_item_is_group         (gint32       item_ID);
-gint32   gimp_item_get_parent       (gint32       item_ID);
-gint*    gimp_item_get_children     (gint32       item_ID,
-                                     gint        *num_children);
-gchar*   gimp_item_get_name         (gint32       item_ID);
-gboolean gimp_item_set_name         (gint32       item_ID,
-                                     const gchar *name);
-gboolean gimp_item_get_visible      (gint32       item_ID);
-gboolean gimp_item_set_visible      (gint32       item_ID,
-                                     gboolean     visible);
-gboolean gimp_item_get_linked       (gint32       item_ID);
-gboolean gimp_item_set_linked       (gint32       item_ID,
-                                     gboolean     linked);
-gboolean gimp_item_get_lock_content (gint32       item_ID);
-gboolean gimp_item_set_lock_content (gint32       item_ID,
-                                     gboolean     lock_content);
-gint     gimp_item_get_tattoo       (gint32       item_ID);
-gboolean gimp_item_set_tattoo       (gint32       item_ID,
-                                     gint         tattoo);
+gboolean gimp_item_is_valid         (gint32          item_ID);
+gint32   gimp_item_get_image        (gint32          item_ID);
+gboolean gimp_item_delete           (gint32          item_ID);
+gboolean gimp_item_is_drawable      (gint32          item_ID);
+gboolean gimp_item_is_layer         (gint32          item_ID);
+gboolean gimp_item_is_channel       (gint32          item_ID);
+gboolean gimp_item_is_layer_mask    (gint32          item_ID);
+gboolean gimp_item_is_selection     (gint32          item_ID);
+gboolean gimp_item_is_vectors       (gint32          item_ID);
+gboolean gimp_item_is_group         (gint32          item_ID);
+gint32   gimp_item_get_parent       (gint32          item_ID);
+gint*    gimp_item_get_children     (gint32          item_ID,
+                                     gint           *num_children);
+gchar*   gimp_item_get_name         (gint32          item_ID);
+gboolean gimp_item_set_name         (gint32          item_ID,
+                                     const gchar    *name);
+gboolean gimp_item_get_visible      (gint32          item_ID);
+gboolean gimp_item_set_visible      (gint32          item_ID,
+                                     gboolean        visible);
+gboolean gimp_item_get_linked       (gint32          item_ID);
+gboolean gimp_item_set_linked       (gint32          item_ID,
+                                     gboolean        linked);
+gboolean gimp_item_get_lock_content (gint32          item_ID);
+gboolean gimp_item_set_lock_content (gint32          item_ID,
+                                     gboolean        lock_content);
+gint     gimp_item_get_tattoo       (gint32          item_ID);
+gboolean gimp_item_set_tattoo       (gint32          item_ID,
+                                     gint            tattoo);
+gboolean gimp_item_to_selection     (gint32          item_ID,
+                                     GimpChannelOps  operation);
 
 
 G_END_DECLS
diff --git a/libgimp/gimpselection_pdb.c b/libgimp/gimpselection_pdb.c
index 554747f..bec80e2 100644
--- a/libgimp/gimpselection_pdb.c
+++ b/libgimp/gimpselection_pdb.c
@@ -23,6 +23,9 @@
 #include "config.h"
 
 #include "gimp.h"
+#undef GIMP_DISABLE_DEPRECATED
+#undef __GIMP_SELECTION_PDB_H__
+#include "gimpselection_pdb.h"
 
 
 /**
@@ -503,14 +506,7 @@ gimp_selection_shrink (gint32 image_ID,
  * gimp_selection_layer_alpha:
  * @layer_ID: Layer with alpha.
  *
- * Transfer the specified layer's alpha channel to the selection mask.
- *
- * The alpha channel information is used to create a selection mask
- * such that for any pixel in the image defined in the specified layer,
- * that layer pixel's alpha value is transferred to the selection mask.
- * If the layer is undefined at a particular image pixel, the
- * associated selection mask value is set to 0. A layer without an
- * alpha channel is considered opaque.
+ * Deprecated: Use gimp_item_to_selection() instead.
  *
  * Returns: TRUE on success.
  */
@@ -537,9 +533,7 @@ gimp_selection_layer_alpha (gint32 layer_ID)
  * gimp_selection_load:
  * @channel_ID: The channel.
  *
- * Transfer the specified channel to the selection mask.
- *
- * This procedure loads the specified channel into the selection mask.
+ * Deprecated: Use gimp_item_to_selection() instead.
  *
  * Returns: TRUE on success.
  */
@@ -599,10 +593,7 @@ gimp_selection_save (gint32 image_ID)
  * @channel_ID: The channel.
  * @operation: The selection operation.
  *
- * Combines the specified channel with the selection mask.
- *
- * This procedure combines the specified channel into the selection
- * mask.
+ * Deprecated: Use gimp_item_to_selection() instead.
  *
  * Returns: TRUE on success.
  */
diff --git a/libgimp/gimpselection_pdb.h b/libgimp/gimpselection_pdb.h
index a842dc2..c6f52ae 100644
--- a/libgimp/gimpselection_pdb.h
+++ b/libgimp/gimpselection_pdb.h
@@ -56,11 +56,15 @@ gboolean               gimp_selection_grow        (gint32          image_ID,
                                                    gint            steps);
 gboolean               gimp_selection_shrink      (gint32          image_ID,
                                                    gint            steps);
+#ifndef GIMP_DISABLE_DEPRECATED
 gboolean               gimp_selection_layer_alpha (gint32          layer_ID);
 gboolean               gimp_selection_load        (gint32          channel_ID);
+#endif /* GIMP_DISABLE_DEPRECATED */
 gint32                 gimp_selection_save        (gint32          image_ID);
+#ifndef GIMP_DISABLE_DEPRECATED
 gboolean               gimp_selection_combine     (gint32          channel_ID,
                                                    GimpChannelOps  operation);
+#endif /* GIMP_DISABLE_DEPRECATED */
 
 
 G_END_DECLS
diff --git a/libgimp/gimpvectors_pdb.c b/libgimp/gimpvectors_pdb.c
index aefa2f6..17343dc 100644
--- a/libgimp/gimpvectors_pdb.c
+++ b/libgimp/gimpvectors_pdb.c
@@ -1268,10 +1268,7 @@ gimp_vectors_bezier_stroke_new_ellipse (gint32  vectors_ID,
  * @feather_radius_x: Feather radius x.
  * @feather_radius_y: Feather radius y.
  *
- * Transforms the specified vectors object into a selection
- *
- * This procedure renders the desired vectors object into the current
- * selection of the image the vectors object belongs to.
+ * Deprecated: Use gimp_item_to_selection() instead.
  *
  * Returns: TRUE on success.
  *
diff --git a/libgimp/gimpvectors_pdb.h b/libgimp/gimpvectors_pdb.h
index f962d2b..7022add 100644
--- a/libgimp/gimpvectors_pdb.h
+++ b/libgimp/gimpvectors_pdb.h
@@ -133,12 +133,14 @@ gint                  gimp_vectors_bezier_stroke_new_ellipse (gint32
                                                               gdouble                 radius_x,
                                                               gdouble                 radius_y,
                                                               gdouble                 angle);
+#ifndef GIMP_DISABLE_DEPRECATED
 gboolean              gimp_vectors_to_selection              (gint32                  vectors_ID,
                                                               GimpChannelOps          operation,
                                                               gboolean                antialias,
                                                               gboolean                feather,
                                                               gdouble                 feather_radius_x,
                                                               gdouble                 feather_radius_y);
+#endif /* GIMP_DISABLE_DEPRECATED */
 gboolean              gimp_vectors_import_from_file          (gint32                  image_ID,
                                                               const gchar            *filename,
                                                               gboolean                merge,
diff --git a/tools/pdbgen/pdb/item.pdb b/tools/pdbgen/pdb/item.pdb
index 46e6a2a..4736857 100644
--- a/tools/pdbgen/pdb/item.pdb
+++ b/tools/pdbgen/pdb/item.pdb
@@ -654,12 +654,53 @@ CODE
     );
 }
 
+sub item_to_selection {
+    $blurb = 'Transforms the specified item into a selection';
+
+    $help = <<'HELP';
+This procedure renders the item's outline into the current selection
+of the image the item belongs to. What exactly the item's outline is
+depends on the item type: for layers, it's the layer's alpha channel,
+for vectors the vector's shape.
+HELP
+
+    &mitch_pdb_misc('2010', '2.8');
+
+    @inargs = (
+        { name => 'item', type => 'item',
+          desc => 'The item to render to the selection' },
+        { name => 'operation', type => 'enum GimpChannelOps',
+          desc => 'The desired operation with current selection' }
+    );
+
+    %invoke = (
+        code => <<'CODE'
+{
+  if (gimp_pdb_item_is_attached (item, NULL, FALSE, error))
+    {
+      GimpPDBContext *pdb_context = GIMP_PDB_CONTEXT (context);
+
+      gimp_item_to_selection (item, operation,
+                              pdb_context->antialias,
+                              pdb_context->feather,
+                              pdb_context->feather_radius_x,
+                              pdb_context->feather_radius_y);
+    }
+  else
+    success = FALSE;
+}
+CODE
+    );
+
+}
+
 @headers = qw("core/gimplayermask.h"
               "core/gimplist.h"
               "core/gimpselection.h"
               "text/gimptextlayer.h"
 	      "vectors/gimpvectors.h"
               "gimppdb-utils.h"
+              "gimppdbcontext.h"
               "gimp-intl.h");
 
 @procs = qw(item_is_valid
@@ -678,7 +719,8 @@ CODE
             item_get_visible item_set_visible
             item_get_linked item_set_linked
             item_get_lock_content item_set_lock_content
-            item_get_tattoo item_set_tattoo);
+            item_get_tattoo item_set_tattoo
+            item_to_selection);
 
 %exports = (app => [ procs], lib => [ procs]);
 
diff --git a/tools/pdbgen/pdb/selection.pdb b/tools/pdbgen/pdb/selection.pdb
index 504fe31..5d3003d 100644
--- a/tools/pdbgen/pdb/selection.pdb
+++ b/tools/pdbgen/pdb/selection.pdb
@@ -411,20 +411,7 @@ CODE
 }
 
 sub selection_layer_alpha {
-    $blurb = <<'BLURB';
-Transfer the specified layer's alpha channel to the selection mask.
-BLURB
-
-    $help = <<'HELP';
-The alpha channel information is used to create a selection mask such
-that for any pixel in the image defined in the specified layer, that
-layer pixel's alpha value is transferred to the selection mask. If the
-layer is undefined at a particular image pixel, the associated
-selection mask value is set to 0. A layer without an alpha channel is
-considered opaque.
-HELP
-
-    &std_pdb_misc;
+    &std_pdb_deprecated ('gimp-item-to-selection');
 
     @inargs = (
 	{ name => 'layer', type => 'layer',
@@ -446,13 +433,7 @@ CODE
 }
 
 sub selection_load {
-    $blurb = 'Transfer the specified channel to the selection mask.';
-
-    $help = <<'HELP';
-This procedure loads the specified channel into the selection mask.
-HELP
-
-    &std_pdb_misc;
+    &std_pdb_deprecated ('gimp-item-to-selection');
 
     @inargs = (
 	{ name => 'channel', type => 'channel',
@@ -474,13 +455,7 @@ CODE
 }
 
 sub selection_combine {
-    $blurb = 'Combines the specified channel with the selection mask.';
-
-    $help = <<'HELP';
-This procedure combines the specified channel into the selection mask.
-HELP
-
-    &std_pdb_misc;
+    &std_pdb_deprecated ('gimp-item-to-selection');
 
     @inargs = (
 	{ name => 'channel', type => 'channel',
@@ -537,7 +512,6 @@ CODE
     );
 }
 
-
 @headers = qw("core/gimppickable.h"
               "gimppdb-utils.h"
               "gimp-intl.h");
diff --git a/tools/pdbgen/pdb/vectors.pdb b/tools/pdbgen/pdb/vectors.pdb
index 16b16d2..d6a97a9 100644
--- a/tools/pdbgen/pdb/vectors.pdb
+++ b/tools/pdbgen/pdb/vectors.pdb
@@ -1255,13 +1255,7 @@ CODE
 }
 
 sub vectors_to_selection {
-    $blurb = 'Transforms the specified vectors object into a selection';
-
-    $help = <<'HELP';
-This procedure renders the desired vectors object into the current selection
-of the image the vectors object belongs to.
-HELP
-
+    &std_pdb_deprecated ('gimp-item-to-selection');
     &simon_pdb_misc('2006', '2.4');
 
     @inargs = (



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