188 lines
7.1 KiB
C++
188 lines
7.1 KiB
C++
#include "StatusBarSettingsActivity.h"
|
|
|
|
#include <GfxRenderer.h>
|
|
#include <I18n.h>
|
|
|
|
#include <cstring>
|
|
|
|
#include "CrossPointSettings.h"
|
|
#include "MappedInputManager.h"
|
|
#include "components/UITheme.h"
|
|
#include "fontIds.h"
|
|
|
|
namespace {
|
|
constexpr int MENU_ITEMS = 7;
|
|
const StrId menuNames[MENU_ITEMS] = {StrId::STR_CHAPTER_PAGE_COUNT,
|
|
StrId::STR_BOOK_PROGRESS_PERCENTAGE,
|
|
StrId::STR_PROGRESS_BAR,
|
|
StrId::STR_PROGRESS_BAR_THICKNESS,
|
|
StrId::STR_TITLE,
|
|
StrId::STR_BATTERY,
|
|
StrId::STR_CLOCK};
|
|
constexpr int PROGRESS_BAR_ITEMS = 3;
|
|
const StrId progressBarNames[PROGRESS_BAR_ITEMS] = {StrId::STR_BOOK, StrId::STR_CHAPTER, StrId::STR_HIDE};
|
|
|
|
constexpr int PROGRESS_BAR_THICKNESS_ITEMS = 3;
|
|
const StrId progressBarThicknessNames[PROGRESS_BAR_THICKNESS_ITEMS] = {
|
|
StrId::STR_PROGRESS_BAR_THIN, StrId::STR_PROGRESS_BAR_MEDIUM, StrId::STR_PROGRESS_BAR_THICK};
|
|
|
|
constexpr int TITLE_ITEMS = 3;
|
|
const StrId titleNames[TITLE_ITEMS] = {StrId::STR_BOOK, StrId::STR_CHAPTER, StrId::STR_HIDE};
|
|
|
|
const int widthMargin = 10;
|
|
const int verticalPreviewPadding = 50;
|
|
const int verticalPreviewTextPadding = 40;
|
|
} // namespace
|
|
|
|
void StatusBarSettingsActivity::onEnter() {
|
|
Activity::onEnter();
|
|
|
|
const int menuCount = SETTINGS.useClock ? MENU_ITEMS : MENU_ITEMS - 1;
|
|
if (selectedIndex >= menuCount) {
|
|
selectedIndex = 0;
|
|
}
|
|
|
|
// Clamp statusBarProgressBar and statusBarTitle in case of corrupt/migrated data
|
|
if (SETTINGS.statusBarProgressBar >= PROGRESS_BAR_ITEMS) {
|
|
SETTINGS.statusBarProgressBar = CrossPointSettings::STATUS_BAR_PROGRESS_BAR::HIDE_PROGRESS;
|
|
}
|
|
|
|
if (SETTINGS.statusBarTitle >= PROGRESS_BAR_THICKNESS_ITEMS) {
|
|
SETTINGS.statusBarTitle = CrossPointSettings::STATUS_BAR_PROGRESS_BAR_THICKNESS::PROGRESS_BAR_NORMAL;
|
|
}
|
|
|
|
if (SETTINGS.statusBarTitle >= TITLE_ITEMS) {
|
|
SETTINGS.statusBarTitle = CrossPointSettings::STATUS_BAR_TITLE::HIDE_TITLE;
|
|
}
|
|
|
|
requestUpdate();
|
|
}
|
|
|
|
void StatusBarSettingsActivity::onExit() { Activity::onExit(); }
|
|
|
|
void StatusBarSettingsActivity::loop() {
|
|
if (mappedInput.wasPressed(MappedInputManager::Button::Back)) {
|
|
finish();
|
|
return;
|
|
}
|
|
|
|
if (mappedInput.wasPressed(MappedInputManager::Button::Confirm)) {
|
|
handleSelection();
|
|
requestUpdate();
|
|
return;
|
|
}
|
|
|
|
// Handle navigation
|
|
buttonNavigator.onNextRelease([this] {
|
|
const int menuCount = SETTINGS.useClock ? MENU_ITEMS : MENU_ITEMS - 1;
|
|
selectedIndex = ButtonNavigator::nextIndex(selectedIndex, menuCount);
|
|
requestUpdate();
|
|
});
|
|
|
|
buttonNavigator.onPreviousRelease([this] {
|
|
const int menuCount = SETTINGS.useClock ? MENU_ITEMS : MENU_ITEMS - 1;
|
|
selectedIndex = ButtonNavigator::previousIndex(selectedIndex, menuCount);
|
|
requestUpdate();
|
|
});
|
|
|
|
buttonNavigator.onNextContinuous([this] {
|
|
const int menuCount = SETTINGS.useClock ? MENU_ITEMS : MENU_ITEMS - 1;
|
|
selectedIndex = ButtonNavigator::nextIndex(selectedIndex, menuCount);
|
|
requestUpdate();
|
|
});
|
|
|
|
buttonNavigator.onPreviousContinuous([this] {
|
|
const int menuCount = SETTINGS.useClock ? MENU_ITEMS : MENU_ITEMS - 1;
|
|
selectedIndex = ButtonNavigator::previousIndex(selectedIndex, menuCount);
|
|
requestUpdate();
|
|
});
|
|
}
|
|
|
|
void StatusBarSettingsActivity::handleSelection() {
|
|
if (selectedIndex == 0) {
|
|
// Chapter Page Count
|
|
SETTINGS.statusBarChapterPageCount = (SETTINGS.statusBarChapterPageCount + 1) % 2;
|
|
} else if (selectedIndex == 1) {
|
|
// Book Progress %
|
|
SETTINGS.statusBarBookProgressPercentage = (SETTINGS.statusBarBookProgressPercentage + 1) % 2;
|
|
} else if (selectedIndex == 2) {
|
|
// Progress Bar
|
|
SETTINGS.statusBarProgressBar = (SETTINGS.statusBarProgressBar + 1) % PROGRESS_BAR_ITEMS;
|
|
} else if (selectedIndex == 3) {
|
|
// Progress Bar Thickness
|
|
SETTINGS.statusBarProgressBarThickness =
|
|
(SETTINGS.statusBarProgressBarThickness + 1) % PROGRESS_BAR_THICKNESS_ITEMS;
|
|
} else if (selectedIndex == 4) {
|
|
// Chapter Title
|
|
SETTINGS.statusBarTitle = (SETTINGS.statusBarTitle + 1) % TITLE_ITEMS;
|
|
} else if (selectedIndex == 5) {
|
|
// Show Battery
|
|
SETTINGS.statusBarBattery = (SETTINGS.statusBarBattery + 1) % 2;
|
|
} else if (selectedIndex == 6 && SETTINGS.useClock) {
|
|
// Show Clock
|
|
SETTINGS.statusBarClock = (SETTINGS.statusBarClock + 1) % 2;
|
|
}
|
|
SETTINGS.saveToFile();
|
|
}
|
|
|
|
void StatusBarSettingsActivity::render(RenderLock&&) {
|
|
renderer.clearScreen();
|
|
|
|
auto metrics = UITheme::getInstance().getMetrics();
|
|
const Rect contentRect = UITheme::getContentRect(renderer, true, false);
|
|
const int pageWidth = (int)renderer.getScreenWidth();
|
|
const int pageHeight = (int)renderer.getScreenHeight();
|
|
|
|
GUI.drawHeader(renderer, Rect{contentRect.x, metrics.topPadding, contentRect.width, metrics.headerHeight},
|
|
tr(STR_CUSTOMISE_STATUS_BAR));
|
|
|
|
const int contentTop = metrics.topPadding + metrics.headerHeight + metrics.verticalSpacing;
|
|
const int contentHeight = pageHeight - contentTop - metrics.buttonHintsHeight - metrics.verticalSpacing * 2;
|
|
const int menuCount = SETTINGS.useClock ? MENU_ITEMS : MENU_ITEMS - 1;
|
|
GUI.drawList(
|
|
renderer, Rect{0, contentTop, pageWidth, contentHeight}, static_cast<int>(menuCount),
|
|
static_cast<int>(selectedIndex), [](int index) { return std::string(I18N.get(menuNames[index])); }, nullptr,
|
|
nullptr,
|
|
[this](int index) {
|
|
// Draw status for each setting
|
|
if (index == 0) {
|
|
return SETTINGS.statusBarChapterPageCount ? tr(STR_SHOW) : tr(STR_HIDE);
|
|
} else if (index == 1) {
|
|
return SETTINGS.statusBarBookProgressPercentage ? tr(STR_SHOW) : tr(STR_HIDE);
|
|
} else if (index == 2) {
|
|
return I18N.get(progressBarNames[SETTINGS.statusBarProgressBar]);
|
|
} else if (index == 3) {
|
|
return I18N.get(progressBarThicknessNames[SETTINGS.statusBarProgressBarThickness]);
|
|
} else if (index == 4) {
|
|
return I18N.get(titleNames[SETTINGS.statusBarTitle]);
|
|
} else if (index == 5) {
|
|
return SETTINGS.statusBarBattery ? tr(STR_SHOW) : tr(STR_HIDE);
|
|
} else if (index == 6) {
|
|
return SETTINGS.statusBarClock ? tr(STR_SHOW) : tr(STR_HIDE);
|
|
} else {
|
|
return tr(STR_HIDE);
|
|
}
|
|
},
|
|
true);
|
|
|
|
// Draw button hints
|
|
const auto labels = mappedInput.mapLabels(tr(STR_BACK), tr(STR_TOGGLE), tr(STR_DIR_UP), tr(STR_DIR_DOWN));
|
|
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
|
|
|
|
std::string title;
|
|
if (SETTINGS.statusBarTitle == CrossPointSettings::STATUS_BAR_TITLE::BOOK_TITLE) {
|
|
title = tr(STR_EXAMPLE_BOOK);
|
|
} else if (SETTINGS.statusBarTitle == CrossPointSettings::STATUS_BAR_TITLE::CHAPTER_TITLE) {
|
|
title = tr(STR_EXAMPLE_CHAPTER);
|
|
}
|
|
|
|
GUI.drawStatusBar(renderer, 75, 8, 32, title, verticalPreviewPadding);
|
|
|
|
renderer.drawText(UI_10_FONT_ID, metrics.contentSidePadding,
|
|
renderer.getScreenHeight() - UITheme::getInstance().getStatusBarHeight() - verticalPreviewPadding -
|
|
verticalPreviewTextPadding,
|
|
tr(STR_PREVIEW));
|
|
|
|
renderer.displayBuffer();
|
|
}
|