~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/script-fu/scripts/test-sphere.scm

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
; This is a slightly modified copy of the sphere script to show and test
2
 
; the possibilities of the new Script-Fu API extensions.
 
1
; This is a a test script to show and test the possibilities of the
 
2
; Script-Fu parameter API.
3
3
;
4
4
; ----------------------------------------------------------------------
5
5
; SF-ADJUSTMENT
8
8
; In interactive mode it creates an adjustment widget in the dialog.
9
9
;
10
10
; Usage:
11
 
; SF-ADJUSTMENT "label" '(value, lower, upper, step_inc, page_inc, digits, type)
 
11
; SF-ADJUSTMENT "label" '(value lower upper step_inc page_inc digits type)
12
12
;
13
13
; type is one of: SF-SLIDER(0), SF-SPINNER(1)
 
14
;
 
15
; ----------------------------------------------------------------------
 
16
; SF-COLOR
 
17
; creates a color button in the dialog. It accepts either a list of three
 
18
; values for the red, green and blue components or a color name in CSS
 
19
; notatation
 
20
;
 
21
; Usage:
 
22
; SF-COLOR "label" '(red green blue)
 
23
; SF-COLOR "label" "color"
 
24
;
14
25
; ----------------------------------------------------------------------
15
26
; SF-FONT
16
27
; creates a font-selection widget in the dialog. It returns a fontname as
28
39
;
29
40
; Usage:
30
41
; SF-FONT "label" "fontname"
 
42
;
31
43
; ----------------------------------------------------------------------
32
44
; SF-BRUSH
33
45
; is only useful in interactive mode. It will create a widget in the control
41
53
; units as passed in as the default value.
42
54
;
43
55
; Usage:
44
 
; SF-BRUSH "Brush" '("Circle (03)" 1.0 44 0)
 
56
; SF-BRUSH "Brush" '("Circle (03)" 100 44 0)
45
57
;
46
58
; Here the brush dialog will be popped up with a default brush of Circle (03)
47
 
; opacity 1.0, spacing 44 and paint mode of Normal (value 0).
 
59
; opacity 100 spacing 44 and paint mode of Normal (value 0).
48
60
; If this selection was unchanged the value passed to the function as a
49
 
; paramater would be '("Circle (03)" 1.0 44 0). BTW the widget used
50
 
; is generally available in the libgimpui library for any plugin that
51
 
; wishes to select a brush.
 
61
; parameter would be '("Circle (03)" 100 44 0).
 
62
;
52
63
; ----------------------------------------------------------------------
53
64
; SF-PATTERN
54
65
; Only useful in interactive mode. It will create a widget in the control
62
73
; The value returned when the script is invoked is a string containing the
63
74
; pattern name. If the above selection was not altered the string would
64
75
; contain "Maple Leaves"
 
76
;
65
77
; ----------------------------------------------------------------------
66
78
; SF-GRADIENT
67
79
; Only useful in interactive mode. It will create a widget in the control
74
86
; The value returned when the script is invoked is a string containing the
75
87
; gradient name. If the above selection was not altered the string would
76
88
; contain "Deep Sea"
 
89
;
77
90
; ----------------------------------------------------------------------
78
91
; SF-PALETTE
79
92
; Only useful in interactive mode. It will create a widget in the control
86
99
; The value returned when the script is invoked is a string containing the
87
100
; palette name. If the above selection was not altered the string would
88
101
; contain "Named Colors"
 
102
;
89
103
; ----------------------------------------------------------------------
90
104
; SF-FILENAME
91
105
; Only useful in interactive mode. It will create a widget in the control
98
112
;
99
113
; The value returned when the script is invoked is a string containing the
100
114
; filename.
 
115
;
101
116
; ----------------------------------------------------------------------
102
117
; SF-DIRNAME
103
118
; Only useful in interactive mode. Very similar to SF-FILENAME, but the
108
123
;
109
124
; The value returned when the script is invoked is a string containing the
110
125
; dirname.
 
126
;
111
127
; ----------------------------------------------------------------------
112
128
; SF-OPTION
113
129
; Only useful in interactive mode. It will create a widget in the control
114
 
; dialog. The widget is an option_menu showing the options that are passed
 
130
; dialog. The widget is a combo-box showing the options that are passed
115
131
; as a list. The first option is the default choice.
116
132
;
117
133
; Usage:
118
134
; SF-OPTION "Orientation" '("Horizontal" "Vertical")
119
135
;
120
136
; The value returned when the script is invoked is the number of the
121
 
