mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-22 23:48:08 -05:00
forgot to add the new CopySizeLayout source file
This commit is contained in:
parent
f53c02491a
commit
759b2d47a5
1 changed files with 46 additions and 0 deletions
46
loader/src/cocos2d-ext/CopySizeLayout.cpp
Normal file
46
loader/src/cocos2d-ext/CopySizeLayout.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
#include <cocos2d.h>
|
||||
#include <Geode/utils/cocos.hpp>
|
||||
#include <Geode/utils/ranges.hpp>
|
||||
#include <Geode/loader/Log.hpp>
|
||||
#include <Geode/binding/CCMenuItemSpriteExtra.hpp>
|
||||
#include <Geode/binding/CCMenuItemToggler.hpp>
|
||||
|
||||
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<CCNode*>(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();
|
||||
}
|
Loading…
Reference in a new issue