diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 2c7ea2eda..cde942e77 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -44,20 +44,21 @@ std::vector ThemeData::sLegacySupportedFeatures { {"z-index"}, {"visible"}}; -std::vector ThemeData::sSupportedAspectRatios { - {"16:9"}, - {"16:9_vertical"}, - {"16:10"}, - {"16:10_vertical"}, - {"3:2"}, - {"3:2_vertical"}, - {"4:3"}, - {"4:3_vertical"}, - {"5:4"}, - {"5:4_vertical"}, - {"12:5"}, - {"43:18"}, - {"64:27"}}; +std::vector> ThemeData::sSupportedAspectRatios { + {"16:9", "16:9"}, + {"16:9_vertical", "16:9 vertical"}, + {"16:10", "16:10"}, + {"16:10_vertical", "16:10 vertical"}, + {"3:2", "3:2"}, + {"3:2_vertical", "3:2 vertical"}, + {"4:3", "4:3"}, + {"4:3_vertical", "4:3 vertical"}, + {"5:4", "5:4"}, + {"5:4_vertical", "5:4 vertical"}, + {"21:9", "21:9"}, + {"21:9_vertical", "21:9 vertical"}, + {"32:9", "32:0"}, + {"32:9_vertical", "32:9 vertical"}}; std::map> ThemeData::sPropertyAttributeMap // The data type is defined by the parent property. @@ -358,20 +359,13 @@ void ThemeData::loadFile(const std::map& sysDataMap, } if (mCurrentThemeSet->second.capabilities.aspectRatios.size() > 0) { - for (auto& aspectRatio : sSupportedAspectRatios) { - if (std::find(mCurrentThemeSet->second.capabilities.aspectRatios.cbegin(), - mCurrentThemeSet->second.capabilities.aspectRatios.cend(), - aspectRatio) != - mCurrentThemeSet->second.capabilities.aspectRatios.cend()) - mAspectRatios.emplace_back(aspectRatio); - } - - if (std::find(mAspectRatios.cbegin(), mAspectRatios.cend(), + if (std::find(mCurrentThemeSet->second.capabilities.aspectRatios.cbegin(), + mCurrentThemeSet->second.capabilities.aspectRatios.cend(), Settings::getInstance()->getString("ThemeAspectRatio")) != - mAspectRatios.cend()) + mCurrentThemeSet->second.capabilities.aspectRatios.cend()) mSelectedAspectRatio = Settings::getInstance()->getString("ThemeAspectRatio"); else - mSelectedAspectRatio = mAspectRatios.front(); + mSelectedAspectRatio = mCurrentThemeSet->second.capabilities.aspectRatios.front(); } } @@ -450,7 +444,7 @@ const ThemeData::ThemeElement* ThemeData::getElement(const std::string& view, return &elemIt->second; } -std::map& ThemeData::getThemeSets() +const std::map& ThemeData::getThemeSets() { if (!mThemeSets.empty()) return mThemeSets; @@ -505,7 +499,7 @@ std::map& ThemeData::getThemeSets() return mThemeSets; } -std::string ThemeData::getThemeFromCurrentSet(const std::string& system) +const std::string ThemeData::getThemeFromCurrentSet(const std::string& system) { if (mThemeSets.empty()) getThemeSets(); @@ -539,6 +533,18 @@ std::string ThemeData::getThemeFromCurrentSet(const std::string& system) return set->second.getThemePath(system); } +const std::string ThemeData::getAspectRatioLabel(const std::string& aspectRatio) +{ + auto it = std::find_if(sSupportedAspectRatios.cbegin(), sSupportedAspectRatios.cend(), + [&aspectRatio](const std::pair& entry) { + return entry.first == aspectRatio; + }); + if (it != sSupportedAspectRatios.cend()) + return it->second; + else + return "invalid ratio"; +} + const std::shared_ptr ThemeData::getDefault() { static std::shared_ptr theme = nullptr; @@ -606,6 +612,7 @@ std::string ThemeData::resolvePlaceholders(const std::string& in) ThemeData::ThemeCapability ThemeData::parseThemeCapabilities(const std::string& path) { ThemeCapability capabilities; + std::vector aspectRatiosTemp; std::string capFile {path + "/capabilities.xml"}; @@ -635,23 +642,26 @@ ThemeData::ThemeCapability ThemeData::parseThemeCapabilities(const std::string& for (pugi::xml_node aspectRatio = themeCapabilities.child("aspectRatio"); aspectRatio; aspectRatio = aspectRatio.next_sibling("aspectRatio")) { std::string value = aspectRatio.text().get(); - if (std::find(sSupportedAspectRatios.cbegin(), sSupportedAspectRatios.cend(), value) == - sSupportedAspectRatios.cend()) { + if (std::find_if(sSupportedAspectRatios.cbegin(), sSupportedAspectRatios.cend(), + [&value](const std::pair& entry) { + return entry.first == value; + }) == sSupportedAspectRatios.cend()) { LOG(LogWarning) << "Declared aspect ratio \"" << value << "\" is not supported, ignoring entry in \"" << capFile << "\""; } else { - if (std::find(capabilities.aspectRatios.cbegin(), capabilities.aspectRatios.cend(), - value) != capabilities.aspectRatios.cend()) { + if (std::find(aspectRatiosTemp.cbegin(), aspectRatiosTemp.cend(), value) != + aspectRatiosTemp.cend()) { LOG(LogWarning) << "Aspect ratio \"" << value << "\" is declared multiple times, ignoring entry in \"" << capFile << "\""; } else { - capabilities.aspectRatios.emplace_back(value); + aspectRatiosTemp.emplace_back(value); } } } + for (pugi::xml_node variant = themeCapabilities.child("variant"); variant; variant = variant.next_sibling("variant")) { ThemeVariant readVariant; @@ -758,6 +768,17 @@ ThemeData::ThemeCapability ThemeData::parseThemeCapabilities(const std::string& capabilities.legacyTheme = true; } + // Add the aspect ratios in the order they are defined in sSupportedAspectRatios so they + // always show up in the same order in the UI Settings menu. + if (!aspectRatiosTemp.empty()) { + for (auto& aspectRatio : sSupportedAspectRatios) { + if (std::find(aspectRatiosTemp.cbegin(), aspectRatiosTemp.cend(), aspectRatio.first) != + aspectRatiosTemp.cend()) { + capabilities.aspectRatios.emplace_back(aspectRatio.first); + } + } + } + return capabilities; } @@ -899,8 +920,9 @@ void ThemeData::parseAspectRatios(const pugi::xml_node& root) prevOff = nameAttr.find_first_not_of(delim, off); off = nameAttr.find_first_of(delim, prevOff); - if (std::find(mAspectRatios.cbegin(), mAspectRatios.cend(), viewKey) == - mAspectRatios.cend()) { + if (std::find(mCurrentThemeSet->second.capabilities.aspectRatios.cbegin(), + mCurrentThemeSet->second.capabilities.aspectRatios.cend(), + viewKey) == mCurrentThemeSet->second.capabilities.aspectRatios.cend()) { throw error << ": aspectRatio value \"" << viewKey << "\" is not defined in capabilities.xml"; } diff --git a/es-core/src/ThemeData.h b/es-core/src/ThemeData.h index 2a4b32780..b31a124cb 100644 --- a/es-core/src/ThemeData.h +++ b/es-core/src/ThemeData.h @@ -14,6 +14,7 @@ #include "utils/FileSystemUtil.h" #include "utils/MathUtil.h" +#include #include #include #include @@ -202,8 +203,9 @@ public: const std::string& element, const std::string& expectedType) const; - static std::map& getThemeSets(); - static std::string getThemeFromCurrentSet(const std::string& system); + const static std::map& getThemeSets(); + const static std::string getThemeFromCurrentSet(const std::string& system); + const static std::string getAspectRatioLabel(const std::string& aspectRatio); const bool isLegacyTheme() { return mLegacyTheme; } @@ -243,7 +245,7 @@ private: static std::vector sLegacySupportedFeatures; static std::vector sLegacySupportedViews; static std::vector sSupportedViews; - static std::vector sSupportedAspectRatios; + static std::vector> sSupportedAspectRatios; static inline std::map mThemeSets; std::map::iterator mCurrentThemeSet; @@ -251,7 +253,6 @@ private: std::map mViews; std::deque mPaths; std::vector mVariants; - std::vector mAspectRatios; std::string mSelectedVariant; std::string mSelectedAspectRatio; bool mLegacyTheme;