From 0c6c5ab986695e7474713fe96bf93bdbc0315574 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Fri, 3 Mar 2023 22:41:53 +0100 Subject: [PATCH] Added carousel theme support for setting the saturation and dimming for unfocused items. --- es-core/src/ThemeData.cpp | 2 + .../components/primary/CarouselComponent.h | 50 ++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 27c57e4a3..ce0699d4e 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -170,6 +170,8 @@ std::map> {"reflectionsOpacity", FLOAT}, {"reflectionsFalloff", FLOAT}, {"unfocusedItemOpacity", FLOAT}, + {"unfocusedItemSaturation", FLOAT}, + {"unfocusedItemDimming", FLOAT}, {"fastScrolling", BOOLEAN}, {"defaultLogo", PATH}, // For backward compatibility with legacy themes. {"logoSize", NORMALIZED_PAIR}, // For backward compatibility with legacy themes. diff --git a/es-core/src/components/primary/CarouselComponent.h b/es-core/src/components/primary/CarouselComponent.h index caac2ac57..e116c7d51 100644 --- a/es-core/src/components/primary/CarouselComponent.h +++ b/es-core/src/components/primary/CarouselComponent.h @@ -186,6 +186,8 @@ private: float mReflectionsOpacity; float mReflectionsFalloff; float mUnfocusedItemOpacity; + float mUnfocusedItemSaturation; + float mUnfocusedItemDimming; ImageFit mImagefit; unsigned int mCarouselColor; unsigned int mCarouselColorEnd; @@ -254,6 +256,8 @@ CarouselComponent::CarouselComponent() , mReflectionsOpacity {0.5f} , mReflectionsFalloff {1.0f} , mUnfocusedItemOpacity {0.5f} + , mUnfocusedItemSaturation {1.0f} + , mUnfocusedItemDimming {1.0f} , mImagefit {ImageFit::CONTAIN} , mCarouselColor {0} , mCarouselColorEnd {0} @@ -906,6 +910,8 @@ template void CarouselComponent::render(const glm::mat4& parentT float distance; float scale; float opacity; + float saturation; + float dimming; glm::mat4 trans; }; @@ -971,6 +977,8 @@ template void CarouselComponent::render(const glm::mat4& parentT itemTrans = glm::rotate(itemTrans, glm::radians(-90.0f), glm::vec3 {0.0f, 0.0f, 1.0f}); float opacity {0.0f}; + float saturation {0.0f}; + float dimming {0.0f}; if (distance == 0.0f || mUnfocusedItemOpacity == 1.0f) { opacity = 1.0f; @@ -979,15 +987,39 @@ template void CarouselComponent::render(const glm::mat4& parentT opacity = mUnfocusedItemOpacity; } else { - float maxDiff {1.0f - mUnfocusedItemOpacity}; + const float maxDiff {1.0f - mUnfocusedItemOpacity}; 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 (distance == 0.0f || mUnfocusedItemDimming == 1.0f) { + dimming = 1.0f; + } + else if (fabsf(distance) >= 1.0f) { + dimming = mUnfocusedItemDimming; + } + else { + const float maxDiff {1.0f - mUnfocusedItemDimming}; + dimming = mUnfocusedItemDimming + (maxDiff - (maxDiff * fabsf(distance))); + } + renderStruct renderItem; renderItem.index = index; renderItem.distance = distance; renderItem.scale = scale; renderItem.opacity = opacity; + renderItem.saturation = saturation; + renderItem.dimming = dimming; renderItem.trans = itemTrans; renderItems.emplace_back(renderItem); @@ -1153,6 +1185,10 @@ template void CarouselComponent::render(const glm::mat4& parentT comp->setScale(renderItem.scale); comp->setOpacity(renderItem.opacity * metadataOpacity); + if (mUnfocusedItemSaturation != 1.0f) + comp->setSaturation(renderItem.saturation); + if (mUnfocusedItemDimming != 1.0f) + comp->setDimming(renderItem.dimming); if (renderItem.index == mCursor && std::abs(renderItem.distance) < 1.0f && (mHasImageSelectedColor || mHasTextSelectedColor)) { if (mHasTextSelectedColor && mEntries.at(renderItem.index).data.imagePath == "" && @@ -1198,6 +1234,10 @@ 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) + comp->setSaturation(renderItem.saturation); + if (mUnfocusedItemDimming != 1.0f) + comp->setDimming(renderItem.dimming); if (mReflectionsFalloff > 0.0f) comp->setReflectionsFalloff(comp->getSize().y / mReflectionsFalloff); comp->setFlipY(true); @@ -1664,6 +1704,14 @@ void CarouselComponent::applyTheme(const std::shared_ptr& theme, mUnfocusedItemOpacity = glm::clamp(elem->get("unfocusedItemOpacity"), 0.1f, 1.0f); + if (elem->has("unfocusedItemSaturation")) + mUnfocusedItemSaturation = + glm::clamp(elem->get("unfocusedItemSaturation"), 0.0f, 1.0f); + + if (elem->has("unfocusedItemDimming")) + mUnfocusedItemDimming = + glm::clamp(elem->get("unfocusedItemDimming"), 0.0f, 1.0f); + if (elem->has("fastScrolling") && elem->get("fastScrolling")) List::mTierList = IList::LIST_SCROLL_STYLE_MEDIUM; }