#!/usr/bin/perl

eval 'exec /usr/bin/perl  -S $0 ${1+"$@"}'
    if 0; # not running under some shell

# 7/15/03 <sjburges@gimp.org>
# Changed spot that its registered from <Image>/Guides to <Image>/Image/Guides
# to reduce horizontal clutter on menubar

use Gimp;
use Gimp::Fu;
use Gimp::Util;

register "guide_to_selection",
         "Puts a selection mask around the guides",
         "Selects the area under the guides (1px wide)",
         "Marc Lehmann",
         "Marc Lehmann <pcg\@goof.com>",
         "1999-08-01",
         N_"<Image>/Image/Guides/To Selection...",
         "*",
         [
          [PF_RADIO,	"operation",	"The selection operation (CHANNEL_OP_ADD, CHANNEL_OP_SUBTRACT, CHANNEL_OP_REPLACE)",		CHANNEL_OP_REPLACE,
                     [ADD => CHANNEL_OP_ADD, SUB => CHANNEL_OP_SUBTRACT, REPLACE => CHANNEL_OP_REPLACE]],
          [PF_TOGGLE,	"feather",	"Feather the selection?",		0],
          [PF_SPINNER,	"feather_radius","Radius for feather operation",	1, [0, 1000, 1e0]],
         ],
         [],
         sub {
    my($img, $drawable, $operation, $feather, $radius) = @_;
    my($W,$H) = ($img->width, $img->height);
    Gimp::Context->push;
    Gimp::Context->set_feather($feather);
    Gimp::Context->set_feather_radius($radius, $radius);

    $i = $img->find_next_guide(0);
    while ($i) {
      my ($x,$y,$w,$h);
      $x = $img->get_guide_position($i);
      if ($img->get_guide_orientation($i) == ORIENTATION_HORIZONTAL) {
         ($x,$y,$w,$h) = (0,$x-$w,$W,1);
      } else {
         ($x,$y,$w,$h) = ($x,0,1,$H);
      }
      $img->select_rectangle($operation,$x,$y,$w,$h);
      $operation = CHANNEL_OP_ADD if $operation == CHANNEL_OP_REPLACE;

      $i = $img->find_next_guide($i);
    }
    Gimp::Context->pop;

    ();
};

exit main;

=head1 LICENSE

Copyright Marc Lehman.
Distributed under the same terms as Gimp-Perl.

=cut

