diff --git a/src/framework/graphics/texturemanager.h b/src/framework/graphics/texturemanager.h index d2be3a2947..cf193654ba 100644 --- a/src/framework/graphics/texturemanager.h +++ b/src/framework/graphics/texturemanager.h @@ -38,10 +38,9 @@ class TextureManager void preload(const std::string& fileName, bool smooth = true) { getTexture(fileName, smooth); } TexturePtr getTexture(const std::string& fileName, bool smooth = true); const TexturePtr& getEmptyTexture() { return m_emptyTexture; } - -private: TexturePtr loadTexture(std::stringstream& file); +private: stdext::map m_textures; std::vector m_animatedTextures; TexturePtr m_emptyTexture; diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index 1164ac38bb..52e60472a2 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -899,4 +899,4 @@ void Application::registerLuaFunctions() g_lua.bindClassMemberFunction("isEnabled", &SoundChannel::isEnabled); g_lua.bindClassMemberFunction("getId", &SoundChannel::getId); #endif -} \ No newline at end of file +} diff --git a/src/framework/ui/uiwidget.h b/src/framework/ui/uiwidget.h index c65245a864..5553a8e163 100644 --- a/src/framework/ui/uiwidget.h +++ b/src/framework/ui/uiwidget.h @@ -474,7 +474,7 @@ class UIWidget : public LuaObject EdgeGroup m_imageBorder; public: - void setImageSource(const std::string_view source); + void setImageSource(const std::string_view source, bool base64); void setImageClip(const Rect& clipRect) { m_imageClipRect = clipRect; updateImageCache(); } void setImageOffsetX(int x) { m_imageRect.setX(x); updateImageCache(); } void setImageOffsetY(int y) { m_imageRect.setY(y); updateImageCache(); } diff --git a/src/framework/ui/uiwidgetimage.cpp b/src/framework/ui/uiwidgetimage.cpp index f2e01890ab..caa03534c4 100644 --- a/src/framework/ui/uiwidgetimage.cpp +++ b/src/framework/ui/uiwidgetimage.cpp @@ -23,10 +23,12 @@ #include #include #include +#include #include #include #include "uiwidget.h" #include "framework/graphics/drawpoolmanager.h" +#include void UIWidget::initImage() {} @@ -34,7 +36,9 @@ void UIWidget::parseImageStyle(const OTMLNodePtr& styleNode) { for (const auto& node : styleNode->children()) { if (node->tag() == "image-source") - setImageSource(stdext::resolve_path(node->value(), node->source())); + setImageSource(stdext::resolve_path(node->value(), node->source()), false); + else if (node->tag() == "image-source-base64") + setImageSource(stdext::resolve_path(node->value(), node->source()), true); else if (node->tag() == "image-offset-x") setImageOffsetX(node->value()); else if (node->tag() == "image-offset-y") @@ -177,7 +181,7 @@ void UIWidget::drawImage(const Rect& screenCoords) } } -void UIWidget::setImageSource(const std::string_view source) +void UIWidget::setImageSource(const std::string_view source, bool base64) { updateImageCache(); @@ -187,7 +191,15 @@ void UIWidget::setImageSource(const std::string_view source) return; } - m_imageTexture = g_textures.getTexture(m_imageSource = source, isImageSmooth()); + if (base64) { + std::stringstream stream; + const auto& decoded = g_crypt.base64Decode(source); + stream.write(decoded.c_str(), decoded.size()); + m_imageTexture = g_textures.loadTexture(stream); + } else { + m_imageTexture = g_textures.getTexture(m_imageSource = source, isImageSmooth()); + } + if (!m_imageTexture) return; @@ -211,4 +223,4 @@ void UIWidget::setImageSource(const std::string_view source) setSize(size); } -} \ No newline at end of file +} diff --git a/src/framework/util/crypt.cpp b/src/framework/util/crypt.cpp index f3bac8a618..8aac1d4871 100644 --- a/src/framework/util/crypt.cpp +++ b/src/framework/util/crypt.cpp @@ -109,7 +109,7 @@ std::string Crypt::base64Encode(const std::string& decoded_string) return ret; } -std::string Crypt::base64Decode(const std::string& encoded_string) +std::string Crypt::base64Decode(const std::string_view& encoded_string) { int len = encoded_string.size(); int i = 0; @@ -375,4 +375,4 @@ std::string Crypt::crc32(const std::string& decoded_string, bool upperCase) else std::transform(result.begin(), result.end(), result.begin(), tolower); return result; -} \ No newline at end of file +} diff --git a/src/framework/util/crypt.h b/src/framework/util/crypt.h index 6bdb1f2a63..7370dfa0fd 100644 --- a/src/framework/util/crypt.h +++ b/src/framework/util/crypt.h @@ -38,7 +38,7 @@ class Crypt ~Crypt(); std::string base64Encode(const std::string& decoded_string); - std::string base64Decode(const std::string& encoded_string); + std::string base64Decode(const std::string_view& encoded_string); std::string xorCrypt(const std::string& buffer, const std::string& key); std::string encrypt(const std::string& decrypted_string) { return _encrypt(decrypted_string, true); } std::string decrypt(const std::string& encrypted_string) { return _decrypt(encrypted_string, true); }