mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-26 08:05:38 +00:00
Added support for setting component opacity from the theme configuration.
This commit is contained in:
parent
c24cf1e57a
commit
f585f87497
|
@ -31,6 +31,7 @@ GuiComponent::GuiComponent()
|
||||||
, mRotationOrigin {0.5f, 0.5f}
|
, mRotationOrigin {0.5f, 0.5f}
|
||||||
, mSize {0.0f, 0.0f}
|
, mSize {0.0f, 0.0f}
|
||||||
, mOpacity {1.0f}
|
, mOpacity {1.0f}
|
||||||
|
, mThemeOpacity {1.0f}
|
||||||
, mRotation {0.0f}
|
, mRotation {0.0f}
|
||||||
, mScale {1.0f}
|
, mScale {1.0f}
|
||||||
, mDefaultZIndex {0.0f}
|
, mDefaultZIndex {0.0f}
|
||||||
|
@ -356,10 +357,11 @@ void GuiComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
|
||||||
else
|
else
|
||||||
setZIndex(getDefaultZIndex());
|
setZIndex(getDefaultZIndex());
|
||||||
|
|
||||||
if (properties & ThemeFlags::VISIBLE && elem->has("visible"))
|
if (properties & ThemeFlags::OPACITY && elem->has("opacity"))
|
||||||
setVisible(elem->get<bool>("visible"));
|
mThemeOpacity = glm::clamp(elem->get<float>("opacity"), 0.0f, 1.0f);
|
||||||
else
|
|
||||||
setVisible(true);
|
if (properties & ThemeFlags::VISIBLE && elem->has("visible") && !elem->get<bool>("visible"))
|
||||||
|
mThemeOpacity = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiComponent::updateHelpPrompts()
|
void GuiComponent::updateHelpPrompts()
|
||||||
|
|
|
@ -191,7 +191,7 @@ public:
|
||||||
|
|
||||||
virtual bool isListScrolling() { return false; }
|
virtual bool isListScrolling() { return false; }
|
||||||
virtual void stopListScrolling() {}
|
virtual void stopListScrolling() {}
|
||||||
virtual float getOpacity() const { return mOpacity; }
|
virtual const float getOpacity() const { return mOpacity; }
|
||||||
virtual void setOpacity(float opacity);
|
virtual void setOpacity(float opacity);
|
||||||
virtual unsigned int getColor() const { return mColor; }
|
virtual unsigned int getColor() const { return mColor; }
|
||||||
virtual unsigned int getColorShift() const { return mColorShift; }
|
virtual unsigned int getColorShift() const { return mColorShift; }
|
||||||
|
@ -291,6 +291,7 @@ protected:
|
||||||
glm::vec2 mSize;
|
glm::vec2 mSize;
|
||||||
|
|
||||||
float mOpacity;
|
float mOpacity;
|
||||||
|
float mThemeOpacity;
|
||||||
float mRotation;
|
float mRotation;
|
||||||
float mScale;
|
float mScale;
|
||||||
float mDefaultZIndex;
|
float mDefaultZIndex;
|
||||||
|
|
|
@ -94,6 +94,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
|
||||||
{"colorEnd", COLOR},
|
{"colorEnd", COLOR},
|
||||||
{"gradientType", STRING},
|
{"gradientType", STRING},
|
||||||
{"scrollFadeIn", BOOLEAN},
|
{"scrollFadeIn", BOOLEAN},
|
||||||
|
{"opacity", FLOAT},
|
||||||
{"visible", BOOLEAN},
|
{"visible", BOOLEAN},
|
||||||
{"zIndex", FLOAT}}},
|
{"zIndex", FLOAT}}},
|
||||||
{"video",
|
{"video",
|
||||||
|
@ -107,8 +108,11 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
|
||||||
{"default", PATH},
|
{"default", PATH},
|
||||||
{"defaultImage", PATH},
|
{"defaultImage", PATH},
|
||||||
{"imageMetadata", STRING},
|
{"imageMetadata", STRING},
|
||||||
|
{"pillarboxes", BOOLEAN},
|
||||||
|
{"scanlines", BOOLEAN},
|
||||||
{"delay", FLOAT},
|
{"delay", FLOAT},
|
||||||
{"scrollFadeIn", BOOLEAN},
|
{"scrollFadeIn", BOOLEAN},
|
||||||
|
{"opacity", FLOAT},
|
||||||
{"visible", BOOLEAN},
|
{"visible", BOOLEAN},
|
||||||
{"zIndex", FLOAT},
|
{"zIndex", FLOAT},
|
||||||
{"showSnapshotNoVideo", BOOLEAN}, // For backward compatibility with legacy themes.
|
{"showSnapshotNoVideo", BOOLEAN}, // For backward compatibility with legacy themes.
|
||||||
|
@ -123,6 +127,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
|
||||||
{"speed", FLOAT},
|
{"speed", FLOAT},
|
||||||
{"direction", STRING},
|
{"direction", STRING},
|
||||||
{"keepAspectRatio", BOOLEAN},
|
{"keepAspectRatio", BOOLEAN},
|
||||||
|
{"opacity", FLOAT},
|
||||||
{"visible", BOOLEAN},
|
{"visible", BOOLEAN},
|
||||||
{"zIndex", FLOAT}}},
|
{"zIndex", FLOAT}}},
|
||||||
{"badges",
|
{"badges",
|
||||||
|
@ -142,6 +147,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
|
||||||
{"controllerSize", FLOAT},
|
{"controllerSize", FLOAT},
|
||||||
{"customBadgeIcon", PATH},
|
{"customBadgeIcon", PATH},
|
||||||
{"customControllerIcon", PATH},
|
{"customControllerIcon", PATH},
|
||||||
|
{"opacity", FLOAT},
|
||||||
{"visible", BOOLEAN},
|
{"visible", BOOLEAN},
|
||||||
{"zIndex", FLOAT}}},
|
{"zIndex", FLOAT}}},
|
||||||
{"text",
|
{"text",
|
||||||
|
@ -166,6 +172,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
|
||||||
{"letterCase", STRING},
|
{"letterCase", STRING},
|
||||||
{"forceUppercase", BOOLEAN}, // For backward compatibility with legacy themes.
|
{"forceUppercase", BOOLEAN}, // For backward compatibility with legacy themes.
|
||||||
{"lineSpacing", FLOAT},
|
{"lineSpacing", FLOAT},
|
||||||
|
{"opacity", FLOAT},
|
||||||
{"visible", BOOLEAN},
|
{"visible", BOOLEAN},
|
||||||
{"zIndex", FLOAT}}},
|
{"zIndex", FLOAT}}},
|
||||||
{"datetime",
|
{"datetime",
|
||||||
|
@ -187,6 +194,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
|
||||||
{"lineSpacing", FLOAT},
|
{"lineSpacing", FLOAT},
|
||||||
{"format", STRING},
|
{"format", STRING},
|
||||||
{"displayRelative", BOOLEAN},
|
{"displayRelative", BOOLEAN},
|
||||||
|
{"opacity", FLOAT},
|
||||||
{"visible", BOOLEAN},
|
{"visible", BOOLEAN},
|
||||||
{"zIndex", FLOAT}}},
|
{"zIndex", FLOAT}}},
|
||||||
{"gamelistinfo",
|
{"gamelistinfo",
|
||||||
|
@ -202,6 +210,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
|
||||||
{"horizontalAlignment", STRING},
|
{"horizontalAlignment", STRING},
|
||||||
{"verticalAlignment", STRING},
|
{"verticalAlignment", STRING},
|
||||||
{"alignment", STRING}, // For backward compatibility with legacy themes.
|
{"alignment", STRING}, // For backward compatibility with legacy themes.
|
||||||
|
{"opacity", FLOAT},
|
||||||
{"visible", BOOLEAN},
|
{"visible", BOOLEAN},
|
||||||
{"zIndex", FLOAT}}},
|
{"zIndex", FLOAT}}},
|
||||||
{"rating",
|
{"rating",
|
||||||
|
@ -213,6 +222,8 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
|
||||||
{"color", COLOR},
|
{"color", COLOR},
|
||||||
{"filledPath", PATH},
|
{"filledPath", PATH},
|
||||||
{"unfilledPath", PATH},
|
{"unfilledPath", PATH},
|
||||||
|
{"opacity", FLOAT},
|
||||||
|
{"visible", BOOLEAN},
|
||||||
{"zIndex", FLOAT}}},
|
{"zIndex", FLOAT}}},
|
||||||
{"carousel",
|
{"carousel",
|
||||||
{{"type", STRING},
|
{{"type", STRING},
|
||||||
|
@ -240,7 +251,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
|
||||||
{"fontSize", FLOAT},
|
{"fontSize", FLOAT},
|
||||||
{"lineSpacing", FLOAT},
|
{"lineSpacing", FLOAT},
|
||||||
{"zIndex", FLOAT},
|
{"zIndex", FLOAT},
|
||||||
{"legacyZIndexMode", STRING}}},
|
{"legacyZIndexMode", STRING}}}, // For backward compatibility with legacy themes.
|
||||||
{"textlist",
|
{"textlist",
|
||||||
{{"pos", NORMALIZED_PAIR},
|
{{"pos", NORMALIZED_PAIR},
|
||||||
{"size", NORMALIZED_PAIR},
|
{"size", NORMALIZED_PAIR},
|
||||||
|
|
|
@ -56,7 +56,8 @@ namespace ThemeFlags
|
||||||
DELAY = 0x00002000,
|
DELAY = 0x00002000,
|
||||||
Z_INDEX = 0x00004000,
|
Z_INDEX = 0x00004000,
|
||||||
ROTATION = 0x00008000,
|
ROTATION = 0x00008000,
|
||||||
VISIBLE = 0x00010000,
|
OPACITY = 0x00010000,
|
||||||
|
VISIBLE = 0x00020000,
|
||||||
ALL = 0xFFFFFFFF
|
ALL = 0xFFFFFFFF
|
||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
|
@ -168,14 +168,14 @@ const std::string BadgeComponent::getDisplayName(const std::string& shortName)
|
||||||
|
|
||||||
void BadgeComponent::render(const glm::mat4& parentTrans)
|
void BadgeComponent::render(const glm::mat4& parentTrans)
|
||||||
{
|
{
|
||||||
if (!isVisible())
|
if (!isVisible() || mThemeOpacity == 0.0f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (mOpacity == 1.0f) {
|
if (mOpacity * mThemeOpacity == 1.0f) {
|
||||||
mFlexboxComponent.render(parentTrans);
|
mFlexboxComponent.render(parentTrans);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mFlexboxComponent.setOpacity(mOpacity);
|
mFlexboxComponent.setOpacity(mOpacity * mThemeOpacity);
|
||||||
mFlexboxComponent.render(parentTrans);
|
mFlexboxComponent.render(parentTrans);
|
||||||
mFlexboxComponent.setOpacity(1.0f);
|
mFlexboxComponent.setOpacity(1.0f);
|
||||||
}
|
}
|
||||||
|
|
|
@ -369,7 +369,7 @@ void ImageComponent::updateVertices()
|
||||||
|
|
||||||
void ImageComponent::updateColors()
|
void ImageComponent::updateColors()
|
||||||
{
|
{
|
||||||
const float opacity = (mOpacity * (mFading ? mFadeOpacity : 1.0f));
|
const float opacity = (mOpacity * mThemeOpacity * (mFading ? mFadeOpacity : 1.0f));
|
||||||
const unsigned int color = Renderer::convertRGBAToABGR(
|
const unsigned int color = Renderer::convertRGBAToABGR(
|
||||||
(mColorShift & 0xFFFFFF00) | static_cast<unsigned char>((mColorShift & 0xFF) * opacity));
|
(mColorShift & 0xFFFFFF00) | static_cast<unsigned char>((mColorShift & 0xFF) * opacity));
|
||||||
const unsigned int colorEnd =
|
const unsigned int colorEnd =
|
||||||
|
@ -384,8 +384,8 @@ void ImageComponent::updateColors()
|
||||||
|
|
||||||
void ImageComponent::render(const glm::mat4& parentTrans)
|
void ImageComponent::render(const glm::mat4& parentTrans)
|
||||||
{
|
{
|
||||||
if (!isVisible() || mTexture == nullptr || mTargetSize == glm::vec2 {0.0f, 0.0f} ||
|
if (!isVisible() || mThemeOpacity == 0.0f || mTexture == nullptr ||
|
||||||
mSize == glm::vec2 {0.0f, 0.0f})
|
mTargetSize == glm::vec2 {0.0f, 0.0f} || mSize == glm::vec2 {0.0f, 0.0f})
|
||||||
return;
|
return;
|
||||||
|
|
||||||
glm::mat4 trans {parentTrans * getTransform()};
|
glm::mat4 trans {parentTrans * getTransform()};
|
||||||
|
|
|
@ -330,10 +330,7 @@ void LottieComponent::update(int deltaTime)
|
||||||
|
|
||||||
void LottieComponent::render(const glm::mat4& parentTrans)
|
void LottieComponent::render(const glm::mat4& parentTrans)
|
||||||
{
|
{
|
||||||
if (!isVisible())
|
if (!isVisible() || mThemeOpacity == 0.0f || mAnimation == nullptr)
|
||||||
return;
|
|
||||||
|
|
||||||
if (mAnimation == nullptr)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
glm::mat4 trans {parentTrans * getTransform()};
|
glm::mat4 trans {parentTrans * getTransform()};
|
||||||
|
@ -472,6 +469,7 @@ void LottieComponent::render(const glm::mat4& parentTrans)
|
||||||
|
|
||||||
#if defined(USE_OPENGL_21)
|
#if defined(USE_OPENGL_21)
|
||||||
// Perform color space conversion from BGRA to RGBA.
|
// Perform color space conversion from BGRA to RGBA.
|
||||||
|
vertices[0].opacity = mThemeOpacity;
|
||||||
vertices[0].shaders = Renderer::SHADER_BGRA_TO_RGBA;
|
vertices[0].shaders = Renderer::SHADER_BGRA_TO_RGBA;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,8 @@ std::string RatingComponent::getRatingValue() const
|
||||||
void RatingComponent::setOpacity(float opacity)
|
void RatingComponent::setOpacity(float opacity)
|
||||||
{
|
{
|
||||||
mOpacity = opacity;
|
mOpacity = opacity;
|
||||||
mColorShift = (mColorShift >> 8 << 8) | static_cast<unsigned char>(mOpacity * 255.0f);
|
mColorShift =
|
||||||
|
(mColorShift >> 8 << 8) | static_cast<unsigned char>(mOpacity * mThemeOpacity * 255.0f);
|
||||||
updateColors();
|
updateColors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +149,8 @@ void RatingComponent::updateColors()
|
||||||
|
|
||||||
void RatingComponent::render(const glm::mat4& parentTrans)
|
void RatingComponent::render(const glm::mat4& parentTrans)
|
||||||
{
|
{
|
||||||
if (!isVisible() || mFilledTexture == nullptr || mUnfilledTexture == nullptr)
|
if (!isVisible() || mFilledTexture == nullptr || mUnfilledTexture == nullptr ||
|
||||||
|
mThemeOpacity == 0.0f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
glm::mat4 trans {parentTrans * getTransform()};
|
glm::mat4 trans {parentTrans * getTransform()};
|
||||||
|
|
|
@ -214,7 +214,7 @@ void ScrollableContainer::update(int deltaTime)
|
||||||
|
|
||||||
void ScrollableContainer::render(const glm::mat4& parentTrans)
|
void ScrollableContainer::render(const glm::mat4& parentTrans)
|
||||||
{
|
{
|
||||||
if (!isVisible())
|
if (!isVisible() || mThemeOpacity == 0.0f || mChildren.front()->getValue() == "")
|
||||||
return;
|
return;
|
||||||
|
|
||||||
glm::mat4 trans {parentTrans * getTransform()};
|
glm::mat4 trans {parentTrans * getTransform()};
|
||||||
|
|
|
@ -32,7 +32,7 @@ public:
|
||||||
void setChangedColor(unsigned int color) override { mColorChangedValue = color; }
|
void setChangedColor(unsigned int color) override { mColorChangedValue = color; }
|
||||||
void setCallback(const std::function<void()>& callbackFunc) { mToggleCallback = callbackFunc; }
|
void setCallback(const std::function<void()>& callbackFunc) { mToggleCallback = callbackFunc; }
|
||||||
|
|
||||||
float getOpacity() const override { return mImage.getOpacity(); }
|
float const getOpacity() const override { return mImage.getOpacity(); }
|
||||||
void setOpacity(float opacity) override { mImage.setOpacity(opacity); }
|
void setOpacity(float opacity) override { mImage.setOpacity(opacity); }
|
||||||
// Multiply all pixels in the image by this color when rendering.
|
// Multiply all pixels in the image by this color when rendering.
|
||||||
void setColorShift(unsigned int color) override { mImage.setColorShift(color); }
|
void setColorShift(unsigned int color) override { mImage.setColorShift(color); }
|
||||||
|
|
|
@ -95,12 +95,11 @@ void TextComponent::setBackgroundColor(unsigned int color)
|
||||||
// Scale the opacity.
|
// Scale the opacity.
|
||||||
void TextComponent::setOpacity(float opacity)
|
void TextComponent::setOpacity(float opacity)
|
||||||
{
|
{
|
||||||
// This function is mostly called to do fade in and fade out of the text component element.
|
float textOpacity {opacity * mColorOpacity * mThemeOpacity};
|
||||||
float o {opacity * mColorOpacity};
|
mColor = (mColor & 0xFFFFFF00) | static_cast<unsigned char>(textOpacity * 255.0f);
|
||||||
mColor = (mColor & 0xFFFFFF00) | static_cast<unsigned char>(o * 255.0f);
|
|
||||||
|
|
||||||
float bgo {opacity * mBgColorOpacity};
|
float textBackgroundOpacity {opacity * mBgColorOpacity * mThemeOpacity};
|
||||||
mBgColor = (mBgColor & 0xFFFFFF00) | static_cast<unsigned char>(bgo * 255.0f);
|
mBgColor = (mBgColor & 0xFFFFFF00) | static_cast<unsigned char>(textBackgroundOpacity * 255.0f);
|
||||||
|
|
||||||
onColorChanged();
|
onColorChanged();
|
||||||
GuiComponent::setOpacity(opacity);
|
GuiComponent::setOpacity(opacity);
|
||||||
|
@ -149,7 +148,7 @@ void TextComponent::setCapitalize(bool capitalize)
|
||||||
|
|
||||||
void TextComponent::render(const glm::mat4& parentTrans)
|
void TextComponent::render(const glm::mat4& parentTrans)
|
||||||
{
|
{
|
||||||
if (!isVisible())
|
if (!isVisible() || mThemeOpacity == 0.0f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
glm::mat4 trans {parentTrans * getTransform()};
|
glm::mat4 trans {parentTrans * getTransform()};
|
||||||
|
@ -302,18 +301,18 @@ void TextComponent::onTextChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
text.append(abbrev);
|
text.append(abbrev);
|
||||||
|
|
||||||
mTextCache = std::shared_ptr<TextCache>(f->buildTextCache(
|
mTextCache = std::shared_ptr<TextCache>(f->buildTextCache(
|
||||||
text, glm::vec2 {}, (mColor >> 8 << 8) | static_cast<unsigned char>(mOpacity * 255.0f),
|
text, glm::vec2 {}, mColor, mSize.x, mHorizontalAlignment, mLineSpacing, mNoTopMargin));
|
||||||
mSize.x, mHorizontalAlignment, mLineSpacing, mNoTopMargin));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
mTextCache = std::shared_ptr<TextCache>(
|
mTextCache = std::shared_ptr<TextCache>(
|
||||||
f->buildTextCache(f->wrapText(text, mSize.x), glm::vec2 {},
|
f->buildTextCache(f->wrapText(text, mSize.x), glm::vec2 {}, mColor, mSize.x,
|
||||||
(mColor >> 8 << 8) | static_cast<unsigned char>(mOpacity * 255.0f),
|
mHorizontalAlignment, mLineSpacing, mNoTopMargin));
|
||||||
mSize.x, mHorizontalAlignment, mLineSpacing, mNoTopMargin));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mOpacity != 1.0f || mThemeOpacity != 1.0f)
|
||||||
|
setOpacity(mOpacity);
|
||||||
|
|
||||||
// This is required to set the color transparency.
|
// This is required to set the color transparency.
|
||||||
onColorChanged();
|
onColorChanged();
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,10 @@ public:
|
||||||
std::string getHiddenValue() const override { return mHiddenText; }
|
std::string getHiddenValue() const override { return mHiddenText; }
|
||||||
void setHiddenValue(const std::string& value) override { setHiddenText(value); }
|
void setHiddenValue(const std::string& value) override { setHiddenText(value); }
|
||||||
|
|
||||||
float getOpacity() const override { return static_cast<float>((mColor & 0x000000FF) / 255.0f); }
|
float const getOpacity() const override
|
||||||
|
{
|
||||||
|
return static_cast<float>((mColor & 0x000000FF) / 255.0f);
|
||||||
|
}
|
||||||
void setOpacity(float opacity) override;
|
void setOpacity(float opacity) override;
|
||||||
|
|
||||||
void setSelectable(bool status) { mSelectable = status; }
|
void setSelectable(bool status) { mSelectable = status; }
|
||||||
|
|
Loading…
Reference in a new issue