Implement per-font resolution

crashfix_debugdraw
Andrei Kortunov 2 years ago
parent 945448cdf1
commit 3037f190be

@ -205,7 +205,6 @@ bool Launcher::AdvancedPage::loadSettings()
loadSettingBool(graphicHerbalismCheckBox, "graphic herbalism", "Game");
scalingSpinBox->setValue(Settings::Manager::getFloat("scaling factor", "GUI"));
fontSizeSpinBox->setValue(Settings::Manager::getInt("font size", "GUI"));
ttfResolutionSpinBox->setValue(Settings::Manager::getInt("ttf resolution", "GUI"));
}
// Bug fixes
@ -373,10 +372,6 @@ void Launcher::AdvancedPage::saveSettings()
int fontSize = fontSizeSpinBox->value();
if (fontSize != Settings::Manager::getInt("font size", "GUI"))
Settings::Manager::setInt("font size", "GUI", fontSize);
int ttfResolution = ttfResolutionSpinBox->value();
if (ttfResolution != Settings::Manager::getInt("ttf resolution", "GUI"))
Settings::Manager::setInt("ttf resolution", "GUI", ttfResolution);
}
// Bug fixes

@ -209,7 +209,6 @@ namespace MWGui
// Load fonts
mFontLoader = std::make_unique<Gui::FontLoader>(encoding, resourceSystem->getVFS(), mScalingFactor);
mFontLoader->loadFonts();
//Register own widgets with MyGUI
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSkill>("Widget");

@ -25,11 +25,52 @@
#include <components/misc/strings/algorithm.hpp>
#include <components/myguiplatform/myguitexture.hpp>
#include <components/myguiplatform/scalinglayer.hpp>
#include <components/settings/settings.hpp>
namespace
{
MyGUI::xml::ElementPtr getProperty(MyGUI::xml::ElementPtr resourceNode, const std::string propertyName)
{
MyGUI::xml::ElementPtr propertyNode = nullptr;
MyGUI::xml::ElementEnumerator propertyIterator = resourceNode->getElementEnumerator();
while (propertyIterator.next("Property"))
{
std::string key = propertyIterator->findAttribute("key");
if (key == propertyName)
{
propertyNode = propertyIterator.current();
break;
}
}
return propertyNode;
}
MyGUI::IntSize getBookSize(MyGUI::IDataStream* layersStream)
{
MyGUI::xml::Document xmlDocument;
xmlDocument.open(layersStream);
MyGUI::xml::ElementPtr root = xmlDocument.getRoot();
MyGUI::xml::ElementEnumerator layersIterator = root->getElementEnumerator();
while (layersIterator.next("Layer"))
{
std::string name = layersIterator->findAttribute("name");
if (name == "JournalBooks")
{
MyGUI::xml::ElementPtr sizeProperty = getProperty(layersIterator.current(), "Size");
const std::string& sizeValue = sizeProperty != nullptr ? sizeProperty->findAttribute("value") : std::string();
if (!sizeValue.empty())
return MyGUI::IntSize::parse(sizeValue);
}
}
return MyGUI::RenderManager::getInstance().getViewSize();
}
unsigned long utf8ToUnicode(std::string_view utf8)
{
if (utf8.empty())
@ -165,6 +206,8 @@ namespace Gui
MyGUI::ResourceManager::getInstance().unregisterLoadXmlDelegate("Resource");
MyGUI::ResourceManager::getInstance().registerLoadXmlDelegate("Resource") = MyGUI::newDelegate(this, &FontLoader::overrideLineHeight);
loadFonts();
}
void FontLoader::loadFonts()
@ -203,6 +246,11 @@ namespace Gui
return;
}
// TODO: it may be worth to take in account resolution change, but it is not safe to replace used assets
std::unique_ptr<MyGUI::IDataStream> layersStream(dataManager->getData("openmw_layers.xml"));
MyGUI::IntSize bookSize = getBookSize(layersStream.get());
float bookScale = osgMyGUI::ScalingLayer::getScaleFactor(bookSize);
std::string oldDataPath = dataManager->getDataPath("");
dataManager->setResourcePath("fonts");
std::unique_ptr<MyGUI::IDataStream> dataStream(dataManager->getData(fileName));
@ -226,15 +274,17 @@ namespace Gui
return;
}
// For TrueType fonts we should override Size and Resolution properties
// to allow to configure font size via config file, without need to edit XML files.
// Also we should take UI scaling factor in account.
int resolution = Settings::Manager::getInt("ttf resolution", "GUI");
resolution = std::clamp(resolution, 50, 125) * mScalingFactor;
int resolution = 70;
MyGUI::xml::ElementPtr resolutionNode = getProperty(resourceNode.current(), "Resolution");
if (resolutionNode == nullptr)
{
resolutionNode = resourceNode->createChild("Property");
resolutionNode->addAttribute("key", "Resolution");
}
else
resolution = MyGUI::utility::parseInt(resolutionNode->findAttribute("value"));
MyGUI::xml::ElementPtr resolutionNode = resourceNode->createChild("Property");
resolutionNode->addAttribute("key", "Resolution");
resolutionNode->addAttribute("value", std::to_string(resolution));
resolutionNode->setAttribute("value", MyGUI::utility::toString(resolution * std::ceil(mScalingFactor)));
MyGUI::xml::ElementPtr sizeNode = resourceNode->createChild("Property");
sizeNode->addAttribute("key", "Size");
@ -246,16 +296,7 @@ namespace Gui
font->setResourceName(fontId);
MyGUI::ResourceManager::getInstance().addResource(font);
float currentX = Settings::Manager::getInt("resolution x", "Video");
float currentY = Settings::Manager::getInt("resolution y", "Video");
// TODO: read size from openmw_layout.xml somehow
// TODO: it may be worth to take in account resolution change, but it is not safe to replace used assets
float heightScale = (currentY / 520);
float widthScale = (currentX / 600);
float uiScale = std::min(widthScale, heightScale);
resolution = Settings::Manager::getInt("ttf resolution", "GUI");
resolution = std::clamp(resolution, 50, 125) * uiScale;
resolutionNode->setAttribute("value", std::to_string(resolution));
resolutionNode->setAttribute("value", MyGUI::utility::toString(static_cast<int>(resolution * bookScale * mScalingFactor)));
MyGUI::ResourceTrueTypeFont* bookFont = static_cast<MyGUI::ResourceTrueTypeFont*>(
MyGUI::FactoryManager::getInstance().createObject("Resource", "ResourceTrueTypeFont"));

