Use reference passing for EpdRenderer
This commit is contained in:
@@ -5,10 +5,10 @@
|
||||
#include "images/CrossLarge.h"
|
||||
|
||||
void BootLogoScreen::onEnter() {
|
||||
const auto pageWidth = renderer->getPageWidth();
|
||||
const auto pageHeight = renderer->getPageHeight();
|
||||
const auto pageWidth = renderer.getPageWidth();
|
||||
const auto pageHeight = renderer.getPageHeight();
|
||||
|
||||
renderer->clearScreen();
|
||||
renderer.clearScreen();
|
||||
// Location for images is from top right in landscape orientation
|
||||
renderer->drawImage(CrossLarge, (pageHeight - 128) / 2, (pageWidth - 128) / 2, 128, 128);
|
||||
renderer.drawImage(CrossLarge, (pageHeight - 128) / 2, (pageWidth - 128) / 2, 128, 128);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
class BootLogoScreen final : public Screen {
|
||||
public:
|
||||
explicit BootLogoScreen(EpdRenderer* renderer, InputManager& inputManager) : Screen(renderer, inputManager) {}
|
||||
explicit BootLogoScreen(EpdRenderer& renderer, InputManager& inputManager) : Screen(renderer, inputManager) {}
|
||||
void onEnter() override;
|
||||
};
|
||||
|
||||
@@ -154,16 +154,16 @@ void EpubReaderScreen::renderPage() {
|
||||
Serial.println("Cache not found, building...");
|
||||
|
||||
{
|
||||
const int textWidth = renderer->getTextWidth("Indexing...");
|
||||
const int textWidth = renderer.getTextWidth("Indexing...");
|
||||
constexpr int margin = 20;
|
||||
const int x = (renderer->getPageWidth() - textWidth - margin * 2) / 2;
|
||||
const int x = (renderer.getPageWidth() - textWidth - margin * 2) / 2;
|
||||
constexpr int y = 50;
|
||||
const int w = textWidth + margin * 2;
|
||||
const int h = renderer->getLineHeight() + margin * 2;
|
||||
renderer->fillRect(x, y, w, h, 0);
|
||||
renderer->drawText(x + margin, y + margin, "Indexing...");
|
||||
renderer->drawRect(x + 5, y + 5, w - 10, h - 10);
|
||||
renderer->flushArea(x, y, w, h);
|
||||
const int h = renderer.getLineHeight() + margin * 2;
|
||||
renderer.fillRect(x, y, w, h, 0);
|
||||
renderer.drawText(x + margin, y + margin, "Indexing...");
|
||||
renderer.drawRect(x + 5, y + 5, w - 10, h - 10);
|
||||
renderer.flushArea(x, y, w, h);
|
||||
}
|
||||
|
||||
section->setupCacheDir();
|
||||
@@ -184,14 +184,14 @@ void EpubReaderScreen::renderPage() {
|
||||
}
|
||||
}
|
||||
|
||||
renderer->clearScreen();
|
||||
renderer.clearScreen();
|
||||
section->renderPage();
|
||||
renderStatusBar();
|
||||
if (pagesUntilFullRefresh <= 1) {
|
||||
renderer->flushDisplay(false);
|
||||
renderer.flushDisplay(false);
|
||||
pagesUntilFullRefresh = PAGES_PER_REFRESH;
|
||||
} else {
|
||||
renderer->flushDisplay();
|
||||
renderer.flushDisplay();
|
||||
pagesUntilFullRefresh--;
|
||||
}
|
||||
|
||||
@@ -206,16 +206,16 @@ void EpubReaderScreen::renderPage() {
|
||||
}
|
||||
|
||||
void EpubReaderScreen::renderStatusBar() const {
|
||||
const auto pageWidth = renderer->getPageWidth();
|
||||
const auto pageWidth = renderer.getPageWidth();
|
||||
|
||||
const std::string progress = std::to_string(section->currentPage + 1) + " / " + std::to_string(section->pageCount);
|
||||
const auto progressTextWidth = renderer->getSmallTextWidth(progress.c_str());
|
||||
renderer->drawSmallText(pageWidth - progressTextWidth, 765, progress.c_str());
|
||||
const auto progressTextWidth = renderer.getSmallTextWidth(progress.c_str());
|
||||
renderer.drawSmallText(pageWidth - progressTextWidth, 765, progress.c_str());
|
||||
|
||||
const uint16_t percentage = battery.readPercentage();
|
||||
const auto percentageText = std::to_string(percentage) + "%";
|
||||
const auto percentageTextWidth = renderer->getSmallTextWidth(percentageText.c_str());
|
||||
renderer->drawSmallText(20, 765, percentageText.c_str());
|
||||
const auto percentageTextWidth = renderer.getSmallTextWidth(percentageText.c_str());
|
||||
renderer.drawSmallText(20, 765, percentageText.c_str());
|
||||
|
||||
// 1 column on left, 2 columns on right, 5 columns of battery body
|
||||
constexpr int batteryWidth = 15;
|
||||
@@ -224,23 +224,23 @@ void EpubReaderScreen::renderStatusBar() const {
|
||||
constexpr int y = 772;
|
||||
|
||||
// Top line
|
||||
renderer->drawLine(x, y, x + batteryWidth - 4, y);
|
||||
renderer.drawLine(x, y, x + batteryWidth - 4, y);
|
||||
// Bottom line
|
||||
renderer->drawLine(x, y + batteryHeight - 1, x + batteryWidth - 4, y + batteryHeight - 1);
|
||||
renderer.drawLine(x, y + batteryHeight - 1, x + batteryWidth - 4, y + batteryHeight - 1);
|
||||
// Left line
|
||||
renderer->drawLine(x, y, x, y + batteryHeight - 1);
|
||||
renderer.drawLine(x, y, x, y + batteryHeight - 1);
|
||||
// Battery end
|
||||
renderer->drawLine(x + batteryWidth - 4, y, x + batteryWidth - 4, y + batteryHeight - 1);
|
||||
renderer->drawLine(x + batteryWidth - 3, y + 2, x + batteryWidth - 3, y + batteryHeight - 3);
|
||||
renderer->drawLine(x + batteryWidth - 2, y + 2, x + batteryWidth - 2, y + batteryHeight - 3);
|
||||
renderer->drawLine(x + batteryWidth - 1, y + 2, x + batteryWidth - 1, y + batteryHeight - 3);
|
||||
renderer.drawLine(x + batteryWidth - 4, y, x + batteryWidth - 4, y + batteryHeight - 1);
|
||||
renderer.drawLine(x + batteryWidth - 3, y + 2, x + batteryWidth - 3, y + batteryHeight - 3);
|
||||
renderer.drawLine(x + batteryWidth - 2, y + 2, x + batteryWidth - 2, y + batteryHeight - 3);
|
||||
renderer.drawLine(x + batteryWidth - 1, y + 2, x + batteryWidth - 1, y + batteryHeight - 3);
|
||||
|
||||
// The +1 is to round up, so that we always fill at least one pixel
|
||||
int filledWidth = percentage * (batteryWidth - 5) / 100 + 1;
|
||||
if (filledWidth > batteryWidth - 5) {
|
||||
filledWidth = batteryWidth - 5; // Ensure we don't overflow
|
||||
}
|
||||
renderer->fillRect(x + 1, y + 1, filledWidth, batteryHeight - 2);
|
||||
renderer.fillRect(x + 1, y + 1, filledWidth, batteryHeight - 2);
|
||||
|
||||
// Page width minus existing content with 30px padding on each side
|
||||
const int leftMargin = 20 + percentageTextWidth + 30;
|
||||
@@ -248,11 +248,11 @@ void EpubReaderScreen::renderStatusBar() const {
|
||||
const int availableTextWidth = pageWidth - leftMargin - rightMargin;
|
||||
const auto tocItem = epub->getTocItem(epub->getTocIndexForSpineIndex(currentSpineIndex));
|
||||
auto title = tocItem.title;
|
||||
int titleWidth = renderer->getSmallTextWidth(title.c_str());
|
||||
int titleWidth = renderer.getSmallTextWidth(title.c_str());
|
||||
while (titleWidth > availableTextWidth) {
|
||||
title = title.substr(0, title.length() - 8) + "...";
|
||||
titleWidth = renderer->getSmallTextWidth(title.c_str());
|
||||
titleWidth = renderer.getSmallTextWidth(title.c_str());
|
||||
}
|
||||
|
||||
renderer->drawSmallText(leftMargin + (availableTextWidth - titleWidth) / 2, 765, title.c_str());
|
||||
renderer.drawSmallText(leftMargin + (availableTextWidth - titleWidth) / 2, 765, title.c_str());
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class EpubReaderScreen final : public Screen {
|
||||
void renderStatusBar() const;
|
||||
|
||||
public:
|
||||
explicit EpubReaderScreen(EpdRenderer* renderer, InputManager& inputManager, Epub* epub,
|
||||
explicit EpubReaderScreen(EpdRenderer& renderer, InputManager& inputManager, Epub* epub,
|
||||
const std::function<void()>& onGoHome)
|
||||
: Screen(renderer, inputManager), epub(epub), onGoHome(onGoHome) {}
|
||||
void onEnter() override;
|
||||
|
||||
@@ -105,23 +105,23 @@ void FileSelectionScreen::displayTaskLoop() {
|
||||
}
|
||||
|
||||
void FileSelectionScreen::render() const {
|
||||
renderer->clearScreen();
|
||||
renderer.clearScreen();
|
||||
|
||||
const auto pageWidth = renderer->getPageWidth();
|
||||
const auto titleWidth = renderer->getTextWidth("CrossPoint Reader", BOLD);
|
||||
renderer->drawText((pageWidth - titleWidth) / 2, 0, "CrossPoint Reader", 1, BOLD);
|
||||
const auto pageWidth = renderer.getPageWidth();
|
||||
const auto titleWidth = renderer.getTextWidth("CrossPoint Reader", BOLD);
|
||||
renderer.drawText((pageWidth - titleWidth) / 2, 0, "CrossPoint Reader", 1, BOLD);
|
||||
|
||||
if (files.empty()) {
|
||||
renderer->drawUiText(10, 50, "No EPUBs found");
|
||||
renderer.drawUiText(10, 50, "No EPUBs found");
|
||||
} else {
|
||||
// Draw selection
|
||||
renderer->fillRect(0, 50 + selectorIndex * 30 + 2, pageWidth - 1, 30);
|
||||
renderer.fillRect(0, 50 + selectorIndex * 30 + 2, pageWidth - 1, 30);
|
||||
|
||||
for (size_t i = 0; i < files.size(); i++) {
|
||||
const auto file = files[i];
|
||||
renderer->drawUiText(10, 50 + i * 30, file.c_str(), i == selectorIndex ? 0 : 1);
|
||||
renderer.drawUiText(10, 50 + i * 30, file.c_str(), i == selectorIndex ? 0 : 1);
|
||||
}
|
||||
}
|
||||
|
||||
renderer->flushDisplay();
|
||||
renderer.flushDisplay();
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class FileSelectionScreen final : public Screen {
|
||||
void loadFiles();
|
||||
|
||||
public:
|
||||
explicit FileSelectionScreen(EpdRenderer* renderer, InputManager& inputManager,
|
||||
explicit FileSelectionScreen(EpdRenderer& renderer, InputManager& inputManager,
|
||||
const std::function<void(const std::string&)>& onSelect)
|
||||
: Screen(renderer, inputManager), onSelect(onSelect) {}
|
||||
void onEnter() override;
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
#include <EpdRenderer.h>
|
||||
|
||||
void FullScreenMessageScreen::onEnter() {
|
||||
const auto width = renderer->getUiTextWidth(text.c_str(), style);
|
||||
const auto height = renderer->getLineHeight();
|
||||
const auto left = (renderer->getPageWidth() - width) / 2;
|
||||
const auto top = (renderer->getPageHeight() - height) / 2;
|
||||
const auto width = renderer.getUiTextWidth(text.c_str(), style);
|
||||
const auto height = renderer.getLineHeight();
|
||||
const auto left = (renderer.getPageWidth() - width) / 2;
|
||||
const auto top = (renderer.getPageHeight() - height) / 2;
|
||||
|
||||
renderer->clearScreen(invert);
|
||||
renderer->drawUiText(left, top, text.c_str(), invert ? 0 : 1, style);
|
||||
renderer->flushDisplay(partialUpdate);
|
||||
renderer.clearScreen(invert);
|
||||
renderer.drawUiText(left, top, text.c_str(), invert ? 0 : 1, style);
|
||||
renderer.flushDisplay(partialUpdate);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ class FullScreenMessageScreen final : public Screen {
|
||||
bool partialUpdate;
|
||||
|
||||
public:
|
||||
explicit FullScreenMessageScreen(EpdRenderer* renderer, InputManager& inputManager, std::string text,
|
||||
explicit FullScreenMessageScreen(EpdRenderer& renderer, InputManager& inputManager, std::string text,
|
||||
const EpdFontStyle style = REGULAR, const bool invert = false,
|
||||
const bool partialUpdate = true)
|
||||
: Screen(renderer, inputManager),
|
||||
|
||||
@@ -5,11 +5,11 @@ class EpdRenderer;
|
||||
|
||||
class Screen {
|
||||
protected:
|
||||
EpdRenderer* renderer;
|
||||
EpdRenderer& renderer;
|
||||
InputManager& inputManager;
|
||||
|
||||
public:
|
||||
explicit Screen(EpdRenderer* renderer, InputManager& inputManager) : renderer(renderer), inputManager(inputManager) {}
|
||||
explicit Screen(EpdRenderer& renderer, InputManager& inputManager) : renderer(renderer), inputManager(inputManager) {}
|
||||
virtual ~Screen() = default;
|
||||
virtual void onEnter() {}
|
||||
virtual void onExit() {}
|
||||
|
||||
@@ -4,4 +4,4 @@
|
||||
|
||||
#include "images/SleepScreenImg.h"
|
||||
|
||||
void SleepScreen::onEnter() { renderer->drawImageNoMargin(SleepScreenImg, 0, 0, 800, 480, false, true); }
|
||||
void SleepScreen::onEnter() { renderer.drawImageNoMargin(SleepScreenImg, 0, 0, 800, 480, false, true); }
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
class SleepScreen final : public Screen {
|
||||
public:
|
||||
explicit SleepScreen(EpdRenderer* renderer, InputManager& inputManager) : Screen(renderer, inputManager) {}
|
||||
explicit SleepScreen(EpdRenderer& renderer, InputManager& inputManager) : Screen(renderer, inputManager) {}
|
||||
void onEnter() override;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user