From 377d8c905ce5d5b3d9e7013091c6620e9667ab6a Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Tue, 31 Oct 2023 10:18:09 +0400 Subject: [PATCH 1/2] Fix TrueType fonts scaling --- apps/openmw/mwgui/formatting.cpp | 2 +- apps/openmw/mwgui/formatting.hpp | 2 +- apps/openmw/mwgui/spellview.cpp | 4 ++-- apps/openmw/mwgui/tooltips.cpp | 6 +++--- components/widgets/box.cpp | 6 +++--- components/widgets/box.hpp | 23 ++++++++++++++++++++--- components/widgets/fontwrapper.hpp | 24 ++++++++++++++++++++++++ components/widgets/numericeditbox.hpp | 4 +++- components/widgets/sharedstatebutton.hpp | 4 +++- components/widgets/widgets.cpp | 3 +++ 10 files changed, 63 insertions(+), 15 deletions(-) create mode 100644 components/widgets/fontwrapper.hpp diff --git a/apps/openmw/mwgui/formatting.cpp b/apps/openmw/mwgui/formatting.cpp index c4f0f804a65..7f62bbf49ce 100644 --- a/apps/openmw/mwgui/formatting.cpp +++ b/apps/openmw/mwgui/formatting.cpp @@ -475,7 +475,7 @@ namespace MWGui::Formatting : GraphicElement(parent, pag, blockStyle) , mTextStyle(textStyle) { - MyGUI::EditBox* box = parent->createWidget("NormalText", + Gui::EditBox* box = parent->createWidget("NormalText", MyGUI::IntCoord(0, pag.getCurrentTop(), pag.getPageWidth(), 0), MyGUI::Align::Left | MyGUI::Align::Top, parent->getName() + MyGUI::utility::toString(parent->getChildCount())); box->setEditStatic(true); diff --git a/apps/openmw/mwgui/formatting.hpp b/apps/openmw/mwgui/formatting.hpp index f093a36dfe5..9a215b200b5 100644 --- a/apps/openmw/mwgui/formatting.hpp +++ b/apps/openmw/mwgui/formatting.hpp @@ -161,7 +161,7 @@ namespace MWGui private: int currentFontHeight() const; TextStyle mTextStyle; - MyGUI::EditBox* mEditBox; + Gui::EditBox* mEditBox; }; class ImageElement : public GraphicElement diff --git a/apps/openmw/mwgui/spellview.cpp b/apps/openmw/mwgui/spellview.cpp index 97de7dbc065..678f6ffe1f0 100644 --- a/apps/openmw/mwgui/spellview.cpp +++ b/apps/openmw/mwgui/spellview.cpp @@ -238,7 +238,7 @@ namespace MWGui mLines.emplace_back(separator, (MyGUI::Widget*)nullptr, NoSpellIndex); } - MyGUI::TextBox* groupWidget = mScrollView->createWidget("SandBrightText", + MyGUI::TextBox* groupWidget = mScrollView->createWidget("SandBrightText", MyGUI::IntCoord(0, 0, mScrollView->getWidth(), 24), MyGUI::Align::Left | MyGUI::Align::Top); groupWidget->setCaptionWithReplacing(label); groupWidget->setTextAlign(MyGUI::Align::Left); @@ -246,7 +246,7 @@ namespace MWGui if (!label2.empty()) { - MyGUI::TextBox* groupWidget2 = mScrollView->createWidget("SandBrightText", + MyGUI::TextBox* groupWidget2 = mScrollView->createWidget("SandBrightText", MyGUI::IntCoord(0, 0, mScrollView->getWidth(), 24), MyGUI::Align::Left | MyGUI::Align::Top); groupWidget2->setCaptionWithReplacing(label2); groupWidget2->setTextAlign(MyGUI::Align::Right); diff --git a/apps/openmw/mwgui/tooltips.cpp b/apps/openmw/mwgui/tooltips.cpp index 929d78f3b13..323579317a0 100644 --- a/apps/openmw/mwgui/tooltips.cpp +++ b/apps/openmw/mwgui/tooltips.cpp @@ -443,7 +443,7 @@ namespace MWGui const std::string realImage = Misc::ResourceHelpers::correctIconPath(image, MWBase::Environment::get().getResourceSystem()->getVFS()); - MyGUI::EditBox* captionWidget = mDynamicToolTipBox->createWidget( + Gui::EditBox* captionWidget = mDynamicToolTipBox->createWidget( "NormalText", MyGUI::IntCoord(0, 0, 300, 300), MyGUI::Align::Left | MyGUI::Align::Top, "ToolTipCaption"); captionWidget->setEditStatic(true); captionWidget->setNeedKeyFocus(false); @@ -452,7 +452,7 @@ namespace MWGui int captionHeight = std::max(!caption.empty() ? captionSize.height : 0, imageSize); - MyGUI::EditBox* textWidget = mDynamicToolTipBox->createWidget("SandText", + Gui::EditBox* textWidget = mDynamicToolTipBox->createWidget("SandText", MyGUI::IntCoord(0, captionHeight + imageCaptionVPadding, 300, 300 - captionHeight - imageCaptionVPadding), MyGUI::Align::Stretch, "ToolTipText"); textWidget->setEditStatic(true); @@ -474,7 +474,7 @@ namespace MWGui MyGUI::ImageBox* icon = mDynamicToolTipBox->createWidget("MarkerButton", MyGUI::IntCoord(padding.left, totalSize.height + padding.top, 8, 8), MyGUI::Align::Default); icon->setColour(MyGUI::Colour(1.0f, 0.3f, 0.3f)); - MyGUI::EditBox* edit = mDynamicToolTipBox->createWidget("SandText", + Gui::EditBox* edit = mDynamicToolTipBox->createWidget("SandText", MyGUI::IntCoord(padding.left + 8 + 4, totalSize.height + padding.top, 300 - padding.left - 8 - 4, 300 - totalSize.height), MyGUI::Align::Default); diff --git a/components/widgets/box.cpp b/components/widgets/box.cpp index 89f92b7bf1f..d7119256564 100644 --- a/components/widgets/box.cpp +++ b/components/widgets/box.cpp @@ -48,7 +48,7 @@ namespace Gui } else { - TextBox::setPropertyOverride(_key, _value); + Gui::TextBox::setPropertyOverride(_key, _value); } } @@ -115,7 +115,7 @@ namespace Gui } else { - EditBox::setPropertyOverride(_key, _value); + Gui::EditBox::setPropertyOverride(_key, _value); } } @@ -144,7 +144,7 @@ namespace Gui } else { - Button::setPropertyOverride(_key, _value); + Gui::Button::setPropertyOverride(_key, _value); } } diff --git a/components/widgets/box.hpp b/components/widgets/box.hpp index b7543f1f056..83cbddb3b08 100644 --- a/components/widgets/box.hpp +++ b/components/widgets/box.hpp @@ -7,8 +7,25 @@ #include #include +#include "fontwrapper.hpp" + namespace Gui { + class Button : public FontWrapper + { + MYGUI_RTTI_DERIVED(Button) + }; + + class TextBox : public FontWrapper + { + MYGUI_RTTI_DERIVED(TextBox) + }; + + class EditBox : public FontWrapper + { + MYGUI_RTTI_DERIVED(EditBox) + }; + class AutoSizedWidget { public: @@ -27,7 +44,7 @@ namespace Gui MyGUI::Align mExpandDirection; }; - class AutoSizedTextBox : public AutoSizedWidget, public MyGUI::TextBox + class AutoSizedTextBox : public AutoSizedWidget, public TextBox { MYGUI_RTTI_DERIVED(AutoSizedTextBox) @@ -40,7 +57,7 @@ namespace Gui std::string mFontSize; }; - class AutoSizedEditBox : public AutoSizedWidget, public MyGUI::EditBox + class AutoSizedEditBox : public AutoSizedWidget, public EditBox { MYGUI_RTTI_DERIVED(AutoSizedEditBox) @@ -59,7 +76,7 @@ namespace Gui int mMaxWidth = 0; }; - class AutoSizedButton : public AutoSizedWidget, public MyGUI::Button + class AutoSizedButton : public AutoSizedWidget, public Button { MYGUI_RTTI_DERIVED(AutoSizedButton) diff --git a/components/widgets/fontwrapper.hpp b/components/widgets/fontwrapper.hpp new file mode 100644 index 00000000000..f6a57923a9b --- /dev/null +++ b/components/widgets/fontwrapper.hpp @@ -0,0 +1,24 @@ +#ifndef OPENMW_WIDGETS_WRAPPER_H +#define OPENMW_WIDGETS_WRAPPER_H + +#include + +#include "components/settings/values.hpp" + +#include + +namespace Gui +{ + template + class FontWrapper : public T + { + public: + void setFontName(std::string_view name) override + { + T::setFontName(name); + T::setPropertyOverride("FontHeight", std::to_string(Settings::gui().mFontSize)); + } + }; +} + +#endif diff --git a/components/widgets/numericeditbox.hpp b/components/widgets/numericeditbox.hpp index 39605b67d9b..ee8ef39a594 100644 --- a/components/widgets/numericeditbox.hpp +++ b/components/widgets/numericeditbox.hpp @@ -3,13 +3,15 @@ #include +#include "fontwrapper.hpp" + namespace Gui { /** * @brief A variant of the EditBox that only allows integer inputs */ - class NumericEditBox final : public MyGUI::EditBox + class NumericEditBox final : public FontWrapper { MYGUI_RTTI_DERIVED(NumericEditBox) diff --git a/components/widgets/sharedstatebutton.hpp b/components/widgets/sharedstatebutton.hpp index 99f597360c4..688d949f6ea 100644 --- a/components/widgets/sharedstatebutton.hpp +++ b/components/widgets/sharedstatebutton.hpp @@ -3,6 +3,8 @@ #include +#include "fontwrapper.hpp" + namespace Gui { @@ -12,7 +14,7 @@ namespace Gui /// @brief A button that applies its own state changes to other widgets, to do this you define it as part of a /// ButtonGroup. - class SharedStateButton final : public MyGUI::Button + class SharedStateButton final : public FontWrapper { MYGUI_RTTI_DERIVED(SharedStateButton) diff --git a/components/widgets/widgets.cpp b/components/widgets/widgets.cpp index 097f84c62f9..d27d7e5fc95 100644 --- a/components/widgets/widgets.cpp +++ b/components/widgets/widgets.cpp @@ -18,9 +18,12 @@ namespace Gui MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); + MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); MyGUI::FactoryManager::getInstance().registerFactory("Widget"); From 960d9032171e94c75fc4bb9ab88b9f9d04a304a4 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Wed, 1 Nov 2023 11:49:13 +0400 Subject: [PATCH 2/2] Add comment --- components/widgets/fontwrapper.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/widgets/fontwrapper.hpp b/components/widgets/fontwrapper.hpp index f6a57923a9b..813d323f990 100644 --- a/components/widgets/fontwrapper.hpp +++ b/components/widgets/fontwrapper.hpp @@ -5,10 +5,11 @@ #include "components/settings/values.hpp" -#include +#include namespace Gui { + /// Wrapper to tell UI element to use font size from settings.cfg template class FontWrapper : public T {