1
; The GIMP -- an image manipulation program
2
; Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
; Round Button --- create a round beveled Web button.
5
; Copyright (C) 1998 Federico Mena Quintero & Arturo Espinosa Aldama
6
; federico@nuclecu.unam.mx arturo@nuclecu.unam.mx
7
; ************************************************************************
8
; Changed on Feb 4, 1999 by Piet van Oostrum <piet@cs.uu.nl>
9
; For use with GIMP 1.1.
10
; All calls to gimp-text-* have been converted to use the *-fontname form.
11
; The corresponding parameters have been replaced by an SF-FONT parameter.
12
; ************************************************************************
14
; This program is free software; you can redistribute it and/or modify
15
; it under the terms of the GNU General Public License as published by
16
; the Free Software Foundation; either version 2 of the License, or
17
; (at your option) any later version.
19
; This program is distributed in the hope that it will be useful,
20
; but WITHOUT ANY WARRANTY; without even the implied warranty of
21
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
; GNU General Public License for more details.
24
; You should have received a copy of the GNU General Public License
25
; along with this program; if not, write to the Free Software
26
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28
(define (text-width extents)
31
(define (text-height extents)
34
(define (text-ascent extents)
37
(define (text-descent extents)
38
(cadr (cddr extents)))
40
(define (round-select img
46
(let* ((diameter (* ratio height)))
47
(gimp-ellipse-select img x y diameter height CHANNEL-OP-ADD FALSE 0 0)
48
(gimp-ellipse-select img (+ x (- width diameter)) y
49
diameter height CHANNEL-OP-ADD FALSE 0 0)
50
(gimp-rect-select img (+ x (/ diameter 2)) y
51
(- width diameter) height CHANNEL-OP-ADD FALSE 0)))
53
(define (script-fu-round-button text
70
(cond ((eqv? notpressed TRUE)
71
(do-pupibutton text size font ul-color lr-color
72
text-color xpadding ypadding bevel ratio 0)))
73
(cond ((eqv? notpressed-active TRUE)
74
(do-pupibutton text size font ul-color-high lr-color-high
75
hlight-color xpadding ypadding bevel ratio 0)))
76
(cond ((eqv? pressed TRUE)
77
(do-pupibutton text size font ul-color-high lr-color-high
78
hlight-color xpadding ypadding bevel ratio 1))))
80
(define (do-pupibutton text
92
(let* ((text-extents (gimp-text-get-extents-fontname text
96
(ascent (text-ascent text-extents))
97
(descent (text-descent text-extents))
99
(height (+ (* 2 (+ ypadding bevel))
102
(radius (/ (* ratio height) 4))
104
(width (+ (* 2 (+ radius xpadding))
106
(text-width text-extents)))
108
(img (car (gimp-image-new width height RGB)))
110
(bumpmap (car (gimp-layer-new img width height
111
RGBA-IMAGE "Bumpmap" 100 NORMAL-MODE)))
112
(gradient (car (gimp-layer-new img width height
113
RGBA-IMAGE "Button" 100 NORMAL-MODE))))
117
(gimp-image-undo-disable img)
119
; Create bumpmap layer
121
(gimp-image-add-layer img bumpmap -1)
122
(gimp-selection-none img)
123
(gimp-context-set-background '(0 0 0))
124
(gimp-edit-fill bumpmap BACKGROUND-FILL)
126
(round-select img (/ bevel 2) (/ bevel 2)
127
(- width bevel) (- height bevel) ratio)
128
(gimp-context-set-background '(255 255 255))
129
(gimp-edit-fill bumpmap BACKGROUND-FILL)
131
(gimp-selection-none img)
132
(plug-in-gauss-rle 1 img bumpmap bevel 1 1)
134
; Create gradient layer
136
(gimp-image-add-layer img gradient -1)
137
(gimp-edit-clear gradient)
138
(round-select img 0 0 width height ratio)
139
(gimp-context-set-foreground ul-color)
140
(gimp-context-set-background lr-color)
142
(gimp-edit-blend gradient FG-BG-RGB-MODE NORMAL-MODE
143
GRADIENT-LINEAR 100 0 REPEAT-NONE FALSE
147
(gimp-selection-none img)
149
(plug-in-bump-map 1 img gradient bumpmap
150
135 45 bevel 0 0 0 0 TRUE pressed 0)
154
(cond ((eqv? pressed 1) (set! bevel (+ bevel 1))))
156
(gimp-context-set-foreground text-color)
157
(let ((textl (car (gimp-text-fontname
158
img -1 0 0 text 0 TRUE size PIXELS
160
(gimp-layer-set-offsets textl
161
(+ xpadding radius bevel)
162
(+ ypadding descent bevel)))
164
; Delete some fucked-up pixels.
166
(gimp-selection-none img)
167
(round-select img 1 1 (- width 1) (- height 1) ratio)
168
(gimp-selection-invert img)
169
(gimp-edit-clear gradient)
173
(gimp-image-remove-layer img bumpmap)
174
(gimp-image-merge-visible-layers img EXPAND-AS-NECESSARY)
176
(gimp-selection-none img)
177
(gimp-image-undo-enable img)
178
(gimp-display-new img)
182
(script-fu-register "script-fu-round-button"
185
"Arturo Espinosa (stolen from quartic's beveled button)"
186
"Arturo Espinosa & Federico Mena Quintero"
189
SF-STRING _"Text" "The GIMP"
190
SF-ADJUSTMENT _"Font size (pixels)" '(16 2 100 1 1 0 1)
191
SF-FONT _"Font" "Sans"
192
SF-COLOR _"Upper color" '(192 192 0)
193
SF-COLOR _"Lower color" '(128 108 0)
194
SF-COLOR _"Text color" '(0 0 0)
195
SF-COLOR _"Upper color (active)" '(255 255 0)
196
SF-COLOR _"Lower color (active)" '(128 108 0)
197
SF-COLOR _"Text color (active)" '(0 0 192)
198
SF-ADJUSTMENT _"Padding X" '(4 0 100 1 10 0 1)
199
SF-ADJUSTMENT _"Padding Y" '(4 0 100 1 10 0 1)
200
SF-ADJUSTMENT _"Bevel width" '(2 0 100 1 10 0 1)
201
SF-ADJUSTMENT _"Round ratio" '(1 0.05 20 0.05 1 2 1)
202
SF-TOGGLE _"Not pressed" TRUE
203
SF-TOGGLE _"Not pressed (active)" TRUE
204
SF-TOGGLE _"Pressed" TRUE)
206
(script-fu-menu-register "script-fu-round-button"
207
_"<Toolbox>/Xtns/Script-Fu/Buttons")