1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- #include "CCNode+REDRelativePositioning.h"
- #include "REDReader.h"
- using namespace cocos2d;
- namespace redream {
- CC_DLL Vec2 getAbsolutePosition(const Vec2 &pt, REDReader::PositionType type, const Size &containerSize, const std::string& /*propName*/)
- {
- Vec2 absPt;
- if (type == REDReader::PositionType::RELATIVE_BOTTOM_LEFT)
- {
- absPt = pt;
- }
- else if (type == REDReader::PositionType::RELATIVE_TOP_LEFT)
- {
- absPt.x = pt.x;
- absPt.y = containerSize.height - pt.y;
- }
- else if (type == REDReader::PositionType::RELATIVE_TOP_RIGHT)
- {
- absPt.x = containerSize.width - pt.x;
- absPt.y = containerSize.height - pt.y;
- }
- else if (type == REDReader::PositionType::RELATIVE_BOTTOM_RIGHT)
- {
- absPt.x = containerSize.width - pt.x;
- absPt.y = pt.y;
- }
- else if (type == REDReader::PositionType::PERCENT)
- {
- absPt.x = (int)(containerSize.width * pt.x / 100.0f);
- absPt.y = (int)(containerSize.height * pt.y / 100.0f);
- }
- else if (type == REDReader::PositionType::MULTIPLY_RESOLUTION)
- {
- float resolutionScale = REDReader::getResolutionScale();
-
- absPt.x = pt.x * resolutionScale;
- absPt.y = pt.y * resolutionScale;
- }
-
- return absPt;
- }
- CC_DLL void setRelativeScale(Node *pNode, float scaleX, float scaleY, REDReader::ScaleType type, const std::string& /*propName*/)
- {
- CCASSERT(pNode, "pNode should not be null");
-
- // if (type == REDReader::ScaleType::MULTIPLY_RESOLUTION)
- // {
- // float resolutionScale = REDReader::getResolutionScale();
- //
- // scaleX *= resolutionScale;
- // scaleY *= resolutionScale;
- // }
-
- pNode->setScaleX(scaleX);
- pNode->setScaleY(scaleY);
- }
- }
|