]>
Commit | Line | Data |
---|---|---|
4744bd90 | 1 | ; CUPS Standard Button |
2 | ; Create a flat rounded button | |
3 | ||
4 | (define (script-fu-cups-standard-button text text-color button-height button-color bg-color) | |
5 | (let* ( | |
6 | (img (car (gimp-image-new 256 256 RGB))) | |
7 | (old-fg (car (gimp-palette-get-foreground))) | |
8 | (old-bg (car (gimp-palette-get-background))) | |
9 | (font-size (+ (/ (* 3 button-height) 5) 1)) | |
10 | (dummy (gimp-palette-set-foreground text-color)) | |
11 | (text-layer (car (gimp-text-fontname img -1 0 0 text 0 | |
12 | TRUE font-size PIXELS | |
13 | "Sans L,"))) | |
14 | (text-width (car (gimp-drawable-width text-layer))) | |
15 | (text-height (car (gimp-drawable-height text-layer))) | |
16 | (button-width (+ text-width button-height)) | |
17 | (bg-layer (car (gimp-layer-new img button-width button-height | |
18 | RGBA-IMAGE "Background" 100 | |
19 | NORMAL-MODE))) | |
20 | ) | |
21 | ||
22 | ; Disable undo while we do our work... | |
23 | (gimp-image-undo-disable img) | |
24 | ||
25 | ; Resize the image as needed... | |
26 | (gimp-image-resize img button-width button-height 0 0) | |
27 | (gimp-image-add-layer img bg-layer 1) | |
28 | (gimp-layer-set-preserve-trans text-layer TRUE) | |
29 | ||
30 | ; Clear the background... | |
31 | (gimp-selection-clear img) | |
32 | (gimp-palette-set-background bg-color) | |
33 | (gimp-edit-fill bg-layer 1) | |
34 | ||
35 | ; Make selections as needed for a rounded box. | |
36 | (gimp-rect-select img (* 0.5 button-height) 0 | |
37 | (- button-width button-height) button-height | |
38 | REPLACE 0 0) | |
39 | (gimp-ellipse-select img (- button-width button-height) 0 | |
40 | button-height button-height ADD 1 0 0) | |
41 | (gimp-ellipse-select img 0 0 button-height button-height ADD 1 0 0) | |
42 | ||
43 | ; Fill in the background... | |
44 | (gimp-palette-set-background button-color) | |
45 | (gimp-edit-fill bg-layer 1) | |
46 | ||
47 | ; Clear the border around the button image... | |
48 | (gimp-selection-invert img) | |
49 | (gimp-edit-clear bg-layer) | |
50 | (gimp-selection-clear img) | |
51 | ||
52 | ; Restore original colors... | |
53 | (gimp-palette-set-foreground old-fg) | |
54 | (gimp-palette-set-background old-bg) | |
55 | ||
56 | ; Translate the text later to center it... | |
57 | (gimp-layer-translate text-layer (* 0.5 button-height) | |
58 | (- (* 0.5 (- button-height text-height)) 1)) | |
59 | ||
60 | ; Then flatten the image... | |
61 | (gimp-image-merge-visible-layers img CLIP-TO-IMAGE) | |
62 | (gimp-convert-indexed img 0 0 16 0 1 "") | |
63 | (gimp-image-undo-enable img) | |
64 | (gimp-display-new img) | |
65 | ) | |
66 | ) | |
67 | ||
68 | (script-fu-register "script-fu-cups-standard-button" | |
69 | "<Toolbox>/Btns/CUPS Standard Button" | |
70 | "CUPS Standard Button" | |
71 | "Michael Sweet <mike@easysw.com>" | |
72 | "Michael Sweet <mike@easysw.com>" | |
73 | "2000" | |
74 | "" | |
75 | SF-VALUE "Text String" "\"Button\"" | |
76 | SF-COLOR "Text Color" '(255 255 255) | |
77 | SF-VALUE "Button Size (in pixels)" "20" | |
78 | SF-COLOR "Button Color" '(102 102 51) | |
79 | SF-COLOR "Background Color" '(212 212 164) | |
80 | ) |