[Gimp-developer] Re: Script-Fu template - really this time...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Simon Budig (Simon.Budig@xxxxxxxxxxx) wrote:
> The script is attached as well as available at
>   http://www.home.unix-ag.org/simon/files/script-fu-template.scm

/me feels stupid.

Now it really is attached...  :-)
 
Bye,
       Simon
-- 
      Simon.Budig@xxxxxxxxxxx       http://www.home.unix-ag.org/simon/
;
; Script-Fu template, fill in the blanks and have fun   :)
;
; (C) 2004 Simon Budig <simon@xxxxxxxx>
;
; This template is in the public domain, I'd like to encourage you to
; place your script under the GPL.
;

; define the function that does the actual work. Choose a name that
; does not clash with other names in the PDB. It starts with "script-fu"
; by convention.

; functions that should be registered in the images context menu have
; to take the image and current drawable as the first two arguments.

(define (script-fu-template image drawable color)

        ; the let* environment allows you to define local variables.
	; It is considered good style to define all variables used
	; in the script here, so that the global namespace does not
	; get polluted.

	(let* (
		; calls to PDB functions always return a list. We have
		; to pick the first element with "car" explicitely, even
		; when the function called returns just one value.

		(width  (car  (gimp-drawable-width drawable)))
		(height (car  (gimp-drawable-height drawable)))
		(x0     (car  (gimp-drawable-offsets drawable)))
		(y0     (cadr (gimp-drawable-offsets drawable)))
		;        ^^^^ - here we pick the second element of the
		;               returned list...

		(old-fg-color (car (gimp-palette-get-foreground)))
	      )

	    ; Ok, we are about to do multiple actions on the image, so
	    ; when the user wants to undo the effect he should not have
	    ; to wade through lots of script-generated steps. Hence
	    ; we create a undo group on our image.

	    (gimp-image-undo-group-start image)

	    ; Here you'd implement your own ideas. For now we
	    ; just select and fill a rectangle centered on the
	    ; currently active drawable.

	    (gimp-rect-select image
			      (+ x0 (* width 0.25))
			      (+ y0 (* height 0.25))
			      (* width 0.5)
			      (* height 0.5)
			      CHANNEL-OP-REPLACE
			      0 0)

	    (gimp-palette-set-foreground color)

	    (gimp-edit-fill drawable FOREGROUND-FILL)

	    ; it always is a good idea to restore the state of the
	    ; GIMP. This makes it easier for the user who uses gimp,
	    ; since e.g. his foreground color does not change
	    ; unexpectedly. Thats why we saved it in a variable,
	    ; now we restore it again.

	    (gimp-palette-set-foreground old-fg-color)

	    ; We are done with our actions. End the undo group
	    ; opened earlier. Be careful to properly end undo
	    ; groups again, otherwise the undo stack of the image
	    ; is messed up.

	    (gimp-image-undo-group-end image)

	    ; finally we notify the UI that something has changed.

	    (gimp-displays-flush)
	)
)


; Here we register the function in the GIMPs PDB.
; We have just one additional parameter to the default parameters:
; the user can choose the color for the script. For more available
; script-fu user interface elements see the "test-sphere.scm" script.

(script-fu-register "script-fu-template"
		    "<Image>/Script-Fu/Render/Rectangle..."
		    "script-fu template (right now renders just a rectangle)"
		    "Simon Budig  <simon@xxxxxxxx>"
		    "Simon Budig"
		    "2004/2/10"
		    "RGB* GRAY*"
		    SF-IMAGE "Input Image" 0
		    SF-DRAWABLE "Input Drawable" 0
		    SF-COLOR "Rectangle Color" '(10 80 256)
)

[Index of Archives]     [Video For Linux]     [Photo]     [Yosemite News]     [gtk]     [GIMP for Windows]     [KDE]     [GEGL]     [Gimp's Home]     [Gimp on GUI]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux