add CCNode::setScaledContentSize, CCNode::getScaledContentWidth etc.

This commit is contained in:
HJfod 2024-03-02 13:36:06 +02:00
parent 6414737b0c
commit be0880f49c
2 changed files with 27 additions and 0 deletions

View file

@ -1054,10 +1054,23 @@ public:
*/
GEODE_DLL void swapChildIndices(CCNode* first, CCNode* second);
/**
* @note Make sure to set the scale first!
* @note Geode addition
*/
GEODE_DLL void setScaledContentSize(CCSize const& size);
// @note Geode addition
GEODE_DLL void setContentWidth(float width);
// @note Geode addition
GEODE_DLL void setContentHeight(float width);
// @note Geode addition
GEODE_DLL float getContentWidth() const;
// @note Geode addition
GEODE_DLL float getContentHeight() const;
// @note Geode addition
GEODE_DLL float getScaledContentWidth() const;
// @note Geode addition
GEODE_DLL float getScaledContentHeight() const;
template <class Filter, class... Args>
geode::EventListenerProtocol* addEventListener(

View file

@ -50,6 +50,10 @@ bool CCNode::hasAncestor(CCNode* ancestor) {
// these use setContentSize and getContentSize because they're virtuals and
// some node may override those for wacky behaviour
void CCNode::setScaledContentSize(CCSize const& size) {
this->setContentSize({ size.width / m_fScaleX, size.height / m_fScaleY });
}
void CCNode::setContentWidth(float width) {
this->setContentSize({ width, m_obContentSize.height });
}
@ -66,6 +70,16 @@ float CCNode::getContentHeight() const {
return this->getContentSize().height;
}
// getScaledContentSize is not const bruh
float CCNode::getScaledContentWidth() const {
return this->getContentWidth() * m_fScaleX;
}
float CCNode::getScaledContentHeight() const {
return this->getContentHeight() * m_fScaleY;
}
CCArray* Layout::getNodesToPosition(CCNode* on) const {
auto arr = CCArray::create();
for (auto child : CCArrayExt<CCNode*>(on->getChildren())) {