From 487a842f36620202871ac76d0548830bc45e1dcf Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 24 Nov 2024 14:42:55 +0100 Subject: [PATCH] Added a 'textBackgroundCornerRadius' property to the grid element Also made the 'backgroundCornerRadius' and 'selectorCornerRadius' properties apply to colored rectangles --- es-core/src/ThemeData.cpp | 1 + .../src/components/primary/GridComponent.h | 43 ++++++++++++++++--- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 1c3fc752b..4c19927e9 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -251,6 +251,7 @@ std::map> {"selectorGradientType", STRING}, {"text", STRING}, {"textRelativeScale", FLOAT}, + {"textBackgroundCornerRadius", FLOAT}, {"textColor", COLOR}, {"textBackgroundColor", COLOR}, {"textSelectedColor", COLOR}, diff --git a/es-core/src/components/primary/GridComponent.h b/es-core/src/components/primary/GridComponent.h index 16a83b6a3..604581e7d 100644 --- a/es-core/src/components/primary/GridComponent.h +++ b/es-core/src/components/primary/GridComponent.h @@ -177,6 +177,7 @@ private: std::unique_ptr mBackgroundImage; std::string mBackgroundImagePath; float mBackgroundRelativeScale; + float mBackgroundCornerRadius; unsigned int mBackgroundColor; unsigned int mBackgroundColorEnd; bool mBackgroundColorGradientHorizontal; @@ -185,11 +186,13 @@ private: std::string mSelectorImagePath; float mSelectorRelativeScale; SelectorLayer mSelectorLayer; + float mSelectorCornerRadius; unsigned int mSelectorColor; unsigned int mSelectorColorEnd; bool mSelectorColorGradientHorizontal; bool mHasSelectorColor; float mTextRelativeScale; + float mTextBackgroundCornerRadius; unsigned int mTextColor; unsigned int mTextBackgroundColor; unsigned int mTextSelectedColor; @@ -254,17 +257,20 @@ GridComponent::GridComponent() , mImageBrightness {0.0f} , mImageSaturation {1.0f} , mBackgroundRelativeScale {1.0f} + , mBackgroundCornerRadius {0.0f} , mBackgroundColor {0xFFFFFFFF} , mBackgroundColorEnd {0xFFFFFFFF} , mBackgroundColorGradientHorizontal {true} , mHasBackgroundColor {false} , mSelectorRelativeScale {1.0f} , mSelectorLayer {SelectorLayer::TOP} + , mSelectorCornerRadius {0.0f} , mSelectorColor {0xFFFFFFFF} , mSelectorColorEnd {0xFFFFFFFF} , mSelectorColorGradientHorizontal {true} , mHasSelectorColor {false} , mTextRelativeScale {1.0f} + , mTextBackgroundCornerRadius {0.0f} , mTextColor {0x000000FF} , mTextBackgroundColor {0xFFFFFF00} , mTextSelectedColor {0x000000FF} @@ -385,6 +391,7 @@ void GridComponent::addEntry(Entry& entry, const std::shared_ptr& 0x00000000, mLineSpacing, 1.0f, mTextHorizontalScrolling, mTextHorizontalScrollSpeed, mTextHorizontalScrollDelay, mTextHorizontalScrollGap); text->setOrigin(0.5f, 0.5f); + text->setBackgroundCornerRadius(mTextBackgroundCornerRadius); text->setColor(mTextColor); text->setBackgroundColor(mTextBackgroundColor); text->setRenderBackground(true); @@ -777,7 +784,9 @@ template void GridComponent::render(const glm::mat4& parentTrans glm::translate(trans, glm::round(glm::vec3 {position.x, position.y, 0.0f}))}; mRenderer->setMatrix(drawTrans); mRenderer->drawRect(0.0f, 0.0f, sizeX, sizeY, mSelectorColor, mSelectorColorEnd, - mSelectorColorGradientHorizontal, opacity); + mSelectorColorGradientHorizontal, opacity, 1.0f, + Renderer::BlendFactor::SRC_ALPHA, + Renderer::BlendFactor::ONE_MINUS_SRC_ALPHA, mSelectorCornerRadius); } }; @@ -887,9 +896,13 @@ template void GridComponent::render(const glm::mat4& parentTrans // If a background color is set but no background image, then render a rectangle. const float sizeX {mItemSize.x * scale * mBackgroundRelativeScale}; const float sizeY {mItemSize.y * scale * mBackgroundRelativeScale}; - mRenderer->setMatrix(trans); - mRenderer->drawRect(backgroundPos.x, backgroundPos.y, sizeX, sizeY, mBackgroundColor, - mBackgroundColorEnd, mBackgroundColorGradientHorizontal, opacity); + const glm::mat4 drawTrans {glm::translate( + trans, glm::round(glm::vec3 {backgroundPos.x, backgroundPos.y, 0.0f}))}; + mRenderer->setMatrix(drawTrans); + mRenderer->drawRect( + 0.0f, 0.0f, sizeX, sizeY, mBackgroundColor, mBackgroundColorEnd, + mBackgroundColorGradientHorizontal, opacity, 1.0f, Renderer::BlendFactor::SRC_ALPHA, + Renderer::BlendFactor::ONE_MINUS_SRC_ALPHA, mBackgroundCornerRadius); } if (cursorEntry && mSelectorLayer == SelectorLayer::MIDDLE) @@ -1162,10 +1175,11 @@ void GridComponent::applyTheme(const std::shared_ptr& theme, } } float backgroundCornerRadius {0.0f}; - if (elem->has("backgroundCornerRadius")) + if (elem->has("backgroundCornerRadius")) { backgroundCornerRadius = glm::clamp(elem->get("backgroundCornerRadius"), 0.0f, 0.5f) * (mItemScale >= 1.0f ? mItemScale : 1.0f) * mRenderer->getScreenWidth(); + } mBackgroundImage->setCornerRadius(backgroundCornerRadius); mBackgroundImage->setImage(elem->get("backgroundImage")); mBackgroundImagePath = path; @@ -1176,6 +1190,11 @@ void GridComponent::applyTheme(const std::shared_ptr& theme, << element.substr(5) << "\", image does not exist: \"" << path << "\""; } } + else if (elem->has("backgroundCornerRadius")) { + mBackgroundCornerRadius = + glm::clamp(elem->get("backgroundCornerRadius"), 0.0f, 0.5f) * + (mItemScale >= 1.0f ? mItemScale : 1.0f) * mRenderer->getScreenWidth(); + } if (elem->has("selectorImage")) { const std::string& path {elem->get("selectorImage")}; @@ -1194,10 +1213,11 @@ void GridComponent::applyTheme(const std::shared_ptr& theme, } } float selectorCornerRadius {0.0f}; - if (elem->has("selectorCornerRadius")) + if (elem->has("selectorCornerRadius")) { selectorCornerRadius = glm::clamp(elem->get("selectorCornerRadius"), 0.0f, 0.5f) * (mItemScale >= 1.0f ? mItemScale : 1.0f) * mRenderer->getScreenWidth(); + } mSelectorImage->setCornerRadius(selectorCornerRadius); mSelectorImage->setImage(elem->get("selectorImage")); mSelectorImagePath = path; @@ -1208,6 +1228,11 @@ void GridComponent::applyTheme(const std::shared_ptr& theme, << element.substr(5) << "\", image does not exist: \"" << path << "\""; } } + else if (elem->has("selectorCornerRadius")) { + mSelectorCornerRadius = glm::clamp(elem->get("selectorCornerRadius"), 0.0f, 0.5f) * + (mItemScale >= 1.0f ? mItemScale : 1.0f) * + mRenderer->getScreenWidth(); + } if (elem->has("selectorLayer")) { const std::string& selectorLayer {elem->get("selectorLayer")}; @@ -1367,6 +1392,12 @@ void GridComponent::applyTheme(const std::shared_ptr& theme, if (elem->has("textRelativeScale")) mTextRelativeScale = glm::clamp(elem->get("textRelativeScale"), 0.2f, 1.0f); + if (elem->has("textBackgroundCornerRadius")) { + mTextBackgroundCornerRadius = + glm::clamp(elem->get("textBackgroundCornerRadius"), 0.0f, 0.5f) * + (mItemScale >= 1.0f ? mItemScale : 1.0f) * mRenderer->getScreenWidth(); + } + if (elem->has("textColor")) mTextColor = elem->get("textColor"); if (elem->has("textBackgroundColor"))