
; The GIMP -- an image manipulation program
; Copyright (C) 1995 Spencer Kimball and Peter Mattis
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
; 
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
; 
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;
; copy layer - a script to simplify copying layers from
;              one image to another
;
; Adrian Likins <adrian@gimp.org> www.gimp.org/~adrian/scripts.html
;
;  The utility of this script is left as an exercise for the reader.


(define (script-fu-layer-copy img drawable layer-to-copy anchor)
  (let* ((width (car (gimp-drawable-width layer-to-copy)))
	 (height (car (gimp-drawable-height layer-to-copy)))
	 (type (car (gimp-drawable-type drawable)))
	 (new-layer (car (gimp-layer-new img width height type "New Layer" 100 NORMAL)))
	 (source-image (car (gimp-drawable-image layer-to-copy))))
    (gimp-edit-clear img new-layer)
    (gimp-selection-all source-image)
    (gimp-edit-copy source-image layer-to-copy)
    (gimp-selection-none source-image)
    (gimp-image-add-layer img new-layer -1)
    (let ((floating-selection (car (gimp-edit-paste img new-layer FALSE))))
      (if (= anchor TRUE)
	  (gimp-floating-sel-anchor floating-selection)))))

(script-fu-register "script-fu-layer-copy"
		      "<Image>/Edit/Layer Copy"
		      "Copy a Layer"
		      "Adrian Likins <adrian@gimp.org>"
		      "Adrian Likins"
		      "11/11/1997"
		      "RGB* INDEXED* GRAY*"
		      SF-IMAGE "Image" 0
		      SF-DRAWABLE "Drawable" 0
		      SF-DRAWABLE "Layer to Copy" 0
		      SF-TOGGLE "Anchor Floating selection?" TRUE)