; choosen option, where the option first is counted as 0.
 
137
; chosen option, where the option first is counted as 0.
 
138
;
 
139
; ----------------------------------------------------------------------
 
140
; SF-ENUM
 
141
; Only useful in interactive mode. It will create a widget in the control
 
142
; dialog. The widget is a combo-box showing all enum values for the given
 
143
; enum type. This has to be the name of a registered enum, without the
 
144
; "Gimp" prefix. The second parameter speficies the default value, using
 
145
; the enum value's nick.
 
146
;
 
147
; Usage:
 
148
; SF-ENUM "Interpolation" '("InterpolationType" "linear")
 
149
;
 
150
; The value returned when the script is invoked corresponds to chosen
 
151
; enum value.
 
152
;
122
153
; ----------------------------------------------------------------------
123
154
 
124
155
 
125
156
(define (script-fu-test-sphere radius
126
 
                               light
127
 
                               shadow
128
 
                               bg-color
129
 
                               sphere-color
130
 
                               brush
131
 
                               text
132
 
                               multi-text
133
 
                               pattern
134
 
                               gradient
135
 
                               gradient-reverse
136
 
                               font
137
 
                               size
138
 
                               unused-palette
139
 
                               unused-filename
140
 
                               unused-orientation
141
 
                               unused-dirname
142
 
                               unused-image
143
 
                               unused-layer
144
 
                               unused-channel
145
 
                               unused-drawable)
146
 
  (let* ((width (* radius 3.75))
147
 
         (height (* radius 2.5))
148
 
         (img (car (gimp-image-new width height RGB)))
149
 
         (drawable (car (gimp-layer-new img width height RGB-IMAGE
150
 
                                        "Sphere Layer" 100 NORMAL-MODE)))
151
 
         (radians (/ (* light *pi*) 180))
152
 
         (cx (/ width 2))
153
 
         (cy (/ height 2))
154
 
         (light-x (+ cx (* radius (* 0.6 (cos radians)))))
155
 
         (light-y (- cy (* radius (* 0.6 (sin radians)))))
156
 
         (light-end-x (+ cx (* radius (cos (+ *pi* radians)))))
157
 
         (light-end-y (- cy (* radius (sin (+ *pi* radians)))))
158
 
         (offset (* radius 0.1))
159
 
         (text-extents (gimp-text-get-extents-fontname multi-text
160
 
                                                       size PIXELS
161
 
                                                       font))
162
 
         (x-position (- cx (/ (car text-extents) 2)))
163
 
         (y-position (- cy (/ (cadr text-extents) 2))))
 
157
                               light
 
158
                               shadow
 
159
                               bg-color
 
160
                               sphere-color
 
161
                               brush
 
162
                               text
 
163
                               multi-text
 
164
                               pattern
 
165
                               gradient
 
166
                               gradient-reverse
 
167
                               font
 
168
                               size
 
169
                               unused-palette
 
170
                               unused-filename
 
171
                               unused-orientation
 
172
                               unused-interpolation
 
173
                               unused-dirname
 
174
                               unused-image
 
175
                               unused-layer
 
176
                               unused-channel
 
177
                               unused-drawable)
 
178
  (let* (
 
179
        (width (* radius 3.75))
 
180
        (height (* radius 2.5))
 
181
        (img (car (gimp-image-new width height RGB)))
 
182
        (drawable (car (gimp-layer-new img width height RGB-IMAGE
 
183
                                       "Sphere Layer" 100 NORMAL-MODE)))
 
184
        (radians (/ (* light *pi*) 180))
 
185
        (cx (/ width 2))
 
186
        (cy (/ height 2))
 
187
        (light-x (+ cx (* radius (* 0.6 (cos radians)))))
 
188
        (light-y (- cy (* radius (* 0.6 (sin radians)))))
 
189
        (light-end-x (+ cx (* radius (cos (+ *pi* radians)))))
 
190
        (light-end-y (- cy (* radius (sin (+ *pi* radians)))))
 
191
        (offset (* radius 0.1))
 
192
        (text-extents (gimp-text-get-extents-fontname multi-text
 
193
                                                      size PIXELS
 
194
                                                      font))
 
195
        (x-position (- cx (/ (car text-extents) 2)))
 
196
        (y-position (- cy (/ (cadr text-extents) 2)))
 
197
        (shadow-w)
 
198
        (shadow-x)
 
199
        )
164
200
 
165
201
    (gimp-context-push)
166
202
 
172
208
    (gimp-context-set-background '(20 20 20))
173
209
 
174
210
    (if (and
175
 
         (or (and (>= light 45) (<= light 75))
176
 
             (and (<= light 135) (>= light 105)))
177
 
         (= shadow TRUE))
178
 
        (let ((shadow-w (* (* radius 2.5) (cos (+ *pi* radians))))
179
 
              (shadow-h (* radius 0.5))
180
 
              (shadow-x cx)
181
 
              (shadow-y (+ cy (* radius 0.65))))
182
 
          (if (< shadow-w 0)
183
 
              (prog1 (set! shadow-x (+ cx shadow-w))
184
 
                     (set! shadow-w (- shadow-w))))
 
211
         (or (and (>= light 45) (<= light 75))
 
212
             (and (<= light 135) (>= light 105)))
 
213
         (= shadow TRUE))
 
214
        (let ((shadow-w (* (* radius 2.5) (cos (+ *pi* radians))))
 
215
              (shadow-h (* radius 0.5))
 
216
              (shadow-x cx)
 
217
              (shadow-y (+ cy (* radius 0.65))))
 
218
          (if (< shadow-w 0)
 
219
              (begin (set! shadow-x (+ cx shadow-w))
 
220
                     (set! shadow-w (- shadow-w))))
185
221
 
186
 
          (gimp-ellipse-select img shadow-x shadow-y shadow-w shadow-h
187
 
                               CHANNEL-OP-REPLACE TRUE TRUE 7.5)
188
 
          (gimp-context-set-pattern pattern)
189
 
          (gimp-edit-bucket-fill drawable PATTERN-BUCKET-FILL MULTIPLY-MODE
190
 
                            100 0 FALSE 0 0)))
 
222
          (gimp-ellipse-select img shadow-x shadow-y shadow-w shadow-h
 
223
                               CHANNEL-OP-REPLACE TRUE TRUE 7.5)
 
224
          (gimp-context-set-pattern pattern)
 
225
          (gimp-edit-bucket-fill drawable PATTERN-BUCKET-FILL MULTIPLY-MODE
 
226
                            100 0 FALSE 0 0)))
191
227
 
192
228
    (gimp-ellipse-select img (- cx radius) (- cy radius)
193
 
                         (* 2 radius) (* 2 radius) CHANNEL-OP-REPLACE TRUE FALSE 0)
 
229
                         (* 2 radius) (* 2 radius) CHANNEL-OP-REPLACE TRUE FALSE 0)
