root/plgtkimageview/DrawCache.xs

Revision 531, 6.2 kB (checked in by jeffrey, 9 months ago)

fixed some documentation issues

Line 
1 #include "gtkimageviewperl.h"
2
3 GType
4 gdk_pixbuf_draw_opts_get_type(void) {
5     static GType t = 0;
6     if (!t) {
7         t = g_boxed_type_register_static("GdkPixbufDrawOpts",
8                                          (GBoxedCopyFunc) g_boxed_copy,
9                                          (GBoxedFreeFunc) g_boxed_free);
10     }
11     return t;
12 }
13
14 /*
15 struct _GdkPixbufDrawOpts {
16     gdouble        zoom;
17     GdkRectangle   zoom_rect;
18     int            widget_x;
19     int            widget_y;       
20     GdkInterpType  interp;
21     GdkPixbuf     *pixbuf;
22     int            check_color1;
23     int            check_color2;
24 };
25 */
26
27 SV *
28 newSVGdkPixbufDrawOpts (GdkPixbufDrawOpts * opts)
29 {
30   HV * hv = newHV();
31   hv_store (hv, "zoom", 4, newSVnv (opts->zoom), 0);
32   hv_store (hv, "zoom_rect", 9, newSVGdkRectangle (&opts->zoom_rect), 0);
33   hv_store (hv, "widget_x", 8, newSViv (opts->widget_x), 0);
34   hv_store (hv, "widget_y", 8, newSViv (opts->widget_y), 0);
35   hv_store (hv, "interp", 6, newSVGdkInterpType (opts->interp), 0);
36   hv_store (hv, "pixbuf", 6, newSVGdkPixbuf (opts->pixbuf), 0);
37   hv_store (hv, "check_color1", 12, newSViv (opts->check_color1), 0);
38   hv_store (hv, "check_color2", 12, newSViv (opts->check_color2), 0);
39   return newRV_noinc ((SV *) hv);
40 }
41
42 /*
43  * returns a pointer to a GdkPixbufDrawOpts you can use until control returns
44  * to perl.
45  */
46 GdkPixbufDrawOpts *
47 SvGdkPixbufDrawOpts (SV * sv)
48 {
49   HV * hv;
50   SV ** svp;
51   GdkPixbufDrawOpts * opts;
52
53 /* Make sure it is what we think it is before we try to
54    dereference and parse it */
55   if (! gperl_sv_is_hash_ref (sv))
56           croak ("Expected a hash reference for Gtk2::Gdk::Pixbuf::Draw::Opts");
57
58   hv = (HV*) SvRV (sv);
59
60   opts = gperl_alloc_temp (sizeof (GdkPixbufDrawOpts));
61
62   svp = hv_fetch (hv, "zoom", 4, FALSE);
63   if (svp) opts->zoom = SvNV (*svp);
64
65   svp = hv_fetch (hv, "zoom_rect", 9, FALSE);
66   if (svp) opts->zoom_rect = * (GdkRectangle *) SvGdkRectangle (*svp);
67
68   svp = hv_fetch (hv, "widget_x", 8, FALSE);
69   if (svp) opts->widget_x = SvIV (*svp);
70
71   svp = hv_fetch (hv, "widget_y", 8, FALSE);
72   if (svp) opts->widget_y = SvIV (*svp);
73
74   svp = hv_fetch (hv, "interp", 6, FALSE);
75   if (svp) opts->interp = SvGdkInterpType (*svp);
76
77   svp = hv_fetch (hv, "pixbuf", 6, FALSE);
78   if (svp) opts->pixbuf = (GdkPixbuf *) SvGdkPixbuf (*svp);
79
80   svp = hv_fetch (hv, "check_color1", 12, FALSE);
81   if (svp) opts->check_color1 = SvIV (*svp);
82
83   svp = hv_fetch (hv, "check_color2", 12, FALSE);
84   if (svp) opts->check_color2 = SvIV (*svp);
85
86   return opts;
87 }
88
89 GType
90 gdk_pixbuf_draw_cache_get_type(void) {
91     static GType t = 0;
92     if (!t) {
93         t = g_boxed_type_register_static("GdkPixbufDrawCache",
94                                          (GBoxedCopyFunc) g_boxed_copy,
95                                          (GBoxedFreeFunc) g_boxed_free);
96     }
97     return t;
98 }
99
100 /*
101 struct _GdkPixbufDrawCache
102 {
103     GdkPixbuf         *last_pixbuf;
104     GdkPixbufDrawOpts  old;
105     int                check_size;
106 };
107 */
108
109 static SV *
110 newSVGdkPixbufDrawCache (GdkPixbufDrawCache * cache)
111 {
112   HV * hv = newHV();
113   hv_store (hv, "last_pixbuf", 11, newSVGdkPixbuf (cache->last_pixbuf), 0);
114   hv_store (hv, "old", 3, newSVGdkPixbufDrawOpts (&cache->old), 0);
115   hv_store (hv, "check_size", 10, newSViv (cache->check_size), 0);
116   return newRV_noinc ((SV *) hv);
117 }
118
119 /*
120  * returns a pointer to a GdkPixbufDrawCache you can use until control returns
121  * to perl.
122  */
123 static GdkPixbufDrawCache *
124 SvGdkPixbufDrawCache (SV * sv)
125 {
126   HV * hv;
127   SV ** svp;
128   GdkPixbufDrawCache * cache;
129
130 /* Make sure it is what we think it is before we try to
131    dereference and parse it */
132   if (! gperl_sv_is_hash_ref (sv))
133           croak ("Expected a hash reference for Gtk2::Gdk::Pixbuf::Draw::Cache");
134
135   hv = (HV*) SvRV (sv);
136
137   cache = gperl_alloc_temp (sizeof (GdkPixbufDrawCache));
138
139   svp = hv_fetch (hv, "last_pixbuf", 11, FALSE);
140   if (svp) cache->last_pixbuf = (GdkPixbuf *) SvGdkPixbuf (*svp);
141
142   svp = hv_fetch (hv, "old", 3, FALSE);
143   if (svp) cache->old = * (GdkPixbufDrawOpts *) SvGdkPixbufDrawOpts (*svp);
144
145   svp = hv_fetch (hv, "check_size", 10, FALSE);
146   if (svp) cache->check_size = SvIV (*svp);
147
148   return cache;
149 }
150
151
152
153 MODULE = Gtk2::Gdk::Pixbuf::Draw::Cache  PACKAGE = Gtk2::Gdk::Pixbuf::Draw::Cache  PREFIX = gdk_pixbuf_draw_cache_
154
155 =for object Gtk2::Gdk::Pixbuf::Draw::Cache Cache for drawing scaled pixbufs
156 =cut
157
158 =for position DESCRIPTION
159
160 =head1 DESCRIPTION
161
162 Gtk2::Gdk::Pixbuf::Draw::Cache provides a cache that should be used by the
163 Gtk2::ImageView::Tool when redrawing the Gtk2::ImageView.
164
165 =cut
166
167 =for apidoc
168
169 Creates a new pixbuf draw cache.
170
171 =head3 Returns
172
173 =over
174
175 =item a new Gtk2::Gdk::Pixbuf::Draw::Cache
176
177 =back
178
179 =cut
180 GdkPixbufDrawCache *
181 gdk_pixbuf_draw_cache_new (class)
182         C_ARGS:
183                 /*void*/
184
185
186 =for apidoc
187
188 Deallocates a pixbuf draw cache and all its data.
189
190 =cut
191 void
192 gdk_pixbuf_draw_cache_free (cache)
193         GdkPixbufDrawCache *    cache
194
195
196 =for apidoc
197
198 Force the pixbuf draw cache to scale the pixbuf at the next draw.
199
200 Gtk2::Gdk::Pixbuf::Draw::Cache tries to minimize the number of scale operations needed by caching the last drawn pixbuf. It would be inefficient to check the individual pixels inside the pixbuf so it assumes that if the memory address of the pixbuf has not changed, then the cache is good to use.
201
202 However, when the image data is modified, this assumtion breaks, which is why this method must be used to tell draw cache about it.
203
204 =cut
205 void
206 gdk_pixbuf_draw_cache_invalidate (cache)
207         GdkPixbufDrawCache *    cache
208
209
210 =for apidoc
211
212 Redraws the area specified in the pixbuf draw options in an efficient way by using caching.
213
214 =over
215
216 =item cache : a GdkPixbufDrawCache
217
218 =item opts : the Gtk2::Gdk::Pixbuf::Draw::Opts to use in this draw
219
220 =item drawable : a GdkDrawable to draw on
221
222 =back
223
224 =cut
225 void
226 gdk_pixbuf_draw_cache_draw (cache, opts, drawable)
227         GdkPixbufDrawCache *    cache
228         GdkPixbufDrawOpts *     opts
229         GdkDrawable *           drawable
230
231
232 =for apidoc
233
234 Gets the fastest method to draw the specified draw options. old is assumed to be the last PixbufDrawOpts used and new is the one to use this time.
235
236 =over
237
238 =item old : the last draw options used
239
240 =item new : the current draw options
241
242 =back
243
244 =head3 Returns
245
246 =over
247
248 =item the best draw method to use to draw
249
250 =back
251
252 =cut
253 GdkPixbufDrawMethod
254 gdk_pixbuf_draw_cache_get_method (class, old, new)
255                 GdkPixbufDrawOpts *     old
256                 GdkPixbufDrawOpts *     new
257         C_ARGS:
258                 old, new
Note: See TracBrowser for help on using the browser.