Make GfxRenderer::orientation non-static

This commit is contained in:
Dave Allie 2025-12-28 19:46:00 +11:00
parent 9d28afdefc
commit d99c1158c3
No known key found for this signature in database
GPG Key ID: F2FDDB3AD8D0276F
10 changed files with 28 additions and 31 deletions

View File

@ -301,7 +301,7 @@ bool ChapterHtmlSlimParser::parseAndBuildPages() {
void ChapterHtmlSlimParser::addLineToPage(std::shared_ptr<TextBlock> 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));

View File

@ -2,9 +2,6 @@
#include <Utf8.h>
// 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

View File

@ -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;

View File

@ -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);

View File

@ -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<Section>(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;

View File

@ -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;

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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();
}