[gimp] libgimp: add API to access item groups
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimp: add API to access item groups
- Date: Sat, 28 Aug 2010 16:51:40 +0000 (UTC)
commit 4e2289f736f9505e6613fdd9f3d7276750b8cbf1
Author: Michael Natterer <mitch gimp org>
Date: Sat Aug 28 18:49:15 2010 +0200
libgimp: add API to access item groups
A layer tree can be traversed completely now. Tree manipulating
functions still missing.
app/pdb/internal-procs.c | 2 +-
app/pdb/item-cmds.c | 207 +++++++++++++++++++++++++++++++++++++++++++++
libgimp/gimpitem_pdb.c | 110 ++++++++++++++++++++++++
libgimp/gimpitem_pdb.h | 4 +
tools/pdbgen/pdb/item.pdb | 115 +++++++++++++++++++++++++
5 files changed, 437 insertions(+), 1 deletions(-)
---
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index b5b13f0..eaae2fc 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
#include "internal-procs.h"
-/* 626 procedures registered total */
+/* 629 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
diff --git a/app/pdb/item-cmds.c b/app/pdb/item-cmds.c
index 1a08df5..81999d9 100644
--- a/app/pdb/item-cmds.c
+++ b/app/pdb/item-cmds.c
@@ -26,6 +26,7 @@
#include "core/gimpimage.h"
#include "core/gimpitem.h"
#include "core/gimplayermask.h"
+#include "core/gimplist.h"
#include "core/gimpparamspecs.h"
#include "core/gimpselection.h"
#include "text/gimptextlayer.h"
@@ -294,6 +295,120 @@ item_is_vectors_invoker (GimpProcedure *procedure,
}
static GValueArray *
+item_is_group_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GValueArray *return_vals;
+ GimpItem *item;
+ gboolean group = FALSE;
+
+ item = gimp_value_get_item (&args->values[0], gimp);
+
+ if (success)
+ {
+ group = (gimp_viewable_get_children (GIMP_VIEWABLE (item)) != NULL);
+ }
+
+ return_vals = gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+
+ if (success)
+ g_value_set_boolean (&return_vals->values[1], group);
+
+ return return_vals;
+}
+
+static GValueArray *
+item_get_parent_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GValueArray *return_vals;
+ GimpItem *item;
+ GimpItem *parent = NULL;
+
+ item = gimp_value_get_item (&args->values[0], gimp);
+
+ if (success)
+ {
+ parent = gimp_item_get_parent (item);
+ }
+
+ return_vals = gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+
+ if (success)
+ gimp_value_set_item (&return_vals->values[1], parent);
+
+ return return_vals;
+}
+
+static GValueArray *
+item_get_children_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GValueArray *return_vals;
+ GimpItem *item;
+ gint32 num_children = 0;
+ gint32 *child_ids = NULL;
+
+ item = gimp_value_get_item (&args->values[0], gimp);
+
+ if (success)
+ {
+ GimpContainer *children = gimp_viewable_get_children (GIMP_VIEWABLE (item));
+
+ if (children)
+ {
+ num_children = gimp_container_get_n_children (children);
+
+ if (num_children)
+ {
+ GList *list;
+ gint i;
+
+ child_ids = g_new (gint32, num_children);
+
+ for (list = GIMP_LIST (children)->list, i = 0;
+ list;
+ list = g_list_next (list), i++)
+ {
+ child_ids[i] = gimp_item_get_ID (GIMP_ITEM (list->data));
+ }
+ }
+ }
+ else
+ success = FALSE;
+
+ }
+
+ return_vals = gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+
+ if (success)
+ {
+ g_value_set_int (&return_vals->values[1], num_children);
+ gimp_value_take_int32array (&return_vals->values[2], child_ids, num_children);
+ }
+
+ return return_vals;
+}
+
+static GValueArray *
item_get_name_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
@@ -822,6 +937,98 @@ register_item_procs (GimpPDB *pdb)
g_object_unref (procedure);
/*
+ * gimp-item-is-group
+ */
+ procedure = gimp_procedure_new (item_is_group_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-item-is-group");
+ gimp_procedure_set_static_strings (procedure,
+ "gimp-item-is-group",
+ "Returns whether the item is a group item.",
+ "This procedure returns TRUE if the specified item is a group item which can have children.",
+ "Michael Natterer <mitch gimp org>",
+ "Michael Natterer",
+ "2010",
+ NULL);
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_item_id ("item",
+ "item",
+ "The item",
+ pdb->gimp, FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_return_value (procedure,
+ g_param_spec_boolean ("group",
+ "group",
+ "TRUE if the item is a group, FALSE otherwise",
+ FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
+
+ /*
+ * gimp-item-get-parent
+ */
+ procedure = gimp_procedure_new (item_get_parent_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-item-get-parent");
+ gimp_procedure_set_static_strings (procedure,
+ "gimp-item-get-parent",
+ "Returns the item's parent item.",
+ "This procedure returns the item's parent item, if any.",
+ "Michael Natterer <mitch gimp org>",
+ "Michael Natterer",
+ "2010",
+ NULL);
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_item_id ("item",
+ "item",
+ "The item",
+ pdb->gimp, FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_return_value (procedure,
+ gimp_param_spec_item_id ("parent",
+ "parent",
+ "The item's parent item",
+ pdb->gimp, FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
+
+ /*
+ * gimp-item-get-children
+ */
+ procedure = gimp_procedure_new (item_get_children_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-item-get-children");
+ gimp_procedure_set_static_strings (procedure,
+ "gimp-item-get-children",
+ "Returns the item's list of children.",
+ "This procedure returns the list of items which are children of the specified item. The order is topmost to bottommost.",
+ "Michael Natterer <mitch gimp org>",
+ "Michael Natterer",
+ "2010",
+ NULL);
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_item_id ("item",
+ "item",
+ "The item",
+ pdb->gimp, FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_return_value (procedure,
+ gimp_param_spec_int32 ("num-children",
+ "num children",
+ "The item's number of children",
+ 0, G_MAXINT32, 0,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_return_value (procedure,
+ gimp_param_spec_int32_array ("child-ids",
+ "child ids",
+ "The item's list of children",
+ GIMP_PARAM_READWRITE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
+
+ /*
* gimp-item-get-name
*/
procedure = gimp_procedure_new (item_get_name_invoker);
diff --git a/libgimp/gimpitem_pdb.c b/libgimp/gimpitem_pdb.c
index ed9d56d..228a9b8 100644
--- a/libgimp/gimpitem_pdb.c
+++ b/libgimp/gimpitem_pdb.c
@@ -22,6 +22,8 @@
#include "config.h"
+#include <string.h>
+
#include "gimp.h"
@@ -327,6 +329,114 @@ gimp_item_is_vectors (gint32 item_ID)
}
/**
+ * gimp_item_is_group:
+ * @item_ID: The item.
+ *
+ * Returns whether the item is a group item.
+ *
+ * This procedure returns TRUE if the specified item is a group item
+ * which can have children.
+ *
+ * Returns: TRUE if the item is a group, FALSE otherwise.
+ *
+ * Since: GIMP 2.8
+ */
+gboolean
+gimp_item_is_group (gint32 item_ID)
+{
+ GimpParam *return_vals;
+ gint nreturn_vals;
+ gboolean group = FALSE;
+
+ return_vals = gimp_run_procedure ("gimp-item-is-group",
+ &nreturn_vals,
+ GIMP_PDB_ITEM, item_ID,
+ GIMP_PDB_END);
+
+ if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
+ group = return_vals[1].data.d_int32;
+
+ gimp_destroy_params (return_vals, nreturn_vals);
+
+ return group;
+}
+
+/**
+ * gimp_item_get_parent:
+ * @item_ID: The item.
+ *
+ * Returns the item's parent item.
+ *
+ * This procedure returns the item's parent item, if any.
+ *
+ * Returns: The item's parent item.
+ *
+ * Since: GIMP 2.8
+ */
+gint32
+gimp_item_get_parent (gint32 item_ID)
+{
+ GimpParam *return_vals;
+ gint nreturn_vals;
+ gint32 parent_ID = -1;
+
+ return_vals = gimp_run_procedure ("gimp-item-get-parent",
+ &nreturn_vals,
+ GIMP_PDB_ITEM, item_ID,
+ GIMP_PDB_END);
+
+ if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
+ parent_ID = return_vals[1].data.d_item;
+
+ gimp_destroy_params (return_vals, nreturn_vals);
+
+ return parent_ID;
+}
+
+/**
+ * gimp_item_get_children:
+ * @item_ID: The item.
+ * @num_children: The item's number of children.
+ *
+ * Returns the item's list of children.
+ *
+ * This procedure returns the list of items which are children of the
+ * specified item. The order is topmost to bottommost.
+ *
+ * Returns: The item's list of children.
+ *
+ * Since: GIMP 2.8
+ */
+gint *
+gimp_item_get_children (gint32 item_ID,
+ gint *num_children)
+{
+ GimpParam *return_vals;
+ gint nreturn_vals;
+ gint *child_ids = NULL;
+
+ return_vals = gimp_run_procedure ("gimp-item-get-children",
+ &nreturn_vals,
+ GIMP_PDB_ITEM, item_ID,
+ GIMP_PDB_END);
+
+ *num_children = 0;
+
+ if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
+ {
+ *num_children = return_vals[1].data.d_int32;
+ child_ids = g_new (gint32, *num_children);
+ memcpy (child_ids,
+ return_vals[2].data.d_int32array,
+ *num_children * sizeof (gint32));
+ }
+
+ gimp_destroy_params (return_vals, nreturn_vals);
+
+ return child_ids;
+}
+
+/**
* gimp_item_get_name:
* @item_ID: The item.
*
diff --git a/libgimp/gimpitem_pdb.h b/libgimp/gimpitem_pdb.h
index 1cbe246..8396306 100644
--- a/libgimp/gimpitem_pdb.h
+++ b/libgimp/gimpitem_pdb.h
@@ -37,6 +37,10 @@ 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);
diff --git a/tools/pdbgen/pdb/item.pdb b/tools/pdbgen/pdb/item.pdb
index d0cb287..46e6a2a 100644
--- a/tools/pdbgen/pdb/item.pdb
+++ b/tools/pdbgen/pdb/item.pdb
@@ -281,6 +281,117 @@ CODE
);
}
+sub item_is_group {
+ $blurb = 'Returns whether the item is a group item.';
+
+ $help = <<HELP;
+This procedure returns TRUE if the specified item is a group item which
+can have children.
+HELP
+
+ &mitch_pdb_misc('2010', '2.8');
+
+ @inargs = (
+ { name => 'item', type => 'item',
+ desc => 'The item' }
+ );
+
+ @outargs = (
+ { name => 'group', type => 'boolean',
+ desc => 'TRUE if the item is a group, FALSE otherwise' }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ group = (gimp_viewable_get_children (GIMP_VIEWABLE (item)) != NULL);
+}
+CODE
+ );
+}
+
+sub item_get_parent {
+ $blurb = "Returns the item's parent item.";
+
+ $help = <<HELP;
+This procedure returns the item's parent item, if any.
+HELP
+
+ &mitch_pdb_misc('2010', '2.8');
+
+ @inargs = (
+ { name => 'item', type => 'item',
+ desc => 'The item' }
+ );
+
+ @outargs = (
+ { name => 'parent', type => 'item',
+ desc => "The item's parent item" }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ parent = gimp_item_get_parent (item);
+}
+CODE
+ );
+}
+
+sub item_get_children {
+ $blurb = "Returns the item's list of children.";
+
+ $help = <<HELP;
+This procedure returns the list of items which are children of the specified
+item. The order is topmost to bottommost.
+HELP
+
+ &mitch_pdb_misc('2010', '2.8');
+
+ @inargs = (
+ { name => 'item', type => 'item',
+ desc => 'The item' }
+ );
+
+ @outargs = (
+ { name => 'child_ids', type => 'int32array',
+ desc => "The item's list of children",
+ array => { name => 'num_children',
+ desc => "The item's number of children" } }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ GimpContainer *children = gimp_viewable_get_children (GIMP_VIEWABLE (item));
+
+ if (children)
+ {
+ num_children = gimp_container_get_n_children (children);
+
+ if (num_children)
+ {
+ GList *list;
+ gint i;
+
+ child_ids = g_new (gint32, num_children);
+
+ for (list = GIMP_LIST (children)->list, i = 0;
+ list;
+ list = g_list_next (list), i++)
+ {
+ child_ids[i] = gimp_item_get_ID (GIMP_ITEM (list->data));
+ }
+ }
+ }
+ else
+ success = FALSE;
+
+}
+CODE
+ );
+}
+
sub item_get_name {
$blurb = "Get the name of the specified item.";
@@ -544,6 +655,7 @@ CODE
}
@headers = qw("core/gimplayermask.h"
+ "core/gimplist.h"
"core/gimpselection.h"
"text/gimptextlayer.h"
"vectors/gimpvectors.h"
@@ -559,6 +671,9 @@ CODE
item_is_layer_mask
item_is_selection
item_is_vectors
+ item_is_group
+ item_get_parent
+ item_get_children
item_get_name item_set_name
item_get_visible item_set_visible
item_get_linked item_set_linked
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]