mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-08 08:37:38 +03:00
Compare commits
4 Commits
72de88c3bf
...
7bfb3af0da
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7bfb3af0da | ||
|
|
e6f6f14b37 | ||
|
|
a4310bf2c3 | ||
|
|
75cc861bd0 |
@ -805,7 +805,8 @@ void GfxRenderer::drawBitmap1Bit(const Bitmap& bitmap, const int x, const int y,
|
||||
free(rowBytes);
|
||||
}
|
||||
|
||||
void GfxRenderer::drawTransparentBitmap(const Bitmap& bitmap, const int x, const int y, const int w, const int h) const {
|
||||
void GfxRenderer::drawTransparentBitmap(const Bitmap& bitmap, const int x, const int y, const int w,
|
||||
const int h) const {
|
||||
// Similar to drawBitmap1Bit but strictly skips 1s (white) in the source 1-bit data
|
||||
// The Bitmap reader returns 2-bit packed data where 0-2=Black and 3=White for 1-bit sources
|
||||
|
||||
|
||||
@ -78,7 +78,8 @@ class GfxRenderer {
|
||||
float cropY = 0) const;
|
||||
void drawBitmap1Bit(const Bitmap& bitmap, const int x, const int y, const int maxWidth, const int maxHeight) const;
|
||||
void drawTransparentBitmap(const Bitmap& bitmap, const int x, const int y, const int w, const int h) const;
|
||||
void drawRoundedBitmap(const Bitmap& bitmap, const int x, const int y, const int w, const int h, const int radius) const;
|
||||
void drawRoundedBitmap(const Bitmap& bitmap, const int x, const int y, const int w, const int h,
|
||||
const int radius) const;
|
||||
void draw2BitImage(const uint8_t data[], int x, int y, int w, int h) const;
|
||||
void fillPolygon(const int* xPoints, const int* yPoints, int numPoints, bool state = true) const;
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ class Container : public UIElement {
|
||||
int borderRadius = 0; // Corner radius (for future rounded rect support)
|
||||
|
||||
public:
|
||||
Container(const std::string& id) : UIElement(id) { bgColorExpr = Expression::parse("0xFF"); }
|
||||
explicit Container(const std::string& id) : UIElement(id), bgColorExpr(Expression::parse("0xFF")) {}
|
||||
virtual ~Container() {
|
||||
for (auto child : children) delete child;
|
||||
}
|
||||
@ -145,7 +145,7 @@ class Rectangle : public UIElement {
|
||||
Expression colorExpr;
|
||||
|
||||
public:
|
||||
Rectangle(const std::string& id) : UIElement(id) { colorExpr = Expression::parse("0x00"); }
|
||||
explicit Rectangle(const std::string& id) : UIElement(id), colorExpr(Expression::parse("0x00")) {}
|
||||
ElementType getType() const override { return ElementType::Rectangle; }
|
||||
|
||||
void setFill(bool f) {
|
||||
@ -199,7 +199,7 @@ class Label : public UIElement {
|
||||
bool ellipsis = true; // Truncate with ... if too long
|
||||
|
||||
public:
|
||||
Label(const std::string& id) : UIElement(id) { colorExpr = Expression::parse("0x00"); }
|
||||
explicit Label(const std::string& id) : UIElement(id), colorExpr(Expression::parse("0x00")) {}
|
||||
ElementType getType() const override { return ElementType::Label; }
|
||||
|
||||
void setText(const std::string& expr) {
|
||||
@ -367,7 +367,7 @@ class BitmapElement : public UIElement {
|
||||
int borderRadius = 0;
|
||||
|
||||
public:
|
||||
BitmapElement(const std::string& id) : UIElement(id) {
|
||||
explicit BitmapElement(const std::string& id) : UIElement(id) {
|
||||
cacheable = true; // Bitmaps benefit from caching
|
||||
}
|
||||
ElementType getType() const override { return ElementType::Bitmap; }
|
||||
@ -407,12 +407,13 @@ class ProgressBar : public UIElement {
|
||||
int borderWidth = 1;
|
||||
|
||||
public:
|
||||
ProgressBar(const std::string& id) : UIElement(id) {
|
||||
valueExpr = Expression::parse("0");
|
||||
maxExpr = Expression::parse("100");
|
||||
fgColorExpr = Expression::parse("0x00"); // Black fill
|
||||
bgColorExpr = Expression::parse("0xFF"); // White background
|
||||
}
|
||||
explicit ProgressBar(const std::string& id)
|
||||
: UIElement(id),
|
||||
valueExpr(Expression::parse("0")),
|
||||
maxExpr(Expression::parse("100")),
|
||||
fgColorExpr(Expression::parse("0x00")), // Black fill
|
||||
bgColorExpr(Expression::parse("0xFF")) // White background
|
||||
{}
|
||||
|
||||
ElementType getType() const override { return ElementType::ProgressBar; }
|
||||
|
||||
@ -480,7 +481,7 @@ class Divider : public UIElement {
|
||||
int thickness = 1;
|
||||
|
||||
public:
|
||||
Divider(const std::string& id) : UIElement(id) { colorExpr = Expression::parse("0x00"); }
|
||||
explicit Divider(const std::string& id) : UIElement(id), colorExpr(Expression::parse("0x00")) {}
|
||||
|
||||
ElementType getType() const override { return ElementType::Divider; }
|
||||
|
||||
@ -524,9 +525,9 @@ class BatteryIcon : public UIElement {
|
||||
Expression colorExpr;
|
||||
|
||||
public:
|
||||
BatteryIcon(const std::string& id) : UIElement(id) {
|
||||
valueExpr = Expression::parse("0");
|
||||
colorExpr = Expression::parse("0x00"); // Black by default
|
||||
explicit BatteryIcon(const std::string& id)
|
||||
: UIElement(id), valueExpr(Expression::parse("0")), colorExpr(Expression::parse("0x00")) {
|
||||
// Black by default
|
||||
}
|
||||
|
||||
ElementType getType() const override { return ElementType::BatteryIcon; }
|
||||
|
||||
@ -83,7 +83,7 @@ class ThemeContext {
|
||||
}
|
||||
|
||||
public:
|
||||
ThemeContext(const ThemeContext* parent = nullptr) : parent(parent) {}
|
||||
explicit ThemeContext(const ThemeContext* parent = nullptr) : parent(parent) {}
|
||||
|
||||
void setString(const std::string& key, const std::string& value) { strings[key] = value; }
|
||||
void setInt(const std::string& key, int value) { ints[key] = value; }
|
||||
|
||||
@ -34,7 +34,7 @@ struct Dimension {
|
||||
struct Color {
|
||||
uint8_t value; // For E-Ink: 0 (Black) to 255 (White), or simplified palette
|
||||
|
||||
Color(uint8_t v) : value(v) {}
|
||||
explicit Color(uint8_t v) : value(v) {}
|
||||
Color() : value(0) {}
|
||||
|
||||
static Color parse(const std::string& str) {
|
||||
|
||||
@ -45,7 +45,7 @@ class UIElement {
|
||||
}
|
||||
|
||||
public:
|
||||
UIElement(const std::string& id) : id(id) { visibleExpr = Expression::parse("true"); }
|
||||
UIElement(const std::string& id) : id(id), visibleExpr(Expression::parse("true")) {}
|
||||
|
||||
virtual ~UIElement() {
|
||||
if (cachedRender) {
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
#include "BasicElements.h"
|
||||
|
||||
#include <GfxRenderer.h>
|
||||
|
||||
#include "Bitmap.h"
|
||||
#include "ListElement.h"
|
||||
#include "ThemeManager.h"
|
||||
#include "ThemeTypes.h"
|
||||
#include <GfxRenderer.h>
|
||||
|
||||
namespace ThemeEngine {
|
||||
|
||||
|
||||
@ -229,21 +229,6 @@ bool HomeActivity::storeCoverBuffer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool HomeActivity::restoreCoverBuffer() {
|
||||
if (!coverBuffer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t* frameBuffer = renderer.getFrameBuffer();
|
||||
if (!frameBuffer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const size_t bufferSize = GfxRenderer::getBufferSize();
|
||||
memcpy(frameBuffer, coverBuffer, bufferSize);
|
||||
return true;
|
||||
}
|
||||
|
||||
void HomeActivity::freeCoverBuffer() {
|
||||
if (coverBuffer) {
|
||||
free(coverBuffer);
|
||||
@ -364,6 +349,74 @@ void HomeActivity::render() {
|
||||
context.setBool("HasCover", hasContinueReading && hasCoverImage && !coverBmpPath.empty());
|
||||
context.setBool("ShowInfoBox", true);
|
||||
|
||||
// Default values
|
||||
std::string chapterTitle = "";
|
||||
std::string currentPageStr = "-";
|
||||
std::string totalPagesStr = "-";
|
||||
int progressPercent = 0;
|
||||
|
||||
if (hasContinueReading) {
|
||||
if (StringUtils::checkFileExtension(APP_STATE.openEpubPath, ".epub")) {
|
||||
Epub epub(APP_STATE.openEpubPath, "/.crosspoint");
|
||||
epub.load(false);
|
||||
|
||||
// Read progress
|
||||
FsFile f;
|
||||
if (SdMan.openFileForRead("HOME", epub.getCachePath() + "/progress.bin", f)) {
|
||||
uint8_t data[4];
|
||||
if (f.read(data, 4) == 4) {
|
||||
int spineIndex = data[0] + (data[1] << 8);
|
||||
int spineCount = epub.getSpineItemsCount();
|
||||
|
||||
currentPageStr = std::to_string(spineIndex + 1); // Display 1-based
|
||||
totalPagesStr = std::to_string(spineCount);
|
||||
|
||||
if (spineCount > 0) {
|
||||
progressPercent = (spineIndex * 100) / spineCount;
|
||||
}
|
||||
|
||||
// Resolve Chapter Title
|
||||
auto spineEntry = epub.getSpineItem(spineIndex);
|
||||
if (spineEntry.tocIndex != -1) {
|
||||
auto tocEntry = epub.getTocItem(spineEntry.tocIndex);
|
||||
chapterTitle = tocEntry.title;
|
||||
}
|
||||
}
|
||||
f.close();
|
||||
}
|
||||
} else if (StringUtils::checkFileExtension(APP_STATE.openEpubPath, ".xtc") ||
|
||||
StringUtils::checkFileExtension(APP_STATE.openEpubPath, ".xtch")) {
|
||||
Xtc xtc(APP_STATE.openEpubPath, "/.crosspoint");
|
||||
if (xtc.load()) {
|
||||
// Read progress
|
||||
FsFile f;
|
||||
if (SdMan.openFileForRead("HOME", xtc.getCachePath() + "/progress.bin", f)) {
|
||||
uint8_t data[4];
|
||||
if (f.read(data, 4) == 4) {
|
||||
uint32_t currentPage = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
|
||||
uint32_t totalPages = xtc.getPageCount();
|
||||
|
||||
currentPageStr = std::to_string(currentPage + 1); // 1-based
|
||||
totalPagesStr = std::to_string(totalPages);
|
||||
|
||||
if (totalPages > 0) {
|
||||
progressPercent = (currentPage * 100) / totalPages;
|
||||
}
|
||||
|
||||
chapterTitle = "Page " + currentPageStr;
|
||||
}
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context.setString("BookChapter", chapterTitle);
|
||||
context.setString("BookCurrentPage", currentPageStr);
|
||||
context.setString("BookTotalPages", totalPagesStr);
|
||||
context.setInt("BookProgressPercent", progressPercent);
|
||||
context.setString("BookProgressPercentStr", std::to_string(progressPercent));
|
||||
|
||||
// --- Main Menu Data ---
|
||||
// Menu items start after the book slot
|
||||
const int menuStartIdx = navBookCount;
|
||||
|
||||
@ -47,7 +47,7 @@ class HomeActivity final : public Activity {
|
||||
void render();
|
||||
int getMenuItemCount() const;
|
||||
bool storeCoverBuffer(); // Store frame buffer for cover image
|
||||
bool restoreCoverBuffer(); // Restore frame buffer from stored cover
|
||||
|
||||
void freeCoverBuffer(); // Free the stored cover buffer
|
||||
void loadRecentBooksData(); // Load and cache recent books data
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user