gimp/tools/pdbgen/pdb/paths.pdb

328 lines
8.8 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 Andy Thomas <alt@gimp.org>
sub pdb_misc {
$author = $copyright = 'Andy Thomas';
$date = '1999';
}
# The defs
sub path_list {
$blurb = 'List the paths associated with the passed image.';
$help = <<'HELP';
List the paths associated with the passed image.
HELP
&pdb_misc;
@inargs = ( &std_image_arg );
$inargs[0]->{desc} = 'The ID of the image to list the paths from';
@outargs = (
{ name => 'paths_list', type => 'stringarray', init => 1,
desc => 'List of the paths belonging to this image',
array => { name => 'num_paths', init => 1,
desc => 'The number of paths returned' } }
);
%invoke = (
vars => [ 'PathsList *plist' ],
code => <<'CODE'
{
plist = gimage->paths;
if (plist && plist->bz_paths)
{
gint count = 0;
GSList *pl = plist->bz_paths;
num_paths = g_slist_length (pl);
paths_list = g_new (gchar *, num_paths);
while (pl)
{
PATHP pptr = pl->data;
paths_list[count++] = g_strdup (pptr->name->str);
pl = pl->next;
}
}
}
CODE
);
}
sub path_get_points {
$blurb = 'List the points associated with the named path.';
$help = <<'HELP';
List the points associated with the named path.
HELP
&pdb_misc;
@inargs = (
&std_image_arg,
{ name => 'pathname', type => 'string',
desc => 'the name of the path whose points should be listed',
alias => 'pname' }
);
$inargs[0]->{desc} = 'The ID of the image to list the paths from';
@outargs = (
{ name => 'paths_type', type => 'int32',
desc => 'The type of the path. Currently only one type (1 = Bezier)
is supported',
alias => 'pptr->pathtype', no_declare => 1 },
{ name => 'path_closed', type => 'int32',
desc => 'Return if the path is closed. {0=path open, 1= path
closed}',
alias => 'pptr->closed', no_declare => 1 },
{ name => 'points_pairs', type => 'floatarray',
desc => 'The points in the path represented as 3 floats. The first is
the x pos, next is the y pos, last is the type of the pnt.
The type field is dependant on the path type. For beziers
(type 1 paths) the type can either be {1.0= BEZIER_ANCHOR,
2.0= BEZIER_CONTROL}. Note all points are returned in pixel
resolution',
alias => 'pnts', init => 1,
array => { name => 'num_path_point_details',
desc => 'The number of points returned. Each point is
made up of (x,y,pnt_type) of floats',
alias => 'num_pdetails', init => 1 } }
);
%invoke = (
vars => [ 'PathsList *plist', 'PATHP pptr = NULL' ],
code => <<'CODE'
{
/* Get the path with the given name */
plist = gimage->paths;
if (plist && plist->bz_paths)
{
GSList *pl = plist->bz_paths;
while (pl)
{
pptr = pl->data;
if (strcmp (pname, pptr->name->str) == 0)
break; /* Found the path */
pl = pl->next;
pptr = NULL;
}
if (pl && pptr)
{
GSList *points_list;
gint pcount = 0;
points_list = pptr->path_details;
if (points_list)
{
num_pdetails = g_slist_length (points_list) * 3;
pnts = g_new (gdouble, num_pdetails);
/* fill points and types in */
while (points_list)
{
PATHPOINTP ppoint = points_list->data;
pnts[pcount] = ppoint->x;
pnts[pcount + 1] = ppoint->y;
pnts[pcount + 2] = (gfloat) ppoint->type; /* Bit of fiddle but should be understandable why it was done */
pcount += 3;
points_list = points_list->next;
}
}
else
success = FALSE;
}
else
success = FALSE;
}
}
CODE
);
}
sub path_get_current {
$blurb = 'The name of the current path. Error if no paths.';
$help = <<'HELP';
The name of the current path. Error if no paths.
HELP
&pdb_misc;
@inargs = ( &std_image_arg );
$inargs[0]->{desc} = 'The ID of the image to get the current paths from';
@outargs = (
{ name => 'current_path_name', type => 'string',
desc => 'The name of the current path',
alias => 'g_strdup (pptr->name->str)', no_declare => 1 }
);
%invoke = (
vars => [ 'PathsList *plist', 'PATHP pptr = NULL' ],
code => <<'CODE'
{
/* Get the path with the given name */
plist = gimage->paths;
if (plist && plist->bz_paths && plist->last_selected_row >= 0)
pptr = (PATHP) g_slist_nth_data (plist->bz_paths, plist->last_selected_row);
else
success = FALSE;
}
CODE
);
}
sub path_set_current {
$blurb = 'List the paths associated with the passed image.';
$help = <<'HELP';
List the paths associated with the passed image.
HELP
&pdb_misc;
@inargs = (
&std_image_arg,
{ name => 'set_current_path_name', type => 'string',
desc => 'The name of the path to set the current path to',
alias => 'pname' }
);
$inargs[0]->{desc} = 'The ID of the image to list set the paths in';
%invoke = ( code => 'success = paths_set_path (gimage, pname);' );
}
sub path_set_points {
$blurb = 'Set the points associated with the named path.';
$help = <<'HELP';
Set the points associated with the named path.
HELP
&pdb_misc;
@inargs = (
&std_image_arg,
{ name => 'pathname', type => 'string',
desc => 'The name of the path to create (if it exists then all
current points are removed). This will not be set as the
current path. You will have to do a gimp_set_current_path
after creating the path to make it current.',
alias => 'pname', init => 1 },
{ name => 'ptype', type => 'int32',
desc => 'The type of the path. Currently only one type (1 = Bezier)
is supported' },
{ name => 'points_pairs', type => 'floatarray', alias => 'pnts',
desc => 'The points in the path represented as 3 floats. The first is
the x pos, next is the y pos, last is the type of the pnt.
The type field is dependant on the path type. For beziers
(type 1 paths) the type can either be {1.0= BEZIER_ANCHOR,
2.0= BEZIER_CONTROL}. Note all points are returned in pixel
resolution',
array => { name => 'num_path_points',
desc => 'The number of points in the path. Each point is
made up of (x,y) of floats. Currently only the
creation of bezier curves is allowed. The type
parameter must be set to (1) to indicate a BEZIER
type curve. For BEZIERS. Note the that points
must be given in the following order... ACCACCAC
... If the path is not closed the last control
point is missed off. Points consist of three
control points (control/anchor/control) so for a
curve that is not closed there must be at least
two points passed (2 x,y pairs). If num_path_pnts
% 3 = 0 then the path is assumed to be closed
and the points are ACCACCACCACC.',
alias => 'numpoints', init => 1 } }
);
$inargs[0]->{desc} = 'The ID of the image to set the paths in';
%invoke = (
vars => [ 'gboolean pclosed = FALSE' ],
code => <<'CODE'
{
if ((numpoints / 2) % 3 == 0)
pclosed = TRUE;
else if ((numpoints / 2) % 3 != 2)
success = FALSE;
if (success && !paths_set_path_points (gimage, pname, ptype, pclosed,
numpoints, pnts))
success = FALSE;
}
CODE
);
}
sub path_stroke_current {
$blurb = 'Stroke the current path in the passed image.';
$help = <<'HELP';
Stroke the current path in the passed image.
HELP
&pdb_misc;
@inargs = ( &std_image_arg );
$inargs[0]->{desc} = 'The ID of the image which contains the path to stroke';
%invoke = (
vars => [ 'PathsList *plist', 'PATHP pptr = NULL' ],
code => <<'CODE'
{
/* Get the path with the given name */
plist = gimage->paths;
if (plist && plist->bz_paths && plist->last_selected_row >= 0)
{
if ((pptr = (PATHP) g_slist_nth_data (plist->bz_paths,
plist->last_selected_row)))
paths_stroke (gimage, plist, pptr); /* Found the path to stroke.. */
else
success = FALSE;
}
else
success = FALSE;
}
CODE
);
}
@headers = qw("gimage.h" "pathsP.h");
@procs = qw(path_list path_get_points path_get_current path_set_current
path_set_points path_stroke_current);
%exports = (app => [@procs]);
$desc = 'Paths';
1;