# Paste in selection.

from gimpfu import *

def python_fu_paste_in_selection(img, drawable, interpolationMethod, anchor):
	layer = img.active_layer
	sel = img.selection
	bounds = pdb.gimp_selection_bounds( img )
	w = bounds[3] - bounds[1]
	h = bounds[4] - bounds[2]

	# 1. Paste buffer into temporary drawable (float)
	pdb.gimp_edit_paste( img.active_layer, False );
	paste = img.active_layer # paste is a floating layer
	
	# 2. Crop, resize & reposition temporary drawable (float)
	paste.transform_scale( bounds[1], bounds[2], bounds[3], bounds[4], 0, interpolationMethod, 0, 3, 0 )
#	paste.resize( w, h )
#	paste.set_offsets( bounds[1], bounds[2] )

	# 3. Anchor float
	if( anchor ):
		pdb.gimp_floating_sel_anchor( paste )

register(
	"python_fu_paste_in_selection",
	"Paste in selection",
	"Paste in selection",
	"scraze",
	"scraze",
	"2011-09-25",
	"<Image>/Filters/Paste In Selection...",
	"RGB*, GRAY*",
	[
		(PF_RADIO, "interpolation", "Interpolation method", 0,
			(("None", 0),
			("Linear", 1),
			("Cubic", 2),
			("Sinc (Lanczos3)", 3))
		),
#		(PF_TOGGLE, "keepratio", "Keep ratio", True),
		(PF_TOGGLE, "anchor", "Merge into current layer", True)
	],
	[],
	python_fu_paste_in_selection)

main()


