;;;
;;; ToggleLayersVisibility.scm
;;;
;;; Copyright (C) 2017 Richard McLean (programmer_ceds A T yahoo D O T co D O T uk)
;;;
;;; 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 3 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, see .
;;; Notes for the Toggle Layers Visibility GIMP script
;;; The script is intended to be used to toggle the visibility of the top n layers of an image
;;;
;;; 1. Set the number of layers to be toggled
;;;
;;; 2. Set the number of the layer that is to be the active layer when the upper layers are made visible (1 to number
;;; of layers)
;;;
;;; 3. Set the number of the layer that is to be the active layer when the upper layers are not visible (1 to number
;;; of layers)
;;;
(define (script-fu-toggle-layers-visibility Image NumLayersToToggle VisibleActiveLayer InvisibleActiveLayer)
(let*
(
(image_layers (gimp-image-get-layers Image))
(num_layers (car image_layers))
(layers (cadr image_layers))
(layer '())
(count 0)
(visible_flag FALSE)
(top_layer_visible FALSE)
)
(if (= num_layers 0)
(error '(The image has no layers))
)
(if (> NumLayersToToggle num_layers)
(set! NumLayersToToggle num_layers)
)
(if (> VisibleActiveLayer num_layers)
(set! VisibleActiveLayer num_layers)
)
(set! VisibleActiveLayer (- VisibleActiveLayer 1))
(if (> InvisibleActiveLayer num_layers)
(set! InvisibleActiveLayer num_layers)
)
(set! InvisibleActiveLayer (- InvisibleActiveLayer 1))
(while (< count NumLayersToToggle)
(set! layer (vector-ref layers count))
(if (= (car (gimp-item-get-visible layer)) TRUE)
(set! visible_flag FALSE)
(set! visible_flag TRUE)
)
(gimp-item-set-visible layer visible_flag)
(if (= count 0)
(set! top_layer_visible visible_flag)
)
(set! count (+ count 1))
)
(if (= top_layer_visible TRUE)
(set! layer (vector-ref layers VisibleActiveLayer))
(set! layer (vector-ref layers InvisibleActiveLayer))
)
(gimp-image-set-active-layer Image layer)
(gimp-displays-flush)
) ;;let
) ;;def
(script-fu-register
"script-fu-toggle-layers-visibility"
_"/Layer/Toggle Top Layers Visibility"
"Make the top layers visible or invisible"
"Richard McLean"
"2017, Richard McLean (programmer_ceds A T yahoo D O T co D O T uk)"
"23rd May 2017"
"RGB* GRAY* INDEXED*"
SF-IMAGE "The Image" 0
SF-ADJUSTMENT "Layers to toggle" '(2 1 2000 1 10 0 1)
SF-ADJUSTMENT "Active layer when top layer is visible" '(1 1 2000 1 10 0 1)
SF-ADJUSTMENT "Active layer when top layer is invisible" '(3 1 2000 1 10 0 1)
)