~ubuntu-branches/ubuntu/maverick/gimp/maverick-updates

« back to all changes in this revision

Viewing changes to plug-ins/script-fu/scripts/pupi-button.scm

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-12-09 19:44:52 UTC
  • Revision ID: james.westby@ubuntu.com-20051209194452-yggpemjlofpjqyf4
Tags: upstream-2.2.9
ImportĀ upstreamĀ versionĀ 2.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
; The GIMP -- an image manipulation program
 
2
; Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 
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
; ************************************************************************
 
13
 
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.
 
18
 
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.
 
23
 
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.
 
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 (round-select img
 
41
                      x
 
42
                      y
 
43
                      width
 
44
                      height
 
45
                      ratio)
 
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)))
 
52
 
 
53
(define (script-fu-round-button text
 
54
                                size
 
55
                                font
 
56
                                ul-color
 
57
                                lr-color
 
58
                                text-color
 
59
                                ul-color-high
 
60
                                lr-color-high
 
61
                                hlight-color
 
62
                                xpadding
 
63
                                ypadding
 
64
                                bevel
 
65
                                ratio
 
66
                                notpressed
 
67
                                notpressed-active
 
68
                                pressed)
 
69
 
 
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))))
 
79
 
 
80
(define (do-pupibutton text
 
81
                       size
 
82
                       font
 
83
                       ul-color
 
84
                       lr-color
 
85
                       text-color
 
86
                       xpadding
 
87
                       ypadding
 
88
                       bevel
 
89
                       ratio
 
90
                       pressed)
 
91
 
 
92
  (let* ((text-extents (gimp-text-get-extents-fontname text
 
93
                                                       size
 
94
                                                       PIXELS
 
95
                                                       font))
 
96
         (ascent (text-ascent text-extents))
 
97
         (descent (text-descent text-extents))
 
98
 
 
99
         (height (+ (* 2 (+ ypadding bevel))
 
100
                        (+ ascent descent)))
 
101
 
 
102
         (radius (/ (* ratio height) 4))
 
103
 
 
104
         (width (+ (* 2 (+ radius xpadding))
 
105
                   bevel
 
106
                   (text-width text-extents)))
 
107
 
 
108
         (img (car (gimp-image-new width height RGB)))
 
109
 
 
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))))
 
114
 
 
115
    (gimp-context-push)
 
116
 
 
117
    (gimp-image-undo-disable img)
 
118
 
 
119
    ; Create bumpmap layer
 
120
    
 
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)
 
125
 
 
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)
 
130
 
 
131
    (gimp-selection-none img)
 
132
    (plug-in-gauss-rle 1 img bumpmap bevel 1 1)
 
133
 
 
134
    ; Create gradient layer
 
135
 
 
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)
 
141
 
 
142
    (gimp-edit-blend gradient FG-BG-RGB-MODE NORMAL-MODE
 
143
                     GRADIENT-LINEAR 100 0 REPEAT-NONE FALSE
 
144
                     FALSE 0 0 TRUE
 
145
                     0 0 0 (- height 1))
 
146
 
 
147
    (gimp-selection-none img)
 
148
 
 
149
    (plug-in-bump-map 1 img gradient bumpmap
 
150
                      135 45 bevel 0 0 0 0 TRUE pressed 0)
 
151
 
 
152
;     Create text layer
 
153
 
 
154
    (cond ((eqv? pressed 1) (set! bevel (+ bevel 1))))
 
155
 
 
156
    (gimp-context-set-foreground text-color)
 
157
    (let ((textl (car (gimp-text-fontname
 
158
                       img -1 0 0 text 0 TRUE size PIXELS
 
159
                       font))))
 
160
      (gimp-layer-set-offsets textl
 
161
                              (+ xpadding radius bevel)
 
162
                              (+ ypadding descent bevel)))
 
163
 
 
164
;   Delete some fucked-up pixels.
 
165
 
 
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)
 
170
 
 
171
;     Done
 
172
 
 
173
    (gimp-image-remove-layer img bumpmap)
 
174
    (gimp-image-merge-visible-layers img EXPAND-AS-NECESSARY)
 
175
 
 
176
    (gimp-selection-none img)
 
177
    (gimp-image-undo-enable img)
 
178
    (gimp-display-new img)
 
179
 
 
180
    (gimp-context-pop)))
 
181
 
 
182
(script-fu-register "script-fu-round-button"
 
183
                    _"_Round Button..."
 
184
                    "Round button"
 
185
                    "Arturo Espinosa (stolen from quartic's beveled button)"
 
186
                    "Arturo Espinosa & Federico Mena Quintero"
 
187
                    "June 1998"
 
188
                    ""
 
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)
 
205
 
 
206
(script-fu-menu-register "script-fu-round-button"
 
207
                         _"<Toolbox>/Xtns/Script-Fu/Buttons")