diff --git a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp
index d2f1c3e..bb29ff1 100644
--- a/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp
+++ b/lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp
@@ -301,7 +301,7 @@ bool ChapterHtmlSlimParser::parseAndBuildPages() {
void ChapterHtmlSlimParser::addLineToPage(std::shared_ptr line) {
const int lineHeight = renderer.getLineHeight(fontId) * lineCompression;
- const int pageHeight = GfxRenderer::getScreenHeight() - marginTop - marginBottom;
+ const int pageHeight = renderer.getScreenHeight() - marginTop - marginBottom;
if (currentPageNextY + lineHeight > pageHeight) {
completePageFn(std::move(currentPage));
diff --git a/lib/GfxRenderer/GfxRenderer.cpp b/lib/GfxRenderer/GfxRenderer.cpp
index 9a8960a..ff23793 100644
--- a/lib/GfxRenderer/GfxRenderer.cpp
+++ b/lib/GfxRenderer/GfxRenderer.cpp
@@ -2,9 +2,6 @@
#include
-// Default to portrait orientation for all callers
-GfxRenderer::Orientation GfxRenderer::orientation = GfxRenderer::Orientation::Portrait;
-
void GfxRenderer::insertFont(const int fontId, EpdFontFamily font) { fontMap.insert({fontId, font}); }
void GfxRenderer::drawPixel(const int x, const int y, const bool state) const {
@@ -262,7 +259,7 @@ void GfxRenderer::displayWindow(const int x, const int y, const int width, const
}
// Note: Internal driver treats screen in command orientation; this library exposes a logical orientation
-int GfxRenderer::getScreenWidth() {
+int GfxRenderer::getScreenWidth() const {
switch (orientation) {
case Orientation::Portrait:
// 480px wide in portrait logical coordinates
@@ -275,7 +272,7 @@ int GfxRenderer::getScreenWidth() {
return EInkDisplay::DISPLAY_HEIGHT;
}
-int GfxRenderer::getScreenHeight() {
+int GfxRenderer::getScreenHeight() const {
switch (orientation) {
case Orientation::Portrait:
// 800px tall in portrait logical coordinates
diff --git a/lib/GfxRenderer/GfxRenderer.h b/lib/GfxRenderer/GfxRenderer.h
index 6b2e40e..dec65b7 100644
--- a/lib/GfxRenderer/GfxRenderer.h
+++ b/lib/GfxRenderer/GfxRenderer.h
@@ -25,8 +25,8 @@ class GfxRenderer {
static_assert(BW_BUFFER_CHUNK_SIZE * BW_BUFFER_NUM_CHUNKS == EInkDisplay::BUFFER_SIZE,
"BW buffer chunking does not line up with display buffer size");
- // Global orientation used for all rendering operations
- static Orientation orientation;
+ // Orientation used for all rendering operations
+ Orientation orientation;
EInkDisplay& einkDisplay;
RenderMode renderMode;
@@ -44,12 +44,12 @@ class GfxRenderer {
void insertFont(int fontId, EpdFontFamily font);
// Orientation control (affects logical width/height and coordinate transforms)
- static void setOrientation(Orientation o) { orientation = o; }
- static Orientation getOrientation() { return orientation; }
+ void setOrientation(const Orientation o) { orientation = o; }
+ Orientation getOrientation() const { return orientation; }
// Screen ops
- static int getScreenWidth();
- static int getScreenHeight();
+ int getScreenWidth() const;
+ int getScreenHeight() const;
void displayBuffer(EInkDisplay::RefreshMode refreshMode = EInkDisplay::FAST_REFRESH) const;
// EXPERIMENTAL: Windowed update - display only a rectangular region
void displayWindow(int x, int y, int width, int height) const;
diff --git a/src/activities/boot_sleep/BootActivity.cpp b/src/activities/boot_sleep/BootActivity.cpp
index 78a1248..616fbf8 100644
--- a/src/activities/boot_sleep/BootActivity.cpp
+++ b/src/activities/boot_sleep/BootActivity.cpp
@@ -8,8 +8,8 @@
void BootActivity::onEnter() {
Activity::onEnter();
- const auto pageWidth = GfxRenderer::getScreenWidth();
- const auto pageHeight = GfxRenderer::getScreenHeight();
+ const auto pageWidth = renderer.getScreenWidth();
+ const auto pageHeight = renderer.getScreenHeight();
renderer.clearScreen();
renderer.drawImage(CrossLarge, (pageWidth - 128) / 2, (pageHeight - 128) / 2, 128, 128);
diff --git a/src/activities/reader/EpubReaderActivity.cpp b/src/activities/reader/EpubReaderActivity.cpp
index 59c12eb..2e7cbbc 100644
--- a/src/activities/reader/EpubReaderActivity.cpp
+++ b/src/activities/reader/EpubReaderActivity.cpp
@@ -79,7 +79,7 @@ void EpubReaderActivity::onExit() {
ActivityWithSubactivity::onExit();
// Reset orientation back to portrait for the rest of the UI
- GfxRenderer::setOrientation(GfxRenderer::Orientation::Portrait);
+ renderer.setOrientation(GfxRenderer::Orientation::Portrait);
// Wait until not rendering to delete task to avoid killing mid-instruction to EPD
xSemaphoreTake(renderingMutex, portMAX_DELAY);
@@ -238,8 +238,8 @@ void EpubReaderActivity::renderScreen() {
Serial.printf("[%lu] [ERS] Loading file: %s, index: %d\n", millis(), filepath.c_str(), currentSpineIndex);
section = std::unique_ptr(new Section(epub, currentSpineIndex, renderer));
if (!section->loadCacheMetadata(READER_FONT_ID, lineCompression, marginTop, marginRight, marginBottom, marginLeft,
- SETTINGS.extraParagraphSpacing, GfxRenderer::getScreenWidth(),
- GfxRenderer::getScreenHeight())) {
+ SETTINGS.extraParagraphSpacing, renderer.getScreenWidth(),
+ renderer.getScreenHeight())) {
Serial.printf("[%lu] [ERS] Cache not found, building...\n", millis());
// Progress bar dimensions
@@ -251,8 +251,8 @@ void EpubReaderActivity::renderScreen() {
const int boxWidthNoBar = textWidth + boxMargin * 2;
const int boxHeightWithBar = renderer.getLineHeight(READER_FONT_ID) + barHeight + boxMargin * 3;
const int boxHeightNoBar = renderer.getLineHeight(READER_FONT_ID) + boxMargin * 2;
- const int boxXWithBar = (GfxRenderer::getScreenWidth() - boxWidthWithBar) / 2;
- const int boxXNoBar = (GfxRenderer::getScreenWidth() - boxWidthNoBar) / 2;
+ const int boxXWithBar = (renderer.getScreenWidth() - boxWidthWithBar) / 2;
+ const int boxXNoBar = (renderer.getScreenWidth() - boxWidthNoBar) / 2;
constexpr int boxY = 50;
const int barX = boxXWithBar + (boxWidthWithBar - barWidth) / 2;
const int barY = boxY + renderer.getLineHeight(READER_FONT_ID) + boxMargin * 2;
@@ -286,8 +286,8 @@ void EpubReaderActivity::renderScreen() {
};
if (!section->persistPageDataToSD(READER_FONT_ID, lineCompression, marginTop, marginRight, marginBottom,
- marginLeft, SETTINGS.extraParagraphSpacing, GfxRenderer::getScreenWidth(),
- GfxRenderer::getScreenHeight(), progressSetup, progressCallback)) {
+ marginLeft, SETTINGS.extraParagraphSpacing, renderer.getScreenWidth(),
+ renderer.getScreenHeight(), progressSetup, progressCallback)) {
Serial.printf("[%lu] [ERS] Failed to persist page data to SD\n", millis());
section.reset();
return;
@@ -392,7 +392,7 @@ void EpubReaderActivity::renderStatusBar() const {
SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::FULL;
// Position status bar near the bottom of the logical screen, regardless of orientation
- const auto screenHeight = GfxRenderer::getScreenHeight();
+ const auto screenHeight = renderer.getScreenHeight();
const auto textY = screenHeight - 24;
int percentageTextWidth = 0;
int progressTextWidth = 0;
@@ -406,7 +406,7 @@ void EpubReaderActivity::renderStatusBar() const {
const std::string progress = std::to_string(section->currentPage + 1) + "/" + std::to_string(section->pageCount) +
" " + std::to_string(bookProgress) + "%";
progressTextWidth = renderer.getTextWidth(SMALL_FONT_ID, progress.c_str());
- renderer.drawText(SMALL_FONT_ID, GfxRenderer::getScreenWidth() - marginRight - progressTextWidth, textY,
+ renderer.drawText(SMALL_FONT_ID, renderer.getScreenWidth() - marginRight - progressTextWidth, textY,
progress.c_str());
}
@@ -448,7 +448,7 @@ void EpubReaderActivity::renderStatusBar() const {
// Page width minus existing content with 30px padding on each side
const int titleMarginLeft = 20 + percentageTextWidth + 30 + marginLeft;
const int titleMarginRight = progressTextWidth + 30 + marginRight;
- const int availableTextWidth = GfxRenderer::getScreenWidth() - titleMarginLeft - titleMarginRight;
+ const int availableTextWidth = renderer.getScreenWidth() - titleMarginLeft - titleMarginRight;
const int tocIndex = epub->getTocIndexForSpineIndex(currentSpineIndex);
std::string title;
diff --git a/src/activities/reader/EpubReaderChapterSelectionActivity.cpp b/src/activities/reader/EpubReaderChapterSelectionActivity.cpp
index 1d956a6..090415d 100644
--- a/src/activities/reader/EpubReaderChapterSelectionActivity.cpp
+++ b/src/activities/reader/EpubReaderChapterSelectionActivity.cpp
@@ -16,7 +16,7 @@ int EpubReaderChapterSelectionActivity::getPageItems() const {
constexpr int startY = 60;
constexpr int lineHeight = 30;
- const int screenHeight = GfxRenderer::getScreenHeight();
+ const int screenHeight = renderer.getScreenHeight();
const int availableHeight = screenHeight - startY;
int items = availableHeight / lineHeight;
diff --git a/src/activities/reader/FileSelectionActivity.cpp b/src/activities/reader/FileSelectionActivity.cpp
index 9a1490c..6104da4 100644
--- a/src/activities/reader/FileSelectionActivity.cpp
+++ b/src/activities/reader/FileSelectionActivity.cpp
@@ -158,7 +158,7 @@ void FileSelectionActivity::displayTaskLoop() {
void FileSelectionActivity::render() const {
renderer.clearScreen();
- const auto pageWidth = GfxRenderer::getScreenWidth();
+ const auto pageWidth = renderer.getScreenWidth();
renderer.drawCenteredText(READER_FONT_ID, 10, "Books", true, BOLD);
// Help text
diff --git a/src/activities/settings/SettingsActivity.cpp b/src/activities/settings/SettingsActivity.cpp
index f0a5ec8..5ba9946 100644
--- a/src/activities/settings/SettingsActivity.cpp
+++ b/src/activities/settings/SettingsActivity.cpp
@@ -141,8 +141,8 @@ void SettingsActivity::displayTaskLoop() {
void SettingsActivity::render() const {
renderer.clearScreen();
- const auto pageWidth = GfxRenderer::getScreenWidth();
- const auto pageHeight = GfxRenderer::getScreenHeight();
+ const auto pageWidth = renderer.getScreenWidth();
+ const auto pageHeight = renderer.getScreenHeight();
// Draw header
renderer.drawCenteredText(READER_FONT_ID, 10, "Settings", true, BOLD);
diff --git a/src/activities/util/FullScreenMessageActivity.cpp b/src/activities/util/FullScreenMessageActivity.cpp
index cf84cc5..54740b6 100644
--- a/src/activities/util/FullScreenMessageActivity.cpp
+++ b/src/activities/util/FullScreenMessageActivity.cpp
@@ -8,7 +8,7 @@ void FullScreenMessageActivity::onEnter() {
Activity::onEnter();
const auto height = renderer.getLineHeight(UI_FONT_ID);
- const auto top = (GfxRenderer::getScreenHeight() - height) / 2;
+ const auto top = (renderer.getScreenHeight() - height) / 2;
renderer.clearScreen();
renderer.drawCenteredText(UI_FONT_ID, top, text.c_str(), true, style);
diff --git a/src/activities/util/KeyboardEntryActivity.cpp b/src/activities/util/KeyboardEntryActivity.cpp
index 73f3dde..8a72f1b 100644
--- a/src/activities/util/KeyboardEntryActivity.cpp
+++ b/src/activities/util/KeyboardEntryActivity.cpp
@@ -235,7 +235,7 @@ void KeyboardEntryActivity::loop() {
}
void KeyboardEntryActivity::render() const {
- const auto pageWidth = GfxRenderer::getScreenWidth();
+ const auto pageWidth = renderer.getScreenWidth();
renderer.clearScreen();
@@ -329,7 +329,7 @@ void KeyboardEntryActivity::render() const {
}
// Draw help text at absolute bottom of screen (consistent with other screens)
- const auto pageHeight = GfxRenderer::getScreenHeight();
+ const auto pageHeight = renderer.getScreenHeight();
renderer.drawText(SMALL_FONT_ID, 10, pageHeight - 30, "Navigate: D-pad | Select: OK | Cancel: BACK");
renderer.displayBuffer();
}