From 63b908afb6e3c5fb88551c4f8dadbbf5e2742ab7 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 22 Oct 2019 01:00:39 +0200 Subject: [PATCH] Added "automatic_merge" property, and a "texture_merged" signal. --- texture_merger.cpp | 21 +++++++++++++++++++-- texture_merger.h | 5 +++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/texture_merger.cpp b/texture_merger.cpp index 989ba93..c66afc9 100644 --- a/texture_merger.cpp +++ b/texture_merger.cpp @@ -35,6 +35,13 @@ void TextureMerger::set_margin(const int margin) { _packer->set_margin(margin); } +bool TextureMerger::get_automatic_merge() const { + return _automatic_merge; +} +void TextureMerger::set_automatic_merge(const bool value) { + _automatic_merge = value; +} + Ref TextureMerger::get_packer() const { return _packer; } @@ -69,8 +76,8 @@ void TextureMerger::set_textures(const Vector &textures) { } } - if (texture_added) - _packer->merge(); + if (texture_added && _automatic_merge) + merge(); } Ref TextureMerger::add_texture(Ref texture) { @@ -126,9 +133,13 @@ int TextureMerger::get_generated_texture_count() { void TextureMerger::merge() { _packer->merge(); + + emit_signal("texture_merged"); } TextureMerger::TextureMerger() { + _automatic_merge = true; + _packer.instance(); _packer->set_keep_original_atlases(true); } @@ -138,6 +149,8 @@ TextureMerger::~TextureMerger() { } void TextureMerger::_bind_methods() { + ADD_SIGNAL(MethodInfo("texture_merged")); + ClassDB::bind_method(D_METHOD("get_texture_flags"), &TextureMerger::get_texture_flags); ClassDB::bind_method(D_METHOD("set_texture_flags", "flags"), &TextureMerger::set_texture_flags); ADD_PROPERTY(PropertyInfo(Variant::INT, "texture_flags", PROPERTY_HINT_FLAGS, "Mipmaps,Repeat,Filter,Anisotropic Linear,Convert to Linear,Mirrored Repeat,Video Surface"), "set_texture_flags", "get_texture_flags"); @@ -158,6 +171,10 @@ void TextureMerger::_bind_methods() { ClassDB::bind_method(D_METHOD("set_margin", "size"), &TextureMerger::set_margin); ADD_PROPERTY(PropertyInfo(Variant::INT, "margin"), "set_margin", "get_margin"); + ClassDB::bind_method(D_METHOD("get_automatic_merge"), &TextureMerger::get_automatic_merge); + ClassDB::bind_method(D_METHOD("set_automatic_merge", "value"), &TextureMerger::set_automatic_merge); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "automatic_merge"), "set_automatic_merge", "get_automatic_merge"); + ClassDB::bind_method(D_METHOD("get_textures"), &TextureMerger::get_textures); ClassDB::bind_method(D_METHOD("set_textures", "textures"), &TextureMerger::set_textures); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "textures", PROPERTY_HINT_NONE, "17/17:Texture", PROPERTY_USAGE_DEFAULT, "Texture"), "set_textures", "get_textures"); diff --git a/texture_merger.h b/texture_merger.h index eb88e8f..709006c 100644 --- a/texture_merger.h +++ b/texture_merger.h @@ -26,6 +26,9 @@ public: int get_margin() const; void set_margin(const int margin); + bool get_automatic_merge() const; + void set_automatic_merge(const bool value); + Ref get_packer() const; void set_packer(const Ref packer); @@ -57,6 +60,8 @@ protected: static void _bind_methods(); private: + bool _automatic_merge; + Ref _packer; Vector > _textures; };