|
|
b579b3 |
#ifndef FONT_INC_CPP
|
|
|
b579b3 |
#define FONT_INC_CPP
|
|
|
b579b3 |
|
|
|
b579b3 |
#include <cstdio></cstdio>
|
|
|
b579b3 |
#include <cstdarg></cstdarg>
|
|
|
b579b3 |
#include <cstring></cstring>
|
|
|
b579b3 |
|
|
|
b579b3 |
#include "font.data.inc.cpp"
|
|
|
b579b3 |
|
|
|
b579b3 |
|
|
|
b579b3 |
|
|
|
b579b3 |
void imgPrint(unsigned char *data, int w, int h, int ch, int x, int y, const unsigned char *color, const char *text) {
|
|
|
b579b3 |
int x0 = x;
|
|
|
b579b3 |
while(unsigned char c = (unsigned char)*text++) {
|
|
|
b579b3 |
if (c == '\n') { x = x0; y += 8; continue; }
|
|
|
b579b3 |
const unsigned char *sym = font8x8data[c];
|
|
|
b579b3 |
for(int yy = y, ey = y + 8; yy < ey; ++yy, ++sym) {
|
|
|
b579b3 |
if (yy >= 0 && yy < h) {
|
|
|
b579b3 |
unsigned char row = *sym;
|
|
|
b579b3 |
for(int xx = x; row; ++xx, row >>= 1)
|
|
|
b579b3 |
if ((row & 1) && xx >= 0 && xx <= w)
|
|
|
b579b3 |
memcpy(data + (yy*w + xx)*ch, color, ch);
|
|
|
b579b3 |
}
|
|
|
b579b3 |
}
|
|
|
b579b3 |
x += 8;
|
|
|
b579b3 |
}
|
|
|
b579b3 |
}
|
|
|
b579b3 |
|
|
|
b579b3 |
|
|
|
b579b3 |
void imgPrintf(unsigned char *data, int w, int h, int ch, int x, int y, const unsigned char *color, const char *format, ...) {
|
|
|
b579b3 |
char buf[1024] = {};
|
|
|
b579b3 |
va_list args;
|
|
|
b579b3 |
va_start(args, format);
|
|
|
b579b3 |
vsnprintf(buf, sizeof(buf),format, args);
|
|
|
b579b3 |
va_end(args);
|
|
|
b579b3 |
imgPrint(data, w, h, ch, x, y, color, buf);
|
|
|
b579b3 |
}
|
|
|
b579b3 |
|
|
|
b579b3 |
|
|
|
b579b3 |
|
|
|
b579b3 |
#endif
|
|
|
b579b3 |
|