aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics/windowed.h
diff options
context:
space:
mode:
authorThierry Crozat2018-05-12 19:57:21 +0100
committerThierry Crozat2018-07-08 16:54:51 +0100
commit812ce59ee44d669d2b17a1c1602f9364900b9479 (patch)
treed1a7b66bc186a5c892c67e281a502a997246f369 /backends/graphics/windowed.h
parent8526c2c31a07e57f7166047a87474bffd82e8a03 (diff)
downloadscummvm-rg350-812ce59ee44d669d2b17a1c1602f9364900b9479.tar.gz
scummvm-rg350-812ce59ee44d669d2b17a1c1602f9364900b9479.tar.bz2
scummvm-rg350-812ce59ee44d669d2b17a1c1602f9364900b9479.zip
SDL: Implement stretch mode API
Four modes are supported: - Use original size with no scaling - Scale by an integral amount as much as possible but not bigger than the window. - Scale to fit the window while respecting the aspect ratio. There may be black bars on the left and right, or on the top and bottom, but not both. This is the default, and the old behaviour. - Scale and stretch to fit the window. In this mode the aspecy ratio is not respected and there is no black bars. The mode is controled by the "scaling_mode" value (between 0 and 3) in the config file. Also add Crtl-Alt-s hotkey to cycle through scaling modes
Diffstat (limited to 'backends/graphics/windowed.h')
-rw-r--r--backends/graphics/windowed.h60
1 files changed, 47 insertions, 13 deletions
diff --git a/backends/graphics/windowed.h b/backends/graphics/windowed.h
index 8a0bddf5be..4732ea9708 100644
--- a/backends/graphics/windowed.h
+++ b/backends/graphics/windowed.h
@@ -26,9 +26,17 @@
#include "backends/graphics/graphics.h"
#include "common/frac.h"
#include "common/rect.h"
+#include "common/config-manager.h"
#include "common/textconsole.h"
#include "graphics/scaler/aspect.h"
+enum {
+ STRETCH_CENTER = 0,
+ STRETCH_INTEGRAL = 1,
+ STRETCH_FIT = 2,
+ STRETCH_STRETCH = 3
+};
+
class WindowedGraphicsManager : virtual public GraphicsManager {
public:
WindowedGraphicsManager() :
@@ -136,6 +144,13 @@ protected:
}
/**
+ * @returns the scale used between the game size and the surface on which it is rendered.
+ */
+ virtual int getGameRenderScale() const {
+ return 1;
+ }
+
+ /**
* Called after the window has been updated with new dimensions.
*
* @param width The new width of the window, excluding window decoration.
@@ -156,13 +171,11 @@ protected:
return;
}
- const frac_t outputAspect = intToFrac(_windowWidth) / _windowHeight;
-
- populateDisplayAreaDrawRect(getDesiredGameAspectRatio(), outputAspect, _gameDrawRect);
+ populateDisplayAreaDrawRect(getDesiredGameAspectRatio(), getWidth() * getGameRenderScale(), _gameDrawRect);
if (getOverlayHeight()) {
const frac_t overlayAspect = intToFrac(getOverlayWidth()) / getOverlayHeight();
- populateDisplayAreaDrawRect(overlayAspect, outputAspect, _overlayDrawRect);
+ populateDisplayAreaDrawRect(overlayAspect, getOverlayWidth(), _overlayDrawRect);
}
if (_overlayVisible) {
@@ -316,15 +329,36 @@ protected:
int _cursorX, _cursorY;
private:
- void populateDisplayAreaDrawRect(const frac_t inputAspect, const frac_t outputAspect, Common::Rect &drawRect) const {
- int width = _windowWidth;
- int height = _windowHeight;
-
- // Maintain aspect ratios
- if (outputAspect < inputAspect) {
- height = intToFrac(width) / inputAspect;
- } else if (outputAspect > inputAspect) {
- width = fracToInt(height * inputAspect);
+ void populateDisplayAreaDrawRect(const frac_t displayAspect, int originalWidth, Common::Rect &drawRect) const {
+ int mode = getStretchMode();
+ // Mode Center = use original size, or divide by an integral amount if window is smaller than game surface
+ // 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
+
+ int width = 0, height = 0;
+ if (mode == STRETCH_CENTER || mode == STRETCH_INTEGRAL) {
+ width = originalWidth;
+ height = intToFrac(width) / displayAspect;
+ if (width > _windowWidth || height > _windowHeight) {
+ int fac = 1 + MAX((width - 1) / _windowWidth, (height - 1) / _windowHeight);
+ width /= fac;
+ height /= fac;
+ } else if (mode == STRETCH_INTEGRAL) {
+ int fac = MIN(_windowWidth / width, _windowHeight / height);
+ width *= fac;
+ height *= fac;
+ }
+ } else {
+ frac_t windowAspect = intToFrac(_windowWidth) / _windowHeight;
+ width = _windowWidth;
+ height = _windowHeight;
+ if (mode != STRETCH_STRETCH) {
+ if (windowAspect < displayAspect)
+ height = intToFrac(width) / displayAspect;
+ else if (windowAspect > displayAspect)
+ width = fracToInt(height * displayAspect);
+ }
}
drawRect.left = (_windowWidth - width) / 2;