From fad56e39d15e49f51b62178e49f54a41310a18ac Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sat, 7 Nov 2020 14:58:14 +0100 Subject: [PATCH] GUI: Scale theme images --- gui/ThemeEngine.cpp | 21 ++++++++++++++++----- gui/ThemeEngine.h | 6 +++++- gui/gui-manager.cpp | 6 +++++- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp index f1e3af20efc..e86f38655eb 100644 --- a/gui/ThemeEngine.cpp +++ b/gui/ThemeEngine.cpp @@ -190,7 +190,7 @@ ThemeEngine::ThemeEngine(Common::String id, GraphicsMode mode) : _system(nullptr), _vectorRenderer(nullptr), _layerToDraw(kDrawLayerBackground), _bytesPerPixel(0), _graphicsMode(kGfxDisabled), _font(nullptr), _initOk(false), _themeOk(false), _enabled(false), _themeFiles(), - _cursor(nullptr) { + _cursor(nullptr), _scaleFactor(1.0f) { _system = g_system; _parser = new ThemeParser(this); @@ -310,8 +310,13 @@ const char *ThemeEngine::findModeConfigName(GraphicsMode mode) { } +void ThemeEngine::setBaseResolution(int w, int h, float s) { + _baseWidth = w; + _baseHeight = h; + _scaleFactor = s; - + _parser->setBaseResolution(w, h, s); +} /********************************************************** * Theme setup/initialization @@ -376,7 +381,7 @@ void ThemeEngine::clearAll() { } } -void ThemeEngine::refresh(int16 baseWidth, int16 baseHeight, float scaleFactor) { +void ThemeEngine::refresh() { // Flush all bitmaps if the overlay pixel format changed. if (_overlayFormat != _system->getOverlayFormat()) { @@ -399,8 +404,6 @@ void ThemeEngine::refresh(int16 baseWidth, int16 baseHeight, float scaleFactor) _abitmaps.clear(); } - _parser->setBaseResolution(baseWidth, baseHeight, scaleFactor); - init(); if (_enabled) { @@ -736,6 +739,14 @@ bool ThemeEngine::addBitmap(const Common::String &filename) { surf = srcSurface->convertTo(_overlayFormat); } + if (_scaleFactor != 1.0) { + Graphics::Surface *tmp2 = surf->scale(surf->w * _scaleFactor, surf->h * _scaleFactor, false); + + surf->free(); + delete surf; + + surf = tmp2; + } // Store the surface into our hashmap (attention, may store NULL entries!) _bitmaps[filename] = surf; diff --git a/gui/ThemeEngine.h b/gui/ThemeEngine.h index 1b18e9ad697..aa8c181d975 100644 --- a/gui/ThemeEngine.h +++ b/gui/ThemeEngine.h @@ -349,10 +349,11 @@ public: /** Default destructor */ ~ThemeEngine(); + void setBaseResolution(int w, int h, float s); bool init(); void clearAll(); - void refresh(int16 baseWidth, int16 baseHeight, float scaleFactor); + void refresh(); void enable(); void showCursor(); @@ -774,6 +775,9 @@ protected: /** Current graphics mode */ GraphicsMode _graphicsMode; + int16 _baseWidth, _baseHeight; + float _scaleFactor; + /** Font info. */ const Graphics::Font *_font; diff --git a/gui/gui-manager.cpp b/gui/gui-manager.cpp index 07736058bfa..4ebda83f588 100644 --- a/gui/gui-manager.cpp +++ b/gui/gui-manager.cpp @@ -129,6 +129,9 @@ void GuiManager::computeScaleFactor() { _baseWidth = (int16)((float)w / _scaleFactor); + if (_theme) + _theme->setBaseResolution(_baseWidth, _baseHeight, _scaleFactor); + debug(3, "Setting %d x %d -> %d x %d -- %g", w, h, _baseWidth, _baseHeight, _scaleFactor); } @@ -206,6 +209,7 @@ bool GuiManager::loadNewTheme(Common::String id, ThemeEngine::GraphicsMode gfx, // Try to load the new theme newTheme = new ThemeEngine(id, gfx); assert(newTheme); + newTheme->setBaseResolution(_baseWidth, _baseHeight, _scaleFactor); if (!newTheme->init()) { delete newTheme; @@ -584,7 +588,7 @@ void GuiManager::screenChange() { computeScaleFactor(); // reinit the whole theme - _theme->refresh(_baseWidth, _baseHeight, _scaleFactor); + _theme->refresh(); // refresh all dialogs for (DialogStack::size_type i = 0; i < _dialogStack.size(); ++i) {