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.

Add drawCenteredText to GfxRenderer

+19 -21
+8 -1
lib/GfxRenderer/GfxRenderer.cpp
··· 47 47 return w; 48 48 } 49 49 50 + void GfxRenderer::drawCenteredText(const int fontId, const int y, const char* text, const bool black, 51 + const EpdFontStyle style) const { 52 + const int x = (getScreenWidth() - getTextWidth(fontId, text, style)) / 2; 53 + drawText(fontId, x, y, text, black, style); 54 + } 55 + 50 56 void GfxRenderer::drawText(const int fontId, const int x, const int y, const char* text, const bool black, 51 57 const EpdFontStyle style) const { 52 58 const int yPos = y + getLineHeight(fontId); ··· 109 115 } 110 116 111 117 void GfxRenderer::drawImage(const uint8_t bitmap[], const int x, const int y, const int width, const int height) const { 112 - einkDisplay.drawImage(bitmap, x, y, width, height); 118 + // Flip X and Y for portrait mode 119 + einkDisplay.drawImage(bitmap, y, x, height, width); 113 120 } 114 121 115 122 void GfxRenderer::clearScreen(const uint8_t color) const { einkDisplay.clearScreen(color); }
+1
lib/GfxRenderer/GfxRenderer.h
··· 40 40 41 41 // Text 42 42 int getTextWidth(int fontId, const char* text, EpdFontStyle style = REGULAR) const; 43 + void drawCenteredText(int fontId, int y, const char* text, bool black = true, EpdFontStyle style = REGULAR) const; 43 44 void drawText(int fontId, int x, int y, const char* text, bool black = true, EpdFontStyle style = REGULAR) const; 44 45 void setFontRenderMode(const FontRenderMode mode) { this->fontRenderMode = mode; } 45 46 int getSpaceWidth(int fontId) const;
+3 -6
src/screens/BootLogoScreen.cpp
··· 10 10 const auto pageHeight = GfxRenderer::getScreenHeight(); 11 11 12 12 renderer.clearScreen(); 13 - // Location for images is from top right in landscape orientation 14 - renderer.drawImage(CrossLarge, (pageHeight - 128) / 2, (pageWidth - 128) / 2, 128, 128); 15 - const int width = renderer.getTextWidth(UI_FONT_ID, "CrossPoint", BOLD); 16 - renderer.drawText(UI_FONT_ID, (pageWidth - width) / 2, pageHeight / 2 + 70, "CrossPoint", true, BOLD); 17 - const int bootingWidth = renderer.getTextWidth(SMALL_FONT_ID, "BOOTING"); 18 - renderer.drawText(SMALL_FONT_ID, (pageWidth - bootingWidth) / 2, pageHeight / 2 + 95, "BOOTING"); 13 + renderer.drawImage(CrossLarge, (pageWidth - 128) / 2, (pageHeight - 128) / 2, 128, 128); 14 + renderer.drawCenteredText(UI_FONT_ID, pageHeight / 2 + 70, "CrossPoint", true, BOLD); 15 + renderer.drawCenteredText(SMALL_FONT_ID, pageHeight / 2 + 95, "BOOTING"); 19 16 renderer.displayBuffer(); 20 17 }
+2 -4
src/screens/EpubReaderScreen.cpp
··· 198 198 199 199 if (section->pageCount == 0) { 200 200 Serial.printf("[%lu] [ERS] No pages to render\n", millis()); 201 - const int width = renderer.getTextWidth(READER_FONT_ID, "Empty chapter", BOLD); 202 - renderer.drawText(READER_FONT_ID, (GfxRenderer::getScreenWidth() - width) / 2, 300, "Empty chapter", true, BOLD); 201 + renderer.drawCenteredText(READER_FONT_ID, 300, "Empty chapter", true, BOLD); 203 202 renderStatusBar(); 204 203 renderer.displayBuffer(); 205 204 return; ··· 207 206 208 207 if (section->currentPage < 0 || section->currentPage >= section->pageCount) { 209 208 Serial.printf("[%lu] [ERS] Page out of bounds: %d (max %d)\n", millis(), section->currentPage, section->pageCount); 210 - const int width = renderer.getTextWidth(READER_FONT_ID, "Out of bounds", BOLD); 211 - renderer.drawText(READER_FONT_ID, (GfxRenderer::getScreenWidth() - width) / 2, 300, "Out of bounds", true, BOLD); 209 + renderer.drawCenteredText(READER_FONT_ID, 300, "Out of bounds", true, BOLD); 212 210 renderStatusBar(); 213 211 renderer.displayBuffer(); 214 212 return;
+1 -2
src/screens/FileSelectionScreen.cpp
··· 121 121 renderer.clearScreen(); 122 122 123 123 const auto pageWidth = GfxRenderer::getScreenWidth(); 124 - const auto titleWidth = renderer.getTextWidth(READER_FONT_ID, "CrossPoint Reader", BOLD); 125 - renderer.drawText(READER_FONT_ID, (pageWidth - titleWidth) / 2, 10, "CrossPoint Reader", true, BOLD); 124 + renderer.drawCenteredText(READER_FONT_ID, 10, "CrossPoint Reader", true, BOLD); 126 125 127 126 if (files.empty()) { 128 127 renderer.drawText(UI_FONT_ID, 20, 60, "No EPUBs found");
+1 -3
src/screens/FullScreenMessageScreen.cpp
··· 5 5 #include "config.h" 6 6 7 7 void FullScreenMessageScreen::onEnter() { 8 - const auto width = renderer.getTextWidth(UI_FONT_ID, text.c_str(), style); 9 8 const auto height = renderer.getLineHeight(UI_FONT_ID); 10 - const auto left = (GfxRenderer::getScreenWidth() - width) / 2; 11 9 const auto top = (GfxRenderer::getScreenHeight() - height) / 2; 12 10 13 11 renderer.clearScreen(); 14 - renderer.drawText(UI_FONT_ID, left, top, text.c_str(), true, style); 12 + renderer.drawCenteredText(UI_FONT_ID, top, text.c_str(), true, style); 15 13 renderer.displayBuffer(refreshMode); 16 14 }
+3 -5
src/screens/SleepScreen.cpp
··· 10 10 const auto pageHeight = GfxRenderer::getScreenHeight(); 11 11 12 12 renderer.clearScreen(); 13 - renderer.drawImage(CrossLarge, (pageHeight - 128) / 2, (pageWidth - 128) / 2, 128, 128); 14 - const int width = renderer.getTextWidth(UI_FONT_ID, "CrossPoint", BOLD); 15 - renderer.drawText(UI_FONT_ID, (pageWidth - width) / 2, pageHeight / 2 + 70, "CrossPoint", true, BOLD); 16 - const int bootingWidth = renderer.getTextWidth(SMALL_FONT_ID, "SLEEPING"); 17 - renderer.drawText(SMALL_FONT_ID, (pageWidth - bootingWidth) / 2, pageHeight / 2 + 95, "SLEEPING"); 13 + renderer.drawImage(CrossLarge, (pageWidth - 128) / 2, (pageHeight - 128) / 2, 128, 128); 14 + renderer.drawCenteredText(UI_FONT_ID, pageHeight / 2 + 70, "CrossPoint", true, BOLD); 15 + renderer.drawCenteredText(SMALL_FONT_ID, pageHeight / 2 + 95, "SLEEPING"); 18 16 renderer.invertScreen(); 19 17 renderer.displayBuffer(EInkDisplay::HALF_REFRESH); 20 18 }