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