Public Access
58 lines
1.7 KiB
C++
58 lines
1.7 KiB
C++
#include "logic/page_render.h"
|
|||
|
|
|
||
|
|
#include <string.h>
|
||
|
|
|
||
|
|
#include "logic/bitmap_format.h"
|
||
|
|
#include "logic/builtin_fonts.h"
|
||
|
|
|
||
|
|
static Font usableFont(PageResources &resources, const char *name)
|
||
|
|
{
|
||
|
|
Font font = resources.font(name);
|
||
|
|
if (validFont(font.data, font.size) && font.scale >= 1)
|
||
|
|
return font;
|
||
|
|
return builtinFont(*findBuiltinFont(FONT_NORMAL_NAME));
|
||
|
|
}
|
||
|
|
|
||
|
|
static void clearBox(uint8_t *bitmap, int x, int y, int width, int height)
|
||
|
|
{
|
||
|
|
for (int yy = y; yy < y + height; yy++)
|
||
|
|
for (int xx = x; xx < x + width; xx++)
|
||
|
|
setBitmapPixel(bitmap, xx, yy, false);
|
||
|
|
}
|
||
|
|
|
||
|
|
void renderPage(const DynamicPage &page, const LocalTime &time, PageResources &resources, uint8_t *bitmap,
|
||
|
|
ElementBox *boxes)
|
||
|
|
{
|
||
|
|
memset(bitmap, 0, BITMAP_BYTES);
|
||
|
|
const PageSlot *slot = activeSlot(page, time.hour * 60 + time.minute);
|
||
|
|
if (slot && slot->bitmap[0] && !resources.background(slot->bitmap, bitmap))
|
||
|
|
memset(bitmap, 0, BITMAP_BYTES);
|
||
|
|
|
||
|
|
for (int i = 0; i < page.element_count && i < PAGE_ELEMENTS; i++)
|
||
|
|
{
|
||
|
|
const PageElement &e = page.elements[i];
|
||
|
|
const char *ha_value = e.type == ElementType::HaValue ? resources.haValue(e) : nullptr;
|
||
|
|
char text[64];
|
||
|
|
elementText(e, time, ha_value, text, sizeof(text));
|
||
|
|
|
||
|
|
Font font = usableFont(resources, e.font);
|
||
|
|
int width = textWidth(font, text), height = fontHeight(font);
|
||
|
|
int x = e.x;
|
||
|
|
if (e.align == Align::Center)
|
||
|
|
x -= width / 2;
|
||
|
|
else if (e.align == Align::Right)
|
||
|
|
x -= width;
|
||
|
|
|
||
|
|
if (e.overlay == Overlay::Box)
|
||
|
|
clearBox(bitmap, x - 1, e.y - 1, width + 2, height + 2);
|
||
|
|
drawText(bitmap, font, x, e.y, text, e.overlay == Overlay::Invert ? DrawMode::Invert : DrawMode::Set);
|
||
|
|
|
||
|
|
if (boxes)
|
||
|
|
{
|
||
|
|
boxes[i].x = x;
|
||
|
|
boxes[i].y = e.y;
|
||
|
|
boxes[i].width = width;
|
||
|
|
boxes[i].height = height;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|