diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index ccbcadc3a..30e8b064b 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -388,6 +388,47 @@ void DBaseStatusBar::SetSize(int reltop, int hres, int vres, int hhres, int hvre SetDrawSize(reltop, hres, vres); } +static void ST_CalcCleanFacs(int designwidth, int designheight, int realwidth, int realheight, int *cleanx, int *cleany) +{ + float ratio; + int cwidth; + int cheight; + int cx1, cy1, cx2, cy2; + + ratio = ActiveRatio(realwidth, realheight); + if (AspectTallerThanWide(ratio)) + { + cwidth = realwidth; + cheight = realheight * AspectMultiplier(ratio) / 48; + } + else + { + cwidth = realwidth * AspectMultiplier(ratio) / 48; + cheight = realheight; + } + // Use whichever pair of cwidth/cheight or width/height that produces less difference + // between CleanXfac and CleanYfac. + cx1 = MAX(cwidth / designwidth, 1); + cy1 = MAX(cheight / designheight, 1); + cx2 = MAX(realwidth / designwidth, 1); + cy2 = MAX(realheight / designheight, 1); + if (abs(cx1 - cy1) <= abs(cx2 - cy2) || MAX(cx1, cx2) >= 4) + { // e.g. 640x360 looks better with this. + *cleanx = cx1; + *cleany = cy1; + } + else + { // e.g. 720x480 looks better with this. + *cleanx = cx2; + *cleany = cy2; + } + + if (*cleanx < *cleany) + *cleany = *cleanx; + else + *cleanx = *cleany; +} + void DBaseStatusBar::SetDrawSize(int reltop, int hres, int vres) { ValidateResolution(hres, vres); @@ -396,7 +437,7 @@ void DBaseStatusBar::SetDrawSize(int reltop, int hres, int vres) HorizontalResolution = hres; VerticalResolution = vres; int x, y; - V_CalcCleanFacs(hres, vres, SCREENWIDTH, SCREENHEIGHT, &x, &y); + ST_CalcCleanFacs(hres, vres, SCREENWIDTH, SCREENHEIGHT, &x, &y); defaultScale = { (double)x, (double)y }; SetScale(); // recalculate positioning info.