194
230
 
195
231
    (gimp-edit-blend drawable FG-BG-RGB-MODE NORMAL-MODE
196
 
                     GRADIENT-RADIAL 100 offset REPEAT-NONE FALSE
197
 
                     FALSE 0 0 TRUE
198
 
                     light-x light-y light-end-x light-end-y)
 
232
                     GRADIENT-RADIAL 100 offset REPEAT-NONE FALSE
 
233
                     FALSE 0 0 TRUE
 
234
                     light-x light-y light-end-x light-end-y)
199
235
 
200
236
    (gimp-selection-none img)
201
237
 
203
239
    (gimp-ellipse-select img 10 10 50 50 CHANNEL-OP-REPLACE TRUE FALSE 0)
204
240
 
205
241
    (gimp-edit-blend drawable CUSTOM-MODE NORMAL-MODE
206
 
                     GRADIENT-LINEAR 100 offset REPEAT-NONE gradient-reverse
207
 
                     FALSE 0 0 TRUE
208
 
                     10 10 30 60)
 
242
                     GRADIENT-LINEAR 100 offset REPEAT-NONE gradient-reverse
 
243
                     FALSE 0 0 TRUE
 
244
                     10 10 30 60)
209
245
 
210
246
    (gimp-selection-none img)
211
247
 
212
248
    (gimp-context-set-foreground '(0 0 0))
213
249
    (gimp-floating-sel-anchor (car (gimp-text-fontname img drawable
214
 
                                                       x-position y-position
215
 
                                                       multi-text
216
 
                                                       0 TRUE
217
 
                                                       size PIXELS
218
 
                                                       font)))
 
250
                                                       x-position y-position
 
251
                                                       multi-text
 
252
                                                       0 TRUE
 
253
                                                       size PIXELS
 
254
                                                       font)))
219
255
 
220
256
    (gimp-image-undo-enable img)
221
257
    (gimp-display-new img)
222
258
 
223
 
    (gimp-context-pop)))
 
259
    (gimp-context-pop)
 
260
  )
 
261
)
224
262
 
