;; layers-view.scm -*-scheme-*- ;; Alan Horkan, April 2004. Copyright: Public Domain. ;; You may do whatever you like with this script but please do share ;; and try to let me know if you make any interesting changes. ;; Ideas from Jasc Paint Shop Pro 8 (same menu locations used, mostly) ;; Layers, View: Current Only; All; None; Invert; Show Link Set; Hide Link Set. ;; Undoable view changes seem odd but i like 'em (and Paint Shop Pro does it too) ; failed to get it working using a straight list ; looked at copy-visible.scm for inspiration: answer use an array. ; TODO learn more Scheme, read 'the Wizard book' again ;) ; ideally moving through the layer stack should be abstracted ; and the specific function passed in a parameter as needed ; again must read 'the wizard book' (define (layers-show image boolean) (let* ( (layers (gimp-image-get-layers image)) (number-layers (car layers)) (layer-array (cadr layers)) ) (gimp-image-undo-group-start image) ; hide all the layers, set visibilty FALSE (set! layer-count 0) (while (< layer-count number-layers) (set! layer (aref layer-array layer-count)) (gimp-drawable-set-visible layer boolean) (set! layer-count (+ layer-count 1))) ) (gimp-image-undo-group-end image) ) (define (script-fu-layers-view-all image drawable) (layers-show image TRUE) ; show all the layers (gimp-displays-flush) ; update the display ) (define (script-fu-layers-view-none image drawable) (layers-show image FALSE) ; hide all the layers (gimp-displays-flush) ; update the display ) ; hide all layers, then (re)show current layer (define (script-fu-layers-view-current-only image drawable) (gimp-image-undo-group-start image) (script-fu-layers-view-none image drawable) ; drawable could be a channel, must check it. (if (not (= 0 (car (gimp-drawable-is-layer drawable)))) (gimp-drawable-set-visible drawable TRUE) ) (gimp-displays-flush) (gimp-image-undo-group-end image) ) ; not the most elegant implementation but it'll do (define (script-fu-layers-view-invert image drawable) (let* ( (layers (gimp-image-get-layers image)) (number-layers (car layers)) (layer-array (cadr layers)) ) (gimp-image-undo-group-start image) ; hide all the layers, set visibilty FALSE (set! layer-count 0) (while (< layer-count number-layers) (set! layer (aref layer-array layer-count)) (if (= (car (gimp-drawable-get-visible layer)) TRUE) (set! boolean FALSE) (set! boolean TRUE) ) (gimp-drawable-set-visible layer boolean) (set! layer-count (+ layer-count 1))) ) (gimp-image-undo-group-end image) (gimp-displays-flush) ) (define (layers-view-linked image drawable boolean) (let* ( (layers (gimp-image-get-layers image)) (number-layers (car layers)) (layer-array (cadr layers)) ) (gimp-image-undo-group-start image) ; hide all the layers, set visibilty FALSE (set! layer-count 0) (while (< layer-count number-layers) (set! layer (aref layer-array layer-count)) ; show/hide linked layer and hide/show the others (if (= FALSE (car (gimp-drawable-get-linked layer))) ; must use #t or #f booleans, TRUE or FALSE unrecognised by (not) ;(set! boolean (not boolean)) ; this isn't working quite right ; dirty inelegant hack because (not) wont work as expected (set! boolean (if (= boolean TRUE) FALSE TRUE) ) ) (gimp-drawable-set-visible layer boolean) (set! layer-count (+ layer-count 1))) ) (gimp-image-undo-group-end image) ) (define (script-fu-layers-view-linked-show image drawable) (layers-view-linked image drawable TRUE) ; #t == TRUE (gimp-displays-flush) ) (define (script-fu-layers-view-linked-hide image drawable) (layers-view-linked image drawable FALSE) ; #f == FALSE (gimp-displays-flush) ) ; this doesn't make as much sense as it does in Paint Shop Pro ; it has many seperate numbered link sets, gimp allows only 1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (set! menu _"/Layer/View/") ;(set! menu _"/Layer/Show ") ;; uncomment above line to move (Show) All/None up to the Layer menu. ;; append/prepend description(s) to about string. (set! description " With sincere thanks to Jasc Paint Shop Pro 8 for the inspiration. " ) (set! authors "Alan Horkan. ") (set! copyrights "Alan Horkan, 2004. Public Domain. ") (set! date "2004 04 02 UTC") (script-fu-register "script-fu-layers-view-current-only" _"/Layer/View/_Current Only" (string-append "Show only the current Layer, hide all other layers. " description) authors copyrights date "" ; strings set using variables, see above SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 ) (script-fu-register "script-fu-layers-view-all" (string-append menu _"_All") (string-append "Show All Layers. Sets every layer to visible. " description) authors copyrights date "" SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 ) (script-fu-register "script-fu-layers-view-none" (string-append menu _"_None") (string-append "Show None of the Layers. Hides every layer. " description) authors copyrights date "" SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 ) (script-fu-register "script-fu-layers-view-invert" _"/Layer/View/_Invert" "Invert the visibility of all Layers. If a layer is showing, it gets hidden and if a layer is hidden it will be shown. " authors copyrights date "" ; strings set using variables, see above SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 ) ;; the names "Link Set Show" and "Link Set Hide" are only a workaround ;; so the two menu items will be beside each other sorted alphabetically sorted (script-fu-register "script-fu-layers-view-linked-show" _"/Layer/View/Link Set _Show" (string-append "Show Link Set. Show only the linked layers and hide all other layers. " description) authors copyrights date "" SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 ) (script-fu-register "script-fu-layers-view-linked-hide" _"/Layer/View/Link Set _Hide" ; sorted, beside link set show (string-append "Hide Link Set. Hide only the linked layers and show all other layers. " description) authors copyrights date "" SF-IMAGE "Image" 0 SF-DRAWABLE "Drawable" 0 )