@ -27,8 +27,6 @@ namespace Gui
public:
FontLoader (ToUTF8::FromType encoding, const VFS::Manager* vfs, float scalingFactor);
void loadFonts();
void overrideLineHeight(MyGUI::xml::ElementPtr _node, const std::string& _file, MyGUI::Version _version);
int getFontHeight();
@ -41,6 +39,7 @@ namespace Gui
int mFontHeight;
float mScalingFactor;
void loadFonts();
void loadFont(const std::string& fontName, const std::string& fontId);
void loadBitmapFont (const std::string& fileName, const std::string& fontId);

@ -63,7 +63,7 @@ namespace osgMyGUI
void ScalingLayer::screenToLayerCoords(int& _left, int& _top) const
{
float scale = getScaleFactor();
float scale = getScaleFactor(mViewSize);
if (scale <= 0.f)
return;
@ -79,14 +79,14 @@ namespace osgMyGUI
_top += mViewSize.height/2;
}
float ScalingLayer::getScaleFactor() const
float ScalingLayer::getScaleFactor(const MyGUI::IntSize& _layerViewSize)
{
MyGUI::IntSize viewSize = MyGUI::RenderManager::getInstance().getViewSize();
float w = static_cast<float>(viewSize.width);
float h = static_cast<float>(viewSize.height);
float heightScale = (h / mViewSize.height);
float widthScale = (w / mViewSize.width);
float heightScale = (h / _layerViewSize.height);
float widthScale = (w / _layerViewSize.width);
return std::min(widthScale, heightScale);
}
@ -100,12 +100,12 @@ namespace osgMyGUI
{
MyGUI::IntSize globalViewSize = MyGUI::RenderManager::getInstance().getViewSize();
MyGUI::IntSize viewSize = globalViewSize;
float scale = getScaleFactor();
float scale = getScaleFactor(mViewSize);
viewSize.width = static_cast<int>(viewSize.width / scale);
viewSize.height = static_cast<int>(viewSize.height / scale);
float hoffset = (globalViewSize.width - mViewSize.width*getScaleFactor())/2.f / static_cast<float>(globalViewSize.width);
float voffset = (globalViewSize.height - mViewSize.height*getScaleFactor())/2.f / static_cast<float>(globalViewSize.height);
float hoffset = (globalViewSize.width - mViewSize.width*getScaleFactor(mViewSize))/2.f / static_cast<float>(globalViewSize.width);
float voffset = (globalViewSize.height - mViewSize.height*getScaleFactor(mViewSize))/2.f / static_cast<float>(globalViewSize.height);
ProxyRenderTarget proxy(_target, viewSize, hoffset, voffset);

@ -21,9 +21,10 @@ namespace osgMyGUI
void resizeView(const MyGUI::IntSize& _viewSize) override;
static float getScaleFactor(const MyGUI::IntSize& _layerViewSize);
private:
void screenToLayerCoords(int& _left, int& _top) const;
float getScaleFactor() const;
};
}

