mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-06 15:47:39 +03:00
Make GfxRenderer::orientation non-static
This commit is contained in:
parent
9d28afdefc
commit
d99c1158c3
@ -301,7 +301,7 @@ bool ChapterHtmlSlimParser::parseAndBuildPages() {
|
|||||||
|
|
||||||
void ChapterHtmlSlimParser::addLineToPage(std::shared_ptr<TextBlock> line) {
|
void ChapterHtmlSlimParser::addLineToPage(std::shared_ptr<TextBlock> line) {
|
||||||
const int lineHeight = renderer.getLineHeight(fontId) * lineCompression;
|
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) {
|
if (currentPageNextY + lineHeight > pageHeight) {
|
||||||
completePageFn(std::move(currentPage));
|
completePageFn(std::move(currentPage));
|
||||||
|
|||||||
@ -2,9 +2,6 @@
|
|||||||
|
|
||||||
#include <Utf8.h>
|
#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::insertFont(const int fontId, EpdFontFamily font) { fontMap.insert({fontId, font}); }
|
||||||
|
|
||||||
void GfxRenderer::drawPixel(const int x, const int y, const bool state) const {
|
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
|
// Note: Internal driver treats screen in command orientation; this library exposes a logical orientation
|
||||||
int GfxRenderer::getScreenWidth() {
|
int GfxRenderer::getScreenWidth() const {
|
||||||
switch (orientation) {
|
switch (orientation) {
|
||||||
case Orientation::Portrait:
|
case Orientation::Portrait:
|
||||||
// 480px wide in portrait logical coordinates
|
// 480px wide in portrait logical coordinates
|
||||||
@ -275,7 +272,7 @@ int GfxRenderer::getScreenWidth() {
|
|||||||
return EInkDisplay::DISPLAY_HEIGHT;
|
return EInkDisplay::DISPLAY_HEIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GfxRenderer::getScreenHeight() {
|
int GfxRenderer::getScreenHeight() const {
|
||||||
switch (orientation) {
|
switch (orientation) {
|
||||||
case Orientation::Portrait:
|
case Orientation::Portrait:
|
||||||
// 800px tall in portrait logical coordinates
|
// 800px tall in portrait logical coordinates
|
||||||
|
|||||||
@ -25,8 +25,8 @@ class GfxRenderer {
|
|||||||
static_assert(BW_BUFFER_CHUNK_SIZE * BW_BUFFER_NUM_CHUNKS == EInkDisplay::BUFFER_SIZE,
|
static_assert(BW_BUFFER_CHUNK_SIZE * BW_BUFFER_NUM_CHUNKS == EInkDisplay::BUFFER_SIZE,
|
||||||
"BW buffer chunking does not line up with display buffer size");
|
"BW buffer chunking does not line up with display buffer size");
|
||||||
|
|
||||||
// Global orientation used for all rendering operations
|
// Orientation used for all rendering operations
|
||||||
static Orientation orientation;
|
Orientation orientation;
|
||||||
|
|
||||||
EInkDisplay& einkDisplay;
|
EInkDisplay& einkDisplay;
|
||||||
RenderMode renderMode;
|
RenderMode renderMode;
|
||||||
@ -44,12 +44,12 @@ class GfxRenderer {
|
|||||||
void insertFont(int fontId, EpdFontFamily font);
|
void insertFont(int fontId, EpdFontFamily font);
|
||||||
|
|
||||||
// Orientation control (affects logical width/height and coordinate transforms)
|
// Orientation control (affects logical width/height and coordinate transforms)
|
||||||
static void setOrientation(Orientation o) { orientation = o; }
|
void setOrientation(const Orientation o) { orientation = o; }
|
||||||
static Orientation getOrientation() { return orientation; }
|
Orientation getOrientation() const { return orientation; }
|
||||||
|
|
||||||
// Screen ops
|
// Screen ops
|
||||||
static int getScreenWidth();
|
int getScreenWidth() const;
|
||||||
static int getScreenHeight();
|
int getScreenHeight() const;
|
||||||
void displayBuffer(EInkDisplay::RefreshMode refreshMode = EInkDisplay::FAST_REFRESH) const;
|
void displayBuffer(EInkDisplay::RefreshMode refreshMode = EInkDisplay::FAST_REFRESH) const;
|
||||||
// EXPERIMENTAL: Windowed update - display only a rectangular region
|
// EXPERIMENTAL: Windowed update - display only a rectangular region
|
||||||
void displayWindow(int x, int y, int width, int height) const;
|
void displayWindow(int x, int y, int width, int height) const;
|
||||||
|
|||||||
@ -8,8 +8,8 @@
|
|||||||
void BootActivity::onEnter() {
|
void BootActivity::onEnter() {
|
||||||
Activity::onEnter();
|
Activity::onEnter();
|
||||||
|
|
||||||
const auto pageWidth = GfxRenderer::getScreenWidth();
|
const auto pageWidth = renderer.getScreenWidth();
|
||||||
const auto pageHeight = GfxRenderer::getScreenHeight();
|
const auto pageHeight = renderer.getScreenHeight();
|
||||||
|
|
||||||
renderer.clearScreen();
|
renderer.clearScreen();
|
||||||
renderer.drawImage(CrossLarge, (pageWidth - 128) / 2, (pageHeight - 128) / 2, 128, 128);
|
renderer.drawImage(CrossLarge, (pageWidth - 128) / 2, (pageHeight - 128) / 2, 128, 128);
|
||||||
|
|||||||
@ -79,7 +79,7 @@ void EpubReaderActivity::onExit() {
|
|||||||
ActivityWithSubactivity::onExit();
|
ActivityWithSubactivity::onExit();
|
||||||
|
|
||||||
// Reset orientation back to portrait for the rest of the UI
|
// 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
|
// Wait until not rendering to delete task to avoid killing mid-instruction to EPD
|
||||||
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
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);
|
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));
|
section = std::unique_ptr<Section>(new Section(epub, currentSpineIndex, renderer));
|
||||||
if (!section->loadCacheMetadata(READER_FONT_ID, lineCompression, marginTop, marginRight, marginBottom, marginLeft,
|
if (!section->loadCacheMetadata(READER_FONT_ID, lineCompression, marginTop, marginRight, marginBottom, marginLeft,
|
||||||
SETTINGS.extraParagraphSpacing, GfxRenderer::getScreenWidth(),
|
SETTINGS.extraParagraphSpacing, renderer.getScreenWidth(),
|
||||||
GfxRenderer::getScreenHeight())) {
|
renderer.getScreenHeight())) {
|
||||||
Serial.printf("[%lu] [ERS] Cache not found, building...\n", millis());
|
Serial.printf("[%lu] [ERS] Cache not found, building...\n", millis());
|
||||||
|
|
||||||
// Progress bar dimensions
|
// Progress bar dimensions
|
||||||
@ -251,8 +251,8 @@ void EpubReaderActivity::renderScreen() {
|
|||||||
const int boxWidthNoBar = textWidth + boxMargin * 2;
|
const int boxWidthNoBar = textWidth + boxMargin * 2;
|
||||||
const int boxHeightWithBar = renderer.getLineHeight(READER_FONT_ID) + barHeight + boxMargin * 3;
|
const int boxHeightWithBar = renderer.getLineHeight(READER_FONT_ID) + barHeight + boxMargin * 3;
|
||||||
const int boxHeightNoBar = renderer.getLineHeight(READER_FONT_ID) + boxMargin * 2;
|
const int boxHeightNoBar = renderer.getLineHeight(READER_FONT_ID) + boxMargin * 2;
|
||||||
const int boxXWithBar = (GfxRenderer::getScreenWidth() - boxWidthWithBar) / 2;
|
const int boxXWithBar = (renderer.getScreenWidth() - boxWidthWithBar) / 2;
|
||||||
const int boxXNoBar = (GfxRenderer::getScreenWidth() - boxWidthNoBar) / 2;
|
const int boxXNoBar = (renderer.getScreenWidth() - boxWidthNoBar) / 2;
|
||||||
constexpr int boxY = 50;
|
constexpr int boxY = 50;
|
||||||
const int barX = boxXWithBar + (boxWidthWithBar - barWidth) / 2;
|
const int barX = boxXWithBar + (boxWidthWithBar - barWidth) / 2;
|
||||||
const int barY = boxY + renderer.getLineHeight(READER_FONT_ID) + boxMargin * 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,
|
if (!section->persistPageDataToSD(READER_FONT_ID, lineCompression, marginTop, marginRight, marginBottom,
|
||||||
marginLeft, SETTINGS.extraParagraphSpacing, GfxRenderer::getScreenWidth(),
|
marginLeft, SETTINGS.extraParagraphSpacing, renderer.getScreenWidth(),
|
||||||
GfxRenderer::getScreenHeight(), progressSetup, progressCallback)) {
|
renderer.getScreenHeight(), progressSetup, progressCallback)) {
|
||||||
Serial.printf("[%lu] [ERS] Failed to persist page data to SD\n", millis());
|
Serial.printf("[%lu] [ERS] Failed to persist page data to SD\n", millis());
|
||||||
section.reset();
|
section.reset();
|
||||||
return;
|
return;
|
||||||
@ -392,7 +392,7 @@ void EpubReaderActivity::renderStatusBar() const {
|
|||||||
SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::FULL;
|
SETTINGS.statusBar == CrossPointSettings::STATUS_BAR_MODE::FULL;
|
||||||
|
|
||||||
// Position status bar near the bottom of the logical screen, regardless of orientation
|
// 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;
|
const auto textY = screenHeight - 24;
|
||||||
int percentageTextWidth = 0;
|
int percentageTextWidth = 0;
|
||||||
int progressTextWidth = 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) +
|
const std::string progress = std::to_string(section->currentPage + 1) + "/" + std::to_string(section->pageCount) +
|
||||||
" " + std::to_string(bookProgress) + "%";
|
" " + std::to_string(bookProgress) + "%";
|
||||||
progressTextWidth = renderer.getTextWidth(SMALL_FONT_ID, progress.c_str());
|
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());
|
progress.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,7 +448,7 @@ void EpubReaderActivity::renderStatusBar() const {
|
|||||||
// Page width minus existing content with 30px padding on each side
|
// Page width minus existing content with 30px padding on each side
|
||||||
const int titleMarginLeft = 20 + percentageTextWidth + 30 + marginLeft;
|
const int titleMarginLeft = 20 + percentageTextWidth + 30 + marginLeft;
|
||||||
const int titleMarginRight = progressTextWidth + 30 + marginRight;
|
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);
|
const int tocIndex = epub->getTocIndexForSpineIndex(currentSpineIndex);
|
||||||
|
|
||||||
std::string title;
|
std::string title;
|
||||||
|
|||||||
@ -16,7 +16,7 @@ int EpubReaderChapterSelectionActivity::getPageItems() const {
|
|||||||
constexpr int startY = 60;
|
constexpr int startY = 60;
|
||||||
constexpr int lineHeight = 30;
|
constexpr int lineHeight = 30;
|
||||||
|
|
||||||
const int screenHeight = GfxRenderer::getScreenHeight();
|
const int screenHeight = renderer.getScreenHeight();
|
||||||
const int availableHeight = screenHeight - startY;
|
const int availableHeight = screenHeight - startY;
|
||||||
int items = availableHeight / lineHeight;
|
int items = availableHeight / lineHeight;
|
||||||
|
|
||||||
|
|||||||
@ -158,7 +158,7 @@ void FileSelectionActivity::displayTaskLoop() {
|
|||||||
void FileSelectionActivity::render() const {
|
void FileSelectionActivity::render() const {
|
||||||
renderer.clearScreen();
|
renderer.clearScreen();
|
||||||
|
|
||||||
const auto pageWidth = GfxRenderer::getScreenWidth();
|
const auto pageWidth = renderer.getScreenWidth();
|
||||||
renderer.drawCenteredText(READER_FONT_ID, 10, "Books", true, BOLD);
|
renderer.drawCenteredText(READER_FONT_ID, 10, "Books", true, BOLD);
|
||||||
|
|
||||||
// Help text
|
// Help text
|
||||||
|
|||||||
@ -141,8 +141,8 @@ void SettingsActivity::displayTaskLoop() {
|
|||||||
void SettingsActivity::render() const {
|
void SettingsActivity::render() const {
|
||||||
renderer.clearScreen();
|
renderer.clearScreen();
|
||||||
|
|
||||||
const auto pageWidth = GfxRenderer::getScreenWidth();
|
const auto pageWidth = renderer.getScreenWidth();
|
||||||
const auto pageHeight = GfxRenderer::getScreenHeight();
|
const auto pageHeight = renderer.getScreenHeight();
|
||||||
|
|
||||||
// Draw header
|
// Draw header
|
||||||
renderer.drawCenteredText(READER_FONT_ID, 10, "Settings", true, BOLD);
|
renderer.drawCenteredText(READER_FONT_ID, 10, "Settings", true, BOLD);
|
||||||
|
|||||||
@ -8,7 +8,7 @@ void FullScreenMessageActivity::onEnter() {
|
|||||||
Activity::onEnter();
|
Activity::onEnter();
|
||||||
|
|
||||||
const auto height = renderer.getLineHeight(UI_FONT_ID);
|
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.clearScreen();
|
||||||
renderer.drawCenteredText(UI_FONT_ID, top, text.c_str(), true, style);
|
renderer.drawCenteredText(UI_FONT_ID, top, text.c_str(), true, style);
|
||||||
|
|||||||
@ -235,7 +235,7 @@ void KeyboardEntryActivity::loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardEntryActivity::render() const {
|
void KeyboardEntryActivity::render() const {
|
||||||
const auto pageWidth = GfxRenderer::getScreenWidth();
|
const auto pageWidth = renderer.getScreenWidth();
|
||||||
|
|
||||||
renderer.clearScreen();
|
renderer.clearScreen();
|
||||||
|
|
||||||
@ -329,7 +329,7 @@ void KeyboardEntryActivity::render() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw help text at absolute bottom of screen (consistent with other screens)
|
// 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.drawText(SMALL_FONT_ID, 10, pageHeight - 30, "Navigate: D-pad | Select: OK | Cancel: BACK");
|
||||||
renderer.displayBuffer();
|
renderer.displayBuffer();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user