#!/usr/bin/perl

use Gimp qw(:auto __ N_);
use Gimp::Fu;

N_"/Xtns/Render"; # dummy translation for i18n bugs

sub stamps {
	my ($size, $hole, $paper, $diameter, $gap) = @_;

	gimp_palette_set_background($paper);
	$img = gimp_image_new($size, $size, RGB);
	$layer = gimp_layer_new($img, $size, $size, RGB_IMAGE, "Layer 1", 100, NORMAL_MODE);
	gimp_image_add_layer($layer, -1);
	gimp_palette_set_background($hole);
	$layer->gimp_edit_fill;
	gimp_selection_none($img);

	my $ncircles = int(($size + $gap) / ($diameter + $gap));
	$x = 0;
	for ($i=0; $i<$ncircles; $i++) {
			gimp_ellipse_select($img,
					$x, 0,
					$diameter, $diameter,
					ADD, 1, 0, 0);
			gimp_ellipse_select($img,
					0, $x,
					$diameter, $diameter,
					ADD, 1, 0, 0);
			$x = $x + $diameter + $gap;
	}
	gimp_palette_set_background($paper);
	gimp_edit_fill($layer);
	gimp_selection_none($img);

# here, at last, comes the clever part! :-)
	$layer->channel_ops_offset(1, 0, -($diameter / 2), -($diameter / 2));
	return $img;
}

register	"stamps",
		"Creates a rectangular image with stamp-like perforations.",
		"Default values are not bad!",
		"Claes G Lindblad <claesg\@algonet.se>",
		"Claes G Lindblad <claesg\@algonet.se>",
		"990314",
		N_"<Toolbox>/Xtns/Render/Stamps",
		undef,
	[
	[PF_INT32, "size", "img size", 90],
	[PF_COLOR, "paper", "paper color", [255, 255, 255]],
	[PF_COLOR, "hole", "hole color", [0, 0, 0]],
	[PF_INT32, "diameter", "diameter", 10],
	[PF_INT32, "gap", "gap", 5]
	],
	\&stamps;

exit main;

