diff --git a/es-core/src/HelpStyle.cpp b/es-core/src/HelpStyle.cpp index e5d86a533..a0d14e0f8 100644 --- a/es-core/src/HelpStyle.cpp +++ b/es-core/src/HelpStyle.cpp @@ -25,6 +25,7 @@ HelpStyle::HelpStyle() entrySpacing = 16.0f; iconTextSpacing = 8.0f; letterCase = "uppercase"; + opacity = 1.0f; if (FONT_SIZE_SMALL != 0) font = Font::get(FONT_SIZE_SMALL); @@ -73,6 +74,9 @@ void HelpStyle::applyTheme(const std::shared_ptr& theme, const std::s if (elem->has("letterCase")) letterCase = elem->get("letterCase"); + if (elem->has("opacity")) + opacity = glm::clamp(elem->get("opacity"), 0.2f, 1.0f); + // Load custom button icons. // The names may look a bit strange when combined with the PREFIX string "button_" but it's // because ThemeData adds this prefix to avoid name collisions when using XML attributes. diff --git a/es-core/src/HelpStyle.h b/es-core/src/HelpStyle.h index 77c60de4a..cb613cb3d 100644 --- a/es-core/src/HelpStyle.h +++ b/es-core/src/HelpStyle.h @@ -28,6 +28,7 @@ struct HelpStyle { std::shared_ptr font; float entrySpacing; float iconTextSpacing; + float opacity; std::string letterCase; struct CustomButtonIcons { diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 2b4c83109..55c6f7f94 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -292,6 +292,7 @@ std::map> {"iconTextSpacing", FLOAT}, {"letterCase", STRING}, {"textStyle", STRING}, // For backward compatibility with legacy themes. + {"opacity", FLOAT}, {"customButtonIcon", PATH}}}, {"sound", {{"path", PATH}}}, diff --git a/es-core/src/components/HelpComponent.cpp b/es-core/src/components/HelpComponent.cpp index 5e99f3f0c..73e627560 100644 --- a/es-core/src/components/HelpComponent.cpp +++ b/es-core/src/components/HelpComponent.cpp @@ -209,21 +209,22 @@ void HelpComponent::updateGrid() std::vector> icons; std::vector> labels; - float width = 0; - const float height = std::round(font->getLetterHeight() * 1.25f); + float width {0.0f}; + const float height {std::round(font->getLetterHeight() * 1.25f)}; // State variable indicating whether gui is dimmed. - bool isDimmed = mWindow->isBackgroundDimmed(); + bool isDimmed {mWindow->isBackgroundDimmed()}; for (auto it = mPrompts.cbegin(); it != mPrompts.cend(); ++it) { auto icon = std::make_shared(); icon->setImage(getIconTexture(it->first.c_str()), false); icon->setColorShift(isDimmed ? mStyle.iconColorDimmed : mStyle.iconColor); icon->setResize(0, height); + icon->setOpacity(mStyle.opacity); icons.push_back(icon); // Apply text style and color from the theme to the label and add it to the label list. - std::string lblInput = it->second; + std::string lblInput {it->second}; if (mStyle.letterCase == "lowercase") lblInput = Utils::String::toLower(lblInput); else if (mStyle.letterCase == "capitalize") @@ -232,6 +233,7 @@ void HelpComponent::updateGrid() lblInput = Utils::String::toUpper(lblInput); auto lbl = std::make_shared( lblInput, font, isDimmed ? mStyle.textColorDimmed : mStyle.textColor); + lbl->setOpacity(mStyle.opacity); labels.push_back(lbl); width += @@ -274,18 +276,18 @@ std::shared_ptr HelpComponent::getIconTexture(const char* name) return nullptr; } - std::shared_ptr tex = - TextureResource::get(pathLookup->second, false, false, false); + std::shared_ptr tex { + TextureResource::get(pathLookup->second, false, false, false)}; mIconCache[std::string(name)] = tex; return tex; } void HelpComponent::setOpacity(float opacity) { - GuiComponent::setOpacity(opacity); + GuiComponent::setOpacity(opacity * mStyle.opacity); for (unsigned int i = 0; i < mGrid->getChildCount(); ++i) - mGrid->getChild(i)->setOpacity(opacity); + mGrid->getChild(i)->setOpacity(opacity * mStyle.opacity); } void HelpComponent::render(const glm::mat4& parentTrans)