[gimp-perl] add_new_layer name more useful. POD after __END__.



commit cde2c8d27c14db6dff8f47ffe2e9e2c2d339d398
Author: Ed J <edj src gnome org>
Date:   Tue Apr 29 14:38:58 2014 +0100

    add_new_layer name more useful. POD after __END__.

 Gimp/Util.pm |  223 +++++++++++++++++++++++++---------------------------------
 1 files changed, 97 insertions(+), 126 deletions(-)
---
diff --git a/Gimp/Util.pm b/Gimp/Util.pm
index ccc380b..197bd2e 100644
--- a/Gimp/Util.pm
+++ b/Gimp/Util.pm
@@ -1,48 +1,9 @@
-=head1 NAME
-
-Gimp::Util - Handy routines for Gimp-Perl users
-
-=head1 SYNOPSIS
-
- use Gimp;
- use Gimp::Util;
-
-=head1 DESCRIPTION
-
-Gimp-Perl is nice, but when you have to write everytime 10 lines just to
-get some simple functions done, it very quickly becomes tedious :-/
-
-This module tries to define some functions that aim to automate frequently
-used tasks, i.e. its a sort of catch-all-bag for (possibly) useful macro
-functions.  If you want to add a function just mail the author of the
-Gimp-Perl extension (see below).
-
-In Gimp-Perl (but not in Gimp as seen by the enduser) it is possible to
-have layers that are NOT attached to an image. This is, IMHO a bad idea,
-you end up with them and the user cannot see them or delete them. So we
-always attach our created layers to an image here, too avoid memory leaks
-and debugging times.
-
-These functions try to preserve the current settings like colors, but not
-all do.
-
-These functions can also be handled in exactly the same way as
-PDB-Functions, i.e. the (hypothetical) function C<gimp_image_xyzzy> can be
-called as $image->xyzzy, if the module is available.
-
-The need to explicitly C<use Gimp::Util> will go away in the future.
-
-=head1 FUNCTIONS
-
-=over 4
-
-=cut
-
 package      Gimp::Util;
+
 use Exporter 'import';
-use vars qw(@EXPORT $VERSION);
 use strict;
