scaled rendering update
This commit is contained in:
@@ -2,19 +2,21 @@
|
||||
|
||||
#include <esp_log.h>
|
||||
|
||||
void gfx_draw_char(const gfx_canvas_t *canvas, const GFXfont *f, const bool inverted, const int16_t x, const int16_t y, const char c) {
|
||||
void (*draw_cb)(void* ctx, uint8_t x, uint8_t y) = inverted ? canvas->clear_pixel_callback : canvas->draw_pixel_callback;
|
||||
if (c < f->first || c > f->last) return;
|
||||
|
||||
const GFXglyph *g = &f->glyph[c - f->first];
|
||||
const uint8_t *bm = f->bitmap + g->bitmapOffset;
|
||||
|
||||
uint16_t bit = 0; // current bit index into bitmap bytes
|
||||
|
||||
for (uint8_t row = 0; row < g->height; row++)
|
||||
for (uint8_t col = 0; col < g->width; col++, bit++)
|
||||
if (bm[bit / 8] & (0x80 >> (bit & 7)))
|
||||
draw_cb(canvas->ctx, x + g->xOffset + col, y + g->yOffset + row);
|
||||
void gfx_draw_char(const gfx_canvas_t *canvas, const GFXfont *f, const bool inverted, const int16_t x, const int16_t y, const char c, const uint8_t scale) {
|
||||
void (*draw_cb)(void* ctx, uint8_t x, uint8_t y) = inverted ? canvas->clear_pixel_callback : canvas->draw_pixel_callback;
|
||||
if (c < f->first || c > f->last) return;
|
||||
const GFXglyph *g = &f->glyph[c - f->first];
|
||||
const uint8_t *bm = f->bitmap + g->bitmapOffset;
|
||||
uint16_t bit = 0; // current bit index into bitmap bytes
|
||||
for (uint8_t row = 0; row < g->height; row++)
|
||||
for (uint8_t col = 0; col < g->width; col++, bit++)
|
||||
if (bm[bit / 8] & (0x80 >> (bit & 7))) {
|
||||
const int16_t px = x + (g->xOffset + col) * scale;
|
||||
const int16_t py = y + (g->yOffset + row) * scale;
|
||||
for (uint8_t sy = 0; sy < scale; sy++)
|
||||
for (uint8_t sx = 0; sx < scale; sx++)
|
||||
draw_cb(canvas->ctx, px + sx, py + sy);
|
||||
}
|
||||
}
|
||||
|
||||
int16_t gfx_string_width(const GFXfont *f, const char *s) {
|
||||
@@ -28,16 +30,21 @@ int16_t gfx_string_width(const GFXfont *f, const char *s) {
|
||||
}
|
||||
|
||||
/* returns x position of the end of the string */
|
||||
int16_t gfx_draw_string(const gfx_canvas_t *canvas, const GFXfont *f, int16_t x, const int16_t y, const char *s, const bool inverted) {
|
||||
while (*s) {
|
||||
gfx_draw_char(canvas, f, inverted, x, y, *s);
|
||||
const char c = *s++;
|
||||
if (c >= f->first && c <= f->last)
|
||||
x += f->glyph[c - f->first].xAdvance;
|
||||
}
|
||||
return x;
|
||||
int16_t gfx_draw_string_scaled(const gfx_canvas_t *canvas, const GFXfont *f, int16_t x, const int16_t y, const char *s, const bool inverted, const uint8_t scale) {
|
||||
while (*s) {
|
||||
gfx_draw_char(canvas, f, inverted, x, y, *s, scale);
|
||||
const char c = *s++;
|
||||
if (c >= f->first && c <= f->last)
|
||||
x += f->glyph[c - f->first].xAdvance * scale;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
int16_t gfx_draw_string(const gfx_canvas_t *canvas, const GFXfont *f, const int16_t x, const int16_t y, const char *s, const bool inverted) {
|
||||
return gfx_draw_string_scaled(canvas, f, x, y, s, inverted, 1);
|
||||
}
|
||||
|
||||
|
||||
int16_t gfx_draw_string_centered(const gfx_canvas_t *canvas, const GFXfont *f, const int16_t centerpoint, const int16_t y, const char *s, const bool inverted) {
|
||||
const uint8_t x = centerpoint - gfx_string_width(f, s) / 2;
|
||||
return gfx_draw_string(canvas, f, x, y, s, inverted);
|
||||
|
||||
@@ -42,6 +42,7 @@ typedef struct {
|
||||
} gfx_canvas_t;
|
||||
|
||||
int16_t gfx_string_width(const GFXfont *f, const char *s);
|
||||
int16_t gfx_draw_string_scaled(const gfx_canvas_t *canvas, const GFXfont* f, int16_t x, int16_t y, const char *s, bool inverted, uint8_t scale);
|
||||
int16_t gfx_draw_string(const gfx_canvas_t *canvas, const GFXfont* f, int16_t x, int16_t y, const char *s, bool inverted);
|
||||
int16_t gfx_draw_string_centered(const gfx_canvas_t *canvas, const GFXfont *f, int16_t centerpoint, int16_t y, const char *s, bool inverted);
|
||||
void gfx_draw_line(const gfx_canvas_t *canvas, uint8_t start_x, uint8_t start_y, uint8_t end_x, uint8_t end_y, bool inverted);
|
||||
|
||||
Reference in New Issue
Block a user