From e6ae806c312e0f2f1efc68479a61186ef6c25d74 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 17 Aug 2022 00:26:47 +0200 Subject: [PATCH] Added an itemInterpolation theme property to control the interpolation method for carousel items. --- es-core/src/ThemeData.cpp | 1 + .../components/primary/CarouselComponent.h | 35 ++++++++++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 6976c379f..dabc606fe 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -257,6 +257,7 @@ std::map> {"itemType", STRING}, {"defaultItem", PATH}, {"itemSize", NORMALIZED_PAIR}, + {"itemInterpolation", STRING}, {"itemScale", FLOAT}, {"itemRotation", FLOAT}, {"itemRotationOrigin", NORMALIZED_PAIR}, diff --git a/es-core/src/components/primary/CarouselComponent.h b/es-core/src/components/primary/CarouselComponent.h index 76b80b094..7bc8217d7 100644 --- a/es-core/src/components/primary/CarouselComponent.h +++ b/es-core/src/components/primary/CarouselComponent.h @@ -129,6 +129,7 @@ private: float mUnfocusedItemOpacity; float mMaxItemCount; glm::vec2 mItemSize; + bool mLinearInterpolation; float mItemScale; float mItemRotation; glm::vec2 mItemRotationOrigin; @@ -165,6 +166,7 @@ CarouselComponent::CarouselComponent() , mUnfocusedItemOpacity {0.5f} , mMaxItemCount {3.0f} , mItemSize {Renderer::getScreenWidth() * 0.25f, Renderer::getScreenHeight() * 0.155f} + , mLinearInterpolation {false} , mItemScale {1.2f} , mItemRotation {7.5f} , mItemRotationOrigin {-3.0f, 0.5f} @@ -201,7 +203,7 @@ void CarouselComponent::addEntry(Entry& entry, const std::shared_ptr(false, dynamic); - item->setLinearInterpolation(true); + item->setLinearInterpolation(mLinearInterpolation); item->setMaxSize(mItemSize * mItemScale); item->applyTheme(theme, "system", "image_logo", ThemeFlags::PATH | ThemeFlags::COLOR); @@ -214,7 +216,7 @@ void CarouselComponent::addEntry(Entry& entry, const std::shared_ptr(false, dynamic); - item->setLinearInterpolation(true); + item->setLinearInterpolation(mLinearInterpolation); item->setImage(entry.data.itemPath); item->setMaxSize(mItemSize * mItemScale); item->applyTheme(theme, "system", "", ThemeFlags::ALL); @@ -224,7 +226,7 @@ void CarouselComponent::addEntry(Entry& entry, const std::shared_ptr(false, dynamic); - defaultItem->setLinearInterpolation(true); + defaultItem->setLinearInterpolation(mLinearInterpolation); defaultItem->setImage(entry.data.defaultItemPath); defaultItem->setMaxSize(mItemSize * mItemScale); defaultItem->applyTheme(theme, "system", "", ThemeFlags::ALL); @@ -285,7 +287,7 @@ void CarouselComponent::updateEntry(Entry& entry, const std::shared_ptr(false, true); - item->setLinearInterpolation(true); + item->setLinearInterpolation(mLinearInterpolation); item->setImage(entry.data.itemPath); item->setMaxSize(mItemSize * mItemScale); item->applyTheme(theme, "system", "", ThemeFlags::ALL); @@ -782,8 +784,27 @@ void CarouselComponent::applyTheme(const std::shared_ptr& theme, } if (!mLegacyMode) { + mLinearInterpolation = true; + if (elem->has("itemScale")) mItemScale = glm::clamp(elem->get("itemScale"), 0.5f, 3.0f); + + if (elem->has("itemInterpolation")) { + const std::string itemInterpolation {elem->get("itemInterpolation")}; + if (itemInterpolation == "linear") { + mLinearInterpolation = true; + } + else if (itemInterpolation == "nearest") { + mLinearInterpolation = false; + } + else { + mLinearInterpolation = true; + LOG(LogWarning) << "CarouselComponent: Invalid theme configuration, property " + " defined as \"" + << itemInterpolation << "\""; + } + } + if (elem->has("itemSize")) { // Keep size within a 0.05 and 1.0 multiple of the screen size. glm::vec2 itemSize {elem->get("itemSize")}; @@ -916,11 +937,7 @@ void CarouselComponent::applyTheme(const std::shared_ptr& theme, if (elem->has("maxLogoCount")) { // For legacy themes we allow a maxLogoCount (maxItemCount) of 0. - if (theme->isLegacyTheme()) - mMaxItemCount = - std::ceil(glm::clamp(elem->get("maxLogoCount"), 0.0f, 30.0f)); - else - mMaxItemCount = glm::clamp(elem->get("maxLogoCount"), 0.5f, 30.0f); + mMaxItemCount = std::ceil(glm::clamp(elem->get("maxLogoCount"), 0.0f, 30.0f)); } if (elem->has("logoRotation"))