1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = gdk-pixbuf-Animations.html
27  * outPack = gdkpixbuf
28  * outFile = PixbufAnimation
29  * strct   = GdkPixbufAnimation
30  * realStrct=
31  * ctorStrct=
32  * clss    = PixbufAnimation
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gdk_pixbuf_animation_
41  * omit structs:
42  * omit prefixes:
43  * 	- gdk_pixbuf_animation_iter_
44  * 	- gdk_pixbuf_simple_anim_
45  * omit code:
46  * 	- gdk_pixbuf_animation_ref
47  * 	- gdk_pixbuf_animation_unref
48  * 	- gdk_pixbuf_animation_new_from_resource
49  * omit signals:
50  * imports:
51  * 	- glib.ErrorG
52  * 	- glib.GException
53  * 	- gdkpixbuf.PixbufAnimationIter
54  * 	- gdk.Pixbuf
55  * 	- glib.Str
56  * 	- gio.InputStream
57  * 	- gio.Cancellable
58  * 	- gio.AsyncResultIF
59  * structWrap:
60  * 	- GAsyncResult* -> AsyncResultIF
61  * 	- GCancellable* -> Cancellable
62  * 	- GInputStream* -> InputStream
63  * 	- GdkPixbuf* -> Pixbuf
64  * 	- GdkPixbufAnimation* -> PixbufAnimation
65  * 	- GdkPixbufAnimationIter* -> PixbufAnimationIter
66  * module aliases:
67  * local aliases:
68  * overrides:
69  */
70 
71 module gdkpixbuf.PixbufAnimation;
72 
73 public  import gtkc.gdkpixbuftypes;
74 
75 private import gtkc.gdkpixbuf;
76 private import glib.ConstructionException;
77 private import gobject.ObjectG;
78 
79 private import glib.ErrorG;
80 private import glib.GException;
81 private import gdkpixbuf.PixbufAnimationIter;
82 private import gdk.Pixbuf;
83 private import glib.Str;
84 private import gio.InputStream;
85 private import gio.Cancellable;
86 private import gio.AsyncResultIF;
87 
88 
89 private import gobject.ObjectG;
90 
91 /**
92  * The GdkPixBuf library provides a simple mechanism to load and
93  * represent animations. An animation is conceptually a series of
94  * frames to be displayed over time. The animation may not be
95  * represented as a series of frames internally; for example, it may
96  * be stored as a sprite and instructions for moving the sprite around
97  * a background. To display an animation you don't need to understand
98  * its representation, however; you just ask GdkPixBuf what should
99  * be displayed at a given point in time.
100  */
101 public class PixbufAnimation : ObjectG
102 {
103 	
104 	/** the main Gtk struct */
105 	protected GdkPixbufAnimation* gdkPixbufAnimation;
106 	
107 	
108 	/** Get the main Gtk struct */
109 	public GdkPixbufAnimation* getPixbufAnimationStruct()
110 	{
111 		return gdkPixbufAnimation;
112 	}
113 	
114 	
115 	/** the main Gtk struct as a void* */
116 	protected override void* getStruct()
117 	{
118 		return cast(void*)gdkPixbufAnimation;
119 	}
120 	
121 	/**
122 	 * Sets our main struct and passes it to the parent class
123 	 */
124 	public this (GdkPixbufAnimation* gdkPixbufAnimation)
125 	{
126 		super(cast(GObject*)gdkPixbufAnimation);
127 		this.gdkPixbufAnimation = gdkPixbufAnimation;
128 	}
129 	
130 	protected override void setStruct(GObject* obj)
131 	{
132 		super.setStruct(obj);
133 		gdkPixbufAnimation = cast(GdkPixbufAnimation*)obj;
134 	}
135 	
136 	/**
137 	 * Creates a new pixbuf animation by loading an image from an resource.
138 	 * The file format is detected automatically. If NULL is returned, then
139 	 * error will be set.
140 	 * Since 2.28
141 	 * Params:
142 	 * resourcePath = the path of the resource file
143 	 * Throws: GException on failure.
144 	 * Throws: ConstructionException GTK+ fails to create the object.
145 	 */
146 	public static PixbufAnimation newFromResource(string resourcePath)
147 	{
148 		// GdkPixbufAnimation * gdk_pixbuf_animation_new_from_resource  (const char *resource_path,  GError **error);
149 		GError* err = null;
150 		
151 		auto p = gdk_pixbuf_animation_new_from_resource(Str.toStringz(resourcePath), &err);
152 		
153 		if (err !is null)
154 		{
155 			throw new GException( new ErrorG(err) );
156 		}
157 		
158 		if(p is null)
159 		{
160 			throw new ConstructionException("null returned by gdk_pixbuf_animation_new_from_resource(Str.toStringz(resourcePath), &err)");
161 		}
162 		
163 		return new PixbufAnimation(cast(GdkPixbufAnimation*) p);
164 	}
165 	
166 	/**
167 	 */
168 	
169 	/**
170 	 * Creates a new animation by loading it from a file. The file format is
171 	 * detected automatically. If the file's format does not support multi-frame
172 	 * images, then an animation with a single frame will be created. Possible errors
173 	 * are in the GDK_PIXBUF_ERROR and G_FILE_ERROR domains.
174 	 * Params:
175 	 * filename = Name of file to load, in the GLib file name encoding
176 	 * Throws: GException on failure.
177 	 * Throws: ConstructionException GTK+ fails to create the object.
178 	 */
179 	public this (string filename)
180 	{
181 		// GdkPixbufAnimation * gdk_pixbuf_animation_new_from_file (const char *filename,  GError **error);
182 		GError* err = null;
183 		
184 		auto p = gdk_pixbuf_animation_new_from_file(Str.toStringz(filename), &err);
185 		
186 		if (err !is null)
187 		{
188 			throw new GException( new ErrorG(err) );
189 		}
190 		
191 		if(p is null)
192 		{
193 			throw new ConstructionException("null returned by gdk_pixbuf_animation_new_from_file(Str.toStringz(filename), &err)");
194 		}
195 		this(cast(GdkPixbufAnimation*) p);
196 	}
197 	
198 	/**
199 	 * Creates a new animation by loading it from an input stream.
200 	 * The file format is detected automatically. If NULL is returned, then
201 	 * error will be set. The cancellable can be used to abort the operation
202 	 * from another thread. If the operation was cancelled, the error
203 	 * G_IO_ERROR_CANCELLED will be returned. Other possible errors are in
204 	 * the GDK_PIXBUF_ERROR and G_IO_ERROR domains.
205 	 * The stream is not closed.
206 	 * Since 2.28
207 	 * Params:
208 	 * stream = a GInputStream to load the pixbuf from
209 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
210 	 * Throws: GException on failure.
211 	 * Throws: ConstructionException GTK+ fails to create the object.
212 	 */
213 	public this (InputStream stream, Cancellable cancellable)
214 	{
215 		// GdkPixbufAnimation * gdk_pixbuf_animation_new_from_stream  (GInputStream *stream,  GCancellable *cancellable,  GError **error);
216 		GError* err = null;
217 		
218 		auto p = gdk_pixbuf_animation_new_from_stream((stream is null) ? null : stream.getInputStreamStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
219 		
220 		if (err !is null)
221 		{
222 			throw new GException( new ErrorG(err) );
223 		}
224 		
225 		if(p is null)
226 		{
227 			throw new ConstructionException("null returned by gdk_pixbuf_animation_new_from_stream((stream is null) ? null : stream.getInputStreamStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err)");
228 		}
229 		this(cast(GdkPixbufAnimation*) p);
230 	}
231 	
232 	/**
233 	 * Creates a new animation by asynchronously loading an image from an input stream.
234 	 * For more details see gdk_pixbuf_new_from_stream(), which is the synchronous
235 	 * version of this function.
236 	 * When the operation is finished, callback will be called in the main thread.
237 	 * You can then call gdk_pixbuf_animation_new_from_stream_finish() to get the
238 	 * result of the operation.
239 	 * Since 2.28
240 	 * Params:
241 	 * stream = a GInputStream from which to load the animation
242 	 * cancellable = optional GCancellable object, NULL to ignore. [allow-none]
243 	 * callback = a GAsyncReadyCallback to call when the the pixbuf is loaded
244 	 * userData = the data to pass to the callback function
245 	 */
246 	public static void newFromStreamAsync(InputStream stream, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
247 	{
248 		// void gdk_pixbuf_animation_new_from_stream_async  (GInputStream *stream,  GCancellable *cancellable,  GAsyncReadyCallback callback,  gpointer user_data);
249 		gdk_pixbuf_animation_new_from_stream_async((stream is null) ? null : stream.getInputStreamStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
250 	}
251 	
252 	/**
253 	 * Finishes an asynchronous pixbuf animation creation operation started with
254 	 * gdk_pixbuf_animation_new_from_stream_async().
255 	 * Since 2.28
256 	 * Params:
257 	 * asyncResult = a GAsyncResult
258 	 * Throws: GException on failure.
259 	 * Throws: ConstructionException GTK+ fails to create the object.
260 	 */
261 	public this (AsyncResultIF asyncResult)
262 	{
263 		// GdkPixbufAnimation * gdk_pixbuf_animation_new_from_stream_finish  (GAsyncResult *async_result,  GError **error);
264 		GError* err = null;
265 		
266 		auto p = gdk_pixbuf_animation_new_from_stream_finish((asyncResult is null) ? null : asyncResult.getAsyncResultTStruct(), &err);
267 		
268 		if (err !is null)
269 		{
270 			throw new GException( new ErrorG(err) );
271 		}
272 		
273 		if(p is null)
274 		{
275 			throw new ConstructionException("null returned by gdk_pixbuf_animation_new_from_stream_finish((asyncResult is null) ? null : asyncResult.getAsyncResultTStruct(), &err)");
276 		}
277 		this(cast(GdkPixbufAnimation*) p);
278 	}
279 	
280 	/**
281 	 * Queries the width of the bounding box of a pixbuf animation.
282 	 * Returns: Width of the bounding box of the animation.
283 	 */
284 	public int getWidth()
285 	{
286 		// int gdk_pixbuf_animation_get_width (GdkPixbufAnimation *animation);
287 		return gdk_pixbuf_animation_get_width(gdkPixbufAnimation);
288 	}
289 	
290 	/**
291 	 * Queries the height of the bounding box of a pixbuf animation.
292 	 * Returns: Height of the bounding box of the animation.
293 	 */
294 	public int getHeight()
295 	{
296 		// int gdk_pixbuf_animation_get_height (GdkPixbufAnimation *animation);
297 		return gdk_pixbuf_animation_get_height(gdkPixbufAnimation);
298 	}
299 	
300 	/**
301 	 * Get an iterator for displaying an animation. The iterator provides
302 	 * the frames that should be displayed at a given time.
303 	 * It should be freed after use with g_object_unref().
304 	 * start_time would normally come from g_get_current_time(), and
305 	 * marks the beginning of animation playback. After creating an
306 	 * iterator, you should immediately display the pixbuf returned by
307 	 * gdk_pixbuf_animation_iter_get_pixbuf(). Then, you should install a
308 	 * timeout (with g_timeout_add()) or by some other mechanism ensure
309 	 * that you'll update the image after
310 	 * gdk_pixbuf_animation_iter_get_delay_time() milliseconds. Each time
311 	 * the image is updated, you should reinstall the timeout with the new,
312 	 * possibly-changed delay time.
313 	 * As a shortcut, if start_time is NULL, the result of
314 	 * g_get_current_time() will be used automatically.
315 	 * To update the image (i.e. possibly change the result of
316 	 * gdk_pixbuf_animation_iter_get_pixbuf() to a new frame of the animation),
317 	 * call gdk_pixbuf_animation_iter_advance().
318 	 * If you're using GdkPixbufLoader, in addition to updating the image
319 	 * after the delay time, you should also update it whenever you
320 	 * receive the area_updated signal and
321 	 * gdk_pixbuf_animation_iter_on_currently_loading_frame() returns
322 	 * TRUE. In this case, the frame currently being fed into the loader
323 	 * has received new data, so needs to be refreshed. The delay time for
324 	 * a frame may also be modified after an area_updated signal, for
325 	 * example if the delay time for a frame is encoded in the data after
326 	 * the frame itself. So your timeout should be reinstalled after any
327 	 * area_updated signal.
328 	 * A delay time of -1 is possible, indicating "infinite."
329 	 * Params:
330 	 * startTime = time when the animation starts playing. [allow-none]
331 	 * Returns: an iterator to move over the animation. [transfer full]
332 	 */
333 	public PixbufAnimationIter getIter(ref GTimeVal startTime)
334 	{
335 		// GdkPixbufAnimationIter * gdk_pixbuf_animation_get_iter (GdkPixbufAnimation *animation,  const GTimeVal *start_time);
336 		auto p = gdk_pixbuf_animation_get_iter(gdkPixbufAnimation, &startTime);
337 		
338 		if(p is null)
339 		{
340 			return null;
341 		}
342 		
343 		return ObjectG.getDObject!(PixbufAnimationIter)(cast(GdkPixbufAnimationIter*) p);
344 	}
345 	
346 	/**
347 	 * If you load a file with gdk_pixbuf_animation_new_from_file() and it turns
348 	 * out to be a plain, unanimated image, then this function will return
349 	 * TRUE. Use gdk_pixbuf_animation_get_static_image() to retrieve
350 	 * the image.
351 	 * Returns: TRUE if the "animation" was really just an image
352 	 */
353 	public int isStaticImage()
354 	{
355 		// gboolean gdk_pixbuf_animation_is_static_image  (GdkPixbufAnimation *animation);
356 		return gdk_pixbuf_animation_is_static_image(gdkPixbufAnimation);
357 	}
358 	
359 	/**
360 	 * If an animation is really just a plain image (has only one frame),
361 	 * this function returns that image. If the animation is an animation,
362 	 * this function returns a reasonable thing to display as a static
363 	 * unanimated image, which might be the first frame, or something more
364 	 * sophisticated. If an animation hasn't loaded any frames yet, this
365 	 * function will return NULL.
366 	 * Returns: unanimated image representing the animation. [transfer none]
367 	 */
368 	public Pixbuf getStaticImage()
369 	{
370 		// GdkPixbuf * gdk_pixbuf_animation_get_static_image  (GdkPixbufAnimation *animation);
371 		auto p = gdk_pixbuf_animation_get_static_image(gdkPixbufAnimation);
372 		
373 		if(p is null)
374 		{
375 			return null;
376 		}
377 		
378 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p);
379 	}
380 }