

; The GIMP -- an image manipulation program
; Copyright (C) 1995 Spencer Kimball and Peter Mattis
; 
; DigiGlow Glowing Text and/or Drop-Shadow version 1.2.1
; Copyright (c) 1998 Nathan Bendixen <issue@noc.technotronic.com>
; For further information: http://noc.technotronic.com/script-fu/digiglow
;
; 
; Based on code from
; Spencer Kimball
; starscape-logo.scm
;
; 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.





(define (find-blend-coords w h)
  (let* ((denom (+ (/ w h) (/ h w)))
	 (bx    (/ (* -2 h) denom))
	 (by    (/ (* -2 w) denom)))
    (cons bx by)))

(define (script-fu-digiglow-logo text size font text-color shadow-color glow-color bg-color flatten-toggle)
  (let* ((img (car (gimp-image-new 256 256 RGB)))
         (border (/ size 4))
	 (grow (/ size 30))
	 (offx (* size 0.03))
	 (offy (* size 0.02))
	 (feather (/ size 4))
	 (shadow-feather (/ size 25))
	 (text-layer (car (gimp-text img -1 0 0 text border TRUE size PIXELS "*" font "*" "*" "*" "*")))
	 (width (car (gimp-drawable-width text-layer)))
	 (height (car (gimp-drawable-height text-layer)))
	 (w (* (/ (- width (* border 2)) 2.0) 0.75))
	 (h (* (/ (- height (* border 2)) 2.0) 0.75))
	 (cx (/ width 2.0))
	 (cy (/ height 2.0))
	 (bx (+ cx (car (find-blend-coords w h))))
	 (by (+ cy (cdr (find-blend-coords w h))))
	 (bg-layer (car (gimp-layer-new img width height RGB_IMAGE "Background" 100 NORMAL)))
	 (glow-layer (car (gimp-layer-new img width height RGBA_IMAGE "Glow" 100 NORMAL)))
	 (shadow-layer (car (gimp-layer-new img width height RGBA_IMAGE "Drop Shadow" 100 NORMAL)))
	 (bump-channel (car (gimp-channel-new img width height "Bump Map" 50 '(0 0 0))))
	 (old-pattern (car (gimp-patterns-get-pattern)))
	 (old-fg (car (gimp-palette-get-foreground)))
	 (old-bg (car (gimp-palette-get-background))))
    (gimp-image-disable-undo img)
    (gimp-image-resize img width height 0 0)
    (gimp-image-add-layer img bg-layer 1)
    (gimp-image-add-layer img glow-layer 1)
    (gimp-image-add-layer img shadow-layer 1)
    (gimp-layer-set-preserve-trans text-layer TRUE)

    (gimp-palette-set-background bg-color)
    (gimp-edit-fill img bg-layer)
    (gimp-edit-clear img shadow-layer)
    (gimp-edit-clear img glow-layer)

    (gimp-selection-layer-alpha img text-layer)
    (gimp-selection-grow img grow)
    (gimp-selection-feather img feather)
    (gimp-palette-set-background glow-color)
    (gimp-selection-feather img feather)
    (gimp-edit-fill img glow-layer)

    (gimp-selection-layer-alpha img text-layer)
    (gimp-selection-feather img shadow-feather)
    (gimp-palette-set-background shadow-color)
    (gimp-selection-translate img offx offy)
    (gimp-edit-fill img shadow-layer)

    (gimp-selection-none img)
    (gimp-palette-set-background text-color)
    (gimp-palette-set-foreground '(255 255 255))
    (gimp-blend img text-layer FG-BG-RGB NORMAL BILINEAR 100 0 REPEAT-NONE FALSE 0 0 cx cy bx by)

    (gimp-selection-all img)
    (gimp-bucket-fill img bump-channel PATTERN-BUCKET-FILL NORMAL 100 0 FALSE 0 0)
    (plug-in-bump-map 1 img text-layer bump-channel 135.0 45.0 4 0 0 0 0 FALSE FALSE 0)
    (gimp-image-remove-channel img bump-channel)
    (gimp-selection-none img)

    (gimp-layer-set-name text-layer text)
    (gimp-patterns-set-pattern old-pattern)
    (gimp-palette-set-background old-bg)
    (gimp-palette-set-foreground old-fg)
    (if (= flatten-toggle TRUE)
        (gimp-image-flatten img))
    (gimp-image-enable-undo img)
    (gimp-display-new img)))

(script-fu-register "script-fu-digiglow-logo"
        	    "<Toolbox>/Xtns/Script-Fu/Logos/Digitools/Digiglow"
		    "Add a glow and/or drop-shadow effect to a text logo"
		    "Nathan Bendixen (issue@noc.technotronic.com)."
		    "Nathan Bendixen"
		    "21st Aug, 1998"
		    ""
                    SF-VALUE "Text String" "\"digiglow\""
		    SF-VALUE "Font Size (in pixels)" "70"
		    SF-VALUE "Font" "\"agate\""
		    SF-COLOR "Text Pattern Color" '(60 60 60)
		    SF-COLOR "Shadow Color" '(0 0 0)
		    SF-COLOR "Glow Color" '(221 225 220)
		    SF-COLOR "Background Color" '(0 0 99)
		    SF-TOGGLE "Flatten Image Layer?" FALSE)
