2026-10-15 19:43:59 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
#include "logic/font.h"
|
2026-10-20 17:52:25 +02:00
|
|
|
#include "logic/life.h"
|
2026-10-15 19:43:59 +02:00
|
|
|
#include "logic/local_time.h"
|
|
|
|
|
#include "logic/page.h"
|
|
|
|
|
|
|
|
|
|
// Draws a dynamic page into a full screen bitmap (logic/bitmap_format.h). Used for the
|
|
|
|
|
// display and for the previews in the web UI. Pure logic, tested in test/test_esp32.
|
|
|
|
|
|
2026-10-15 21:01:14 +02:00
|
|
|
// Where the page gets its bitmaps, fonts, Home Assistant values and the stopwatch
|
2026-10-15 19:43:59 +02:00
|
|
|
class PageResources
|
|
|
|
|
{
|
|
|
|
|
public:
|
2026-10-15 21:01:14 +02:00
|
|
|
// Loads a bitmap (background or image); false when it is gone
|
2026-10-15 19:43:59 +02:00
|
|
|
virtual bool background(const char *name, uint8_t *bitmap) = 0;
|
|
|
|
|
// A font by name; a font without data when it is gone ("Normal" is used then)
|
|
|
|
|
virtual Font font(const char *name) = 0;
|
|
|
|
|
// The current value of a Home Assistant element; nullptr when not known
|
|
|
|
|
virtual const char *haValue(const PageElement &element) = 0;
|
2026-10-15 21:01:14 +02:00
|
|
|
virtual uint32_t stopwatchMs() { return 0; }
|
|
|
|
|
virtual bool stopwatchRunning() { return false; }
|
2026-10-20 17:52:25 +02:00
|
|
|
// The running Game of Life of the shown page when this element starts like it
|
|
|
|
|
// (sameLifeStart); nullptr otherwise (the start is drawn then)
|
|
|
|
|
virtual const LifeRunner *life(const PageElement &) { return nullptr; }
|
2026-10-15 19:43:59 +02:00
|
|
|
};
|
|
|
|
|
|
2026-10-15 21:01:14 +02:00
|
|
|
// The area an element covers on the screen (for the editor), may be partly off screen.
|
|
|
|
|
// For scrolling texts, the window.
|
2026-10-15 19:43:59 +02:00
|
|
|
struct ElementBox
|
|
|
|
|
{
|
|
|
|
|
int16_t x = 0;
|
|
|
|
|
int16_t y = 0;
|
|
|
|
|
int16_t width = 0;
|
|
|
|
|
int16_t height = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2026-10-15 21:01:14 +02:00
|
|
|
// now_ms: a running millisecond counter (millis()), for scrolling. boxes: nullptr, or room
|
|
|
|
|
// for page.element_count boxes.
|
|
|
|
|
// Returns the ms until the page looks different again (scrolling, seconds, a running
|
2026-10-20 17:52:25 +02:00
|
|
|
// stopwatch, the next generation of a Game of Life), or 0 when it only changes with the minute or its content (Home Assistant
|
2026-10-15 21:01:14 +02:00
|
|
|
// values, the stopwatch being started or stopped).
|
|
|
|
|
uint32_t renderPage(const DynamicPage &page, const LocalTime &time, uint32_t now_ms, PageResources &resources,
|
|
|
|
|
uint8_t *bitmap, ElementBox *boxes = nullptr);
|