GUI: Scale theme images

This commit is contained in:
Eugene Sandulenko 2020-11-07 14:58:14 +01:00
parent 25ed466e3f
commit fad56e39d1
3 changed files with 26 additions and 7 deletions

View file

@ -190,7 +190,7 @@ ThemeEngine::ThemeEngine(Common::String id, GraphicsMode mode) :
_system(nullptr), _vectorRenderer(nullptr), _system(nullptr), _vectorRenderer(nullptr),
_layerToDraw(kDrawLayerBackground), _bytesPerPixel(0), _graphicsMode(kGfxDisabled), _layerToDraw(kDrawLayerBackground), _bytesPerPixel(0), _graphicsMode(kGfxDisabled),
_font(nullptr), _initOk(false), _themeOk(false), _enabled(false), _themeFiles(), _font(nullptr), _initOk(false), _themeOk(false), _enabled(false), _themeFiles(),
_cursor(nullptr) { _cursor(nullptr), _scaleFactor(1.0f) {
_system = g_system; _system = g_system;
_parser = new ThemeParser(this); _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 * 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. // Flush all bitmaps if the overlay pixel format changed.
if (_overlayFormat != _system->getOverlayFormat()) { if (_overlayFormat != _system->getOverlayFormat()) {
@ -399,8 +404,6 @@ void ThemeEngine::refresh(int16 baseWidth, int16 baseHeight, float scaleFactor)
_abitmaps.clear(); _abitmaps.clear();
} }
_parser->setBaseResolution(baseWidth, baseHeight, scaleFactor);
init(); init();
if (_enabled) { if (_enabled) {
@ -736,6 +739,14 @@ bool ThemeEngine::addBitmap(const Common::String &filename) {
surf = srcSurface->convertTo(_overlayFormat); 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!) // Store the surface into our hashmap (attention, may store NULL entries!)
_bitmaps[filename] = surf; _bitmaps[filename] = surf;

View file

@ -349,10 +349,11 @@ public:
/** Default destructor */ /** Default destructor */
~ThemeEngine(); ~ThemeEngine();
void setBaseResolution(int w, int h, float s);
bool init(); bool init();
void clearAll(); void clearAll();
void refresh(int16 baseWidth, int16 baseHeight, float scaleFactor); void refresh();
void enable(); void enable();
void showCursor(); void showCursor();
@ -774,6 +775,9 @@ protected:
/** Current graphics mode */ /** Current graphics mode */
GraphicsMode _graphicsMode; GraphicsMode _graphicsMode;
int16 _baseWidth, _baseHeight;
float _scaleFactor;
/** Font info. */ /** Font info. */
const Graphics::Font *_font; const Graphics::Font *_font;

View file

@ -129,6 +129,9 @@ void GuiManager::computeScaleFactor() {
_baseWidth = (int16)((float)w / _scaleFactor); _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); 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 // Try to load the new theme
newTheme = new ThemeEngine(id, gfx); newTheme = new ThemeEngine(id, gfx);
assert(newTheme); assert(newTheme);
newTheme->setBaseResolution(_baseWidth, _baseHeight, _scaleFactor);
if (!newTheme->init()) { if (!newTheme->init()) {
delete newTheme; delete newTheme;
@ -584,7 +588,7 @@ void GuiManager::screenChange() {
computeScaleFactor(); computeScaleFactor();
// reinit the whole theme // reinit the whole theme
_theme->refresh(_baseWidth, _baseHeight, _scaleFactor); _theme->refresh();
// refresh all dialogs // refresh all dialogs
for (DialogStack::size_type i = 0; i < _dialogStack.size(); ++i) { for (DialogStack::size_type i = 0; i < _dialogStack.size(); ++i) {