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