mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-21 21:55:38 +00:00
Added themeable opacity support for the help system.
This commit is contained in:
parent
d1f4453e3b
commit
027265da67
|
@ -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<ThemeData>& theme, const std::s
|
|||
if (elem->has("letterCase"))
|
||||
letterCase = elem->get<std::string>("letterCase");
|
||||
|
||||
if (elem->has("opacity"))
|
||||
opacity = glm::clamp(elem->get<float>("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.
|
||||
|
|
|
@ -28,6 +28,7 @@ struct HelpStyle {
|
|||
std::shared_ptr<Font> font;
|
||||
float entrySpacing;
|
||||
float iconTextSpacing;
|
||||
float opacity;
|
||||
std::string letterCase;
|
||||
|
||||
struct CustomButtonIcons {
|
||||
|
|
|
@ -292,6 +292,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
|
|||
{"iconTextSpacing", FLOAT},
|
||||
{"letterCase", STRING},
|
||||
{"textStyle", STRING}, // For backward compatibility with legacy themes.
|
||||
{"opacity", FLOAT},
|
||||
{"customButtonIcon", PATH}}},
|
||||
{"sound",
|
||||
{{"path", PATH}}},
|
||||
|
|
|
@ -209,21 +209,22 @@ void HelpComponent::updateGrid()
|
|||
std::vector<std::shared_ptr<ImageComponent>> icons;
|
||||
std::vector<std::shared_ptr<TextComponent>> 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<ImageComponent>();
|
||||
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<TextComponent>(
|
||||
lblInput, font, isDimmed ? mStyle.textColorDimmed : mStyle.textColor);
|
||||
lbl->setOpacity(mStyle.opacity);
|
||||
labels.push_back(lbl);
|
||||
|
||||
width +=
|
||||
|
@ -274,18 +276,18 @@ std::shared_ptr<TextureResource> HelpComponent::getIconTexture(const char* name)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<TextureResource> tex =
|
||||
TextureResource::get(pathLookup->second, false, false, false);
|
||||
std::shared_ptr<TextureResource> 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)
|
||||
|
|
Loading…
Reference in a new issue