diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-07-10 13:44:10 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2025-07-15 11:40:25 +0200 |
commit | f83b1d648fc6ec2c64fd2c3483fede23c973c20f (patch) | |
tree | 04dd7950cbea1331870190d1caf9061011dfca05 /src/gui/widgets | |
parent | 32bcf41f01d4ed4a3a08030095611e75d6186d60 (diff) | |
download | mana-master.tar.gz mana-master.tar.bz2 mana-master.tar.xz mana-master.zip |
Rather than rendering the same texture 4 additional times, render a
specific outline version of the text. While reducing the number of times
the text is drawn, it does increase font texture use.
Result is a generally prettier outline due to rendering it properly at
sharp corners of the characters. The shadow for outlined text is now
also thicker, as appropriate.
As part of this change, the `TextRenderer` class was merged into the
`Graphics` and `TrueTypeFont` classes. There seemed to be little point
in having a separate function for this, apart from needing more static
casts to `Graphics*`.
Also fixed an issue where the font style was not being restored after
adjusting the font scale, when using an older SDL_ttf than 2.0.18.
Closes #87
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/browserbox.cpp | 22 | ||||
-rw-r--r-- | src/gui/widgets/button.cpp | 20 | ||||
-rw-r--r-- | src/gui/widgets/checkbox.cpp | 18 | ||||
-rw-r--r-- | src/gui/widgets/label.cpp | 24 | ||||
-rw-r--r-- | src/gui/widgets/radiobutton.cpp | 20 | ||||
-rw-r--r-- | src/gui/widgets/textbox.cpp | 24 | ||||
-rw-r--r-- | src/gui/widgets/textpreview.cpp | 21 | ||||
-rw-r--r-- | src/gui/widgets/window.cpp | 14 |
8 files changed, 75 insertions, 88 deletions
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 1deea30b..bf337a0f 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -23,7 +23,6 @@ #include "gui/widgets/browserbox.h" #include "keyboardconfig.h" -#include "textrenderer.h" #include "gui/gui.h" #include "gui/truetypefont.h" @@ -292,6 +291,8 @@ void BrowserBox::draw(gcn::Graphics *graphics) } } + auto g = static_cast<Graphics*>(graphics); + for (const auto &row : mTextRows) { for (const auto &part : row.parts) @@ -301,16 +302,15 @@ void BrowserBox::draw(gcn::Graphics *graphics) if (part.y > yEnd) return; - TextRenderer::renderText(graphics, - part.text, - part.x, - part.y, - Graphics::LEFT, - part.color, - part.font, - part.outlineColor.has_value() || mOutline, - mShadows, - part.outlineColor); + g->drawText(part.text, + part.x, + part.y, + Graphics::LEFT, + part.color, + part.font, + part.outlineColor.has_value() || mOutline, + mShadows, + part.outlineColor); } } } diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index 31c3a677..604f5dc8 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -28,7 +28,6 @@ #include "resources/image.h" #include "resources/theme.h" -#include "textrenderer.h" #include <guichan/exception.hpp> #include <guichan/font.hpp> @@ -132,8 +131,9 @@ void Button::draw(gcn::Graphics *graphics) if (isPressed()) widgetState.flags |= STATE_SELECTED; + auto g = static_cast<Graphics *>(graphics); auto &skin = gui->getTheme()->getSkin(SkinType::Button); - skin.draw(static_cast<Graphics *>(graphics), widgetState); + skin.draw(g, widgetState); auto skinState = skin.getState(widgetState.flags); auto font = (skinState && skinState->textFormat.bold) ? boldFont : getFont(); @@ -196,18 +196,16 @@ void Button::draw(gcn::Graphics *graphics) } if (btnIconWidth) - static_cast<Graphics *>(graphics)->drawImage(icon, btnIconX, btnIconY); + g->drawImage(icon, btnIconX, btnIconY); if (auto skinState = skin.getState(widgetState.flags)) { - auto &textFormat = skinState->textFormat; - TextRenderer::renderText(static_cast<Graphics *>(graphics), - getCaption(), - textX, - textY, - getAlignment(), - font, - textFormat); + g->drawText(getCaption(), + textX, + textY, + getAlignment(), + font, + skinState->textFormat); } } diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp index e6079f2f..4bb0bb72 100644 --- a/src/gui/widgets/checkbox.cpp +++ b/src/gui/widgets/checkbox.cpp @@ -21,8 +21,6 @@ #include "gui/widgets/checkbox.h" -#include "textrenderer.h" - #include "gui/gui.h" #include "resources/theme.h" @@ -44,19 +42,19 @@ void CheckBox::draw(gcn::Graphics* graphics) if (isSelected()) widgetState.flags |= STATE_SELECTED; + auto g = static_cast<Graphics *>(graphics); auto &skin = gui->getTheme()->getSkin(SkinType::CheckBox); - skin.draw(static_cast<Graphics *>(graphics), widgetState); + skin.draw(g, widgetState); if (auto skinState = skin.getState(widgetState.flags)) { auto &textFormat = skinState->textFormat; - TextRenderer::renderText(static_cast<Graphics *>(graphics), - getCaption(), - skin.getMinWidth() + skin.padding + skin.spacing, - skin.padding, - Graphics::LEFT, - textFormat.bold ? boldFont : getFont(), - textFormat); + g->drawText(getCaption(), + skin.getMinWidth() + skin.padding + skin.spacing, + skin.padding, + Graphics::LEFT, + textFormat.bold ? boldFont : getFont(), + textFormat); } } diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp index a2ed8820..9c0fd3cd 100644 --- a/src/gui/widgets/label.cpp +++ b/src/gui/widgets/label.cpp @@ -21,8 +21,6 @@ #include "gui/widgets/label.h" -#include "textrenderer.h" - #include "resources/theme.h" #include <guichan/exception.hpp> @@ -59,15 +57,15 @@ void Label::draw(gcn::Graphics *graphics) throw GCN_EXCEPTION("Unknown alignment."); } - TextRenderer::renderText(static_cast<Graphics *>(graphics), - getCaption(), - textX, - textY, - getAlignment(), - getForegroundColor(), - getFont(), - mOutlineColor.has_value(), - mShadowColor.has_value(), - mOutlineColor, - mShadowColor); + auto g = static_cast<Graphics *>(graphics); + g->drawText(getCaption(), + textX, + textY, + getAlignment(), + getForegroundColor(), + getFont(), + mOutlineColor.has_value(), + mShadowColor.has_value(), + mOutlineColor, + mShadowColor); } diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp index ceba78eb..3474bbd8 100644 --- a/src/gui/widgets/radiobutton.cpp +++ b/src/gui/widgets/radiobutton.cpp @@ -21,11 +21,11 @@ #include "gui/widgets/radiobutton.h" -#include "textrenderer.h" - #include "gui/gui.h" #include "resources/theme.h" +#include <guichan/font.hpp> + RadioButton::RadioButton(const std::string &caption, const std::string &group, bool marked) @@ -44,19 +44,19 @@ void RadioButton::draw(gcn::Graphics* graphics) if (isSelected()) widgetState.flags |= STATE_SELECTED; + auto g = static_cast<Graphics *>(graphics); auto &skin = gui->getTheme()->getSkin(SkinType::RadioButton); - skin.draw(static_cast<Graphics *>(graphics), widgetState); + skin.draw(g, widgetState); if (auto skinState = skin.getState(widgetState.flags)) { auto &textFormat = skinState->textFormat; - TextRenderer::renderText(static_cast<Graphics *>(graphics), - getCaption(), - skin.getMinWidth() + skin.padding + skin.spacing, - skin.padding, - Graphics::LEFT, - textFormat.bold ? boldFont : getFont(), - textFormat); + g->drawText(getCaption(), + skin.getMinWidth() + skin.padding + skin.spacing, + skin.padding, + Graphics::LEFT, + textFormat.bold ? boldFont : getFont(), + textFormat); } } diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp index 6cc514fe..7fd7d626 100644 --- a/src/gui/widgets/textbox.cpp +++ b/src/gui/widgets/textbox.cpp @@ -23,7 +23,6 @@ #include "gui/gui.h" #include "resources/theme.h" -#include "textrenderer.h" #include <guichan/font.hpp> @@ -96,7 +95,7 @@ void TextBox::setTextWrapped(const std::string &text, int minDimension) xpos = width; wrappedStream << word; } - else if (xpos != 0 && xpos + getFont()->getWidth(" ") + width <= + else if (xpos != 0 && xpos + getFont()->getWidth(" ") + width <= mMinWidth) { xpos += getFont()->getWidth(" ") + width; @@ -176,18 +175,19 @@ void TextBox::draw(gcn::Graphics *graphics) graphics->setColor(*mTextColor); graphics->setFont(getFont()); + auto g = static_cast<Graphics*>(graphics); + for (i = 0; i < mTextRows.size(); i++) { // Move the text one pixel so we can have a caret before a letter. - TextRenderer::renderText(graphics, - mTextRows[i], - 1, - i * getFont()->getHeight(), - gcn::Graphics::LEFT, - *mTextColor, - getFont(), - mOutlineColor.has_value(), - false, - mOutlineColor); + g->drawText(mTextRows[i], + 1, + i * getFont()->getHeight(), + gcn::Graphics::LEFT, + *mTextColor, + getFont(), + mOutlineColor.has_value(), + false, + mOutlineColor); } } diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp index 2f80bd23..aed04853 100644 --- a/src/gui/widgets/textpreview.cpp +++ b/src/gui/widgets/textpreview.cpp @@ -21,13 +21,7 @@ #include "gui/widgets/textpreview.h" -#include "configuration.h" -#include "textrenderer.h" - #include "gui/gui.h" -#include "gui/truetypefont.h" - -#include <typeinfo> TextPreview::TextPreview(const std::string &text) : mText(text) @@ -36,12 +30,13 @@ TextPreview::TextPreview(const std::string &text) mTextColor = &Theme::getThemeColor(Theme::TEXT); } -void TextPreview::draw(gcn::Graphics* graphics) +void TextPreview::draw(gcn::Graphics *graphics) { - TextRenderer::renderText(graphics, mText, 2, 2, gcn::Graphics::LEFT, - gcn::Color(mTextColor->r, - mTextColor->g, - mTextColor->b, - 255), - mFont, mOutline, mShadow); + auto g = static_cast<Graphics*>(graphics); + g->drawText(mText, 2, 2, gcn::Graphics::LEFT, + gcn::Color(mTextColor->r, + mTextColor->g, + mTextColor->b, + 255), + mFont, mOutline, mShadow); } diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index bf496bd8..14d91af1 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -23,7 +23,6 @@ #include "configuration.h" #include "log.h" -#include "textrenderer.h" #include "gui/gui.h" #include "gui/viewport.h" @@ -139,13 +138,12 @@ void Window::drawFrame(gcn::Graphics *graphics) if (auto skinState = skin.getState(widgetState.flags)) { auto &textFormat = skinState->textFormat; - TextRenderer::renderText(g, - getCaption(), - getFrameSize() + skin.titleOffsetX, - getFrameSize() + skin.titleOffsetY, - gcn::Graphics::LEFT, - textFormat.bold ? boldFont : getFont(), - textFormat); + g->drawText(getCaption(), + getFrameSize() + skin.titleOffsetX, + getFrameSize() + skin.titleOffsetY, + gcn::Graphics::LEFT, + textFormat.bold ? boldFont : getFont(), + textFormat); } } } |