;;mhchrome
;Kiki
;http://kikidide.yuki-mura.net/GIMP/gimp.htm
;http://kikidide.yuki-mura.net/GIMP/engimp.htm
;


(define (script-fu-mhchrome text size font tmode text-color text-gradient tpat bevel bg-mode bg-color bg-grad bg-pat)
  (let* ((img (car (gimp-image-new 256 256 RGB)))
;;文字
	 (text-layer (car (gimp-text-fontname img -1 0 0 text (+ (+ (/ size 10) 4) bevel) TRUE size PIXELS font)))
;;幅と高さ
	 (width (car (gimp-drawable-width text-layer)))
	 (height (car (gimp-drawable-height text-layer)))
;;背景
	 (bg-layer (car (gimp-layer-new img width height RGB-IMAGE "Background" 100 0)))
	 (t2-layer (car (gimp-layer-new img width height RGB-IMAGE "t2" 100 0)))

         (old-fg (car (gimp-palette-get-foreground)))
         (old-grad (car (gimp-gradients-get-active)))
         (old-pat (car (gimp-patterns-get-pattern)))
)
(gimp-image-undo-disable img)
;;サイズ調整
    (gimp-image-resize img width height 0 0)

;;前景色の決定
    (gimp-palette-set-foreground text-color)
    (gimp-selection-layer-alpha text-layer)		;add
    (gimp-selection-grow img (/ bevel 2))		;add
    (gimp-edit-fill text-layer 0)
    (cond((= tmode 1)
       (gimp-gradients-set-active text-gradient)
       (gimp-edit-blend text-layer 3 0 2 100 20 REPEAT-NONE
		      FALSE FALSE 0 0 FALSE 0 0 width height))	;CUSOM:3 NORMAL:0 RADIAL:2
       ((= tmode 2)
;;       (gimp-selection-layer-alpha text-layer)		;none
       (gimp-patterns-set-pattern tpat)
       (gimp-bucket-fill text-layer PATTERN-BUCKET-FILL 0 100 255 FALSE 0 0)	;NORNAL:0
;;       (gimp-selection-none img)			;none
     ))
    (gimp-selection-none img)				;add


    (script-fu-mhchromeimg img text-layer bevel TRUE)

;;背景色の決定
    (gimp-palette-set-foreground bg-color)
    (gimp-image-add-layer img bg-layer 2)
    (gimp-drawable-fill bg-layer 0)
;;    (gimp-edit-fill bg-layer 0)
    (cond((= bg-mode 1)
       (gimp-gradients-set-active bg-grad)
       (gimp-blend bg-layer 3 0 0 100 20 REPEAT-NONE FALSE 0 0 0 0 0 0 width height))	;CUSOM:3 NORMAL:0 LINEAR:0
    ((= bg-mode 2)
       (gimp-selection-all img)
       (gimp-patterns-set-pattern bg-pat)
       (gimp-bucket-fill bg-layer PATTERN-BUCKET-FILL 0 100 255 FALSE 0 0)		;NORNAL:0
       (gimp-selection-none img)
       ))

    (gimp-palette-set-foreground old-fg)
    (gimp-gradients-set-active old-grad)
    (gimp-patterns-set-pattern old-pat)

    (gimp-image-undo-enable img)
    (gimp-display-new img)
))

(script-fu-register "script-fu-mhchrome"
		    "<Toolbox>/Xtns/Script-Fu/MH/chrome"
		    "mhchrome"
		    "Kiki"
		    "Kiki"
		    "2013/9"
		    ""
		    SF-STRING		"Text String"	"chrome"
		    SF-ADJUSTMENT	"Font Size (pixels)" '(120 2 1000 1 10 0 1)
		    SF-FONT		"Font"		"Arial Black"
                    SF-OPTION		"text-mode"	'(_"color" _"gradient" _"texture")
		    SF-COLOR		"Text Color"	'(66 83 122)
                    SF-GRADIENT		"Gradient"	"Nauseating Headache"
                    SF-PATTERN		"Pattern"	"Pastel Stuff"
		    SF-ADJUSTMENT	"Bevel" '(7 3 50 1 10 0 1)
		    SF-OPTION		"bg mode"          '(_"color" _"gradient" _"pattern")
		    SF-COLOR		"Background Color"	'(255 255 255)
		    SF-GRADIENT "Background Gradient"     "Rounded edge"
		    SF-PATTERN  "Background Pattern"      "Slate"
)



