home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 August / ENTER.ISO / files / gimp-2.0.5-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / beveled-pattern-button.scm < prev    next >
Encoding:
Text File  |  2004-09-26  |  4.1 KB  |  127 lines

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