From 524e29c4dfcbe713fc25075c9e1c566370062a55 Mon Sep 17 00:00:00 2001 From: François Revel Date: Wed, 4 Jun 2008 01:53:20 +0000 Subject: - fixed alpha bitmap drawing - fixed polygon drawing - newstyle throbber, loosely copied from the gtk one. svn path=/trunk/netsurf/; revision=4259 --- beos/beos_bitmap.cpp | 6 ++- beos/beos_gui.cpp | 32 +++++++++++++++- beos/beos_plotters.cpp | 40 ++++++++++++++++++-- beos/beos_scaffolding.cpp | 4 +- beos/beos_throbber.cpp | 79 +++++++++++++++++++++++++++++++++++++++- beos/beos_throbber.h | 3 +- beos/res/throbber.gif | Bin 5175 -> 0 bytes beos/res/throbber/throbber0.png | Bin 0 -> 521 bytes beos/res/throbber/throbber1.png | Bin 0 -> 820 bytes beos/res/throbber/throbber2.png | Bin 0 -> 812 bytes beos/res/throbber/throbber3.png | Bin 0 -> 826 bytes beos/res/throbber/throbber4.png | Bin 0 -> 818 bytes beos/res/throbber/throbber5.png | Bin 0 -> 815 bytes beos/res/throbber/throbber6.png | Bin 0 -> 839 bytes beos/res/throbber/throbber7.png | Bin 0 -> 811 bytes beos/res/throbber/throbber8.png | Bin 0 -> 833 bytes 16 files changed, 155 insertions(+), 9 deletions(-) delete mode 100644 beos/res/throbber.gif create mode 100644 beos/res/throbber/throbber0.png create mode 100644 beos/res/throbber/throbber1.png create mode 100644 beos/res/throbber/throbber2.png create mode 100644 beos/res/throbber/throbber3.png create mode 100644 beos/res/throbber/throbber4.png create mode 100644 beos/res/throbber/throbber5.png create mode 100644 beos/res/throbber/throbber6.png create mode 100644 beos/res/throbber/throbber7.png create mode 100644 beos/res/throbber/throbber8.png diff --git a/beos/beos_bitmap.cpp b/beos/beos_bitmap.cpp index 6f950394f..3ccf591e3 100644 --- a/beos/beos_bitmap.cpp +++ b/beos/beos_bitmap.cpp @@ -97,8 +97,10 @@ static inline void nsbeos_rgba_to_bgra(void *src, void *dst, int width, int heig to[x].g = from[x].g; to[x].r = from[x].r; to[x].a = from[x].a; + /* if (from[x].a == 0) *(rgb_color *)&to[x] = B_TRANSPARENT_32_BIT; + */ } from += rowstride; to += rowstride; @@ -168,7 +170,7 @@ bool bitmap_test_opaque(struct bitmap *bitmap) { assert(bitmap); /* todo: test if bitmap as opaque */ - return bitmap->opaque; + return false;//bitmap->opaque; } @@ -181,7 +183,7 @@ bool bitmap_get_opaque(struct bitmap *bitmap) { assert(bitmap); /* todo: get whether bitmap is opaque */ - return bitmap->opaque; + return false;//bitmap->opaque; } diff --git a/beos/beos_gui.cpp b/beos/beos_gui.cpp index 601bdb5b6..2ea0043d7 100644 --- a/beos/beos_gui.cpp +++ b/beos/beos_gui.cpp @@ -334,8 +334,38 @@ void gui_init(int argc, char** argv) //nsbeos_completion_init(); + + /* 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", \ + "./beos/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); + nsbeos_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 0 find_resource(buf, "throbber.gif", "./beos/res/throbber.gif"); - nsbeos_throbber_initialise(buf); + nsbeos_throbber_initialise_from_gif(buf); +#endif + if (nsbeos_throbber == NULL) die("Unable to load throbber image.\n"); diff --git a/beos/beos_plotters.cpp b/beos/beos_plotters.cpp index 0cfee16a0..89266d64c 100644 --- a/beos/beos_plotters.cpp +++ b/beos/beos_plotters.cpp @@ -107,6 +107,9 @@ const struct plotter_table nsbeos_plotters = { }; +// #pragma mark - implementation + + BView *nsbeos_current_gc(void) { return current_view; @@ -158,9 +161,14 @@ bool nsbeos_plot_rectangle(int x0, int y0, int width, int height, nsbeos_set_colour(c); + float pensize = view->PenSize(); + view->SetPenSize(line_width); + BRect rect(x0, y0, x0 + width - 1, y0 + height - 1); view->StrokeRect(rect, pat); + view->SetPenSize(pensize); + //nsbeos_current_gc_unlock(); #if 0 /* GTK */ @@ -200,10 +208,15 @@ bool nsbeos_plot_line(int x0, int y0, int x1, int y1, int width, nsbeos_set_colour(c); + float pensize = view->PenSize(); + view->SetPenSize(width); + BPoint start(x0, y0); BPoint end(x1, y1); view->StrokeLine(start, end, pat); + view->SetPenSize(pensize); + //nsbeos_current_gc_unlock(); #if 0 /* GTK */ @@ -236,8 +249,20 @@ bool nsbeos_plot_polygon(int *p, unsigned int n, colour fill) return false; } - rgb_color color = nsbeos_rgb_colour(fill); + nsbeos_set_colour(fill); + BPoint points[n]; + + for (i = 0; i < n; i++) { + points[i] = BPoint(p[2 * i], p[2 * i + 1]); + } + + if (fill == TRANSPARENT) + view->StrokePolygon(points, (int32)n); + else + view->FillPolygon(points, (int32)n); + +#if 0 view->BeginLineArray(n); for (i = 0; i < n; i++) { @@ -247,6 +272,7 @@ bool nsbeos_plot_polygon(int *p, unsigned int n, colour fill) } view->EndLineArray(); +#endif //nsbeos_current_gc_unlock(); @@ -467,21 +493,29 @@ static bool nsbeos_plot_bbitmap(int x, int y, int width, int height, } drawing_mode oldmode = view->DrawingMode(); - view->SetDrawingMode(B_OP_OVER); + source_alpha alpha; + alpha_function func; + view->GetBlendingMode(&alpha, &func); + //view->SetDrawingMode(B_OP_OVER); + view->SetDrawingMode(B_OP_ALPHA); + view->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); // XXX DrawBitmap() resamples if rect doesn't match, // but doesn't do any filtering // XXX: use Zeta API if available ? BRect rect(x, y, x + width - 1, y + height - 1); + /* rgb_color old = view->LowColor(); if (bg != TRANSPARENT) { view->SetLowColor(nsbeos_rgb_colour(bg)); view->FillRect(rect, B_SOLID_LOW); } + */ view->DrawBitmap(b, rect); // maybe not needed? - view->SetLowColor(old); + //view->SetLowColor(old); + view->SetBlendingMode(alpha, func); view->SetDrawingMode(oldmode); //nsbeos_current_gc_unlock(); diff --git a/beos/beos_scaffolding.cpp b/beos/beos_scaffolding.cpp index 7bda4e4d7..79162ef71 100644 --- a/beos/beos_scaffolding.cpp +++ b/beos/beos_scaffolding.cpp @@ -527,6 +527,7 @@ void nsbeos_scaffolding_dispatch_event(nsbeos_scaffolding *scaffold, BMessage *m url = data; } else url << path.Path(); + browser_window_go(bw, url.String(), 0, true); break; } @@ -1303,7 +1304,8 @@ nsbeos_scaffolding *nsbeos_new_scaffolding(struct gui_window *toplevel) toolbar->AddChild(g->throbber); g->throbber->SetViewColor(toolbar->ViewColor()); g->throbber->SetLowColor(toolbar->ViewColor()); - g->throbber->SetDrawingMode(B_OP_OVER); + g->throbber->SetDrawingMode(B_OP_ALPHA); + g->throbber->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); /* set up the throbber. */ g->throbber->SetBitmap(nsbeos_throbber->framedata[0]); g->throb_frame = 0; 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 #include +#include 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 +#include + 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. diff --git a/beos/beos_throbber.h b/beos/beos_throbber.h index 47f8249e6..5c890f9fe 100644 --- a/beos/beos_throbber.h +++ b/beos/beos_throbber.h @@ -29,7 +29,8 @@ struct nsbeos_throbber extern struct nsbeos_throbber *nsbeos_throbber; -bool nsbeos_throbber_initialise(const char *fn); +bool nsbeos_throbber_initialise_from_gif(const char *fn); +bool nsbeos_throbber_initialise_from_png(const int frames, ...); void nsbeos_throbber_finalise(void); #endif /* __BEOS_THROBBER_H__ */ diff --git a/beos/res/throbber.gif b/beos/res/throbber.gif deleted file mode 100644 index f9d0c152d..000000000 Binary files a/beos/res/throbber.gif and /dev/null differ diff --git a/beos/res/throbber/throbber0.png b/beos/res/throbber/throbber0.png new file mode 100644 index 000000000..7c79be47b Binary files /dev/null and b/beos/res/throbber/throbber0.png differ diff --git a/beos/res/throbber/throbber1.png b/beos/res/throbber/throbber1.png new file mode 100644 index 000000000..b5b83a465 Binary files /dev/null and b/beos/res/throbber/throbber1.png differ diff --git a/beos/res/throbber/throbber2.png b/beos/res/throbber/throbber2.png new file mode 100644 index 000000000..dc1019dbd Binary files /dev/null and b/beos/res/throbber/throbber2.png differ diff --git a/beos/res/throbber/throbber3.png b/beos/res/throbber/throbber3.png new file mode 100644 index 000000000..5d458ac0b Binary files /dev/null and b/beos/res/throbber/throbber3.png differ diff --git a/beos/res/throbber/throbber4.png b/beos/res/throbber/throbber4.png new file mode 100644 index 000000000..4940aba02 Binary files /dev/null and b/beos/res/throbber/throbber4.png differ diff --git a/beos/res/throbber/throbber5.png b/beos/res/throbber/throbber5.png new file mode 100644 index 000000000..4c70ba64b Binary files /dev/null and b/beos/res/throbber/throbber5.png differ diff --git a/beos/res/throbber/throbber6.png b/beos/res/throbber/throbber6.png new file mode 100644 index 000000000..3242b06b4 Binary files /dev/null and b/beos/res/throbber/throbber6.png differ diff --git a/beos/res/throbber/throbber7.png b/beos/res/throbber/throbber7.png new file mode 100644 index 000000000..c4605101f Binary files /dev/null and b/beos/res/throbber/throbber7.png differ diff --git a/beos/res/throbber/throbber8.png b/beos/res/throbber/throbber8.png new file mode 100644 index 000000000..68f451e5b Binary files /dev/null and b/beos/res/throbber/throbber8.png differ -- cgit v1.2.3