summaryrefslogtreecommitdiff
path: root/gtk/gtk_throbber.c
diff options
context:
space:
mode:
Diffstat (limited to 'gtk/gtk_throbber.c')
-rw-r--r--gtk/gtk_throbber.c72
1 files changed, 70 insertions, 2 deletions
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 <rjek@rjek.com>
+ * Copyright 2008 Rob Kendrick <rjek@netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
@@ -18,6 +18,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <stdarg.h>
#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.