Added six new theme properties for sizing and placement of the helpsystem when a menu is open

This commit is contained in:
Leon Styhre 2023-04-09 12:47:44 +02:00
parent aa6aaf128e
commit dfe7469101
6 changed files with 91 additions and 15 deletions

View file

@ -16,16 +16,24 @@ HelpStyle::HelpStyle()
: position {Renderer::getScreenWidth() * 0.012f, : position {Renderer::getScreenWidth() * 0.012f,
Renderer::getScreenHeight() * Renderer::getScreenHeight() *
(Renderer::getIsVerticalOrientation() ? 0.975f : 0.9515f)} (Renderer::getIsVerticalOrientation() ? 0.975f : 0.9515f)}
, positionDimmed {position}
, origin {glm::vec2 {0.0f, 0.0f}} , origin {glm::vec2 {0.0f, 0.0f}}
, originDimmed {origin}
, textColor {0x777777FF} , textColor {0x777777FF}
, textColorDimmed {0x777777FF} , textColorDimmed {0x777777FF}
, iconColor {0x777777FF} , iconColor {0x777777FF}
, iconColorDimmed {0x777777FF} , iconColorDimmed {0x777777FF}
, font {Renderer::getIsVerticalOrientation() ? Font::get(0.025f * Renderer::getScreenWidth()) : , font {Renderer::getIsVerticalOrientation() ? Font::get(0.025f * Renderer::getScreenWidth()) :
Font::get(FONT_SIZE_SMALL)} Font::get(FONT_SIZE_SMALL)}
, fontDimmed {Renderer::getIsVerticalOrientation() ?
Font::get(0.025f * Renderer::getScreenWidth()) :
Font::get(FONT_SIZE_SMALL)}
, entrySpacing {0.00833f} , entrySpacing {0.00833f}
, entrySpacingDimmed {entrySpacing}
, iconTextSpacing {0.00416f} , iconTextSpacing {0.00416f}
, iconTextSpacingDimmed {iconTextSpacing}
, opacity {1.0f} , opacity {1.0f}
, opacityDimmed {opacity}
, legacyTheme {false} , legacyTheme {false}
, letterCase {"uppercase"} , letterCase {"uppercase"}
{ {
@ -43,9 +51,20 @@ void HelpStyle::applyTheme(const std::shared_ptr<ThemeData>& theme, const std::s
position = elem->get<glm::vec2>("pos") * position = elem->get<glm::vec2>("pos") *
glm::vec2 {Renderer::getScreenWidth(), Renderer::getScreenHeight()}; glm::vec2 {Renderer::getScreenWidth(), Renderer::getScreenHeight()};
if (elem->has("posDimmed"))
positionDimmed = elem->get<glm::vec2>("posDimmed") *
glm::vec2 {Renderer::getScreenWidth(), Renderer::getScreenHeight()};
else
positionDimmed = position;
if (elem->has("origin")) if (elem->has("origin"))
origin = elem->get<glm::vec2>("origin"); origin = elem->get<glm::vec2>("origin");
if (elem->has("originDimmed"))
originDimmed = elem->get<glm::vec2>("originDimmed");
else
originDimmed = origin;
if (elem->has("textColor")) if (elem->has("textColor"))
textColor = elem->get<unsigned int>("textColor"); textColor = elem->get<unsigned int>("textColor");
@ -62,21 +81,45 @@ void HelpStyle::applyTheme(const std::shared_ptr<ThemeData>& theme, const std::s
else else
iconColorDimmed = iconColor; iconColorDimmed = iconColor;
if (elem->has("fontPath") || elem->has("fontSize")) if (elem->has("fontPath") || elem->has("fontSize")) {
font = Font::getFromTheme(elem, ThemeFlags::ALL, font, 0.0f, false, theme->isLegacyTheme()); font = Font::getFromTheme(elem, ThemeFlags::ALL, font, 0.0f, false, theme->isLegacyTheme());
if (!elem->has("fontSizeDimmed"))
fontDimmed = Font::getFromTheme(elem, ThemeFlags::ALL, font, 0.0f, false,
theme->isLegacyTheme());
}
if (elem->has("fontSizeDimmed")) {
fontDimmed = Font::getFromTheme(elem, ThemeFlags::ALL, font, 0.0f, false,
theme->isLegacyTheme(), 1.0f, true);
}
if (elem->has("entrySpacing")) if (elem->has("entrySpacing"))
entrySpacing = glm::clamp(elem->get<float>("entrySpacing"), 0.0f, 0.04f); entrySpacing = glm::clamp(elem->get<float>("entrySpacing"), 0.0f, 0.04f);
if (elem->has("entrySpacingDimmed"))
entrySpacingDimmed = glm::clamp(elem->get<float>("entrySpacingDimmed"), 0.0f, 0.04f);
else
entrySpacingDimmed = entrySpacing;
if (elem->has("iconTextSpacing")) if (elem->has("iconTextSpacing"))
iconTextSpacing = glm::clamp(elem->get<float>("iconTextSpacing"), 0.0f, 0.04f); iconTextSpacing = glm::clamp(elem->get<float>("iconTextSpacing"), 0.0f, 0.04f);
if (elem->has("iconTextSpacingDimmed"))
iconTextSpacingDimmed = glm::clamp(elem->get<float>("iconTextSpacingDimmed"), 0.0f, 0.04f);
else
iconTextSpacingDimmed = iconTextSpacing;
if (elem->has("letterCase")) if (elem->has("letterCase"))
letterCase = elem->get<std::string>("letterCase"); letterCase = elem->get<std::string>("letterCase");
if (elem->has("opacity")) if (elem->has("opacity"))
opacity = glm::clamp(elem->get<float>("opacity"), 0.2f, 1.0f); opacity = glm::clamp(elem->get<float>("opacity"), 0.2f, 1.0f);
if (elem->has("opacityDimmed"))
opacityDimmed = glm::clamp(elem->get<float>("opacityDimmed"), 0.2f, 1.0f);
else
opacityDimmed = opacity;
// Load custom button icons. // Load custom button icons.
// The names may look a bit strange when combined with the PREFIX string "button_" but it's // 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. // because ThemeData adds this prefix to avoid name collisions when using XML attributes.

View file

@ -19,15 +19,21 @@ class ThemeData;
struct HelpStyle { struct HelpStyle {
glm::vec2 position; glm::vec2 position;
glm::vec2 positionDimmed;
glm::vec2 origin; glm::vec2 origin;
glm::vec2 originDimmed;
unsigned int textColor; unsigned int textColor;
unsigned int textColorDimmed; unsigned int textColorDimmed;
unsigned int iconColor; unsigned int iconColor;
unsigned int iconColorDimmed; unsigned int iconColorDimmed;
std::shared_ptr<Font> font; std::shared_ptr<Font> font;
std::shared_ptr<Font> fontDimmed;
float entrySpacing; float entrySpacing;
float entrySpacingDimmed;
float iconTextSpacing; float iconTextSpacing;
float iconTextSpacingDimmed;
float opacity; float opacity;
float opacityDimmed;
bool legacyTheme; bool legacyTheme;
std::string letterCase; std::string letterCase;

View file

@ -498,18 +498,24 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"allowDuplicates", BOOLEAN}}}, {"allowDuplicates", BOOLEAN}}},
{"helpsystem", {"helpsystem",
{{"pos", NORMALIZED_PAIR}, {{"pos", NORMALIZED_PAIR},
{"posDimmed", NORMALIZED_PAIR},
{"origin", NORMALIZED_PAIR}, {"origin", NORMALIZED_PAIR},
{"originDimmed", NORMALIZED_PAIR},
{"textColor", COLOR}, {"textColor", COLOR},
{"textColorDimmed", COLOR}, {"textColorDimmed", COLOR},
{"iconColor", COLOR}, {"iconColor", COLOR},
{"iconColorDimmed", COLOR}, {"iconColorDimmed", COLOR},
{"fontPath", PATH}, {"fontPath", PATH},
{"fontSize", FLOAT}, {"fontSize", FLOAT},
{"fontSizeDimmed", FLOAT},
{"entrySpacing", FLOAT}, {"entrySpacing", FLOAT},
{"entrySpacingDimmed", FLOAT},
{"iconTextSpacing", FLOAT}, {"iconTextSpacing", FLOAT},
{"iconTextSpacingDimmed", FLOAT},
{"letterCase", STRING}, {"letterCase", STRING},
{"textStyle", STRING}, // For backward compatibility with legacy themes. {"textStyle", STRING}, // For backward compatibility with legacy themes.
{"opacity", FLOAT}, {"opacity", FLOAT},
{"opacityDimmed", FLOAT},
{"customButtonIcon", PATH}}}, {"customButtonIcon", PATH}}},
{"navigationsounds", {"navigationsounds",
{{"systembrowseSound", PATH}, {{"systembrowseSound", PATH},

View file

@ -243,7 +243,9 @@ void HelpComponent::updateGrid()
return; return;
} }
std::shared_ptr<Font>& font {mStyle.font}; const bool isDimmed {mWindow->isBackgroundDimmed()};
std::shared_ptr<Font>& font {isDimmed ? mStyle.fontDimmed : mStyle.font};
mGrid = std::make_shared<ComponentGrid>(glm::ivec2 {static_cast<int>(mPrompts.size()) * 5, 1}); mGrid = std::make_shared<ComponentGrid>(glm::ivec2 {static_cast<int>(mPrompts.size()) * 5, 1});
std::vector<std::shared_ptr<ImageComponent>> icons; std::vector<std::shared_ptr<ImageComponent>> icons;
@ -251,14 +253,13 @@ void HelpComponent::updateGrid()
float width {0.0f}; float width {0.0f};
float height {font->getLetterHeight() * 1.25f}; float height {font->getLetterHeight() * 1.25f};
bool isDimmed {mWindow->isBackgroundDimmed()};
for (auto it = mPrompts.cbegin(); it != mPrompts.cend(); ++it) { for (auto it = mPrompts.cbegin(); it != mPrompts.cend(); ++it) {
auto icon = std::make_shared<ImageComponent>(); auto icon = std::make_shared<ImageComponent>();
icon->setImage(getIconTexture(it->first.c_str()), false); icon->setImage(getIconTexture(it->first.c_str()), false);
icon->setColorShift(isDimmed ? mStyle.iconColorDimmed : mStyle.iconColor); icon->setColorShift(isDimmed ? mStyle.iconColorDimmed : mStyle.iconColor);
icon->setResize(0, height); icon->setResize(0, height);
icon->setOpacity(mStyle.opacity); icon->setOpacity(isDimmed ? mStyle.opacityDimmed : mStyle.opacity);
icons.push_back(icon); icons.push_back(icon);
// Apply text style and color from the theme to the label and add it to the label list. // Apply text style and color from the theme to the label and add it to the label list.
@ -271,12 +272,14 @@ void HelpComponent::updateGrid()
lblInput = Utils::String::toUpper(lblInput); lblInput = Utils::String::toUpper(lblInput);
auto lbl = std::make_shared<TextComponent>( auto lbl = std::make_shared<TextComponent>(
lblInput, font, isDimmed ? mStyle.textColorDimmed : mStyle.textColor); lblInput, font, isDimmed ? mStyle.textColorDimmed : mStyle.textColor);
lbl->setOpacity(mStyle.opacity); lbl->setOpacity(isDimmed ? mStyle.opacityDimmed : mStyle.opacity);
labels.push_back(lbl); labels.push_back(lbl);
width += icon->getSize().x + lbl->getSize().x + width += icon->getSize().x + lbl->getSize().x +
((mStyle.iconTextSpacing * mRenderer->getScreenWidth() + (((isDimmed ? mStyle.iconTextSpacingDimmed : mStyle.iconTextSpacing) *
mStyle.entrySpacing * mRenderer->getScreenWidth())); mRenderer->getScreenWidth() +
(isDimmed ? mStyle.entrySpacingDimmed : mStyle.entrySpacing) *
mRenderer->getScreenWidth()));
} }
mGrid->setSize(width, height); mGrid->setSize(width, height);
@ -285,10 +288,14 @@ void HelpComponent::updateGrid()
const int col {i * 5}; const int col {i * 5};
mGrid->setColWidthPerc(col, icons.at(i)->getSize().x / width); mGrid->setColWidthPerc(col, icons.at(i)->getSize().x / width);
mGrid->setColWidthPerc(col + 1, mGrid->setColWidthPerc(col + 1,
(mStyle.iconTextSpacing * mRenderer->getScreenWidth()) / width); ((isDimmed ? mStyle.iconTextSpacingDimmed : mStyle.iconTextSpacing) *
mRenderer->getScreenWidth()) /
width);
mGrid->setColWidthPerc(col + 2, labels.at(i)->getSize().x / width); mGrid->setColWidthPerc(col + 2, labels.at(i)->getSize().x / width);
mGrid->setColWidthPerc(col + 3, mGrid->setColWidthPerc(col + 3,
(mStyle.entrySpacing * mRenderer->getScreenWidth()) / width); ((isDimmed ? mStyle.entrySpacingDimmed : mStyle.entrySpacing) *
mRenderer->getScreenWidth()) /
width);
mGrid->setEntry(icons.at(i), glm::ivec2 {col, 0}, false, false); mGrid->setEntry(icons.at(i), glm::ivec2 {col, 0}, false, false);
mGrid->setEntry(labels.at(i), glm::ivec2 {col + 2, 0}, false, false); mGrid->setEntry(labels.at(i), glm::ivec2 {col + 2, 0}, false, false);
@ -300,6 +307,12 @@ void HelpComponent::updateGrid()
if (mStyle.legacyTheme) { if (mStyle.legacyTheme) {
mGrid->setPosition({mStyle.position.x, mStyle.position.y, 0.0f}); mGrid->setPosition({mStyle.position.x, mStyle.position.y, 0.0f});
} }
else if (isDimmed) {
mGrid->setPosition(
{mStyle.positionDimmed.x + ((mStyle.entrySpacingDimmed * mRenderer->getScreenWidth()) *
mStyle.originDimmed.x),
mStyle.positionDimmed.y, 0.0f});
}
else { else {
mGrid->setPosition( mGrid->setPosition(
{mStyle.position.x + {mStyle.position.x +
@ -307,7 +320,7 @@ void HelpComponent::updateGrid()
mStyle.position.y, 0.0f}); mStyle.position.y, 0.0f});
} }
mGrid->setOrigin(mStyle.origin); mGrid->setOrigin(isDimmed ? mStyle.originDimmed : mStyle.origin);
} }
std::shared_ptr<TextureResource> HelpComponent::getIconTexture(const char* name) std::shared_ptr<TextureResource> HelpComponent::getIconTexture(const char* name)
@ -336,10 +349,12 @@ std::shared_ptr<TextureResource> HelpComponent::getIconTexture(const char* name)
void HelpComponent::setOpacity(float opacity) void HelpComponent::setOpacity(float opacity)
{ {
GuiComponent::setOpacity(opacity * mStyle.opacity); GuiComponent::setOpacity(
opacity * (mWindow->isBackgroundDimmed() ? mStyle.opacityDimmed : mStyle.opacity));
for (unsigned int i = 0; i < mGrid->getChildCount(); ++i) for (unsigned int i = 0; i < mGrid->getChildCount(); ++i)
mGrid->getChild(i)->setOpacity(opacity * mStyle.opacity); mGrid->getChild(i)->setOpacity(
opacity * (mWindow->isBackgroundDimmed() ? mStyle.opacityDimmed : mStyle.opacity));
} }
void HelpComponent::render(const glm::mat4& parentTrans) void HelpComponent::render(const glm::mat4& parentTrans)

View file

@ -431,7 +431,8 @@ std::shared_ptr<Font> Font::getFromTheme(const ThemeData::ThemeElement* elem,
const float maxHeight, const float maxHeight,
const bool linearMagnify, const bool linearMagnify,
const bool legacyTheme, const bool legacyTheme,
const float sizeMultiplier) const float sizeMultiplier,
const bool fontSizeDimmed)
{ {
mLegacyTheme = legacyTheme; mLegacyTheme = legacyTheme;
@ -446,7 +447,11 @@ std::shared_ptr<Font> Font::getFromTheme(const ThemeData::ThemeElement* elem,
static_cast<float>(Renderer::getScreenWidth()) : static_cast<float>(Renderer::getScreenWidth()) :
static_cast<float>(Renderer::getScreenHeight())}; static_cast<float>(Renderer::getScreenHeight())};
if (properties & FONT_SIZE && elem->has("fontSize")) { if (fontSizeDimmed && properties & FONT_SIZE && elem->has("fontSizeDimmed")) {
size = glm::clamp(screenSize * elem->get<float>("fontSizeDimmed"), screenSize * 0.001f,
screenSize * 1.5f);
}
else if (properties & FONT_SIZE && elem->has("fontSize")) {
size = glm::clamp(screenSize * elem->get<float>("fontSize"), screenSize * 0.001f, size = glm::clamp(screenSize * elem->get<float>("fontSize"), screenSize * 0.001f,
screenSize * 1.5f); screenSize * 1.5f);
// This is used by the carousel where the itemScale property also scales the font size. // This is used by the carousel where the itemScale property also scales the font size.

View file

@ -138,7 +138,8 @@ public:
const float maxHeight = 0.0f, const float maxHeight = 0.0f,
const bool linearMagnify = false, const bool linearMagnify = false,
const bool legacyTheme = false, const bool legacyTheme = false,
const float sizeMultiplier = 1.0f); const float sizeMultiplier = 1.0f,
const bool fontSizeDimmed = false);
// Returns an approximation of VRAM used by this font's texture (in bytes). // Returns an approximation of VRAM used by this font's texture (in bytes).
size_t getMemUsage() const; size_t getMemUsage() const;