home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / Topware / gimp / gimp-setup-20001226.exe / Main / beveled-pattern-button.scm < prev    next >
Encoding:
Text File  |  2000-12-27  |  4.3 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. ; Changed on Feb 4, 1999 by Piet van Oostrum <piet@cs.uu.nl>
  19. ; For use with GIMP 1.1.
  20. ; All calls to gimp-text-* have been converted to use the *-fontname form.
  21. ; The corresponding parameters have been replaced by an SF-FONT parameter.
  22. ; ************************************************************************
  23.  
  24. (define (text-width extents)
  25.   (car extents))
  26.  
  27. (define (text-height extents)
  28.   (cadr extents))
  29.  
  30. (define (text-ascent extents)
  31.   (caddr extents))
  32.  
  33. (define (text-descent extents)
  34.   (cadr (cddr extents)))
  35.  
  36. (define (script-fu-beveled-pattern-button
  37.      text text-size font text-color pattern pressed)
  38.   (let* ((old-bg-color (car (gimp-palette-get-background)))
  39.  
  40.      (text-extents (gimp-text-get-extents-fontname
  41.             text text-size PIXELS font))
  42.      (ascent (text-ascent text-extents))
  43.      (descent (text-descent text-extents))
  44.  
  45.      (xpadding 8)
  46.      (ypadding 6)
  47.  
  48.      (width (+ (* 2 xpadding)
  49.            (- (text-width text-extents)
  50.               (text-width
  51.                (gimp-text-get-extents-fontname
  52.             " " text-size PIXELS font)))))
  53.      (height (+ (* 2 ypadding)
  54.             (+ ascent descent)))
  55.      
  56.      (img (car (gimp-image-new width height RGB)))
  57.      (background (car (gimp-layer-new img width height RGBA_IMAGE "Background" 100 NORMAL)))
  58.      (bumpmap (car (gimp-layer-new img width height RGBA_IMAGE "Bumpmap" 100 NORMAL)))
  59.      (textl (car
  60.          (gimp-text-fontname
  61.           img -1 0 0 text 0 TRUE text-size PIXELS font))))
  62.  
  63.     (gimp-image-undo-disable img)
  64.     (gimp-image-add-layer img background 1)
  65.     (gimp-image-add-layer img bumpmap 1)
  66.  
  67.     ; Create pattern layer
  68.  
  69.     (gimp-palette-set-background '(0 0 0))
  70.     (gimp-edit-fill background BG-IMAGE-FILL)
  71.     (gimp-patterns-set-pattern pattern)
  72.     (gimp-bucket-fill background PATTERN-BUCKET-FILL NORMAL 100 0 FALSE 0 0)
  73.  
  74.     ; Create bumpmap layer
  75.  
  76.     (gimp-edit-fill bumpmap BG-IMAGE-FILL)
  77.  
  78.     (gimp-palette-set-background '(127 127 127))
  79.     (gimp-rect-select img 1 1 (- width 2) (- height 2) REPLACE FALSE 0)
  80.     (gimp-edit-fill bumpmap BG-IMAGE-FILL)
  81.  
  82.     (gimp-palette-set-background '(255 255 255))
  83.     (gimp-rect-select img 2 2 (- width 4) (- height 4) REPLACE FALSE 0)
  84.     (gimp-edit-fill bumpmap BG-IMAGE-FILL)
  85.  
  86.     (gimp-selection-none img)
  87.  
  88.     ; Bumpmap
  89.  
  90.     (plug-in-bump-map 1 img background bumpmap 135 45 2 0 0 0 0 TRUE pressed 0)
  91.  
  92.     ; Color and position text
  93.  
  94.     (gimp-palette-set-background text-color)
  95.     (gimp-layer-set-preserve-trans textl TRUE)
  96.     (gimp-edit-fill textl BG-IMAGE-FILL)
  97.  
  98.     (gimp-layer-set-offsets textl
  99.                 xpadding
  100.                 (+ ypadding descent))
  101.  
  102.     ; Clean up
  103.  
  104.     (gimp-image-set-active-layer img background)
  105.     (gimp-image-remove-layer img bumpmap)
  106.     (gimp-image-flatten img)
  107.  
  108.     (gimp-palette-set-background old-bg-color)
  109.     (gimp-image-undo-enable img)
  110.     (gimp-display-new img)))
  111.  
  112.  
  113. (script-fu-register "script-fu-beveled-pattern-button"
  114.             _"<Toolbox>/Xtns/Script-Fu/Web Page Themes/Beveled Pattern/Button..."
  115.             "Beveled pattern button"
  116.             "Federico Mena Quintero"
  117.             "Federico Mena Quintero"
  118.             "July 1997"
  119.             ""
  120.             SF-STRING  _"Text"       "Hello world!"
  121.             SF-ADJUSTMENT _"Font Size (pixels)" '(32 2 1000 1 10 0 1)
  122.             SF-FONT    _"Font" "-*-helvetica-*-r-*-*-32-*-*-*-p-*-*-*"
  123.             SF-COLOR   _"Text Color" '(0 0 0)
  124.             SF-PATTERN _"Pattern"    "Wood"
  125.             SF-TOGGLE  _"Pressed"   FALSE)
  126.