GUI: Add support for specified dimensions for bitmaps in theme file

When we are using SVG, there is no reliable way to get the proper
dimensions. The original code was relying on the dimensions of
the BMP file, and then was using those for understanding the
rendering positions e.g. for PicButtons.
This commit is contained in:
Eugene Sandulenko 2021-04-06 23:18:34 +02:00
parent def114c1fe
commit 3021f34060
4 changed files with 38 additions and 3 deletions

View File

@ -274,6 +274,14 @@ ThemeEngine::~ThemeEngine() {
}
_svgs.clear();
for (PointMap::iterator i = _bitmapDims.begin(); i != _bitmapDims.end(); ++i) {
Common::Point *point = i->_value;
if (point) {
delete point;
}
}
_bitmapDims.clear();
delete _parser;
delete _themeEval;
delete[] _cursor;
@ -698,7 +706,7 @@ bool ThemeEngine::addTextColor(TextColor colorId, int r, int g, int b) {
return true;
}
bool ThemeEngine::addBitmap(const Common::String &filename, const Common::String &scalablefile) {
bool ThemeEngine::addBitmap(const Common::String &filename, const Common::String &scalablefile, int width, int height) {
// Nothing has to be done if the bitmap already has been loaded.
Graphics::Surface *surf = _bitmaps[filename];
if (surf) {
@ -769,6 +777,8 @@ bool ThemeEngine::addBitmap(const Common::String &filename, const Common::String
_svgs[filename] = image;
}
_bitmapDims[filename] = new Common::Point(width * _scaleFactor, height * _scaleFactor);
if (_scaleFactor != 1.0) {
Graphics::Surface *tmp2 = surf->scale(surf->w * _scaleFactor, surf->h * _scaleFactor, false);

View File

@ -204,6 +204,7 @@ class ThemeEngine {
protected:
typedef Common::HashMap<Common::String, Graphics::Surface *> ImagesMap;
typedef Common::HashMap<Common::String, Graphics::SVGBitmap *> SVGMap;
typedef Common::HashMap<Common::String, Common::Point *> PointMap;
typedef Common::HashMap<Common::String, Graphics::TransparentSurface *> AImagesMap;
friend class GUI::Dialog;
@ -586,8 +587,9 @@ public:
*
* @param filename Name of the bitmap file.
* @param filename Name of the scalable (SVG) file, could be empty
* @param width, height Default image dimensions
*/
bool addBitmap(const Common::String &filename, const Common::String &scalablefile);
bool addBitmap(const Common::String &filename, const Common::String &scalablefile, int widht, int height);
/**
* Interface for the ThemeParser class: Loads a bitmap with transparency file to use on the GUI.
@ -642,6 +644,10 @@ public:
return _svgs.contains(name) ? _svgs[name] : 0;
}
Common::Point *getBitmapDims(const Common::String &name) {
return _bitmapDims.contains(name) ? _bitmapDims[name] : 0;
}
const Graphics::Surface *getImageSurface(const Common::String &name) const {
return _bitmaps.contains(name) ? _bitmaps[name] : 0;
}
@ -808,6 +814,7 @@ protected:
ImagesMap _bitmaps;
SVGMap _svgs;
PointMap _bitmapDims;
AImagesMap _abitmaps;
Graphics::PixelFormat _overlayFormat;
Graphics::PixelFormat _cursorFormat;

View File

@ -302,7 +302,23 @@ bool ThemeParser::parserCallback_bitmap(ParserNode *node) {
if (node->values.contains("scalable_file"))
scalableFile = node->values["scalable_file"];
if (!_theme->addBitmap(node->values["filename"], scalableFile))
int width = 0, height = 0;
Common::String val;
if (node->values.contains("width")) {
val = node->values["width"];
if (!parseIntegerKey(val, 1, &width))
return parserError("Error parsing width value");
}
if (node->values.contains("height")) {
val = node->values["height"];
if (!parseIntegerKey(val, 1, &height))
return parserError("Error parsing width height");
}
if (!_theme->addBitmap(node->values["filename"], scalableFile, width, height))
return parserError("Error loading Bitmap file '" + node->values["filename"] + "'");
return true;

View File

@ -92,6 +92,8 @@ protected:
XML_PROP(filename, true)
XML_PROP(resolution, false)
XML_PROP(scalable_file, false)
XML_PROP(width, false)
XML_PROP(height, false)
KEY_END()
XML_KEY(alphabitmap)
XML_PROP(filename, true)