mirror of
https://github.com/GabsPuNs/Project-Zenith-Main.git
synced 2026-07-12 07:29:04 +00:00
More accurate menus
This commit is contained in:
@@ -72,11 +72,16 @@ bool RmlManager::Init(int viewport_width, int viewport_height)
|
||||
Rml::Shutdown();
|
||||
return false;
|
||||
}
|
||||
|
||||
app.DebugPrintf("[RmlManager] Context created (%dx%d)\n", viewport_width, viewport_height);
|
||||
|
||||
m_renderer->SetViewport(viewport_width, viewport_height);
|
||||
m_initialised = true;
|
||||
|
||||
app.DebugPrintf("[RmlManager] Initialised (%dx%d)\n", viewport_width, viewport_height);
|
||||
|
||||
UpdateDpRatio();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -106,6 +111,7 @@ void RmlManager::Update()
|
||||
{
|
||||
if (!m_initialised || !m_context)
|
||||
return;
|
||||
|
||||
m_context->Update();
|
||||
}
|
||||
|
||||
@@ -154,3 +160,34 @@ void RmlManager::OnResize(int width, int height)
|
||||
m_context->SetDimensions(Rml::Vector2i(width, height));
|
||||
m_renderer->SetViewport(width, height);
|
||||
}
|
||||
|
||||
// GabsPuN: Taken from the Quake port as something temporary
|
||||
void RmlManager::UpdateDpRatio()
|
||||
{
|
||||
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 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;
|
||||
if (auto_dp > viewport_cap)
|
||||
auto_dp = viewport_cap;
|
||||
|
||||
float dp_ratio = auto_dp;
|
||||
|
||||
if (dp_ratio < 0.5f)
|
||||
dp_ratio = 0.5f;
|
||||
if (dp_ratio > 3.0f)
|
||||
dp_ratio = 3.0f;
|
||||
|
||||
m_context->SetDensityIndependentPixelRatio(dp_ratio);
|
||||
}
|
||||
Reference in New Issue
Block a user