; This file is part of the Skin Generator, Copyright (c) 2004 Alexander R. Pruss
;
; 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.


(define (script-fu-set-visible-list img name-list)
    (let* ((layers (gimp-image-get-layers img))
	 (num-of-layers (car layers))
	 (layers-array (cadr layers))
      )
	 (set! i 0)
	 (while (< i num-of-layers)
	    (set! layer (aref layers-array i))
        (set! j 0)
        (set! layer-name (car (gimp-drawable-get-name layer)))
        (set! names name-list)
        (gimp-drawable-set-visible layer FALSE)
        (while (< 0 (length names))
          (if (equal? (car names) layer-name)
            (gimp-drawable-set-visible layer TRUE) )
          (set! names (cdr names))
         )
	    (set! i (+ i 1))
        )
       ))

(define (my-rotate img drawable x1 y1 w h angle)
        (gimp-rect-select img x1 y1 w h REPLACE 0 0)
        (if (= 0 (car (gimp-selection-is-empty img)))
              (begin
               (set! floater (car (gimp-selection-float drawable 0 0)))
               (plug-in-rotate FALSE img floater angle FALSE)
               (gimp-floating-sel-anchor floater)
              )
        )
)

(define (my-do-rotations img drawable angle)
;; Graffiti
        (my-rotate img drawable 5 8 42 42 angle)
        (my-rotate img drawable 273 8 42 42 angle)
        (my-rotate img drawable 5 64 42 42 angle)
        (my-rotate img drawable 273 64 42 42 angle)
;;
        (my-rotate img drawable 54 112 16 16 angle)
        (my-rotate img drawable 250 112 16 16 angle)
;; SB
        (my-rotate img drawable 2 134 24 24 angle)
        (my-rotate img drawable 26 134 24 24 angle)
        (my-rotate img drawable 50 134 24 24 angle)
        (my-rotate img drawable 74 134 24 24 angle)
        (my-rotate img drawable 128 134 24 24 angle)
        (my-rotate img drawable 180 134 24 24 angle)
;        (my-rotate img drawable 102 134 24 24 angle)
)

(define (my-rotate-list img angle name-list)
    (let* ((layers (gimp-image-get-layers img))
	 (num-of-layers (car layers))
	 (layers-array (cadr layers))
      )
	 (set! i 0)
	 (while (< i num-of-layers)
	    (set! layer (aref layers-array i))
        (set! j 0)
        (set! layer-name (car (gimp-drawable-get-name layer)))
        (set! names name-list)
        (while (< 0 (length names))
          (if (equal? (car names) layer-name)
            (my-do-rotations img layer angle)
           )
          (set! names (cdr names))
         )
	    (set! i (+ i 1))
        )
       ))

(define (script-fu-dump-0 img filename name-list)
       (set! img2 (car (gimp-image-duplicate img)))
       (script-fu-set-visible-list img2 name-list)
       (set! save-layer (car (gimp-image-merge-visible-layers img2 1)))
       (file-png-save 1 img2 save-layer filename filename 0 9 1 1 0 0 1)
       (gimp-image-delete img2)
)

