mirror of
https://github.com/usetrmnl/bb_epaper.git
synced 2026-04-29 13:43:26 -07:00
Added support for transparent or opaque character drawing
This commit is contained in:
@@ -315,6 +315,20 @@ void FunctionTest(void)
|
||||
epd.drawRect(60, 60, 40, 40, BBEP_RED);
|
||||
epd.drawCircle(26, 134, 25, BBEP_RED);
|
||||
epd.fillRoundRect(60, 114, 40, 40, 8, BBEP_BLACK);
|
||||
for (int y=160; y<200; y+=3) {
|
||||
epd.drawLine(0, y, 127, y, BBEP_BLACK);
|
||||
}
|
||||
// Show options for transparent foreground and background of text drawing
|
||||
epd.setFont(FONT_12x16);
|
||||
epd.setCursor(0, 162);
|
||||
epd.setTextColor(BBEP_BLACK);
|
||||
epd.print("AB");
|
||||
epd.setTextColor(BBEP_BLACK, BBEP_WHITE);
|
||||
epd.println("CD");
|
||||
epd.setTextColor(BBEP_WHITE);
|
||||
epd.print("EF");
|
||||
epd.setTextColor(BBEP_TRANSPARENT, BBEP_BLACK);
|
||||
epd.print("GH");
|
||||
epd.writePlane();
|
||||
epd.refresh(REFRESH_FULL, true); // display the white buffer and return
|
||||
epd.sleep(LIGHT_SLEEP);
|
||||
|
||||
+46
-12
@@ -503,10 +503,10 @@ int bbepLoadG5(BBEPDISP *pBBEP, const uint8_t *pG5, int x, int y, int iFG, int i
|
||||
src_mask = 0x80; // MSB on left
|
||||
}
|
||||
if (u8 & src_mask) {
|
||||
if (iFG >= 0)
|
||||
if (iFG != BBEP_TRANSPARENT)
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, x+tx, y+ty, (uint8_t)iFG);
|
||||
} else {
|
||||
if (iBG >= 0)
|
||||
if (iBG != BBEP_TRANSPARENT)
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, x+tx, y+ty, (uint8_t)iBG);
|
||||
}
|
||||
src_mask >>= 1;
|
||||
@@ -608,10 +608,10 @@ int bbepLoadBMP(BBEPDISP *pBBEP, const uint8_t *pBMP, int dx, int dy, int iFG, i
|
||||
src_mask = 0x80; // MSB on left
|
||||
}
|
||||
if (b & src_mask) {
|
||||
if (iFG >= 0)
|
||||
if (iFG != BBEP_TRANSPARENT)
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, dx+x, dy+y, (uint8_t)iFG);
|
||||
} else {
|
||||
if (iBG >= 0)
|
||||
if (iBG != BBEP_TRANSPARENT)
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, dx+x, dy+y, (uint8_t)iBG);
|
||||
}
|
||||
src_mask >>= 1;
|
||||
@@ -750,7 +750,7 @@ void bbepSetTextWrap(BBEPDISP *pBBEP, int bWrap)
|
||||
//
|
||||
int bbepWriteStringCustom(BBEPDISP *pBBEP, BB_FONT *pFont, int x, int y, char *szMsg, int iColor, uint8_t iPlane)
|
||||
{
|
||||
int rc, i, h, w, j, end_y, dx, dy, tx, ty, iSrcPitch, iPitch;
|
||||
int rc, i, h, w, j, end_y, dx, dy, tx, ty, iSrcPitch, iPitch, iBG;
|
||||
signed int n;
|
||||
unsigned int c, bInvert = 0;
|
||||
uint8_t *s, uc0, uc1;
|
||||
@@ -763,6 +763,8 @@ int bbepWriteStringCustom(BBEPDISP *pBBEP, BB_FONT *pFont, int x, int y, char *s
|
||||
pBBEP->last_error = BBEP_ERROR_BAD_PARAMETER;
|
||||
return BBEP_ERROR_BAD_PARAMETER; // invalid param
|
||||
}
|
||||
iBG = pBBEP->iBG;
|
||||
if (iBG == -1) iBG = BBEP_TRANSPARENT; // -1 = don't care
|
||||
if (x == -1)
|
||||
x = pBBEP->iCursorX;
|
||||
if (y == -1)
|
||||
@@ -833,7 +835,11 @@ int bbepWriteStringCustom(BBEPDISP *pBBEP, BB_FONT *pFont, int x, int y, char *s
|
||||
u8Count = 8;
|
||||
for (tx=x; tx<x+w; tx++) {
|
||||
if (u8 & 0x80) {
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, tx, ty, iColor);
|
||||
if (iColor != BBEP_TRANSPARENT) {
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, tx, ty, iColor);
|
||||
}
|
||||
} else if (iBG != BBEP_TRANSPARENT) {
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, tx, ty, iBG);
|
||||
}
|
||||
u8 <<= 1;
|
||||
u8Count--;
|
||||
@@ -1002,10 +1008,14 @@ int bbepWriteString(BBEPDISP *pBBEP, int x, int y, char *szMsg, int iSize, int i
|
||||
uint8_t c, *s, ucCMD, ucCMD1, ucCMD2;
|
||||
int iOldFG; // old fg color to make sure red works
|
||||
uint8_t u8Temp[40];
|
||||
int iBG;
|
||||
|
||||
if (pBBEP == NULL) {
|
||||
return BBEP_ERROR_BAD_PARAMETER;
|
||||
}
|
||||
iBG = pBBEP->iBG;
|
||||
if (iBG == -1) iBG = BBEP_TRANSPARENT; // -1 = don't care
|
||||
|
||||
if (pBBEP->chip_type == BBEP_CHIP_UC81xx) {
|
||||
if (pBBEP->iFlags & BBEP_RED_SWAPPED) {
|
||||
ucCMD1 = UC8151_DTM1;
|
||||
@@ -1094,7 +1104,11 @@ int bbepWriteString(BBEPDISP *pBBEP, int x, int y, char *szMsg, int iSize, int i
|
||||
u8Mask = 1<<ty;
|
||||
for (int tx = 0; tx<iLen; tx++) {
|
||||
if (u8Temp[tx] & u8Mask) {
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, x+tx, y+ty, iColor);
|
||||
if (iColor != BBEP_TRANSPARENT) {
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, x+tx, y+ty, iColor);
|
||||
}
|
||||
} else if (iBG != BBEP_TRANSPARENT) {
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, x+tx, y+ty, iBG);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1105,10 +1119,18 @@ int bbepWriteString(BBEPDISP *pBBEP, int x, int y, char *szMsg, int iSize, int i
|
||||
u8Mask = 0x80;
|
||||
for (int tx = 7; tx>=0; tx--) {
|
||||
if (s[0] & u8Mask) {
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, x+ty, y+tx+8, iColor);
|
||||
if (iColor != BBEP_TRANSPARENT) {
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, x+ty, y+tx+8, iColor);
|
||||
}
|
||||
} else if (iBG != BBEP_TRANSPARENT) {
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, x+ty, y+tx+8, iBG);
|
||||
}
|
||||
if (s[1] & u8Mask) {
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, x+ty, y+tx, iColor);
|
||||
if (iColor != BBEP_TRANSPARENT) {
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, x+ty, y+tx, iColor);
|
||||
}
|
||||
} else if (iBG != BBEP_TRANSPARENT) {
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, x+ty, y+tx+8, iBG);
|
||||
}
|
||||
u8Mask >>= 1;
|
||||
}
|
||||
@@ -1259,10 +1281,18 @@ int bbepWriteString(BBEPDISP *pBBEP, int x, int y, char *szMsg, int iSize, int i
|
||||
u8Mask = 1<<ty;
|
||||
for (int tx = 0; tx<iLen; tx++) {
|
||||
if (u8Temp[6+tx] & u8Mask) {
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, x+tx, y+ty, iColor);
|
||||
if (iColor != BBEP_TRANSPARENT) {
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, x+tx, y+ty, iColor);
|
||||
}
|
||||
} else if (iBG != BBEP_TRANSPARENT) {
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, x+tx, y+ty, iBG);
|
||||
}
|
||||
if (u8Temp[18+tx] & u8Mask) {
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, x+tx, y+ty+8, iColor);
|
||||
if (iColor != BBEP_TRANSPARENT) {
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, x+tx, y+ty+8, iColor);
|
||||
}
|
||||
} else if (iBG != BBEP_TRANSPARENT) {
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, x+tx, y+ty+8, iBG);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1303,7 +1333,11 @@ int bbepWriteString(BBEPDISP *pBBEP, int x, int y, char *szMsg, int iSize, int i
|
||||
u8Mask = 1<<ty;
|
||||
for (int tx = 0; tx<iLen; tx++) {
|
||||
if (u8Temp[tx] & u8Mask) {
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, x+tx, ty+y, iColor);
|
||||
if (iColor != BBEP_TRANSPARENT) {
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, x+tx, ty+y, iColor);
|
||||
}
|
||||
} else if (iBG != BBEP_TRANSPARENT) {
|
||||
(*pBBEP->pfnSetPixelFast)(pBBEP, x+tx, ty+y, iBG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,8 +212,6 @@ bool BBEPAPER::hasPartialRefresh()
|
||||
|
||||
void BBEPAPER::setTextColor(int iFG, int iBG)
|
||||
{
|
||||
if (iFG > BBEP_RED) iFG = BBEP_BLACK;
|
||||
if (iBG > BBEP_RED) iBG = BBEP_BLACK;
|
||||
if ((_bbep.iFlags & (BBEP_3COLOR | BBEP_4COLOR)) == 0) {
|
||||
if (iFG == BBEP_RED || iFG == BBEP_YELLOW) iFG = BBEP_BLACK; // can't set red color
|
||||
if (iBG == BBEP_RED || iFG == BBEP_YELLOW) iBG = BBEP_BLACK;
|
||||
|
||||
+2
-1
@@ -173,6 +173,7 @@ enum {
|
||||
#define BBEP_WHITE 1
|
||||
#define BBEP_YELLOW 2
|
||||
#define BBEP_RED 3
|
||||
#define BBEP_TRANSPARENT 255
|
||||
|
||||
// 4 gray levels
|
||||
#define BBEP_GRAY0 0
|
||||
@@ -340,7 +341,7 @@ class BBEPAPER
|
||||
void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
|
||||
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
|
||||
void setTextWrap(bool bWrap);
|
||||
void setTextColor(int iFG, int iBG = -1);
|
||||
void setTextColor(int iFG, int iBG = BBEP_TRANSPARENT);
|
||||
void setCursor(int x, int y);
|
||||
int loadBMP(const uint8_t *pBMP, int x, int y, int iFG, int iBG);
|
||||
int loadBMP3(const uint8_t *pBMP, int x, int y);
|
||||
|
||||
Reference in New Issue
Block a user