Added an 'interpolation' property to the badge element

This commit is contained in:
Leon Styhre 2023-09-30 11:36:10 +02:00
parent c988170641
commit fcc46148e9
3 changed files with 21 additions and 0 deletions

View file

@ -383,6 +383,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"folderLinkIconColor", COLOR},
{"folderLinkIconColorEnd", COLOR},
{"folderLinkIconGradientType", STRING},
{"interpolation", STRING},
{"opacity", FLOAT},
{"visible", BOOLEAN},
{"zIndex", FLOAT}}},

View file

@ -76,6 +76,7 @@ BadgeComponent::BadgeComponent()
, mFlexboxComponent {mFlexboxItems}
, mBadgeTypes {{SLOT_COLLECTION, SLOT_FOLDER, SLOT_FAVORITE, SLOT_COMPLETED, SLOT_KIDGAME,
SLOT_BROKEN, SLOT_CONTROLLER, SLOT_ALTEMULATOR, SLOT_MANUAL}}
, mLinearInterpolation {false}
{
mBadgeIcons[SLOT_COLLECTION] = ":/graphics/badge_collection.svg";
mBadgeIcons[SLOT_FOLDER] = ":/graphics/badge_folder.svg";
@ -300,6 +301,21 @@ void BadgeComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
}
if (elem->has("interpolation")) {
const std::string& interpolation {elem->get<std::string>("interpolation")};
if (interpolation == "linear") {
mLinearInterpolation = true;
}
else if (interpolation == "nearest") {
mLinearInterpolation = false;
}
else {
LOG(LogWarning) << "BadgeComponent: Invalid theme configuration, property "
"\"interpolation\" for element \""
<< element.substr(7) << "\" defined as \"" << interpolation << "\"";
}
}
unsigned int badgeIconColorShift {0xFFFFFFFF};
unsigned int badgeIconColorShiftEnd {0xFFFFFFFF};
bool badgeIconColorGradientHorizontal {true};
@ -417,9 +433,11 @@ void BadgeComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
item.label = slot;
ImageComponent badgeImage {false, false};
badgeImage.setLinearInterpolation(mLinearInterpolation);
badgeImage.setImage(mBadgeIcons[slot]);
item.baseImage = badgeImage;
item.overlayImage = ImageComponent {false, false};
item.overlayImage.setLinearInterpolation(mLinearInterpolation);
item.baseImage.setColorShift(badgeIconColorShift);
item.baseImage.setColorShiftEnd(badgeIconColorShiftEnd);

View file

@ -62,6 +62,8 @@ private:
std::vector<std::string> mBadgeTypes;
std::map<std::string, std::string> mBadgeIcons;
bool mLinearInterpolation;
};
#endif // ES_CORE_COMPONENTS_BADGE_COMPONENT_H