GUI: Load SVGs from theme

This commit is contained in:
Eugene Sandulenko 2021-04-04 21:48:31 +02:00
parent 55ae2e4367
commit 4a58f08a37
2 changed files with 30 additions and 2 deletions

View File

@ -33,6 +33,7 @@
#include "graphics/cursorman.h"
#include "graphics/fontman.h"
#include "graphics/surface.h"
#include "graphics/svg.h"
#include "graphics/transparent_surface.h"
#include "graphics/VectorRenderer.h"
#include "graphics/fonts/bdf.h"
@ -265,6 +266,14 @@ ThemeEngine::~ThemeEngine() {
}
_abitmaps.clear();
for (SVGMap::iterator i = _svgs.begin(); i != _svgs.end(); ++i) {
Graphics::SVGBitmap *svg = i->_value;
if (svg) {
delete svg;
}
}
_svgs.clear();
delete _parser;
delete _themeEval;
delete[] _cursor;
@ -689,7 +698,7 @@ bool ThemeEngine::addTextColor(TextColor colorId, int r, int g, int b) {
return true;
}
bool ThemeEngine::addBitmap(const Common::String &filename) {
bool ThemeEngine::addBitmap(const Common::String &filename, const Common::String &scalablefile) {
// Nothing has to be done if the bitmap already has been loaded.
Graphics::Surface *surf = _bitmaps[filename];
if (surf) {
@ -745,6 +754,21 @@ bool ThemeEngine::addBitmap(const Common::String &filename) {
surf = srcSurface->convertTo(_overlayFormat);
}
if (!scalablefile.empty()) {
Graphics::SVGBitmap *image = nullptr;
Common::ArchiveMemberList members;
_themeFiles.listMatchingMembers(members, filename);
for (Common::ArchiveMemberList::const_iterator i = members.begin(), end = members.end(); i != end; ++i) {
Common::SeekableReadStream *stream = (*i)->createReadStream();
if (stream) {
image = new Graphics::SVGBitmap(stream);
break;
}
}
_svgs[filename] = image;
}
if (_scaleFactor != 1.0) {
Graphics::Surface *tmp2 = surf->scale(surf->w * _scaleFactor, surf->h * _scaleFactor, false);

View File

@ -45,6 +45,7 @@ class OSystem;
namespace Graphics {
struct DrawStep;
class VectorRenderer;
class SVGBitmap;
}
namespace GUI {
@ -202,6 +203,7 @@ private:
class ThemeEngine {
protected:
typedef Common::HashMap<Common::String, Graphics::Surface *> ImagesMap;
typedef Common::HashMap<Common::String, Graphics::SVGBitmap *> SVGMap;
typedef Common::HashMap<Common::String, Graphics::TransparentSurface *> AImagesMap;
friend class GUI::Dialog;
@ -582,8 +584,9 @@ public:
* The filename is also used as its identifier.
*
* @param filename Name of the bitmap file.
* @param filename Name of the scalable (SVG) file, could be empty
*/
bool addBitmap(const Common::String &filename);
bool addBitmap(const Common::String &filename, const Common::String &scalablefile);
/**
* Interface for the ThemeParser class: Loads a bitmap with transparency file to use on the GUI.
@ -799,6 +802,7 @@ protected:
Common::Array<LangExtraFont> _langExtraFonts;
ImagesMap _bitmaps;
SVGMap _svgs;
AImagesMap _abitmaps;
Graphics::PixelFormat _overlayFormat;
Graphics::PixelFormat _cursorFormat;