From 759b2d47a5da7efa7d39bbeced562f040da58521 Mon Sep 17 00:00:00 2001 From: HJfod <60038575+HJfod@users.noreply.github.com> Date: Wed, 31 Jan 2024 23:43:42 +0200 Subject: [PATCH] forgot to add the new CopySizeLayout source file --- loader/src/cocos2d-ext/CopySizeLayout.cpp | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 loader/src/cocos2d-ext/CopySizeLayout.cpp 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(); +}