From fbeaf48e324d158d52acbd0b6477d22e5e5d05c6 Mon Sep 17 00:00:00 2001 From: pablohc Date: Sun, 29 Mar 2026 22:14:21 +0200 Subject: [PATCH] refactor: pass precomputed BookOverlayInfo to renderBitmapSleepScreen --- lib/I18n/I18nKeys.h | 3 ++- src/activities/boot_sleep/SleepActivity.cpp | 12 +++++++----- src/activities/boot_sleep/SleepActivity.h | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/I18n/I18nKeys.h b/lib/I18n/I18nKeys.h index aad6c695..ebabe73d 100644 --- a/lib/I18n/I18nKeys.h +++ b/lib/I18n/I18nKeys.h @@ -408,7 +408,8 @@ inline const char* const* getStringArray(Language lang) { constexpr uint8_t getLanguageCount() { return static_cast(Language::_COUNT); } // Sorted language indices by code (auto-generated by gen_i18n.py) -// Order: English, Беларуская, Català, Čeština, Dansk, Deutsch, Español, Suomi, Français, Italiano, Қазақша, Nederlands, Polski, Português (Brasil), Română, Русский, Svenska, Türkçe, Українська +// Order: English, Беларуская, Català, Čeština, Dansk, Deutsch, Español, Suomi, Français, Italiano, Қазақша, Nederlands, +// Polski, Português (Brasil), Română, Русский, Svenska, Türkçe, Українська constexpr uint8_t SORTED_LANGUAGE_INDICES[] = {0, 11, 9, 4, 15, 3, 1, 14, 2, 12, 18, 16, 13, 5, 8, 6, 7, 17, 10}; static_assert(sizeof(SORTED_LANGUAGE_INDICES) / sizeof(SORTED_LANGUAGE_INDICES[0]) == getLanguageCount(), diff --git a/src/activities/boot_sleep/SleepActivity.cpp b/src/activities/boot_sleep/SleepActivity.cpp index cf26e648..054d438a 100644 --- a/src/activities/boot_sleep/SleepActivity.cpp +++ b/src/activities/boot_sleep/SleepActivity.cpp @@ -93,7 +93,7 @@ void SleepActivity::renderCustomSleepScreen() const { delay(100); Bitmap bitmap(file, true); if (bitmap.parseHeaders() == BmpReaderError::Ok) { - renderBitmapSleepScreen(bitmap); + renderBitmapSleepScreen(bitmap, BookOverlayInfo{}); file.close(); dir.close(); return; @@ -111,7 +111,7 @@ void SleepActivity::renderCustomSleepScreen() const { Bitmap bitmap(file, true); if (bitmap.parseHeaders() == BmpReaderError::Ok) { LOG_DBG("SLP", "Loading: /sleep.bmp"); - renderBitmapSleepScreen(bitmap); + renderBitmapSleepScreen(bitmap, BookOverlayInfo{}); file.close(); return; } @@ -247,7 +247,7 @@ BookOverlayInfo SleepActivity::getBookOverlayInfo(const std::string& bookPath) c return info; } -void SleepActivity::renderBitmapSleepScreen(const Bitmap& bitmap) const { +void SleepActivity::renderBitmapSleepScreen(const Bitmap& bitmap, const BookOverlayInfo& overlayInfo) const { int x, y; const auto pageWidth = renderer.getScreenWidth(); const auto pageHeight = renderer.getScreenHeight(); @@ -300,7 +300,6 @@ void SleepActivity::renderBitmapSleepScreen(const Bitmap& bitmap) const { } const uint8_t overlayMode = SETTINGS.sleepCoverOverlay; - const BookOverlayInfo overlayInfo = overlayMode < 3 ? getBookOverlayInfo(APP_STATE.openEpubPath) : BookOverlayInfo{}; const auto drawOverlay = [&]() { const bool hasTitle = !overlayInfo.title.empty(); const bool hasProgress = !overlayInfo.progressText.empty(); @@ -476,7 +475,10 @@ void SleepActivity::renderCoverSleepScreen() const { Bitmap bitmap(file); if (bitmap.parseHeaders() == BmpReaderError::Ok) { LOG_DBG("SLP", "Rendering sleep cover: %s", coverBmpPath.c_str()); - renderBitmapSleepScreen(bitmap); + const uint8_t overlayMode = SETTINGS.sleepCoverOverlay; + const BookOverlayInfo coverOverlayInfo = + overlayMode < 3 ? getBookOverlayInfo(APP_STATE.openEpubPath) : BookOverlayInfo{}; + renderBitmapSleepScreen(bitmap, coverOverlayInfo); file.close(); return; } diff --git a/src/activities/boot_sleep/SleepActivity.h b/src/activities/boot_sleep/SleepActivity.h index 5d757b6f..bc1eb11e 100644 --- a/src/activities/boot_sleep/SleepActivity.h +++ b/src/activities/boot_sleep/SleepActivity.h @@ -24,7 +24,7 @@ class SleepActivity final : public Activity { void renderDefaultSleepScreen() const; void renderCustomSleepScreen() const; void renderCoverSleepScreen() const; - void renderBitmapSleepScreen(const Bitmap& bitmap) const; + void renderBitmapSleepScreen(const Bitmap& bitmap, const BookOverlayInfo& overlayInfo) const; void renderBlankSleepScreen() const; BookOverlayInfo getBookOverlayInfo(const std::string& bookPath) const; };