;;mhchromeimg
;Kiki

(define (script-fu-mhchromeimg img drawable bevel text?)
  (let* (

;;幅と高さ
	 (width (car (gimp-drawable-width drawable)))
	 (height (car (gimp-drawable-height drawable)))
;;背景
	 (t2-layer (car (gimp-layer-new img width height RGB-IMAGE "t2" 100 0)))

         (old-fg (car (gimp-palette-get-foreground)))
         (old-bg (car (gimp-palette-get-background)))
         (old-grad (car (gimp-gradients-get-active)))
         (old-pat (car (gimp-patterns-get-pattern)))
  )

    (gimp-image-undo-group-start img)

(if (= FALSE text?)					;add
(begin							;add
	 (set! width (+ width (* bevel 1.5)))		;add
	 (set! height (+ height (* bevel 1.5)))		;add
	 (gimp-image-resize img width height (/ bevel 1.4) (/ bevel 1.4))	;add
	 (gimp-layer-resize drawable width height (/ bevel 1.4) (/ bevel 1.4))	;add
))

    (gimp-image-add-layer img t2-layer 1)
    (if (= FALSE text?) (gimp-layer-resize t2-layer width height 0 0))	;add
    (gimp-palette-set-background '(255 255 255))	;add
    (gimp-edit-clear t2-layer)
    (gimp-selection-layer-alpha drawable)
    (gimp-selection-feather img bevel)
    (gimp-palette-set-foreground '(0 0 0))
    (gimp-edit-fill t2-layer 0)
    (gimp-selection-none img)				;add
    (plug-in-emboss 1 img t2-layer 135 45 2 1)		;change 2.4
    (define (splineValue)
      (let* ((a (cons-array 12 'byte)))
        (set-pt a 0  0 255)
        (set-pt a 1  45 0)
        (set-pt a 2  81 255)
        (set-pt a 3 170 0)
        (set-pt a 4 204 255)
        (set-pt a 5 255 0)
        a
      )
    )
    (gimp-curves-spline t2-layer 0 12 (splineValue))	;0:VALUE-LUT 1:RED-LUT 2:GREEN-LUT 3:BLUE-LUT..
    (gimp-selection-layer-alpha drawable)
    (gimp-selection-grow img (/ bevel 2))
    (gimp-layer-add-alpha t2-layer)
    (gimp-selection-feather img (+ (* (/ bevel 30) 7) 3))
    (gimp-selection-invert img)
    (gimp-edit-clear t2-layer) 
    (gimp-selection-none img)

    (gimp-layer-set-mode drawable SCREEN-MODE)
    (gimp-image-merge-down img drawable 0)

    (gimp-palette-set-foreground old-fg)
    (gimp-palette-set-background old-bg)
    (gimp-gradients-set-active old-grad)
    (gimp-patterns-set-pattern old-pat)

    (gimp-image-undo-group-end img)
    (gimp-displays-flush)
))


(define (script-fu-mhchromeimgh img drawable bevel)
	(script-fu-mhchromeimg img drawable bevel FALSE)
)

(script-fu-register "script-fu-mhchromeimgh"
		    "<Image>/Script-Fu/MH/chrome"
		    "mhchromeimg"
		    "Kiki"
		    "Kiki"
		    "2012/9"
		    "RGBA"
		    SF-IMAGE        "Image"    0
		    SF-DRAWABLE     "Drawable" 0
		    SF-ADJUSTMENT	"Bevel" '(7 3 50 1 10 0 1)
)




