moved getCascadeBoundingBox() to utils

This commit is contained in:
SunLightJuly 2014-09-18 15:27:11 +08:00
parent 1af68e9274
commit 855d8d7a72
4 changed files with 49 additions and 48 deletions

View File

@ -803,49 +803,6 @@ Rect Node::getBoundingBox() const
return RectApplyAffineTransform(rect, getNodeToParentAffineTransform()); 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 // MARK: Children logic
// lazy allocs // lazy allocs

View File

@ -1079,11 +1079,6 @@ public:
/** @deprecated Use getBoundingBox instead */ /** @deprecated Use getBoundingBox instead */
CC_DEPRECATED_ATTRIBUTE inline virtual Rect boundingBox() const { return getBoundingBox(); } 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 void setEventDispatcher(EventDispatcher* dispatcher);
virtual EventDispatcher* getEventDispatcher() const { return _eventDispatcher; }; virtual EventDispatcher* getEventDispatcher() const { return _eventDispatcher; };

View File

@ -192,6 +192,50 @@ double gettime()
return (double)tv.tv_sec + (double)tv.tv_usec/1000000; 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 NS_CC_END

View File

@ -82,6 +82,11 @@ namespace utils
/** Get current exact time, accurate to nanoseconds. /** Get current exact time, accurate to nanoseconds.
*/ */
double CC_DLL gettime(); double CC_DLL gettime();
/**
* calculate all children's boundingBox
*/
Rect getCascadeBoundingBox(Node *node);
} }
NS_CC_END NS_CC_END