;;; Plugin  : Pop Out Text or Shape
;;; Author  : Rod Detmer
;;; Date    : December 2015
;;; Revision: v-01
;;;                
;;; Version : v-01
;;; Latest version at: http://www.gimpchat.com
;;; Required : Gimp 2.8 or later
;;;
;;; Description:
;;; Creates a pop out effect on a pattern layer. 
;;; Change Log:
;;; Version-1.0
;;;
; Information can be found at http://www.gimpchat.com
;
; License: GPLv3
; 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.
;
; To view a copy of the GNU General Public License
; visit: http://www.gnu.org/licenses/gpl.html

(define (script-fu-pop-out-effect_RD image drawable 
                                          my-pattern 
										  shadow-color 
										  shadow-blur
                                          back-shadow-size 
										  offsetx
										  offsety
										  text-bevel)
(gimp-image-undo-group-start image)

  ; save user settings
  (gimp-context-push)
 
  ; begin
 
  (let*
    ( 
	(width (car (gimp-image-width image)))
    (height (car (gimp-image-height image)))
    (original (car (gimp-layer-new-from-visible image image "Original")))	
    (pattern-fill (car (gimp-layer-new image width height RGBA-IMAGE "Pattern Fill" 100 0)))
    (pattern-template (car (gimp-layer-new image width height RGBA-IMAGE "Pattern Filled Text" 100 0)))	
    (shadow-color-fill (car (gimp-layer-new image width height RGBA-IMAGE "Shadow Color" 100 0)))	
    ;(original-copy (car (gimp-layer-new image width height RGBA-IMAGE "Pattern Filled Text" 100 0)))
    ;(original-copy (car (gimp-floating-sel-anchor)))	
    )

	
	 ; add our layers to the image
  (gimp-image-add-layer image original 0)
  (gimp-layer-resize-to-image-size original)

  	 ; add the pattern layer
  (gimp-image-add-layer image pattern-fill 2)
  (gimp-layer-resize-to-image-size pattern-fill)  
  (gimp-context-set-pattern my-pattern)
  (gimp-drawable-fill pattern-fill PATTERN-FILL)  
  ;(gimp-patterns-popup "my-pattern" "patterns" "Warning")



	 


	; Create our colored and blurred shadow layer
  (gimp-image-add-layer image shadow-color-fill 1) 
  (gimp-layer-resize-to-image-size shadow-color-fill)  	
  (gimp-selection-layer-alpha original) ; our selection
  (gimp-selection-grow image back-shadow-size)
  (gimp-context-set-foreground shadow-color)  
  (gimp-edit-fill shadow-color-fill FOREGROUND-FILL) 
  
   ; deselect the selection before blur
  (gimp-selection-none image)
  
    ; Blur shadow layer
  (plug-in-gauss RUN-NONINTERACTIVE image shadow-color-fill shadow-blur shadow-blur 1) 

     ; Create pattern filled text layer 
  (gimp-image-add-layer image pattern-template 0)
  (gimp-layer-resize-to-image-size pattern-template)
  (gimp-context-set-pattern my-pattern)
  (gimp-drawable-fill pattern-template PATTERN-FILL)   
  (gimp-selection-layer-alpha original) ; our selection  
  (gimp-selection-invert image)
  (gimp-edit-clear pattern-template)  
  ;(gimp-floating-sel-anchor original-copy)  
   ; Offset our pattern filled text layer
  (gimp-drawable-offset pattern-template 0 0 offsetx offsety)   
  
    ; bevel the text pattern filled layer
  (script-fu-add-bevel image pattern-template text-bevel FALSE FALSE)

  (gimp-layer-set-mode pattern-template SCREEN-MODE)

  
    ; Set visibility
  (gimp-drawable-set-visible drawable FALSE)	
  (gimp-drawable-set-visible original TRUE) 

    ; set opacity original layer
  (gimp-layer-set-opacity original 70)	
          ; end
	

  ; remove artifacts
  (gimp-selection-layer-alpha original) ; our selection  
  (gimp-selection-invert image)
  (gimp-edit-clear pattern-template)   
  
  (gimp-selection-none image)    
  ; display new image and return user settings
  (gimp-context-pop)   
  (gimp-image-undo-group-end image)
  (gimp-displays-flush image) 
     
  )
)


    ;register menu location and information   

(script-fu-register
"script-fu-pop-out-effect_RD"
"<Image>/Rod/Alpha to Logo/Pop Out Effect"
"creates a pop out effect from a pattern layer  -  script name: pop-out-effect_RD.scm"
"Rod Detmer"
"Rod Detmer"
"December 2015"
"RGB* GRAY*"
SF-IMAGE       "The Image"                  0
SF-DRAWABLE    "The Drawable"               0 
SF-PATTERN "Select Pattern"                 "Bricks"  
SF-COLOR       "Shadow Color"              '(20 5 8)
SF-ADJUSTMENT  "Shadow Blur"               '(20.0 0.0 9480.0 1 10 0 SF-SLIDER)
SF-ADJUSTMENT "Shadow Size"                '(5 1 36727 1 10 0 SF-SLIDER) 
SF-ADJUSTMENT "offset Amount x ( Vert)"    '(5 -1185 1185 1 10 0 SF-SLIDER) 
SF-ADJUSTMENT "offset Amount y ( Horiz)"   '(7 -1185 1185 1 10 0 SF-SLIDER)
SF-ADJUSTMENT "Bevel Size"                 '(4 1 30 1 10 0 SF-SLIDER)
)