aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics/openglsdl
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/openglsdl
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/openglsdl')
-rw-r--r--backends/graphics/openglsdl/openglsdl-graphics.cpp83
-rw-r--r--backends/graphics/openglsdl/openglsdl-graphics.h6
2 files changed, 86 insertions, 3 deletions
diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp
index 3209905085..8dcc5582a9 100644
--- a/backends/graphics/openglsdl/openglsdl-graphics.cpp
+++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp
@@ -39,7 +39,7 @@ OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager(uint desktopWidth, uint deskt
#else
_lastVideoModeLoad(0),
#endif
- _graphicsScale(2), _ignoreLoadVideoMode(false), _gotResize(false), _wantsFullScreen(false), _ignoreResizeEvents(0),
+ _graphicsScale(2), _stretchMode(STRETCH_FIT), _ignoreLoadVideoMode(false), _gotResize(false), _wantsFullScreen(false), _ignoreResizeEvents(0),
_desiredFullscreenWidth(0), _desiredFullscreenHeight(0) {
// Setup OpenGL attributes for SDL
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
@@ -266,6 +266,54 @@ bool OpenGLSdlGraphicsManager::getFeatureState(OSystem::Feature f) const {
}
}
+namespace {
+const OSystem::GraphicsMode sdlGlStretchModes[] = {
+ {"center", _s("Center"), STRETCH_CENTER},
+ {"pixel-perfect", _s("Pixel-perfect scaling"), STRETCH_INTEGRAL},
+ {"fit", _s("Fit to window"), STRETCH_FIT},
+ {"stretch", _s("Stretch to window"), STRETCH_STRETCH},
+ {nullptr, nullptr, 0}
+};
+
+} // End of anonymous namespace
+
+const OSystem::GraphicsMode *OpenGLSdlGraphicsManager::getSupportedStretchModes() const {
+ return sdlGlStretchModes;
+}
+
+int OpenGLSdlGraphicsManager::getDefaultStretchMode() const {
+ return STRETCH_FIT;
+}
+
+bool OpenGLSdlGraphicsManager::setStretchMode(int mode) {
+ assert(getTransactionMode() != kTransactionNone);
+
+ if (mode == _stretchMode)
+ return true;
+
+ // Check this is a valid mode
+ const OSystem::GraphicsMode *sm = sdlGlStretchModes;
+ bool found = false;
+ while (sm->name) {
+ if (sm->id == mode) {
+ found = true;
+ break;
+ }
+ sm++;
+ }
+ if (!found) {
+ warning("unknown stretch mode %d", mode);
+ return false;
+ }
+
+ _stretchMode = mode;
+ return true;
+}
+
+int OpenGLSdlGraphicsManager::getStretchMode() const {
+ return _stretchMode;
+}
+
void OpenGLSdlGraphicsManager::initSize(uint w, uint h, const Graphics::PixelFormat *format) {
// HACK: This is stupid but the SurfaceSDL backend defaults to 2x. This
// assures that the launcher (which requests 320x200) has a reasonable
@@ -735,7 +783,7 @@ bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) {
// Ctrl+Alt+f toggles filtering on/off
beginGFXTransaction();
- setFeatureState(OSystem::kFeatureFilteringMode, !getFeatureState(OSystem::kFeatureFilteringMode));
+ setFeatureState(OSystem::kFeatureFilteringMode, !getFeatureState(OSystem::kFeatureFilteringMode));
endGFXTransaction();
// Make sure we do not ignore the next resize. This
@@ -751,6 +799,34 @@ bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) {
#endif
return true;
+ } else if (event.kbd.keycode == Common::KEYCODE_s) {
+ // Never try to resize the window when changing the scaling mode.
+ _ignoreLoadVideoMode = true;
+
+ // Ctrl+Alt+s cycles through stretch mode
+ int index = 0;
+ const OSystem::GraphicsMode *sm = sdlGlStretchModes;
+ while (sm->name) {
+ if (sm->id == _stretchMode)
+ break;
+ sm++;
+ index++;
+ }
+ index++;
+ if (!sdlGlStretchModes[index].name)
+ index = 0;
+ beginGFXTransaction();
+ setStretchMode(sdlGlStretchModes[index].id);
+ endGFXTransaction();
+
+#ifdef USE_OSD
+ Common::String message = Common::String::format("%s: %s",
+ _("Stretch mode"),
+ _(sdlGlStretchModes[index].description)
+ );
+ displayMessageOnOSD(message.c_str());
+#endif
+ return true;
}
}
// Fall through
@@ -769,7 +845,8 @@ bool OpenGLSdlGraphicsManager::isHotkey(const Common::Event &event) const {
return event.kbd.keycode == Common::KEYCODE_PLUS || event.kbd.keycode == Common::KEYCODE_MINUS
|| event.kbd.keycode == Common::KEYCODE_KP_PLUS || event.kbd.keycode == Common::KEYCODE_KP_MINUS
|| event.kbd.keycode == Common::KEYCODE_a
- || event.kbd.keycode == Common::KEYCODE_f;
+ || event.kbd.keycode == Common::KEYCODE_f
+ || event.kbd.keycode == Common::KEYCODE_s;
}
return false;
diff --git a/backends/graphics/openglsdl/openglsdl-graphics.h b/backends/graphics/openglsdl/openglsdl-graphics.h
index 954c7215a4..b6ea496575 100644
--- a/backends/graphics/openglsdl/openglsdl-graphics.h
+++ b/backends/graphics/openglsdl/openglsdl-graphics.h
@@ -43,6 +43,11 @@ public:
virtual void setFeatureState(OSystem::Feature f, bool enable) override;
virtual bool getFeatureState(OSystem::Feature f) const override;
+ virtual const OSystem::GraphicsMode *getSupportedStretchModes() const override;
+ virtual int getDefaultStretchMode() const override;
+ virtual bool setStretchMode(int mode) override;
+ virtual int getStretchMode() const override;
+
virtual void initSize(uint w, uint h, const Graphics::PixelFormat *format) override;
#ifdef USE_RGB_COLOR
@@ -82,6 +87,7 @@ private:
uint _lastRequestedWidth;
uint _lastRequestedHeight;
uint _graphicsScale;
+ int _stretchMode;
bool _ignoreLoadVideoMode;
bool _gotResize;