RmlUi: DPI scaling now uses the window size instead of the desktop resolution and is updated when the window is resized.

This commit is contained in:
Zero
2026-06-20 15:57:06 +02:00
parent d34ff23292
commit f7e0465dc3
3 changed files with 19 additions and 15 deletions

View File

@@ -26,6 +26,8 @@ RmlManager& RmlManager::Get()
RmlManager::RmlManager()
: m_initialised(false)
, m_context(nullptr)
, m_viewport_width(0)
, m_viewport_height(0)
{
}
@@ -88,12 +90,15 @@ bool RmlManager::Init(int viewport_width, int viewport_height)
app.DebugPrintf("[RmlManager] Context created (%dx%d)\n", viewport_width, viewport_height);
m_viewport_width = viewport_width;
m_viewport_height = viewport_height;
m_renderer->SetViewport(viewport_width, viewport_height);
m_initialised = true;
app.DebugPrintf("[RmlManager] Initialised (%dx%d)\n", viewport_width, viewport_height);
UpdateDpRatio();
UpdateDpRatio(m_viewport_width, m_viewport_height);
return true;
}
@@ -170,28 +175,24 @@ void RmlManager::OnResize(int width, int height)
{
if (!m_initialised || !m_context)
return;
m_viewport_width = width;
m_viewport_height = height;
m_context->SetDimensions(Rml::Vector2i(width, height));
m_renderer->SetViewport(width, height);
UpdateDpRatio(width, height);
}
// GabsPuN: Taken from the Quake port as something temporary
void RmlManager::UpdateDpRatio()
void RmlManager::UpdateDpRatio(int viewport_width, int viewport_height)
{
if (!m_context)
return;
int width = GetSystemMetrics(SM_CXSCREEN);
int height = GetSystemMetrics(SM_CYSCREEN);
float scale_x = static_cast<float>(width) / 1920;
float scale_y = static_cast<float>(height) / 1080;
float scale_x = static_cast<float>(viewport_width) / 1920;
float scale_y = static_cast<float>(viewport_height) / 1080;
float base_ratio = (scale_x < scale_y) ? scale_x : scale_y;
float blend = (base_ratio > 1.0f) ? std::min(base_ratio - 1.0f, 1.0f) : 0.0f;
float effective_dpi = (1.0f - blend) + blend;
float auto_dp = base_ratio * effective_dpi;
float viewport_cap = 0.88f * static_cast<float>(height) / 850.0f;
float auto_dp = base_ratio;
float viewport_cap = 0.88f * static_cast<float>(viewport_height) / 850.0f;
if (auto_dp > viewport_cap)
auto_dp = viewport_cap;

View File

@@ -31,7 +31,7 @@ public:
RenderInterface_D3D11* GetRenderInterface() const { return m_renderer.get(); }
void OnResize(int width, int height);
void UpdateDpRatio();
void UpdateDpRatio(int viewport_width, int viewport_height);
void OnLanguageChanged();
@@ -48,6 +48,9 @@ private:
std::unique_ptr<FileInterface_Game> m_file_interface;
Rml::Context* m_context;
int m_viewport_width;
int m_viewport_height;
};
#pragma pop_macro("GetFirstChild")

View File

@@ -18,5 +18,5 @@ void RmlManager::Shutdown() {}
void RmlManager::Update() {}
void RmlManager::Render() {}
void RmlManager::OnResize(int width, int height) {}
void RmlManager::UpdateDpRatio() {}
void RmlManager::UpdateDpRatio(int, int) {}
void RmlManager::OnLanguageChanged() {}