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),
_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;

View file

@ -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;

View file

@ -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) {