@ -39,14 +39,13 @@ TrueType fonts are configured via ``openmw.cfg`` too:
In this example, OpenMW will scan ``Fonts`` folder in data directories for ``.omwfont`` files.
These files are XML files with schema provided by MyGUI. OpenMW uses ``.omwfont`` files which name (without extension) matches ``openmw.cfg`` entries.
It is also possible to adjust the font size and resolution via ``settings.cfg`` file::
It is also possible to adjust the font size via ``settings.cfg`` file::
[GUI]
font size = 16
ttf resolution = 75
The ``font size`` setting accepts clamped values in range from 12 to 18 while ``ttf resolution`` setting accepts values from 50 to 125.
The ``font size`` setting accepts clamped values in range from 12 to 18.
Any Resolution or Size properties in the ``.omwfont`` file have no effect because the engine settings override them.
Any Size property in the ``.omwfont`` file has no effect because the engine overrides it.
The engine automatically takes UI scaling factor into account, so don't account for it when tweaking the settings.

@ -26,18 +26,6 @@ TrueType fonts do not have this issue.
This setting can be configured in the Interface section of Advanced tab of the launcher.
ttf resolution
--------------
:Type: integer
:Range: 50 to 125
:Default: 75
Allows to specify resolution for in-game TrueType fonts.
Note: actual resolution depends on "scaling factor" setting value, this value is for 1.0 scaling factor.
This setting can be configured in the Interface section of Advanced tab of the launcher.
menu transparency
-----------------

@ -4,6 +4,7 @@
<Property key="Antialias" value="false"/>
<Property key="TabWidth" value="8"/>
<Property key="OffsetHeight" value="0"/>
<Property key="Resolution" value="58"/>
<Codes>
<Code range="33 126"/>
<Code range="192 382"/>

@ -5,6 +5,7 @@
<Property key="TabWidth" value="8"/>
<Property key="SubstituteCode" value="0"/>
<Property key="OffsetHeight" value="0"/>
<Property key="Resolution" value="70"/>
<Codes>
<Code range="0"/>
<Code range="65 90"/>

@ -5,6 +5,7 @@
<Property key="SubstituteCode" value="63"/>
<Property key="TabWidth" value="8"/>
<Property key="OffsetHeight" value="0"/>
<Property key="Resolution" value="70"/>
<Codes>
<Code range="33 126"/>
<Code range="161"/>

@ -192,9 +192,6 @@ scaling factor = 1.0
# Size of in-game fonts
font size = 16
# Resolution of TrueType fonts glyphs
ttf resolution = 75
# Transparency of GUI windows (0.0 to 1.0, transparent to opaque).
menu transparency = 0.84

@ -1063,33 +1063,6 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="ttfResolutionLabel">
<property name="toolTip">
<string>Resolution of TrueType fonts glyphs. Automatically takes in account UI scaling factor.
Lower values make text more blurry, higher ones - more pixelated.</string>
</property>
<property name="text">
<string>TTF texture resolution</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="ttfResolutionSpinBox">
<property name="minimum">
<number>50</number>
</property>
<property name="maximum">
<number>125</number>
</property>
<property name="singleStep">
<number>5</number>
</property>
<property name="value">
<number>75</number>
</property>
</widget>
</item>
</layout>
</item>
<item>

Loading…
Cancel
Save