aboutsummaryrefslogtreecommitdiff
path: root/extension/src/openvic-extension/singletons/AssetManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'extension/src/openvic-extension/singletons/AssetManager.cpp')
-rw-r--r--extension/src/openvic-extension/singletons/AssetManager.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/extension/src/openvic-extension/singletons/AssetManager.cpp b/extension/src/openvic-extension/singletons/AssetManager.cpp
index d17edd0..3b37c8c 100644
--- a/extension/src/openvic-extension/singletons/AssetManager.cpp
+++ b/extension/src/openvic-extension/singletons/AssetManager.cpp
@@ -120,6 +120,29 @@ Ref<ImageTexture> AssetManager::get_texture(StringName const& path, LoadFlags lo
}
}
+Ref<StyleBoxTexture> AssetManager::make_stylebox_texture(Ref<Texture2D> const& texture, Vector2 const& border) {
+ ERR_FAIL_NULL_V(texture, nullptr);
+
+ Ref<StyleBoxTexture> stylebox;
+ stylebox.instantiate();
+ ERR_FAIL_NULL_V(stylebox, nullptr);
+
+ stylebox->set_texture(texture);
+
+ static const StringName changed_signal = "changed";
+ static const StringName emit_changed_func = "emit_changed";
+ texture->connect(changed_signal, Callable { *stylebox, emit_changed_func }, Object::CONNECT_PERSIST);
+
+ if (border != Vector2 {}) {
+ stylebox->set_texture_margin(SIDE_LEFT, border.x);
+ stylebox->set_texture_margin(SIDE_RIGHT, border.x);
+ stylebox->set_texture_margin(SIDE_TOP, border.y);
+ stylebox->set_texture_margin(SIDE_BOTTOM, border.y);
+ }
+
+ return stylebox;
+}
+
Ref<FontFile> AssetManager::get_font(StringName const& name) {
const font_map_t::const_iterator it = fonts.find(name);
if (it != fonts.end()) {