225
263
(script-fu-register "script-fu-test-sphere"
226
 
                    "_Sphere..."
227
 
                    "Simple script to test and show the usage of the new Script-Fu API extensions."
228
 
                    "Spencer Kimball, Sven Neumann"
229
 
                    "Spencer Kimball"
230
 
                    "1996, 1998"
231
 
                    ""
232
 
                    SF-ADJUSTMENT "Radius (in pixels)" '(100 1 5000 1 10 0 1)
233
 
                    SF-ADJUSTMENT "Lighting (degrees)" '(45 0 360 1 10 1 0)
234
 
                    SF-TOGGLE     "Shadow"             TRUE
235
 
                    SF-COLOR      "Background color"   '(255 255 255)
236
 
                    SF-COLOR      "Sphere color"       '(255 0 0)
237
 
                    SF-BRUSH      "Brush"              '("Circle (03)" 1.0 44 0)
238
 
                    SF-STRING     "Text"               "Script-Fu rocks!"
239
 
                    SF-TEXT       "Multi-line text"    "Hello,\nWorld!"
240
 
                    SF-PATTERN    "Pattern"            "Maple Leaves"
241
 
                    SF-GRADIENT   "Gradient"           "Deep Sea"
242
 
                    SF-TOGGLE     "Gradient reverse"   FALSE
243
 
                    SF-FONT       "Font"               "Agate"
244
 
                    SF-ADJUSTMENT "Font size (pixels)" '(50 1 1000 1 10 0 1)
245
 
                    SF-PALETTE    "Palette"            "Default"
246
 
                    SF-FILENAME   "Environment map"
247
 
                                  (string-append ""
248
 
                                                 gimp-data-directory
249
 
                                                 "/scripts/images/beavis.jpg")
250
 
                    SF-OPTION     "Orientation"        '("Horizontal" "Vertical")
251
 
                    SF-DIRNAME    "Output directory"   "/var/tmp/"
252
 
                    SF-IMAGE      "Image"              -1
253
 
                    SF-LAYER      "Layer"              -1
254
 
                    SF-CHANNEL    "Channel"            -1
255
 
                    SF-DRAWABLE   "Drawable"           -1)
 
264
  _"_Sphere..."
 
265
  "Simple script to test and show the usage of the new Script-Fu API extensions."
 
266
  "Spencer Kimball, Sven Neumann"
 
267
  "Spencer Kimball"
 
268
  "1996, 1998"
 
269
  ""
 
270
  SF-ADJUSTMENT "Radius (in pixels)" (list 100 1 5000 1 10 0 SF-SPINNER)
 
271
  SF-ADJUSTMENT "Lighting (degrees)" (list 45 0 360 1 10 1 SF-SLIDER)
 
272
  SF-TOGGLE     "Shadow"             TRUE
 
273
  SF-COLOR      "Background color"   "white"
 
274
  SF-COLOR      "Sphere color"       "red"
 
275
  SF-BRUSH      "Brush"              '("Circle (03)" 1.0 44 0)
 
276
  SF-STRING     "Text"               "Tiny-Fu rocks!"
 
277
  SF-TEXT       "Multi-line text"    "Hello,\nWorld!"
 
278
  SF-PATTERN    "Pattern"            "Maple Leaves"
 
279
  SF-GRADIENT   "Gradient"           "Deep Sea"
 
280
  SF-TOGGLE     "Gradient reverse"   FALSE
 
281
  SF-FONT       "Font"               "Agate"
 
282
  SF-ADJUSTMENT "Font size (pixels)" '(50 1 1000 1 10 0 1)
 
283
  SF-PALETTE    "Palette"            "Default"
 
284
  SF-FILENAME   "Environment map"
 
285
                (string-append gimp-data-directory
 
286
                               "/scripts/images/beavis.jpg")
 
287
  SF-OPTION     "Orientation"        '("Horizontal"
 
288
                                       "Vertical")
 
289
  SF-ENUM       "Interpolation"      '("InterpolationType" "linear")
 
290
  SF-DIRNAME    "Output directory"   "/var/tmp/"
 
291
  SF-IMAGE      "Image"              -1
 
292
  SF-LAYER      "Layer"              -1
 
293
  SF-CHANNEL    "Channel"            -1
 
294
  SF-DRAWABLE   "Drawable"           -1
 
295
  SF-VECTORS    "Vectors"            -1
 
296
)
256
297
 
257
298
(script-fu-menu-register "script-fu-test-sphere"
258
 
                         "<Toolbox>/Xtns/Script-Fu/Test")
 
299
                         "<Toolbox>/Xtns/Languages/Script-Fu/Test")