-
Notifications
You must be signed in to change notification settings - Fork 13
/
espvgax2_print.h
145 lines (137 loc) · 3.76 KB
/
espvgax2_print.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//file included from ESPVGAX2.cpp
static ESPVGAX2_PROGMEM uint8_t *fnt=0;
static uint16_t glyphscount;
static uint8_t fntheight;
static uint8_t hspace;
static uint8_t vspace;
static uint8_t fntglyphw;
static bool bmpfont;
static bool bmpcolor;
static uint8_t bmpcolormask;
void ESPVGAX2::setFont(ESPVGAX2_PROGMEM uint8_t *fnt_, uint8_t glyphscount_,
uint8_t fntheight_, uint8_t fntglyphw_, uint8_t hspace_, uint8_t vspace_) {
fnt=fnt_;
glyphscount=glyphscount_;
fntheight=fntheight_;
bmpfont=false;
hspace=hspace_;
vspace=vspace_;
fntglyphw=fntglyphw_;
}
void ESPVGAX2::setBitmapFont(ESPVGAX2_PROGMEM uint8_t *bmp, uint8_t h, int gw) {
fnt=bmp;
glyphscount=256;
fntheight=h;
bmpfont=true;
hspace=0;
vspace=0;
fntglyphw=gw;
bmpcolor=false;
}
void ESPVGAX2::setBitmapFontColor(ESPVGAX2_PROGMEM uint8_t *bmp, uint8_t h,
uint8_t mask, int gw) {
setBitmapFont(bmp, h, gw);
bmpcolormask=mask;
bmpcolor=true;
}
#define PRINT_LOOP_CODE(reader) \
int cr_dx0=dx0override!=-1 ? dx0override : dx0; \
if (dy0>=ESPVGAX2_HEIGHT) \
calc=true; \
if (c=='\n') { \
dx=cr_dx0; \
dy0+=fntheight+vspace; \
} else if (c=='\e') { \
color=reader(pstr++); \
if (color==0xff) \
color=default_color; \
} else { \
if (bmpfont) { \
if (wrap && dx+8*fntglyphw>ESPVGAX2_WIDTH) { \
dx=cr_dx0; \
dy0+=fntheight; \
} \
uint8_t uc=0xff&((uint8_t)c); \
int bx=(uc%16); \
int by=fntheight*(uc/16); \
if (!calc) { \
if (bmpcolor) { \
blitwmask_P(fnt+(by*16+bx)*fntglyphw, \
dx, dy0, \
8*fntglyphw, \
fntheight, \
bmpcolormask, \
op, \
128*fntglyphw); \
} else { \
bitblit_P(fnt+(by*16+bx)*fntglyphw, \
dx, dy0, \
8*fntglyphw, \
fntheight, \
color, \
op, \
128*fntglyphw); \
} \
} \
dx+=8*fntglyphw; \
} else { \
c-=33; \
if (c>=0 && c<glyphscount) { \
/* calculate glyph bitmap address */ \
uint8_t *fntg=fnt+c*(4+fntheight*fntglyphw); \
/* read glyph width (first byte) */ \
uint8_t fntw=pgm_read_byte(fntg); \
if (wrap && dx+fntw>ESPVGAX2_WIDTH) { \
dx=cr_dx0; \
dy0+=fntheight+vspace; \
} \
if (!calc) { \
bitblit_P(fntg+4, \
dx, dy0, \
fntw, fntheight, \
color, \
op, \
8*fntglyphw); \
} \
if (bold) { \
if (!calc) \
bitblit_P(fntg+4, \
dx+1, dy0, \
fntw, \
fntheight, \
color, \
ESPVGAX2_OP_OR, \
8*fntglyphw); \
dx++; \
} \
dx+=fntw+1; \
} else { \
dx+=2+hspace; \
} \
} \
} \
if (dx>maxx) \
maxx=dx;
#define PRINTCODE(reader) \
int dx0=dx; \
int maxx=0; \
int dlen=len; \
uint8_t default_color=color; \
int8_t *pstr=(int8_t*)str; \
int8_t c; \
while (0!=(c=reader(pstr++))) { \
PRINT_LOOP_CODE(reader); \
if (len>-1 && --dlen<=0) \
break; \
} \
return PrintInfo(dx, dy0, maxx);
ESPVGAX2::PrintInfo ESPVGAX2::print_P(ESPVGAX2_PROGMEM const char *str, int dx,
int dy0, uint8_t color, bool wrap, int len, int op, bool bold,
int dx0override, bool calc) {
PRINTCODE(pgm_read_byte);
}
ESPVGAX2::PrintInfo ESPVGAX2::print(const char *str, int dx, int dy0,
uint8_t color, bool wrap, int len, int op, bool bold, int dx0override,
bool calc) {
PRINTCODE(*);
}