GUI: Retain aspect ratio when scaling GUI bitmaps
This commit is contained in:
parent
3df69113f3
commit
9c8a0d083b
1 changed files with 9 additions and 0 deletions
|
@ -546,6 +546,15 @@ Graphics::Surface *scaleGfx(const Graphics::Surface *gfx, int w, int h) {
|
|||
const Graphics::PixelFormat &requiredFormat = g_gui.theme()->getPixelFormat();
|
||||
Graphics::Surface tmp;
|
||||
|
||||
// Maintain aspect ratio
|
||||
float xRatio = 1.0f * w / gfx->w;
|
||||
float yRatio = 1.0f * h / gfx->h;
|
||||
|
||||
if (xRatio < yRatio)
|
||||
h = gfx->h * xRatio;
|
||||
else
|
||||
w = gfx->w * yRatio;
|
||||
|
||||
tmp.create(gfx->w, gfx->h, g_gui.theme()->getPixelFormat());
|
||||
tmp.copyFrom(*gfx);
|
||||
tmp.convertToInPlace(requiredFormat);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue