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
This commit is contained in:
Matthias Melcher 2018-03-27 21:54:04 +00:00
parent e52b55c09d
commit 29bda776bb
8 changed files with 289 additions and 401 deletions

View File

@ -18,116 +18,8 @@
#if 0
#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Hor_Slider.H>
#include <FL/fl_draw.H>
class MyBox : public Fl_Box
{
public:
MyBox(int x, int y, int w, int h) :
Fl_Box(x, y, w, h)
{
box(FL_DOWN_BOX);
}
void draw()
{
Fl_Box::draw();
fl_color(FL_BLUE);
fl_pie(x()+20, y()+20, w()-40, h()-40, a1, a2);
}
double a1 = 0.0;
double a2 = 240.0;
};
Fl_Window *win;
MyBox *box = 0L;
char s1Label[80] = { 0 };
char s2Label[80] = { 0 };
int main(int argc, char **argv)
{
win = new Fl_Window(0, 0, 600, 800);
box = new MyBox(10, 10, 580, 580);
auto s1 = new Fl_Hor_Slider(210, 600, 380, 45, s1Label);
s1->range(-360, 360);
s1->value(0.0);
s1->labelsize(35);
s1->align(FL_ALIGN_LEFT);
s1->increment(1, 0);
s1->callback(
[](Fl_Widget *w, void*) {
auto s = (Fl_Slider*)w;
box->a1 = s->value();
sprintf(s1Label, "%g", s->value());
win->redraw();
}
);
auto s2 = new Fl_Hor_Slider(210, 660, 380, 45, s2Label);
s2->range(-360, 360);
s2->value(240.0);
s2->labelsize(35);
s2->align(FL_ALIGN_LEFT);
s2->callback(
[](Fl_Widget *w, void*) {
auto s = (Fl_Slider*)w;
box->a2 = s->value();
sprintf(s2Label, "%g", s->value());
win->redraw();
}
);
win->show(argc, argv);
Fl::run();
return 0;
}
#elif 1
#include <stdlib.h>
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Adjuster.H>
#include <FL/Fl_Box.H>
void adjcb(Fl_Widget *o, void *v) {
Fl_Adjuster *a = (Fl_Adjuster*)o;
Fl_Box *b = (Fl_Box *)v;
a->format((char *)(b->label()));
b->redraw();
}
int main(int argc, char ** argv) {
Fl_Double_Window window(320,100,argv[0]);
char buf1[100];
Fl_Box b1(FL_DOWN_BOX,20,30,80,25,buf1);
b1.color(FL_WHITE);
Fl_Adjuster a1(20+80,30,3*25,25);
a1.callback(adjcb,&b1);
adjcb(&a1,&b1);
char buf2[100];
Fl_Box b2(FL_DOWN_BOX,20+80+4*25,30,80,25,buf2);
b2.color(FL_WHITE);
Fl_Adjuster a2(b2.x()+b2.w(),10,25,3*25);
a2.callback(adjcb,&b2);
adjcb(&a2,&b2);
window.resizable(window);
window.end();
window.show(argc, argv);
return Fl::run();
}
#elif 0
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>

View File

@ -5,7 +5,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.1.0'
}
}

View File

@ -1,6 +1,6 @@
#Sun Feb 05 20:05:03 IST 2017
#Tue Mar 27 23:05:16 CEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

View File

