From bd22f5583d85dfb3e109239ac2ab67d73b6afaec Mon Sep 17 00:00:00 2001 From: SkullzOTS <86809689+SkullzOTS@users.noreply.github.com> Date: Sat, 12 Aug 2023 02:49:25 -0300 Subject: [PATCH 01/16] Update uiwidget.h --- src/framework/ui/uiwidget.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/framework/ui/uiwidget.h b/src/framework/ui/uiwidget.h index c65245a864..017b64e68c 100644 --- a/src/framework/ui/uiwidget.h +++ b/src/framework/ui/uiwidget.h @@ -475,6 +475,7 @@ class UIWidget : public LuaObject public: void setImageSource(const std::string_view source); + void setImageSourceBase64(const std::string& source); 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(); } From 04085438c7a2d9df21eb9c31c3365fb0ea8c639a Mon Sep 17 00:00:00 2001 From: SkullzOTS <86809689+SkullzOTS@users.noreply.github.com> Date: Sat, 12 Aug 2023 02:51:47 -0300 Subject: [PATCH 02/16] Update uiwidgetimage.cpp --- src/framework/ui/uiwidgetimage.cpp | 45 +++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/framework/ui/uiwidgetimage.cpp b/src/framework/ui/uiwidgetimage.cpp index f2e01890ab..5a5305db72 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() {} @@ -35,6 +37,8 @@ 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())); + else if(node->tag() == "image-source-base64") + setImageSourceBase64(node->value()); else if (node->tag() == "image-offset-x") setImageOffsetX(node->value()); else if (node->tag() == "image-offset-y") @@ -211,4 +215,43 @@ void UIWidget::setImageSource(const std::string_view source) setSize(size); } -} \ No newline at end of file +} + +void UIWidget::setImageSourceBase64(const std::string& source) +{ + updateImageCache(); + + if (source.empty()) { + m_imageTexture = nullptr; + m_imageSource = {}; + return; + } + + std::stringstream stream; + std::string decoded = g_crypt.base64Decode(source); + stream.write(decoded.c_str(), decoded.size()); + m_imageTexture = g_textures.loadTexture(stream); + if (!m_imageTexture) + return; + + if (m_imageTexture->isAnimatedTexture()) { + if (isImageIndividualAnimation()) { + m_imageAnimatorTimer.restart(); + m_currentFrame = 0; + } else + std::static_pointer_cast(m_imageTexture)->restart(); + } + + if (!m_rect.isValid() || hasProp(PropImageAutoResize)) { + const auto& imageSize = m_imageTexture->getSize(); + + Size size = getSize(); + if (size.width() <= 0 || hasProp(PropImageAutoResize)) + size.setWidth(imageSize.width()); + + if (size.height() <= 0 || hasProp(PropImageAutoResize)) + size.setHeight(imageSize.height()); + + setSize(size); + } +} From 9f4b13d579f78df8aa9131499743fb7d70a3fa7f Mon Sep 17 00:00:00 2001 From: SkullzOTS <86809689+SkullzOTS@users.noreply.github.com> Date: Sat, 12 Aug 2023 02:52:16 -0300 Subject: [PATCH 03/16] Update luafunctions.cpp --- src/framework/luafunctions.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index 1164ac38bb..88f4f31166 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -620,6 +620,7 @@ void Application::registerLuaFunctions() g_lua.bindClassMemberFunction("getOpacity", &UIWidget::getOpacity); g_lua.bindClassMemberFunction("getRotation", &UIWidget::getRotation); g_lua.bindClassMemberFunction("setImageSource", &UIWidget::setImageSource); + g_lua.bindClassMemberFunction("setImageSourceBase64", &UIWidget::setImageSourceBase64); g_lua.bindClassMemberFunction("setImageClip", &UIWidget::setImageClip); g_lua.bindClassMemberFunction("setImageOffsetX", &UIWidget::setImageOffsetX); g_lua.bindClassMemberFunction("setImageOffsetY", &UIWidget::setImageOffsetY); @@ -899,4 +900,4 @@ void Application::registerLuaFunctions() g_lua.bindClassMemberFunction("isEnabled", &SoundChannel::isEnabled); g_lua.bindClassMemberFunction("getId", &SoundChannel::getId); #endif -} \ No newline at end of file +} From 5d00bf14a01249a96978d048b82f253dc9ae9bff Mon Sep 17 00:00:00 2001 From: SkullzOTS <86809689+SkullzOTS@users.noreply.github.com> Date: Mon, 14 Aug 2023 17:45:10 -0300 Subject: [PATCH 04/16] public loadTexture --- src/framework/graphics/texturemanager.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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; From 08ac8c08e837fee3489d3a71d437f32f3ab7fb22 Mon Sep 17 00:00:00 2001 From: SkullzOTS <86809689+SkullzOTS@users.noreply.github.com> Date: Sun, 20 Aug 2023 10:20:00 -0300 Subject: [PATCH 05/16] Update uiwidget.h --- src/framework/ui/uiwidget.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/framework/ui/uiwidget.h b/src/framework/ui/uiwidget.h index 017b64e68c..5553a8e163 100644 --- a/src/framework/ui/uiwidget.h +++ b/src/framework/ui/uiwidget.h @@ -474,8 +474,7 @@ class UIWidget : public LuaObject EdgeGroup m_imageBorder; public: - void setImageSource(const std::string_view source); - void setImageSourceBase64(const std::string& 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(); } From f57e13cd25b594ae9e1664576269cafa12f574f0 Mon Sep 17 00:00:00 2001 From: SkullzOTS <86809689+SkullzOTS@users.noreply.github.com> Date: Sun, 20 Aug 2023 10:20:04 -0300 Subject: [PATCH 06/16] Update uiwidgetimage.cpp --- src/framework/ui/uiwidgetimage.cpp | 49 +++++------------------------- 1 file changed, 7 insertions(+), 42 deletions(-) diff --git a/src/framework/ui/uiwidgetimage.cpp b/src/framework/ui/uiwidgetimage.cpp index 5a5305db72..b17a43e235 100644 --- a/src/framework/ui/uiwidgetimage.cpp +++ b/src/framework/ui/uiwidgetimage.cpp @@ -36,9 +36,7 @@ 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())); - else if(node->tag() == "image-source-base64") - setImageSourceBase64(node->value()); + setImageSource(stdext::resolve_path(node->value(), node->source()), node->value()); else if (node->tag() == "image-offset-x") setImageOffsetX(node->value()); else if (node->tag() == "image-offset-y") @@ -181,7 +179,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(); @@ -192,45 +190,12 @@ void UIWidget::setImageSource(const std::string_view source) } m_imageTexture = g_textures.getTexture(m_imageSource = source, isImageSmooth()); - if (!m_imageTexture) - return; - - if (m_imageTexture->isAnimatedTexture()) { - if (isImageIndividualAnimation()) { - m_imageAnimatorTimer.restart(); - m_currentFrame = 0; - } else - std::static_pointer_cast(m_imageTexture)->restart(); + if (base64) { + std::stringstream stream; + std::string decoded = g_crypt.base64Decode(source); + stream.write(decoded.c_str(), decoded.size()); + m_imageTexture = g_textures.loadTexture(stream); } - - if (!m_rect.isValid() || hasProp(PropImageAutoResize)) { - const auto& imageSize = m_imageTexture->getSize(); - - Size size = getSize(); - if (size.width() <= 0 || hasProp(PropImageAutoResize)) - size.setWidth(imageSize.width()); - - if (size.height() <= 0 || hasProp(PropImageAutoResize)) - size.setHeight(imageSize.height()); - - setSize(size); - } -} - -void UIWidget::setImageSourceBase64(const std::string& source) -{ - updateImageCache(); - - if (source.empty()) { - m_imageTexture = nullptr; - m_imageSource = {}; - return; - } - - std::stringstream stream; - std::string decoded = g_crypt.base64Decode(source); - stream.write(decoded.c_str(), decoded.size()); - m_imageTexture = g_textures.loadTexture(stream); if (!m_imageTexture) return; From 599cee10bad195b04528595e444057114436f363 Mon Sep 17 00:00:00 2001 From: SkullzOTS <86809689+SkullzOTS@users.noreply.github.com> Date: Sun, 20 Aug 2023 10:20:08 -0300 Subject: [PATCH 07/16] Update luafunctions.cpp --- src/framework/luafunctions.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index 88f4f31166..52e60472a2 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -620,7 +620,6 @@ void Application::registerLuaFunctions() g_lua.bindClassMemberFunction("getOpacity", &UIWidget::getOpacity); g_lua.bindClassMemberFunction("getRotation", &UIWidget::getRotation); g_lua.bindClassMemberFunction("setImageSource", &UIWidget::setImageSource); - g_lua.bindClassMemberFunction("setImageSourceBase64", &UIWidget::setImageSourceBase64); g_lua.bindClassMemberFunction("setImageClip", &UIWidget::setImageClip); g_lua.bindClassMemberFunction("setImageOffsetX", &UIWidget::setImageOffsetX); g_lua.bindClassMemberFunction("setImageOffsetY", &UIWidget::setImageOffsetY); From 7ffd0592c3c954cfdbe3b2210d42b27c66a7865e Mon Sep 17 00:00:00 2001 From: SkullzOTS <86809689+SkullzOTS@users.noreply.github.com> Date: Sun, 20 Aug 2023 10:26:11 -0300 Subject: [PATCH 08/16] Update crypt.cpp --- src/framework/util/crypt.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 +} From 1da38785fee6da3aa85b345be85ee142d0727c56 Mon Sep 17 00:00:00 2001 From: SkullzOTS <86809689+SkullzOTS@users.noreply.github.com> Date: Sun, 20 Aug 2023 10:26:26 -0300 Subject: [PATCH 09/16] Update crypt.h --- src/framework/util/crypt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); } From aa54aabcc612606224f6a10fda0d709f8d64c51b Mon Sep 17 00:00:00 2001 From: SkullzOTS <86809689+SkullzOTS@users.noreply.github.com> Date: Sun, 20 Aug 2023 11:04:37 -0300 Subject: [PATCH 10/16] Update uiwidgetimage.cpp --- src/framework/ui/uiwidgetimage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/framework/ui/uiwidgetimage.cpp b/src/framework/ui/uiwidgetimage.cpp index b17a43e235..cf8c3c61f2 100644 --- a/src/framework/ui/uiwidgetimage.cpp +++ b/src/framework/ui/uiwidgetimage.cpp @@ -192,7 +192,7 @@ void UIWidget::setImageSource(const std::string_view source, bool base64) m_imageTexture = g_textures.getTexture(m_imageSource = source, isImageSmooth()); if (base64) { std::stringstream stream; - std::string decoded = g_crypt.base64Decode(source); + const auto& decoded = g_crypt.base64Decode(source); stream.write(decoded.c_str(), decoded.size()); m_imageTexture = g_textures.loadTexture(stream); } From 1f5714716d77d7b9410e8976d92fb2e829bdc9c1 Mon Sep 17 00:00:00 2001 From: SkullzOTS <86809689+SkullzOTS@users.noreply.github.com> Date: Sun, 20 Aug 2023 11:05:45 -0300 Subject: [PATCH 11/16] Update uiwidget.h --- src/framework/ui/uiwidget.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/framework/ui/uiwidget.h b/src/framework/ui/uiwidget.h index 5553a8e163..0ce7e096fe 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, bool base64); + void setImageSource(const std::string_view source, bool base64 = false); 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(); } From 55b2c0995af4854c02ffd435184fbb2e83d48622 Mon Sep 17 00:00:00 2001 From: SkullzOTS <86809689+SkullzOTS@users.noreply.github.com> Date: Sun, 20 Aug 2023 11:13:06 -0300 Subject: [PATCH 12/16] Update uiwidgetimage.cpp --- src/framework/ui/uiwidgetimage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/framework/ui/uiwidgetimage.cpp b/src/framework/ui/uiwidgetimage.cpp index cf8c3c61f2..b542db7434 100644 --- a/src/framework/ui/uiwidgetimage.cpp +++ b/src/framework/ui/uiwidgetimage.cpp @@ -36,7 +36,7 @@ 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()), node->value()); + setImageSource(stdext::resolve_path(node->value(), node->source()), false); else if (node->tag() == "image-offset-x") setImageOffsetX(node->value()); else if (node->tag() == "image-offset-y") From 2c6d2b03b2b8ee6f76300cd392e3c70ea3839dcb Mon Sep 17 00:00:00 2001 From: SkullzOTS <86809689+SkullzOTS@users.noreply.github.com> Date: Sun, 20 Aug 2023 11:16:34 -0300 Subject: [PATCH 13/16] Update uiwidgetimage.cpp --- src/framework/ui/uiwidgetimage.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/framework/ui/uiwidgetimage.cpp b/src/framework/ui/uiwidgetimage.cpp index b542db7434..9e0cfc4ae1 100644 --- a/src/framework/ui/uiwidgetimage.cpp +++ b/src/framework/ui/uiwidgetimage.cpp @@ -37,6 +37,8 @@ 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()), 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") From bb9de410c69f16eff50365e74a2f41eea8500dea Mon Sep 17 00:00:00 2001 From: SkullzOTS <86809689+SkullzOTS@users.noreply.github.com> Date: Sun, 20 Aug 2023 11:19:33 -0300 Subject: [PATCH 14/16] Update uiwidget.h --- src/framework/ui/uiwidget.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/framework/ui/uiwidget.h b/src/framework/ui/uiwidget.h index 0ce7e096fe..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, bool base64 = false); + 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(); } From 9c143bf63f66fd2597a61aee5358325b4afd4856 Mon Sep 17 00:00:00 2001 From: SkullzOTS <86809689+SkullzOTS@users.noreply.github.com> Date: Sun, 20 Aug 2023 11:33:54 -0300 Subject: [PATCH 15/16] fix terminal error with base64 --- src/framework/ui/uiwidgetimage.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/framework/ui/uiwidgetimage.cpp b/src/framework/ui/uiwidgetimage.cpp index 9e0cfc4ae1..6421117a9d 100644 --- a/src/framework/ui/uiwidgetimage.cpp +++ b/src/framework/ui/uiwidgetimage.cpp @@ -191,13 +191,15 @@ void UIWidget::setImageSource(const std::string_view source, bool base64) 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; From 39f1fa8df65f3c554786d1b245ddfd542ff91721 Mon Sep 17 00:00:00 2001 From: SkullzOTS <86809689+SkullzOTS@users.noreply.github.com> Date: Sun, 20 Aug 2023 11:35:11 -0300 Subject: [PATCH 16/16] Update uiwidgetimage.cpp --- src/framework/ui/uiwidgetimage.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/framework/ui/uiwidgetimage.cpp b/src/framework/ui/uiwidgetimage.cpp index 6421117a9d..caa03534c4 100644 --- a/src/framework/ui/uiwidgetimage.cpp +++ b/src/framework/ui/uiwidgetimage.cpp @@ -197,8 +197,8 @@ void UIWidget::setImageSource(const std::string_view source, bool base64) stream.write(decoded.c_str(), decoded.size()); m_imageTexture = g_textures.loadTexture(stream); } else { - m_imageTexture = g_textures.getTexture(m_imageSource = source, isImageSmooth()); - } + m_imageTexture = g_textures.getTexture(m_imageSource = source, isImageSmooth()); + } if (!m_imageTexture) return;