Added support for two new 'scrollFadeIn' and 'defaultImage' properties.

Also fixed some issues with theming ScrollableContainer.
This commit is contained in:
Leon Styhre 2022-01-30 19:30:38 +01:00
parent 6676e9c353
commit 3bf46c3fb0
6 changed files with 51 additions and 16 deletions

View file

@ -129,25 +129,22 @@ void GamelistView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
}
else if (element.second.type == "text") {
if (element.second.has("container") && element.second.get<bool>("container")) {
mContainerTextComponents.push_back(std::make_unique<TextComponent>());
mContainerTextComponents.back()->setDefaultZIndex(40.0f);
mContainerComponents.push_back(std::make_unique<ScrollableContainer>());
mContainerComponents.back()->setAutoScroll(true);
mContainerComponents.back()->setDefaultZIndex(40.0f);
addChild(mContainerComponents.back().get());
mContainerTextComponents.push_back(std::make_unique<TextComponent>());
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<TextComponent>());
@ -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<unsigned char>(
glm::mix(static_cast<float>(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<unsigned char>(
glm::mix(static_cast<float>(FADE_IN_START_OPACITY), 1.0f, t) * 255));

View file

@ -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}

View file

@ -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;

View file

@ -85,6 +85,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"color", COLOR},
{"colorEnd", COLOR},
{"gradientType", STRING},
{"scrollFadeIn", BOOLEAN},
{"visible", BOOLEAN},
{"zIndex", FLOAT}}},
{"video",
@ -96,8 +97,10 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"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.

View file

@ -516,6 +516,9 @@ void ImageComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
setColorGradientHorizontal(
!(elem->get<std::string>("gradientType").compare("horizontal")));
}
if (elem->has("scrollFadeIn") && elem->get<bool>("scrollFadeIn"))
mComponentThemeFlags |= ComponentThemeFlags::SCROLL_FADE_IN;
}
std::vector<HelpPrompt> ImageComponent::getHelpPrompts()

View file

@ -244,6 +244,11 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (elem->has("default"))
mConfig.defaultVideoPath = elem->get<std::string>("default");
if (elem->has("defaultImage")) {
mStaticImage.setDefaultImage(elem->get<std::string>("defaultImage"));
mStaticImage.setImage(mStaticImagePath);
}
if (elem->has("path"))
mConfig.staticVideoPath = elem->get<std::string>("path");
@ -262,6 +267,9 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (properties & METADATA && elem->has("imageMetadata"))
setMetadataField(elem->get<std::string>("imageMetadata"));
if (elem->has("scrollFadeIn") && elem->get<bool>("scrollFadeIn"))
mComponentThemeFlags |= ComponentThemeFlags::SCROLL_FADE_IN;
}
std::vector<HelpPrompt> VideoComponent::getHelpPrompts()