More pass by reference changes

This commit is contained in:
Dave Allie 2025-12-06 15:50:11 +11:00
parent 5ed2fe391d
commit 4ecfdea1a1
No known key found for this signature in database
GPG Key ID: F2FDDB3AD8D0276F
7 changed files with 42 additions and 37 deletions

View File

@ -2,8 +2,6 @@
#include <Utf8.h> #include <Utf8.h>
EpdFont::EpdFont(const EpdFontData* data) { this->data = data; }
inline int min(const int a, const int b) { return a < b ? a : b; } inline int min(const int a, const int b) { return a < b ? a : b; }
inline int max(const int a, const int b) { return a < b ? b : a; } inline int max(const int a, const int b) { return a < b ? b : a; }

View File

@ -6,7 +6,7 @@ class EpdFont {
public: public:
const EpdFontData* data; const EpdFontData* data;
explicit EpdFont(const EpdFontData* data); explicit EpdFont(const EpdFontData* data) : data(data) {}
~EpdFont() = default; ~EpdFont() = default;
void getTextDimensions(const char* string, int* w, int* h) const; void getTextDimensions(const char* string, int* w, int* h) const;
bool hasPrintableChars(const char* string) const; bool hasPrintableChars(const char* string) const;

View File

@ -11,12 +11,12 @@ static tinfl_decompressor decomp;
template <typename Renderable> template <typename Renderable>
class EpdFontRenderer { class EpdFontRenderer {
Renderable* renderer; Renderable& renderer;
void renderChar(uint32_t cp, int* x, const int* y, uint16_t color, EpdFontStyle style = REGULAR); void renderChar(uint32_t cp, int* x, const int* y, uint16_t color, EpdFontStyle style = REGULAR);
public: public:
const EpdFontFamily* fontFamily; const EpdFontFamily* fontFamily;
explicit EpdFontRenderer(const EpdFontFamily* fontFamily, Renderable* renderer) explicit EpdFontRenderer(const EpdFontFamily* fontFamily, Renderable& renderer)
: fontFamily(fontFamily), renderer(renderer) {} : fontFamily(fontFamily), renderer(renderer) {}
~EpdFontRenderer() = default; ~EpdFontRenderer() = default;
void renderString(const char* string, int* x, int* y, uint16_t color, EpdFontStyle style = REGULAR); void renderString(const char* string, int* x, int* y, uint16_t color, EpdFontStyle style = REGULAR);
@ -113,7 +113,7 @@ void EpdFontRenderer<Renderable>::renderChar(const uint32_t cp, int* x, const in
} }
if (bm) { if (bm) {
renderer->drawPixel(xx, yy, color); renderer.drawPixel(xx, yy, color);
} }
byteComplete = !byteComplete; byteComplete = !byteComplete;
localX++; localX++;

View File

@ -8,21 +8,30 @@
#include "builtinFonts/ubuntu_10.h" #include "builtinFonts/ubuntu_10.h"
#include "builtinFonts/ubuntu_bold_10.h" #include "builtinFonts/ubuntu_bold_10.h"
EpdRenderer::EpdRenderer(XteinkDisplay* display) { EpdFont bookerlyFont(&bookerly);
const auto bookerlyFontFamily = new EpdFontFamily(new EpdFont(&bookerly), new EpdFont(&bookerly_bold), EpdFont bookerlyBoldFont(&bookerly_bold);
new EpdFont(&bookerly_italic), new EpdFont(&bookerly_bold_italic)); EpdFont bookerlyItalicFont(&bookerly_italic);
const auto ubuntuFontFamily = new EpdFontFamily(new EpdFont(&ubuntu_10), new EpdFont(&ubuntu_bold_10)); EpdFont bookerlyBoldItalicFont(&bookerly_bold_italic);
EpdFontFamily bookerlyFontFamily(&bookerlyFont, &bookerlyBoldFont, &bookerlyItalicFont, &bookerlyBoldItalicFont);
this->display = display; EpdFont smallFont(&babyblue);
this->regularFontRenderer = new EpdFontRenderer<XteinkDisplay>(bookerlyFontFamily, display); EpdFontFamily smallFontFamily(&smallFont);
this->smallFontRenderer = new EpdFontRenderer<XteinkDisplay>(new EpdFontFamily(new EpdFont(&babyblue)), display);
this->uiFontRenderer = new EpdFontRenderer<XteinkDisplay>(ubuntuFontFamily, display);
this->marginTop = 11; EpdFont ubuntu10Font(&ubuntu_10);
this->marginBottom = 30; EpdFont ununtuBold10Font(&ubuntu_bold_10);
this->marginLeft = 10; EpdFontFamily ubuntuFontFamily(&ubuntu10Font, &ununtuBold10Font);
this->marginRight = 10;
this->lineCompression = 0.95f; EpdRenderer::EpdRenderer(XteinkDisplay& display)
: display(display), marginTop(11), marginBottom(30), marginLeft(10), marginRight(10), lineCompression(0.95f) {
this->regularFontRenderer = new EpdFontRenderer<XteinkDisplay>(&bookerlyFontFamily, display);
this->smallFontRenderer = new EpdFontRenderer<XteinkDisplay>(&smallFontFamily, display);
this->uiFontRenderer = new EpdFontRenderer<XteinkDisplay>(&ubuntuFontFamily, display);
}
EpdRenderer::~EpdRenderer() {
delete regularFontRenderer;
delete smallFontRenderer;
delete uiFontRenderer;
} }
int EpdRenderer::getTextWidth(const char* text, const EpdFontStyle style) const { int EpdRenderer::getTextWidth(const char* text, const EpdFontStyle style) const {
@ -107,24 +116,24 @@ void EpdRenderer::drawTextBox(const int x, const int y, const std::string& text,
} }
void EpdRenderer::drawLine(int x1, int y1, int x2, int y2, uint16_t color) const { void EpdRenderer::drawLine(int x1, int y1, int x2, int y2, uint16_t color) const {
display->drawLine(x1 + marginLeft, y1 + marginTop, x2 + marginLeft, y2 + marginTop, display.drawLine(x1 + marginLeft, y1 + marginTop, x2 + marginLeft, y2 + marginTop,
color > 0 ? GxEPD_BLACK : GxEPD_WHITE); color > 0 ? GxEPD_BLACK : GxEPD_WHITE);
} }
void EpdRenderer::drawRect(const int x, const int y, const int width, const int height, const uint16_t color) const { void EpdRenderer::drawRect(const int x, const int y, const int width, const int height, const uint16_t color) const {
display->drawRect(x + marginLeft, y + marginTop, width, height, color > 0 ? GxEPD_BLACK : GxEPD_WHITE); display.drawRect(x + marginLeft, y + marginTop, width, height, color > 0 ? GxEPD_BLACK : GxEPD_WHITE);
} }
void EpdRenderer::fillRect(const int x, const int y, const int width, const int height, const uint16_t color) const { void EpdRenderer::fillRect(const int x, const int y, const int width, const int height, const uint16_t color) const {
display->fillRect(x + marginLeft, y + marginTop, width, height, color > 0 ? GxEPD_BLACK : GxEPD_WHITE); display.fillRect(x + marginLeft, y + marginTop, width, height, color > 0 ? GxEPD_BLACK : GxEPD_WHITE);
} }
void EpdRenderer::drawCircle(const int x, const int y, const int radius, const uint16_t color) const { void EpdRenderer::drawCircle(const int x, const int y, const int radius, const uint16_t color) const {
display->drawCircle(x + marginLeft, y + marginTop, radius, color > 0 ? GxEPD_BLACK : GxEPD_WHITE); display.drawCircle(x + marginLeft, y + marginTop, radius, color > 0 ? GxEPD_BLACK : GxEPD_WHITE);
} }
void EpdRenderer::fillCircle(const int x, const int y, const int radius, const uint16_t color) const { void EpdRenderer::fillCircle(const int x, const int y, const int radius, const uint16_t color) const {
display->fillCircle(x + marginLeft, y + marginTop, radius, color > 0 ? GxEPD_BLACK : GxEPD_WHITE); display.fillCircle(x + marginLeft, y + marginTop, radius, color > 0 ? GxEPD_BLACK : GxEPD_WHITE);
} }
void EpdRenderer::drawImage(const uint8_t bitmap[], const int x, const int y, const int width, const int height, void EpdRenderer::drawImage(const uint8_t bitmap[], const int x, const int y, const int width, const int height,
@ -134,23 +143,23 @@ void EpdRenderer::drawImage(const uint8_t bitmap[], const int x, const int y, co
void EpdRenderer::drawImageNoMargin(const uint8_t bitmap[], const int x, const int y, const int width, const int height, void EpdRenderer::drawImageNoMargin(const uint8_t bitmap[], const int x, const int y, const int width, const int height,
const bool invert, const bool mirrorY) const { const bool invert, const bool mirrorY) const {
display->drawImage(bitmap, x, y, width, height, invert, mirrorY); display.drawImage(bitmap, x, y, width, height, invert, mirrorY);
} }
void EpdRenderer::clearScreen(const bool black) const { void EpdRenderer::clearScreen(const bool black) const {
Serial.println("Clearing screen"); Serial.println("Clearing screen");
display->fillScreen(black ? GxEPD_BLACK : GxEPD_WHITE); display.fillScreen(black ? GxEPD_BLACK : GxEPD_WHITE);
} }
void EpdRenderer::flushDisplay(const bool partialUpdate) const { display->display(partialUpdate); } void EpdRenderer::flushDisplay(const bool partialUpdate) const { display.display(partialUpdate); }
void EpdRenderer::flushArea(const int x, const int y, const int width, const int height) const { void EpdRenderer::flushArea(const int x, const int y, const int width, const int height) const {
display->displayWindow(x + marginLeft, y + marginTop, width, height); display.displayWindow(x + marginLeft, y + marginTop, width, height);
} }
int EpdRenderer::getPageWidth() const { return display->width() - marginLeft - marginRight; } int EpdRenderer::getPageWidth() const { return display.width() - marginLeft - marginRight; }
int EpdRenderer::getPageHeight() const { return display->height() - marginTop - marginBottom; } int EpdRenderer::getPageHeight() const { return display.height() - marginTop - marginBottom; }
int EpdRenderer::getSpaceWidth() const { return regularFontRenderer->fontFamily->getGlyph(' ', REGULAR)->advanceX; } int EpdRenderer::getSpaceWidth() const { return regularFontRenderer->fontFamily->getGlyph(' ', REGULAR)->advanceX; }

View File

@ -7,7 +7,7 @@
#define XteinkDisplay GxEPD2_BW<GxEPD2_426_GDEQ0426T82, GxEPD2_426_GDEQ0426T82::HEIGHT> #define XteinkDisplay GxEPD2_BW<GxEPD2_426_GDEQ0426T82, GxEPD2_426_GDEQ0426T82::HEIGHT>
class EpdRenderer { class EpdRenderer {
XteinkDisplay* display; XteinkDisplay& display;
EpdFontRenderer<XteinkDisplay>* regularFontRenderer; EpdFontRenderer<XteinkDisplay>* regularFontRenderer;
EpdFontRenderer<XteinkDisplay>* smallFontRenderer; EpdFontRenderer<XteinkDisplay>* smallFontRenderer;
EpdFontRenderer<XteinkDisplay>* uiFontRenderer; EpdFontRenderer<XteinkDisplay>* uiFontRenderer;
@ -18,8 +18,8 @@ class EpdRenderer {
float lineCompression; float lineCompression;
public: public:
explicit EpdRenderer(XteinkDisplay* display); explicit EpdRenderer(XteinkDisplay& display);
~EpdRenderer() = default; ~EpdRenderer();
int getTextWidth(const char* text, EpdFontStyle style = REGULAR) const; int getTextWidth(const char* text, EpdFontStyle style = REGULAR) const;
int getUiTextWidth(const char* text, EpdFontStyle style = REGULAR) const; int getUiTextWidth(const char* text, EpdFontStyle style = REGULAR) const;
int getSmallTextWidth(const char* text, EpdFontStyle style = REGULAR) const; int getSmallTextWidth(const char* text, EpdFontStyle style = REGULAR) const;

View File

@ -31,7 +31,7 @@
GxEPD2_BW<GxEPD2_426_GDEQ0426T82, GxEPD2_426_GDEQ0426T82::HEIGHT> display(GxEPD2_426_GDEQ0426T82(EPD_CS, EPD_DC, GxEPD2_BW<GxEPD2_426_GDEQ0426T82, GxEPD2_426_GDEQ0426T82::HEIGHT> display(GxEPD2_426_GDEQ0426T82(EPD_CS, EPD_DC,
EPD_RST, EPD_BUSY)); EPD_RST, EPD_BUSY));
InputManager inputManager; InputManager inputManager;
EpdRenderer renderer(&display); EpdRenderer renderer(display);
Screen* currentScreen; Screen* currentScreen;
CrossPointState appState; CrossPointState appState;

View File

@ -74,8 +74,6 @@ void EpubReaderScreen::handleInput() {
return; return;
} }
Serial.printf("Prev released: %d, Next released: %d\n", prevReleased, nextReleased);
const bool skipChapter = inputManager.getHeldTime() > SKIP_CHAPTER_MS; const bool skipChapter = inputManager.getHeldTime() > SKIP_CHAPTER_MS;
if (skipChapter) { if (skipChapter) {