gimp/tools/pdbgen/pdb/gradients.pdb
Michael Natterer a456ac9bde include "libgimpbase/gimpbase.h" instead of "libgimpbase/gimpparasite.h"
2004-07-16  Michael Natterer  <mitch@gimp.org>

	* tools/pdbgen/pdb.pl: include "libgimpbase/gimpbase.h" instead of
	"libgimpbase/gimpparasite.h" for getting the GimpParasite type.

	* tools/pdbgen/app.pl
	* tools/pdbgen/pdb/drawable.pdb
	* tools/pdbgen/pdb/edit.pdb
	* tools/pdbgen/pdb/gradients.pdb
	* tools/pdbgen/pdb/guides.pdb
	* tools/pdbgen/pdb/image.pdb: removed redundant #includes.

	* tools/pdbgen/pdb/plug_in.pdb: standardized "success" logic.
	Consistetly fail if there is no currently queried plugin.

	* app/pdb/*.c: regenerated.
2004-07-16 14:43:56 +00:00

524 lines
13 KiB
Plaintext

# The GIMP -- an image manipulation program
# Copyright (C) 1995 Spencer Kimball and Peter Mattis
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# "Perlized" from C source by Manish Singh <yosh@gimp.org>
sub federico_misc {
$author = $copyright = 'Federico Mena Quintero';
$date = '1997';
}
sub shlomi_misc {
$author = $copyright = 'Shlomi Fish';
$date = '2004';
}
# The defs
sub gradients_refresh {
$blurb = 'Refresh current gradients. This function always succeeds.';
$help = <<'HELP';
This procedure retrieves all gradients currently in the user's gradient path
and updates the gradient dialogs accordingly.
HELP
$author = $copyright = 'Michael Natterer';
$date = '2002';
%invoke = (
code => <<'CODE'
{
gimp_data_factory_data_save (gimp->gradient_factory);
gimp_data_factory_data_init (gimp->gradient_factory, FALSE);
}
CODE
);
}
sub gradients_get_list {
$blurb = 'Retrieve the list of loaded gradients.';
$help = <<'HELP';
This procedure returns a list of the gradients that are currently loaded in the
gradient editor. You can later use the gimp_gradients_set_active function to
set the active gradient.
HELP
&federico_misc;
@inargs = (
{ name => 'filter',
type => 'string', null_ok => 1,
desc => 'An optional regular expression used to filter the list' }
);
@outargs = (
{ name => 'gradient_list', type => 'stringarray',
desc => 'The list of gradient names',
array => { name => 'num_gradients',
desc => 'The number of loaded gradients' },
init => 1 }
);
%invoke = (
headers => [ qw("core/gimpcontainer-filter.h") ],
code => 'gradient_list = gimp_container_get_filtered_name_array (gimp->gradient_factory->container, filter, &num_gradients);'
);
}
sub gradients_get_gradient {
$blurb = 'Retrieve the name of the active gradient.';
$help = <<'HELP';
This procedure returns the name of the active gradient in the gradient editor.
HELP
&federico_misc;
@outargs = (
{ name => 'name', type => 'string',
desc => 'The name of the active gradient',
alias => 'g_strdup (GIMP_OBJECT (gimp_context_get_gradient (context))->name)',
no_declare => 1 }
);
%invoke = ( code => 'success = gimp_context_get_gradient (context) != NULL;' );
}
sub gradients_set_gradient {
$blurb = 'Sets the specified gradient as the active gradient.';
$help = <<'HELP';
This procedure lets you set the specified gradient as the active or "current"
one. The name is simply a string which corresponds to one of the loaded
gradients in the gradient editor. If no matching gradient is found, this
procedure will return an error. Otherwise, the specified gradient will become
active and will be used for subsequent custom gradient operations.
HELP
&federico_misc;
@inargs = (
{ name => 'name', type => 'string',
desc => 'The name of the gradient to set' }
);
%invoke = (
vars => [ 'GimpGradient *gradient' ],
code => <<'CODE'
{
gradient = (GimpGradient *)
gimp_container_get_child_by_name (gimp->gradient_factory->container, name);
if (gradient)
gimp_context_set_gradient (context, gradient);
else
success = FALSE;
}
CODE
);
}
sub sample_num_arg {
{ name => 'num_samples', type => $_[0] . 'int32',
desc => 'The number of samples to take', alias => 'i' }
}
sub reverse_arg {
{ name => 'reverse', type => 'boolean',
desc => 'Use the reverse gradient (%%desc%%)' }
}
sub sample_outargs {
@outargs = (
{ name => 'color_samples', type => 'floatarray', init => 1,
desc => 'Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An }',
array => { name => 'array_length', no_lib => 1, init => 1,
desc => 'Length of the color_samples array (4 *
num_samples)' } }
);
}
sub gradients_sample_uniform {
$blurb = 'Sample the active gradient in uniform parts.';
$help = <<'HELP';
This procedure samples the active gradient from the gradient editor in the
specified number of uniform parts. It returns a list of floating-point values
which correspond to the RGBA values for each sample. The minimum number of
samples to take is 2, in which case the returned colors will correspond to the
{ 0.0, 1.0 } positions in the gradient. For example, if the number of samples
is 3, the procedure will return the colors at positions { 0.0, 0.5, 1.0 }.
HELP
&federico_misc;
@inargs = (
&sample_num_arg('2 <= '),
&reverse_arg
);
&sample_outargs;
%invoke = (
vars => [ 'GimpGradient *gradient', 'gdouble pos, delta', 'GimpRGB color', 'gdouble *pv' ],
code => <<'CODE'
{
pos = 0.0;
delta = 1.0 / (i - 1);
array_length = i * 4;
pv = color_samples = g_new (gdouble, array_length);
gradient = gimp_context_get_gradient (context);
while (i--)
{
gimp_gradient_get_color_at (gradient, pos, reverse, &color);
*pv++ = color.r;
*pv++ = color.g;
*pv++ = color.b;
*pv++ = color.a;
pos += delta;
}
}
CODE
);
}
sub gradients_sample_custom {
$blurb = 'Sample the active gradient in custom positions.';
$help = <<'HELP';
This procedure samples the active gradient from the gradient editor in the
specified number of points. The procedure will sample the gradient in the
specified positions from the list. The left endpoint of the gradient
corresponds to position 0.0, and the right endpoint corresponds to 1.0. The
procedure returns a list of floating-point values which correspond to the RGBA
values for each sample.
HELP
&federico_misc;
@inargs = (
{ name => 'positions',
type => 'floatarray',
desc => 'The list of positions to sample along the gradient',
alias => 'pos',
array => &sample_num_arg("") },
&reverse_arg
);
&sample_outargs;
%invoke = (
vars => [ 'GimpGradient *gradient', 'GimpRGB color', 'gdouble *pv' ],
code => <<'CODE'
{
array_length = i * 4;
pv = color_samples = g_new (gdouble, array_length);
gradient = gimp_context_get_gradient (context);
while (i--)
{
gimp_gradient_get_color_at (gradient, *pos, reverse, &color);
*pv++ = color.r;
*pv++ = color.g;
*pv++ = color.b;
*pv++ = color.a;
pos++;
}
}
CODE
);
}
sub sample_size_arg {
{ name => 'sample_size',
type => '0 < int32 <= 10000',
desc => 'Size of the sample to return when the gradient is changed
(%%desc%%)',
on_fail => 'sample_size = GIMP_GRADIENT_DEFAULT_SAMPLE_SIZE;',
no_success => 1 }
}
sub gradients_get_gradient_data {
$blurb = <<'BLURB';
Retrieve information about the specified gradient (including data).
BLURB
$help = <<'HELP';
This procedure retrieves information about the gradient. This includes the
gradient name, and the sample data for the gradient.
HELP
&federico_misc;
@inargs = (
{ name => 'name', type => 'string',
desc => 'The gradient name ("" means current active gradient)' },
&sample_size_arg,
&reverse_arg
);
@outargs = (
{ name => 'name', type => 'string',
desc => 'The gradient name',
alias => 'g_strdup (GIMP_OBJECT (gradient)->name)', no_declare => 1 },
{ name => 'grad_data', type => 'floatarray', alias => 'values',
desc => 'The gradient sample data', init => 1,
array => { name => 'width',
desc => 'The gradient sample width (r,g,b,a)',
alias => 'sample_size * 4', no_declare => 1 } }
);
%invoke = (
vars => [ 'GimpGradient *gradient = NULL' ],
code => <<'CODE'
{
if (strlen (name))
{
gradient = (GimpGradient *)
gimp_container_get_child_by_name (gimp->gradient_factory->container,
name);
}
else
{
gradient = gimp_context_get_gradient (context);
}
if (gradient)
{
gdouble *pv;
gdouble pos, delta;
GimpRGB color;
gint i;
i = sample_size;
pos = 0.0;
delta = 1.0 / (i - 1);
pv = values = g_new (gdouble, i * 4);
while (i--)
{
gimp_gradient_get_color_at (gradient, pos, reverse, &color);
*pv++ = color.r;
*pv++ = color.g;
*pv++ = color.b;
*pv++ = color.a;
pos += delta;
}
}
else
success = FALSE;
}
CODE
);
}
sub gradients_new
{
$blurb = "Creates a new gradient";
$help = "This procedure creates a new, uninitialized gradient";
$since = '2.2';
&shlomi_misc;
@inargs = (
{ name => 'name', type => 'string',
desc => 'The requested name of the new gradient' }
);
@outargs = (
{ name => 'name', type => 'string',
desc => 'The actual new gradient name',
alias => 'g_strdup (GIMP_OBJECT (gradient)->name)', no_declare => 1 },
);
%invoke = (
vars => [ 'GimpGradient * gradient = NULL'],
code => <<'CODE'
{
gradient = (GimpGradient *)
gimp_data_factory_data_new (gimp->gradient_factory, name);
}
CODE
);
}
my $_get_gradient_from_name_code = <<'CODE';
if (strlen (name))
{
gradient = (GimpGradient *)
gimp_container_get_child_by_name (gimp->gradient_factory->container,
name);
}
else
{
gradient = gimp_context_get_gradient (context);
}
CODE
sub gradients_duplicate
{
$blurb = "Duplicates a gradient";
$help = "This procedure creates an identical gradient by a different name";
$since = '2.2';
&shlomi_misc;
@inargs = (
{ name => 'name', type => 'string',
desc => "The name of the gradient to duplicate" }
);
@outargs = (
{ name => 'name', type => 'string',
desc => "The name of the gradient's copy",
alias => 'g_strdup (GIMP_OBJECT (gradient_copy)->name)',
no_declare => 1 }
);
%invoke = (
vars => [ 'GimpGradient *gradient = NULL',
'GimpGradient *gradient_copy = NULL' ],
code => <<"CODE"
{
$_get_gradient_from_name_code
if (gradient)
{
gradient_copy = (GimpGradient *)
gimp_data_factory_data_duplicate (gimp->gradient_factory,
GIMP_DATA (gradient));
success = (gradient_copy != NULL);
}
else
{
success = FALSE;
}
}
CODE
);
}
sub gradients_delete
{
$blurb = "Deletes a gradient";
$help = "This procedure deletes a gradient";
$since = '2.2';
&shlomi_misc;
@inargs = (
{ name => 'name', type => 'string',
desc => "The name of the gradient to delete" }
);
%invoke = (
vars => [ 'GimpGradient *gradient = NULL' ],
code => <<"CODE"
{
$_get_gradient_from_name_code
success = (gradient && GIMP_DATA (gradient)->deletable);
if (success)
{
GError *error = NULL;
success = gimp_data_factory_data_delete (gimp->gradient_factory,
GIMP_DATA (gradient),
TRUE, &error);
if (! success)
{
g_message (error->message);
g_clear_error (&error);
}
}
}
CODE
);
}
sub gradients_rename
{
$blurb = "Rename a gradient";
$help = "This procedure renames a gradient";
$since = '2.2';
&shlomi_misc;
@inargs = (
{ name => 'name', type => 'string',
desc => "The name of the gradient to rename" },
{ name => 'new_name', type => 'string',
desc => "The new name of the gradient" }
);
@outargs = (
{ name => 'name', type => 'string',
desc => "The actual new name of the gradient",
alias => 'g_strdup (GIMP_OBJECT (gradient)->name)', no_declare => 1 },
);
%invoke = (
vars => [ 'GimpGradient *gradient = NULL' ],
code => <<"CODE"
{
$_get_gradient_from_name_code
success = (gradient && GIMP_DATA (gradient)->writable);
if (success)
gimp_object_set_name (GIMP_OBJECT (gradient), new_name);
}
CODE
);
}
@headers = qw(<string.h> "core/gimp.h" "core/gimpcontext.h" "core/gimplist.h"
"core/gimpdatafactory.h" "core/gimpgradient.h");
@procs = qw(gradients_refresh gradients_get_list
gradients_get_gradient gradients_set_gradient
gradients_sample_uniform gradients_sample_custom
gradients_get_gradient_data
gradients_new gradients_duplicate
gradients_delete gradients_rename);
%exports = (app => [@procs], lib => [@procs]);
$desc = 'Gradients';
1;