2012-09-17 14:27:17 +08:00
|
|
|
#include "CCNode+CCBRelativePositioning.h"
|
|
|
|
#include "CCBReader.h"
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
using namespace cocos2d;
|
|
|
|
|
|
|
|
namespace cocosbuilder {
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2014-04-15 18:13:57 +08:00
|
|
|
Vector2 getAbsolutePosition(const Vector2 &pt, CCBReader::PositionType type, const Size &containerSize, const std::string& propName)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2014-04-15 18:13:57 +08:00
|
|
|
Vector2 absPt = Vector2(0,0);
|
2013-07-27 21:44:49 +08:00
|
|
|
if (type == CCBReader::PositionType::RELATIVE_BOTTOM_LEFT)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
absPt = pt;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (type == CCBReader::PositionType::RELATIVE_TOP_LEFT)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
absPt.x = pt.x;
|
|
|
|
absPt.y = containerSize.height - pt.y;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (type == CCBReader::PositionType::RELATIVE_TOP_RIGHT)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
absPt.x = containerSize.width - pt.x;
|
|
|
|
absPt.y = containerSize.height - pt.y;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (type == CCBReader::PositionType::RELATIVE_BOTTOM_RIGHT)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
absPt.x = containerSize.width - pt.x;
|
|
|
|
absPt.y = pt.y;
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (type == CCBReader::PositionType::PERCENT)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
absPt.x = (int)(containerSize.width * pt.x / 100.0f);
|
|
|
|
absPt.y = (int)(containerSize.height * pt.y / 100.0f);
|
|
|
|
}
|
2013-07-27 21:44:49 +08:00
|
|
|
else if (type == CCBReader::PositionType::MULTIPLY_RESOLUTION)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
float resolutionScale = CCBReader::getResolutionScale();
|
|
|
|
|
|
|
|
absPt.x = pt.x * resolutionScale;
|
|
|
|
absPt.y = pt.y * resolutionScale;
|
|
|
|
}
|
|
|
|
|
|
|
|
return absPt;
|
|
|
|
}
|
|
|
|
|
2013-12-09 17:45:24 +08:00
|
|
|
void setRelativeScale(Node *pNode, float scaleX, float scaleY, CCBReader::ScaleType type, const std::string& propName)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(pNode, "pNode should not be null");
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
if (type == CCBReader::ScaleType::MULTIPLY_RESOLUTION)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
float resolutionScale = CCBReader::getResolutionScale();
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
scaleX *= resolutionScale;
|
|
|
|
scaleY *= resolutionScale;
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:44:49 +08:00
|
|
|
pNode->setScaleX(scaleX);
|
|
|
|
pNode->setScaleY(scaleY);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
}
|