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