(define (script-fu-save-standard img0 drawable)
       (set! img (car (gimp-image-duplicate img0)))

        (script-fu-dump-0 img "c:/palmBMX/quickconv/templates/Standard-Cap.png"
                '("Background" "Capitalizer" "Divider" "Buttons"  "Button labels"
                  "Down arrow disabled" "Speaker crossout"))
        (script-fu-dump-0 img "c:/palmBMX/quickconv/templates/Standard-1.png"
                '("Background" "Divider" "Buttons"  "Button labels"
                  "Down arrow disabled" "Speaker crossout"))
        (script-fu-dump-0 img "c:/palmBMX/quickconv/templates/Standard-2.png"
                '("Background" "Divider" "Buttons"  "Button labels"
                  "Up arrow disabled, charging" "Speaker crossout"))
        (script-fu-dump-0 img "c:/palmBMX/quickconv/templates/Standard-3.png"
                '("Background" "Divider" "Buttons"  "Button labels"
                  "Down arrow, empty battery"))
        (script-fu-dump-0 img "c:/palmBMX/quickconv/templates/Standard-4.png"
                '("Background" "Divider" "Buttons"  "Button labels"
                  "Up arrow, full battery"))
        (script-fu-dump-0 img "c:/palmBMX/quickconv/templates/Standard-5.png"
                '("Background" "Divider" "Buttons"  "Button labels"
                  "Down arrow, empty battery"
                  "Reddish glow"))
        (script-fu-dump-0 img "c:/palmBMX/quickconv/templates/Standard-6.png"
                '("Background" "Divider" "Buttons"  "Button labels"
                  "Up arrow, full battery" "Speaker crossout"
                  "Reddish glow"))

        (my-rotate-list img 1 '("Button labels" "Down arrow, empty battery"
        "Up arrow, full battery" "Up arrow disabled, charging" "Speaker crossout"
        "Reddish glow"))

        (script-fu-dump-0 img "c:/palmBMX/quickconv/templates/Standard-1-R.png"
                '("Background" "Divider" "Buttons"  "Button labels"
                  "Down arrow disabled" "Speaker crossout"))
        (script-fu-dump-0 img "c:/palmBMX/quickconv/templates/Standard-2-R.png"
                '("Background" "Divider" "Buttons"  "Button labels"
                  "Up arrow disabled, charging" "Speaker crossout"))
        (script-fu-dump-0 img "c:/palmBMX/quickconv/templates/Standard-3-R.png"
                '("Background" "Divider" "Buttons"  "Button labels"
                  "Down arrow, empty battery"))
        (script-fu-dump-0 img "c:/palmBMX/quickconv/templates/Standard-4-R.png"
                '("Background" "Divider" "Buttons"  "Button labels"
                  "Up arrow, full battery"))
        (script-fu-dump-0 img "c:/palmBMX/quickconv/templates/Standard-5-R.png"
                '("Background" "Divider" "Buttons"  "Button labels"
                  "Down arrow, empty battery"
                  "Reddish glow"))
        (script-fu-dump-0 img "c:/palmBMX/quickconv/templates/Standard-6-R.png"
                '("Background" "Divider" "Buttons"  "Button labels"
                  "Up arrow, full battery" "Speaker crossout"
                  "Reddish glow"))

        (my-rotate-list img 2 '("Button labels" "Down arrow, empty battery"
        "Up arrow, full battery" "Up arrow disabled, charging" "Speaker crossout"
        "Reddish glow"))

        (script-fu-dump-0 img "c:/palmBMX/quickconv/templates/Standard-1-L.png"
                '("Background" "Divider" "Buttons"  "Button labels"
                  "Down arrow disabled" "Speaker crossout"))
        (script-fu-dump-0 img "c:/palmBMX/quickconv/templates/Standard-2-L.png"
                '("Background" "Divider" "Buttons"  "Button labels"
                  "Up arrow disabled, charging" "Speaker crossout"))
        (script-fu-dump-0 img "c:/palmBMX/quickconv/templates/Standard-3-L.png"
                '("Background" "Divider" "Buttons"  "Button labels"
                  "Down arrow, empty battery"))
        (script-fu-dump-0 img "c:/palmBMX/quickconv/templates/Standard-4-L.png"
                '("Background" "Divider" "Buttons"  "Button labels"
                  "Up arrow, full battery"))
        (script-fu-dump-0 img "c:/palmBMX/quickconv/templates/Standard-5-L.png"
                '("Background" "Divider" "Buttons"  "Button labels"
                  "Down arrow, empty battery"
                  "Reddish glow"))
        (script-fu-dump-0 img "c:/palmBMX/quickconv/templates/Standard-6-L.png"
                '("Background" "Divider" "Buttons"  "Button labels"
                  "Up arrow, full battery" "Speaker crossout"
                  "Reddish glow"))

       (gimp-image-delete img)
)

(script-fu-register "script-fu-save-standard"
		    _"<Image>/Script-Fu/Skins/Save Standard Template"
		    "Save Geek"
		    "Alex Pruss"
		    "Alex Pruss"
		    "August, 2004"
		    "RGB* INDEXED* GRAY*"
		    SF-IMAGE    "Image"    0
            SF-DRAWABLE "Drawable"    0)
