|
|
|
@ -150,19 +150,9 @@ void LCD_setCircle(int x0, int y0, int radius, enum Color bw, int lineThickness) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// This function will draw a char (defined in the ASCII table
|
|
|
|
|
// near the beginning of this sketch) at a defined x and y).
|
|
|
|
|
// The color can be either black (1) or white (0).
|
|
|
|
|
void LCD_setChar(struct Utf8Char character, int x, int y, enum Color bw) |
|
|
|
|
{ |
|
|
|
|
LCD_setCharEx(character, x, y, bw, 1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void LCD_setCharEx(struct Utf8Char character, int x, int y, enum Color bw, uint8_t style) |
|
|
|
|
static void LCD_setCharEx(struct Utf8Char character, int x, int y, enum Color color, struct TextStyle style) |
|
|
|
|
{ |
|
|
|
|
const struct FontGraphic *symbol = Font_GetSymbol(character); |
|
|
|
|
bool bg = style & 0x80; |
|
|
|
|
enum FontStyle style_real = style & 0x7F; |
|
|
|
|
|
|
|
|
|
uint8_t column; // temp byte to store character's column bitmap
|
|
|
|
|
for (int i = 0; i < 5; i++) // 5 columns (x) per character
|
|
|
|
@ -172,36 +162,36 @@ void LCD_setCharEx(struct Utf8Char character, int x, int y, enum Color bw, uint8 |
|
|
|
|
{ |
|
|
|
|
bool bit = column & (1 << j); |
|
|
|
|
|
|
|
|
|
if (style_real == FONT_NORMAL) { |
|
|
|
|
if (style.size == FONT_NORMAL) { |
|
|
|
|
if (bit) {// test bits to set pixels
|
|
|
|
|
LCD_setPixel(x + i, y + j, bw); |
|
|
|
|
LCD_setPixel(x + i, y + j, color); |
|
|
|
|
} |
|
|
|
|
else if (bg) { |
|
|
|
|
LCD_setPixel(x + i, y + j, !bw); |
|
|
|
|
else if (style.bg) { |
|
|
|
|
LCD_setPixel(x + i, y + j, !color); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else if (style_real == FONT_DOUBLE) { |
|
|
|
|
else if (style.size == FONT_DOUBLE) { |
|
|
|
|
if (bit) {// test bits to set pixels
|
|
|
|
|
LCD_setPixel(x + i * 2, y + j * 2, bw); |
|
|
|
|
LCD_setPixel(x + i * 2 + 1, y + j * 2, bw); |
|
|
|
|
LCD_setPixel(x + i * 2, y + j * 2 + 1, bw); |
|
|
|
|
LCD_setPixel(x + i * 2 + 1, y + j * 2 + 1, bw); |
|
|
|
|
LCD_setPixel(x + i * 2, y + j * 2, color); |
|
|
|
|
LCD_setPixel(x + i * 2 + 1, y + j * 2, color); |
|
|
|
|
LCD_setPixel(x + i * 2, y + j * 2 + 1, color); |
|
|
|
|
LCD_setPixel(x + i * 2 + 1, y + j * 2 + 1, color); |
|
|
|
|
} |
|
|
|
|
else if (bg) { |
|
|
|
|
LCD_setPixel(x + i * 2, y + j * 2, !bw); |
|
|
|
|
LCD_setPixel(x + i * 2 + 1, y + j * 2, !bw); |
|
|
|
|
LCD_setPixel(x + i * 2, y + j * 2 + 1, !bw); |
|
|
|
|
LCD_setPixel(x + i * 2 + 1, y + j * 2 + 1, !bw); |
|
|
|
|
else if (style.bg) { |
|
|
|
|
LCD_setPixel(x + i * 2, y + j * 2, !color); |
|
|
|
|
LCD_setPixel(x + i * 2 + 1, y + j * 2, !color); |
|
|
|
|
LCD_setPixel(x + i * 2, y + j * 2 + 1, !color); |
|
|
|
|
LCD_setPixel(x + i * 2 + 1, y + j * 2 + 1, !color); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else if (style_real == FONT_BOLD) { |
|
|
|
|
else if (style.size == FONT_BOLD) { |
|
|
|
|
if (bit) {// test bits to set pixels
|
|
|
|
|
LCD_setPixel(x + i, y + j, bw); |
|
|
|
|
LCD_setPixel(x + i + 1, y + j, bw); |
|
|
|
|
LCD_setPixel(x + i, y + j, color); |
|
|
|
|
LCD_setPixel(x + i + 1, y + j, color); |
|
|
|
|
} |
|
|
|
|
else if (bg) { |
|
|
|
|
LCD_setPixel(x + i, y + j, !bw); |
|
|
|
|
LCD_setPixel(x + i + 1, y + j, !bw); |
|
|
|
|
else if (style.bg) { |
|
|
|
|
LCD_setPixel(x + i, y + j, !color); |
|
|
|
|
LCD_setPixel(x + i + 1, y + j, !color); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -214,67 +204,77 @@ void LCD_setCharEx(struct Utf8Char character, int x, int y, enum Color bw, uint8 |
|
|
|
|
// library.
|
|
|
|
|
void LCD_setStr(const char *dString, int x, int y, enum Color bw) |
|
|
|
|
{ |
|
|
|
|
LCD_setStrEx(dString, x, y, bw, 1); |
|
|
|
|
LCD_setStrEx(dString, x, y, bw, (struct TextStyle) {}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static const int char_widths[] = { |
|
|
|
|
[FONT_NORMAL] = 5, |
|
|
|
|
[FONT_DOUBLE] = 10, |
|
|
|
|
[FONT_BOLD] = 6 |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static const int char_spacings[] = { |
|
|
|
|
[FONT_NORMAL] = 1, |
|
|
|
|
[FONT_DOUBLE] = 2, |
|
|
|
|
[FONT_BOLD] = 1 |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static const int char_heights[] = { |
|
|
|
|
[FONT_NORMAL] = 8, |
|
|
|
|
[FONT_DOUBLE] = 16, |
|
|
|
|
[FONT_BOLD] = 8 |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// setStr draws a string of characters, calling setChar with
|
|
|
|
|
// progressive coordinates until it's done.
|
|
|
|
|
// This function was grabbed from the SparkFun ColorLCDShield
|
|
|
|
|
// library.
|
|
|
|
|
void LCD_setStrEx(const char *dString, int x, int y, enum Color bw, uint8_t style) |
|
|
|
|
// library. AND HEAVILY MODIFIED
|
|
|
|
|
void LCD_setStrEx(const char *dString, int x, int y, enum Color color, struct TextStyle style) |
|
|
|
|
{ |
|
|
|
|
const int x0 = x; |
|
|
|
|
struct Utf8Iterator iter; |
|
|
|
|
Utf8Iterator_Init(&iter, dString); |
|
|
|
|
bool bg = style & 0x80; |
|
|
|
|
enum FontStyle style_real = style & 0x7F; |
|
|
|
|
|
|
|
|
|
int charw = char_widths[style.size]; |
|
|
|
|
int charh = char_heights[style.size]; |
|
|
|
|
|
|
|
|
|
int spacingx = char_spacings[style.size] + style.spacing_x; |
|
|
|
|
int spacingy = style.spacing_y; |
|
|
|
|
|
|
|
|
|
struct Utf8Char uchar; |
|
|
|
|
int limit = style.max_chars; |
|
|
|
|
while ((uchar = Utf8Iterator_Next(&iter)).uint) { |
|
|
|
|
LCD_setCharEx(uchar, x, y, bw, style); |
|
|
|
|
LCD_setCharEx(uchar, x, y, color, style); |
|
|
|
|
|
|
|
|
|
if (style_real == FONT_NORMAL) { |
|
|
|
|
x += 5; |
|
|
|
|
if (bg) { |
|
|
|
|
for (int i = y; i < y + 8; i++) { |
|
|
|
|
LCD_setPixel(x, i, !bw); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
x++; |
|
|
|
|
if (x > (LCD_WIDTH - 5)) // Enables wrap around
|
|
|
|
|
{ |
|
|
|
|
x = 0; |
|
|
|
|
y += 8; |
|
|
|
|
} |
|
|
|
|
if (limit > 0) { |
|
|
|
|
limit -= 1; |
|
|
|
|
if (limit == 0) return; |
|
|
|
|
} |
|
|
|
|
else if (style_real == FONT_DOUBLE) { |
|
|
|
|
x += 10; |
|
|
|
|
if (bg) { |
|
|
|
|
for (int i = y; i < y + 16; i++) { |
|
|
|
|
LCD_setPixel(x, i, !bw); |
|
|
|
|
LCD_setPixel(x + 1, i, !bw); |
|
|
|
|
|
|
|
|
|
x += charw; |
|
|
|
|
|
|
|
|
|
if (style.bg) { |
|
|
|
|
for (int i = y; i < y + charh; i++) { |
|
|
|
|
for (int j = x; j < x + spacingx; j++) { |
|
|
|
|
LCD_setPixel(j, i, !color); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
x += 2; |
|
|
|
|
if (x > (LCD_WIDTH - 10)) // Enables wrap around
|
|
|
|
|
{ |
|
|
|
|
x = 0; |
|
|
|
|
y += 16; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else if (style_real == FONT_BOLD) { |
|
|
|
|
x += 6; |
|
|
|
|
if (bg) { |
|
|
|
|
for (int i = y; i < y + 8; i++) { |
|
|
|
|
LCD_setPixel(x, i, !bw); |
|
|
|
|
LCD_setPixel(x + 1, i, !bw); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
x += 1; |
|
|
|
|
if (x > (LCD_WIDTH - 6)) // Enables wrap around
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
x += spacingx; |
|
|
|
|
if (x > (LCD_WIDTH - charw)) { |
|
|
|
|
if (style.nowrap) break; |
|
|
|
|
if (style.wrap_to_0) { |
|
|
|
|
x = 0; |
|
|
|
|
y += 8; |
|
|
|
|
} else { |
|
|
|
|
x = x0; |
|
|
|
|
} |
|
|
|
|
y += charh + spacingy; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// no more characters could be seen
|
|
|
|
|
if (y >= LCD_HEIGHT) { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|