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