Author: rjek
Date: Mon Jun 2 11:47:15 2008
New Revision: 4244
URL:
http://source.netsurf-browser.org?rev=4244&view=rev
Log:
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.
Modified:
trunk/netsurf/gtk/gtk_gui.c
trunk/netsurf/gtk/gtk_throbber.c
trunk/netsurf/gtk/gtk_throbber.h
Modified: trunk/netsurf/gtk/gtk_gui.c
URL:
http://source.netsurf-browser.org/trunk/netsurf/gtk/gtk_gui.c?rev=4244&am...
==============================================================================
--- trunk/netsurf/gtk/gtk_gui.c (original)
+++ trunk/netsurf/gtk/gtk_gui.c Mon Jun 2 11:47:15 2008
@@ -195,8 +195,32 @@
nsgtk_completion_init();
- find_resource(buf, "throbber.gif", "./gtk/res/throbber.gif");
- nsgtk_throbber_initialise(buf);
+ /* This is an ugly hack to just get the new-style throbber going.
+ * It, along with the PNG throbber loader, need making more generic.
+ */
+ {
+#define STROF(n) #n
+#define FIND_THROB(n) find_resource(filenames[(n)], \
+ "throbber/throbber" STROF(n) ".png", \
+ "./gtk/res/throbber/throbber" STROF(n) ".png")
+ char filenames[9][PATH_MAX];
+ FIND_THROB(0);
+ FIND_THROB(1);
+ FIND_THROB(2);
+ FIND_THROB(3);
+ FIND_THROB(4);
+ FIND_THROB(5);
+ FIND_THROB(6);
+ FIND_THROB(7);
+ FIND_THROB(8);
+ nsgtk_throbber_initialise_from_png(9,
+ filenames[0], filenames[1], filenames[2], filenames[3],
+ filenames[4], filenames[5], filenames[6], filenames[7],
+ filenames[8]);
+#undef FIND_THROB
+#undef STROF
+ }
+
if (nsgtk_throbber == NULL)
die("Unable to load throbber image.\n");
Modified: trunk/netsurf/gtk/gtk_throbber.c
URL:
http://source.netsurf-browser.org/trunk/netsurf/gtk/gtk_throbber.c?rev=42...
==============================================================================
--- trunk/netsurf/gtk/gtk_throbber.c (original)
+++ trunk/netsurf/gtk/gtk_throbber.c Mon Jun 2 11:47:15 2008
@@ -1,5 +1,5 @@
/*
- * Copyright 2006 Rob Kendrick <rjek(a)rjek.com>
+ * Copyright 2008 Rob Kendrick <rjek(a)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.
Modified: trunk/netsurf/gtk/gtk_throbber.h
URL:
http://source.netsurf-browser.org/trunk/netsurf/gtk/gtk_throbber.h?rev=42...
==============================================================================
--- trunk/netsurf/gtk/gtk_throbber.h (original)
+++ trunk/netsurf/gtk/gtk_throbber.h Mon Jun 2 11:47:15 2008
@@ -1,5 +1,5 @@
/*
- * Copyright 2006 Rob Kendrick <rjek(a)rjek.com>
+ * Copyright 2008 Rob Kendrick <rjek(a)netsurf-browser.org>
*
* This file is part of NetSurf,
http://www.netsurf-browser.org/
*
@@ -29,7 +29,8 @@
extern struct nsgtk_throbber *nsgtk_throbber;
-bool nsgtk_throbber_initialise(const char *fn);
+bool nsgtk_throbber_initialise_from_gif(const char *fn);
+bool nsgtk_throbber_initialise_from_png(const int frames, ...);
void nsgtk_throbber_finalise(void);
#endif /* __GTK_THROBBER_H__ */