From 530fd26a3b805a583556dc1e3c9f01b588eeb447 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sat, 28 Jan 2023 11:27:05 +0100 Subject: [PATCH] Added the ability to color shift badge icons, badge controller icons and badge folder link icons. --- es-core/src/ThemeData.cpp | 9 +++ es-core/src/components/BadgeComponent.cpp | 93 +++++++++++++++++++++++ 2 files changed, 102 insertions(+) diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 921ce2e90..9fe858417 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -361,6 +361,15 @@ std::map> {"folderLinkPos", NORMALIZED_PAIR}, {"folderLinkSize", FLOAT}, {"customFolderLinkIcon", PATH}, + {"badgeIconColor", COLOR}, + {"badgeIconColorEnd", COLOR}, + {"badgeIconGradientType", STRING}, + {"controllerIconColor", COLOR}, + {"controllerIconColorEnd", COLOR}, + {"controllerIconGradientType", STRING}, + {"folderLinkIconColor", COLOR}, + {"folderLinkIconColorEnd", COLOR}, + {"folderLinkIconGradientType", STRING}, {"opacity", FLOAT}, {"visible", BOOLEAN}, {"zIndex", FLOAT}}}, diff --git a/es-core/src/components/BadgeComponent.cpp b/es-core/src/components/BadgeComponent.cpp index 630af083c..cd3e54db3 100644 --- a/es-core/src/components/BadgeComponent.cpp +++ b/es-core/src/components/BadgeComponent.cpp @@ -293,6 +293,84 @@ void BadgeComponent::applyTheme(const std::shared_ptr& theme, } } + unsigned int badgeIconColorShift {0xFFFFFFFF}; + unsigned int badgeIconColorShiftEnd {0xFFFFFFFF}; + bool badgeIconColorGradientHorizontal {true}; + + if (elem->has("badgeIconColor")) { + badgeIconColorShift = elem->get("badgeIconColor"); + badgeIconColorShiftEnd = badgeIconColorShift; + } + if (elem->has("badgeIconColorEnd")) + badgeIconColorShiftEnd = elem->get("badgeIconColorEnd"); + if (elem->has("badgeIconGradientType")) { + const std::string& gradientType {elem->get("badgeIconGradientType")}; + if (gradientType == "horizontal") { + badgeIconColorGradientHorizontal = true; + } + else if (gradientType == "vertical") { + badgeIconColorGradientHorizontal = false; + } + else { + badgeIconColorGradientHorizontal = true; + LOG(LogWarning) << "BadgeComponent: Invalid theme configuration, property " + "\"badgeIconGradientType\" for element \"" + << element.substr(7) << "\" defined as \"" << gradientType << "\""; + } + } + + unsigned int controllerIconColorShift {0xFFFFFFFF}; + unsigned int controllerIconColorShiftEnd {0xFFFFFFFF}; + bool controllerIconColorGradientHorizontal {true}; + + if (elem->has("controllerIconColor")) { + controllerIconColorShift = elem->get("controllerIconColor"); + controllerIconColorShiftEnd = controllerIconColorShift; + } + if (elem->has("controllerIconColorEnd")) + controllerIconColorShiftEnd = elem->get("controllerIconColorEnd"); + if (elem->has("controllerIconGradientType")) { + const std::string& gradientType {elem->get("controllerIconGradientType")}; + if (gradientType == "horizontal") { + controllerIconColorGradientHorizontal = true; + } + else if (gradientType == "vertical") { + controllerIconColorGradientHorizontal = false; + } + else { + controllerIconColorGradientHorizontal = true; + LOG(LogWarning) << "BadgeComponent: Invalid theme configuration, property " + "\"controllerIconGradientType\" for element \"" + << element.substr(7) << "\" defined as \"" << gradientType << "\""; + } + } + + unsigned int folderLinkIconColorShift {0xFFFFFFFF}; + unsigned int folderLinkIconColorShiftEnd {0xFFFFFFFF}; + bool folderLinkIconColorGradientHorizontal {true}; + + if (elem->has("folderLinkIconColor")) { + folderLinkIconColorShift = elem->get("folderLinkIconColor"); + folderLinkIconColorShiftEnd = folderLinkIconColorShift; + } + if (elem->has("folderLinkIconColorEnd")) + folderLinkIconColorShiftEnd = elem->get("folderLinkIconColorEnd"); + if (elem->has("folderLinkIconGradientType")) { + const std::string& gradientType {elem->get("folderLinkIconGradientType")}; + if (gradientType == "horizontal") { + folderLinkIconColorGradientHorizontal = true; + } + else if (gradientType == "vertical") { + folderLinkIconColorGradientHorizontal = false; + } + else { + folderLinkIconColorGradientHorizontal = true; + LOG(LogWarning) << "BadgeComponent: Invalid theme configuration, property " + "\"folderLinkIconGradientType\" for element \"" + << element.substr(7) << "\" defined as \"" << gradientType << "\""; + } + } + if (elem->has("slots")) { // Replace possible whitespace separators with commas. std::string slotsTag {Utils::String::toLower(elem->get("slots"))}; @@ -336,6 +414,11 @@ void BadgeComponent::applyTheme(const std::shared_ptr& theme, item.baseImage = badgeImage; item.overlayImage = ImageComponent {false, false}; + item.baseImage.setColorShift(badgeIconColorShift); + item.baseImage.setColorShiftEnd(badgeIconColorShiftEnd); + if (badgeIconColorGradientHorizontal != true) + item.baseImage.setColorGradientHorizontal(badgeIconColorGradientHorizontal); + if (slot == "folder") { std::string folderLinkPath {":/graphics/badge_folderlink_overlay.svg"}; @@ -355,6 +438,11 @@ void BadgeComponent::applyTheme(const std::shared_ptr& theme, } item.overlayImage.setImage(folderLinkPath); + item.overlayImage.setColorShift(folderLinkIconColorShift); + item.overlayImage.setColorShiftEnd(folderLinkIconColorShiftEnd); + if (folderLinkIconColorGradientHorizontal != true) + item.overlayImage.setColorGradientHorizontal( + folderLinkIconColorGradientHorizontal); if (elem->has("folderLinkPos")) { glm::vec2 folderLinkPos {elem->get("folderLinkPos")}; @@ -374,6 +462,11 @@ void BadgeComponent::applyTheme(const std::shared_ptr& theme, controllerPos.x = glm::clamp(controllerPos.x, -1.0f, 2.0f); controllerPos.y = glm::clamp(controllerPos.y, -1.0f, 2.0f); item.overlayPosition = controllerPos; + item.overlayImage.setColorShift(controllerIconColorShift); + item.overlayImage.setColorShiftEnd(controllerIconColorShiftEnd); + if (controllerIconColorGradientHorizontal != true) + item.overlayImage.setColorGradientHorizontal( + controllerIconColorGradientHorizontal); } if (elem->has("controllerSize"))