diff --git a/ChangeLog b/ChangeLog index e4ea72eae1..b8ea46e69a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2008-05-17 Michael Natterer + + * tools/pdbgen/pdb/gradient.pdb: applied patch from Lars-Peter + Clausen which adds gimp-gradient-get-number-of-segments. Fixes + bug #533474. + + * app/pdb/gradient-cmds.c + * app/pdb/internal-procs.c + * libgimp/gimpgradient_pdb.[ch]: regenerated. + + * libgimp/gimp.def: add the new symbol. + 2008-05-17 Michael Natterer * plug-ins/twain/Makefile.am: add -framework options to diff --git a/app/pdb/gradient-cmds.c b/app/pdb/gradient-cmds.c index cc046f7736..42cae84abe 100644 --- a/app/pdb/gradient-cmds.c +++ b/app/pdb/gradient-cmds.c @@ -263,6 +263,45 @@ gradient_delete_invoker (GimpProcedure *procedure, return gimp_procedure_get_return_values (procedure, success); } +static GValueArray * +gradient_get_number_of_segments_invoker (GimpProcedure *procedure, + Gimp *gimp, + GimpContext *context, + GimpProgress *progress, + const GValueArray *args, + GError **error) +{ + gboolean success = TRUE; + GValueArray *return_vals; + const gchar *name; + gint32 num_segments = 0; + + name = g_value_get_string (&args->values[0]); + + if (success) + { + GimpGradient *gradient; + GimpGradientSegment *seg; + + gradient = gimp_pdb_get_gradient (gimp, name, FALSE, error); + + if (gradient) + { + for (seg = gradient->segments; seg; seg = seg->next) + num_segments++; + } + else + success = FALSE; + } + + return_vals = gimp_procedure_get_return_values (procedure, success); + + if (success) + g_value_set_int (&return_vals->values[1], num_segments); + + return return_vals; +} + static GValueArray * gradient_get_uniform_samples_invoker (GimpProcedure *procedure, Gimp *gimp, @@ -1501,6 +1540,36 @@ register_gradient_procs (GimpPDB *pdb) gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); + /* + * gimp-gradient-get-number-of-segments + */ + procedure = gimp_procedure_new (gradient_get_number_of_segments_invoker); + gimp_object_set_static_name (GIMP_OBJECT (procedure), + "gimp-gradient-get-number-of-segments"); + gimp_procedure_set_static_strings (procedure, + "gimp-gradient-get-number-of-segments", + "Returns the number of segments of the specified gradient", + "This procedure returns the number of segments of the specified gradient.", + "Lars-Peter Clausen ", + "Lars-Peter Clausen", + "2008", + NULL); + gimp_procedure_add_argument (procedure, + gimp_param_spec_string ("name", + "name", + "The gradient name", + FALSE, FALSE, TRUE, + NULL, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_return_value (procedure, + gimp_param_spec_int32 ("num-segments", + "num segments", + "Number of segments", + G_MININT32, G_MAXINT32, 0, + GIMP_PARAM_READWRITE)); + gimp_pdb_register_procedure (pdb, procedure); + g_object_unref (procedure); + /* * gimp-gradient-get-uniform-samples */ diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c index f1f6933591..45967330b8 100644 --- a/app/pdb/internal-procs.c +++ b/app/pdb/internal-procs.c @@ -29,7 +29,7 @@ #include "internal-procs.h" -/* 585 procedures registered total */ +/* 586 procedures registered total */ void internal_procs_init (GimpPDB *pdb) diff --git a/libgimp/gimp.def b/libgimp/gimp.def index 54ac5640c8..a3dbdf9105 100644 --- a/libgimp/gimp.def +++ b/libgimp/gimp.def @@ -243,6 +243,7 @@ EXPORTS gimp_gradient_delete gimp_gradient_duplicate gimp_gradient_get_custom_samples + gimp_gradient_get_number_of_segments gimp_gradient_get_uniform_samples gimp_gradient_is_editable gimp_gradient_new diff --git a/libgimp/gimpgradient_pdb.c b/libgimp/gimpgradient_pdb.c index 232f3b60e0..e8dec879b8 100644 --- a/libgimp/gimpgradient_pdb.c +++ b/libgimp/gimpgradient_pdb.c @@ -189,6 +189,39 @@ gimp_gradient_delete (const gchar *name) return success; } +/** + * gimp_gradient_get_number_of_segments: + * @name: The gradient name. + * + * Returns the number of segments of the specified gradient + * + * This procedure returns the number of segments of the specified + * gradient. + * + * Returns: Number of segments. + * + * Since: GIMP 2.6 + */ +gint +gimp_gradient_get_number_of_segments (const gchar *name) +{ + GimpParam *return_vals; + gint nreturn_vals; + gint num_segments = 0; + + return_vals = gimp_run_procedure ("gimp-gradient-get-number-of-segments", + &nreturn_vals, + GIMP_PDB_STRING, name, + GIMP_PDB_END); + + if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS) + num_segments = return_vals[1].data.d_int32; + + gimp_destroy_params (return_vals, nreturn_vals); + + return num_segments; +} + /** * gimp_gradient_get_uniform_samples: * @name: The gradient name. diff --git a/libgimp/gimpgradient_pdb.h b/libgimp/gimpgradient_pdb.h index 922cc680e4..474bfd7fbb 100644 --- a/libgimp/gimpgradient_pdb.h +++ b/libgimp/gimpgradient_pdb.h @@ -35,6 +35,7 @@ gboolean gimp_gradient_is_editable (const gchar gchar* gimp_gradient_rename (const gchar *name, const gchar *new_name); gboolean gimp_gradient_delete (const gchar *name); +gint gimp_gradient_get_number_of_segments (const gchar *name); gboolean gimp_gradient_get_uniform_samples (const gchar *name, gint num_samples, gboolean reverse, diff --git a/tools/pdbgen/pdb/gradient.pdb b/tools/pdbgen/pdb/gradient.pdb index d4b7784969..84cfc8800e 100644 --- a/tools/pdbgen/pdb/gradient.pdb +++ b/tools/pdbgen/pdb/gradient.pdb @@ -176,6 +176,48 @@ CODE ); } +sub gradient_get_number_of_segments { + $blurb = 'Returns the number of segments of the specified gradient'; + + $help = <<'HELP'; +This procedure returns the number of segments of the specified gradient. +HELP + + $author = 'Lars-Peter Clausen '; + $copyright = 'Lars-Peter Clausen'; + $date = '2008'; + $since = '2.6'; + + + @inargs = ( + { name => 'name', type => 'string', non_empty => 1, + desc => 'The gradient name' } + ); + + @outargs = ( + { name => 'num_segments', type => 'int32', + init => 0, desc => 'Number of segments' } + ); + %invoke = ( + code => <<'CODE' +{ + GimpGradient *gradient; + GimpGradientSegment *seg; + + gradient = gimp_pdb_get_gradient (gimp, name, FALSE, error); + + if (gradient) + { + for (seg = gradient->segments; seg; seg = seg->next) + num_segments++; + } + else + success = FALSE; +} +CODE + ); +} + sub gradient_get_uniform_samples { $blurb = 'Sample the specified in uniform parts.'; @@ -1385,8 +1427,9 @@ CODE @procs = qw(gradient_new gradient_duplicate gradient_is_editable - gradient_rename + gradient_rename gradient_delete + gradient_get_number_of_segments gradient_get_uniform_samples gradient_get_custom_samples gradient_segment_get_left_color gradient_segment_set_left_color gradient_segment_get_right_color gradient_segment_set_right_color