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