mirror of https://github.com/axmolengine/axmol.git
moved getCascadeBoundingBox() to utils
This commit is contained in:
parent
1af68e9274
commit
855d8d7a72
|
@ -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<Node*>(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
|
||||
|
|
|
@ -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; };
|
||||
|
||||
|
|
|
@ -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<Node*>(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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue