From a8d1c4a2e122a68783c9f74c99a77398aeb8d6bd Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Tue, 25 Oct 2022 20:33:12 +0200 Subject: [PATCH] Fixed an issue in CarouselComponent where setting itemScale to less than 1.0 did not work as expected. Also fixed a problem where carousel text entries did not get multiplied by itemScale. --- .../components/primary/CarouselComponent.h | 32 +++++++++++++------ es-core/src/resources/Font.cpp | 11 ++++--- es-core/src/resources/Font.h | 3 +- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/es-core/src/components/primary/CarouselComponent.h b/es-core/src/components/primary/CarouselComponent.h index 6f3351918..e8cc42093 100644 --- a/es-core/src/components/primary/CarouselComponent.h +++ b/es-core/src/components/primary/CarouselComponent.h @@ -227,7 +227,7 @@ void CarouselComponent::addEntry(Entry& entry, const std::shared_ptr(false, dynamic); item->setLinearInterpolation(mLinearInterpolation); item->setMipmapping(true); - item->setMaxSize(glm::round(mItemSize * mItemScale)); + item->setMaxSize(glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f))); item->applyTheme(theme, "system", "image_logo", ThemeFlags::PATH | ThemeFlags::COLOR); item->setRotateByTargetSize(true); @@ -241,7 +241,7 @@ void CarouselComponent::addEntry(Entry& entry, const std::shared_ptr(false, dynamic); item->setLinearInterpolation(mLinearInterpolation); item->setMipmapping(true); - item->setMaxSize(glm::round(mItemSize * mItemScale)); + item->setMaxSize(glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f))); item->setImage(entry.data.itemPath); item->applyTheme(theme, "system", "", ThemeFlags::ALL); item->setRotateByTargetSize(true); @@ -252,7 +252,8 @@ void CarouselComponent::addEntry(Entry& entry, const std::shared_ptr(false, dynamic); defaultItem->setLinearInterpolation(mLinearInterpolation); defaultItem->setMipmapping(true); - defaultItem->setMaxSize(glm::round(mItemSize * mItemScale)); + defaultItem->setMaxSize( + glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f))); defaultItem->setImage(entry.data.defaultItemPath); defaultItem->applyTheme(theme, "system", "", ThemeFlags::ALL); defaultItem->setRotateByTargetSize(true); @@ -276,7 +277,8 @@ void CarouselComponent::addEntry(Entry& entry, const std::shared_ptr( nameEntry, mFont, 0x000000FF, mItemHorizontalAlignment, mItemVerticalAlignment, - glm::vec3 {0.0f, 0.0f, 0.0f}, glm::round(mItemSize * mItemScale), 0x00000000); + glm::vec3 {0.0f, 0.0f, 0.0f}, + glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f)), 0x00000000); if (legacyMode) { text->applyTheme(theme, "system", "text_logoText", ThemeFlags::FONT_PATH | ThemeFlags::FONT_SIZE | ThemeFlags::COLOR | @@ -324,7 +326,7 @@ void CarouselComponent::updateEntry(Entry& entry, const std::shared_ptr(false, true); item->setLinearInterpolation(mLinearInterpolation); item->setMipmapping(true); - item->setMaxSize(glm::round(mItemSize * mItemScale)); + item->setMaxSize(glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f))); item->setImage(entry.data.itemPath); item->applyTheme(theme, "system", "", ThemeFlags::ALL); item->setRotateByTargetSize(true); @@ -769,9 +771,17 @@ template void CarouselComponent::render(const glm::mat4& parentT if (singleEntry) distance = 0.0f; - float scale {1.0f + ((mItemScale - 1.0f) * (1.0f - fabsf(distance)))}; - scale = std::min(mItemScale, std::max(1.0f, scale)); - scale /= mItemScale; + float scale {0.0f}; + + if (mItemScale >= 1.0f) { + scale = 1.0f + ((mItemScale - 1.0f) * (1.0f - fabsf(distance))); + scale = std::min(mItemScale, std::max(1.0f, scale)); + scale /= mItemScale; + } + else { + scale = 1.0f + ((1.0f - mItemScale) * (fabsf(distance) - 1.0f)); + scale = std::max(mItemScale, std::min(1.0f, scale)); + } glm::mat4 itemTrans {carouselTrans}; if (singleEntry) @@ -1012,7 +1022,7 @@ void CarouselComponent::applyTheme(const std::shared_ptr& theme, } if (elem->has("itemScale")) - mItemScale = glm::clamp(elem->get("itemScale"), 0.5f, 3.0f); + mItemScale = glm::clamp(elem->get("itemScale"), 0.2f, 3.0f); if (elem->has("itemTransitions")) { const std::string itemTransitions {elem->get("itemTransitions")}; @@ -1206,7 +1216,9 @@ void CarouselComponent::applyTheme(const std::shared_ptr& theme, } } - mFont = Font::getFromTheme(elem, properties, mFont, 0.0f, mLegacyMode); + // For non-legacy themes, scale the font size with the itemScale property value. + mFont = Font::getFromTheme(elem, properties, mFont, 0.0f, mLegacyMode, + (mLegacyMode ? 1.0f : (mItemScale >= 1.0f ? mItemScale : 1.0f))); if (elem->has("textColor")) mTextColor = elem->get("textColor"); diff --git a/es-core/src/resources/Font.cpp b/es-core/src/resources/Font.cpp index c6bf3ed02..6a3924989 100644 --- a/es-core/src/resources/Font.cpp +++ b/es-core/src/resources/Font.cpp @@ -422,7 +422,8 @@ std::shared_ptr Font::getFromTheme(const ThemeData::ThemeElement* elem, unsigned int properties, const std::shared_ptr& orig, const float maxHeight, - const bool legacyTheme) + const bool legacyTheme, + const float sizeMultiplier) { mLegacyTheme = legacyTheme; @@ -438,6 +439,8 @@ std::shared_ptr Font::getFromTheme(const ThemeData::ThemeElement* elem, if (properties & FONT_SIZE && elem->has("fontSize")) { size = glm::clamp(screenHeight * elem->get("fontSize"), screenHeight * 0.001f, screenHeight * 1.5f); + // This is used by the carousel where the itemScale property also scales the font size. + size *= sizeMultiplier; } if (maxHeight != 0.0f && size > maxHeight) @@ -741,10 +744,8 @@ Font::Glyph* Font::getGlyph(const unsigned int id) } // Use the letter 'S' as a size reference. - if (mLetterHeight == 0 && id == 'S') { - const float ratio {static_cast(glyphSize.y) / std::round(mFontSize)}; - mLetterHeight = mFontSize * ratio; - } + if (mLetterHeight == 0 && id == 'S') + mLetterHeight = static_cast(glyphSize.y); // Create glyph. Glyph& glyph {mGlyphMap[id]}; diff --git a/es-core/src/resources/Font.h b/es-core/src/resources/Font.h index b3fc40cde..7ba8b93d5 100644 --- a/es-core/src/resources/Font.h +++ b/es-core/src/resources/Font.h @@ -94,7 +94,8 @@ public: unsigned int properties, const std::shared_ptr& orig, const float maxHeight = 0.0f, - const bool legacyTheme = false); + const bool legacyTheme = false, + const float sizeMultiplier = 1.0f); // Returns an approximation of VRAM used by this font's texture (in bytes). size_t getMemUsage() const;