Skip to content
Permalink
Browse files

BACKENDS: add Fit to window (4:3) stretch mode to SDL2 backend

  • Loading branch information...
rsn8887 committed Aug 13, 2019
1 parent 59cff4b commit 5b32f377a9d717a16c57ca09d3223350137bf964
Showing with 11 additions and 2 deletions.
  1. +1 −0 backends/graphics/surfacesdl/surfacesdl-graphics.cpp
  2. +10 −2 backends/graphics/windowed.h
@@ -76,6 +76,7 @@ const OSystem::GraphicsMode s_supportedStretchModes[] = {
{"pixel-perfect", _s("Pixel-perfect scaling"), STRETCH_INTEGRAL},
{"fit", _s("Fit to window"), STRETCH_FIT},
{"stretch", _s("Stretch to window"), STRETCH_STRETCH},
{"fit_force_aspect", _s("Fit to window (4:3)"), STRETCH_FIT_FORCE_ASPECT},
{nullptr, nullptr, 0}
};
#endif
@@ -34,7 +34,8 @@ enum {
STRETCH_CENTER = 0,
STRETCH_INTEGRAL = 1,
STRETCH_FIT = 2,
STRETCH_STRETCH = 3
STRETCH_STRETCH = 3,
STRETCH_FIT_FORCE_ASPECT = 4
};

class WindowedGraphicsManager : virtual public GraphicsManager {
@@ -341,6 +342,7 @@ class WindowedGraphicsManager : virtual public GraphicsManager {
// Mode Integral = scale by an integral amount.
// Mode Fit = scale to fit the window while respecting the aspect ratio
// Mode Stretch = scale and stretch to fit the window without respecting the aspect ratio
// Mode Fit Force Aspect = scale to fit the window while forcing a 4:3 aspect ratio

int width = 0, height = 0;
if (mode == STRETCH_CENTER || mode == STRETCH_INTEGRAL) {
@@ -359,7 +361,13 @@ class WindowedGraphicsManager : virtual public GraphicsManager {
frac_t windowAspect = intToFrac(_windowWidth) / _windowHeight;
width = _windowWidth;
height = _windowHeight;
if (mode != STRETCH_STRETCH) {
if (mode == STRETCH_FIT_FORCE_ASPECT) {
frac_t ratio = intToFrac(4) / 3;
if (windowAspect < ratio)
height = intToFrac(width) / ratio;
else if (windowAspect > ratio)
width = fracToInt(height * ratio);
} else if (mode != STRETCH_STRETCH) {
if (windowAspect < displayAspect)
height = intToFrac(width) / displayAspect;
else if (windowAspect > displayAspect)

0 comments on commit 5b32f37

Please sign in to comment.
You can’t perform that action at this time.