From b034fe61fe410586a3dbf2de750ec9d6b11d3ed3 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sat, 4 Mar 2023 12:42:50 +0100 Subject: [PATCH] Fixed an issue where unfocusedItemSaturation couldn't be combined with imageSaturation for the carousel and grid elements. --- .../components/primary/CarouselComponent.h | 30 +++++++++++-------- .../src/components/primary/GridComponent.h | 21 +++++++++---- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/es-core/src/components/primary/CarouselComponent.h b/es-core/src/components/primary/CarouselComponent.h index e116c7d51..e14555e4b 100644 --- a/es-core/src/components/primary/CarouselComponent.h +++ b/es-core/src/components/primary/CarouselComponent.h @@ -187,6 +187,7 @@ private: float mReflectionsFalloff; float mUnfocusedItemOpacity; float mUnfocusedItemSaturation; + bool mHasUnfocusedItemSaturation; float mUnfocusedItemDimming; ImageFit mImagefit; unsigned int mCarouselColor; @@ -257,6 +258,7 @@ CarouselComponent::CarouselComponent() , mReflectionsFalloff {1.0f} , mUnfocusedItemOpacity {0.5f} , mUnfocusedItemSaturation {1.0f} + , mHasUnfocusedItemSaturation {false} , mUnfocusedItemDimming {1.0f} , mImagefit {ImageFit::CONTAIN} , mCarouselColor {0} @@ -991,15 +993,17 @@ template void CarouselComponent::render(const glm::mat4& parentT opacity = mUnfocusedItemOpacity + (maxDiff - (maxDiff * fabsf(distance))); } - if (distance == 0.0f || mUnfocusedItemSaturation == 1.0f) { - saturation = 1.0f; - } - else if (fabsf(distance) >= 1.0f) { - saturation = mUnfocusedItemSaturation; - } - else { - const float maxDiff {1.0f - mUnfocusedItemSaturation}; - saturation = mUnfocusedItemSaturation + (maxDiff - (maxDiff * fabsf(distance))); + if (mHasUnfocusedItemSaturation) { + if (distance == 0.0f) { + saturation = mImageSaturation; + } + else if (fabsf(distance) >= 1.0f) { + saturation = mUnfocusedItemSaturation; + } + else { + const float maxDiff {mImageSaturation - mUnfocusedItemSaturation}; + saturation = mUnfocusedItemSaturation + (maxDiff - (maxDiff * fabsf(distance))); + } } if (distance == 0.0f || mUnfocusedItemDimming == 1.0f) { @@ -1185,7 +1189,7 @@ template void CarouselComponent::render(const glm::mat4& parentT comp->setScale(renderItem.scale); comp->setOpacity(renderItem.opacity * metadataOpacity); - if (mUnfocusedItemSaturation != 1.0f) + if (mHasUnfocusedItemSaturation) comp->setSaturation(renderItem.saturation); if (mUnfocusedItemDimming != 1.0f) comp->setDimming(renderItem.dimming); @@ -1234,7 +1238,7 @@ template void CarouselComponent::render(const glm::mat4& parentT float falloff {glm::clamp(mReflectionsFalloff, 0.0f, 1.0f)}; falloff = mReflectionsOpacity * (1.0f - falloff); comp->setOpacity(comp->getOpacity() * mReflectionsOpacity); - if (mUnfocusedItemSaturation != 1.0f) + if (mHasUnfocusedItemSaturation) comp->setSaturation(renderItem.saturation); if (mUnfocusedItemDimming != 1.0f) comp->setDimming(renderItem.dimming); @@ -1704,9 +1708,11 @@ void CarouselComponent::applyTheme(const std::shared_ptr& theme, mUnfocusedItemOpacity = glm::clamp(elem->get("unfocusedItemOpacity"), 0.1f, 1.0f); - if (elem->has("unfocusedItemSaturation")) + if (elem->has("unfocusedItemSaturation")) { mUnfocusedItemSaturation = glm::clamp(elem->get("unfocusedItemSaturation"), 0.0f, 1.0f); + mHasUnfocusedItemSaturation = true; + } if (elem->has("unfocusedItemDimming")) mUnfocusedItemDimming = diff --git a/es-core/src/components/primary/GridComponent.h b/es-core/src/components/primary/GridComponent.h index 524685234..ae4de03a7 100644 --- a/es-core/src/components/primary/GridComponent.h +++ b/es-core/src/components/primary/GridComponent.h @@ -156,6 +156,7 @@ private: bool mInstantRowTransitions; float mUnfocusedItemOpacity; float mUnfocusedItemSaturation; + bool mHasUnfocusedItemSaturation; float mUnfocusedItemDimming; ImageFit mImagefit; float mImageRelativeScale; @@ -226,6 +227,7 @@ GridComponent::GridComponent() , mInstantRowTransitions {false} , mUnfocusedItemOpacity {1.0f} , mUnfocusedItemSaturation {1.0f} + , mHasUnfocusedItemSaturation {false} , mUnfocusedItemDimming {1.0f} , mImagefit {ImageFit::CONTAIN} , mImageRelativeScale {1.0f} @@ -745,7 +747,8 @@ template void GridComponent::render(const glm::mat4& parentTrans } opacity = mUnfocusedItemOpacity * metadataOpacity; - saturation = mUnfocusedItemSaturation; + if (mHasUnfocusedItemSaturation) + saturation = mUnfocusedItemSaturation; dimming = mUnfocusedItemDimming; if (*it == static_cast(mCursor)) { @@ -753,7 +756,9 @@ template void GridComponent::render(const glm::mat4& parentTrans scale = glm::mix(1.0f, mItemScale, mTransitionFactor); opacity = glm::mix(mUnfocusedItemOpacity * metadataOpacity, 1.0f * metadataOpacity, mTransitionFactor); - saturation = glm::mix(mUnfocusedItemSaturation, 1.0f, mTransitionFactor); + if (mHasUnfocusedItemSaturation) + saturation = + glm::mix(mUnfocusedItemSaturation, mImageSaturation, mTransitionFactor); dimming = glm::mix(mUnfocusedItemDimming, 1.0f, mTransitionFactor); } else if (*it == static_cast(mLastCursor)) { @@ -761,7 +766,9 @@ template void GridComponent::render(const glm::mat4& parentTrans scale = glm::mix(mItemScale, 1.0f, mTransitionFactor); opacity = glm::mix(1.0f * metadataOpacity, mUnfocusedItemOpacity * metadataOpacity, mTransitionFactor); - saturation = glm::mix(1.0f, mUnfocusedItemSaturation, mTransitionFactor); + if (mHasUnfocusedItemSaturation) + saturation = + glm::mix(mImageSaturation, mUnfocusedItemSaturation, mTransitionFactor); dimming = glm::mix(1.0f, mUnfocusedItemDimming, mTransitionFactor); } @@ -772,7 +779,7 @@ template void GridComponent::render(const glm::mat4& parentTrans mBackgroundImage->setPosition(mEntries.at(*it).data.item->getPosition()); mBackgroundImage->setScale(scale); mBackgroundImage->setOpacity(opacity); - if (mUnfocusedItemSaturation != 1.0f) + if (mHasUnfocusedItemSaturation) mBackgroundImage->setSaturation(saturation); if (mUnfocusedItemDimming != 1.0f) mBackgroundImage->setDimming(dimming); @@ -806,7 +813,7 @@ template void GridComponent::render(const glm::mat4& parentTrans mEntries.at(*it).data.item->setScale(scale); mEntries.at(*it).data.item->setOpacity(opacity); - if (mUnfocusedItemSaturation != 1.0f) + if (mHasUnfocusedItemSaturation) mEntries.at(*it).data.item->setSaturation(saturation); if (mUnfocusedItemDimming != 1.0f) mEntries.at(*it).data.item->setDimming(dimming); @@ -1217,9 +1224,11 @@ void GridComponent::applyTheme(const std::shared_ptr& theme, if (elem->has("unfocusedItemOpacity")) mUnfocusedItemOpacity = glm::clamp(elem->get("unfocusedItemOpacity"), 0.1f, 1.0f); - if (elem->has("unfocusedItemSaturation")) + if (elem->has("unfocusedItemSaturation")) { mUnfocusedItemSaturation = glm::clamp(elem->get("unfocusedItemSaturation"), 0.0f, 1.0f); + mHasUnfocusedItemSaturation = true; + } if (elem->has("unfocusedItemDimming")) mUnfocusedItemDimming = glm::clamp(elem->get("unfocusedItemDimming"), 0.0f, 1.0f);