; web-menu-logo-0.10, 
; Copyright (c), 1997, Naresh Sharma naresh@mantra.nl
; MANTRA Research, http://www.mantra.nl
; Created with some inspiration from the basic logo :-)
; 
;  Web-Menu-Logo's for any web-based application. You can draws main menu's
;  sub-menus, sub-sub-sub...-sub menu's or what ever you can brew...
; 
;  Distributed under GNU GPL blah! blah!
;
; The intention was to create unassisted logos, but there is some gimp bug that
; does not (yet!) allow me to create them unassisted.
; Enjoy this script and send me improvements. I will be improving this in time.
; This is really really alpha
; 
; The names of the menu images default to the menu names separated by
; underscores for instance you want to create a menu called 
; 
;      My Great Home Page
;
; You will get two gif images called:
;
;      My_Great_Home_Page.gif    and   My_Great_Home_Page_on.gif
;
; Now you could use the first gif as a normal decoration on your home page
; and the second gif as an active decoration using javascript.
;
; GIMP ON FOLKS!

(define (new-script-fu-web-menu-logo text size font bg-color text-color text-color-active x-crop y-crop vbar-xshift img-border vbar-spacing button_status arrowheight arrowwidth)
  (define (update-segment! s x0 y0 x1 y1)
    (aset s 0 x0)
    (aset s 1 y0)
    (aset s 2 x1)
    (aset s 3 y1))
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  ; Define an arrow for selected/mouse-over menu image
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (define (update-arrow-segment! as ax0 ay0 ax1 ay1 ax2 ay2 ax3 ay3 ax4 ay4)
    (aset as 0 ax0)
    (aset as 1 ay0)
    (aset as 2 ax1)
    (aset as 3 ay1)
    (aset as 4 ax2)
    (aset as 5 ay2)
    (aset as 6 ax3)
    (aset as 7 ay3)
    (aset as 8 ax4)
    (aset as 9 ay4))


  (let* ((img (car (gimp-image-new 400 256 RGB)))
	 (text-layer (car (gimp-text img -1 vbar-xshift 0 text (+ vbar-spacing img-border) TRUE size PIXELS "*" font "*" "*" "*" "*")))
	 (width (car (gimp-drawable-width text-layer)))
	 (width (+ vbar-xshift width))
	 (height (car (gimp-drawable-height text-layer)))
	 (bg-layer (car (gimp-layer-new img width height RGB_IMAGE "Background" 100 NORMAL)))
	 (shadow-layer (car (gimp-layer-new img width height RGBA_IMAGE "Shadow" 100 MULTIPLY)))
	 (old-fg (car (gimp-palette-get-foreground)))
	 (old-bg (car (gimp-palette-get-background)))
	 (segment (cons-array 4 'double))
	 (arrowsegment (cons-array 10 'double))
	 (char-num (string-length text))
	 )
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ; Draw a verticle line
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (gimp-brushes-set-brush "Circle (01)")
    (if (= 0 button_status)
	(begin
	    
	  (update-arrow-segment! arrowsegment 
				 0 (- 0 vbar-spacing)
				 0 (- (/ height 2) (/ arrowwidth 2))
				 arrowheight (/ height 2)
				 0 (+ (/ height 2) (/ arrowwidth 2))
				 0 (+ vbar-spacing height))
	  (gimp-pencil img text-layer 10 arrowsegment)))
    
    (if (= 1 button_status)
	(begin
	  
	  (update-segment! segment 0 (- 0 vbar-spacing) 0 (+ vbar-spacing height))
	  (gimp-pencil img text-layer 4 segment)))
    

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;    (gimp-image-disable-undo img)
;   you may uncomment the above to loose all the info :)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (gimp-image-resize img width height 0 0)
    (gimp-image-add-layer img shadow-layer 1)
    (gimp-image-add-layer img bg-layer 2)
    
    (if (= 1 button_status)
	(gimp-palette-set-background text-color-active))
    (if (= 0 button_status)
	(gimp-palette-set-background text-color))    
    (gimp-layer-set-preserve-trans text-layer TRUE)
    (gimp-edit-fill img text-layer)
    (gimp-palette-set-background bg-color)
    (gimp-edit-fill img bg-layer)
    (gimp-edit-clear img shadow-layer)
    (gimp-selection-layer-alpha img text-layer)
    (gimp-palette-set-background '(0 0 0))
    (gimp-selection-feather img 7.5)
    (gimp-edit-fill img shadow-layer)
    (gimp-selection-none img)
    (gimp-palette-set-foreground '(255 255 255))
    (gimp-blend img text-layer FG-BG-RGB MULTIPLY RADIAL 100 20 REPEAT-NONE FALSE 0 0 0 0 width height)
    (gimp-layer-translate shadow-layer 3 3)
    (gimp-layer-set-name text-layer text)
    (gimp-palette-set-background old-bg)
    (gimp-palette-set-foreground old-fg)
    (gimp-image-enable-undo img)

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ; Flatten the image to make it a www gif bitmap
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (gimp-image-flatten img)
    (gimp-convert-indexed img 1 255)
    (gimp-crop img (- (- width x-crop) vbar-spacing) (- (- height y-crop) (* 2 vbar-spacing)) (/ x-crop 2)  (+ (/ y-crop 2) vbar-spacing))

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;    (gimp-display-new img)
    ;    If you want the see what has been produced, please uncomment the
    ;    above.
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (set! index 0)
    (set! file-name "")
    
    (while (< index char-num)
	   (set! letter (substring text index (+ index 1)))
	   (if (equal? " " letter)
	       (set! letter "_"))
	   (set! file-name (string-append file-name letter))
	   (set! index (+ 1 index)))
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ; Here we are setting the file name to be the original menu separated
    ; by under-scores "_" for the both images and appending a ".gif"
    ; after the normal image and "_on.gif" after the active image.
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (set! file-name-off (string-append file-name ".gif"))
    (set! file-name-on (string-append file-name "_on.gif"))
    (if (= 0 button_status)
	(begin
	  (gimp-image-set-filename img file-name-on)
	  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	  ; The unassisted save must come here but, gimp crashes if the 
	  ; save is unassisted.
	  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	  (file-gif-save 0 img bg-layer file-name-on file-name-on 0 0 0 0)))
    (if (= 1 button_status)
	(begin
	  (gimp-image-set-filename img file-name-off)
	  (file-gif-save 0 img bg-layer file-name-off file-name-off 0 0 0 0)))
))


(define (script-fu-web-menu-logo new-text 
			       new-size 
			       new-x-crop 
			       new-y-crop 
			       new-vbar-xshift
			       new-imageborder
			       new-vbar-spacing
			       new-arrowheight
			       new-arrowwidth
			       new-font 
			       new-bg-color 
			       new-text-color 
			       new-text-color-active
			       )
  (new-script-fu-web-menu-logo 
   new-text 
   new-size 
   new-font 
   new-bg-color 
   new-text-color
   new-text-color-active
   new-x-crop 
   new-y-crop
   new-vbar-xshift
   new-imageborder
   new-vbar-spacing 
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   ; 0 is for normal logo
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   0
   new-arrowheight
   new-arrowwidth)
  
  (new-script-fu-web-menu-logo
   new-text
   new-size
   new-font
   new-bg-color
   new-text-color
   new-text-color-active
   new-x-crop 
   new-y-crop
   new-vbar-xshift
   new-imageborder
   new-vbar-spacing 
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   ; 0 is for active logo
   ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   1
   new-arrowheight
   new-arrowwidth)
  
  )


(script-fu-register "script-fu-web-menu-logo"
		    "<Toolbox>/Xtns/Script-Fu/Logos/Web Menu"
		    "Creates two logos. The logo is give a default file name of the menu separated by underscores"
		    "Naresh Sharma"
		    "Naresh Sharma"
		    "1997"
		    ""
		    SF-VALUE "Text String" "\"My Web Menu\""
		    SF-VALUE "Font Size (in pixels)" "40"
		    SF-VALUE "X-Crop (in pixels)" "8"
		    SF-VALUE "Y-Crop (in pixels)" "10"
		    SF-VALUE "X-Shift (in pixels)" "20"
		    SF-VALUE "Image Border (in pixels)" "10"
		    SF-VALUE "Spacing between Vertical Bar and Text" "10"
		    SF-VALUE "Arrow Height" "10"
		    SF-VALUE "Arrow Width" "12"
		    SF-VALUE "Font" "\"agate\""
		    SF-COLOR "Background Color" '(255 255 255)
		    SF-COLOR "Active Text Color" '(206 178 44)
		    SF-COLOR "Passive Text Color" '(113 98 23))
