2025-12-08 22:06:09 +11:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <EInkDisplay.h>
|
2025-12-12 22:13:34 +11:00
|
|
|
#include <EpdFontFamily.h>
|
2025-12-19 08:45:14 +11:00
|
|
|
#include <FS.h>
|
2025-12-08 22:06:09 +11:00
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
2025-12-19 08:45:14 +11:00
|
|
|
#include "Bitmap.h"
|
|
|
|
|
|
2025-12-08 22:06:09 +11:00
|
|
|
class GfxRenderer {
|
|
|
|
|
public:
|
2025-12-16 02:16:35 +11:00
|
|
|
enum RenderMode { BW, GRAYSCALE_LSB, GRAYSCALE_MSB };
|
2025-12-08 22:06:09 +11:00
|
|
|
|
2025-12-19 22:28:17 -05:00
|
|
|
// Logical screen orientation from the perspective of callers
|
|
|
|
|
enum class Orientation {
|
|
|
|
|
Portrait, // 480x800 logical coordinates (current default)
|
|
|
|
|
LandscapeNormal, // 800x480 logical coordinates, native panel orientation
|
|
|
|
|
LandscapeFlipped // 800x480 logical coordinates, rotated 180° (swap top/bottom)
|
|
|
|
|
};
|
|
|
|
|
|
2025-12-08 22:06:09 +11:00
|
|
|
private:
|
2025-12-17 01:39:22 +11:00
|
|
|
static constexpr size_t BW_BUFFER_CHUNK_SIZE = 8000; // 8KB chunks to allow for non-contiguous memory
|
|
|
|
|
static constexpr size_t BW_BUFFER_NUM_CHUNKS = EInkDisplay::BUFFER_SIZE / BW_BUFFER_CHUNK_SIZE;
|
|
|
|
|
static_assert(BW_BUFFER_CHUNK_SIZE * BW_BUFFER_NUM_CHUNKS == EInkDisplay::BUFFER_SIZE,
|
|
|
|
|
"BW buffer chunking does not line up with display buffer size");
|
|
|
|
|
|
2025-12-28 19:46:00 +11:00
|
|
|
// Orientation used for all rendering operations
|
|
|
|
|
Orientation orientation;
|
2025-12-19 22:28:17 -05:00
|
|
|
|
2025-12-08 22:06:09 +11:00
|
|
|
EInkDisplay& einkDisplay;
|
2025-12-16 02:16:35 +11:00
|
|
|
RenderMode renderMode;
|
2025-12-17 01:39:22 +11:00
|
|
|
uint8_t* bwBufferChunks[BW_BUFFER_NUM_CHUNKS] = {nullptr};
|
2025-12-08 22:06:09 +11:00
|
|
|
std::map<int, EpdFontFamily> fontMap;
|
|
|
|
|
void renderChar(const EpdFontFamily& fontFamily, uint32_t cp, int* x, const int* y, bool pixelState,
|
|
|
|
|
EpdFontStyle style) const;
|
2025-12-17 01:39:22 +11:00
|
|
|
void freeBwBufferChunks();
|
2025-12-08 22:06:09 +11:00
|
|
|
|
|
|
|
|
public:
|
2025-12-16 02:16:35 +11:00
|
|
|
explicit GfxRenderer(EInkDisplay& einkDisplay) : einkDisplay(einkDisplay), renderMode(BW) {}
|
2025-12-08 22:06:09 +11:00
|
|
|
~GfxRenderer() = default;
|
|
|
|
|
|
|
|
|
|
// Setup
|
|
|
|
|
void insertFont(int fontId, EpdFontFamily font);
|
|
|
|
|
|
2025-12-19 22:28:17 -05:00
|
|
|
// Orientation control (affects logical width/height and coordinate transforms)
|
2025-12-28 19:46:00 +11:00
|
|
|
void setOrientation(const Orientation o) { orientation = o; }
|
|
|
|
|
Orientation getOrientation() const { return orientation; }
|
2025-12-19 22:28:17 -05:00
|
|
|
|
2025-12-08 22:06:09 +11:00
|
|
|
// Screen ops
|
2025-12-28 19:46:00 +11:00
|
|
|
int getScreenWidth() const;
|
|
|
|
|
int getScreenHeight() const;
|
2025-12-08 22:06:09 +11:00
|
|
|
void displayBuffer(EInkDisplay::RefreshMode refreshMode = EInkDisplay::FAST_REFRESH) const;
|
2025-12-19 22:28:17 -05:00
|
|
|
// EXPERIMENTAL: Windowed update - display only a rectangular region
|
2025-12-17 00:17:49 +11:00
|
|
|
void displayWindow(int x, int y, int width, int height) const;
|
2025-12-08 22:06:09 +11:00
|
|
|
void invertScreen() const;
|
|
|
|
|
void clearScreen(uint8_t color = 0xFF) const;
|
|
|
|
|
|
|
|
|
|
// Drawing
|
|
|
|
|
void drawPixel(int x, int y, bool state = true) const;
|
|
|
|
|
void drawLine(int x1, int y1, int x2, int y2, bool state = true) const;
|
|
|
|
|
void drawRect(int x, int y, int width, int height, bool state = true) const;
|
|
|
|
|
void fillRect(int x, int y, int width, int height, bool state = true) const;
|
|
|
|
|
void drawImage(const uint8_t bitmap[], int x, int y, int width, int height) const;
|
2025-12-19 08:45:14 +11:00
|
|
|
void drawBitmap(const Bitmap& bitmap, int x, int y, int maxWidth, int maxHeight) const;
|
2025-12-08 22:06:09 +11:00
|
|
|
|
|
|
|
|
// Text
|
|
|
|
|
int getTextWidth(int fontId, const char* text, EpdFontStyle style = REGULAR) const;
|
2025-12-08 22:52:19 +11:00
|
|
|
void drawCenteredText(int fontId, int y, const char* text, bool black = true, EpdFontStyle style = REGULAR) const;
|
2025-12-08 22:06:09 +11:00
|
|
|
void drawText(int fontId, int x, int y, const char* text, bool black = true, EpdFontStyle style = REGULAR) const;
|
|
|
|
|
int getSpaceWidth(int fontId) const;
|
|
|
|
|
int getLineHeight(int fontId) const;
|
|
|
|
|
|
2025-12-25 19:54:02 -05:00
|
|
|
// UI Components
|
|
|
|
|
void drawButtonHints(int fontId, const char* btn1, const char* btn2, const char* btn3, const char* btn4) const;
|
|
|
|
|
|
2025-12-16 02:16:35 +11:00
|
|
|
// Grayscale functions
|
|
|
|
|
void setRenderMode(const RenderMode mode) { this->renderMode = mode; }
|
|
|
|
|
void copyGrayscaleLsbBuffers() const;
|
|
|
|
|
void copyGrayscaleMsbBuffers() const;
|
|
|
|
|
void displayGrayBuffer() const;
|
2025-12-17 00:17:49 +11:00
|
|
|
void storeBwBuffer();
|
|
|
|
|
void restoreBwBuffer();
|
2025-12-16 02:16:35 +11:00
|
|
|
|
2025-12-08 22:06:09 +11:00
|
|
|
// Low level functions
|
2025-12-13 16:02:27 +11:00
|
|
|
uint8_t* getFrameBuffer() const;
|
2025-12-17 00:17:49 +11:00
|
|
|
static size_t getBufferSize();
|
2025-12-13 16:02:27 +11:00
|
|
|
void grayscaleRevert() const;
|
2025-12-08 22:06:09 +11:00
|
|
|
};
|