Reverted ButtonComponent and SliderComponent to render the debug overlays themselves

This commit is contained in:
Leon Styhre 2024-08-11 18:14:39 +02:00
parent 8ee7b6f118
commit b697dc2a52
5 changed files with 34 additions and 10 deletions

View file

@ -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);
}

View file

@ -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<int>(mSize.y) % 2 != static_cast<int>(mBarHeight) % 2) {
if (mBarHeight > 1.0f && mSize.y / mBarHeight < 5.0f)

View file

@ -56,6 +56,7 @@ private:
float mBarHeight;
float mBarPosY;
int mMoveAccumulator;
glm::vec2 mSliderTextSize;
ImageComponent mKnob;
ImageComponent mKnobDisabled;

View file

@ -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) {

View file

@ -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;