diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index dbf443afb..07819e888 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -1066,10 +1066,15 @@ void ThemeData::parseElement(const pugi::xml_node& root, std::string nodeName = node.name(); - if (!mLegacyTheme && element.type == "video") { - if (nodeName == "showSnapshotNoVideo" || nodeName == "showSnapshotDelay") + if (!mLegacyTheme) { + if (nodeName == "showSnapshotNoVideo" || nodeName == "showSnapshotDelay") { throw error << ": Legacy <" << nodeName << "> property found for non-legacy theme set"; + } + else if (nodeName == "forceUppercase") { + throw error << ": Legacy <" << nodeName + << "> property found for non-legacy theme set"; + } } // If an attribute exists, then replace nodeName with its name. diff --git a/es-core/src/ThemeData.h b/es-core/src/ThemeData.h index a256d8a6d..15288ffa4 100644 --- a/es-core/src/ThemeData.h +++ b/es-core/src/ThemeData.h @@ -50,12 +50,13 @@ namespace ThemeFlags ALIGNMENT = 0x00000080, TEXT = 0x00000100, METADATA = 0x00000200, - FORCE_UPPERCASE = 0x00000400, - LINE_SPACING = 0x00000800, - DELAY = 0x00001000, - Z_INDEX = 0x00002000, - ROTATION = 0x00004000, - VISIBLE = 0x00008000, + LETTER_CASE = 0x00000400, + FORCE_UPPERCASE = 0x00000800, // For backward compatibility with legacy themes. + LINE_SPACING = 0x00001000, + DELAY = 0x00002000, + Z_INDEX = 0x00004000, + ROTATION = 0x00008000, + VISIBLE = 0x00010000, ALL = 0xFFFFFFFF }; // clang-format on diff --git a/es-core/src/components/CarouselComponent.cpp b/es-core/src/components/CarouselComponent.cpp index 7cbdcb6ba..1cd128c53 100644 --- a/es-core/src/components/CarouselComponent.cpp +++ b/es-core/src/components/CarouselComponent.cpp @@ -94,8 +94,8 @@ void CarouselComponent::addEntry(const std::shared_ptr& theme, if (legacyMode) { text->applyTheme(theme, "system", "text_logoText", ThemeFlags::FONT_PATH | ThemeFlags::FONT_SIZE | ThemeFlags::COLOR | - ThemeFlags::FORCE_UPPERCASE | ThemeFlags::LINE_SPACING | - ThemeFlags::TEXT); + ThemeFlags::LETTER_CASE | ThemeFlags::FORCE_UPPERCASE | + ThemeFlags::LINE_SPACING | ThemeFlags::TEXT); } if (!legacyMode) { text->setLineSpacing(mLineSpacing); @@ -401,14 +401,24 @@ void CarouselComponent::applyTheme(const std::shared_ptr& theme, letterCase = elem->get("letterCase"); if (elem->has("text")) { - if (letterCase == "uppercase") + if (letterCase == "uppercase") { mText = Utils::String::toUpper(elem->get("text")); - else if (letterCase == "lowercase") + } + else if (letterCase == "lowercase") { mText = Utils::String::toLower(elem->get("text")); - else if (letterCase == "capitalize") + } + else if (letterCase == "capitalize") { mText = Utils::String::toCapitalized(elem->get("text")); - else + } + else if (letterCase == "none") { mText = elem->get("text"); + } + else { + LOG(LogWarning) + << "CarouselComponent: Invalid theme configuration, property set to \"" + << letterCase << "\""; + mText = elem->get("text"); + } } GuiComponent::applyTheme(theme, view, element, ALL); diff --git a/es-core/src/components/DateTimeComponent.cpp b/es-core/src/components/DateTimeComponent.cpp index 3ab63c81b..59efb5440 100644 --- a/es-core/src/components/DateTimeComponent.cpp +++ b/es-core/src/components/DateTimeComponent.cpp @@ -147,6 +147,25 @@ void DateTimeComponent::applyTheme(const std::shared_ptr& theme, if (properties & METADATA && elem->has("metadata")) setMetadataField(elem->get("metadata")); + if (properties & LETTER_CASE && elem->has("letterCase")) { + std::string letterCase {elem->get("letterCase")}; + if (letterCase == "uppercase") { + setUppercase(true); + } + else if (letterCase == "lowercase") { + setLowercase(true); + } + else if (letterCase == "capitalize") { + setCapitalize(true); + } + else if (letterCase != "none") { + LOG(LogWarning) + << "DateTimeComponent: Invalid theme configuration, property set to \"" + << letterCase << "\""; + } + } + + // Legacy themes only. if (properties & FORCE_UPPERCASE && elem->has("forceUppercase")) setUppercase(elem->get("forceUppercase")); diff --git a/es-core/src/components/TextComponent.cpp b/es-core/src/components/TextComponent.cpp index fe5afaef4..81603a8ec 100644 --- a/es-core/src/components/TextComponent.cpp +++ b/es-core/src/components/TextComponent.cpp @@ -21,7 +21,7 @@ TextComponent::TextComponent() , mRenderBackground {false} , mUppercase {false} , mLowercase {false} - , mCapitalized {false} + , mCapitalize {false} , mAutoCalcExtent {1, 1} , mHorizontalAlignment {ALIGN_LEFT} , mVerticalAlignment {ALIGN_CENTER} @@ -46,7 +46,7 @@ TextComponent::TextComponent(const std::string& text, , mRenderBackground {false} , mUppercase {false} , mLowercase {false} - , mCapitalized {false} + , mCapitalize {false} , mAutoCalcExtent {1, 1} , mHorizontalAlignment {align} , mVerticalAlignment {ALIGN_CENTER} @@ -126,7 +126,7 @@ void TextComponent::setUppercase(bool uppercase) mUppercase = uppercase; if (uppercase) { mLowercase = false; - mCapitalized = false; + mCapitalize = false; } onTextChanged(); } @@ -136,15 +136,15 @@ void TextComponent::setLowercase(bool lowercase) mLowercase = lowercase; if (lowercase) { mUppercase = false; - mCapitalized = false; + mCapitalize = false; } onTextChanged(); } -void TextComponent::setCapitalized(bool capitalized) +void TextComponent::setCapitalize(bool capitalize) { - mCapitalized = capitalized; - if (capitalized) { + mCapitalize = capitalize; + if (capitalize) { mUppercase = false; mLowercase = false; } @@ -230,7 +230,7 @@ void TextComponent::calculateExtent() mSize = mFont->sizeText(Utils::String::toUpper(mText), mLineSpacing); else if (mLowercase) mSize = mFont->sizeText(Utils::String::toLower(mText), mLineSpacing); - else if (mCapitalized) + else if (mCapitalize) mSize = mFont->sizeText(Utils::String::toCapitalized(mText), mLineSpacing); else mSize = mFont->sizeText(mText, mLineSpacing); // Original case. @@ -247,7 +247,7 @@ void TextComponent::calculateExtent() mFont->sizeWrappedText(Utils::String::toLower(mText), getSize().x, mLineSpacing) .y; } - else if (mCapitalized) { + else if (mCapitalize) { mSize.y = mFont ->sizeWrappedText(Utils::String::toCapitalized(mText), getSize().x, mLineSpacing) @@ -275,7 +275,7 @@ void TextComponent::onTextChanged() text = Utils::String::toUpper(mText); else if (mLowercase) text = Utils::String::toLower(mText); - else if (mCapitalized) + else if (mCapitalize) text = Utils::String::toCapitalized(mText); else text = mText; // Original case. @@ -397,6 +397,25 @@ void TextComponent::applyTheme(const std::shared_ptr& theme, if (properties & METADATA && elem->has("metadata")) setMetadataField(elem->get("metadata")); + if (properties & LETTER_CASE && elem->has("letterCase")) { + std::string letterCase {elem->get("letterCase")}; + if (letterCase == "uppercase") { + setUppercase(true); + } + else if (letterCase == "lowercase") { + setLowercase(true); + } + else if (letterCase == "capitalize") { + setCapitalize(true); + } + else if (letterCase != "none") { + LOG(LogWarning) + << "TextComponent: Invalid theme configuration, property set to \"" + << letterCase << "\""; + } + } + + // Legacy themes only. if (properties & FORCE_UPPERCASE && elem->has("forceUppercase")) setUppercase(elem->get("forceUppercase")); diff --git a/es-core/src/components/TextComponent.h b/es-core/src/components/TextComponent.h index a133765fe..bd6dc1b89 100644 --- a/es-core/src/components/TextComponent.h +++ b/es-core/src/components/TextComponent.h @@ -36,7 +36,7 @@ public: void setFont(const std::shared_ptr& font); void setUppercase(bool uppercase); void setLowercase(bool lowercase); - void setCapitalized(bool capitalize); + void setCapitalize(bool capitalize); void onSizeChanged() override; void setText(const std::string& text, bool update = true); void setHiddenText(const std::string& text) { mHiddenText = text; } @@ -93,7 +93,7 @@ private: bool mUppercase; bool mLowercase; - bool mCapitalized; + bool mCapitalize; glm::ivec2 mAutoCalcExtent; std::shared_ptr mTextCache; Alignment mHorizontalAlignment; diff --git a/es-core/src/components/TextListComponent.h b/es-core/src/components/TextListComponent.h index 1ac6bb6c3..0f5c66028 100644 --- a/es-core/src/components/TextListComponent.h +++ b/es-core/src/components/TextListComponent.h @@ -78,6 +78,38 @@ public: void setUppercase(bool uppercase) { mUppercase = uppercase; + + if (uppercase) { + mLowercase = false; + mCapitalize = false; + } + + for (auto it = mEntries.begin(); it != mEntries.end(); ++it) + it->data.textCache.reset(); + } + + void setLowercase(bool lowercase) + { + mLowercase = lowercase; + + if (lowercase) { + mUppercase = false; + mCapitalize = false; + } + + for (auto it = mEntries.begin(); it != mEntries.end(); ++it) + it->data.textCache.reset(); + } + + void setCapitalize(bool capitalize) + { + mCapitalize = capitalize; + + if (capitalize) { + mUppercase = false; + mLowercase = false; + } + for (auto it = mEntries.begin(); it != mEntries.end(); ++it) it->data.textCache.reset(); } @@ -115,6 +147,8 @@ private: std::shared_ptr mFont; bool mUppercase; + bool mLowercase; + bool mCapitalize; float mLineSpacing; float mSelectorHeight; float mSelectorOffsetY; @@ -140,6 +174,8 @@ template TextListComponent::TextListComponent() mFont = Font::get(FONT_SIZE_MEDIUM); mUppercase = false; + mLowercase = false; + mCapitalize = false; mLineSpacing = 1.5f; mSelectorHeight = mFont->getSize() * 1.5f; mSelectorOffsetY = 0; @@ -229,9 +265,20 @@ template void TextListComponent::render(const glm::mat4& parentT else color = mColors[entry.data.colorId]; - if (!entry.data.textCache) - entry.data.textCache = std::unique_ptr(font->buildTextCache( - mUppercase ? Utils::String::toUpper(entry.name) : entry.name, 0, 0, 0x000000FF)); + if (!entry.data.textCache) { + if (mUppercase) + entry.data.textCache = std::unique_ptr( + font->buildTextCache(Utils::String::toUpper(entry.name), 0, 0, 0x000000FF)); + else if (mLowercase) + entry.data.textCache = std::unique_ptr( + font->buildTextCache(Utils::String::toLower(entry.name), 0, 0, 0x000000FF)); + else if (mCapitalize) + entry.data.textCache = std::unique_ptr(font->buildTextCache( + Utils::String::toCapitalized(entry.name), 0, 0, 0x000000FF)); + else + entry.data.textCache = + std::unique_ptr(font->buildTextCache(entry.name, 0, 0, 0x000000FF)); + } // If a game is marked as hidden, lower the text opacity a lot. // If a game is marked to not be counted, lower the opacity a moderate amount. @@ -462,6 +509,25 @@ void TextListComponent::applyTheme(const std::shared_ptr& theme, } } + if (properties & LETTER_CASE && elem->has("letterCase")) { + std::string letterCase {elem->get("letterCase")}; + if (letterCase == "uppercase") { + setUppercase(true); + } + else if (letterCase == "lowercase") { + setLowercase(true); + } + else if (letterCase == "capitalize") { + setCapitalize(true); + } + else if (letterCase != "none") { + LOG(LogWarning) + << "TextListComponent: Invalid theme configuration, property set to \"" + << letterCase << "\""; + } + } + + // Legacy themes only. if (properties & FORCE_UPPERCASE && elem->has("forceUppercase")) setUppercase(elem->get("forceUppercase"));