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 module gdkpixbuf.PixbufAnimation;
26 
27 private import gdkpixbuf.Pixbuf;
28 private import gdkpixbuf.PixbufAnimationIter;
29 private import gdkpixbuf.c.functions;
30 public  import gdkpixbuf.c.types;
31 private import gio.AsyncResultIF;
32 private import gio.Cancellable;
33 private import gio.InputStream;
34 private import glib.ConstructionException;
35 private import glib.ErrorG;
36 private import glib.GException;
37 private import glib.Str;
38 private import glib.TimeVal;
39 private import gobject.ObjectG;
40 
41 
42 /**
43  * An opaque object representing an animation.
44  * 
45  * The GdkPixBuf library provides a simple mechanism to load and
46  * represent animations. An animation is conceptually a series of
47  * frames to be displayed over time.
48  * 
49  * The animation may not be represented as a series of frames
50  * internally; for example, it may be stored as a sprite and
51  * instructions for moving the sprite around a background.
52  * 
53  * To display an animation you don't need to understand its
54  * representation, however; you just ask `GdkPixbuf` what should
55  * be displayed at a given point in time.
56  */
57 public class PixbufAnimation : ObjectG
58 {
59 	/** the main Gtk struct */
60 	protected GdkPixbufAnimation* gdkPixbufAnimation;
61 
62 	/** Get the main Gtk struct */
63 	public GdkPixbufAnimation* getPixbufAnimationStruct(bool transferOwnership = false)
64 	{
65 		if (transferOwnership)
66 			ownedRef = false;
67 		return gdkPixbufAnimation;
68 	}
69 
70 	/** the main Gtk struct as a void* */
71 	protected override void* getStruct()
72 	{
73 		return cast(void*)gdkPixbufAnimation;
74 	}
75 
76 	/**
77 	 * Sets our main struct and passes it to the parent class.
78 	 */
79 	public this (GdkPixbufAnimation* gdkPixbufAnimation, bool ownedRef = false)
80 	{
81 		this.gdkPixbufAnimation = gdkPixbufAnimation;
82 		super(cast(GObject*)gdkPixbufAnimation, ownedRef);
83 	}
84 
85 
86 	/** */
87 	public static GType getType()
88 	{
89 		return gdk_pixbuf_animation_get_type();
90 	}
91 
92 	/**
93 	 * Creates a new animation by loading it from a file.
94 	 *
95 	 * The file format is detected automatically.
96 	 *
97 	 * If the file's format does not support multi-frame images, then an animation
98 	 * with a single frame will be created.
99 	 *
100 	 * Possible errors are in the `GDK_PIXBUF_ERROR` and `G_FILE_ERROR` domains.
101 	 *
102 	 * Params:
103 	 *     filename = Name of file to load, in the GLib file
104 	 *         name encoding
105 	 *
106 	 * Returns: A newly-created animation
107 	 *
108 	 * Throws: GException on failure.
109 	 * Throws: ConstructionException GTK+ fails to create the object.
110 	 */
111 	public this(string filename)
112 	{
113 		GError* err = null;
114 
115 		auto __p = gdk_pixbuf_animation_new_from_file(Str.toStringz(filename), &err);
116 
117 		if (err !is null)
118 		{
119 			throw new GException( new ErrorG(err) );
120 		}
121 
122 		if(__p is null)
123 		{
124 			throw new ConstructionException("null returned by new_from_file");
125 		}
126 
127 		this(cast(GdkPixbufAnimation*) __p, true);
128 	}
129 
130 	/**
131 	 * Creates a new animation by loading it from an input stream.
132 	 *
133 	 * The file format is detected automatically.
134 	 *
135 	 * If `NULL` is returned, then @error will be set.
136 	 *
137 	 * The @cancellable can be used to abort the operation from another thread.
138 	 * If the operation was cancelled, the error `G_IO_ERROR_CANCELLED` will be
139 	 * returned. Other possible errors are in the `GDK_PIXBUF_ERROR` and
140 	 * `G_IO_ERROR` domains.
141 	 *
142 	 * The stream is not closed.
143 	 *
144 	 * Params:
145 	 *     stream = a `GInputStream` to load the pixbuf from
146 	 *     cancellable = optional `GCancellable` object
147 	 *
148 	 * Returns: A newly-created animation
149 	 *
150 	 * Since: 2.28
151 	 *
152 	 * Throws: GException on failure.
153 	 * Throws: ConstructionException GTK+ fails to create the object.
154 	 */
155 	public this(InputStream stream, Cancellable cancellable)
156 	{
157 		GError* err = null;
158 
159 		auto __p = gdk_pixbuf_animation_new_from_stream((stream is null) ? null : stream.getInputStreamStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err);
160 
161 		if (err !is null)
162 		{
163 			throw new GException( new ErrorG(err) );
164 		}
165 
166 		if(__p is null)
167 		{
168 			throw new ConstructionException("null returned by new_from_stream");
169 		}
170 
171 		this(cast(GdkPixbufAnimation*) __p, true);
172 	}
173 
174 	/**
175 	 * Finishes an asynchronous pixbuf animation creation operation started with
176 	 * [func@GdkPixbuf.PixbufAnimation.new_from_stream_async].
177 	 *
178 	 * Params:
179 	 *     asyncResult = a #GAsyncResult
180 	 *
181 	 * Returns: the newly created animation
182 	 *
183 	 * Since: 2.28
184 	 *
185 	 * Throws: GException on failure.
186 	 * Throws: ConstructionException GTK+ fails to create the object.
187 	 */
188 	public this(AsyncResultIF asyncResult)
189 	{
190 		GError* err = null;
191 
192 		auto __p = gdk_pixbuf_animation_new_from_stream_finish((asyncResult is null) ? null : asyncResult.getAsyncResultStruct(), &err);
193 
194 		if (err !is null)
195 		{
196 			throw new GException( new ErrorG(err) );
197 		}
198 
199 		if(__p is null)
200 		{
201 			throw new ConstructionException("null returned by new_from_stream_finish");
202 		}
203 
204 		this(cast(GdkPixbufAnimation*) __p, true);
205 	}
206 
207 	/**
208 	 * Creates a new animation by asynchronously loading an image from an input stream.
209 	 *
210 	 * For more details see gdk_pixbuf_new_from_stream(), which is the synchronous
211 	 * version of this function.
212 	 *
213 	 * When the operation is finished, `callback` will be called in the main thread.
214 	 * You can then call gdk_pixbuf_animation_new_from_stream_finish() to get the
215 	 * result of the operation.
216 	 *
217 	 * Params:
218 	 *     stream = a #GInputStream from which to load the animation
219 	 *     cancellable = optional #GCancellable object
220 	 *     callback = a `GAsyncReadyCallback` to call when the pixbuf is loaded
221 	 *     userData = the data to pass to the callback function
222 	 *
223 	 * Since: 2.28
224 	 */
225 	public static void newFromStreamAsync(InputStream stream, Cancellable cancellable, GAsyncReadyCallback callback, void* userData)
226 	{
227 		gdk_pixbuf_animation_new_from_stream_async((stream is null) ? null : stream.getInputStreamStruct(), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData);
228 	}
229 
230 	/**
231 	 * Queries the height of the bounding box of a pixbuf animation.
232 	 *
233 	 * Returns: Height of the bounding box of the animation.
234 	 */
235 	public int getHeight()
236 	{
237 		return gdk_pixbuf_animation_get_height(gdkPixbufAnimation);
238 	}
239 
240 	/**
241 	 * Get an iterator for displaying an animation.
242 	 *
243 	 * The iterator provides the frames that should be displayed at a
244 	 * given time.
245 	 *
246 	 * @start_time would normally come from g_get_current_time(), and marks
247 	 * the beginning of animation playback. After creating an iterator, you
248 	 * should immediately display the pixbuf returned by
249 	 * gdk_pixbuf_animation_iter_get_pixbuf(). Then, you should install
250 	 * a timeout (with g_timeout_add()) or by some other mechanism ensure
251 	 * that you'll update the image after
252 	 * gdk_pixbuf_animation_iter_get_delay_time() milliseconds. Each time
253 	 * the image is updated, you should reinstall the timeout with the new,
254 	 * possibly-changed delay time.
255 	 *
256 	 * As a shortcut, if @start_time is `NULL`, the result of
257 	 * g_get_current_time() will be used automatically.
258 	 *
259 	 * To update the image (i.e. possibly change the result of
260 	 * gdk_pixbuf_animation_iter_get_pixbuf() to a new frame of the animation),
261 	 * call gdk_pixbuf_animation_iter_advance().
262 	 *
263 	 * If you're using #GdkPixbufLoader, in addition to updating the image
264 	 * after the delay time, you should also update it whenever you
265 	 * receive the area_updated signal and
266 	 * gdk_pixbuf_animation_iter_on_currently_loading_frame() returns
267 	 * `TRUE`. In this case, the frame currently being fed into the loader
268 	 * has received new data, so needs to be refreshed. The delay time for
269 	 * a frame may also be modified after an area_updated signal, for
270 	 * example if the delay time for a frame is encoded in the data after
271 	 * the frame itself. So your timeout should be reinstalled after any
272 	 * area_updated signal.
273 	 *
274 	 * A delay time of -1 is possible, indicating "infinite".
275 	 *
276 	 * Params:
277 	 *     startTime = time when the animation starts playing
278 	 *
279 	 * Returns: an iterator to move over the animation
280 	 */
281 	public PixbufAnimationIter getIter(TimeVal startTime)
282 	{
283 		auto __p = gdk_pixbuf_animation_get_iter(gdkPixbufAnimation, (startTime is null) ? null : startTime.getTimeValStruct());
284 
285 		if(__p is null)
286 		{
287 			return null;
288 		}
289 
290 		return ObjectG.getDObject!(PixbufAnimationIter)(cast(GdkPixbufAnimationIter*) __p, true);
291 	}
292 
293 	/**
294 	 * Retrieves a static image for the animation.
295 	 *
296 	 * If an animation is really just a plain image (has only one frame),
297 	 * this function returns that image.
298 	 *
299 	 * If the animation is an animation, this function returns a reasonable
300 	 * image to use as a static unanimated image, which might be the first
301 	 * frame, or something more sophisticated depending on the file format.
302 	 *
303 	 * If an animation hasn't loaded any frames yet, this function will
304 	 * return `NULL`.
305 	 *
306 	 * Returns: unanimated image representing the animation
307 	 */
308 	public Pixbuf getStaticImage()
309 	{
310 		auto __p = gdk_pixbuf_animation_get_static_image(gdkPixbufAnimation);
311 
312 		if(__p is null)
313 		{
314 			return null;
315 		}
316 
317 		return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) __p);
318 	}
319 
320 	/**
321 	 * Queries the width of the bounding box of a pixbuf animation.
322 	 *
323 	 * Returns: Width of the bounding box of the animation.
324 	 */
325 	public int getWidth()
326 	{
327 		return gdk_pixbuf_animation_get_width(gdkPixbufAnimation);
328 	}
329 
330 	/**
331 	 * Checks whether the animation is a static image.
332 	 *
333 	 * If you load a file with gdk_pixbuf_animation_new_from_file() and it
334 	 * turns out to be a plain, unanimated image, then this function will
335 	 * return `TRUE`. Use gdk_pixbuf_animation_get_static_image() to retrieve
336 	 * the image.
337 	 *
338 	 * Returns: `TRUE` if the "animation" was really just an image
339 	 */
340 	public bool isStaticImage()
341 	{
342 		return gdk_pixbuf_animation_is_static_image(gdkPixbufAnimation) != 0;
343 	}
344 
345 	alias doref = ref_;
346 	/**
347 	 * Adds a reference to an animation.
348 	 *
349 	 * Deprecated: Use g_object_ref().
350 	 *
351 	 * Returns: The same as the @animation argument.
352 	 */
353 	public override PixbufAnimation ref_()
354 	{
355 		auto __p = gdk_pixbuf_animation_ref(gdkPixbufAnimation);
356 
357 		if(__p is null)
358 		{
359 			return null;
360 		}
361 
362 		return ObjectG.getDObject!(PixbufAnimation)(cast(GdkPixbufAnimation*) __p);
363 	}
364 
365 	/**
366 	 * Removes a reference from an animation.
367 	 *
368 	 * Deprecated: Use g_object_unref().
369 	 */
370 	public override void unref()
371 	{
372 		gdk_pixbuf_animation_unref(gdkPixbufAnimation);
373 	}
374 }