home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_gimp.idb / usr / freeware / share / gimp / scripts / beveled-pattern-button.scm.z / beveled-pattern-button.scm
Encoding:
Text File  |  1999-07-21  |  4.0 KB  |  130 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; Beveled pattern button for web pages
  4. ; Copyright (C) 1997 Federico Mena Quintero
  5. ; federico@nuclecu.unam.mx
  6. ; This program is free software; you can redistribute it and/or modify
  7. ; it under the terms of the GNU General Public License as published by
  8. ; the Free Software Foundation; either version 2 of the License, or
  9. ; (at your option) any later version.
  10. ; This program is distributed in the hope that it will be useful,
  11. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ; GNU General Public License for more details.
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program; if not, write to the Free Software
  16. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.  
  19. (define (text-width extents)
  20.   (car extents))
  21.  
  22. (define (text-height extents)
  23.   (cadr extents))
  24.  
  25. (define (text-ascent extents)
  26.   (caddr extents))
  27.  
  28. (define (text-descent extents)
  29.   (cadr (cddr extents)))
  30.  
  31. (define (script-fu-beveled-pattern-button
  32.      text text-size foundry family weight slant set-width spacing text-color pattern pressed)
  33.   (let* ((old-bg-color (car (gimp-palette-get-background)))
  34.  
  35.      (text-extents (gimp-text-get-extents
  36.             text text-size PIXELS foundry family weight slant set-width spacing))
  37.      (ascent (text-ascent text-extents))
  38.      (descent (text-descent text-extents))
  39.  
  40.      (xpadding 8)
  41.      (ypadding 6)
  42.  
  43.      (width (+ (* 2 xpadding)
  44.            (- (text-width text-extents)
  45.               (text-width
  46.                (gimp-text-get-extents
  47.             " " text-size PIXELS foundry family weight slant set-width spacing)))))
  48.      (height (+ (* 2 ypadding)
  49.             (+ ascent descent)))
  50.      
  51.      (img (car (gimp-image-new width height RGB)))
  52.      (background (car (gimp-layer-new img width height RGBA_IMAGE "Background" 100 NORMAL)))
  53.      (bumpmap (car (gimp-layer-new img width height RGBA_IMAGE "Bumpmap" 100 NORMAL)))
  54.      (textl (car
  55.          (gimp-text
  56.           img -1 0 0 text 0 TRUE text-size PIXELS foundry family weight slant set-width spacing))))
  57.  
  58.     (gimp-image-disable-undo img)
  59.     (gimp-image-add-layer img background 1)
  60.     (gimp-image-add-layer img bumpmap 1)
  61.  
  62.     ; Create pattern layer
  63.  
  64.     (gimp-palette-set-background '(0 0 0))
  65.     (gimp-edit-fill img background)
  66.     (gimp-patterns-set-pattern pattern)
  67.     (gimp-bucket-fill img background PATTERN-BUCKET-FILL NORMAL 100 0 FALSE 0 0)
  68.  
  69.     ; Create bumpmap layer
  70.  
  71.     (gimp-edit-fill img bumpmap)
  72.  
  73.     (gimp-palette-set-background '(127 127 127))
  74.     (gimp-rect-select img 1 1 (- width 2) (- height 2) REPLACE FALSE 0)
  75.     (gimp-edit-fill img bumpmap)
  76.  
  77.     (gimp-palette-set-background '(255 255 255))
  78.     (gimp-rect-select img 2 2 (- width 4) (- height 4) REPLACE FALSE 0)
  79.     (gimp-edit-fill img bumpmap)
  80.  
  81.     (gimp-selection-none img)
  82.  
  83.     ; Bumpmap
  84.  
  85.     (plug-in-bump-map 1 img background bumpmap 135 45 2 0 0 0 0 TRUE pressed 0)
  86.  
  87.     ; Color and position text
  88.  
  89.     (gimp-palette-set-background text-color)
  90.     (gimp-layer-set-preserve-trans textl TRUE)
  91.     (gimp-edit-fill img textl)
  92.  
  93.     (gimp-layer-set-offsets textl
  94.                 xpadding
  95.                 (+ ypadding descent))
  96.  
  97.     ; Clean up
  98.  
  99.     (gimp-image-set-active-layer img background)
  100.     (gimp-image-remove-layer img bumpmap)
  101.     (gimp-image-flatten img)
  102.  
  103.     (gimp-palette-set-background old-bg-color)
  104.     (gimp-image-enable-undo img)
  105.     (gimp-display-new img)))
  106.  
  107.  
  108. (script-fu-register "script-fu-beveled-pattern-button"
  109.             "<Toolbox>/Xtns/Script-Fu/Web page themes/Beveled pattern/Button"
  110.             "Beveled pattern button"
  111.             "Federico Mena Quintero"
  112.             "Federico Mena Quintero"
  113.             "July 1997"
  114.             ""
  115.             SF-VALUE  "Text"       "\"Hello world!\""
  116.             SF-VALUE  "Text size"  "32"
  117.             SF-VALUE  "Foundry"    "\"adobe\""
  118.             SF-VALUE  "Family"     "\"utopia\""
  119.             SF-VALUE  "Weight"     "\"bold\""
  120.             SF-VALUE  "Slant"      "\"r\""
  121.             SF-VALUE  "Set width"  "\"normal\""
  122.             SF-VALUE  "Spacing"    "\"p\""
  123.             SF-COLOR  "Text color" '(0 0 0)
  124.             SF-VALUE  "Pattern"    "\"Wood\""
  125.             SF-TOGGLE "Pressed?"   FALSE)
  126.