home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 February / PCWorld_2001-02_cd.bin / Software / Topware / gimp / gimp-setup-20001226.exe / Main / beveled-button.scm < prev    next >
Encoding:
Text File  |  2000-12-27  |  5.2 KB  |  170 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; Button00 --- create a simple beveled Web button
  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.  
  25. (define (text-width extents)
  26.   (car extents))
  27.  
  28. (define (text-height extents)
  29.   (cadr extents))
  30.  
  31. (define (text-ascent extents)
  32.   (caddr extents))
  33.  
  34. (define (text-descent extents)
  35.   (cadr (cddr extents)))
  36.  
  37. (define (blend-bumpmap img drawable x1 y1 x2 y2)
  38.   (gimp-blend drawable
  39.           FG-BG-RGB
  40.           DARKEN-ONLY
  41.           LINEAR
  42.           100
  43.           0
  44.           REPEAT-NONE
  45.           FALSE
  46.           0
  47.           0
  48.           x1
  49.           y1
  50.           x2
  51.           y2))
  52.  
  53. (define (script-fu-button00 text
  54.                 size
  55.                 font
  56.                 ul-color
  57.                 lr-color
  58.                 text-color
  59.                 padding
  60.                 bevel-width
  61.                 pressed)
  62.   (let* ((old-fg-color (car (gimp-palette-get-foreground)))
  63.      (old-bg-color (car (gimp-palette-get-background)))
  64.      
  65.      (text-extents (gimp-text-get-extents-fontname text
  66.                           size
  67.                           PIXELS
  68.                           font))
  69.      (ascent (text-ascent text-extents))
  70.      (descent (text-descent text-extents))
  71.      
  72.      (img-width (+ (* 2 (+ padding bevel-width))
  73.                (- (text-width text-extents)
  74.               (text-width (gimp-text-get-extents-fontname " "
  75.                                  size
  76.                                  PIXELS
  77.                                  font)))))
  78.      (img-height (+ (* 2 (+ padding bevel-width))
  79.             (+ ascent descent)))
  80.  
  81.      (img (car (gimp-image-new img-width img-height RGB)))
  82.  
  83.      (bumpmap (car (gimp-layer-new img img-width img-height RGBA_IMAGE "Bumpmap" 100 NORMAL)))
  84.      (gradient (car (gimp-layer-new img img-width img-height RGBA_IMAGE "Gradient" 100 NORMAL))))
  85.  
  86.     (gimp-image-undo-disable img)
  87.  
  88.     ; Create bumpmap layer
  89.     
  90.     (gimp-image-add-layer img bumpmap -1)
  91.     (gimp-palette-set-foreground '(0 0 0))
  92.     (gimp-palette-set-background '(255 255 255))
  93.     (gimp-edit-fill bumpmap BG-IMAGE-FILL)
  94.  
  95.     (gimp-rect-select img 0 0 bevel-width img-height REPLACE FALSE 0)
  96.     (blend-bumpmap img bumpmap 0 0 (- bevel-width 1) 0)
  97.  
  98.     (gimp-rect-select img 0 0 img-width bevel-width REPLACE FALSE 0)
  99.     (blend-bumpmap img bumpmap 0 0 0 (- bevel-width 1))
  100.  
  101.     (gimp-rect-select img (- img-width bevel-width) 0 bevel-width img-height REPLACE FALSE 0)
  102.     (blend-bumpmap img bumpmap (- img-width 1) 0 (- img-width bevel-width) 0)
  103.  
  104.     (gimp-rect-select img 0 (- img-height bevel-width) img-width bevel-width REPLACE FALSE 0)
  105.     (blend-bumpmap img bumpmap 0 (- img-height 1) 0 (- img-height bevel-width))
  106.  
  107.     (gimp-selection-none img)
  108.  
  109.     ; Create gradient layer
  110.  
  111.     (gimp-image-add-layer img gradient -1)
  112.     (gimp-palette-set-foreground ul-color)
  113.     (gimp-palette-set-background lr-color)
  114.     (gimp-blend gradient
  115.         FG-BG-RGB
  116.         NORMAL
  117.         LINEAR
  118.         100
  119.         0
  120.         REPEAT-NONE
  121.         FALSE
  122.         0
  123.         0
  124.         0
  125.         0
  126.         (- img-width 1)
  127.         (- img-height 1))
  128.  
  129.     (plug-in-bump-map 1 img gradient bumpmap 135 45 bevel-width 0 0 0 0 TRUE pressed 0)
  130.  
  131.     ; Create text layer
  132.  
  133.     (gimp-palette-set-foreground text-color)
  134.     (let ((textl (car (gimp-text-fontname
  135.                img -1 0 0 text 0 TRUE size PIXELS font))))
  136.       (gimp-layer-set-offsets textl
  137.                   (+ bevel-width padding)
  138.                   (+ bevel-width padding descent)))
  139.  
  140.     ; Done
  141.  
  142.     (gimp-selection-none img)
  143.     (gimp-palette-set-foreground old-fg-color)
  144.     (gimp-palette-set-background old-bg-color)
  145.     (gimp-image-undo-enable img)
  146.     (gimp-display-new img)))
  147.  
  148. ; Register!
  149.  
  150. (script-fu-register "script-fu-button00"
  151.             _"<Toolbox>/Xtns/Script-Fu/Buttons/Simple Beveled Button..."
  152.             "Simple beveled button"
  153.             "Federico Mena Quintero"
  154.             "Federico Mena Quintero"
  155.             "June 1997"
  156.             ""
  157.             SF-STRING     _"Text" "Hello world!"
  158.             SF-ADJUSTMENT _"Font Size (pixels)" '(16 2 100 1 1 0 1)
  159.             SF-FONT       _"Font" "-*-helvetica-*-r-*-*-16-*-*-*-p-*-*-*"
  160.             SF-COLOR      _"Upper-Left color" '(0 255 127)
  161.             SF-COLOR      _"Lower-Right color" '(0 127 255)
  162.             SF-COLOR      _"Text Color" '(0 0 0)
  163.             SF-ADJUSTMENT _"Padding" '(2 1 100 1 10 0 1)
  164.             SF-ADJUSTMENT _"Bevel Width" '(4 1 100 1 10 0 1)
  165.             SF-TOGGLE     _"Pressed" FALSE)
  166.