From b697dc2a52c44f69f113f337adb8b07a770c097c Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 11 Aug 2024 18:14:39 +0200 Subject: [PATCH] Reverted ButtonComponent and SliderComponent to render the debug overlays themselves --- es-core/src/components/ButtonComponent.cpp | 8 ++++++++ es-core/src/components/SliderComponent.cpp | 22 ++++++++++++++++------ es-core/src/components/SliderComponent.h | 1 + es-core/src/components/TextComponent.cpp | 9 ++++++--- es-core/src/components/TextComponent.h | 4 +++- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/es-core/src/components/ButtonComponent.cpp b/es-core/src/components/ButtonComponent.cpp index 3b8451bf5..6e9f9f9d2 100644 --- a/es-core/src/components/ButtonComponent.cpp +++ b/es-core/src/components/ButtonComponent.cpp @@ -140,6 +140,14 @@ void ButtonComponent::render(const glm::mat4& parentTrans) (mSize.y - mButtonText->getSize().y) / 2.0f, 0.0f}; trans = glm::translate(trans, glm::round(centerOffset)); + if (Settings::getInstance()->getBool("DebugText")) { + mButtonText->setDebugRendering(false); + mRenderer->drawRect(centerOffset.x, 0.0f, mButtonText->getSize().x, mSize.y, 0x00000033, + 0x00000033); + mRenderer->drawRect(mBox.getPosition().x, 0.0f, mBox.getSize().x, mSize.y, 0x0000FF33, + 0x0000FF33); + } + mButtonText->setColor(getCurTextColor()); mButtonText->render(trans); } diff --git a/es-core/src/components/SliderComponent.cpp b/es-core/src/components/SliderComponent.cpp index 57f5b3828..cacd7005f 100644 --- a/es-core/src/components/SliderComponent.cpp +++ b/es-core/src/components/SliderComponent.cpp @@ -24,6 +24,8 @@ SliderComponent::SliderComponent(float min, float max, float increment, const st , mBarLength {0.0f} , mBarHeight {0.0f} , mBarPosY {0.0f} + , mMoveAccumulator {0} + , mSliderTextSize {0.0f, 0.f} , mSuffix {suffix} { assert((min - max) != 0.0f); @@ -94,6 +96,16 @@ void SliderComponent::update(int deltaTime) void SliderComponent::render(const glm::mat4& parentTrans) { glm::mat4 trans {parentTrans * getTransform()}; + mRenderer->setMatrix(trans); + + if (Settings::getInstance()->getBool("DebugText")) { + mSliderText->setDebugRendering(false); + mRenderer->drawRect(mSize.x - mSliderTextSize.x, (mSize.y - mSliderTextSize.y) / 2.0f, + mSliderTextSize.x, mSliderTextSize.y, 0x0000FF33, 0x0000FF33); + mRenderer->drawRect(mSize.x - mSliderTextSize.x, 0.0f, mSliderTextSize.x, mSize.y, + 0x00000033, 0x00000033); + } + mSliderText->render(trans); mRenderer->setMatrix(trans); @@ -129,8 +141,6 @@ void SliderComponent::onSizeChanged() void SliderComponent::onValueChanged() { - glm::vec2 textSize {0.0f, 0.0f}; - { std::stringstream ss; ss << std::fixed; @@ -147,8 +157,8 @@ void SliderComponent::onValueChanged() ss << mSuffix; mSliderText->setText(val); - textSize = mSliderText->getFont()->sizeText(ss.str()); - mSliderText->setPosition(mSize.x - textSize.x, (mSize.y - textSize.y) / 2.0f); + mSliderTextSize = mSliderText->getFont()->sizeText(ss.str()); + mSliderText->setPosition(mSize.x - mSliderTextSize.x, (mSize.y - mSliderTextSize.y) / 2.0f); } mKnob.setResize(0.0f, std::round(mSize.y * 0.7f)); @@ -168,8 +178,8 @@ void SliderComponent::onValueChanged() setSize(getSize().x, getSize().y - 1.0f); } - mBarLength = - mSize.x - mKnob.getSize().x - (textSize.x + (4.0f * mRenderer->getScreenWidthModifier())); + mBarLength = mSize.x - mKnob.getSize().x - + (mSliderTextSize.x + (4.0f * mRenderer->getScreenWidthModifier())); if (static_cast(mSize.y) % 2 != static_cast(mBarHeight) % 2) { if (mBarHeight > 1.0f && mSize.y / mBarHeight < 5.0f) diff --git a/es-core/src/components/SliderComponent.h b/es-core/src/components/SliderComponent.h index cc8a95135..feabea06d 100644 --- a/es-core/src/components/SliderComponent.h +++ b/es-core/src/components/SliderComponent.h @@ -56,6 +56,7 @@ private: float mBarHeight; float mBarPosY; int mMoveAccumulator; + glm::vec2 mSliderTextSize; ImageComponent mKnob; ImageComponent mKnobDisabled; diff --git a/es-core/src/components/TextComponent.cpp b/es-core/src/components/TextComponent.cpp index 9f87ead88..edc006554 100644 --- a/es-core/src/components/TextComponent.cpp +++ b/es-core/src/components/TextComponent.cpp @@ -38,6 +38,7 @@ TextComponent::TextComponent() , mSelectable {false} , mVerticalAutoSizing {false} , mHorizontalScrolling {false} + , mDebugRendering {true} , mScrollSpeed {0.0f} , mScrollSpeedMultiplier {1.0f} , mScrollDelay {1500.0f} @@ -85,6 +86,7 @@ TextComponent::TextComponent(const std::string& text, , mSelectable {false} , mVerticalAutoSizing {false} , mHorizontalScrolling {horizontalScrolling} + , mDebugRendering {true} , mScrollSpeed {0.0f} , mScrollSpeedMultiplier {scrollSpeedMultiplier} , mScrollDelay {scrollDelay} @@ -300,8 +302,9 @@ void TextComponent::render(const glm::mat4& parentTrans) } // Draw the overall textbox area. If we're inside a vertical scrollable container then - // this area is rendered inside that component instead of here. - if (!secondPass && Settings::getInstance()->getBool("DebugText")) { + // this area is rendered inside that component instead of here. Some other components + // also disable rendering here in a similar fashion. + if (mDebugRendering && !secondPass && Settings::getInstance()->getBool("DebugText")) { if (!mParent || !mParent->isScrollable()) mRenderer->drawRect(0.0f, 0.0f, mSize.x, mSize.y, 0x0000FF33, 0x0000FF33); } @@ -309,7 +312,7 @@ void TextComponent::render(const glm::mat4& parentTrans) trans = glm::translate(trans, glm::vec3 {0.0f, std::round(yOff), 0.0f}); mRenderer->setMatrix(trans); - if (Settings::getInstance()->getBool("DebugText")) { + if (mDebugRendering && Settings::getInstance()->getBool("DebugText")) { const float relativeScaleOffset {(mSize.x - (mSize.x * mRelativeScale)) / 2.0f}; if (mHorizontalScrolling && !secondPass) { if (mScrollOffset1 <= mTextCache->metrics.size.x) { diff --git a/es-core/src/components/TextComponent.h b/es-core/src/components/TextComponent.h index a056eea04..bcc4dc732 100644 --- a/es-core/src/components/TextComponent.h +++ b/es-core/src/components/TextComponent.h @@ -54,6 +54,8 @@ public: void setRenderBackground(bool render) { mRenderBackground = render; } void setBackgroundMargins(const glm::vec2 margins) { mBackgroundMargins = margins; } void setBackgroundCornerRadius(const float radius) { mBackgroundCornerRadius = radius; } + // Used by some components that render the debug overlay themselves. + void setDebugRendering(bool state) { mDebugRendering = state; } void render(const glm::mat4& parentTrans) override; void onFocusLost() override { resetComponent(); } @@ -177,8 +179,8 @@ private: bool mNoTopMargin; bool mSelectable; bool mVerticalAutoSizing; - bool mHorizontalScrolling; + bool mDebugRendering; float mScrollSpeed; float mScrollSpeedMultiplier; float mScrollDelay;