- EXPORT    = qw(
+use File::Basename;
+our @EXPORT    = qw(
                 layer_create
                 text_draw
                 image_create_text
@@ -54,20 +15,7 @@ import Gimp;
 # manual "import" to shut perl -cw up
 sub __ ($);
 
-$VERSION = 2.300001;
-
-##############################################################################
-=pod
-
-=item C<get_state ()>, C<set_state state>
-
-C<get_state> returns a scalar representing most of gimps global state
-(at the moment foreground colour, background colour, active gradient,
-pattern and brush). The state can later be restored by a call to
-C<set_state>. This is ideal for library functions such as the ones used
-here, at least when it includes more state in the future.
-
-=cut
+our $VERSION = 2.300001;
 
 sub get_state() {
    [
@@ -88,15 +36,6 @@ sub set_state($) {
    Brushes->set_brush($s->[4]);
 }
 
-##############################################################################
-=pod
-
-=item C<layer_create image,name,color,pos>
-
-create a colored layer, insert into image and return layer
-
-=cut
-
 # [12/23/98] v0.0.1 Tels - First version
 sub layer_create {
   my ($image,$name,$color,$pos) = @_;
@@ -115,15 +54,6 @@ sub layer_create {
   $layer;
   }
 
-##############################################################################
-=pod
-
-=item C<text_draw image,layer,text,font,size,fgcolor>
-
-Create a colored text, draw over a background, add to img, ret img.
-
-=cut
-
 # [12/23/98] v0.0.1 Tels - First version
 sub text_draw {
   my ($image,$layer,$text,$font,$size,$fgcolor) = @_;
@@ -153,16 +83,6 @@ sub text_draw {
   $layer;
 }
 
-##############################################################################
-=pod
-
-=item C<image_create_text text,font,size,fgcolor,bgcolor>
-
-Create an image, add colored text layer on a background layer, return img.
-
-=cut
-
-# [12/23/98] v0.0.1 Tels - First version
 sub image_create_text {
   my ($text,$font,$size,$fgcolor,$bgcolor) = @_;
   my $tcol; # temp. color
@@ -200,16 +120,6 @@ sub image_create_text {
   $image;
   }
 
-##############################################################################
-=pod
-
-=item C<layer_add_layer_as_mask image,layer,layermask>
-
-Take a layer and add it as a mask to another layer, return mask.
-
-=cut
-
-# [12/23/98] v0.0.1 Tels - First version
 sub layer_add_layer_as_mask {
   my ($image,$layer,$layer_mask) = @_;
   my $mask;
@@ -224,33 +134,6 @@ sub layer_add_layer_as_mask {
   $mask;
   }
 
-##############################################################################
-# all functions below are by Marc Lehmann
-=pod
-
-=item C<gimp_image_layertype $alpha>
-
-returns the corresponding layer type for an image, alpha controls wether the layer type
-is with alpha or not. Example: imagetype: RGB -> RGB_IMAGE (or RGBA_IMAGE).
-
-=item C<gimp_layer2imagetype $layertype>
-
-returns the corresponding layer type for an image, alpha controls wether the layer type
-is with alpha or not. Example: imagetype: RGB -> RGB_IMAGE (or RGBA_IMAGE).
-
-=item C<gimp_image_add_new_layer $image,$index,$fill_type,$alpha>
-
-creates a new layer and adds it at position $index (default 0) to the
-image, after filling it with gimp_drawable_fill $fill_type (default
-BG_IMAGE_FILL). If $alpha is non-zero (default 1), the new layer has
-alpha.
-
-=item C<gimp_image_set_visible $image,@layers>, C<gimp_image_set_invisible $image,@layers>
-
-mark the given layers visible (invisible) and all others invisible (visible).
-
-=cut
-
 sub gimp_image_layertype {
    my($type,$alpha) = ($_[0]->base_type,$_[1]);
    $type == &RGB     ? $alpha ? &RGBA_IMAGE     : &RGB_IMAGE     :
@@ -272,7 +155,12 @@ sub gimp_layer2imagetype {
 
 sub gimp_image_add_new_layer {
    my ($image,$index,$filltype,$alpha)= _;
-   my $layer = new Gimp::Layer ($image, $image->width, $image->height, $image->layertype (defined $alpha ? 
$alpha : 1), join(":",(caller)[1,2]), 100, &NORMAL_MODE);
+   my $layer = Gimp::Layer->new(
+      $image, $image->width, $image->height,
+      $image->layertype (defined $alpha ? $alpha : 1),
+      join(':', map { basename($_) } (caller 2)[1,2]),
+      100, &NORMAL_MODE
+   );
    $layer->fill (defined $filltype ? $filltype : &BACKGROUND_FILL);
    $image->add_layer ($layer, $index*1);
    $layer;
@@ -294,13 +182,96 @@ sub gimp_image_set_invisible {
    }
 }
 
-=pod
+1;
+__END__
+=head1 NAME
+
+Gimp::Util - Handy routines for Gimp-Perl users
+
+=head1 SYNOPSIS
+
+ use Gimp;
+ use Gimp::Util;
+
+=head1 DESCRIPTION
+
+Gimp-Perl is nice, but when you have to write everytime 10 lines just to
+get some simple functions done, it very quickly becomes tedious :-/
+
+This module tries to define some functions that aim to automate frequently
+used tasks, i.e. its a sort of catch-all-bag for (possibly) useful macro
+functions.  If you want to add a function just mail the author of the
+Gimp-Perl extension (see below).
+
+In Gimp-Perl (but not in Gimp as seen by the enduser) it is possible to
+have layers that are NOT attached to an image. This is, IMHO a bad idea,
+you end up with them and the user cannot see them or delete them. So we
+always attach our created layers to an image here, too avoid memory leaks
+and debugging times.
+
+These functions try to preserve the current settings like colors, but not
+all do.
+
+These functions can also be handled in exactly the same way as
+PDB-Functions, i.e. the (hypothetical) function C<gimp_image_xyzzy> can be
+called as $image->xyzzy, if the module is available.
+
+The need to explicitly C<use Gimp::Util> will go away in the future.
+
+=head1 FUNCTIONS
+
+=over 4
+
+=item C<get_state ()>, C<set_state state>
+
+C<get_state> returns a scalar representing most of gimps global state
+(at the moment foreground colour, background colour, active gradient,
+pattern and brush). The state can later be restored by a call to
+C<set_state>. This is ideal for library functions such as the ones used
+here, at least when it includes more state in the future.
+
+=item C<layer_create image,name,color,pos>
+
+create a colored layer, insert into image and return layer
+
+=item C<text_draw image,layer,text,font,size,fgcolor>
+
+Create a colored text, draw over a background, add to img, ret img.
+
+=item C<image_create_text text,font,size,fgcolor,bgcolor>
+
+Create an image, add colored text layer on a background layer, return img.
+
+=item C<layer_add_layer_as_mask image,layer,layermask>
+
+Take a layer and add it as a mask to another layer, return mask.
+
+=item C<gimp_image_layertype $alpha>
+
+returns the corresponding layer type for an image, alpha controls wether the layer type
+is with alpha or not. Example: imagetype: RGB -> RGB_IMAGE (or RGBA_IMAGE).
+
+=item C<gimp_layer2imagetype $layertype>
+
+returns the corresponding layer type for an image, alpha controls wether the layer type
+is with alpha or not. Example: imagetype: RGB -> RGB_IMAGE (or RGBA_IMAGE).
+
+=item C<$image-E<gt>add_new_layer($index,$fill_type,$alpha)>
+
+creates a new layer and adds it at position $index (default 0) to the
+image, after filling it with gimp_drawable_fill $fill_type (default
+BG_IMAGE_FILL). If $alpha is non-zero (default 1), the new layer has
+alpha. Makes up a name based on the 2nd-level caller filename and line.
+
+=item C<$image-E<gt>set_visible(@layers)>, C<$image-E<gt>set_invisible(@layers)>
+
+mark the given layers visible (invisible) and all others invisible (visible).
 
 =back
 
 =head1 AUTHOR
 
-Various, version 1.000 written mainly by Tels (http://bloodgate.com/). The author
-of the Gimp-Perl extension (contact him to include new functions) is Marc
-Lehmann <pcg goof com>
+Various, version 1.000 written mainly by Tels (http://bloodgate.com/). The
+author of the Gimp-Perl extension (contact him to include new functions)
+is Marc Lehmann <pcg goof com>
 


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