diff --git a/loader/src/cocos2d-ext/CopySizeLayout.cpp b/loader/src/cocos2d-ext/CopySizeLayout.cpp new file mode 100644 index 00000000..a8ed26b1 --- /dev/null +++ b/loader/src/cocos2d-ext/CopySizeLayout.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include +#include + +using namespace geode::prelude; + +CopySizeLayout* CopySizeLayout::create() { + auto ret = new CopySizeLayout(); + ret->m_targets = CCArray::create(); + ret->m_targets->retain(); + ret->autorelease(); + return ret; +} + +CopySizeLayout::~CopySizeLayout() { + m_targets->release(); +} + +CopySizeLayout* CopySizeLayout::add(CCNode* target) { + m_targets->addObject(target); + return this; +} + +CopySizeLayout* CopySizeLayout::remove(CCNode* target) { + m_targets->removeObject(target); + return this; +} + +void CopySizeLayout::apply(CCNode* in) { + AnchorLayout::apply(in); + for (auto& node : CCArrayExt(m_targets)) { + // Prevent accidental infinite loop + if (node == in) continue; + node->ignoreAnchorPointForPosition(false); + node->setContentSize(in->getContentSize()); + node->setPosition(in->getContentSize() / 2); + node->updateLayout(); + } +} + +CCSize CopySizeLayout::getSizeHint(CCNode* in) const { + return in->getContentSize(); +}