#!/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 Gimp::Image(300,200,RGB);

# instead of my $bg=gimp_layer_new($img, ...)
  my $bg=new Gimp::Layer($img,300,200,RGB_IMAGE,"Background",100,NORMAL_MODE);

# instead of gimp_display_new($img);
  new Gimp::Display($img);

# For any of Gimp::Image, Gimp::Drawable, Gimp::Layer, Gimp::Palette,
# Gimp::Edit, Gimp::Gradients, Gimp::Patterns, Gimp::Progress,
# Gimp::Channel, Gimp::Selection, Gimp::Display, Gimp::Plugin, you can
# use a syntax like Gimp::Objtype->function, and it will be translated
# into gimp_objtype_function

# instead of gimp_context_set_background() you can use
  Gimp::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_insert_layer($img,$bg,0,1);
  $bg->insert_layer(0,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.
Distributed under the same terms as Gimp-Perl.

=cut
