diff --git a/STM32_HAL_Lib/mctext.c b/STM32_HAL_Lib/mctext.c index 4777348..7079441 100644 --- a/STM32_HAL_Lib/mctext.c +++ b/STM32_HAL_Lib/mctext.c @@ -16,7 +16,7 @@ void (*mct_SetPixel)(uint8_t, uint8_t, uint8_t) = ST7565_SetPixel; // Draw a single character. Returns width of drawn character -uint8_t mct_Char(uint8_t x, uint8_t y, unsigned char c, uint8_t color, const uint8_t *font) { +uint8_t mct_CharT(uint8_t x, uint8_t y, unsigned char c, uint8_t color, const uint8_t *font, uint8_t transp) { uint8_t pk = font[0]; // Is it a packed font? uint8_t w = font[1]; // Font char width uint8_t h = font[2]; // Font char height @@ -33,7 +33,7 @@ uint8_t mct_Char(uint8_t x, uint8_t y, unsigned char c, uint8_t color, const uin // Calc the offset for desired symbol if (pk) { // The font is packed if (w) { // The font is monospaced - bps = w*h/8 + 1; // Bytes per symbol + width byte + bps = w*h/8; // Bytes per symbol if ((w*h)%8 > 0) bps++; // Correction for the last byte o = FONT_HEADER+(c-fc)*bps; // Offset for desired symbol } else { // The font is not monospaced @@ -82,6 +82,7 @@ uint8_t mct_Char(uint8_t x, uint8_t y, unsigned char c, uint8_t color, const uin seg = font[o]; for (b=0; b>b) & 1) mct_SetPixel(x+i, y+j*8+b, color); + else if (!transp) mct_SetPixel(x+i, y+j*8+b, !color); } o++; } @@ -91,11 +92,16 @@ uint8_t mct_Char(uint8_t x, uint8_t y, unsigned char c, uint8_t color, const uin return w; } +// Draw a single character. Transparent background. Returns width of drawn character +uint8_t mct_Char(uint8_t x, uint8_t y, unsigned char c, uint8_t color, const uint8_t *font) { + mct_CharT(x, y, c, color, font, 1); +} + // Draw a string of characters void mct_String(uint8_t x, uint8_t y, const char *c, uint8_t color, const uint8_t *font) { - uint8_t w = font[0]; // Font char width - uint8_t h = font[1]; // Font char height - uint8_t s = font[2]; // Font space between characters + uint8_t w = font[1]; // Font char width + uint8_t h = font[2]; // Font char height + uint8_t s = font[3]; // Font space between characters if (y+h > LCDHEIGHT) return; while (c[0] != 0) {