diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index 7811874c87..1dbf638b41 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -803,49 +803,6 @@ Rect Node::getBoundingBox() const return RectApplyAffineTransform(rect, getNodeToParentAffineTransform()); } -Rect Node::getCascadeBoundingBox(void) -{ - Rect cbb; - - // check all childrens bounding box, get maximize box - Node* child = nullptr; - bool merge = false; - for(auto object : _children) - { - child = dynamic_cast(object); - if (!child->isVisible()) continue; - - const Rect box = child->getCascadeBoundingBox(); - if (box.size.width <= 0 || box.size.height <= 0) continue; - - if (!merge) - { - cbb = box; - merge = true; - } - else - { - cbb.merge(box); - } - } - - // merge content size - if (_contentSize.width > 0 && _contentSize.height > 0) - { - const Rect box = RectApplyAffineTransform(Rect(0, 0, _contentSize.width, _contentSize.height), nodeToWorldTransform()); - if (!merge) - { - cbb = box; - } - else - { - cbb.merge(box); - } - } - - return cbb; -} - // MARK: Children logic // lazy allocs diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index 839e155331..d2a6034633 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -1079,11 +1079,6 @@ public: /** @deprecated Use getBoundingBox instead */ CC_DEPRECATED_ATTRIBUTE inline virtual Rect boundingBox() const { return getBoundingBox(); } - /** - * This boundingBox will calculate all children's boundingBox every time - */ - virtual Rect getCascadeBoundingBox(void); - virtual void setEventDispatcher(EventDispatcher* dispatcher); virtual EventDispatcher* getEventDispatcher() const { return _eventDispatcher; }; diff --git a/cocos/base/ccUtils.cpp b/cocos/base/ccUtils.cpp index b304b95751..5a2c64be14 100644 --- a/cocos/base/ccUtils.cpp +++ b/cocos/base/ccUtils.cpp @@ -192,6 +192,50 @@ double gettime() return (double)tv.tv_sec + (double)tv.tv_usec/1000000; } +Rect getCascadeBoundingBox(Node *node) +{ + Rect cbb; + Size contentSize = node->getContentSize(); + + // check all childrens bounding box, get maximize box + Node* child = nullptr; + bool merge = false; + for(auto object : node->getChildren()) + { + child = dynamic_cast(object); + if (!child->isVisible()) continue; + + const Rect box = child->getCascadeBoundingBox(); + if (box.size.width <= 0 || box.size.height <= 0) continue; + + if (!merge) + { + cbb = box; + merge = true; + } + else + { + cbb.merge(box); + } + } + + // merge content size + if (contentSize.width > 0 && contentSize.height > 0) + { + const Rect box = RectApplyAffineTransform(Rect(0, 0, contentSize.width, contentSize.height), node->getNodeToWorldAffineTransform()); + if (!merge) + { + cbb = box; + } + else + { + cbb.merge(box); + } + } + + return cbb; +} + } NS_CC_END diff --git a/cocos/base/ccUtils.h b/cocos/base/ccUtils.h index ba5dabbe15..2f4170127e 100644 --- a/cocos/base/ccUtils.h +++ b/cocos/base/ccUtils.h @@ -82,6 +82,11 @@ namespace utils /** Get current exact time, accurate to nanoseconds. */ double CC_DLL gettime(); + + /** + * calculate all children's boundingBox + */ + Rect getCascadeBoundingBox(Node *node); } NS_CC_END