GUI: Compute base scale factor and set it for ThemeParser
This commit is contained in:
parent
3ab7626e78
commit
a0d4162a2b
6 changed files with 56 additions and 11 deletions
|
@ -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) {
|
||||
|
|
|
@ -352,7 +352,7 @@ public:
|
|||
bool init();
|
||||
void clearAll();
|
||||
|
||||
void refresh();
|
||||
void refresh(int16 baseWidth, int16 baseHeight);
|
||||
void enable();
|
||||
|
||||
void showCursor();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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<int16>(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) {
|
||||
|
|
|
@ -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<GuiObjectTrashItem> _guiObjectTrash;
|
||||
|
||||
void computeScaleFactor();
|
||||
|
||||
void initKeymap();
|
||||
void enableKeymap(bool enabled);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue