From 98589be65c8e636297e3245924f5fac2b5c4b562 Mon Sep 17 00:00:00 2001 From: Rob Kendrick Date: Mon, 2 Jun 2008 16:47:15 +0000 Subject: nsgtk now loads the throbber from a set of PNG files. This change will make your eyes bleed. Please avoid looking at it until I make this cleaner. svn path=/trunk/netsurf/; revision=4244 --- gtk/gtk_throbber.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) (limited to 'gtk/gtk_throbber.c') diff --git a/gtk/gtk_throbber.c b/gtk/gtk_throbber.c index 9bf5a10df..b0d41595f 100644 --- a/gtk/gtk_throbber.c +++ b/gtk/gtk_throbber.c @@ -1,5 +1,5 @@ /* - * Copyright 2006 Rob Kendrick + * Copyright 2008 Rob Kendrick * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -18,6 +18,7 @@ #include #include +#include #include "utils/log.h" #include "image/gifread.h" #include "gtk/gtk_throbber.h" @@ -25,7 +26,74 @@ struct nsgtk_throbber *nsgtk_throbber = NULL; -bool nsgtk_throbber_initialise(const char *fn) +/** + * Creates the throbber using a PNG for each frame. The number of frames must + * be at least two. The first frame is the inactive frame, others are the + * active frames. + * + * \param frames The number of frames. Must be at least two. + * \param ... Filenames of PNGs containing frames. + * \return true on success. + */ +bool nsgtk_throbber_initialise_from_png(const int frames, ...) +{ + va_list filenames; + GError *err = NULL; + struct nsgtk_throbber *throb; /**< structure we generate */ + bool errors_when_loading = false; /**< true if a frame failed */ + + if (frames < 2) { + /* we need at least two frames - one for idle, one for active */ + LOG(("Insufficent number of frames in throbber animation!")); + LOG(("(called with %d frames, where 2 is a minimum.)", + frames)); + return false; + } + + throb = malloc(sizeof(throb)); + throb->nframes = frames; + throb->framedata = malloc(sizeof(GdkPixbuf *) * throb->nframes); + + va_start(filenames, frames); + + for (int i = 0; i < frames; i++) { + const char *fn = va_arg(filenames, const char *); + throb->framedata[i] = gdk_pixbuf_new_from_file(fn, &err); + if (err != NULL) { + LOG(("Error when loading %s: %s (%d)", + fn, err->message, err->code)); + throb->framedata[i] = NULL; + errors_when_loading = true; + } + } + + va_end(filenames); + + if (errors_when_loading == true) { + for (int i = 0; i < frames; i++) { + if (throb->framedata[i] != NULL) + gdk_pixbuf_unref(throb->framedata[i]); + } + + free(throb); + + return false; + } + + nsgtk_throbber = throb; + + return true; +} + +/** + * Creates the throbber using a single GIF, using the first frame as the + * inactive throbber, and the others for the active animation. The GIF must + * therefor have at least two frames. + * + * \param fn Filename of GIF to use. It must have at least two frames. + * \return true on success. + */ +bool nsgtk_throbber_initialise_from_gif(const char *fn) { /* disect the GIF provided by filename in *fn into a series of * GdkPixbuf for use later. -- cgit v1.2.3