1
0
mirror of https://github.com/jscrane/r65emu.git synced 2024-12-22 03:30:02 +00:00
r65emu/utftdisplay.cpp
2014-11-16 21:45:00 +00:00

55 lines
1002 B
C++

#include <UTFT.h>
#include "memory.h"
#include "utftdisplay.h"
#include "TinyFont.h"
extern UTFT utft;
void UTFTDisplay::begin(unsigned bg, unsigned fg) {
_bg = bg;
_fg = fg;
_dx = utft.getDisplayXSize();
_dy = utft.getDisplayYSize();
utft.setFont((uint8_t *)TinyFont);
utft.setColor(fg);
_cx = utft.getFontXsize();
_cy = utft.getFontYsize();
_oxs = _dx;
}
void UTFTDisplay::clear() {
utft.fillScr(_bg);
}
void UTFTDisplay::error(char *s)
{
utft.setColor(_fg);
char *lines[5];
int l = 0;
for (char *p = s, *q = s; *p; p++)
if (*p == '\n') {
*p++ = 0;
lines[l++] = q;
q = p;
}
unsigned y = (_dy - l*_cy)/2;
for (int i = 0; i < l; i++) {
char *p = lines[i];
unsigned x = (_dx - strlen(p)*_cx)/2;
utft.print(p, x, y);
y += _cy;
}
}
void UTFTDisplay::status(const char *s)
{
utft.setColor(_fg);
unsigned y = _dy - _cy, n = strlen(s), xs = _dx - n*_cx;
for (unsigned x = _oxs; x < xs; x += _cx)
utft.print(" ", x, y);
utft.print(s, xs, y);
_oxs = xs;
}