(define
    (script-fu-set-pixel
        image
        drawables
        x
        y
        DrawLine
        ToggleVisibility
    )

    ; use v3 binding of return args from PDB
    (script-fu-use-v3)

    (let*
        (
            (drawable (vector-ref drawables 0))
            (points   (cons-array 4 'double))
        )
            (gimp-image-undo-group-start image)

            (gimp-selection-none image)

            (gimp-context-push)

            (vector-set! points 0 (+ x 3))
            (vector-set! points 1 y)
            (vector-set! points 2 (+ x 5))
            (vector-set! points 3 y)

            (gimp-drawable-set-pixel drawable x y '(0 0 255 255))

            (gimp-context-set-opacity 100.0)

            (gimp-context-set-brush-size 1)
            (gimp-context-set-antialias FALSE)

            (if (= DrawLine 1)
                (gimp-pencil drawable points)
            )

            (if (= ToggleVisibility 1)
                (begin
                    (gimp-item-set-visible drawable FALSE)
                    (gimp-item-set-visible drawable TRUE)
                )
            )

            (gimp-context-pop)
            (gimp-displays-flush)
            (gimp-image-undo-group-end image)
        )
); define

; Register the function with GIMP:

;(Note that the '_' (underscore) characters in the parameter descriptions prevent
; warnings about controls not having mnemonics)

(script-fu-register-filter
    "script-fu-set-pixel"
    "Set Pixel"
    _"xx"
    "x"
    "x"
    "x"
    "*"
    SF-ONE-DRAWABLE
    SF-ADJUSTMENT  "_X coordinate" '(1 0 10000 1 10 0 1)
    SF-ADJUSTMENT  "_Y coordinate" '(1 0 10000 1 10 0 1)
    SF-TOGGLE      "_Draw line as well?" FALSE
    SF-TOGGLE      "_Toggle visibility?" FALSE

)
(script-fu-menu-register "script-fu-set-pixel"
                         "<Image>/Tools")
