; simple-button.scm ; GIMP 1.0 script to create a simple button. ; ; Author: "Zow" Terry Brugger ; Date: 11/14/2000 ; ; This script is provided under the GPL, version 2. ; No warranty is expressed or implied. See http://www.gnu.org/ for details. ; The actual impact-button function (define (script-fu-simple-button text text-size text-foundry text-family text-weight text-slant text-set-width text-spacing text-color background-color) (let* ( ; Save the palette colors (old-fg-color (car (gimp-palette-get-foreground))) (old-bg-color (car (gimp-palette-get-background))) ; Calculate the height & width necessary for the given text ; Get the amount of space that the text will take up (text-extents (gimp-text-get-extents text text-size PIXELS text-foundry text-family text-weight text-slant text-set-width text-spacing)) ; And the width, as we'll need that too (text-width (get-text-width text-extents)) ; Get the height of the text (text-height (get-text-height text-extents)) ; extra space for aestedics (border text-height) ; set our size to be the text width plus a border by ; the text height plus a border ; the start points are past half the border (width (+ text-width border)) (height (+ text-height border)) (start-text-x (/ border 2)) (start-text-y (/ border 2)) ; set the x coordinate of the upper-left corner of the second circle (cir2x (- width height)) ; set the coordinates for the rectangle selection (rectx (/ height 2)) (rectxlen (- width height)) ; Create a new image to draw on (image (car (gimp-image-new width height RGB))) ; Every image needs a background ; We kind of cheat to set the color first (background (car (gimp-layer-new image width height RGBA_IMAGE "Background" 100 NORMAL))) ) ; end definitions ; Set up the image for processing (set-up image background background-color) ; Add the text (add-text image text text-size text-foundry text-family text-weight text-slant text-set-width text-spacing 0 text-color background-color start-text-x start-text-y) ; set foreground to black & background to white for masking (gimp-palette-set-default-colors) ; Flaten the layers so we can erase at just one level (gimp-image-set-active-layer image background) (gimp-image-flatten image) ; clear any current selection (gimp-selection-clear image) ; select the first circle (gimp-ellipse-select image 0 0 height height ADD 1 0 0) ; select the second circle (gimp-ellipse-select image cir2x 0 height height ADD 1 0 0) ; select the rectangle (gimp-rect-select image rectx 0 rectxlen height ADD 1 0 0) ; invert the selection (gimp-selection-invert image) ; "erase" everything (gimp-edit-fill image (car (gimp-image-get-active-layer image))) ; Clean up (gimp-selection-none image) (clean-up image (car (gimp-image-get-active-layer image)) old-fg-color old-bg-color) ) ; end let* ) ; end script-fu-impact-button ; Register the script (script-fu-register "script-fu-simple-button" "/Xtns/Script-Fu/Buttons/Simple" "Creates a simple text button." "\"Zow\" Terry Brugger " "(c)2000 \"Zow\" Terry Brugger" "11/14/2000" "" SF-VALUE "Text" "\"Your text here\"" SF-VALUE "Text size" "16" ; SF-VALUE "Foundry" "\"urw\"" SF-VALUE "Foundry" "\"adobe\"" ; SF-VALUE "Family" "\"zapf chancery\"" SF-VALUE "Family" "\"helvetica\"" SF-VALUE "Weight" "\"medium\"" ; SF-VALUE "Slant" "\"i\"" SF-VALUE "Slant" "\"o\"" SF-VALUE "Set width" "\"normal\"" SF-VALUE "Spacing" "\"p\"" SF-COLOR "Text color" '(255 255 255) SF-COLOR "Background" '(0 0 255) ) ; end script-fu-register