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

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; Round Button --- create a round beveled Web button.
  4. ; Copyright (C) 1998 Federico Mena Quintero & Arturo Espinosa Aldama
  5. ; federico@nuclecu.unam.mx arturo@nuclecu.unam.mx
  6. ; ************************************************************************
  7. ; Changed on Feb 4, 1999 by Piet van Oostrum <piet@cs.uu.nl>
  8. ; For use with GIMP 1.1.
  9. ; All calls to gimp-text-* have been converted to use the *-fontname form.
  10. ; The corresponding parameters have been replaced by an SF-FONT parameter.
  11. ; ************************************************************************
  12. ; This program is free software; you can redistribute it and/or modify
  13. ; it under the terms of the GNU General Public License as published by
  14. ; the Free Software Foundation; either version 2 of the License, or
  15. ; (at your option) any later version.
  16. ; This program is distributed in the hope that it will be useful,
  17. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. ; GNU General Public License for more details.
  20. ; You should have received a copy of the GNU General Public License
  21. ; along with this program; if not, write to the Free Software
  22. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  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 (round-select img x y width height ratio)
  37.   (let* ((diameter (* ratio height)))
  38.     (gimp-ellipse-select img x y diameter height ADD FALSE 0 0)
  39.     (gimp-ellipse-select img (+ x (- width diameter)) y
  40.              diameter height ADD FALSE 0 0)
  41.     (gimp-rect-select img (+ x (/ diameter 2)) y
  42.               (- width diameter) height ADD FALSE 0)))
  43.   
  44. (define (script-fu-round-button text
  45.                 size
  46.                 font
  47.                 ul-color
  48.                 lr-color
  49.                 text-color
  50.                 ul-color-high
  51.                 lr-color-high
  52.                 hlight-color
  53.                 xpadding
  54.                 ypadding
  55.                 bevel
  56.                 ratio
  57.                 notpressed
  58.                 notpressed-active
  59.                 pressed)
  60.  
  61.   (cond ((eqv? notpressed TRUE)
  62.      (do-pupibutton text size font ul-color lr-color
  63.             text-color xpadding ypadding bevel ratio 0)))
  64.   (cond ((eqv? notpressed-active TRUE)
  65.      (do-pupibutton text size font ul-color-high lr-color-high
  66.             hlight-color xpadding ypadding bevel ratio 0)))
  67.   (cond ((eqv? pressed TRUE)
  68.      (do-pupibutton text size font ul-color-high lr-color-high
  69.             hlight-color xpadding ypadding bevel ratio 1))))
  70.   
  71. (define (do-pupibutton text
  72.                 size
  73.                 font
  74.                 ul-color
  75.                 lr-color
  76.                 text-color
  77.                 xpadding
  78.                 ypadding
  79.                 bevel
  80.                 ratio
  81.                 pressed)
  82.  
  83.   (let* ((old-fg-color (car (gimp-palette-get-foreground)))
  84.      (old-bg-color (car (gimp-palette-get-background)))
  85.      
  86.      (text-extents (gimp-text-get-extents-fontname text
  87.                           size
  88.                           PIXELS
  89.                           font))
  90.      (ascent (text-ascent text-extents))
  91.      (descent (text-descent text-extents))
  92.      
  93.      (height (+ (* 2 (+ ypadding bevel))
  94.             (+ ascent descent)))
  95.  
  96.      (radius (/ (* ratio height) 4))
  97.  
  98.      (width (+ (* 2 (+ radius xpadding)) bevel
  99.                (- (text-width text-extents)
  100.               (text-width (gimp-text-get-extents-fontname " "
  101.                                  size
  102.                                  PIXELS
  103.                                  font)))))
  104.                                  
  105.      (img (car (gimp-image-new width height RGB)))
  106.  
  107.      (bumpmap (car (gimp-layer-new img width height
  108.                        RGBA_IMAGE "Bumpmap" 100 NORMAL)))
  109.      (gradient (car (gimp-layer-new img width height
  110.                     RGBA_IMAGE "Button" 100 NORMAL))))
  111.     (gimp-image-undo-disable img)
  112.  
  113.     ; Create bumpmap layer
  114.     
  115.     (gimp-image-add-layer img bumpmap -1)
  116.     (gimp-selection-none img)
  117.     (gimp-palette-set-background '(0 0 0))
  118.     (gimp-edit-fill bumpmap BG-IMAGE-FILL)
  119.  
  120.     (round-select img (/ bevel 2) (/ bevel 2)
  121.           (- width bevel) (- height bevel) ratio)
  122.     (gimp-palette-set-background '(255 255 255))
  123.     (gimp-edit-fill bumpmap BG-IMAGE-FILL)
  124.  
  125.     (gimp-selection-none img)
  126.     (plug-in-gauss-rle 1 img bumpmap bevel 1 1)
  127.  
  128.     ; Create gradient layer
  129.  
  130.     (gimp-image-add-layer img gradient -1)
  131.     (gimp-edit-clear gradient)
  132.     (round-select img 0 0 width height ratio)
  133.     (gimp-palette-set-foreground ul-color)
  134.     (gimp-palette-set-background lr-color)
  135.  
  136.     (gimp-blend gradient
  137.         FG-BG-RGB
  138.         NORMAL
  139.         LINEAR
  140.         100
  141.         0
  142.         REPEAT-NONE
  143.         FALSE
  144.         0
  145.         0
  146.         0
  147.         0
  148.         0
  149.         (- height 1))
  150.  
  151.     (gimp-selection-none img)
  152.  
  153.     (plug-in-bump-map 1 img gradient bumpmap
  154.               135 45 bevel 0 0 0 0 TRUE pressed 0)
  155.  
  156. ;     Create text layer
  157.  
  158.     (cond ((eqv? pressed 1) (set! bevel (+ bevel 1))))
  159.  
  160.     (gimp-palette-set-foreground text-color)
  161.     (let ((textl (car (gimp-text-fontname
  162.                img -1 0 0 text 0 TRUE size PIXELS
  163.                font))))
  164.       (gimp-layer-set-offsets textl
  165.                   (+ xpadding radius bevel)
  166.                   (+ ypadding descent bevel)))
  167.  
  168. ;   Delete some fucked-up pixels.
  169.  
  170.     (gimp-selection-none img)
  171.     (round-select img 1 1 (- width 1) (- height 1) ratio)
  172.     (gimp-selection-invert img)
  173.     (gimp-edit-clear gradient)
  174.  
  175. ;     Done
  176.  
  177.     (gimp-image-remove-layer img bumpmap)
  178.     (gimp-image-merge-visible-layers img EXPAND-AS-NECESSARY)
  179.  
  180.     (gimp-selection-none img)
  181.     (gimp-palette-set-foreground old-fg-color)
  182.     (gimp-palette-set-background old-bg-color)
  183.     (gimp-image-undo-enable img)
  184.     (gimp-display-new img)))
  185.  
  186. ; Register!
  187.  
  188. (script-fu-register "script-fu-round-button"
  189.             _"<Toolbox>/Xtns/Script-Fu/Buttons/Round Button..."
  190.             "Round button"
  191.             "Arturo Espinosa (stolen from quartic's beveled button)"
  192.             "Arturo Espinosa & Federico Mena Quintero"
  193.             "June 1998"
  194.             ""
  195.             SF-STRING     _"Text" "The GIMP"
  196.             SF-ADJUSTMENT _"Font Size (pixels)" '(16 2 100 1 1 0 1)
  197.             SF-FONT       _"Font" "-*-helvetica-*-r-*-*-24-*-*-*-p-*-*-*"
  198.             SF-COLOR      _"Upper Color" '(192 192 0)
  199.             SF-COLOR      _"Lower Color" '(128 108 0)
  200.             SF-COLOR      _"Text Color" '(0 0 0)
  201.             SF-COLOR      _"Upper Color (Active)" '(255 255 0)
  202.             SF-COLOR      _"Lower Color (Active)" '(128 108 0)
  203.             SF-COLOR      _"Text Color (Active)" '(0 0 192)
  204.             SF-ADJUSTMENT _"Padding X" '(4 0 100 1 10 0 1)
  205.             SF-ADJUSTMENT _"Padding Y" '(4 0 100 1 10 0 1)
  206.             SF-ADJUSTMENT _"Bevel Width" '(2 0 100 1 10 0 1)
  207.             SF-ADJUSTMENT _"Round Ratio" '(1 0.05 20 0.05 1 2 1)
  208.             SF-TOGGLE     _"Not Pressed" TRUE
  209.             SF-TOGGLE     _"Not Pressed (Active)" TRUE
  210.             SF-TOGGLE     _"Pressed" TRUE)
  211.  
  212.  
  213.