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