mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 22:57:50 +03:00
feat: better icon loading for themes
This commit is contained in:
parent
dccd200b86
commit
40b5420e11
@ -30,26 +30,28 @@ void Icon::draw(const GfxRenderer& renderer, const ThemeContext& context) {
|
||||
int cx = absX + w / 2;
|
||||
int cy = absY + h / 2;
|
||||
|
||||
// Check if it's a path to a BMP file
|
||||
if (iconName.find('/') != std::string::npos || iconName.find('.') != std::string::npos) {
|
||||
// Try to load as bitmap
|
||||
std::string path = iconName;
|
||||
if (path[0] != '/') {
|
||||
path = ThemeManager::get().getAssetPath(iconName);
|
||||
}
|
||||
// 1. Try to load as a theme asset (exact match or .bmp extension)
|
||||
std::string path = iconName;
|
||||
bool isPath = iconName.find('/') != std::string::npos || iconName.find('.') != std::string::npos;
|
||||
|
||||
const std::vector<uint8_t>* data = ThemeManager::get().getCachedAsset(path);
|
||||
if (data && !data->empty()) {
|
||||
Bitmap bmp(data->data(), data->size());
|
||||
if (bmp.parseHeaders() == BmpReaderError::Ok) {
|
||||
renderer.drawBitmap(bmp, absX, absY, w, h);
|
||||
markClean();
|
||||
return;
|
||||
}
|
||||
std::string assetPath = path;
|
||||
if (!isPath) {
|
||||
assetPath = ThemeManager::get().getAssetPath(iconName + ".bmp");
|
||||
} else if (path[0] != '/') {
|
||||
assetPath = ThemeManager::get().getAssetPath(iconName);
|
||||
}
|
||||
|
||||
const std::vector<uint8_t>* data = ThemeManager::get().getCachedAsset(assetPath);
|
||||
if (data && !data->empty()) {
|
||||
Bitmap bmp(data->data(), data->size());
|
||||
if (bmp.parseHeaders() == BmpReaderError::Ok) {
|
||||
renderer.drawBitmap(bmp, absX, absY, w, h);
|
||||
markClean();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Built-in icons (simple geometric shapes)
|
||||
// 2. Built-in icons (simple geometric shapes) as fallback
|
||||
if (iconName == "heart" || iconName == "favorite") {
|
||||
// Simple heart shape approximation
|
||||
int s = w / 4;
|
||||
|
||||
@ -22,7 +22,11 @@ std::string ThemeManager::getAssetPath(const std::string& assetName) {
|
||||
// Check if absolute path
|
||||
if (!assetName.empty() && assetName[0] == '/') return assetName;
|
||||
|
||||
// Otherwise relative to theme assets
|
||||
// Otherwise relative to theme root
|
||||
std::string rootPath = "/themes/" + currentThemeName + "/" + assetName;
|
||||
if (SdMan.exists(rootPath.c_str())) return rootPath;
|
||||
|
||||
// Fallback to assets/ subfolder
|
||||
return "/themes/" + currentThemeName + "/assets/" + assetName;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user