From a0d4162a2bd43be470fcadb3abaaa4db929c9b10 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Mon, 26 Oct 2020 18:27:06 +0100 Subject: [PATCH] GUI: Compute base scale factor and set it for ThemeParser --- gui/ThemeEngine.cpp | 4 +++- gui/ThemeEngine.h | 2 +- gui/ThemeParser.cpp | 18 ++++++++++-------- gui/ThemeParser.h | 7 +++++++ gui/gui-manager.cpp | 30 +++++++++++++++++++++++++++++- gui/gui-manager.h | 6 ++++++ 6 files changed, 56 insertions(+), 11 deletions(-) diff --git a/gui/ThemeEngine.cpp b/gui/ThemeEngine.cpp index 9f94b842eaf..391433d2f4b 100644 --- a/gui/ThemeEngine.cpp +++ b/gui/ThemeEngine.cpp @@ -376,7 +376,7 @@ void ThemeEngine::clearAll() { } } -void ThemeEngine::refresh() { +void ThemeEngine::refresh(int16 baseWidth, int16 baseHeight) { // Flush all bitmaps if the overlay pixel format changed. if (_overlayFormat != _system->getOverlayFormat()) { @@ -399,6 +399,8 @@ void ThemeEngine::refresh() { _abitmaps.clear(); } + _parser->setBaseResolution(baseWidth, baseHeight); + init(); if (_enabled) { diff --git a/gui/ThemeEngine.h b/gui/ThemeEngine.h index 0e35372b6b5..0c5bd0f6f23 100644 --- a/gui/ThemeEngine.h +++ b/gui/ThemeEngine.h @@ -352,7 +352,7 @@ public: bool init(); void clearAll(); - void refresh(); + void refresh(int16 baseWidth, int16 baseHeight); void enable(); void showCursor(); diff --git a/gui/ThemeParser.cpp b/gui/ThemeParser.cpp index 31706db8545..b8d85093c54 100644 --- a/gui/ThemeParser.cpp +++ b/gui/ThemeParser.cpp @@ -126,6 +126,8 @@ ThemeParser::ThemeParser(ThemeEngine *parent) : XMLParser() { _defaultStepGlobal = defaultDrawStep(); _defaultStepLocal = nullptr; _theme = parent; + + _baseWidth = _baseHeight = 0; } ThemeParser::~ThemeParser() { @@ -921,7 +923,7 @@ bool ThemeParser::parseCommonLayoutProps(ParserNode *node, const Common::String return false; if (wtoken.lastChar() == '%') - width = g_system->getOverlayWidth() * width / 100; + width = _baseWidth * width / 100; } htoken = tokenizer.nextToken(); @@ -935,7 +937,7 @@ bool ThemeParser::parseCommonLayoutProps(ParserNode *node, const Common::String return false; if (htoken.lastChar() == '%') - height = g_system->getOverlayHeight() * height / 100; + height = _baseHeight * height / 100; } if (!tokenizer.empty()) @@ -961,7 +963,7 @@ bool ThemeParser::parseCommonLayoutProps(ParserNode *node, const Common::String if (!_theme->getEvaluator()->hasVar(var + "Width")) return false; - x = (g_system->getOverlayWidth() / 2) - (_theme->getEvaluator()->getVar(var + "Width") / 2); + x = (_baseWidth / 2) - (_theme->getEvaluator()->getVar(var + "Width") / 2); } else if (_theme->getEvaluator()->hasVar(xpos)) { x = _theme->getEvaluator()->getVar(xpos); @@ -972,7 +974,7 @@ bool ThemeParser::parseCommonLayoutProps(ParserNode *node, const Common::String return false; if (xpos.lastChar() == 'r') - x = g_system->getOverlayWidth() - x; + x = _baseWidth - x; } ypos = tokenizer.nextToken(); @@ -981,7 +983,7 @@ bool ThemeParser::parseCommonLayoutProps(ParserNode *node, const Common::String if (!_theme->getEvaluator()->hasVar(var + "Height")) return false; - y = (g_system->getOverlayHeight() / 2) - (_theme->getEvaluator()->getVar(var + "Height") / 2); + y = (_baseHeight / 2) - (_theme->getEvaluator()->getVar(var + "Height") / 2); } else if (_theme->getEvaluator()->hasVar(ypos)) { y = _theme->getEvaluator()->getVar(ypos); @@ -992,7 +994,7 @@ bool ThemeParser::parseCommonLayoutProps(ParserNode *node, const Common::String return false; if (ypos.lastChar() == 'b') - y = g_system->getOverlayHeight() - y; + y = _baseHeight - y; } if (!tokenizer.empty()) @@ -1046,9 +1048,9 @@ bool ThemeParser::resolutionCheck(const Common::String &resolution) { } if (cur[0] == 'x') { - val = g_system->getOverlayWidth(); + val = _baseWidth; } else if (cur[0] == 'y') { - val = g_system->getOverlayHeight(); + val = _baseHeight; } else { warning("Error parsing theme 'resolution' token '%s'", resolution.c_str()); return false; diff --git a/gui/ThemeParser.h b/gui/ThemeParser.h index f91bd26f451..d697ff9e87a 100644 --- a/gui/ThemeParser.h +++ b/gui/ThemeParser.h @@ -36,6 +36,11 @@ public: ~ThemeParser() override; + void setBaseResolution(int w, int h) { + _baseWidth = w; + _baseHeight = h; + } + bool getPaletteColor(const Common::String &name, int &r, int &g, int &b) { if (!_palette.contains(name)) return false; @@ -266,6 +271,8 @@ protected: Graphics::DrawStep *_defaultStepGlobal; Graphics::DrawStep *_defaultStepLocal; + int16 _baseWidth, _baseHeight; + struct PaletteColor { uint8 r, g, b; }; diff --git a/gui/gui-manager.cpp b/gui/gui-manager.cpp index 8d582d22612..004d23f01ff 100644 --- a/gui/gui-manager.cpp +++ b/gui/gui-manager.cpp @@ -67,6 +67,8 @@ GuiManager::GuiManager() : _redrawStatus(kRedrawDisabled), _stateIsSaved(false), _width = _system->getOverlayWidth(); _height = _system->getOverlayHeight(); + computeScaleFactor(); + _launched = false; _useRTL = false; @@ -107,6 +109,30 @@ GuiManager::~GuiManager() { delete _theme; } +void GuiManager::computeScaleFactor() { + int16 w = g_system->getOverlayWidth(); + int16 h = g_system->getOverlayHeight(); + + // Hardcoding for now + if (h < 240) { // 320 x 200 + _baseHeight = MIN(200, h); + } else if (h < 400) { // 320 x 240 + _baseHeight = 240; + } else if (h < 480) { // 640 x 400 + _baseHeight = 400; + } else if (h < 720) { // 640 x 480 + _baseHeight = 480; + } else { // 960 x 720 + _baseHeight = 720; + } + + float scaleFactor = (float)h / (float)_baseHeight; + + _baseWidth = (int16)((float)w / scaleFactor); + + warning("Setting %d x %d -> %d x %d", w, h, _baseWidth, _baseHeight); +} + Common::Keymap *GuiManager::getKeymap() const { using namespace Common; @@ -558,8 +584,10 @@ void GuiManager::screenChange() { _width = _system->getOverlayWidth(); _height = _system->getOverlayHeight(); + computeScaleFactor(); + // reinit the whole theme - _theme->refresh(); + _theme->refresh(_baseWidth, _baseHeight); // refresh all dialogs for (DialogStack::size_type i = 0; i < _dialogStack.size(); ++i) { diff --git a/gui/gui-manager.h b/gui/gui-manager.h index 29769900b81..228a5066498 100644 --- a/gui/gui-manager.h +++ b/gui/gui-manager.h @@ -94,6 +94,9 @@ public: int getWidth() const { return _width; } int getHeight() const { return _height; } + int getBaseWidth() const { return _baseWidth; } + int getBaseHeight() const { return _baseHeight; } + bool useRTL() const { return _useRTL; } void setLanguageRTL(); @@ -144,6 +147,7 @@ protected: RedrawStatus _redrawStatus; int _lastScreenChangeID; int _width, _height; + int16 _baseWidth, _baseHeight; DialogStack _dialogStack; bool _stateIsSaved; @@ -175,6 +179,8 @@ protected: }; Common::List _guiObjectTrash; + void computeScaleFactor(); + void initKeymap(); void enableKeymap(bool enabled);