diff options
Diffstat (limited to 'backends/graphics/openglsdl')
| -rw-r--r-- | backends/graphics/openglsdl/openglsdl-graphics.cpp | 83 | ||||
| -rw-r--r-- | backends/graphics/openglsdl/openglsdl-graphics.h | 6 | 
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;  | 
