From 1852c697fc787927dc1df49aebac4f18a90e5177 Mon Sep 17 00:00:00 2001 From: Anton Mukhin Date: Sat, 19 Jul 2025 08:11:56 +0300 Subject: [PATCH] mctext lib update --- STM32_HAL_Lib/mctext.c | 60 +++++++++++++++++++++++++++++++----------- STM32_HAL_Lib/mctext.h | 7 +++-- 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/STM32_HAL_Lib/mctext.c b/STM32_HAL_Lib/mctext.c index 308051f..8dd4145 100644 --- a/STM32_HAL_Lib/mctext.c +++ b/STM32_HAL_Lib/mctext.c @@ -2,7 +2,7 @@ * mctext.c * * Created on: May 16, 2025 - * Author: User + * Author: Anton Mukhin */ @@ -15,8 +15,10 @@ void (*mct_SetPixel)(uint8_t, uint8_t, uint8_t) = ST7565_SetPixel; //=================================================================================// + + // Draw a single character. Returns width of drawn character -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 mct_CharTS(uint8_t x, uint8_t y, unsigned char c, uint8_t color, const uint8_t *font, uint8_t transp, uint8_t scale) { 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 @@ -25,10 +27,11 @@ uint8_t mct_CharT(uint8_t x, uint8_t y, unsigned char c, uint8_t color, const ui uint8_t i, j, p, s, b, seg; // i-cur.column, j-cur.row of 8, p-rows of 8, s-height in cur.row of 8, b-cur.bit in cur.row, seg-byte.segment uint8_t bps; // Bytes per symbol for packed fonts uint16_t o; // Current offset + uint8_t sx, sy; // To paint scaled pixel if (c < fc || c > lc) return 0; if (x > LCDWIDTH) return 0; - if (y+h > LCDHEIGHT) return 0; + if (y + h * scale > LCDHEIGHT) return 0; // Calc the offset for desired symbol if (pk) { // The font is packed @@ -51,11 +54,19 @@ uint8_t mct_CharT(uint8_t x, uint8_t y, unsigned char c, uint8_t color, const ui bps = w*h/8; // Bytes per current symbol if ((w*h)%8 > 0) bps++; // Correction for the last byte b = 0; // bit indexer in "current" byte - for (i=0; i LCDWIDTH) return i-1; // Check if we're out of display size - for (j=0; j>b) & 1) mct_SetPixel(x+i, y+j, color); // Paint the pixel + if ((seg>>b) & 1) { + for (sx = 0; sx < scale; sx++) + for (sy = 0; sy < scale; sy++) + mct_SetPixel(x+i+sx, y+j+sy, color); // Paint the pixel + } else if (!transp) { + for (sx = 0; sx < scale; sx++) + for (sy = 0; sy < scale; sy++) + mct_SetPixel(x+i+sx, y+j+sy, !color); // Paint the background pixel + } if (b < 7) b++; else {b = 0; o++;} // Track bits and bytes } } @@ -74,22 +85,34 @@ uint8_t mct_CharT(uint8_t x, uint8_t y, unsigned char c, uint8_t color, const ui } // Draw the symbol - for (i=0; i LCDWIDTH) return i-1; // Check if we're out of display size for (j=0; j= 8) ? 8 : (h - j*8) % 8; // Clac the amount of pixels in current byte 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); + if ((seg>>b) & 1) { + for (sx = 0; sx < scale; sx++) + for (sy = 0; sy < scale; sy++) + mct_SetPixel(x+i+sx, y+j*8*scale+b*scale+sy, color); + } else if (!transp) { + for (sx = 0; sx < scale; sx++) + for (sy = 0; sy < scale; sy++) + mct_SetPixel(x+i+sx, y+j*8*scale+b*scale+sy, !color); + } } o++; } //mct_SetPixel(x+i, y, color); // For testing purposes } } - return w; + return w*scale; +} + +// Draw a single character. Not scaled +uint8_t mct_CharT(uint8_t x, uint8_t y, unsigned char c, uint8_t color, const uint8_t *font, uint8_t transp) { + return mct_CharTS(x, y, c, color, font, 1, 1); } // Draw a single character. Transparent background. Returns width of drawn character @@ -97,17 +120,22 @@ uint8_t mct_Char(uint8_t x, uint8_t y, unsigned char c, uint8_t color, const uin return 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) { +// Draw a string of characters. Transparency, Scale +void mct_StringTS(uint8_t x, uint8_t y, const char *c, uint8_t color, const uint8_t *font, uint8_t transp, uint8_t scale) { 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; + if (y+h*scale > LCDHEIGHT) return; while (c[0] != 0) { - if (x+w > LCDWIDTH) return; - w = mct_Char(x, y, (unsigned char)*c, color, font); + //if (x+w > LCDWIDTH) return; + w = mct_CharTS(x, y, (unsigned char)*c, color, font, transp, scale); c++; - x += w + s; + x += w + s*scale; } } + +// Draw a string of characters +void mct_String(uint8_t x, uint8_t y, const char *c, uint8_t color, const uint8_t *font) { + mct_StringTS(x, y, c, color, font, 1, 1); +} diff --git a/STM32_HAL_Lib/mctext.h b/STM32_HAL_Lib/mctext.h index c21b0f3..2dadbe9 100644 --- a/STM32_HAL_Lib/mctext.h +++ b/STM32_HAL_Lib/mctext.h @@ -2,17 +2,20 @@ * mctext.h * * Created on: May 16, 2025 - * Author: User + * Author: Anton Mukhin */ #ifndef INC_MCTEXT_H_ #define INC_MCTEXT_H_ -#include "stm32f1xx_hal.h" +#include "stm32g0xx_hal.h" // Draw a single character. Returns width of drawn character +uint8_t mct_CharT(uint8_t x, uint8_t y, unsigned char c, uint8_t color, const uint8_t *font, uint8_t transp); + +// 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); // Draw a string of characters