From 94c6640e7277293e089bb4f294153e3232f3452e Mon Sep 17 00:00:00 2001 From: Sophia Hadash Date: Sun, 22 Aug 2021 16:43:15 +0200 Subject: [PATCH] Add help component theme options `textColorDimmed` and `iconColorDimmed`. --- es-core/src/HelpStyle.cpp | 10 +++++++++- es-core/src/HelpStyle.h | 4 +++- es-core/src/ThemeData.cpp | 2 ++ es-core/src/Window.cpp | 9 +++++++-- es-core/src/Window.h | 1 + es-core/src/components/HelpComponent.cpp | 12 ++++++++++-- 6 files changed, 32 insertions(+), 6 deletions(-) diff --git a/es-core/src/HelpStyle.cpp b/es-core/src/HelpStyle.cpp index 7294c2f21..159b80636 100644 --- a/es-core/src/HelpStyle.cpp +++ b/es-core/src/HelpStyle.cpp @@ -16,8 +16,10 @@ HelpStyle::HelpStyle() position = glm::vec2{Renderer::getScreenWidth() * 0.012f, Renderer::getScreenHeight() * 0.9515f}; origin = glm::vec2{}; - iconColor = 0x777777FF; textColor = 0x777777FF; + textColorDimmed = 0x777777FF; + iconColor = 0x777777FF; + iconColorDimmed = 0x777777FF; entrySpacing = 16.0f; iconTextSpacing = 8.0f; textStyle = "uppercase"; @@ -45,9 +47,15 @@ void HelpStyle::applyTheme(const std::shared_ptr& theme, const std::s if (elem->has("textColor")) textColor = elem->get("textColor"); + if (elem->has("textColorDimmed")) + textColorDimmed = elem->get("textColorDimmed"); + if (elem->has("iconColor")) iconColor = elem->get("iconColor"); + if (elem->has("iconColorDimmed")) + iconColorDimmed = elem->get("iconColorDimmed"); + if (elem->has("fontPath") || elem->has("fontSize")) font = Font::getFromTheme(elem, ThemeFlags::ALL, font); diff --git a/es-core/src/HelpStyle.h b/es-core/src/HelpStyle.h index 5a7afe50e..5a5e3870a 100644 --- a/es-core/src/HelpStyle.h +++ b/es-core/src/HelpStyle.h @@ -21,8 +21,10 @@ class ThemeData; struct HelpStyle { glm::vec2 position; glm::vec2 origin; - unsigned int iconColor; unsigned int textColor; + unsigned int textColorDimmed; + unsigned int iconColor; + unsigned int iconColorDimmed; std::shared_ptr font; float entrySpacing; float iconTextSpacing; diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index a208e14ff..936321011 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -151,7 +151,9 @@ std::map> The {{"pos", NORMALIZED_PAIR}, {"origin", NORMALIZED_PAIR}, {"textColor", COLOR}, + {"textColorDimmed", COLOR}, {"iconColor", COLOR}, + {"iconColorDimmed", COLOR}, {"fontPath", PATH}, {"fontSize", FLOAT}, {"entrySpacing", FLOAT}, diff --git a/es-core/src/Window.cpp b/es-core/src/Window.cpp index 6dab2c03e..8b021ed9b 100644 --- a/es-core/src/Window.cpp +++ b/es-core/src/Window.cpp @@ -359,6 +359,11 @@ void Window::update(int deltaTime) mScreensaver->update(deltaTime); } +bool Window::isBackgroundDimmed() +{ + return !mGuiStack.empty() && (mGuiStack.front() != mGuiStack.back() || mRenderLaunchScreen); +} + void Window::render() { glm::mat4 trans{Renderer::getIdentity()}; @@ -366,7 +371,7 @@ void Window::render() mRenderedHelpPrompts = false; // Draw only bottom and top of GuiStack (if they are different). - if (mGuiStack.size()) { + if (!mGuiStack.empty()) { auto& bottom = mGuiStack.front(); auto& top = mGuiStack.back(); @@ -408,7 +413,7 @@ void Window::render() unsigned char* processedTexture = new unsigned char[Renderer::getScreenWidth() * Renderer::getScreenHeight() * 4]; - // Defocus the background using multiple passes of gaussian blur, with the number + // De-focus the background using multiple passes of gaussian blur, with the number // of iterations relative to the screen resolution. Renderer::shaderParameters backgroundParameters; diff --git a/es-core/src/Window.h b/es-core/src/Window.h index 2f68f7cc2..193053c43 100644 --- a/es-core/src/Window.h +++ b/es-core/src/Window.h @@ -88,6 +88,7 @@ public: void removeGui(GuiComponent* gui); GuiComponent* peekGui(); int getGuiStackSize() { return static_cast(mGuiStack.size()); } + bool isBackgroundDimmed(); bool init(); void deinit(); diff --git a/es-core/src/components/HelpComponent.cpp b/es-core/src/components/HelpComponent.cpp index 647fa6b15..6f036d859 100644 --- a/es-core/src/components/HelpComponent.cpp +++ b/es-core/src/components/HelpComponent.cpp @@ -10,6 +10,7 @@ #include "Log.h" #include "Settings.h" +#include "Window.h" #include "components/ComponentGrid.h" #include "components/ImageComponent.h" #include "components/TextComponent.h" @@ -121,10 +122,16 @@ void HelpComponent::updateGrid() float width = 0; const float height = std::round(font->getLetterHeight() * 1.25f); + // State variable indicating whether gui is dimmed. + bool isDimmed = mWindow->isBackgroundDimmed(); + LOG(LogError) << "updateGrid() called. dimmed = \"" << isDimmed << "\""; + for (auto it = mPrompts.cbegin(); it != mPrompts.cend(); it++) { auto icon = std::make_shared(mWindow); icon->setImage(getIconTexture(it->first.c_str())); - icon->setColorShift(mStyle.iconColor); + icon->setColorShift(isDimmed ? mStyle.iconColorDimmed : mStyle.iconColor); + LOG(LogError) << "setColorShift() called. dimmed = \"" + << (isDimmed ? mStyle.iconColorDimmed : mStyle.iconColor) << "\""; icon->setResize(0, height); icons.push_back(icon); @@ -140,7 +147,8 @@ void HelpComponent::updateGrid() lblInput = Utils::String::toUpper(lblInput); } - auto lbl = std::make_shared(mWindow, lblInput, font, mStyle.textColor); + auto lbl = std::make_shared( + mWindow, lblInput, font, isDimmed ? mStyle.textColorDimmed : mStyle.textColor); labels.push_back(lbl); width +=