From 29bda776bb78352b331771bd1169de31e4edc1be Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Tue, 27 Mar 2018 21:54:04 +0000 Subject: Android: Implemented Pixmap drawing, also much cleanup in Fl_Android_Graphics_Driver. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12810 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/drivers/Android/Fl_Android_Graphics_Driver.cxx | 68 +++++++++++++++++++++- 1 file changed, 65 insertions(+), 3 deletions(-) (limited to 'src/drivers/Android/Fl_Android_Graphics_Driver.cxx') diff --git a/src/drivers/Android/Fl_Android_Graphics_Driver.cxx b/src/drivers/Android/Fl_Android_Graphics_Driver.cxx index b6fa13c23..7b74c0c01 100644 --- a/src/drivers/Android/Fl_Android_Graphics_Driver.cxx +++ b/src/drivers/Android/Fl_Android_Graphics_Driver.cxx @@ -26,6 +26,9 @@ #include #include + +extern int fl_convert_pixmap(const char*const* cdata, uchar* out, Fl_Color bg); + static int sign(int v) { return (v<0) ? -1 : 1; } /* @@ -370,7 +373,7 @@ void Fl_Android_Graphics_Driver::polygon(int x0, int y0, int x1, int y1, int x2, */ void Fl_Android_Graphics_Driver::begin_vertices() { - pnVertex = 0; + pnVertex = n = 0; pVertexGapStart = 0; } @@ -387,7 +390,7 @@ void Fl_Android_Graphics_Driver::add_vertex(float x, float y, bool gap) } pVertex[pnVertex].set(x, y); pVertex[pnVertex].pIsGap = gap; - pnVertex++; + pnVertex++; n = pnVertex; } /** @@ -959,6 +962,21 @@ void Fl_Android_Graphics_Driver::circle(double x, double y, double r) } +void Fl_Android_Graphics_Driver::draw(Fl_Pixmap * pxm, int XP, int YP, int WP, int HP, int cx, int cy) +{ + int X, Y, W, H; + if (Fl_Graphics_Driver::prepare(pxm, XP, YP, WP, HP, cx, cy, X, Y, W, H)) { + return; + } + if (*Fl_Graphics_Driver::id(pxm)) { + Fl_Android_565A_Map *cache = (Fl_Android_565A_Map*)*Fl_Graphics_Driver::id(pxm); + for (const auto &it: pClippingRegion.overlapping(Fl_Rect_Region(X, Y, W, H))) { + draw(XP, YP, cache, it->clipped_rect()); + } + } +} + + void Fl_Android_Graphics_Driver::draw(Fl_Bitmap *bm, int XP, int YP, int WP, int HP, int cx, int cy) { int X, Y, W, H; @@ -968,7 +986,7 @@ void Fl_Android_Graphics_Driver::draw(Fl_Bitmap *bm, int XP, int YP, int WP, int if (*Fl_Graphics_Driver::id(bm)) { Fl_Android_Bytemap *cache = (Fl_Android_Bytemap*)*Fl_Graphics_Driver::id(bm); for (const auto &it: pClippingRegion.overlapping(Fl_Rect_Region(X, Y, W, H))) { - render_bytemap(XP, YP, cache, it->clipped_rect()); + draw(XP, YP, cache, it->clipped_rect()); } } } @@ -995,6 +1013,50 @@ fl_uintptr_t Fl_Android_Graphics_Driver::cache(Fl_Bitmap *bm) return (fl_uintptr_t)cache; } + + +fl_uintptr_t Fl_Android_Graphics_Driver::cache(Fl_Pixmap *img) +{ + int w = img->w(), h = img->h(); + int rowBytes = 4*w; + uchar *rgba = (uchar*)calloc(w*h, 4); + int ret = fl_convert_pixmap(img->data(), rgba, 0); + if (ret==0) { + ::free(rgba); + return 0; + } + + Fl_Android_565A_Map *cache = new Fl_Android_565A_Map(w, h); + for (int yy=0; yypWords + yy*cache->pStride; + for (int xx=0; xx> 3) & 0x001f) ) << 16) | src[3]; // FIXME: alpha + *dst++ = c; + src+=4; + } + } + + ::free(rgba); + return (fl_uintptr_t)cache; +} + + +void Fl_Android_Graphics_Driver::set_color(Fl_Color i, unsigned int c) +{ + if (i>255) return; + fl_cmap[i] = c; +} + + +void Fl_Android_Graphics_Driver::color(uchar r, uchar g, uchar b) +{ + color( (((Fl_Color)r)<<24)|(((Fl_Color)g)<<16)|(((Fl_Color)b)<<8) ); +} + + // // End of "$Id$". // -- cgit v1.2.3