1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#!/usr/bin/perl
# this plugin shows some syntax tricks you can use to make oo-like calls.
# I find these make the logic easier to follow. Its good to understand this
# if for no other reason than lots of scripts use it.
use Gimp qw(:auto);
# the extension that's called.
sub plug_in_example_oo {
# we use syntax tricks to make it seem like we're generating a new
# object by calling 'new'. This is fairly standard PERL OO magic.
# instead of my $img=gimp_image_new(300,200,RGB)
my $img=new Image(300,200,RGB);
# instead of my $bg=gimp_layer_new($img, ...)
my $bg=new Layer($img,300,200,RGB_IMAGE,"Background",100,NORMAL_MODE);
# instead of gimp_display_new($img);
new Display($img);
# For any of Image, Drawable, Layer, Palette, Edit, Gradients, Patterns,
# Progress, Channel, Selection, Display, Plugin, you can use a syntax
# like Objtype->function, and it will be translated into
# gimp_objtype_function
# instead of gimp_palette_set_background() you can use
Palette->set_background([200,200,100]);
# Next, we have 2 examples of using the drawable or image as an object when
# its the first parameter to the PDB call.
# image_add_layer($img,$bg,1);
$img->add_layer($bg,1);
# gimp_drawable_fill ($bg,BACKGROUND_FILL);
$bg->fill(BACKGROUND_FILL);
# Finally, we have a plugin example. Note that though the PDB defintion
# specifies a run mode, image and drawable, we only specify a drawable.
# plug_in_blur(1,$img,$bg);
$bg->blur();
}
Gimp::on_run {
plug_in_example_oo;
};
Gimp::on_query {
gimp_install_procedure("plug_in_example_oo", # name
"a test plug-in in perl",# blurb
"try it out", # help (be more verbose than this)
"Marc Lehmann", # Author
"Marc Lehmann", # Copyright
"1998-04-27", # Date
"<Toolbox>/Xtns/Perl Example Plug-in", # Menu
undef, # Image types"
PLUGIN, # Type
[
[PDB_INT32, "run_mode", "Interactive, [non-interactive]"]
], # Params
[]); # Return values
};
exit main;
=head1 LICENSE
Copyright Marc Lehman.
Distrubuted under the same terms as Gimp-Perl.
=cut
|