Skip to content

Commit

Permalink
Merge branch 'font_fix' into 'master'
Browse files Browse the repository at this point in the history
Fix TrueType fonts scaling

See merge request OpenMW/openmw!3541
  • Loading branch information
Capostrophic committed Nov 2, 2023
2 parents 8a8d77a + 960d903 commit 4445a55
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 15 deletions.
2 changes: 1 addition & 1 deletion apps/openmw/mwgui/formatting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ namespace MWGui::Formatting
: GraphicElement(parent, pag, blockStyle)
, mTextStyle(textStyle)
{
MyGUI::EditBox* box = parent->createWidget<MyGUI::EditBox>("NormalText",
Gui::EditBox* box = parent->createWidget<Gui::EditBox>("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);
Expand Down
2 changes: 1 addition & 1 deletion apps/openmw/mwgui/formatting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ namespace MWGui
private:
int currentFontHeight() const;
TextStyle mTextStyle;
MyGUI::EditBox* mEditBox;
Gui::EditBox* mEditBox;
};

class ImageElement : public GraphicElement
Expand Down
4 changes: 2 additions & 2 deletions apps/openmw/mwgui/spellview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,15 @@ namespace MWGui
mLines.emplace_back(separator, (MyGUI::Widget*)nullptr, NoSpellIndex);
}

MyGUI::TextBox* groupWidget = mScrollView->createWidget<MyGUI::TextBox>("SandBrightText",
MyGUI::TextBox* groupWidget = mScrollView->createWidget<Gui::TextBox>("SandBrightText",
MyGUI::IntCoord(0, 0, mScrollView->getWidth(), 24), MyGUI::Align::Left | MyGUI::Align::Top);
groupWidget->setCaptionWithReplacing(label);
groupWidget->setTextAlign(MyGUI::Align::Left);
groupWidget->setNeedMouseFocus(false);

if (!label2.empty())
{
MyGUI::TextBox* groupWidget2 = mScrollView->createWidget<MyGUI::TextBox>("SandBrightText",
MyGUI::TextBox* groupWidget2 = mScrollView->createWidget<Gui::TextBox>("SandBrightText",
MyGUI::IntCoord(0, 0, mScrollView->getWidth(), 24), MyGUI::Align::Left | MyGUI::Align::Top);
groupWidget2->setCaptionWithReplacing(label2);
groupWidget2->setTextAlign(MyGUI::Align::Right);
Expand Down
6 changes: 3 additions & 3 deletions apps/openmw/mwgui/tooltips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ namespace MWGui
const std::string realImage
= Misc::ResourceHelpers::correctIconPath(image, MWBase::Environment::get().getResourceSystem()->getVFS());

MyGUI::EditBox* captionWidget = mDynamicToolTipBox->createWidget<MyGUI::EditBox>(
Gui::EditBox* captionWidget = mDynamicToolTipBox->createWidget<Gui::EditBox>(
"NormalText", MyGUI::IntCoord(0, 0, 300, 300), MyGUI::Align::Left | MyGUI::Align::Top, "ToolTipCaption");
captionWidget->setEditStatic(true);
captionWidget->setNeedKeyFocus(false);
Expand All @@ -452,7 +452,7 @@ namespace MWGui

int captionHeight = std::max(!caption.empty() ? captionSize.height : 0, imageSize);

MyGUI::EditBox* textWidget = mDynamicToolTipBox->createWidget<MyGUI::EditBox>("SandText",
Gui::EditBox* textWidget = mDynamicToolTipBox->createWidget<Gui::EditBox>("SandText",
MyGUI::IntCoord(0, captionHeight + imageCaptionVPadding, 300, 300 - captionHeight - imageCaptionVPadding),
MyGUI::Align::Stretch, "ToolTipText");
textWidget->setEditStatic(true);
Expand All @@ -474,7 +474,7 @@ namespace MWGui
MyGUI::ImageBox* icon = mDynamicToolTipBox->createWidget<MyGUI::ImageBox>("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<MyGUI::EditBox>("SandText",
Gui::EditBox* edit = mDynamicToolTipBox->createWidget<Gui::EditBox>("SandText",
MyGUI::IntCoord(padding.left + 8 + 4, totalSize.height + padding.top, 300 - padding.left - 8 - 4,
300 - totalSize.height),
MyGUI::Align::Default);
Expand Down
6 changes: 3 additions & 3 deletions components/widgets/box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace Gui
}
else
{
TextBox::setPropertyOverride(_key, _value);
Gui::TextBox::setPropertyOverride(_key, _value);
}
}

Expand Down Expand Up @@ -115,7 +115,7 @@ namespace Gui
}
else
{
EditBox::setPropertyOverride(_key, _value);
Gui::EditBox::setPropertyOverride(_key, _value);
}
}

Expand Down Expand Up @@ -144,7 +144,7 @@ namespace Gui
}
else
{
Button::setPropertyOverride(_key, _value);
Gui::Button::setPropertyOverride(_key, _value);
}
}

Expand Down
23 changes: 20 additions & 3 deletions components/widgets/box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,25 @@
#include <MyGUI_TextBox.h>
#include <MyGUI_Widget.h>

#include "fontwrapper.hpp"

namespace Gui
{
class Button : public FontWrapper<MyGUI::Button>
{
MYGUI_RTTI_DERIVED(Button)
};

class TextBox : public FontWrapper<MyGUI::TextBox>
{
MYGUI_RTTI_DERIVED(TextBox)
};

class EditBox : public FontWrapper<MyGUI::EditBox>
{
MYGUI_RTTI_DERIVED(EditBox)
};

class AutoSizedWidget
{
public:
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down
25 changes: 25 additions & 0 deletions components/widgets/fontwrapper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef OPENMW_WIDGETS_WRAPPER_H
#define OPENMW_WIDGETS_WRAPPER_H

#include <MyGUI_Prerequest.h>

#include "components/settings/values.hpp"

#include <string>

namespace Gui
{
/// Wrapper to tell UI element to use font size from settings.cfg
template <class T>
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
4 changes: 3 additions & 1 deletion components/widgets/numericeditbox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

#include <MyGUI_EditBox.h>

#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::EditBox>
{
MYGUI_RTTI_DERIVED(NumericEditBox)

Expand Down
4 changes: 3 additions & 1 deletion components/widgets/sharedstatebutton.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <MyGUI_Button.h>

#include "fontwrapper.hpp"

namespace Gui
{

Expand All @@ -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::Button>
{
MYGUI_RTTI_DERIVED(SharedStateButton)

Expand Down
3 changes: 3 additions & 0 deletions components/widgets/widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ namespace Gui
MyGUI::FactoryManager::getInstance().registerFactory<Gui::HBox>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<Gui::Spacer>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<Gui::VBox>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<Gui::EditBox>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<Gui::TextBox>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<Gui::AutoSizedTextBox>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<Gui::AutoSizedEditBox>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<Gui::AutoSizedButton>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<Gui::Button>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<Gui::ImageButton>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<Gui::NumericEditBox>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<Gui::SharedStateButton>("Widget");
Expand Down

0 comments on commit 4445a55

Please sign in to comment.