From b116381d28c3d74b3cb4487493b5b0627b15fdbf Mon Sep 17 00:00:00 2001 From: Maksym H Date: Sat, 16 Sep 2023 00:40:40 +0300 Subject: [PATCH] Fix background image scaling in MainMenu --- src/gui/guiEngine.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gui/guiEngine.cpp b/src/gui/guiEngine.cpp index 4f20d1cf1..bd7349174 100644 --- a/src/gui/guiEngine.cpp +++ b/src/gui/guiEngine.cpp @@ -474,9 +474,15 @@ void GUIEngine::drawBackground(video::IVideoDriver *driver) } /* Draw background texture */ + float aspectRatioScreen = (float) screensize.X / screensize.Y; + float aspectRatioSource = (float) sourcesize.X / sourcesize.Y; + + int sourceX = aspectRatioSource > aspectRatioScreen ? (sourcesize.X - sourcesize.Y * aspectRatioScreen) / 2 : 0; + int sourceY = aspectRatioSource < aspectRatioScreen ? (sourcesize.Y - sourcesize.X / aspectRatioScreen) / 2 : 0; + draw2DImageFilterScaled(driver, texture, core::rect(0, 0, screensize.X, screensize.Y), - core::rect(0, 0, sourcesize.X, sourcesize.Y), + core::rect(sourceX, sourceY, sourcesize.X - sourceX, sourcesize.Y - sourceY), NULL, NULL, true); }