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_gui.c | 28 +++++++++++++++++++-- gtk/gtk_throbber.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- gtk/gtk_throbber.h | 5 ++-- 3 files changed, 99 insertions(+), 6 deletions(-) (limited to 'gtk') diff --git a/gtk/gtk_gui.c b/gtk/gtk_gui.c index dfeec03f5..b251fec15 100644 --- a/gtk/gtk_gui.c +++ b/gtk/gtk_gui.c @@ -195,8 +195,32 @@ void gui_init(int argc, char** argv) 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"); 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. diff --git a/gtk/gtk_throbber.h b/gtk/gtk_throbber.h index d4ff2cd41..a98a5c5eb 100644 --- a/gtk/gtk_throbber.h +++ b/gtk/gtk_throbber.h @@ -1,5 +1,5 @@ /* - * Copyright 2006 Rob Kendrick + * Copyright 2008 Rob Kendrick * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -29,7 +29,8 @@ struct nsgtk_throbber 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__ */ -- cgit v1.2.3