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