This commit is contained in:
24
src/text.cpp
24
src/text.cpp
@ -2,25 +2,25 @@
|
||||
#include "text.h"
|
||||
|
||||
void drawTextSprite(Window window, const unsigned char* sprite, int w, int h, int xPos, int yPos, CRGB color, boolean invert) {
|
||||
for (byte y=0; y<h; y++) for (byte x=0; x<w; x++) {
|
||||
bool on = (sprite[x]>>(h-1-y)&1)*255;
|
||||
if (invert) on = !on;
|
||||
if (on) setPixel(window, x+xPos, y+yPos, color);
|
||||
}
|
||||
for (byte y=0; y<h; y++) for (byte x=0; x<w; x++) {
|
||||
bool on = (sprite[x]>>(h-1-y)&1)*255;
|
||||
if (invert) on = !on;
|
||||
if (on) setPixel(window, x+xPos, y+yPos, color);
|
||||
}
|
||||
}
|
||||
|
||||
void drawChar(Window window, const unsigned char* font, int w, int h, int x, int y, char c, CRGB color) {
|
||||
const unsigned char* sprite = &font[(c-32)*w];
|
||||
drawTextSprite(window, sprite, w, h, x, y, color, false);
|
||||
const unsigned char* sprite = &font[(c-32)*w];
|
||||
drawTextSprite(window, sprite, w, h, x, y, color, false);
|
||||
}
|
||||
|
||||
void drawDigit(Window window, const unsigned char* font, int w, int h, int x, int y, int digit, CRGB color, boolean invert) {
|
||||
const unsigned char* sprite = &font[digit*w];
|
||||
drawTextSprite(window, sprite, w, h, x, y, color, invert);
|
||||
const unsigned char* sprite = &font[digit*w];
|
||||
drawTextSprite(window, sprite, w, h, x, y, color, invert);
|
||||
}
|
||||
|
||||
void drawText(Window window, const char *font, int w, int h, char *text, int x, int y, CRGB color) {
|
||||
for (uint16_t i = 0; i < strlen(text); i++) {
|
||||
drawChar(window, font5x7, 5, 7, x+i*(w+1), y, text[i], color);
|
||||
}
|
||||
for (uint16_t i = 0; i < strlen(text); i++) {
|
||||
drawChar(window, font5x7, 5, 7, x+i*(w+1), y, text[i], color);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user