@ -33,6 +33,7 @@
class Fl_Android_Window_Driver;
class Fl_Android_Bytemap;
class Fl_Android_565A_Map;
/**
\brief The Windows-specific graphics driver class.
@ -60,49 +61,11 @@ protected:
float scale_; // scale between user and graphical coordinates: graphical = user * scale_
/** Sets the current value of the scaling factor */
virtual void scale(float f) { scale_ = f; }
public:
// The following functions create the various graphics drivers that are required
// for core operations. They must be implemented as members of Fl_Graphics_Driver,
// but located in the device driver module that is linked to the core library
/** Instantiate the graphics driver adequate to draw to the platform's display driver.
Each platform implements this method its own way.
*/
static Fl_Graphics_Driver *newMainGraphicsDriver();
/** A 2D coordinate transformation matrix */
struct matrix {double a, b, c, d, x, y;};
/** Features that a derived class may possess. */
typedef enum {
NATIVE = 1, /**< native graphics driver for the platform */
PRINTER = 2 /**< graphics driver for a printer drawing surface */
} driver_feature;
protected:
int fl_clip_state_number; ///< For internal use by FLTK
static const matrix m0; ///< For internal use by FLTK
Fl_Font font_; ///< current font
Fl_Fontsize size_; ///< current font size
Fl_Color color_; ///< current color
int sptr;///< For internal use by FLTK
static const int matrix_stack_size = FL_MATRIX_STACK_SIZE; ///< For internal use by FLTK
matrix stack[FL_MATRIX_STACK_SIZE]; ///< For internal use by FLTK
matrix m; ///< current transformation matrix
int n; ///< For internal use by FLTK
int gap_; ///< For internal use by FLTK
int what; ///< For internal use by FLTK
int rstackptr; ///< For internal use by FLTK
static const int region_stack_max = FL_REGION_STACK_SIZE - 1; ///< For internal use by FLTK
Fl_Region rstack[FL_REGION_STACK_SIZE]; ///< For internal use by FLTK
Fl_Font_Descriptor *font_descriptor_; ///< For internal use by FLTK
#ifndef FL_DOXYGEN
enum {LINE, LOOP, POLYGON, POINT_};
inline int vertex_no() { return n; }
inline int vertex_kind() {return what;}
#endif
matrix *fl_matrix; /**< Points to the current coordinate transformation matrix */
virtual void global_gc();
/** Support function for Fl_Pixmap drawing */
virtual fl_uintptr_t cache(Fl_Pixmap *img) { return 0; }
#endif
/** Support function for Fl_Pixmap drawing */
virtual fl_uintptr_t cache(Fl_Pixmap *img) override;
/** Support function for Fl_Bitmap drawing */
virtual fl_uintptr_t cache(Fl_Bitmap *img) override;
#if 0
@ -123,13 +86,13 @@ protected:
the image offset by the cx and cy arguments.
*/
virtual void draw(Fl_RGB_Image * rgb,int XP, int YP, int WP, int HP, int cx, int cy) {}
#endif
/** \brief Draws an Fl_Pixmap object using this graphics driver.
*
Specifies a bounding box for the image, with the origin (upper left-hand corner) of
the image offset by the cx and cy arguments.
*/
virtual void draw(Fl_Pixmap * pxm,int XP, int YP, int WP, int HP, int cx, int cy) {}
#endif
virtual void draw(Fl_Pixmap * pxm,int XP, int YP, int WP, int HP, int cx, int cy) override;
/** \brief Draws an Fl_Bitmap object using this graphics driver.
*
Specifies a bounding box for the image, with the origin (upper left-hand corner) of
@ -150,39 +113,6 @@ protected:
}
// Support function for image drawing
virtual void uncache_pixmap(fl_uintptr_t p);
// accessor functions to protected image members
int start_image(Fl_Image *img, int XP, int YP, int WP, int HP, int &cx, int &cy,
int &X, int &Y, int &W, int &H);
/** Accessor to a private member variable of Fl_RGB_Image */
static fl_uintptr_t* id(Fl_RGB_Image *rgb) {return &(rgb->id_);}
/** Accessor to a private member variable of Fl_Pixmap */
static fl_uintptr_t* id(Fl_Pixmap *pm) {return &(pm->id_);}
/** Accessor to a private member variable of Fl_Bitmap */
static fl_uintptr_t* id(Fl_Bitmap *bm) {return &(bm->id_);}
/** Accessor to a private member variable of Fl_RGB_Image */
static fl_uintptr_t* mask(Fl_RGB_Image *rgb) {return &(rgb->mask_);}
/** Accessor to a private member variable of Fl_Pixmap */
static fl_uintptr_t* mask(Fl_Pixmap *pm) {return &(pm->mask_);}
/** Accessor to a private member variable of Fl_Pixmap */
static float* cache_scale(Fl_Pixmap *pm) {return &(pm->cache_scale_);}
/** Accessor to a private member variable of Fl_Bitmap */
static float* cache_scale(Fl_Bitmap *bm) {return &(bm->cache_scale_);}
/** Accessor to a private member variable of Fl_RGB_Image */
static float* cache_scale(Fl_RGB_Image *rgb) {return &(rgb->cache_scale_);}
/** Accessor to a private member variable of Fl_Pixmap */
static Fl_Color* pixmap_bg_color(Fl_Pixmap *pm) {return &(pm->pixmap_bg_color);}
/** For internal library use only */
static void draw_empty(Fl_Image* img, int X, int Y) {img->draw_empty(X, Y);}
/** Accessor to a private member function of Fl_Bitmap */
static int prepare(Fl_Bitmap *bm, int XP, int YP, int WP, int HP, int &cx, int &cy,
int &X, int &Y, int &W, int &H) {
return bm->prepare(XP,YP,WP,HP,cx,cy,X,Y,W,H);
}
/** Accessor to a private member function of Fl_Pixmap */
static int prepare(Fl_Pixmap *pm, int XP, int YP, int WP, int HP, int &cx, int &cy,
int &X, int &Y, int &W, int &H) {
return pm->prepare(XP,YP,WP,HP,cx,cy,X,Y,W,H);
}
#endif
public:
/** Constructor, C++11 initialises member variables in-line */
@ -270,52 +200,44 @@ public:
virtual void gap() override;
/** see fl_circle() */
virtual void circle(double x, double y, double r) override;
#if 0
// TODO: arc()
// --- implementation is in src/fl_arc.cxx which includes src/drivers/xxx/Fl_xxx_Graphics_Driver_arc.cxx if needed
virtual void arc(double x, double y, double r, double start, double end);
#endif
virtual void arc(double x, double y, double r, double start, double end) override { super::arc(x, y, r, start, end); }
// --- implementation is in src/fl_arci.cxx which includes src/drivers/xxx/Fl_xxx_Graphics_Driver_arci.cxx
/** see fl_arc(int x, int y, int w, int h, double a1, double a2) */
virtual void arc(int x, int y, int w, int h, double a1, double a2) override;
/** see fl_pie() */
virtual void pie(int x, int y, int w, int h, double a1, double a2) override;
#if 0
// TODO: curve()
// --- implementation is in src/fl_curve.cxx which includes src/drivers/xxx/Fl_xxx_Graphics_Driver_curve.cxx if needed
virtual void curve(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3);
#endif
// super: virtual void curve(double X0, double Y0, double X1, double Y1, double X2, double Y2, double X3, double Y3);
// --- implementation is in src/fl_line_style.cxx which includes src/cfg_gfx/xxx_line_style.cxx
// TODO: line_style()
/** see fl_line_style() */
virtual void line_style(int style, int width=0, char* dashes=0) override;
// --- implementation is in src/fl_color.cxx which includes src/cfg_gfx/xxx_color.cxx
/** see fl_color(Fl_Color) */
// super: virtual void color(Fl_Color c);
#if 0
virtual void set_color(Fl_Color i, unsigned int c);
virtual void free_color(Fl_Color i, int overlay);
virtual void color(Fl_Color c) override { super::color(c); }
virtual void set_color(Fl_Color i, unsigned int c) override;
// super: virtual void free_color(Fl_Color i, int overlay);
/** see fl_color(void) */
virtual Fl_Color color() { return color_; }
virtual Fl_Color color() override { return super::color(); }
/** see fl_color(uchar, uchar, uchar) */
virtual void color(uchar r, uchar g, uchar b) {}
#endif
virtual void color(uchar r, uchar g, uchar b) override;
/** see fl_draw(const char *str, int n, int x, int y) */
virtual void draw(const char *str, int n, int x, int y) override;
#if 0
/** Draw the first \p n bytes of the string \p str starting at position \p x , \p y */
virtual void draw(const char *str, int n, float x, float y) { draw(str, n, (int)(x+0.5), (int)(y+0.5));}
// super: virtual void draw(const char *str, int n, float x, float y);
/** see fl_draw(int angle, const char *str, int n, int x, int y) */
virtual void draw(int angle, const char *str, int n, int x, int y) { draw(str, n, x, y); }
// TODO: drawing text at an angle is not supported
virtual void draw(int angle, const char *str, int n, int x, int y) override { draw(str, n, x, y); }
/** see fl_rtl_draw(const char *str, int n, int x, int y) */
virtual void rtl_draw(const char *str, int n, int x, int y) { draw(str, n, x, y); }
// TODO: drawing text right-to-left is not supported
virtual void rtl_draw(const char *str, int n, int x, int y) override { draw(str, n, x, y); }
/** Returns non-zero if the graphics driver possesses the \p feature */
virtual int has_feature(driver_feature feature) { return 0; }
#endif
// super: virtual int has_feature(driver_feature feature)
/** see fl_font(Fl_Font, Fl_Fontsize) */
virtual void font(Fl_Font face, Fl_Fontsize fsize) override;
/** see fl_font(void) */
// super: virtual Fl_Font font() {return font_; }
virtual Fl_Font font() override { return super::font(); }
/** Return the current font size */
virtual Fl_Fontsize size() override;
/** Compute the width of the first \p n bytes of the string \p str if drawn with current font */
@ -340,10 +262,12 @@ public:
virtual uchar **mask_bitmap() { return 0; }
/** Support for pixmap drawing */
virtual void mask_bitmap(uchar **) {}
#endif
// default implementation may be enough
/** Support for PostScript drawing */
virtual float scale_font_for_PostScript(Fl_Font_Descriptor *desc, int s) { return float(s); }
virtual float scale_font_for_PostScript(Fl_Font_Descriptor *desc, int s) override { return float(s); }
// default implementation may be enough
#if 0
/** Support for PostScript drawing */
virtual float scale_bitmap_for_PostScript() { return 2; }
virtual void set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win);
@ -359,12 +283,10 @@ public:
virtual int get_font_sizes(Fl_Font fnum, int*& sizep) override;
/** Support for Fl::set_fonts() */
virtual Fl_Font set_fonts(const char *name) override;
#if 0
/** Some platforms may need to implement this to support fonts */
virtual Fl_Fontdesc* calc_fl_fonts(void) {return NULL;}
// super: virtual Fl_Fontdesc* calc_fl_fonts(void) {return NULL;}
/** Support for Fl::set_font() */
virtual unsigned font_desc_size();
#endif
// super: virtual unsigned font_desc_size();
/** Support for Fl::get_font() */
virtual const char *font_name(int num) override;
/** Support for Fl::set_font() */
@ -375,10 +297,10 @@ public:
/** Support function for fl_overlay_rect() and scaled GUI.
Defaut implementation may be enough */
virtual bool overlay_rect_unscaled();
#endif
/** Support function for fl_overlay_rect() and scaled GUI.
Defaut implementation may be enough */
virtual void overlay_rect(int x, int y, int w , int h) { loop(x, y, x+w-1, y, x+w-1, y+h-1, x, y+h-1); }
#endif
// super: virtual void overlay_rect(int x, int y, int w , int h) { loop(x, y, x+w-1, y, x+w-1, y+h-1, x, y+h-1); }
// --- end of original Fl_Graphics_Driver header -----------------------------
// --- start of Android additions --------------------------------------------
@ -393,7 +315,8 @@ protected:
void yxline_unclipped(int x, int y, int y1);
void end_polygon(int begin, int end);
void ellipse(double xt, double yt, double rx, double ry);
void render_bytemap(int x, int y, Fl_Android_Bytemap *bm, Fl_Rect_Region &r);
void draw(int xx, int yy, Fl_Android_565A_Map *bm, Fl_Rect_Region &r);
void draw(int x, int y, Fl_Android_Bytemap *bm, Fl_Rect_Region &r);
int render_letter(int xx, int yy, uint32_t c, Fl_Rect_Region &r);
// pointer into the screen buffer at the top left corner of the current window

