; v2022-06-18, works with gimp 2.10.32
; Resources:
; create-wm.scm
; https://pastebin.com/fKUxE8Ag
;==================================================
;
; Installation:
; This script should be placed in the user or system-wide script folder.
;
;	Windows 7/10
;	C:\Program Files\GIMP 2\share\gimp\2.0\scripts
;	or
;	C:\Users\YOUR-NAME\AppData\Roaming\GIMP\2.10\scripts
;	
;    
;	Linux
;	/home/yourname/.config/GIMP/2.10/scripts  
;	or
;	Linux system-wide
;	/usr/share/gimp/2.0/scripts
;
;==================================================
;
; LICENSE
;
;    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 3 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, see <http://www.gnu.org/licenses/>.
;
;==============================================================

(script-fu-register
    "simple-embosed-water-mark-embose"             ;func name
    "simple-embosed-water-mark-EMBOSE"             ;func label
    "Embose a simple water mark, previously created by the similar named -CREATE script.\nThe water mark is looked for in the clipboard. When the -CREATE script did not copy it there, the user is expected to:\n1) Copy the water mark to the clip board, possibly by Select -> All (Ctrl+A) followed by Edit -> Copy (Ctrl+C)\n2) Clicked on an opened image, or open it, right before activating this script.\n3) Activate the script. Set the sliders to 0 to get the watermark at the center of the image.\nThe script will clear the current selection for the image, if there is one.\nIt will not work on indexed type images.\nA watermark created by the similar name -CREATE script will be hardly, or not at all, observeable on an area that has no variation of color."
                                                   ;description
    "Ron Varburg"                                  ;author
    "copyright 2019-2022, Ron Varburg"    ;copyright notice
    "October 28, 2019"     ;date created
    "RGB | RGBA | GRAY | GRAYA"           ;image type that the script works on
    SF-IMAGE       "Input Image"    0
    SF-DRAWABLE    "Input Drawable" 0
    SF-ADJUSTMENT  "Desired Horizontal Location of watermark upper\nleft corner. Negative numbers set it to the left (%)"  '(0 -50 +50 1 5 0 0)
                           ; horizontal location of the mark.
                           ; Specified as precentage of image width
    SF-ADJUSTMENT  "Desired Vertical Location of watermark upper\nleft corner. Negative numbers set it upper (%)"  '(0 -50 +50 1 5 0 0)
                           ; vertical location of the mark.
                           ; Specified as precentage of image height
)
(script-fu-menu-register "simple-embosed-water-mark-embose" "<Image>/Script-Fu")

(define (simple-embosed-water-mark-embose inImg inDrawable inHorizontalLocation inVerticalLocation)

    (if (= (car (gimp-image-is-valid inImg)) FALSE)
        (
             (gimp-message "No valid image was marked, or otherwise given, to operate on. Quiting.")
             (quit)
	)
    )
    (if (= (car (gimp-edit-paste-as-new-image)) -1)
        (
             (gimp-message "Watermark was not copied to the clipboard. Quiting.")
             (quit)
	)
    )
    (if (= TRUE (car (gimp-layer-is-floating-sel 
                    (car (gimp-image-get-active-layer inImg)))))
        (
             (gimp-message "The script doesn't work with floating selections. Quiting.") 
             (quit)
	)
    )
    (gimp-image-undo-group-start inImg)
    (let*
        ( 
            (horLoc (* (car (gimp-image-width inImg)) (/ inHorizontalLocation 100) ) )
            (verLoc (* (car (gimp-image-height inImg)) (/ inVerticalLocation 100) ) )
            (watermarkLayer1 (car (gimp-edit-paste inDrawable TRUE) ) ) 
            ; watermarkLayer1 is actualy a floating selection at this point. This will be adjusted later.
            (watermarkLayer2 -1)
        ) ;end of our local variables

    (gimp-item-transform-translate watermarkLayer1 horLoc verLoc)
    (gimp-floating-sel-to-layer watermarkLayer1) 
        ; floating selection became the active layer.
    (gimp-layer-set-mode watermarkLayer1 LAYER-MODE-OVERLAY)
    (set! watermarkLayer2  (car (gimp-layer-copy watermarkLayer1 FALSE) ) )
    (gimp-image-insert-layer inImg watermarkLayer2 0 0)
    (gimp-displays-flush)
    ;Finish the undo group for the process
    (gimp-image-undo-group-end inImg) 
    (list watermarkLayer1)
    ) ;end let

)

