112ac1d3 |
1 | ;; Common Lisp bindings for GTK+ v2.x |
2 | ;; Copyright 2004-2005 Espen S. Johnsen <espen@users.sf.net> |
43e8a182 |
3 | ;; |
112ac1d3 |
4 | ;; Permission is hereby granted, free of charge, to any person obtaining |
5 | ;; a copy of this software and associated documentation files (the |
6 | ;; "Software"), to deal in the Software without restriction, including |
7 | ;; without limitation the rights to use, copy, modify, merge, publish, |
8 | ;; distribute, sublicense, and/or sell copies of the Software, and to |
9 | ;; permit persons to whom the Software is furnished to do so, subject to |
10 | ;; the following conditions: |
43e8a182 |
11 | ;; |
112ac1d3 |
12 | ;; The above copyright notice and this permission notice shall be |
13 | ;; included in all copies or substantial portions of the Software. |
43e8a182 |
14 | ;; |
112ac1d3 |
15 | ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
16 | ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
17 | ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
18 | ;; IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
19 | ;; CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
20 | ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
21 | ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
22 | |
98d09247 |
23 | ;; $Id: pixbuf.lisp,v 1.8 2008-04-30 18:04:09 espen Exp $ |
43e8a182 |
24 | |
25 | |
26 | (in-package "GDK") |
27 | |
28 | (defbinding pixbuf-get-option () (copy-of string) |
29 | (pixbuf pixbuf) |
30 | (key string)) |
31 | |
98d09247 |
32 | (defbinding %pixbuf-new-from-file () (or null (referenced pixbuf)) |
43e8a182 |
33 | (filename pathname) |
73326d92 |
34 | (nil (or null gerror) :out)) |
43e8a182 |
35 | |
98d09247 |
36 | (defbinding %pixbuf-new-from-file-at-size () (or null (referenced pixbuf)) |
43e8a182 |
37 | (filename pathname) |
38 | (width int) |
39 | (height int) |
73326d92 |
40 | (nil (or null gerror) :out)) |
43e8a182 |
41 | |
90c5d56b |
42 | #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0") |
98d09247 |
43 | (defbinding %pixbuf-new-from-file-at-scale () (or null (referenced pixbuf)) |
43e8a182 |
44 | (filename pathname) |
45 | (width int) |
46 | (height int) |
47 | (preserve-aspect-ratio boolean) |
73326d92 |
48 | (nil (or null gerror) :out)) |
43e8a182 |
49 | |
50 | (defun pixbuf-load (filename &key width height size (preserve-aspect-ratio t)) |
90c5d56b |
51 | #?-(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0") |
43e8a182 |
52 | (unless preserve-aspect-ratio |
53 | (warn ":preserve-aspect-ratio not supported with this version of Gtk")) |
54 | |
ed794f57 |
55 | (multiple-value-bind (pixbuf gerror) |
56 | (cond |
57 | (size |
90c5d56b |
58 | #?-(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0") |
59 | (%pixbuf-new-from-file-at-size filename size size) |
60 | #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0") |
61 | (%pixbuf-new-from-file-at-scale filename size size preserve-aspect-ratio)) |
ed794f57 |
62 | ((and width height) |
90c5d56b |
63 | #?-(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0") |
64 | (%pixbuf-new-from-file-at-size filename width height) |
65 | #?(pkg-exists-p "gtk+-2.0" :atleast-version "2.6.0") |
66 | (%pixbuf-new-from-file-at-scale filename width height preserve-aspect-ratio)) |
ed794f57 |
67 | ((or width height) |
68 | (error "Both :width and :height must be specified")) |
69 | (t (%pixbuf-new-from-file filename))) |
70 | (if gerror |
71 | (signal-gerror gerror) |
72 | pixbuf))) |
43e8a182 |
73 | |
74 | |
75 | ;; (defbinding pixbuf-get-file-info () (copy-of pixbuf-format) |
76 | ;; (filename pathname) |
77 | ;; (width int :out) |
78 | ;; (height int :out)) |
79 | |
80 | (defbinding %pixbuf-savev () boolean |
81 | (pixbuf pixbuf) |
82 | (filename pathname) |
83 | (type string) |
ed794f57 |
84 | (keys strings) |
fd092148 |
85 | (values strings) |
73326d92 |
86 | (nil (or null gerror) :out)) |
43e8a182 |
87 | |
88 | (defun pixbuf-save (pixbuf filename type &rest options) |
89 | (let ((keys (make-array 0 :adjustable t :fill-pointer t)) |
90 | (values (make-array 0 :adjustable t :fill-pointer t))) |
91 | (loop |
92 | as (key value . rest) = options then rest |
fd092148 |
93 | while key |
43e8a182 |
94 | do (vector-push-extend (string-downcase key) keys) |
95 | (vector-push-extend |
96 | (etypecase value |
97 | (string value) |
98 | (symbol (string-downcase value)) |
99 | (number (format nil "~A" value))) |
100 | values)) |
ed794f57 |
101 | (multiple-value-bind (ok-p gerror) |
fd092148 |
102 | (%pixbuf-savev pixbuf filename (string-downcase type) keys values) |
ed794f57 |
103 | (unless ok-p |
104 | (signal-gerror gerror))))) |
43e8a182 |
105 | |
106 | (defbinding pixbuf-new-from-xpm-data () (referenced pixbuf) |
107 | (data (vector string))) |
108 | |
109 | (defbinding %pixbuf-new-subpixbuf () pixbuf ;; or (referenced pixbuf)? |
110 | (pixbuf pixbuf) |
111 | (x int) (y int) (width int) (height int)) |
112 | |
113 | (defbinding %pixbuf-copy () (referenced pixbuf) |
114 | (pixbuf pixbuf)) |
115 | |
116 | (defun copy-pixbuf (pixbuf &optional x y width height) |
117 | (if (and (not x) (not y) (not width) (not height)) |
118 | (%pixbuf-copy pixbuf) |
119 | (%pixbuf-new-subpixbuf pixbuf x y width height))) |
120 | |
73326d92 |
121 | (defbinding %pixbuf-get-from-drawable () (or null (referenced pixbuf)) |
c379590e |
122 | (dest (or null pixbuf)) |
123 | (drawable drawable) |
124 | (colormap (or null colormap)) |
125 | (src-x int) |
126 | (src-y int) |
127 | (dest-x int) |
128 | (dest-y int) |
129 | (width int) |
130 | (height int)) |
131 | |
132 | (defun pixbuf-get-from-drawable (drawable &key (src-x 0) (src-y 0) (dest-x 0) (dest-y 0) width height colormap dest) |
133 | (unless (or (and width height) (not (typep drawable 'window))) |
134 | (error "Width and height must be specified for windows")) |
135 | (or |
136 | (%pixbuf-get-from-drawable dest drawable |
137 | (cond |
138 | (colormap) |
139 | ((slot-boundp drawable 'colormap) nil) |
140 | ((colormap-get-system))) |
141 | src-x src-y dest-x dest-y (or width -1) (or height -1)) |
142 | (error "Couldn't get pixbuf from drawable"))) |
143 | |
43e8a182 |
144 | |
98d09247 |
145 | ;;; Pixbuf Loader |
146 | |
147 | (defbinding %pixbuf-loader-new-with-type () pointer |
148 | (type string) |
149 | (nil gerror-signal :out)) |
150 | |
151 | (defbinding %pixbuf-loader-new-with-mime-type () pointer |
152 | (mime-type string) |
153 | (nil gerror-signal :out)) |
154 | |
155 | (defmethod allocate-foreign ((loader pixbuf-loader) &key type mime-type) |
156 | (cond |
157 | ((and type mime-type) |
158 | (error "Only one of the keyword arguments :TYPE and :MIME-TYPE can be specified")) |
159 | (type (%pixbuf-loader-new-with-type type)) |
160 | (mime-type (%pixbuf-loader-new-with-mime-type mime-type)) |
161 | ((call-next-method)))) |
162 | |
163 | (defbinding pixbuf-loader-write (loader buffer &optional (length (length buffer))) boolean |
164 | (loader pixbuf-loader) |
165 | (buffer (unboxed-vector (unsigned-byte 8))) |
166 | (length integer) |
167 | (nil gerror-signal :out)) |
168 | |
169 | (defbinding pixbuf-loader-close () boolean |
170 | (loader pixbuf-loader) |
171 | (nil gerror-signal :out)) |
172 | |
173 | (defbinding pixbuf-loader-get-pixbuf () (or null pixbuf) |
174 | (loader pixbuf-loader)) |
175 | |
176 | (defbinding pixbuf-loader-get-animation () (or null pixbuf-animation) |
177 | (loader pixbuf-loader)) |
178 | |
179 | (defbinding pixbuf-loader-set-size () nil |
180 | (loader pixbuf-loader) |
181 | (width integer) |
182 | (height integer)) |
183 | |
184 | |
43e8a182 |
185 | ;;; Utilities |
186 | |
187 | (defbinding pixbuf-add-alpha |
188 | (pixbuf &optional substitute-color (red 255) (green 255) (blue 255)) |
189 | (referenced pixbuf) |
190 | (pixbuf pixbuf) |
191 | (substitute-color boolean) |
192 | (red (unsigned 8)) |
193 | (green (unsigned 8)) |
194 | (blue (unsigned 8))) |