mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 18:39:18 +02:00
Fix loading screen background aspect ratio on ultrawide displays
This commit is contained in:
25
uilayer.cpp
25
uilayer.cpp
@@ -515,15 +515,24 @@ void ui_layer::render_background()
|
|||||||
if (m_background == 0)
|
if (m_background == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ImVec2 size = ImGui::GetIO().DisplaySize;
|
ImVec2 display_size = ImGui::GetIO().DisplaySize;
|
||||||
|
ImVec2 image_size;
|
||||||
|
ImVec2 start_position;
|
||||||
|
ImVec2 end_position;
|
||||||
|
|
||||||
opengl_texture &tex = GfxRenderer->Texture(m_background);
|
opengl_texture &tex = GfxRenderer->Texture(m_background);
|
||||||
tex.create();
|
tex.create();
|
||||||
|
|
||||||
ImGui::SetNextWindowPos(ImVec2(0, 0));
|
// Get the scaling factor based on the image aspect ratio vs. the display aspect ratio.
|
||||||
ImGui::SetNextWindowSize(size);
|
float scale_factor = (tex.width() / tex.height()) > (display_size.x / display_size.y)
|
||||||
ImGui::Begin("Logo", nullptr,
|
? display_size.y / tex.height()
|
||||||
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse |
|
: display_size.x / tex.width();
|
||||||
ImGuiWindowFlags_NoBringToFrontOnFocus);
|
|
||||||
ImGui::Image(reinterpret_cast<void *>(tex.id), size, ImVec2(0, 1), ImVec2(1, 0));
|
// Resize the image to fill the display. This will zoom in on the image on ultrawide monitors.
|
||||||
ImGui::End();
|
image_size = ImVec2((int)(tex.width() * scale_factor), (int)(tex.height() * scale_factor));
|
||||||
|
// Center the image on the display.
|
||||||
|
start_position = ImVec2((display_size.x - image_size.x) / 2, (display_size.y - image_size.y) / 2);
|
||||||
|
end_position = ImVec2(image_size.x + start_position.x, image_size.y + start_position.y);
|
||||||
|
// The image is flipped upside-down, we'll use the UV parameters to draw it from bottom up to un-flip it.
|
||||||
|
ImGui::GetBackgroundDrawList()->AddImage((ImTextureID)tex.id, start_position, end_position, ImVec2(0, 1), ImVec2(1, 0));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user