summaryrefslogtreecommitdiff
path: root/beos/beos_throbber.cpp
diff options
context:
space:
mode:
authorFran├žois Revel <mmu_man@netsurf-browser.org>2008-06-04 01:53:20 +0000
committerFran├žois Revel <mmu_man@netsurf-browser.org>2008-06-04 01:53:20 +0000
commit524e29c4dfcbe713fc25075c9e1c566370062a55 (patch)
tree996eb330d23a3ff78598f259cd48b3cc6c174ee7 /beos/beos_throbber.cpp
parent38be80a680ea5e7403dd39353902a7941e7b0147 (diff)
downloadnetsurf-524e29c4dfcbe713fc25075c9e1c566370062a55.tar.gz
netsurf-524e29c4dfcbe713fc25075c9e1c566370062a55.tar.bz2
- fixed alpha bitmap drawing
- fixed polygon drawing - newstyle throbber, loosely copied from the gtk one. svn path=/trunk/netsurf/; revision=4259
Diffstat (limited to 'beos/beos_throbber.cpp')
-rw-r--r--beos/beos_throbber.cpp79
1 files changed, 78 insertions, 1 deletions
diff --git a/beos/beos_throbber.cpp b/beos/beos_throbber.cpp
index 69cc09076..672ec7be3 100644
--- a/beos/beos_throbber.cpp
+++ b/beos/beos_throbber.cpp
@@ -18,6 +18,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
extern "C" {
#include "utils/log.h"
#include "image/gifread.h"
@@ -25,9 +26,85 @@ extern "C" {
#include "beos/beos_throbber.h"
#include "beos/beos_bitmap.h"
+#include <File.h>
+#include <TranslationUtils.h>
+
struct nsbeos_throbber *nsbeos_throbber = NULL;
-bool nsbeos_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 nsbeos_throbber_initialise_from_png(const int frames, ...)
+{
+ va_list filenames;
+ status_t err;
+ struct nsbeos_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 = (struct nsbeos_throbber *)malloc(sizeof(throb));
+ throb->nframes = frames;
+ throb->framedata = (BBitmap **)malloc(sizeof(BBitmap *) * throb->nframes);
+
+ va_start(filenames, frames);
+
+ for (int i = 0; i < frames; i++) {
+ const char *fn = va_arg(filenames, const char *);
+ BFile file(fn, B_READ_ONLY);
+ throb->framedata[i] = NULL;
+ err = file.InitCheck();
+ if (err < B_OK) {
+ LOG(("Error when loading %s: %s", fn, strerror(err)));
+ errors_when_loading = true;
+ continue;
+ }
+ throb->framedata[i] = BTranslationUtils::GetBitmap(&file);
+ if (throb->framedata[i] == NULL) {
+ LOG(("Error when loading %s: GetBitmap() returned NULL", fn));
+ errors_when_loading = true;
+ }
+ }
+
+ va_end(filenames);
+
+ if (errors_when_loading == true) {
+ for (int i = 0; i < frames; i++) {
+ delete throb->framedata[i];
+ }
+
+ free(throb->framedata);
+ free(throb);
+
+ return false;
+ }
+
+ nsbeos_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 nsbeos_throbber_initialise_from_gif(const char *fn)
{
/* disect the GIF provided by filename in *fn into a series of
* BBitmap for use later.