mirror of
https://github.com/GabsPuNs/Project-Zenith-Main.git
synced 2026-07-11 04:59:17 +00:00
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:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user