gimpScripty

Poslední změna : 2010/10/02 00:22

respace-tiles.scm

syntax lisp

(define (script-fu-respace-tiles-normalize inImage inLayer tileSize margin spacing)

        (let* (
                                (theWidth (car (gimp-drawable-width inLayer)))
                                (theHeight (car (gimp-drawable-height inLayer)))
                                (theImage (car(gimp-image-new theWidth theHeight RGB)))
                                (theLayer)
                                )

        (gimp-context-push)

        (set! theLayer (car (gimp-layer-new theImage theWidth theHeight
                                                                                                                                                        RGBA-IMAGE
                                                                                                                                                        "Tiles"
                                                                                                                                                        100 NORMAL-MODE)))
        (gimp-image-add-layer theImage theLayer 0)
        (gimp-edit-clear theLayer)
        (gimp-display-new theImage)

        (letrec (
                (leftTop (trunc (/ spacing 2)))
                (rightBot(ceiling (/ spacing 2)))
                (loopTiles
                    (lambda(tx ty sx sy)
                            (cond
                                    ((> (+ tileSize sy) theHeight) #t) ;No more lines
                                    ((> (+ tileSize sx) theWidth) (loopTiles 0 (+ ty tileSize) margin (+ sy tileSize spacing) )) ;New line
                                    ((begin
                                            (gimp-selection-clear inImage)
                                            (gimp-rect-select inImage (+ sx leftTop) (+ sy leftTop) (- tileSize rightBot) (- tileSize rightBot) 0 FALSE 0)

                                            (gimp-edit-copy-visible inImage)
                                                    (let (
                                                            (newTile (car (gimp-edit-paste theLayer TRUE)))
                                                            )
                                                        (gimp-layer-set-offsets newTile tx ty)
                                                    )
                                            (loopTiles (+ tx tileSize) ty (+ sx tileSize spacing) sy)
                                        ))
                        ))
            )

            
        )
        (loopTiles 0 0 margin margin (* theHeight theWidth))
        )
        (gimp-selection-clear inImage)
        (gimp-floating-sel-anchor (car (gimp-image-get-floating-sel theImage)))
        
        (gimp-displays-flush)

        (gimp-context-pop)
        )
)

(script-fu-register "script-fu-respace-tiles-normalize"
        _"Respace normalize "
        _"Change spacing and margin to zero on a grid of tiles. "
        "P"
        "2010"
        "P"
        ""
    SF-IMAGE "Image" 0
    SF-DRAWABLE "Drawable" 0
    SF-ADJUSTMENT _"TileSize" '(32 2 512 1 8 0 0)
    SF-ADJUSTMENT _"Margin" '(1 0 16 1 1 0 0)
    SF-ADJUSTMENT _"Spacing" '(2 0 16 1 1 0 0)
)

(script-fu-menu-register "script-fu-respace-tiles-normalize"
                                                                                                    "/Filters/Map/Tiles")

(script-fu-menu-register "script-fu-respace-tiles-normalize"
                                                                                                    "/Test")
/syntax