From 3bf46c3fb0365acd14e62c21bc2d089e3b7f0843 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 30 Jan 2022 19:30:38 +0100 Subject: [PATCH] Added support for two new 'scrollFadeIn' and 'defaultImage' properties. Also fixed some issues with theming ScrollableContainer. --- es-app/src/views/GamelistView.cpp | 21 +++++++--------- es-core/src/GuiComponent.cpp | 2 +- es-core/src/GuiComponent.h | 30 ++++++++++++++++++++--- es-core/src/ThemeData.cpp | 3 +++ es-core/src/components/ImageComponent.cpp | 3 +++ es-core/src/components/VideoComponent.cpp | 8 ++++++ 6 files changed, 51 insertions(+), 16 deletions(-) diff --git a/es-app/src/views/GamelistView.cpp b/es-app/src/views/GamelistView.cpp index 6e7cabaac..453c086f7 100644 --- a/es-app/src/views/GamelistView.cpp +++ b/es-app/src/views/GamelistView.cpp @@ -129,25 +129,22 @@ void GamelistView::onThemeChanged(const std::shared_ptr& theme) } else if (element.second.type == "text") { if (element.second.has("container") && element.second.get("container")) { - mContainerTextComponents.push_back(std::make_unique()); - mContainerTextComponents.back()->setDefaultZIndex(40.0f); mContainerComponents.push_back(std::make_unique()); mContainerComponents.back()->setAutoScroll(true); + mContainerComponents.back()->setDefaultZIndex(40.0f); + addChild(mContainerComponents.back().get()); + mContainerTextComponents.push_back(std::make_unique()); + mContainerTextComponents.back()->setDefaultZIndex(40.0f); mContainerComponents.back()->addChild(mContainerTextComponents.back().get()); mContainerComponents.back()->applyTheme(theme, "gamelist", element.first, POSITION | ThemeFlags::SIZE | Z_INDEX | VISIBLE); - mContainerTextComponents.back()->applyTheme(theme, "gamelist", element.first, - ALL ^ POSITION ^ Z_INDEX ^ - ThemeFlags::SIZE ^ VISIBLE); mContainerTextComponents.back()->setSize( mContainerComponents.back()->getSize().x, 0.0f); - mContainerComponents.back()->setDefaultZIndex( - mContainerTextComponents.back()->getDefaultZIndex()); - mContainerComponents.back()->setZIndex( - mContainerTextComponents.back()->getZIndex()); + mContainerTextComponents.back()->applyTheme( + theme, "gamelist", element.first, + (ALL ^ POSITION ^ Z_INDEX ^ ThemeFlags::SIZE ^ VISIBLE ^ ROTATION) | COLOR); mContainerComponents.back()->setScrollHide(true); - addChild(mContainerComponents.back().get()); } else { mTextComponents.push_back(std::make_unique()); @@ -551,7 +548,7 @@ void GamelistView::updateInfoPanel() // Fade in the game image. for (auto& image : mImageComponents) { - if (image->getMetadataField() == "md_image") { + if (image->getScrollFadeIn()) { auto func = [&image](float t) { image->setOpacity(static_cast( glm::mix(static_cast(FADE_IN_START_OPACITY), 1.0f, t) * 255)); @@ -562,7 +559,7 @@ void GamelistView::updateInfoPanel() // Fade in the static image. for (auto& video : mVideoComponents) { - if (video->getMetadataField() == "md_video") { + if (video->getScrollFadeIn()) { auto func = [&video](float t) { video->setOpacity(static_cast( glm::mix(static_cast(FADE_IN_START_OPACITY), 1.0f, t) * 255)); diff --git a/es-core/src/GuiComponent.cpp b/es-core/src/GuiComponent.cpp index d6f0fd91b..7bee95f34 100644 --- a/es-core/src/GuiComponent.cpp +++ b/es-core/src/GuiComponent.cpp @@ -26,6 +26,7 @@ GuiComponent::GuiComponent() , mColorShiftEnd {0} , mColorOriginalValue {0} , mColorChangedValue {0} + , mComponentThemeFlags {0} , mPosition {0.0f, 0.0f, 0.0f} , mOrigin {0.0f, 0.0f} , mRotationOrigin {0.5f, 0.5f} @@ -34,7 +35,6 @@ GuiComponent::GuiComponent() , mScale {1.0f} , mDefaultZIndex {0.0f} , mZIndex {0.0f} - , mScrollHide {false} , mIsProcessing {false} , mVisible {true} , mEnabled {true} diff --git a/es-core/src/GuiComponent.h b/es-core/src/GuiComponent.h index 7aa9cc844..39130ee80 100644 --- a/es-core/src/GuiComponent.h +++ b/es-core/src/GuiComponent.h @@ -112,8 +112,32 @@ public: const bool isVisible() const { return mVisible; } void setVisible(bool visible) { mVisible = visible; } - const bool getScrollHide() { return mScrollHide; } - void setScrollHide(bool state) { mScrollHide = state; } + // clang-format off + enum ComponentThemeFlags : unsigned int { + SCROLL_HIDE = 0x00000001, + SCROLL_FADE_IN = 0x00000002 + }; + // clang-format on + + const bool getScrollHide() { return mComponentThemeFlags & ComponentThemeFlags::SCROLL_HIDE; } + void setScrollHide(bool state) + { + if (state) + mComponentThemeFlags |= ComponentThemeFlags::SCROLL_HIDE; + else + mComponentThemeFlags ^= ComponentThemeFlags::SCROLL_HIDE; + } + const bool getScrollFadeIn() + { + return mComponentThemeFlags & ComponentThemeFlags::SCROLL_FADE_IN; + } + void setScrollFadeIn(bool state) + { + if (state) + mComponentThemeFlags |= ComponentThemeFlags::SCROLL_FADE_IN; + else + mComponentThemeFlags ^= ComponentThemeFlags::SCROLL_FADE_IN; + } // Returns the center point of the image (takes origin into account). const glm::vec2 getCenter() const; @@ -265,6 +289,7 @@ protected: unsigned int mColorShiftEnd; unsigned int mColorOriginalValue; unsigned int mColorChangedValue; + unsigned int mComponentThemeFlags; glm::vec3 mPosition; glm::vec2 mOrigin; @@ -276,7 +301,6 @@ protected: float mDefaultZIndex; float mZIndex; - bool mScrollHide; bool mIsProcessing; bool mVisible; bool mEnabled; diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index df7d999ba..65e29ecdc 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -85,6 +85,7 @@ std::map> {"color", COLOR}, {"colorEnd", COLOR}, {"gradientType", STRING}, + {"scrollFadeIn", BOOLEAN}, {"visible", BOOLEAN}, {"zIndex", FLOAT}}}, {"video", @@ -96,8 +97,10 @@ std::map> {"rotationOrigin", NORMALIZED_PAIR}, {"path", PATH}, {"default", PATH}, + {"defaultImage", PATH}, {"imageMetadata", STRING}, {"delay", FLOAT}, + {"scrollFadeIn", BOOLEAN}, {"visible", BOOLEAN}, {"zIndex", FLOAT}, {"showSnapshotNoVideo", BOOLEAN}, // For backward compatibility with legacy themes. diff --git a/es-core/src/components/ImageComponent.cpp b/es-core/src/components/ImageComponent.cpp index e86a983cc..f4b02d320 100644 --- a/es-core/src/components/ImageComponent.cpp +++ b/es-core/src/components/ImageComponent.cpp @@ -516,6 +516,9 @@ void ImageComponent::applyTheme(const std::shared_ptr& theme, setColorGradientHorizontal( !(elem->get("gradientType").compare("horizontal"))); } + + if (elem->has("scrollFadeIn") && elem->get("scrollFadeIn")) + mComponentThemeFlags |= ComponentThemeFlags::SCROLL_FADE_IN; } std::vector ImageComponent::getHelpPrompts() diff --git a/es-core/src/components/VideoComponent.cpp b/es-core/src/components/VideoComponent.cpp index ad6043441..96fa2c761 100644 --- a/es-core/src/components/VideoComponent.cpp +++ b/es-core/src/components/VideoComponent.cpp @@ -244,6 +244,11 @@ void VideoComponent::applyTheme(const std::shared_ptr& theme, if (elem->has("default")) mConfig.defaultVideoPath = elem->get("default"); + if (elem->has("defaultImage")) { + mStaticImage.setDefaultImage(elem->get("defaultImage")); + mStaticImage.setImage(mStaticImagePath); + } + if (elem->has("path")) mConfig.staticVideoPath = elem->get("path"); @@ -262,6 +267,9 @@ void VideoComponent::applyTheme(const std::shared_ptr& theme, if (properties & METADATA && elem->has("imageMetadata")) setMetadataField(elem->get("imageMetadata")); + + if (elem->has("scrollFadeIn") && elem->get("scrollFadeIn")) + mComponentThemeFlags |= ComponentThemeFlags::SCROLL_FADE_IN; } std::vector VideoComponent::getHelpPrompts()