mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-05 07:07:38 +03:00
Crop home page covers
This commit is contained in:
parent
781a01a6ef
commit
f5508f291e
@ -263,7 +263,7 @@ void HomeActivity::render() {
|
|||||||
if (hasContinueReading) {
|
if (hasContinueReading) {
|
||||||
if (recentsLoaded) {
|
if (recentsLoaded) {
|
||||||
recentsDisplayed = true;
|
recentsDisplayed = true;
|
||||||
UITheme::drawRecentBookCover(renderer, Rect{0, metrics.homeTopPadding, pageWidth, metrics.homeCoverHeight},
|
UITheme::drawRecentBookCover(renderer, Rect{0, metrics.homeTopPadding, pageWidth, metrics.homeCoverTileHeight},
|
||||||
recentBooks, selectorIndex, coverRendered, coverBufferStored, bufferRestored,
|
recentBooks, selectorIndex, coverRendered, coverBufferStored, bufferRestored,
|
||||||
std::bind(&HomeActivity::storeCoverBuffer, this));
|
std::bind(&HomeActivity::storeCoverBuffer, this));
|
||||||
} else if (!recentsLoading && firstRenderDone) {
|
} else if (!recentsLoading && firstRenderDone) {
|
||||||
@ -282,7 +282,7 @@ void HomeActivity::render() {
|
|||||||
|
|
||||||
UITheme::drawButtonMenu(
|
UITheme::drawButtonMenu(
|
||||||
renderer,
|
renderer,
|
||||||
Rect{0, metrics.homeTopPadding + metrics.homeCoverHeight + metrics.verticalSpacing, pageWidth,
|
Rect{0, metrics.homeTopPadding + metrics.homeCoverTileHeight + metrics.verticalSpacing, pageWidth,
|
||||||
pageHeight - (metrics.headerHeight + metrics.homeTopPadding + metrics.verticalSpacing * 2 +
|
pageHeight - (metrics.headerHeight + metrics.homeTopPadding + metrics.verticalSpacing * 2 +
|
||||||
metrics.buttonHintsHeight)},
|
metrics.buttonHintsHeight)},
|
||||||
static_cast<int>(menuItems.size()), selectorIndex - recentBooks.size(),
|
static_cast<int>(menuItems.size()), selectorIndex - recentBooks.size(),
|
||||||
|
|||||||
@ -45,6 +45,7 @@ struct ThemeMetrics {
|
|||||||
|
|
||||||
int homeTopPadding;
|
int homeTopPadding;
|
||||||
int homeCoverHeight;
|
int homeCoverHeight;
|
||||||
|
int homeCoverTileHeight;
|
||||||
int homeRecentBooksCount;
|
int homeRecentBooksCount;
|
||||||
|
|
||||||
int buttonHintsHeight;
|
int buttonHintsHeight;
|
||||||
|
|||||||
@ -29,6 +29,7 @@ constexpr ThemeMetrics values = {.batteryWidth = 15,
|
|||||||
.scrollBarRightOffset = 5,
|
.scrollBarRightOffset = 5,
|
||||||
.homeTopPadding = 20,
|
.homeTopPadding = 20,
|
||||||
.homeCoverHeight = 400,
|
.homeCoverHeight = 400,
|
||||||
|
.homeCoverTileHeight = 400,
|
||||||
.homeRecentBooksCount = 1,
|
.homeRecentBooksCount = 1,
|
||||||
.buttonHintsHeight = 40,
|
.buttonHintsHeight = 40,
|
||||||
.sideButtonHintsWidth = 30,
|
.sideButtonHintsWidth = 30,
|
||||||
|
|||||||
@ -250,7 +250,7 @@ void LyraTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect,
|
|||||||
std::function<bool()> storeCoverBuffer) {
|
std::function<bool()> storeCoverBuffer) {
|
||||||
const int tileWidth = (rect.width - 2 * LyraMetrics::values.contentSidePadding) / 3;
|
const int tileWidth = (rect.width - 2 * LyraMetrics::values.contentSidePadding) / 3;
|
||||||
const int tileHeight = rect.height;
|
const int tileHeight = rect.height;
|
||||||
const int bookTitleHeight = 53;
|
const int bookTitleHeight = tileHeight - LyraMetrics::values.homeCoverHeight - hPaddingInSelection;
|
||||||
const int tileY = rect.y;
|
const int tileY = rect.y;
|
||||||
const bool hasContinueReading = !recentBooks.empty();
|
const bool hasContinueReading = !recentBooks.empty();
|
||||||
|
|
||||||
@ -274,9 +274,15 @@ void LyraTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect,
|
|||||||
if (SdMan.openFileForRead("HOME", coverBmpPath, file)) {
|
if (SdMan.openFileForRead("HOME", coverBmpPath, file)) {
|
||||||
Bitmap bitmap(file);
|
Bitmap bitmap(file);
|
||||||
if (bitmap.parseHeaders() == BmpReaderError::Ok) {
|
if (bitmap.parseHeaders() == BmpReaderError::Ok) {
|
||||||
|
float coverHeight = static_cast<float>(bitmap.getHeight());
|
||||||
|
float coverWidth = static_cast<float>(bitmap.getWidth());
|
||||||
|
float ratio = coverWidth / coverHeight;
|
||||||
|
const float tileRatio = static_cast<float>(tileWidth - 2 * hPaddingInSelection) /
|
||||||
|
static_cast<float>(LyraMetrics::values.homeCoverHeight);
|
||||||
|
float cropX = 1.0f - (tileRatio / ratio);
|
||||||
|
|
||||||
renderer.drawBitmap(bitmap, tileX + hPaddingInSelection, tileY + hPaddingInSelection,
|
renderer.drawBitmap(bitmap, tileX + hPaddingInSelection, tileY + hPaddingInSelection,
|
||||||
tileWidth - 2 * hPaddingInSelection,
|
tileWidth - 2 * hPaddingInSelection, LyraMetrics::values.homeCoverHeight, cropX);
|
||||||
tileHeight - bookTitleHeight - hPaddingInSelection);
|
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
@ -298,10 +304,10 @@ void LyraTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect,
|
|||||||
renderer.fillRoundedRect(tileX, tileY, tileWidth, hPaddingInSelection, cornerRadius, true, true, false, false,
|
renderer.fillRoundedRect(tileX, tileY, tileWidth, hPaddingInSelection, cornerRadius, true, true, false, false,
|
||||||
COLOR_LIGHT_GRAY);
|
COLOR_LIGHT_GRAY);
|
||||||
renderer.fillRectDither(tileX, tileY + hPaddingInSelection, hPaddingInSelection,
|
renderer.fillRectDither(tileX, tileY + hPaddingInSelection, hPaddingInSelection,
|
||||||
tileHeight - hPaddingInSelection, COLOR_LIGHT_GRAY);
|
LyraMetrics::values.homeCoverHeight, COLOR_LIGHT_GRAY);
|
||||||
renderer.fillRectDither(tileX + tileWidth - hPaddingInSelection, tileY + hPaddingInSelection,
|
renderer.fillRectDither(tileX + tileWidth - hPaddingInSelection, tileY + hPaddingInSelection,
|
||||||
hPaddingInSelection, tileHeight - hPaddingInSelection, COLOR_LIGHT_GRAY);
|
hPaddingInSelection, LyraMetrics::values.homeCoverHeight, COLOR_LIGHT_GRAY);
|
||||||
renderer.fillRoundedRect(tileX, tileY + tileHeight + hPaddingInSelection - bookTitleHeight, tileWidth,
|
renderer.fillRoundedRect(tileX, tileY + LyraMetrics::values.homeCoverHeight + hPaddingInSelection, tileWidth,
|
||||||
bookTitleHeight, cornerRadius, false, false, true, true, COLOR_LIGHT_GRAY);
|
bookTitleHeight, cornerRadius, false, false, true, true, COLOR_LIGHT_GRAY);
|
||||||
}
|
}
|
||||||
renderer.drawText(UI_10_FONT_ID, tileX + hPaddingInSelection,
|
renderer.drawText(UI_10_FONT_ID, tileX + hPaddingInSelection,
|
||||||
|
|||||||
@ -21,7 +21,8 @@ constexpr ThemeMetrics values = {.batteryWidth = 16,
|
|||||||
.scrollBarWidth = 4,
|
.scrollBarWidth = 4,
|
||||||
.scrollBarRightOffset = 5,
|
.scrollBarRightOffset = 5,
|
||||||
.homeTopPadding = 56,
|
.homeTopPadding = 56,
|
||||||
.homeCoverHeight = 266,
|
.homeCoverHeight = 226,
|
||||||
|
.homeCoverTileHeight = 327,
|
||||||
.homeRecentBooksCount = 3,
|
.homeRecentBooksCount = 3,
|
||||||
.buttonHintsHeight = 40,
|
.buttonHintsHeight = 40,
|
||||||
.sideButtonHintsWidth = 19,
|
.sideButtonHintsWidth = 19,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user