16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-17 23:39:18 +02:00

Fix scaling background image while loading

This commit is contained in:
2025-10-14 22:43:05 +02:00
parent 62f8c2a225
commit d56e841d35

View File

@@ -493,31 +493,25 @@ void ui_layer::render_menu()
void ui_layer::render_background() void ui_layer::render_background()
{ {
if (m_background == 0) if (m_background == 0)
return; return;
ImVec2 display_size = ImGui::GetIO().DisplaySize; ImVec2 display_size = ImGui::GetIO().DisplaySize;
ImVec2 image_size; ITexture &tex = GfxRenderer->Texture(m_background);
ImVec2 start_position; tex.create();
ImVec2 end_position;
ITexture &tex = GfxRenderer->Texture(m_background); float tex_w = (float)tex.get_width();
tex.create(); float tex_h = (float)tex.get_height();
// Get the scaling factor based on the image aspect ratio vs. the display aspect ratio. // skalowanie "cover" wypełnia cały ekran, zachowując proporcje
//float scale_factor = (tex.get_width() / tex.get_height()) > (display_size.x / display_size.y) float scale_factor = (display_size.x / display_size.y) > (tex_w / tex_h) ? display_size.x / tex_w : display_size.y / tex_h;
// ? display_size.y / tex.get_height()
// : display_size.x / tex.get_width();
float scale_factor = (tex.get_width() / tex.get_height()) < (display_size.x / display_size.y)
? display_size.y / tex.get_height()
: display_size.x / tex.get_width();
ImVec2 image_size(tex_w * scale_factor, tex_h * scale_factor);
// Resize the image to fill the display. This will zoom in on the image on ultrawide monitors.
image_size = ImVec2((int)(tex.get_width() * scale_factor), (int)(tex.get_height() * scale_factor)); // wyśrodkowanie obrazka
// Center the image on the display. ImVec2 start_position((display_size.x - image_size.x) * 0.5f, (display_size.y - image_size.y) * 0.5f);
start_position = ImVec2((display_size.x - image_size.x) / 2, (display_size.y - image_size.y) / 2); ImVec2 end_position(start_position.x + image_size.x, start_position.y + image_size.y);
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. // obrazek jest odwrócony w pionie odwracamy UV
ImGui::GetBackgroundDrawList()->AddImage(reinterpret_cast<ImTextureID>(tex.get_id()), start_position, end_position, ImVec2(0, 1), ImVec2(1, 0)); ImGui::GetBackgroundDrawList()->AddImage(reinterpret_cast<ImTextureID>(tex.get_id()), start_position, end_position, ImVec2(0, 1), ImVec2(1, 0));
} }