mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 22:57:50 +03:00
Update XtcReaderChapterSelectionActivity.cpp
This commit is contained in:
parent
b19e0b3c80
commit
93be1e072b
@ -84,32 +84,31 @@ void XtcReaderChapterSelectionActivity::loop() {
|
||||
const int pageItems = getPageItems();
|
||||
|
||||
if (mappedInput.wasReleased(MappedInputManager::Button::Confirm)) {
|
||||
const auto& chapters = xtc->getChapters();
|
||||
pagebegin=(page-1)*pageItems;
|
||||
const auto& chapters = xtc->getChapters_gd(pagebegin);
|
||||
if (!chapters.empty() && selectorIndex >= 0 && selectorIndex < static_cast<int>(chapters.size())) {
|
||||
onSelectPage(chapters[selectorIndex].startPage);
|
||||
}
|
||||
} else if (mappedInput.wasReleased(MappedInputManager::Button::Back)) {
|
||||
} else if (mappedInput.wasReleased(MappedInputManager::Button::Back)) {
|
||||
onGoBack();
|
||||
} else if (prevReleased) {
|
||||
const int total = static_cast<int>(xtc->getChapters().size());
|
||||
if (total == 0) {
|
||||
return;
|
||||
}
|
||||
if (skipPage) {
|
||||
selectorIndex = ((selectorIndex / pageItems - 1) * pageItems + total) % total;
|
||||
bool isUpKey = mappedInput.wasReleased(MappedInputManager::Button::Up);
|
||||
if (skipPage || isUpKey) {
|
||||
page -= 1;
|
||||
if(page < 1) page = 1;
|
||||
selectorIndex = (page-1)*pageItems;
|
||||
} else {
|
||||
selectorIndex = (selectorIndex + total - 1) % total;
|
||||
selectorIndex--;
|
||||
if(selectorIndex < 0) selectorIndex = 0;
|
||||
}
|
||||
updateRequired = true;
|
||||
} else if (nextReleased) {
|
||||
const int total = static_cast<int>(xtc->getChapters().size());
|
||||
if (total == 0) {
|
||||
return;
|
||||
}
|
||||
if (skipPage) {
|
||||
selectorIndex = ((selectorIndex / pageItems + 1) * pageItems) % total;
|
||||
bool isDownKey = mappedInput.wasReleased(MappedInputManager::Button::Down);
|
||||
if (skipPage || isDownKey) {
|
||||
page += 1;
|
||||
selectorIndex = (page-1)*pageItems;
|
||||
} else {
|
||||
selectorIndex = (selectorIndex + 1) % total;
|
||||
selectorIndex++;
|
||||
}
|
||||
updateRequired = true;
|
||||
}
|
||||
@ -143,14 +142,21 @@ void XtcReaderChapterSelectionActivity::renderScreen() {
|
||||
|
||||
const auto pageStartIndex = selectorIndex / pageItems * pageItems;
|
||||
renderer.fillRect(0, 60 + (selectorIndex % pageItems) * 30 - 2, pageWidth - 1, 30);
|
||||
for (int i = pageStartIndex; i < static_cast<int>(chapters.size()) && i < pageStartIndex + pageItems; i++) {
|
||||
const auto& chapter = chapters[i];
|
||||
const char* title = chapter.name.empty() ? "Unnamed" : chapter.name.c_str();
|
||||
renderer.drawText(UI_10_FONT_ID, 20, 60 + (i % pageItems) * 30, title, i != selectorIndex);
|
||||
}
|
||||
for (int i = pagebegin; i <= pagebegin + pageItems - 1; i++) {
|
||||
int localIdx = i - pagebegin;
|
||||
|
||||
uint32_t currOffset = this->xtc->getChapterstartpage(i);
|
||||
std::string dirTitle = this->xtc->getChapterTitleByIndex(i);
|
||||
|
||||
Serial.printf("[%lu] [XTC_CHAPTER] 第%d章,名字为:%s,页码为%d\n", millis(), i, dirTitle.c_str(),currOffset);
|
||||
static char title[64];
|
||||
strncpy(title, dirTitle.c_str(), sizeof(title)-1);
|
||||
title[sizeof(title)-1] = '\0';
|
||||
|
||||
int drawY = BASE_Y + localIdx * FIX_LINE_HEIGHT;
|
||||
|
||||
const auto labels = mappedInput.mapLabels("« Back", "Select", "Up", "Down");
|
||||
renderer.drawButtonHints(UI_10_FONT_ID, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
|
||||
Serial.printf("选中的选项是:%d\n",selectorIndex);
|
||||
renderer.drawText(UI_10_FONT_ID, 20, drawY, title, i!= selectorIndex);
|
||||
}
|
||||
|
||||
renderer.displayBuffer();
|
||||
}
|
||||
renderer.displayBuffer();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user