View File

@ -26,6 +26,9 @@
#include <errno.h>
#include <math.h>
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; yy<w; yy++) {
const uchar *src = rgba + yy*rowBytes;
uint32_t *dst = cache->pWords + yy*cache->pStride;
for (int xx=0; xx<w; xx++) {
uint32_t c = ((((src[0] << 8) & 0xf800) |
((src[1] << 3) & 0x07e0) |
((src[2] >> 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$".
//

View File

@ -46,6 +46,26 @@ public:
};
/**
* A 565a map is an array of words for interleaved RGB and Alpha data.
* 565 is the number of bit per component, compatible with our screen memory
* scheme. The second word is actually a byt containing the alpha value for
* the previous pixel: rrrrrggg.gggbbbbb.aaaaaaaa.00000000
*/
class Fl_Android_565A_Map
{
public:
Fl_Android_565A_Map();
Fl_Android_565A_Map(int w, int h);
~Fl_Android_565A_Map();
public:
int pWidth = 0, pHeight = 0, pStride = 0;
int pXOffset = 0, pYOffset = 0;
uint32_t *pWords = nullptr;
};
/**
* This class reads True Type Font files and creates Bytemaps for glyphs at the
* requested height.

View File

@ -65,6 +65,8 @@ static const char *old_font_names[] = {
"$DroidSansMono.ttf", "$DroidSansMono.ttf"
};
// -----------------------------------------------------------------------------
/**
* Create an empty Bytemap.
*/
@ -78,7 +80,7 @@ Fl_Android_Bytemap::Fl_Android_Bytemap()
Fl_Android_Bytemap::Fl_Android_Bytemap(int w, int h)
{
pWidth = w; pStride = w; pHeight = h;
pBytes = (unsigned char *)malloc(w*h);
pBytes = (unsigned char *)calloc(w, h);
}
/**
@ -89,6 +91,144 @@ Fl_Android_Bytemap::~Fl_Android_Bytemap()
if (pBytes) ::free(pBytes);
}
/**
* Render a bytemap to the screen using the current fl_color.
*
* Bytes are seen as alpha values for the RGB color set by fl_color. For better
* performance, alpha is only rendered in 5 steps. All rendering is offset as
* described in the bytemap, and clipped to the clipping region.
* @param xx, yy bottom left position of the bytemap (baseline for text)
* @param bm bytemap including offsets and size
* @param r clipping rectangle
*/
void Fl_Android_Graphics_Driver::draw(int xx, int yy, Fl_Android_Bytemap *bm,
Fl_Rect_Region &r)
{
xx += bm->pXOffset; yy += bm->pYOffset;
if (xx>r.right()) return;
if (yy>r.bottom()) return;
if (xx+bm->pWidth < r.left()) return;
if (yy+bm->pHeight < r.top()) return;
uint16_t cc = make565(fl_color()), cc12 = (cc&0xf7de)>>1, cc14 = (cc12&0xf7de)>>1, cc34 = cc12+cc14;
int32_t ss = pStride;
uint16_t *bits = pBits;
uint32_t ww = bm->pWidth;
uint32_t hh = bm->pHeight;
unsigned char *srcBytes = bm->pBytes;
int dx = r.left()-xx;
int dy = r.top()-yy;
int dr = (xx+ww)-r.right();
int db = (yy+hh)-r.bottom();
if (dx>0) { xx+=dx; ww-=dx; srcBytes+=dx; }
if (dy>0) { yy+=dy; hh-=dy; srcBytes+=dy*bm->pStride; }
if (dr>0) { ww-=dr; }
if (db>0) { hh-=db; }
for (uint32_t iy = 0; iy<hh; ++iy) {
uint16_t *d = bits + (yy+iy)*ss + xx;
unsigned char *s = srcBytes + iy*bm->pStride;
for (uint32_t ix = 0; ix<ww; ++ix) {
#if 1
// 5 step antialiasing
unsigned char v = *s++;
if (v>200) { // 100% black
*d = cc;
} else if (v<50) { // 0%
} else if (v>150) { // 75%
uint16_t nn = *d, nn14 = (nn&(uint16_t(0xe79c)))>>2;
*d = nn14 + cc34;
} else if (v<100) { // 25%
uint16_t nn = *d, nn12 = (nn&(uint16_t(0xf7de)))>>1, nn14 = (nn12&(uint16_t(0xf7de)))>>1, nn34 = nn12+nn14;
*d = nn34 + cc14;
} else { // 50%
uint16_t nn = *d, nn12 = (nn&(uint16_t(0xf7de)))>>1;
*d = nn12 + cc12;
}
#else
// pure black and white
if (*s++ > 128)
*d = cc;
#endif
d++;
}
}
}
// -----------------------------------------------------------------------------
/**
* Create an empty image.
* All initialisation of members is done in-lin (C++11)
*/
Fl_Android_565A_Map::Fl_Android_565A_Map()
{
}
Fl_Android_565A_Map::Fl_Android_565A_Map(int w, int h)
{
pWidth = w; pStride = w; pHeight = h;
pWords = (uint32_t*)calloc(4, w*h);
}
Fl_Android_565A_Map::~Fl_Android_565A_Map()
{
if (pWords) ::free(pWords);
}
/**
* Render a bytemap to the screen using the current fl_color.
*
* Bytes are seen as alpha values for the RGB color set by fl_color. For better
* performance, alpha is only rendered in 5 steps. All rendering is offset as
* described in the bytemap, and clipped to the clipping region.
* @param xx, yy bottom left position of the bytemap (baseline for text)
* @param bm bytemap including offsets and size
* @param r clipping rectangle
*/
void Fl_Android_Graphics_Driver::draw(int xx, int yy, Fl_Android_565A_Map *bm,
Fl_Rect_Region &r)
{
xx += bm->pXOffset; yy += bm->pYOffset;
if (xx>r.right()) return;
if (yy>r.bottom()) return;
if (xx+bm->pWidth < r.left()) return;
if (yy+bm->pHeight < r.top()) return;
uint16_t cc = make565(fl_color()); // TODO: alpha: , cc12 = (cc&0xf7de)>>1, cc14 = (cc12&0xf7de)>>1, cc34 = cc12+cc14;
int32_t ss = pStride;
uint16_t *bits = pBits;
uint32_t ww = bm->pWidth;
uint32_t hh = bm->pHeight;
uint32_t *srcWords = bm->pWords;
int dx = r.left()-xx;
int dy = r.top()-yy;
int dr = (xx+ww)-r.right();
int db = (yy+hh)-r.bottom();
if (dx>0) { xx+=dx; ww-=dx; srcWords+=dx; }
if (dy>0) { yy+=dy; hh-=dy; srcWords+=dy*bm->pStride; }
if (dr>0) { ww-=dr; }
if (db>0) { hh-=db; }
for (uint32_t iy = 0; iy<hh; ++iy) {
uint16_t *d = bits + (yy+iy)*ss + xx;
uint32_t *s = srcWords + iy*bm->pStride;
for (uint32_t ix = 0; ix<ww; ++ix) {
uint32_t c = *s++;
uint8_t alpha = c;
if (alpha>0) {
uint16_t rgb = c >> 16;
// TODO: alpha blending: *d = rgb*a + (*d)*(1-a);
*d = rgb;
}
d++;
}
}
}
// -----------------------------------------------------------------------------
@ -426,72 +566,6 @@ void Fl_Android_Graphics_Driver::font(Fl_Font fnum, Fl_Fontsize size) {
font_ = fnum;
}
/**
* Render a bytemap to the screen using the current fl_color.
*
* Bytes are seen as alpha values for the RGB color set by fl_color. For better
* performance, alpha is only rendered in 5 steps. All rendering is offset as
* described in the bytemap, and clipped to the clipping region.
* @param xx, yy bottom left position of the bytemap (baseline for text)
* @param bm bytemap including offsets and size
* @param r clipping rectangle
*/
void Fl_Android_Graphics_Driver::render_bytemap(int xx, int yy, Fl_Android_Bytemap *bm, Fl_Rect_Region &r)
{
xx += bm->pXOffset; yy += bm->pYOffset;
if (xx>r.right()) return;
if (yy>r.bottom()) return;
if (xx+bm->pWidth < r.left()) return;
if (yy+bm->pHeight < r.top()) return;
uint16_t cc = make565(fl_color()), cc12 = (cc&0xf7de)>>1, cc14 = (cc12&0xf7de)>>1, cc34 = cc12+cc14;
int32_t ss = pStride;
uint16_t *bits = pBits;
uint32_t ww = bm->pWidth;
uint32_t hh = bm->pHeight;
unsigned char *srcBytes = bm->pBytes;
int dx = r.left()-xx;
int dy = r.top()-yy;
int dr = (xx+ww)-r.right();
int db = (yy+hh)-r.bottom();
if (dx>0) { xx+=dx; ww-=dx; srcBytes+=dx; }
if (dy>0) { yy+=dy; hh-=dy; srcBytes+=dy*bm->pStride; }
if (dr>0) { ww-=dr; }
if (db>0) { hh-=db; }
for (uint32_t iy = 0; iy<hh; ++iy) {
uint16_t *d = bits + (yy+iy)*ss + xx;
unsigned char *s = srcBytes + iy*bm->pStride;
for (uint32_t ix = 0; ix<ww; ++ix) {
#if 1
// 5 step antialiasing
unsigned char v = *s++;
if (v>200) { // 100% black
*d = cc;
} else if (v<50) { // 0%
} else if (v>150) { // 75%
uint16_t nn = *d, nn14 = (nn&(uint16_t(0xe79c)))>>2;
*d = nn14 + cc34;
} else if (v<100) { // 25%
uint16_t nn = *d, nn12 = (nn&(uint16_t(0xf7de)))>>1, nn14 = (nn12&(uint16_t(0xf7de)))>>1, nn34 = nn12+nn14;
*d = nn34 + cc14;
} else { // 50%
uint16_t nn = *d, nn12 = (nn&(uint16_t(0xf7de)))>>1;
*d = nn12 + cc12;
}
#else
// pure black and white
if (*s++ > 128)
*d = cc;
#endif
d++;
}
}
}
/**
* Copy a single letter to the screen.
* @param xx, yy position of character on screen
@ -509,7 +583,7 @@ int Fl_Android_Graphics_Driver::render_letter(int xx, int yy, uint32_t c, Fl_Rec
Fl_Android_Bytemap *bm = fd->get_bytemap(c);
if (!bm) return oxx;
render_bytemap(xx, yy, bm, r);
draw(xx, yy, bm, r);
return oxx + bm->pAdvance;
}
@ -706,120 +780,6 @@ void Fl_Android_Graphics_Driver::font_name(int num, const char *name)
}
}
#if 0
// TODO: do we need that?
const char* Fl_Xlib_Graphics_Driver::get_font_name(Fl_Font fnum, int* ap) {
Fl_Xlib_Fontdesc *f = ((Fl_Xlib_Fontdesc*)fl_fonts) + fnum;
if (!f->fontname[0]) {
int type = 0;
const char* p = f->name;
if (!p) {
if (ap) *ap = 0;
return "";
}
char *o = f->fontname;
if (*p != '-') { // non-standard font, just replace * with spaces:
if (strstr(p,"bold")) type = FL_BOLD;
if (strstr(p,"ital")) type |= FL_ITALIC;
for (;*p; p++) {
if (*p == '*' || *p == ' ' || *p == '-') {
do p++; while (*p == '*' || *p == ' ' || *p == '-');
if (!*p) break;
if (o < (f->fontname + ENDOFBUFFER - 1)) *o++ = ' ';
}
if (o < (f->fontname + ENDOFBUFFER - 1)) *o++ = *p;
}
*o = 0;
} else { // standard dash-separated font:
// get the family:
const char *x = fl_font_word(p,2); if (*x) x++; if (*x=='*') x++;
if (!*x) {
if (ap) *ap = 0;
return p;
}
const char *e = fl_font_word(x,1);
if ((e - x) < (int)(ENDOFBUFFER - 1)) {
// MRS: we want strncpy here, not strlcpy...
strncpy(o,x,e-x);
o += e-x;
} else {
strlcpy(f->fontname, x, ENDOFBUFFER);
o = f->fontname+ENDOFBUFFER-1;
}
// collect all the attribute words:
for (int n = 3; n <= 6; n++) {
// get the next word:
if (*e) e++; x = e; e = fl_font_word(x,1);
int t = attribute(n,x);
if (t < 0) {
if (o < (f->fontname + ENDOFBUFFER - 1)) *o++ = ' ';
if ((e - x) < (int)(ENDOFBUFFER - (o - f->fontname) - 1)) {
// MRS: we want strncpy here, not strlcpy...
strncpy(o,x,e-x);
o += e-x;
} else {
strlcpy(o,x, ENDOFBUFFER - (o - f->fontname) - 1);
o = f->fontname+ENDOFBUFFER-1;
}
} else type |= t;
}
// skip over the '*' for the size and get the registry-encoding:
x = fl_font_word(e,2);
if (*x) {x++; *o++ = '('; while (*x) *o++ = *x++; *o++ = ')';}
*o = 0;
if (type & FL_BOLD) strlcat(f->fontname, " bold", ENDOFBUFFER);
if (type & FL_ITALIC) strlcat(f->fontname, " italic", ENDOFBUFFER);
}
f->fontname[ENDOFBUFFER] = (char)type;
}
if (ap) *ap = f->fontname[ENDOFBUFFER];
return f->fontname;
}
#define ENDOFBUFFER sizeof(fl_fonts->fontname)-1
// turn a stored font name into a pretty name:
const char* Fl_Quartz_Graphics_Driver::get_font_name(Fl_Font fnum, int* ap) {
if (!fl_fonts) fl_fonts = calc_fl_fonts();
Fl_Fontdesc *f = fl_fonts + fnum;
if (!f->fontname[0]) {
this->set_fontname_in_fontdesc(f);
const char* p = f->name;
if (!p || !*p) {if (ap) *ap = 0; return "";}
int type = 0;
if (strstr(f->name, "Bold")) type |= FL_BOLD;
if (strstr(f->name, "Italic") || strstr(f->name, "Oblique")) type |= FL_ITALIC;
f->fontname[ENDOFBUFFER] = (char)type;
}
if (ap) *ap = f->fontname[ENDOFBUFFER];
return f->fontname;
}
int Fl_Quartz_Graphics_Driver::get_font_sizes(Fl_Font fnum, int*& sizep) {
static int array[128];
if (!fl_fonts) fl_fonts = calc_fl_fonts();
Fl_Fontdesc *s = fl_fonts+fnum;
if (!s->name) s = fl_fonts; // empty slot in table, use entry 0
int cnt = 0;
// ATS supports all font size
array[0] = 0;
sizep = array;
cnt = 1;
return cnt;
}
#endif
//
// End of "$Id$".

View File

@ -38,6 +38,37 @@ class Fl_Window;
class FL_EXPORT Fl_Android_Screen_Driver : public Fl_Screen_Driver
{
#if 0
// No, this is not how we will implement this.
enum {
/// request attribute for a specific screen; default to screen 0
INDEX = 0x0001, // add an integer in the vararg list
/// allow or lock screen rotation
ROTATION_MASK = 0x0006, ROTATION_KEEP = 0x0000,
MAY_ROTATE = 0x0006, LOCK_TO_PORTRAIT = 0x0002, LOCK_TO_LANDSCAPE = 0x0004,
/// screen size
SIZE_MASK = 0x0038, SIZE_KEEP = 0x0000,
NATIVE_SIZE = 0x0008, // keep the full native screen size
FIRST_WINDOW = 0x0010, // adapt the screen to the size of the first window
ALL_WINDOWS = 0x0018, // adapt the screen to show all windows
FIXED_DIAGONAL = 0x0020, // keep aspect ration at 1:1, add an int for the length of the diagonal
// fixed size override the previous flags for portrait and/or landscape
FIXED_PORTRAIT_SIZE = 0x0040, // add two int width and height
NO_FIXED_PORTRAIT_SIZE = 0x80000040, // release fixed portrait size
FIXED_LANDSCAPE_SIZE = 0x0080, // add two int width and height
NO_FIXED_LANDSCAPE_SIZE = 0x80000080, // release fixed landscape size
// show or hide mobile device screen items
SHOW_STATUS_BAR = 0x0080, // top of the screen
HIDE_STATUS_BAR = 0x80000080, // top of the screen
SHOW_NAVIGATION_BAR = 0x0100, // bottom of the screen
HIDE_NAVIGATION_BAR = 0x0100, // bottom of the screen
};
/// request some attributes from a screen that may or may not be met
virtual hint(unsigned int flags, ...);
#endif
private:
int handle_queued_events(double time_to_wait);
int handle_app_command();