From f7e0465dc3ea001f4ae37185fd0ea8479449079f Mon Sep 17 00:00:00 2001 From: Zero <128979226+lux-zero-161@users.noreply.github.com> Date: Sat, 20 Jun 2026 15:57:06 +0200 Subject: [PATCH] RmlUi: DPI scaling now uses the window size instead of the desktop resolution and is updated when the window is resized. --- Minecraft.Client/RmlManager.cpp | 27 ++++++++++++++------------- Minecraft.Client/RmlManager.h | 5 ++++- Minecraft.Server/RmlManagerStub.cpp | 2 +- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Minecraft.Client/RmlManager.cpp b/Minecraft.Client/RmlManager.cpp index 38c223df..d0386b6e 100644 --- a/Minecraft.Client/RmlManager.cpp +++ b/Minecraft.Client/RmlManager.cpp @@ -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(width) / 1920; - float scale_y = static_cast(height) / 1080; + float scale_x = static_cast(viewport_width) / 1920; + float scale_y = static_cast(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(height) / 850.0f; + float auto_dp = base_ratio; + float viewport_cap = 0.88f * static_cast(viewport_height) / 850.0f; if (auto_dp > viewport_cap) auto_dp = viewport_cap; diff --git a/Minecraft.Client/RmlManager.h b/Minecraft.Client/RmlManager.h index 80e30ea0..15f590ab 100644 --- a/Minecraft.Client/RmlManager.h +++ b/Minecraft.Client/RmlManager.h @@ -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 m_file_interface; Rml::Context* m_context; + + int m_viewport_width; + int m_viewport_height; }; #pragma pop_macro("GetFirstChild") diff --git a/Minecraft.Server/RmlManagerStub.cpp b/Minecraft.Server/RmlManagerStub.cpp index 0f39b6cc..ce057d64 100644 --- a/Minecraft.Server/RmlManagerStub.cpp +++ b/Minecraft.Server/RmlManagerStub.cpp @@ -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() {} \ No newline at end of file