A fork of https://github.com/crosspoint-reader/crosspoint-reader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

More pass by reference changes

+42 -37
-2
lib/EpdFont/EpdFont.cpp
··· 2 2 3 3 #include <Utf8.h> 4 4 5 - EpdFont::EpdFont(const EpdFontData* data) { this->data = data; } 6 - 7 5 inline int min(const int a, const int b) { return a < b ? a : b; } 8 6 inline int max(const int a, const int b) { return a < b ? b : a; } 9 7
+1 -1
lib/EpdFont/EpdFont.h
··· 6 6 7 7 public: 8 8 const EpdFontData* data; 9 - explicit EpdFont(const EpdFontData* data); 9 + explicit EpdFont(const EpdFontData* data) : data(data) {} 10 10 ~EpdFont() = default; 11 11 void getTextDimensions(const char* string, int* w, int* h) const; 12 12 bool hasPrintableChars(const char* string) const;
+3 -3
lib/EpdFontRenderer/EpdFontRenderer.hpp
··· 11 11 12 12 template <typename Renderable> 13 13 class EpdFontRenderer { 14 - Renderable* renderer; 14 + Renderable& renderer; 15 15 void renderChar(uint32_t cp, int* x, const int* y, uint16_t color, EpdFontStyle style = REGULAR); 16 16 17 17 public: 18 18 const EpdFontFamily* fontFamily; 19 - explicit EpdFontRenderer(const EpdFontFamily* fontFamily, Renderable* renderer) 19 + explicit EpdFontRenderer(const EpdFontFamily* fontFamily, Renderable& renderer) 20 20 : fontFamily(fontFamily), renderer(renderer) {} 21 21 ~EpdFontRenderer() = default; 22 22 void renderString(const char* string, int* x, int* y, uint16_t color, EpdFontStyle style = REGULAR); ··· 113 113 } 114 114 115 115 if (bm) { 116 - renderer->drawPixel(xx, yy, color); 116 + renderer.drawPixel(xx, yy, color); 117 117 } 118 118 byteComplete = !byteComplete; 119 119 localX++;
+34 -25
lib/EpdRenderer/EpdRenderer.cpp
··· 8 8 #include "builtinFonts/ubuntu_10.h" 9 9 #include "builtinFonts/ubuntu_bold_10.h" 10 10 11 - EpdRenderer::EpdRenderer(XteinkDisplay* display) { 12 - const auto bookerlyFontFamily = new EpdFontFamily(new EpdFont(&bookerly), new EpdFont(&bookerly_bold), 13 - new EpdFont(&bookerly_italic), new EpdFont(&bookerly_bold_italic)); 14 - const auto ubuntuFontFamily = new EpdFontFamily(new EpdFont(&ubuntu_10), new EpdFont(&ubuntu_bold_10)); 11 + EpdFont bookerlyFont(&bookerly); 12 + EpdFont bookerlyBoldFont(&bookerly_bold); 13 + EpdFont bookerlyItalicFont(&bookerly_italic); 14 + EpdFont bookerlyBoldItalicFont(&bookerly_bold_italic); 15 + EpdFontFamily bookerlyFontFamily(&bookerlyFont, &bookerlyBoldFont, &bookerlyItalicFont, &bookerlyBoldItalicFont); 15 16 16 - this->display = display; 17 - this->regularFontRenderer = new EpdFontRenderer<XteinkDisplay>(bookerlyFontFamily, display); 18 - this->smallFontRenderer = new EpdFontRenderer<XteinkDisplay>(new EpdFontFamily(new EpdFont(&babyblue)), display); 19 - this->uiFontRenderer = new EpdFontRenderer<XteinkDisplay>(ubuntuFontFamily, display); 17 + EpdFont smallFont(&babyblue); 18 + EpdFontFamily smallFontFamily(&smallFont); 19 + 20 + EpdFont ubuntu10Font(&ubuntu_10); 21 + EpdFont ununtuBold10Font(&ubuntu_bold_10); 22 + EpdFontFamily ubuntuFontFamily(&ubuntu10Font, &ununtuBold10Font); 23 + 24 + EpdRenderer::EpdRenderer(XteinkDisplay& display) 25 + : display(display), marginTop(11), marginBottom(30), marginLeft(10), marginRight(10), lineCompression(0.95f) { 26 + this->regularFontRenderer = new EpdFontRenderer<XteinkDisplay>(&bookerlyFontFamily, display); 27 + this->smallFontRenderer = new EpdFontRenderer<XteinkDisplay>(&smallFontFamily, display); 28 + this->uiFontRenderer = new EpdFontRenderer<XteinkDisplay>(&ubuntuFontFamily, display); 29 + } 20 30 21 - this->marginTop = 11; 22 - this->marginBottom = 30; 23 - this->marginLeft = 10; 24 - this->marginRight = 10; 25 - this->lineCompression = 0.95f; 31 + EpdRenderer::~EpdRenderer() { 32 + delete regularFontRenderer; 33 + delete smallFontRenderer; 34 + delete uiFontRenderer; 26 35 } 27 36 28 37 int EpdRenderer::getTextWidth(const char* text, const EpdFontStyle style) const { ··· 107 116 } 108 117 109 118 void EpdRenderer::drawLine(int x1, int y1, int x2, int y2, uint16_t color) const { 110 - display->drawLine(x1 + marginLeft, y1 + marginTop, x2 + marginLeft, y2 + marginTop, 111 - color > 0 ? GxEPD_BLACK : GxEPD_WHITE); 119 + display.drawLine(x1 + marginLeft, y1 + marginTop, x2 + marginLeft, y2 + marginTop, 120 + color > 0 ? GxEPD_BLACK : GxEPD_WHITE); 112 121 } 113 122 114 123 void EpdRenderer::drawRect(const int x, const int y, const int width, const int height, const uint16_t color) const { 115 - display->drawRect(x + marginLeft, y + marginTop, width, height, color > 0 ? GxEPD_BLACK : GxEPD_WHITE); 124 + display.drawRect(x + marginLeft, y + marginTop, width, height, color > 0 ? GxEPD_BLACK : GxEPD_WHITE); 116 125 } 117 126 118 127 void EpdRenderer::fillRect(const int x, const int y, const int width, const int height, const uint16_t color) const { 119 - display->fillRect(x + marginLeft, y + marginTop, width, height, color > 0 ? GxEPD_BLACK : GxEPD_WHITE); 128 + display.fillRect(x + marginLeft, y + marginTop, width, height, color > 0 ? GxEPD_BLACK : GxEPD_WHITE); 120 129 } 121 130 122 131 void EpdRenderer::drawCircle(const int x, const int y, const int radius, const uint16_t color) const { 123 - display->drawCircle(x + marginLeft, y + marginTop, radius, color > 0 ? GxEPD_BLACK : GxEPD_WHITE); 132 + display.drawCircle(x + marginLeft, y + marginTop, radius, color > 0 ? GxEPD_BLACK : GxEPD_WHITE); 124 133 } 125 134 126 135 void EpdRenderer::fillCircle(const int x, const int y, const int radius, const uint16_t color) const { 127 - display->fillCircle(x + marginLeft, y + marginTop, radius, color > 0 ? GxEPD_BLACK : GxEPD_WHITE); 136 + display.fillCircle(x + marginLeft, y + marginTop, radius, color > 0 ? GxEPD_BLACK : GxEPD_WHITE); 128 137 } 129 138 130 139 void EpdRenderer::drawImage(const uint8_t bitmap[], const int x, const int y, const int width, const int height, ··· 134 143 135 144 void EpdRenderer::drawImageNoMargin(const uint8_t bitmap[], const int x, const int y, const int width, const int height, 136 145 const bool invert, const bool mirrorY) const { 137 - display->drawImage(bitmap, x, y, width, height, invert, mirrorY); 146 + display.drawImage(bitmap, x, y, width, height, invert, mirrorY); 138 147 } 139 148 140 149 void EpdRenderer::clearScreen(const bool black) const { 141 150 Serial.println("Clearing screen"); 142 - display->fillScreen(black ? GxEPD_BLACK : GxEPD_WHITE); 151 + display.fillScreen(black ? GxEPD_BLACK : GxEPD_WHITE); 143 152 } 144 153 145 - void EpdRenderer::flushDisplay(const bool partialUpdate) const { display->display(partialUpdate); } 154 + void EpdRenderer::flushDisplay(const bool partialUpdate) const { display.display(partialUpdate); } 146 155 147 156 void EpdRenderer::flushArea(const int x, const int y, const int width, const int height) const { 148 - display->displayWindow(x + marginLeft, y + marginTop, width, height); 157 + display.displayWindow(x + marginLeft, y + marginTop, width, height); 149 158 } 150 159 151 - int EpdRenderer::getPageWidth() const { return display->width() - marginLeft - marginRight; } 160 + int EpdRenderer::getPageWidth() const { return display.width() - marginLeft - marginRight; } 152 161 153 - int EpdRenderer::getPageHeight() const { return display->height() - marginTop - marginBottom; } 162 + int EpdRenderer::getPageHeight() const { return display.height() - marginTop - marginBottom; } 154 163 155 164 int EpdRenderer::getSpaceWidth() const { return regularFontRenderer->fontFamily->getGlyph(' ', REGULAR)->advanceX; } 156 165
+3 -3
lib/EpdRenderer/EpdRenderer.h
··· 7 7 #define XteinkDisplay GxEPD2_BW<GxEPD2_426_GDEQ0426T82, GxEPD2_426_GDEQ0426T82::HEIGHT> 8 8 9 9 class EpdRenderer { 10 - XteinkDisplay* display; 10 + XteinkDisplay& display; 11 11 EpdFontRenderer<XteinkDisplay>* regularFontRenderer; 12 12 EpdFontRenderer<XteinkDisplay>* smallFontRenderer; 13 13 EpdFontRenderer<XteinkDisplay>* uiFontRenderer; ··· 18 18 float lineCompression; 19 19 20 20 public: 21 - explicit EpdRenderer(XteinkDisplay* display); 22 - ~EpdRenderer() = default; 21 + explicit EpdRenderer(XteinkDisplay& display); 22 + ~EpdRenderer(); 23 23 int getTextWidth(const char* text, EpdFontStyle style = REGULAR) const; 24 24 int getUiTextWidth(const char* text, EpdFontStyle style = REGULAR) const; 25 25 int getSmallTextWidth(const char* text, EpdFontStyle style = REGULAR) const;
+1 -1
src/main.cpp
··· 31 31 GxEPD2_BW<GxEPD2_426_GDEQ0426T82, GxEPD2_426_GDEQ0426T82::HEIGHT> display(GxEPD2_426_GDEQ0426T82(EPD_CS, EPD_DC, 32 32 EPD_RST, EPD_BUSY)); 33 33 InputManager inputManager; 34 - EpdRenderer renderer(&display); 34 + EpdRenderer renderer(display); 35 35 Screen* currentScreen; 36 36 CrossPointState appState; 37 37
-2
src/screens/EpubReaderScreen.cpp
··· 74 74 return; 75 75 } 76 76 77 - Serial.printf("Prev released: %d, Next released: %d\n", prevReleased, nextReleased); 78 - 79 77 const bool skipChapter = inputManager.getHeldTime() > SKIP_CHAPTER_MS; 80 78 81 79 if (skipChapter) {