mirror of https://github.com/axmolengine/axmol.git
Sync LayoutHelper APIs
This commit is contained in:
parent
c596975a93
commit
6be52c29e7
|
@ -80,7 +80,7 @@ set(COCOS_UI_HEADER
|
|||
ui/UIAbstractCheckButton.h
|
||||
ui/UIButton.h
|
||||
ui/UICheckBox.h
|
||||
# ui/UIDeprecated.h
|
||||
ui/LayoutHelper.h
|
||||
ui/UIHBox.h
|
||||
ui/UIHelper.h
|
||||
ui/UIImageView.h
|
||||
|
@ -115,7 +115,7 @@ set(COCOS_UI_SRC
|
|||
ui/UIAbstractCheckButton.cpp
|
||||
ui/UICheckBox.cpp
|
||||
ui/UIRadioButton.cpp
|
||||
# ui/UIDeprecated.cpp
|
||||
ui/LayoutHelper.cpp
|
||||
ui/UIHBox.cpp
|
||||
ui/UIHelper.cpp
|
||||
ui/UIImageView.cpp
|
||||
|
|
|
@ -1,156 +1,16 @@
|
|||
//
|
||||
//
|
||||
// Copyright (c) 2014-2020 Simdsoft Limited - All Rights Reserved
|
||||
//
|
||||
#include "LayoutHelper.h"
|
||||
#include "ui/LayoutHelper.h"
|
||||
|
||||
namespace LayoutHelper {
|
||||
cocos2d::Rect ScreenVisibleRect::s_ScreenVisibleRect;
|
||||
USING_NS_CC;
|
||||
|
||||
/// x-studio365: when design resolution changed, should call this func.
|
||||
void ScreenVisibleRect::refresh(void)
|
||||
Size LayoutHelper::s_designSize;
|
||||
float LayoutHelper::s_adjustedScale = 1.0f;
|
||||
|
||||
void LayoutHelper::setDesignSizeFixedEdge(const Size& designSize)
|
||||
{
|
||||
auto director = Director::getInstance();
|
||||
s_ScreenVisibleRect.origin = Director::getInstance()->getVisibleOrigin();
|
||||
s_ScreenVisibleRect.size = Director::getInstance()->getVisibleSize();
|
||||
}
|
||||
|
||||
void ScreenVisibleRect::lazyInit()
|
||||
{
|
||||
if (s_ScreenVisibleRect.size.width == 0.0f && s_ScreenVisibleRect.size.height == 0.0f)
|
||||
{
|
||||
auto director = Director::getInstance();
|
||||
auto glview = director->getOpenGLView();
|
||||
|
||||
if (glview->getResolutionPolicy() == ResolutionPolicy::NO_BORDER) {
|
||||
s_ScreenVisibleRect.origin = director->getVisibleOrigin();
|
||||
s_ScreenVisibleRect.size = director->getVisibleSize();
|
||||
}
|
||||
else {
|
||||
s_ScreenVisibleRect.origin = nodes_layout::getVisibleOrigin();
|
||||
s_ScreenVisibleRect.size = nodes_layout::getVisibleSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cocos2d::Rect ScreenVisibleRect::getScreenVisibleRect()
|
||||
{
|
||||
lazyInit();
|
||||
return cocos2d::Rect(s_ScreenVisibleRect.origin.x, s_ScreenVisibleRect.origin.y, s_ScreenVisibleRect.size.width, s_ScreenVisibleRect.size.height);
|
||||
}
|
||||
|
||||
cocos2d::Size ScreenVisibleRect::size()
|
||||
{
|
||||
lazyInit();
|
||||
return s_ScreenVisibleRect.size;
|
||||
}
|
||||
|
||||
Point ScreenVisibleRect::left()
|
||||
{
|
||||
lazyInit();
|
||||
return cocos2d::Point(s_ScreenVisibleRect.origin.x, s_ScreenVisibleRect.origin.y + s_ScreenVisibleRect.size.height / 2);
|
||||
}
|
||||
|
||||
Point ScreenVisibleRect::right()
|
||||
{
|
||||
lazyInit();
|
||||
return cocos2d::Point(s_ScreenVisibleRect.origin.x + s_ScreenVisibleRect.size.width, s_ScreenVisibleRect.origin.y + s_ScreenVisibleRect.size.height / 2);
|
||||
}
|
||||
|
||||
Point ScreenVisibleRect::top()
|
||||
{
|
||||
lazyInit();
|
||||
return cocos2d::Point(s_ScreenVisibleRect.origin.x + s_ScreenVisibleRect.size.width / 2, s_ScreenVisibleRect.origin.y + s_ScreenVisibleRect.size.height);
|
||||
}
|
||||
|
||||
Point ScreenVisibleRect::bottom()
|
||||
{
|
||||
lazyInit();
|
||||
return cocos2d::Point(s_ScreenVisibleRect.origin.x + s_ScreenVisibleRect.size.width / 2, s_ScreenVisibleRect.origin.y);
|
||||
}
|
||||
|
||||
Point ScreenVisibleRect::center()
|
||||
{
|
||||
lazyInit();
|
||||
return cocos2d::Point(s_ScreenVisibleRect.origin.x + s_ScreenVisibleRect.size.width / 2, s_ScreenVisibleRect.origin.y + s_ScreenVisibleRect.size.height / 2);
|
||||
}
|
||||
|
||||
Point ScreenVisibleRect::leftTop()
|
||||
{
|
||||
lazyInit();
|
||||
return cocos2d::Point(s_ScreenVisibleRect.origin.x, s_ScreenVisibleRect.origin.y + s_ScreenVisibleRect.size.height);
|
||||
}
|
||||
|
||||
Point ScreenVisibleRect::rightTop()
|
||||
{
|
||||
lazyInit();
|
||||
return cocos2d::Point(s_ScreenVisibleRect.origin.x + s_ScreenVisibleRect.size.width, s_ScreenVisibleRect.origin.y + s_ScreenVisibleRect.size.height);
|
||||
}
|
||||
|
||||
Point ScreenVisibleRect::leftBottom()
|
||||
{
|
||||
lazyInit();
|
||||
return s_ScreenVisibleRect.origin;
|
||||
}
|
||||
|
||||
Point ScreenVisibleRect::rightBottom()
|
||||
{
|
||||
lazyInit();
|
||||
return cocos2d::Point(s_ScreenVisibleRect.origin.x + s_ScreenVisibleRect.size.width, s_ScreenVisibleRect.origin.y);
|
||||
}
|
||||
|
||||
const cocos2d::Point nodes_layout::ANCHOR_CENTER = cocos2d::Point(0.5, 0.5); // center
|
||||
const cocos2d::Point nodes_layout::ANCHOR_LB = cocos2d::Point(0.0f, 0.0f); // left bottom,
|
||||
const cocos2d::Point nodes_layout::ANCHOR_LT = cocos2d::Point(0.0f, 1.0f); // left top
|
||||
const cocos2d::Point nodes_layout::ANCHOR_RB = cocos2d::Point(1.0f, 0.0f); // rigth bottom
|
||||
const cocos2d::Point nodes_layout::ANCHOR_RT = cocos2d::Point(1.0f, 1.0f); // rigth top
|
||||
|
||||
float nodes_layout::adjustedScale = 1.0f;
|
||||
cocos2d::Size nodes_layout::designSize;
|
||||
|
||||
//cocos2d::Size nodes_layout::getScreenSize(void)
|
||||
//{
|
||||
// return nodes_layout::designSize * nodes_layout::adjustedScale;
|
||||
//}
|
||||
//
|
||||
//cocos2d::Vec2 nodes_layout::getSceenOffset(cocos2d::Point anchor)
|
||||
//{
|
||||
// float offsetX = anchor.x * (nodes_layout::getScreenSize().width - nodes_layout::designSize.width);
|
||||
// float offsetY = anchor.y * (nodes_layout::getScreenSize().height - nodes_layout::designSize.height);
|
||||
// return cocos2d::Vec2(offsetX, offsetY);
|
||||
//}
|
||||
|
||||
void nodes_layout::setDesignSizeNoBorder(const cocos2d::Size& designSize)
|
||||
{
|
||||
// save smart size
|
||||
nodes_layout::designSize = designSize;
|
||||
|
||||
// Set the design resolution//·Ö±æÂʵĴóС
|
||||
GLView* pEGLView = Director::getInstance()->getOpenGLView();
|
||||
const cocos2d::Size& frameSize = pEGLView->getFrameSize();
|
||||
|
||||
// Size lsSize = lsaSize;
|
||||
|
||||
float scaleX = (float)frameSize.width / nodes_layout::designSize.width;
|
||||
float scaleY = (float)frameSize.height / nodes_layout::designSize.height;
|
||||
|
||||
adjustedScale = 0.0f; // MAX(scaleX, scaleY);
|
||||
if (scaleX > scaleY) {
|
||||
adjustedScale = scaleX / (frameSize.height / nodes_layout::designSize.height);
|
||||
}
|
||||
else {
|
||||
adjustedScale = scaleY / (frameSize.width / nodes_layout::designSize.width);
|
||||
}
|
||||
|
||||
cocos2d::log("x: %f; y: %f; scale: %f", scaleX, scaleY, adjustedScale);
|
||||
|
||||
pEGLView->setDesignResolutionSize(nodes_layout::designSize.width * adjustedScale,
|
||||
nodes_layout::designSize.height * adjustedScale, ResolutionPolicy::NO_BORDER);
|
||||
}
|
||||
|
||||
void nodes_layout::setDesignSizeFixedEdge(const Size& designSize)
|
||||
{
|
||||
nodes_layout::designSize = designSize;
|
||||
LayoutHelper::s_designSize = designSize;
|
||||
|
||||
// Set the design resolution//分辨率的大小
|
||||
GLView* pEGLView = Director::getInstance()->getOpenGLView();
|
||||
|
@ -172,20 +32,48 @@ void nodes_layout::setDesignSizeFixedEdge(const Size& designSize)
|
|||
}
|
||||
}
|
||||
|
||||
cocos2d::Vec2 nodes_layout::getVisibleOrigin(void)
|
||||
void LayoutHelper::setDesignSizeNoBorder(const cocos2d::Size& designSize)
|
||||
{
|
||||
const auto& adjustedDesignSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize();
|
||||
return cocos2d::Vec2((adjustedDesignSize.width - nodes_layout::designSize.width) * .5f,
|
||||
(adjustedDesignSize.height - nodes_layout::designSize.height) * .5f);
|
||||
// save smart size
|
||||
LayoutHelper::s_designSize = designSize;
|
||||
|
||||
// Set the design resolution//·Ö±æÂʵĴóС
|
||||
GLView* pEGLView = Director::getInstance()->getOpenGLView();
|
||||
const cocos2d::Size& frameSize = pEGLView->getFrameSize();
|
||||
|
||||
// Size lsSize = lsaSize;
|
||||
|
||||
float scaleX = (float)frameSize.width / LayoutHelper::s_designSize.width;
|
||||
float scaleY = (float)frameSize.height / LayoutHelper::s_designSize.height;
|
||||
|
||||
LayoutHelper::s_adjustedScale = 0.0f; // MAX(scaleX, scaleY);
|
||||
if (scaleX > scaleY) {
|
||||
LayoutHelper::s_adjustedScale = scaleX / (frameSize.height / LayoutHelper::s_designSize.height);
|
||||
}
|
||||
else {
|
||||
LayoutHelper::s_adjustedScale = scaleY / (frameSize.width / LayoutHelper::s_designSize.width);
|
||||
}
|
||||
|
||||
cocos2d::Size nodes_layout::getVisibleSize(void)
|
||||
cocos2d::log("x: %f; y: %f; scale: %f", scaleX, scaleY, s_adjustedScale);
|
||||
|
||||
pEGLView->setDesignResolutionSize(LayoutHelper::s_designSize.width * s_adjustedScale,
|
||||
LayoutHelper::s_designSize.height * s_adjustedScale, ResolutionPolicy::NO_BORDER);
|
||||
}
|
||||
|
||||
cocos2d::Vec2 LayoutHelper::getVisibleOrigin(void)
|
||||
{
|
||||
return nodes_layout::designSize;
|
||||
const auto& adjustedDesignSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize();
|
||||
return cocos2d::Vec2((adjustedDesignSize.width - LayoutHelper::s_designSize.width) * .5f,
|
||||
(adjustedDesignSize.height - LayoutHelper::s_designSize.height) * .5f);
|
||||
}
|
||||
|
||||
cocos2d::Size LayoutHelper::getVisibleSize(void)
|
||||
{
|
||||
return LayoutHelper::s_designSize;
|
||||
}
|
||||
|
||||
/// Get node group size
|
||||
Size nodes_layout::getNodeGroupSize(const std::vector<Node*>& nodes)
|
||||
Size LayoutHelper::getNodeGroupSize(const std::vector<Node*>& nodes)
|
||||
{
|
||||
if (nodes.empty())
|
||||
{
|
||||
|
@ -225,7 +113,7 @@ Size nodes_layout::getNodeGroupSize(const std::vector<Node*>& nodes)
|
|||
}
|
||||
|
||||
/// Set nodes group size
|
||||
void nodes_layout::setNodeGroupSize(const std::vector<Node*>& nodes, const cocos2d::Size& newSize)
|
||||
void LayoutHelper::setNodeGroupSize(const std::vector<Node*>& nodes, const cocos2d::Size& newSize)
|
||||
{
|
||||
cocos2d::Size groupSize = getNodeGroupScaledSize(nodes);
|
||||
if (groupSize.height == 0 || groupSize.width == 0 || newSize.width == 0 || newSize.height == 0)
|
||||
|
@ -256,7 +144,7 @@ void nodes_layout::setNodeGroupSize(const std::vector<Node*>& nodes, const coc
|
|||
}
|
||||
}
|
||||
|
||||
Size nodes_layout::getNodeGroupScaledSize(const std::vector<Node*>& nodes)
|
||||
Size LayoutHelper::getNodeGroupScaledSize(const std::vector<Node*>& nodes)
|
||||
{
|
||||
if (nodes.empty())
|
||||
{
|
||||
|
@ -266,8 +154,8 @@ Size nodes_layout::getNodeGroupScaledSize(const std::vector<Node*>& nodes)
|
|||
auto scale = getScale2D(nodes[0]);
|
||||
|
||||
// group nodes locators
|
||||
float minX = nodes_layout::getNodeLeft(nodes[0]), maxX = nodes_layout::getNodeLeft(nodes[0]) + nodes[0]->getContentSize().width * scale.x;
|
||||
float minY = nodes_layout::getNodeTop(nodes[0]), maxY = nodes_layout::getNodeTop(nodes[0]) + nodes[0]->getContentSize().height * scale.y;
|
||||
float minX = LayoutHelper::getNodeLeft(nodes[0]), maxX = LayoutHelper::getNodeLeft(nodes[0]) + nodes[0]->getContentSize().width * scale.x;
|
||||
float minY = LayoutHelper::getNodeTop(nodes[0]), maxY = LayoutHelper::getNodeTop(nodes[0]) + nodes[0]->getContentSize().height * scale.y;
|
||||
float x = 0.0f, y = 0.0f;
|
||||
// float width = 0.0f, height = 0.f;
|
||||
for (size_t index = 1; index < nodes.size(); ++index) {
|
||||
|
@ -275,7 +163,7 @@ Size nodes_layout::getNodeGroupScaledSize(const std::vector<Node*>& nodes)
|
|||
|
||||
scale = getScale2D(child);
|
||||
|
||||
if (minX >(x = nodes_layout::getNodeLeft(child)))
|
||||
if (minX >(x = LayoutHelper::getNodeLeft(child)))
|
||||
{
|
||||
minX = x;
|
||||
}
|
||||
|
@ -284,7 +172,7 @@ Size nodes_layout::getNodeGroupScaledSize(const std::vector<Node*>& nodes)
|
|||
maxX = x + child->getContentSize().width * scale.x;
|
||||
}
|
||||
|
||||
if (minY >(y = nodes_layout::getNodeTop(child)))
|
||||
if (minY >(y = LayoutHelper::getNodeTop(child)))
|
||||
{
|
||||
minY = y;
|
||||
}
|
||||
|
@ -301,7 +189,7 @@ Size nodes_layout::getNodeGroupScaledSize(const std::vector<Node*>& nodes)
|
|||
}
|
||||
|
||||
/// Get Node group left
|
||||
float nodes_layout::getNodeGroupLeft(const std::vector<Node*>& nodes)
|
||||
float LayoutHelper::getNodeGroupLeft(const std::vector<Node*>& nodes)
|
||||
{
|
||||
size_t index = 0;
|
||||
float minLeft = getNodeLeft(nodes[index]);
|
||||
|
@ -316,7 +204,7 @@ float nodes_layout::getNodeGroupLeft(const std::vector<Node*>& nodes)
|
|||
}
|
||||
|
||||
/// Get node group top
|
||||
float nodes_layout::getNodeGroupTop(const std::vector<Node*>& nodes)
|
||||
float LayoutHelper::getNodeGroupTop(const std::vector<Node*>& nodes)
|
||||
{
|
||||
size_t index = 0;
|
||||
float minTop = getNodeTop(nodes[index]);
|
||||
|
@ -331,7 +219,7 @@ float nodes_layout::getNodeGroupTop(const std::vector<Node*>& nodes)
|
|||
}
|
||||
|
||||
/// Get node group right
|
||||
float nodes_layout::getNodeGroupRight(const std::vector<Node*>& nodes)
|
||||
float LayoutHelper::getNodeGroupRight(const std::vector<Node*>& nodes)
|
||||
{
|
||||
size_t index = 0;
|
||||
float minRight = getNodeRight(nodes[index]);
|
||||
|
@ -346,7 +234,7 @@ float nodes_layout::getNodeGroupRight(const std::vector<Node*>& nodes)
|
|||
}
|
||||
|
||||
/// Get node group bottom
|
||||
float nodes_layout::getNodeGroupBottom(const std::vector<Node*>& nodes)
|
||||
float LayoutHelper::getNodeGroupBottom(const std::vector<Node*>& nodes)
|
||||
{
|
||||
size_t index = 0;
|
||||
float minBottom = getNodeBottom(nodes[index]);
|
||||
|
@ -364,7 +252,7 @@ float nodes_layout::getNodeGroupBottom(const std::vector<Node*>& nodes)
|
|||
** setNodeGroupLeft
|
||||
**
|
||||
*/
|
||||
void nodes_layout::setNodeGroupLeft(const std::vector<Node*>& nodes, float left)
|
||||
void LayoutHelper::setNodeGroupLeft(const std::vector<Node*>& nodes, float left)
|
||||
{
|
||||
float delta = left - getNodeGroupLeft(nodes);
|
||||
|
||||
|
@ -378,7 +266,7 @@ void nodes_layout::setNodeGroupLeft(const std::vector<Node*>& nodes, float left)
|
|||
** setNodeGroupLeft
|
||||
**
|
||||
*/
|
||||
void nodes_layout::setNodeGroupTop(const std::vector<Node*>& nodes, float top)
|
||||
void LayoutHelper::setNodeGroupTop(const std::vector<Node*>& nodes, float top)
|
||||
{
|
||||
float delta = top - getNodeGroupTop(nodes);
|
||||
|
||||
|
@ -388,7 +276,7 @@ void nodes_layout::setNodeGroupTop(const std::vector<Node*>& nodes, float top)
|
|||
}
|
||||
}
|
||||
|
||||
void nodes_layout::setNodeGroupLT(const std::vector<Node*>& nodes, const cocos2d::Vec2& p)
|
||||
void LayoutHelper::setNodeGroupLT(const std::vector<Node*>& nodes, const cocos2d::Vec2& p)
|
||||
{
|
||||
float deltaL = p.x - getNodeGroupLeft(nodes);
|
||||
float deltaT = p.y - getNodeGroupTop(nodes);
|
||||
|
@ -403,7 +291,7 @@ void nodes_layout::setNodeGroupLT(const std::vector<Node*>& nodes, const cocos2d
|
|||
** setNodeGroupRight
|
||||
**
|
||||
*/
|
||||
void nodes_layout::setNodeGroupRight(const std::vector<Node*>& nodes, float right)
|
||||
void LayoutHelper::setNodeGroupRight(const std::vector<Node*>& nodes, float right)
|
||||
{
|
||||
float delta = right - getNodeGroupRight(nodes);
|
||||
|
||||
|
@ -417,7 +305,7 @@ void nodes_layout::setNodeGroupRight(const std::vector<Node*>& nodes, float righ
|
|||
** setNodeGroupRight
|
||||
**
|
||||
*/
|
||||
void nodes_layout::setNodeGroupBottom(const std::vector<Node*>& nodes, float bottom)
|
||||
void LayoutHelper::setNodeGroupBottom(const std::vector<Node*>& nodes, float bottom)
|
||||
{
|
||||
float delta = bottom - getNodeGroupBottom(nodes);
|
||||
|
||||
|
@ -427,7 +315,7 @@ void nodes_layout::setNodeGroupBottom(const std::vector<Node*>& nodes, float bot
|
|||
}
|
||||
}
|
||||
|
||||
void nodes_layout::moveNodeGroupHorizontally(const std::vector<Node*>& nodes, float delta)
|
||||
void LayoutHelper::moveNodeGroupHorizontally(const std::vector<Node*>& nodes, float delta)
|
||||
{
|
||||
for (auto node : nodes)
|
||||
{
|
||||
|
@ -435,7 +323,7 @@ void nodes_layout::moveNodeGroupHorizontally(const std::vector<Node*>& nodes, fl
|
|||
}
|
||||
}
|
||||
|
||||
void nodes_layout::moveNodeGroupVertically(const std::vector<Node*>& nodes, float delta)
|
||||
void LayoutHelper::moveNodeGroupVertically(const std::vector<Node*>& nodes, float delta)
|
||||
{
|
||||
for (auto node : nodes)
|
||||
{
|
||||
|
@ -450,7 +338,7 @@ void nodes_layout::moveNodeGroupVertically(const std::vector<Node*>& nodes, floa
|
|||
/// 水平居中
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
void nodes_layout::centerHorizontally(const std::vector<Node*>& nodes)
|
||||
void LayoutHelper::centerHorizontally(const std::vector<Node*>& nodes)
|
||||
{
|
||||
if (nodes.empty())
|
||||
{
|
||||
|
@ -508,7 +396,7 @@ void nodes_layout::centerHorizontally(const std::vector<Node*>& nodes)
|
|||
/// 垂直居中
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
void nodes_layout::centerVertically(const std::vector<Node*>& nodes)
|
||||
void LayoutHelper::centerVertically(const std::vector<Node*>& nodes)
|
||||
{
|
||||
if (nodes.empty())
|
||||
{
|
||||
|
@ -552,7 +440,7 @@ void nodes_layout::centerVertically(const std::vector<Node*>& nodes)
|
|||
/// 居中
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
void nodes_layout::centerHoriVerti(const std::vector<Node*>& nodes)
|
||||
void LayoutHelper::centerToParent(const std::vector<Node*>& nodes)
|
||||
{
|
||||
if (nodes.empty())
|
||||
{
|
||||
|
@ -560,7 +448,7 @@ void nodes_layout::centerHoriVerti(const std::vector<Node*>& nodes)
|
|||
}
|
||||
else if (nodes.size() == 1)
|
||||
{
|
||||
centerNode(nodes[0]);
|
||||
LayoutHelper::centerNode(nodes[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -607,7 +495,7 @@ void nodes_layout::centerHoriVerti(const std::vector<Node*>& nodes)
|
|||
/// 左对齐
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
void nodes_layout::alignLefts(const std::vector<Node*>& nodes)
|
||||
void LayoutHelper::alignLefts(const std::vector<Node*>& nodes)
|
||||
{
|
||||
if (nodes.size() < 2)
|
||||
return;
|
||||
|
@ -633,7 +521,7 @@ void nodes_layout::alignLefts(const std::vector<Node*>& nodes)
|
|||
/// 右对齐
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
void nodes_layout::alignRights(const std::vector<Node*>& nodes)
|
||||
void LayoutHelper::alignRights(const std::vector<Node*>& nodes)
|
||||
{
|
||||
if (nodes.size() < 2)
|
||||
return;
|
||||
|
@ -660,7 +548,7 @@ void nodes_layout::alignRights(const std::vector<Node*>& nodes)
|
|||
/// 顶端对齐
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
void nodes_layout::alignTops(const std::vector<Node*>& nodes)
|
||||
void LayoutHelper::alignTops(const std::vector<Node*>& nodes)
|
||||
{
|
||||
if (nodes.size() < 2)
|
||||
return;
|
||||
|
@ -686,7 +574,7 @@ void nodes_layout::alignTops(const std::vector<Node*>& nodes)
|
|||
/// 底端对齐
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
void nodes_layout::alignBottoms(const std::vector<Node*>& nodes)
|
||||
void LayoutHelper::alignBottoms(const std::vector<Node*>& nodes)
|
||||
{
|
||||
if (nodes.size() < 2)
|
||||
return;
|
||||
|
@ -712,7 +600,7 @@ void nodes_layout::alignBottoms(const std::vector<Node*>& nodes)
|
|||
/// 水平对齐
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
void nodes_layout::alignHorizontals(const std::vector<Node*>& nodes)
|
||||
void LayoutHelper::alignHorizontals(const std::vector<Node*>& nodes)
|
||||
{
|
||||
if (nodes.size() < 2)
|
||||
return;
|
||||
|
@ -745,7 +633,7 @@ void nodes_layout::alignHorizontals(const std::vector<Node*>& nodes)
|
|||
/// 垂直对齐
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
void nodes_layout::alignVerticals(const std::vector<Node*>& nodes)
|
||||
void LayoutHelper::alignVerticals(const std::vector<Node*>& nodes)
|
||||
{
|
||||
if (nodes.size() < 2)
|
||||
return;
|
||||
|
@ -778,7 +666,7 @@ void nodes_layout::alignVerticals(const std::vector<Node*>& nodes)
|
|||
/// 中心原点对齐
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
void nodes_layout::alignCenters(const std::vector<Node*>& nodes)
|
||||
void LayoutHelper::alignCenters(const std::vector<Node*>& nodes)
|
||||
{
|
||||
if (nodes.size() < 2)
|
||||
return;
|
||||
|
@ -791,7 +679,7 @@ void nodes_layout::alignCenters(const std::vector<Node*>& nodes)
|
|||
/// 使宽度相等
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
void nodes_layout::makeSameWidth(const std::vector<Node*>& nodes)
|
||||
void LayoutHelper::makeSameWidth(const std::vector<Node*>& nodes)
|
||||
{
|
||||
if (nodes.size() < 2)
|
||||
return;
|
||||
|
@ -817,7 +705,7 @@ void nodes_layout::makeSameWidth(const std::vector<Node*>& nodes)
|
|||
/// 使高度相等
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
void nodes_layout::makeSameHeight(const std::vector<Node*>& nodes)
|
||||
void LayoutHelper::makeSameHeight(const std::vector<Node*>& nodes)
|
||||
{
|
||||
if (nodes.size() < 2)
|
||||
return;
|
||||
|
@ -843,7 +731,7 @@ void nodes_layout::makeSameHeight(const std::vector<Node*>& nodes)
|
|||
/// 使得大小相等
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
void nodes_layout::makeSameSize(const std::vector<Node*>& nodes)
|
||||
void LayoutHelper::makeSameSize(const std::vector<Node*>& nodes)
|
||||
{
|
||||
if (nodes.size() < 2)
|
||||
return;
|
||||
|
@ -856,7 +744,7 @@ void nodes_layout::makeSameSize(const std::vector<Node*>& nodes)
|
|||
/// 使水平间距相等
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
void nodes_layout::makeHorizontalSpacingEqual(std::vector<Node*>& nodes)
|
||||
void LayoutHelper::makeHorizontalSpacingEqual(std::vector<Node*>& nodes)
|
||||
{
|
||||
if (nodes.size() < 3)
|
||||
return;
|
||||
|
@ -883,14 +771,14 @@ void nodes_layout::makeHorizontalSpacingEqual(std::vector<Node*>& nodes)
|
|||
|
||||
if (avgHSpacing < 0.0f) avgHSpacing = 0.0f;
|
||||
|
||||
nodes_layout::makeHorizontalSpacingEqual(nodes, avgHSpacing);
|
||||
LayoutHelper::makeHorizontalSpacingEqual(nodes, avgHSpacing);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使水平间距相等
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
void nodes_layout::makeHorizontalSpacingEqual(const std::vector<Node*>& nodes, float theSpacing)
|
||||
void LayoutHelper::makeHorizontalSpacingEqual(const std::vector<Node*>& nodes, float theSpacing)
|
||||
{
|
||||
Node* child, *childNext;
|
||||
for (size_t index = 0; index < nodes.size() - 1; ++index)
|
||||
|
@ -905,7 +793,7 @@ void nodes_layout::makeHorizontalSpacingEqual(const std::vector<Node*>& nodes, f
|
|||
/// 使垂直间距相等
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
void nodes_layout::makeVerticalSpacingEqual(std::vector<Node*>& nodes)
|
||||
void LayoutHelper::makeVerticalSpacingEqual(std::vector<Node*>& nodes)
|
||||
{
|
||||
if (nodes.size() < 3)
|
||||
return;
|
||||
|
@ -931,10 +819,10 @@ void nodes_layout::makeVerticalSpacingEqual(std::vector<Node*>& nodes)
|
|||
|
||||
if (avgVSpacing < 0.0f) avgVSpacing = 0.0f;
|
||||
|
||||
nodes_layout::makeVerticalSpacingEqual(nodes, avgVSpacing);
|
||||
LayoutHelper::makeVerticalSpacingEqual(nodes, avgVSpacing);
|
||||
}
|
||||
|
||||
void nodes_layout::increaseHorizontalSpacing(std::vector<Node*>& nodes, float theSpacing)
|
||||
void LayoutHelper::increaseHorizontalSpacing(std::vector<Node*>& nodes, float theSpacing)
|
||||
{
|
||||
if (nodes.size() < 2)
|
||||
return;
|
||||
|
@ -949,7 +837,7 @@ void nodes_layout::increaseHorizontalSpacing(std::vector<Node*>& nodes, float th
|
|||
}
|
||||
}
|
||||
|
||||
void nodes_layout::increaseVerticalSpacing(std::vector<Node*>& nodes, float theSpacing)
|
||||
void LayoutHelper::increaseVerticalSpacing(std::vector<Node*>& nodes, float theSpacing)
|
||||
{
|
||||
if (nodes.size() < 2)
|
||||
return;
|
||||
|
@ -965,33 +853,33 @@ void nodes_layout::increaseVerticalSpacing(std::vector<Node*>& nodes, float theS
|
|||
}
|
||||
|
||||
|
||||
void nodes_layout::decreaseHorizontalSpacing(std::vector<Node*>& nodes, float theSpacing)
|
||||
void LayoutHelper::decreaseHorizontalSpacing(std::vector<Node*>& nodes, float theSpacing)
|
||||
{
|
||||
increaseHorizontalSpacing(nodes, -theSpacing);
|
||||
}
|
||||
|
||||
|
||||
void nodes_layout::decreaseVerticalSpacing(std::vector<Node*>& nodes, float theSpacing)
|
||||
void LayoutHelper::decreaseVerticalSpacing(std::vector<Node*>& nodes, float theSpacing)
|
||||
{
|
||||
increaseVerticalSpacing(nodes, -theSpacing);
|
||||
}
|
||||
|
||||
|
||||
void nodes_layout::removeHorizontalSpacing(const std::vector<Node*>& nodes)
|
||||
void LayoutHelper::removeHorizontalSpacing(const std::vector<Node*>& nodes)
|
||||
{
|
||||
nodes_layout::makeHorizontalSpacingEqual(nodes, 0);
|
||||
LayoutHelper::makeHorizontalSpacingEqual(nodes, 0);
|
||||
}
|
||||
|
||||
void nodes_layout::removeVerticalSpacing(const std::vector<Node*>& nodes)
|
||||
void LayoutHelper::removeVerticalSpacing(const std::vector<Node*>& nodes)
|
||||
{
|
||||
nodes_layout::makeVerticalSpacingEqual(nodes, 0);
|
||||
LayoutHelper::makeVerticalSpacingEqual(nodes, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使垂直间距相等
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
void nodes_layout::makeVerticalSpacingEqual(const std::vector<Node*>& nodes, float theSpacing)
|
||||
void LayoutHelper::makeVerticalSpacingEqual(const std::vector<Node*>& nodes, float theSpacing)
|
||||
{
|
||||
Node* child, *childNext;
|
||||
for (size_t index = 0; index < nodes.size() - 1; ++index)
|
||||
|
@ -1002,42 +890,138 @@ void nodes_layout::makeVerticalSpacingEqual(const std::vector<Node*>& nodes, flo
|
|||
}
|
||||
}
|
||||
|
||||
/// visual screen
|
||||
float nodes_layout::scr::getNodeLeft(Node* pNode)
|
||||
// ----------------- LayoutHelper::VisibleRect --------------------------
|
||||
|
||||
cocos2d::Rect LayoutHelper::VisibleRect::s_ScreenVisibleRect;
|
||||
|
||||
/// x-studio: when design resolution changed, should call this func.
|
||||
void LayoutHelper::VisibleRect::refresh(void)
|
||||
{
|
||||
cocos2d::Point ptLocal(nodes_layout::getNodeLeft(pNode), 0);
|
||||
auto director = Director::getInstance();
|
||||
s_ScreenVisibleRect.origin = Director::getInstance()->getVisibleOrigin();
|
||||
s_ScreenVisibleRect.size = Director::getInstance()->getVisibleSize();
|
||||
}
|
||||
|
||||
void LayoutHelper::VisibleRect::lazyInit()
|
||||
{
|
||||
if (s_ScreenVisibleRect.size.width == 0.0f && s_ScreenVisibleRect.size.height == 0.0f)
|
||||
{
|
||||
auto director = Director::getInstance();
|
||||
auto glview = director->getOpenGLView();
|
||||
|
||||
if (glview->getResolutionPolicy() == ResolutionPolicy::NO_BORDER) {
|
||||
s_ScreenVisibleRect.origin = director->getVisibleOrigin();
|
||||
s_ScreenVisibleRect.size = director->getVisibleSize();
|
||||
}
|
||||
else {
|
||||
s_ScreenVisibleRect.origin = LayoutHelper::getVisibleOrigin();
|
||||
s_ScreenVisibleRect.size = LayoutHelper::getVisibleSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cocos2d::Rect LayoutHelper::VisibleRect::getScreenVisibleRect()
|
||||
{
|
||||
lazyInit();
|
||||
return cocos2d::Rect(s_ScreenVisibleRect.origin.x, s_ScreenVisibleRect.origin.y, s_ScreenVisibleRect.size.width, s_ScreenVisibleRect.size.height);
|
||||
}
|
||||
|
||||
cocos2d::Size LayoutHelper::VisibleRect::size()
|
||||
{
|
||||
lazyInit();
|
||||
return s_ScreenVisibleRect.size;
|
||||
}
|
||||
|
||||
Point LayoutHelper::VisibleRect::left()
|
||||
{
|
||||
lazyInit();
|
||||
return cocos2d::Point(s_ScreenVisibleRect.origin.x, s_ScreenVisibleRect.origin.y + s_ScreenVisibleRect.size.height / 2);
|
||||
}
|
||||
|
||||
Point LayoutHelper::VisibleRect::right()
|
||||
{
|
||||
lazyInit();
|
||||
return cocos2d::Point(s_ScreenVisibleRect.origin.x + s_ScreenVisibleRect.size.width, s_ScreenVisibleRect.origin.y + s_ScreenVisibleRect.size.height / 2);
|
||||
}
|
||||
|
||||
Point LayoutHelper::VisibleRect::top()
|
||||
{
|
||||
lazyInit();
|
||||
return cocos2d::Point(s_ScreenVisibleRect.origin.x + s_ScreenVisibleRect.size.width / 2, s_ScreenVisibleRect.origin.y + s_ScreenVisibleRect.size.height);
|
||||
}
|
||||
|
||||
Point LayoutHelper::VisibleRect::bottom()
|
||||
{
|
||||
lazyInit();
|
||||
return cocos2d::Point(s_ScreenVisibleRect.origin.x + s_ScreenVisibleRect.size.width / 2, s_ScreenVisibleRect.origin.y);
|
||||
}
|
||||
|
||||
Point LayoutHelper::VisibleRect::center()
|
||||
{
|
||||
lazyInit();
|
||||
return cocos2d::Point(s_ScreenVisibleRect.origin.x + s_ScreenVisibleRect.size.width / 2, s_ScreenVisibleRect.origin.y + s_ScreenVisibleRect.size.height / 2);
|
||||
}
|
||||
|
||||
Point LayoutHelper::VisibleRect::leftTop()
|
||||
{
|
||||
lazyInit();
|
||||
return cocos2d::Point(s_ScreenVisibleRect.origin.x, s_ScreenVisibleRect.origin.y + s_ScreenVisibleRect.size.height);
|
||||
}
|
||||
|
||||
Point LayoutHelper::VisibleRect::rightTop()
|
||||
{
|
||||
lazyInit();
|
||||
return cocos2d::Point(s_ScreenVisibleRect.origin.x + s_ScreenVisibleRect.size.width, s_ScreenVisibleRect.origin.y + s_ScreenVisibleRect.size.height);
|
||||
}
|
||||
|
||||
Point LayoutHelper::VisibleRect::leftBottom()
|
||||
{
|
||||
lazyInit();
|
||||
return s_ScreenVisibleRect.origin;
|
||||
}
|
||||
|
||||
Point LayoutHelper::VisibleRect::rightBottom()
|
||||
{
|
||||
lazyInit();
|
||||
return cocos2d::Point(s_ScreenVisibleRect.origin.x + s_ScreenVisibleRect.size.width, s_ScreenVisibleRect.origin.y);
|
||||
}
|
||||
|
||||
/// visual screen
|
||||
float LayoutHelper::VisibleRect::getNodeLeft(Node* pNode)
|
||||
{
|
||||
cocos2d::Point ptLocal(LayoutHelper::getNodeLeft(pNode), 0);
|
||||
auto ptWorld = pNode->getParent()->convertToWorldSpace(ptLocal);
|
||||
return ptWorld.x;
|
||||
}
|
||||
float nodes_layout::scr::getNodeBottom(Node* pNode)
|
||||
float LayoutHelper::VisibleRect::getNodeBottom(Node* pNode)
|
||||
{
|
||||
cocos2d::Point ptLocal(0, nodes_layout::getNodeBottom(pNode));
|
||||
cocos2d::Point ptLocal(0, LayoutHelper::getNodeBottom(pNode));
|
||||
auto ptWorld = pNode->getParent()->convertToWorldSpace(ptLocal);
|
||||
|
||||
return ptWorld.y;
|
||||
}
|
||||
float nodes_layout::scr::getNodeRight(Node* pNode)
|
||||
float LayoutHelper::VisibleRect::getNodeRight(Node* pNode)
|
||||
{
|
||||
cocos2d::Point ptLocal(nodes_layout::getNodeLeft(pNode) + pNode->getContentSize().width/* * pNode->getScaleX()*/, 0);
|
||||
cocos2d::Point ptLocal(LayoutHelper::getNodeLeft(pNode) + pNode->getContentSize().width/* * pNode->getScaleX()*/, 0);
|
||||
auto ptWorld = pNode->getParent()->convertToWorldSpace(ptLocal);
|
||||
|
||||
auto ScreenVisibleRect = ScreenVisibleRect::getScreenVisibleRect();
|
||||
return ScreenVisibleRect.size.width - ptWorld.x;
|
||||
auto visibleRect = LayoutHelper::VisibleRect::getScreenVisibleRect();
|
||||
return visibleRect.size.width - ptWorld.x;
|
||||
}
|
||||
float nodes_layout::scr::getNodeTop(Node* pNode)
|
||||
float LayoutHelper::VisibleRect::getNodeTop(Node* pNode)
|
||||
{
|
||||
cocos2d::Point ptLocal(0, nodes_layout::getNodeBottom(pNode) + pNode->getContentSize().height/* * pNode->getScaleY()*/);
|
||||
cocos2d::Point ptLocal(0, LayoutHelper::getNodeBottom(pNode) + pNode->getContentSize().height/* * pNode->getScaleY()*/);
|
||||
auto ptWorld = pNode->getParent()->convertToWorldSpace(ptLocal);
|
||||
auto ScreenVisibleRect = ScreenVisibleRect::getScreenVisibleRect();
|
||||
auto visibleRect = LayoutHelper::VisibleRect::getScreenVisibleRect();
|
||||
|
||||
return ScreenVisibleRect.size.height - ptWorld.y;
|
||||
return visibleRect.size.height - ptWorld.y;
|
||||
}
|
||||
|
||||
void nodes_layout::scr::setNodeLeft(Node* pNode, float left)
|
||||
void LayoutHelper::VisibleRect::setNodeLeft(Node* pNode, float left)
|
||||
{
|
||||
CC_ASSERT(pNode);
|
||||
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize();
|
||||
cocos2d::Point delta = cocos2d::Vec2(0, scrSize.height) - ScreenVisibleRect::leftTop();
|
||||
cocos2d::Point delta = cocos2d::Vec2(0, scrSize.height) - LayoutHelper::VisibleRect::leftTop();
|
||||
Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
cocos2d::Point achorPoint = Vec2::ZERO;
|
||||
if (!pNode->isIgnoreAnchorPointForPosition())
|
||||
|
@ -1049,11 +1033,11 @@ void nodes_layout::scr::setNodeLeft(Node* pNode, float left)
|
|||
pNode->setPositionX(ptLocal.x);
|
||||
|
||||
}
|
||||
void nodes_layout::scr::setNodeTop(Node* pNode, float top)
|
||||
void LayoutHelper::VisibleRect::setNodeTop(Node* pNode, float top)
|
||||
{
|
||||
CC_ASSERT(pNode);
|
||||
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize();
|
||||
cocos2d::Point delta = cocos2d::Vec2(0, scrSize.height) - ScreenVisibleRect::leftTop();
|
||||
cocos2d::Point delta = cocos2d::Vec2(0, scrSize.height) - LayoutHelper::VisibleRect::leftTop();
|
||||
Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
cocos2d::Point achorPoint = Vec2::ZERO;
|
||||
if (!pNode->isIgnoreAnchorPointForPosition())
|
||||
|
@ -1066,11 +1050,11 @@ void nodes_layout::scr::setNodeTop(Node* pNode, float top)
|
|||
pNode->setPositionY(ptLocal.y);
|
||||
|
||||
}
|
||||
void nodes_layout::scr::setNodeRight(Node* pNode, float right)
|
||||
void LayoutHelper::VisibleRect::setNodeRight(Node* pNode, float right)
|
||||
{
|
||||
CC_ASSERT(pNode);
|
||||
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize();
|
||||
cocos2d::Point delta = cocos2d::Vec2(scrSize.width, 0) - ScreenVisibleRect::rightBottom();
|
||||
cocos2d::Point delta = cocos2d::Vec2(scrSize.width, 0) - LayoutHelper::VisibleRect::rightBottom();
|
||||
Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
cocos2d::Point achorPoint = Vec2::ZERO;
|
||||
if (!pNode->isIgnoreAnchorPointForPosition())
|
||||
|
@ -1082,11 +1066,11 @@ void nodes_layout::scr::setNodeRight(Node* pNode, float right)
|
|||
auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld);
|
||||
pNode->setPositionX(ptLocal.x);
|
||||
}
|
||||
void nodes_layout::scr::setNodeBottom(Node* pNode, float bottom)
|
||||
void LayoutHelper::VisibleRect::setNodeBottom(Node* pNode, float bottom)
|
||||
{
|
||||
CC_ASSERT(pNode);
|
||||
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize();
|
||||
cocos2d::Point delta = cocos2d::Vec2(scrSize.width, 0) - ScreenVisibleRect::rightBottom();
|
||||
cocos2d::Point delta = cocos2d::Vec2(scrSize.width, 0) - LayoutHelper::VisibleRect::rightBottom();
|
||||
Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
cocos2d::Point achorPoint = Vec2::ZERO;
|
||||
if (!pNode->isIgnoreAnchorPointForPosition())
|
||||
|
@ -1100,11 +1084,11 @@ void nodes_layout::scr::setNodeBottom(Node* pNode, float bottom)
|
|||
|
||||
}
|
||||
|
||||
void nodes_layout::scr::setNodeLT(Node* pNode, const cocos2d::Point& p)
|
||||
void LayoutHelper::VisibleRect::setNodeLT(Node* pNode, const cocos2d::Point& p)
|
||||
{
|
||||
CC_ASSERT(pNode);
|
||||
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize();
|
||||
cocos2d::Point delta = cocos2d::Vec2(0, scrSize.height) - ScreenVisibleRect::leftTop();
|
||||
cocos2d::Point delta = cocos2d::Vec2(0, scrSize.height) - LayoutHelper::VisibleRect::leftTop();
|
||||
Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
cocos2d::Point achorPoint = Vec2::ZERO;
|
||||
if (!pNode->isIgnoreAnchorPointForPosition())
|
||||
|
@ -1117,11 +1101,11 @@ void nodes_layout::scr::setNodeLT(Node* pNode, const cocos2d::Point& p)
|
|||
auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld);
|
||||
pNode->setPosition(ptLocal);
|
||||
}
|
||||
void nodes_layout::scr::setNodeRT(Node* pNode, const cocos2d::Point& p)
|
||||
void LayoutHelper::VisibleRect::setNodeRT(Node* pNode, const cocos2d::Point& p)
|
||||
{ // right top
|
||||
CC_ASSERT(pNode);
|
||||
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize();
|
||||
cocos2d::Point delta = cocos2d::Vec2(scrSize.width, scrSize.height) - ScreenVisibleRect::rightTop();
|
||||
cocos2d::Point delta = cocos2d::Vec2(scrSize.width, scrSize.height) - LayoutHelper::VisibleRect::rightTop();
|
||||
Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
cocos2d::Point achorPoint = Vec2::ZERO;
|
||||
if (!pNode->isIgnoreAnchorPointForPosition())
|
||||
|
@ -1133,11 +1117,11 @@ void nodes_layout::scr::setNodeRT(Node* pNode, const cocos2d::Point& p)
|
|||
auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld);
|
||||
pNode->setPosition(ptLocal);
|
||||
}
|
||||
void nodes_layout::scr::setNodeLB(Node* pNode, const cocos2d::Point& p)
|
||||
void LayoutHelper::VisibleRect::setNodeLB(Node* pNode, const cocos2d::Point& p)
|
||||
{ // left bottom
|
||||
CC_ASSERT(pNode);
|
||||
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize();
|
||||
cocos2d::Point delta = cocos2d::Vec2(0, 0) - ScreenVisibleRect::leftBottom();
|
||||
cocos2d::Point delta = cocos2d::Vec2(0, 0) - LayoutHelper::VisibleRect::leftBottom();
|
||||
Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
cocos2d::Point achorPoint = Vec2::ZERO;
|
||||
if (!pNode->isIgnoreAnchorPointForPosition())
|
||||
|
@ -1149,11 +1133,11 @@ void nodes_layout::scr::setNodeLB(Node* pNode, const cocos2d::Point& p)
|
|||
auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld);
|
||||
pNode->setPosition(ptLocal);
|
||||
}
|
||||
void nodes_layout::scr::setNodeRB(Node* pNode, const cocos2d::Point& p)
|
||||
void LayoutHelper::VisibleRect::setNodeRB(Node* pNode, const cocos2d::Point& p)
|
||||
{ // right bottom
|
||||
CC_ASSERT(pNode);
|
||||
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize();
|
||||
cocos2d::Point delta = cocos2d::Vec2(scrSize.width, 0) - ScreenVisibleRect::rightBottom();
|
||||
cocos2d::Point delta = cocos2d::Vec2(scrSize.width, 0) - LayoutHelper::VisibleRect::rightBottom();
|
||||
cocos2d::Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
cocos2d::Point achorPoint = Vec2::ZERO;
|
||||
if (!pNode->isIgnoreAnchorPointForPosition())
|
||||
|
@ -1168,14 +1152,14 @@ void nodes_layout::scr::setNodeRB(Node* pNode, const cocos2d::Point& p)
|
|||
}
|
||||
|
||||
/// ratio position
|
||||
void nodes_layout::scr::setNodeNormalizedLT(Node* pNode, const cocos2d::Point& ratio)
|
||||
void LayoutHelper::VisibleRect::setNodeNormalizedLT(Node* pNode, const cocos2d::Point& ratio)
|
||||
{
|
||||
CC_ASSERT(pNode);
|
||||
|
||||
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize();
|
||||
cocos2d::Point delta = cocos2d::Vec2(0, scrSize.height) - ScreenVisibleRect::leftTop();
|
||||
cocos2d::Point delta = cocos2d::Vec2(0, scrSize.height) - LayoutHelper::VisibleRect::leftTop();
|
||||
|
||||
cocos2d::Size vscrSize = ScreenVisibleRect::size();
|
||||
cocos2d::Size vscrSize = LayoutHelper::VisibleRect::size();
|
||||
cocos2d::Point p = cocos2d::Vec2(vscrSize.width * ratio.x, vscrSize.height * ratio.y);
|
||||
|
||||
cocos2d::Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
|
@ -1190,13 +1174,13 @@ void nodes_layout::scr::setNodeNormalizedLT(Node* pNode, const cocos2d::Point& r
|
|||
auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld);
|
||||
pNode->setPosition(ptLocal);
|
||||
}
|
||||
void nodes_layout::scr::setNodeNormalizedRT(Node* pNode, const cocos2d::Point& ratio)
|
||||
void LayoutHelper::VisibleRect::setNodeNormalizedRT(Node* pNode, const cocos2d::Point& ratio)
|
||||
{ // right top
|
||||
CC_ASSERT(pNode);
|
||||
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize();
|
||||
cocos2d::Point delta = cocos2d::Vec2(scrSize.width, scrSize.height) - ScreenVisibleRect::rightTop();
|
||||
cocos2d::Point delta = cocos2d::Vec2(scrSize.width, scrSize.height) - LayoutHelper::VisibleRect::rightTop();
|
||||
|
||||
cocos2d::Size vscrSize = ScreenVisibleRect::size();
|
||||
cocos2d::Size vscrSize = LayoutHelper::VisibleRect::size();
|
||||
cocos2d::Point p = cocos2d::Vec2(vscrSize.width * ratio.x, vscrSize.height * ratio.y);
|
||||
|
||||
cocos2d::Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
|
@ -1210,13 +1194,13 @@ void nodes_layout::scr::setNodeNormalizedRT(Node* pNode, const cocos2d::Point& r
|
|||
auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld);
|
||||
pNode->setPosition(ptLocal);
|
||||
}
|
||||
void nodes_layout::scr::setNodeNormalizedLB(Node* pNode, const cocos2d::Point& ratio)
|
||||
void LayoutHelper::VisibleRect::setNodeNormalizedLB(Node* pNode, const cocos2d::Point& ratio)
|
||||
{ // left bottom
|
||||
CC_ASSERT(pNode);
|
||||
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize();
|
||||
cocos2d::Point delta = cocos2d::Vec2(0, 0) - ScreenVisibleRect::leftBottom();
|
||||
cocos2d::Point delta = cocos2d::Vec2(0, 0) - LayoutHelper::VisibleRect::leftBottom();
|
||||
|
||||
cocos2d::Size vscrSize = ScreenVisibleRect::size();
|
||||
cocos2d::Size vscrSize = LayoutHelper::VisibleRect::size();
|
||||
cocos2d::Point p = cocos2d::Vec2(vscrSize.width * ratio.x, vscrSize.height * ratio.y);
|
||||
|
||||
cocos2d::Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
|
@ -1230,13 +1214,13 @@ void nodes_layout::scr::setNodeNormalizedLB(Node* pNode, const cocos2d::Point& r
|
|||
auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld);
|
||||
pNode->setPosition(ptLocal);
|
||||
}
|
||||
void nodes_layout::scr::setNodeNormalizedRB(Node* pNode, const cocos2d::Point& ratio)
|
||||
void LayoutHelper::VisibleRect::setNodeNormalizedRB(Node* pNode, const cocos2d::Point& ratio)
|
||||
{ // right bottom
|
||||
CC_ASSERT(pNode);
|
||||
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize();
|
||||
cocos2d::Point delta = cocos2d::Vec2(scrSize.width, 0) - ScreenVisibleRect::rightBottom();
|
||||
cocos2d::Point delta = cocos2d::Vec2(scrSize.width, 0) - LayoutHelper::VisibleRect::rightBottom();
|
||||
|
||||
cocos2d::Size vscrSize = ScreenVisibleRect::size();
|
||||
cocos2d::Size vscrSize = LayoutHelper::VisibleRect::size();
|
||||
cocos2d::Point p = cocos2d::Vec2(vscrSize.width * ratio.x, vscrSize.height * ratio.y);
|
||||
|
||||
cocos2d::Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
|
@ -1251,13 +1235,13 @@ void nodes_layout::scr::setNodeNormalizedRB(Node* pNode, const cocos2d::Point& r
|
|||
pNode->setPosition(ptLocal);
|
||||
}
|
||||
|
||||
void nodes_layout::scr::setNodeNormalizedTop(Node* pNode, const float ratioTop)
|
||||
void LayoutHelper::VisibleRect::setNodeNormalizedTop(Node* pNode, const float ratioTop)
|
||||
{ // right top
|
||||
CC_ASSERT(pNode);
|
||||
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize();
|
||||
cocos2d::Point delta = cocos2d::Vec2(scrSize.width, scrSize.height) - ScreenVisibleRect::rightTop();
|
||||
cocos2d::Point delta = cocos2d::Vec2(scrSize.width, scrSize.height) - LayoutHelper::VisibleRect::rightTop();
|
||||
|
||||
cocos2d::Size vscrSize = ScreenVisibleRect::size();
|
||||
cocos2d::Size vscrSize = LayoutHelper::VisibleRect::size();
|
||||
float top = vscrSize.width * ratioTop;
|
||||
|
||||
cocos2d::Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
|
@ -1271,33 +1255,31 @@ void nodes_layout::scr::setNodeNormalizedTop(Node* pNode, const float ratioTop)
|
|||
pNode->setPositionY(ptWorld.y);
|
||||
}
|
||||
|
||||
void nodes_layout::scr::setNodeNormalizedPositionX(cocos2d::Node* pNode, float ratio)
|
||||
void LayoutHelper::VisibleRect::setNodeNormalizedPositionX(cocos2d::Node* pNode, float ratio)
|
||||
{
|
||||
CC_ASSERT(pNode);
|
||||
cocos2d::Rect ScreenVisibleRect = LayoutHelper::ScreenVisibleRect::getScreenVisibleRect();
|
||||
cocos2d::Point ptWorld(ScreenVisibleRect.size.width * ratio + ScreenVisibleRect.origin.x, 0);
|
||||
cocos2d::Rect visibleRect = LayoutHelper::LayoutHelper::VisibleRect::getScreenVisibleRect();
|
||||
cocos2d::Point ptWorld(visibleRect.size.width * ratio + visibleRect.origin.x, 0);
|
||||
auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld);
|
||||
pNode->setPositionX(ptLocal.x);
|
||||
}
|
||||
|
||||
void nodes_layout::scr::setNodeNormalizedPositionY(cocos2d::Node* pNode, float ratio)
|
||||
void LayoutHelper::VisibleRect::setNodeNormalizedPositionY(cocos2d::Node* pNode, float ratio)
|
||||
{
|
||||
CC_ASSERT(pNode);
|
||||
cocos2d::Rect ScreenVisibleRect = LayoutHelper::ScreenVisibleRect::getScreenVisibleRect();
|
||||
cocos2d::Rect visibleRect = LayoutHelper::LayoutHelper::VisibleRect::getScreenVisibleRect();
|
||||
|
||||
cocos2d::Point ptWorld(0, ScreenVisibleRect.size.height * ratio + ScreenVisibleRect.origin.y);
|
||||
cocos2d::Point ptWorld(0, visibleRect.size.height * ratio + visibleRect.origin.y);
|
||||
auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld);
|
||||
pNode->setPositionY(ptLocal.y);
|
||||
}
|
||||
void nodes_layout::scr::setNodeNormalizedPosition(Node* pNode, const cocos2d::Point& ratio)
|
||||
void LayoutHelper::VisibleRect::setNodeNormalizedPosition(Node* pNode, const cocos2d::Point& ratio)
|
||||
{
|
||||
CC_ASSERT(pNode);
|
||||
pNode->setIgnoreAnchorPointForPosition(false);
|
||||
pNode->setAnchorPoint(cocos2d::Vec2(.5f, .5f));
|
||||
cocos2d::Rect ScreenVisibleRect = LayoutHelper::ScreenVisibleRect::getScreenVisibleRect();
|
||||
cocos2d::Point ptWorld(ScreenVisibleRect.size.width * ratio.x + ScreenVisibleRect.origin.x, ScreenVisibleRect.size.height * ratio.y + ScreenVisibleRect.origin.y);
|
||||
cocos2d::Rect visibleRect = LayoutHelper::LayoutHelper::VisibleRect::getScreenVisibleRect();
|
||||
cocos2d::Point ptWorld(visibleRect.size.width * ratio.x + visibleRect.origin.x, visibleRect.size.height * ratio.y + visibleRect.origin.y);
|
||||
auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld);
|
||||
pNode->setPosition(ptLocal);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
// so, we publish it to here.
|
||||
// usage:
|
||||
// #include "ui/LayoutHelper.h"
|
||||
// nodes_layout::centerNode(node); // the node should be already have parent.
|
||||
// nodes_layout::makeVerticalSpacingEqual(nodes); // all the nodes shoud be in the same parent.
|
||||
// LayoutHelper::centerNode(node); // the node should be already have parent.
|
||||
// LayoutHelper::makeVerticalSpacingEqual(nodes); // all the nodes shoud be in the same parent.
|
||||
//
|
||||
#pragma once
|
||||
#ifndef _LAYOUTHELPER_H_
|
||||
|
@ -15,8 +15,6 @@
|
|||
#include "cocos2d.h"
|
||||
#include "base/ccMacros.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
// f(x) = s * a + x
|
||||
#define adjust_coord(__sz__,__achor__,__coord__) ( (__sz__) * (__achor__) + (__coord__) )
|
||||
|
||||
|
@ -42,38 +40,23 @@ inline cocos2d::Size operator*(const cocos2d::Size& left, const cocos2d::Vec2& r
|
|||
return cocos2d::Size(left.width * right.x, left.height * right.y);
|
||||
}
|
||||
|
||||
namespace LayoutHelper {
|
||||
struct CC_DLL LayoutHelper {
|
||||
|
||||
class CC_DLL ScreenVisibleRect
|
||||
{
|
||||
public:
|
||||
static void refresh(void);
|
||||
static cocos2d::Size s_designSize;
|
||||
static float s_adjustedScale;
|
||||
|
||||
static cocos2d::Rect getScreenVisibleRect();
|
||||
static cocos2d::Size size();
|
||||
static cocos2d::Point left();
|
||||
static cocos2d::Point right();
|
||||
static cocos2d::Point top();
|
||||
static cocos2d::Point bottom();
|
||||
static cocos2d::Point center();
|
||||
static cocos2d::Point leftTop();
|
||||
static cocos2d::Point rightTop();
|
||||
static cocos2d::Point leftBottom();
|
||||
static cocos2d::Point rightBottom();
|
||||
|
||||
private:
|
||||
static void lazyInit();
|
||||
static cocos2d::Rect s_ScreenVisibleRect;
|
||||
};
|
||||
|
||||
class CC_DLL nodes_layout {
|
||||
public:
|
||||
static float adjustedScale;
|
||||
static cocos2d::Size designSize;
|
||||
/// <summary>
|
||||
/// adatpe design size with fixed edge, normally, use this function for screen adatpe
|
||||
/// </summary>
|
||||
/// <param name="designSize"></param>
|
||||
static void setDesignSizeFixedEdge(const cocos2d::Size& designSize);
|
||||
|
||||
/// <summary>
|
||||
/// adapte design size with no border
|
||||
/// </summary>
|
||||
/// <param name="designSize"></param>
|
||||
static void setDesignSizeNoBorder(const cocos2d::Size& designSize);
|
||||
|
||||
static void setDesignSizeFixedEdge(const cocos2d::Size& designSize);
|
||||
static cocos2d::Vec2 getVisibleOrigin(void);
|
||||
static cocos2d::Size getVisibleSize(void);
|
||||
|
||||
|
@ -104,27 +87,21 @@ namespace LayoutHelper {
|
|||
#define isIgnoreY(align) (align != ALIGN_TOP) && (align != ALIGN_BOTTOM)
|
||||
#define isIgnoreXY(align) (align == ALIGN_CENTER)
|
||||
|
||||
static const cocos2d::Point ANCHOR_CENTER; // center
|
||||
static const cocos2d::Point ANCHOR_LB; // left bottom,
|
||||
static const cocos2d::Point ANCHOR_LT; // left top
|
||||
static const cocos2d::Point ANCHOR_RB; // rigth bottom
|
||||
static const cocos2d::Point ANCHOR_RT; // rigth top
|
||||
static cocos2d::Vec2 getScale2D(cocos2d::Node* pNode) { return cocos2d::Vec2(pNode->getScaleX(), pNode->getScaleY()); }
|
||||
|
||||
static cocos2d::Vec2 getScale2D(Node* pNode) { return cocos2d::Vec2(pNode->getScaleX(), pNode->getScaleY()); }
|
||||
|
||||
static float getNodeLeftX(Node* pNode) {
|
||||
static float getNodeLeftX(cocos2d::Node* pNode) {
|
||||
return pNode->getPositionX() - pNode->getAnchorPoint().x * pNode->getContentSize().width * pNode->getScaleX();
|
||||
}
|
||||
|
||||
static float getNodeRightX(Node* pNode) {
|
||||
static float getNodeRightX(cocos2d::Node* pNode) {
|
||||
return pNode->getPositionX() + (1 - pNode->getAnchorPoint().x) * pNode->getContentSize().width * pNode->getScaleX();
|
||||
}
|
||||
|
||||
static float getNodeTopY(Node* pNode) {
|
||||
static float getNodeTopY(cocos2d::Node* pNode) {
|
||||
return pNode->getPositionY() + (1 - pNode->getAnchorPoint().y) * pNode->getContentSize().height * pNode->getScaleY();
|
||||
}
|
||||
|
||||
static float getNodeBottomY(Node* pNode) {
|
||||
static float getNodeBottomY(cocos2d::Node* pNode) {
|
||||
return pNode->getPositionY() + pNode->getAnchorPoint().y * pNode->getContentSize().height * pNode->getScaleY();
|
||||
}
|
||||
|
||||
|
@ -140,7 +117,7 @@ namespace LayoutHelper {
|
|||
** x: specify coord x.so
|
||||
** y: specify coord y.
|
||||
*/
|
||||
static void setNodePosition(Node* pNode, const int align, float x, float y)
|
||||
static void setNodePosition(cocos2d::Node* pNode, const int align, float x, float y)
|
||||
{
|
||||
const AlignType alignType = (const AlignType)align;
|
||||
if (alignType == ALIGN_NONE) {
|
||||
|
@ -177,52 +154,52 @@ namespace LayoutHelper {
|
|||
** y: specify coord y.
|
||||
**
|
||||
*/
|
||||
static void setNodePosition(Node* pNode, const cocos2d::Point& anchorPoint, const int align, float x, float y)
|
||||
static void setNodePosition(cocos2d::Node* pNode, const cocos2d::Point& anchorPoint, const int align, float x, float y)
|
||||
{
|
||||
pNode->setAnchorPoint(anchorPoint);
|
||||
setNodePosition(pNode, align, x, y);
|
||||
}
|
||||
|
||||
static void setNodePosition(Node* pNode, const int align, float value = 0.0f)
|
||||
static void setNodePosition(cocos2d::Node* pNode, const int align, float value = 0.0f)
|
||||
{ // ignore x or y
|
||||
setNodePosition(pNode, align, value, value);
|
||||
}
|
||||
|
||||
static void setNodePosition(Node* pNode, const cocos2d::Point& anchorPoint, const int align, float value = 0.0f)
|
||||
static void setNodePosition(cocos2d::Node* pNode, const cocos2d::Point& anchorPoint, const int align, float value = 0.0f)
|
||||
{ // ignore x or y
|
||||
setNodePosition(pNode, anchorPoint, align, value, value);
|
||||
}
|
||||
|
||||
// @version 1
|
||||
static void centerNodeX(Node* pNode)
|
||||
static void centerNodeX(cocos2d::Node* pNode)
|
||||
{
|
||||
Node* pNodeParent = pNode->getParent();
|
||||
cocos2d::Node* pNodeParent = pNode->getParent();
|
||||
if (pNodeParent)
|
||||
{
|
||||
nodes_layout::centerNodeX(pNode, pNodeParent->getContentSize());
|
||||
centerNodeX(pNode, pNodeParent->getContentSize());
|
||||
}
|
||||
}
|
||||
|
||||
static void centerNodeY(Node* pNode)
|
||||
static void centerNodeY(cocos2d::Node* pNode)
|
||||
{
|
||||
Node* pNodeParent = pNode->getParent();
|
||||
cocos2d::Node* pNodeParent = pNode->getParent();
|
||||
if ((pNodeParent))
|
||||
{
|
||||
nodes_layout::centerNodeY(pNode, pNodeParent->getContentSize());
|
||||
centerNodeY(pNode, pNodeParent->getContentSize());
|
||||
}
|
||||
}
|
||||
|
||||
static void centerNode(Node* pNode)
|
||||
static void centerNode(cocos2d::Node* pNode)
|
||||
{
|
||||
Node* pNodeParent = pNode->getParent();
|
||||
cocos2d::Node* pNodeParent = pNode->getParent();
|
||||
if ((pNodeParent))
|
||||
{
|
||||
nodes_layout::centerNode(pNode, pNodeParent->getContentSize());
|
||||
centerNode(pNode, pNodeParent->getContentSize());
|
||||
}
|
||||
}
|
||||
|
||||
// @version 2
|
||||
static void centerNodeX(Node* pNode, const cocos2d::Size& parentSize)
|
||||
static void centerNodeX(cocos2d::Node* pNode, const cocos2d::Size& parentSize)
|
||||
{
|
||||
CC_ASSERT(pNode);
|
||||
|
||||
|
@ -237,7 +214,7 @@ namespace LayoutHelper {
|
|||
|
||||
|
||||
|
||||
static void centerNodeY(Node* pNode, const cocos2d::Size& parentSize)
|
||||
static void centerNodeY(cocos2d::Node* pNode, const cocos2d::Size& parentSize)
|
||||
{
|
||||
CC_ASSERT(pNode);
|
||||
|
||||
|
@ -250,12 +227,12 @@ namespace LayoutHelper {
|
|||
pNode->setPositionY(center_coord(parentSize.height, size.height, achorY));
|
||||
}
|
||||
|
||||
static void centerNode(Node* pNode, const cocos2d::Size& parentSize)
|
||||
static void centerNode(cocos2d::Node* pNode, const cocos2d::Size& parentSize)
|
||||
{
|
||||
CC_ASSERT(pNode);
|
||||
|
||||
cocos2d::Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
cocos2d::Point achor = Vec2::ZERO;
|
||||
cocos2d::Point achor = cocos2d::Vec2::ZERO;
|
||||
if (!pNode->isIgnoreAnchorPointForPosition())
|
||||
{
|
||||
achor = pNode->getAnchorPoint();
|
||||
|
@ -265,18 +242,18 @@ namespace LayoutHelper {
|
|||
}
|
||||
|
||||
// @version 1
|
||||
static void setNodeLeft(Node* pNode, float left, float anchor = 0.0f)
|
||||
static void setNodeLeft(cocos2d::Node* pNode, float left, float anchor = 0.0f)
|
||||
{
|
||||
Node* pNodeParent = pNode->getParent();
|
||||
cocos2d::Node* pNodeParent = pNode->getParent();
|
||||
if ((pNodeParent))
|
||||
{
|
||||
setNodeLeft(pNode, pNodeParent->getContentSize(), left, anchor);
|
||||
}
|
||||
}
|
||||
|
||||
static float getNodeLeft(Node* pNode, float anchor = 0.0f)
|
||||
static float getNodeLeft(cocos2d::Node* pNode, float anchor = 0.0f)
|
||||
{
|
||||
Node* pNodeParent = pNode->getParent();
|
||||
cocos2d::Node* pNodeParent = pNode->getParent();
|
||||
if ((pNodeParent))
|
||||
{
|
||||
return getNodeLeft(pNode, pNodeParent->getContentSize(), anchor);
|
||||
|
@ -284,18 +261,18 @@ namespace LayoutHelper {
|
|||
return 0.0f;
|
||||
}
|
||||
|
||||
static void setNodeTop(Node* pNode, float top, float anchor = 0.0f)
|
||||
static void setNodeTop(cocos2d::Node* pNode, float top, float anchor = 0.0f)
|
||||
{
|
||||
Node* pNodeParent = pNode->getParent();
|
||||
cocos2d::Node* pNodeParent = pNode->getParent();
|
||||
if ((pNodeParent))
|
||||
{
|
||||
nodes_layout::setNodeTop(pNode, pNodeParent->getContentSize(), top, anchor);
|
||||
setNodeTop(pNode, pNodeParent->getContentSize(), top, anchor);
|
||||
}
|
||||
}
|
||||
|
||||
static float getNodeTop(Node* pNode, float anchor = 0.0f)
|
||||
static float getNodeTop(cocos2d::Node* pNode, float anchor = 0.0f)
|
||||
{
|
||||
Node* pNodeParent = pNode->getParent();
|
||||
cocos2d::Node* pNodeParent = pNode->getParent();
|
||||
if ((pNodeParent))
|
||||
{
|
||||
return getNodeTop(pNode, pNodeParent->getContentSize(), anchor);
|
||||
|
@ -303,17 +280,17 @@ namespace LayoutHelper {
|
|||
return 0.0f;
|
||||
}
|
||||
|
||||
static void setNodeRight(Node* pNode, float right)
|
||||
static void setNodeRight(cocos2d::Node* pNode, float right)
|
||||
{
|
||||
Node* pNodeParent = pNode->getParent();
|
||||
cocos2d::Node* pNodeParent = pNode->getParent();
|
||||
if ((pNodeParent))
|
||||
{
|
||||
nodes_layout::setNodeRight(pNode, pNodeParent->getContentSize(), right);
|
||||
setNodeRight(pNode, pNodeParent->getContentSize(), right);
|
||||
}
|
||||
}
|
||||
static float getNodeRight(Node* pNode, float anchor = 0.0f)
|
||||
static float getNodeRight(cocos2d::Node* pNode, float anchor = 0.0f)
|
||||
{
|
||||
Node* pNodeParent = pNode->getParent();
|
||||
cocos2d::Node* pNodeParent = pNode->getParent();
|
||||
if ((pNodeParent))
|
||||
{
|
||||
return getNodeRight(pNode, pNodeParent->getContentSize(), anchor);
|
||||
|
@ -321,18 +298,18 @@ namespace LayoutHelper {
|
|||
return 0.0f;
|
||||
}
|
||||
|
||||
static void setNodeBottom(Node* pNode, float bottom, float anchor = .0f)
|
||||
static void setNodeBottom(cocos2d::Node* pNode, float bottom, float anchor = .0f)
|
||||
{
|
||||
Node* pNodeParent = pNode->getParent();
|
||||
cocos2d::Node* pNodeParent = pNode->getParent();
|
||||
if ((pNodeParent))
|
||||
{
|
||||
nodes_layout::setNodeBottom(pNode, pNodeParent->getContentSize(), bottom, anchor);
|
||||
setNodeBottom(pNode, pNodeParent->getContentSize(), bottom, anchor);
|
||||
}
|
||||
}
|
||||
|
||||
static float getNodeBottom(Node* pNode, float anchor = 0.0f)
|
||||
static float getNodeBottom(cocos2d::Node* pNode, float anchor = 0.0f)
|
||||
{
|
||||
Node* pNodeParent = pNode->getParent();
|
||||
cocos2d::Node* pNodeParent = pNode->getParent();
|
||||
if ((pNodeParent))
|
||||
{
|
||||
return getNodeBottom(pNode, pNodeParent->getContentSize(), anchor);
|
||||
|
@ -340,44 +317,44 @@ namespace LayoutHelper {
|
|||
return 0.0f;
|
||||
}
|
||||
|
||||
static void setNodeLB(Node* pNode, const cocos2d::Point& p)
|
||||
static void setNodeLB(cocos2d::Node* pNode, const cocos2d::Point& p)
|
||||
{ // left bottom
|
||||
Node* pNodeParent = pNode->getParent();
|
||||
cocos2d::Node* pNodeParent = pNode->getParent();
|
||||
if ((pNodeParent))
|
||||
{
|
||||
nodes_layout::setNodeLB(pNode, pNodeParent->getContentSize(), p);
|
||||
setNodeLB(pNode, pNodeParent->getContentSize(), p);
|
||||
}
|
||||
}
|
||||
|
||||
static void setNodeRB(Node* pNode, const cocos2d::Point& p)
|
||||
static void setNodeRB(cocos2d::Node* pNode, const cocos2d::Point& p)
|
||||
{ // right bottom
|
||||
Node* pNodeParent = pNode->getParent();
|
||||
cocos2d::Node* pNodeParent = pNode->getParent();
|
||||
if ((pNodeParent))
|
||||
{
|
||||
nodes_layout::setNodeRB(pNode, pNodeParent->getContentSize(), p);
|
||||
setNodeRB(pNode, pNodeParent->getContentSize(), p);
|
||||
}
|
||||
}
|
||||
|
||||
static void setNodeLT(Node* pNode, const cocos2d::Point& p)
|
||||
static void setNodeLT(cocos2d::Node* pNode, const cocos2d::Point& p)
|
||||
{ // left top
|
||||
Node* pNodeParent = pNode->getParent();
|
||||
cocos2d::Node* pNodeParent = pNode->getParent();
|
||||
if ((pNodeParent))
|
||||
{
|
||||
nodes_layout::setNodeLT(pNode, pNodeParent->getContentSize(), p);
|
||||
setNodeLT(pNode, pNodeParent->getContentSize(), p);
|
||||
}
|
||||
}
|
||||
|
||||
static void setNodeRT(Node* pNode, const cocos2d::Point& p)
|
||||
static void setNodeRT(cocos2d::Node* pNode, const cocos2d::Point& p)
|
||||
{ // right top
|
||||
Node* pNodeParent = pNode->getParent();
|
||||
cocos2d::Node* pNodeParent = pNode->getParent();
|
||||
if ((pNodeParent))
|
||||
{
|
||||
nodes_layout::setNodeRT(pNode, pNodeParent->getContentSize(), p);
|
||||
setNodeRT(pNode, pNodeParent->getContentSize(), p);
|
||||
}
|
||||
}
|
||||
|
||||
// @version 2 used as internal interfaces
|
||||
static void setNodeLeft(Node* pNode, const cocos2d::Size& parentSize, float left, float anchor = 0.0f)
|
||||
static void setNodeLeft(cocos2d::Node* pNode, const cocos2d::Size& parentSize, float left, float anchor = 0.0f)
|
||||
{
|
||||
CC_ASSERT(pNode);
|
||||
|
||||
|
@ -389,11 +366,11 @@ namespace LayoutHelper {
|
|||
}
|
||||
pNode->setPositionX(adjust_coord(size.width, achorX, left) - size.width * anchor);
|
||||
}
|
||||
static float getNodeLeft(Node* pNode, const cocos2d::Size& parentSize, float anchor = 0.0f)
|
||||
static float getNodeLeft(cocos2d::Node* pNode, const cocos2d::Size& parentSize, float anchor = 0.0f)
|
||||
{
|
||||
CC_ASSERT(pNode);
|
||||
|
||||
Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
cocos2d::Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
float achorX = 0.0f;
|
||||
if (!pNode->isIgnoreAnchorPointForPosition())
|
||||
{
|
||||
|
@ -402,7 +379,7 @@ namespace LayoutHelper {
|
|||
return adjust_coord_r(size.width, achorX, pNode->getPositionX()) + anchor * size.width;
|
||||
}
|
||||
|
||||
static void setNodeTop(Node* pNode, const cocos2d::Size& parentSize, float top, float anchor = 0.0f)
|
||||
static void setNodeTop(cocos2d::Node* pNode, const cocos2d::Size& parentSize, float top, float anchor = 0.0f)
|
||||
{
|
||||
CC_ASSERT(pNode);
|
||||
|
||||
|
@ -414,11 +391,11 @@ namespace LayoutHelper {
|
|||
}
|
||||
pNode->setPositionY(adjust_coord_neg(parentSize.height, size.height, achorY, top) - size.height * anchor);
|
||||
}
|
||||
static float getNodeTop(Node* pNode, const cocos2d::Size& parentSize, float anchor = 0.0f)
|
||||
static float getNodeTop(cocos2d::Node* pNode, const cocos2d::Size& parentSize, float anchor = 0.0f)
|
||||
{
|
||||
CC_ASSERT(pNode);
|
||||
|
||||
Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
cocos2d::Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
float achorY = 0.0f;
|
||||
if (!pNode->isIgnoreAnchorPointForPosition())
|
||||
{
|
||||
|
@ -427,7 +404,7 @@ namespace LayoutHelper {
|
|||
return adjust_coord_neg_r(parentSize.height, size.height, achorY, pNode->getPositionY()) + size.height * anchor;
|
||||
}
|
||||
|
||||
static void setNodeRight(Node* pNode, const cocos2d::Size& parentSize, float right)
|
||||
static void setNodeRight(cocos2d::Node* pNode, const cocos2d::Size& parentSize, float right)
|
||||
{
|
||||
CC_ASSERT(pNode);
|
||||
|
||||
|
@ -440,11 +417,11 @@ namespace LayoutHelper {
|
|||
pNode->setPositionX(adjust_coord_neg(parentSize.width, size.width, achorX, right));
|
||||
}
|
||||
|
||||
static float getNodeRight(Node* pNode, const cocos2d::Size& parentSize, float anchor = 0.0f)
|
||||
static float getNodeRight(cocos2d::Node* pNode, const cocos2d::Size& parentSize, float anchor = 0.0f)
|
||||
{
|
||||
CC_ASSERT(pNode);
|
||||
|
||||
Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
cocos2d::Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
float achorX = 0.0f;
|
||||
if (!pNode->isIgnoreAnchorPointForPosition())
|
||||
{
|
||||
|
@ -453,11 +430,11 @@ namespace LayoutHelper {
|
|||
return adjust_coord_neg_r(parentSize.width, size.width, achorX, pNode->getPositionX()) + anchor * size.width;
|
||||
}
|
||||
|
||||
static void setNodeBottom(Node* pNode, const cocos2d::Size& parentSize, float bottom, float anchor = 0.0f)
|
||||
static void setNodeBottom(cocos2d::Node* pNode, const cocos2d::Size& parentSize, float bottom, float anchor = 0.0f)
|
||||
{
|
||||
CC_ASSERT(pNode);
|
||||
|
||||
Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
cocos2d::Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
float achorY = 0.0f;
|
||||
if (!pNode->isIgnoreAnchorPointForPosition())
|
||||
{
|
||||
|
@ -466,11 +443,11 @@ namespace LayoutHelper {
|
|||
pNode->setPositionY(adjust_coord(size.height, achorY, bottom) - anchor * size.height);
|
||||
}
|
||||
|
||||
static float getNodeBottom(Node* pNode, const cocos2d::Size& parentSize, float anchor = 0.f)
|
||||
static float getNodeBottom(cocos2d::Node* pNode, const cocos2d::Size& parentSize, float anchor = 0.f)
|
||||
{
|
||||
CC_ASSERT(pNode);
|
||||
|
||||
Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
cocos2d::Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
float achorY = 0.0f;
|
||||
if (!pNode->isIgnoreAnchorPointForPosition())
|
||||
{
|
||||
|
@ -479,12 +456,12 @@ namespace LayoutHelper {
|
|||
return adjust_coord_r(size.height, achorY, pNode->getPositionY()) + size.height * anchor;
|
||||
}
|
||||
|
||||
static void setNodeLB(Node* pNode, const cocos2d::Size& parentSize, const cocos2d::Point& p)
|
||||
static void setNodeLB(cocos2d::Node* pNode, const cocos2d::Size& parentSize, const cocos2d::Point& p)
|
||||
{ // left bottom
|
||||
CC_ASSERT(pNode);
|
||||
|
||||
Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
cocos2d::Point achorPoint = Vec2::ZERO;
|
||||
cocos2d::Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
cocos2d::Point achorPoint = cocos2d::Vec2::ZERO;
|
||||
if (!pNode->isIgnoreAnchorPointForPosition())
|
||||
{
|
||||
achorPoint = pNode->getAnchorPoint();
|
||||
|
@ -494,12 +471,12 @@ namespace LayoutHelper {
|
|||
adjust_coord(size.height, achorPoint.y, p.y)));
|
||||
}
|
||||
|
||||
static void setNodeRB(Node* pNode, const cocos2d::Size& parentSize, const cocos2d::Point& p)
|
||||
static void setNodeRB(cocos2d::Node* pNode, const cocos2d::Size& parentSize, const cocos2d::Point& p)
|
||||
{ // right bottom
|
||||
CC_ASSERT(pNode);
|
||||
|
||||
Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
cocos2d::Point achorPoint = Vec2::ZERO;
|
||||
cocos2d::Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
cocos2d::Point achorPoint = cocos2d::Vec2::ZERO;
|
||||
if (!pNode->isIgnoreAnchorPointForPosition())
|
||||
{
|
||||
achorPoint = pNode->getAnchorPoint();
|
||||
|
@ -509,12 +486,12 @@ namespace LayoutHelper {
|
|||
adjust_coord(size.height, achorPoint.y, p.y)));
|
||||
}
|
||||
|
||||
static void setNodeLT(Node* pNode, const cocos2d::Size& parentSize, const cocos2d::Point& p)
|
||||
static void setNodeLT(cocos2d::Node* pNode, const cocos2d::Size& parentSize, const cocos2d::Point& p)
|
||||
{ // left top
|
||||
CC_ASSERT(pNode);
|
||||
|
||||
Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
cocos2d::Point achorPoint = Vec2::ZERO;
|
||||
cocos2d::Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
cocos2d::Point achorPoint = cocos2d::Vec2::ZERO;
|
||||
if (!pNode->isIgnoreAnchorPointForPosition())
|
||||
{
|
||||
achorPoint = pNode->getAnchorPoint();
|
||||
|
@ -524,12 +501,12 @@ namespace LayoutHelper {
|
|||
adjust_coord_neg(parentSize.height, size.height, achorPoint.y, p.y)));
|
||||
}
|
||||
|
||||
static void setNodeRT(Node* pNode, const cocos2d::Size& parentSize, const cocos2d::Point& p)
|
||||
static void setNodeRT(cocos2d::Node* pNode, const cocos2d::Size& parentSize, const cocos2d::Point& p)
|
||||
{ // right top
|
||||
CC_ASSERT(pNode);
|
||||
|
||||
Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
cocos2d::Point achorPoint = Vec2::ZERO;
|
||||
cocos2d::Size size = pNode->getContentSize() * getScale2D(pNode);
|
||||
cocos2d::Point achorPoint = cocos2d::Vec2::ZERO;
|
||||
if (!pNode->isIgnoreAnchorPointForPosition())
|
||||
{
|
||||
achorPoint = pNode->getAnchorPoint();
|
||||
|
@ -557,9 +534,9 @@ namespace LayoutHelper {
|
|||
setNodeNormalizedPositionY(pNode, pNodeParent->getContentSize(), ratio);
|
||||
}
|
||||
}
|
||||
static void setNodeNormalizedPosition(Node* pNode, const cocos2d::Point& ratio)
|
||||
static void setNodeNormalizedPosition(cocos2d::Node* pNode, const cocos2d::Point& ratio)
|
||||
{
|
||||
Node* pNodeParent = pNode->getParent();
|
||||
cocos2d::Node* pNodeParent = pNode->getParent();
|
||||
if ((pNodeParent))
|
||||
{
|
||||
setNodeNormalizedPosition(pNode, pNodeParent->getContentSize(), ratio);
|
||||
|
@ -580,111 +557,62 @@ namespace LayoutHelper {
|
|||
|
||||
pNode->setPositionY(parentSize.height * ratio);
|
||||
}
|
||||
static void setNodeNormalizedPosition(Node* pNode, const cocos2d::Size& parentSize, const cocos2d::Point& ratio)
|
||||
static void setNodeNormalizedPosition(cocos2d::Node* pNode, const cocos2d::Size& parentSize, const cocos2d::Point& ratio)
|
||||
{
|
||||
CC_ASSERT(pNode);
|
||||
|
||||
pNode->setPosition(cocos2d::Point(parentSize.width * ratio.x, parentSize.height * ratio.y));
|
||||
}
|
||||
|
||||
///// visible screen location methods //////
|
||||
class CC_DLL scr {
|
||||
public:
|
||||
static void setNodePosition(Node* pNode, const cocos2d::Point& p)
|
||||
{
|
||||
setNodeNormalizedPosition(pNode, cocos2d::Vec2(p.x / designSize.width * nodes_layout::adjustedScale, p.y / designSize.height * nodes_layout::adjustedScale));
|
||||
}
|
||||
static void centerNode(Node* pNode)
|
||||
{
|
||||
setNodeNormalizedPosition(pNode, cocos2d::Vec2(.5f, .5f));
|
||||
}
|
||||
static void centerNodeX(Node* pNode)
|
||||
{
|
||||
setNodeNormalizedPositionX(pNode, .5f);
|
||||
}
|
||||
static void centerNodeY(Node* pNode)
|
||||
{
|
||||
setNodeNormalizedPositionY(pNode, .5f);
|
||||
}
|
||||
static void setNodeLeft(Node* pNode, float left);
|
||||
static void setNodeTop(Node* pNode, float top);
|
||||
static void setNodeRight(Node* pNode, float right);
|
||||
static void setNodeBottom(Node* pNode, float bottom);
|
||||
|
||||
static float getNodeLeft(Node* pNode);
|
||||
static float getNodeTop(Node* pNode);
|
||||
static float getNodeRight(Node* pNode);
|
||||
static float getNodeBottom(Node* pNode);
|
||||
|
||||
static void setNodeLT(Node* pNode, const cocos2d::Point& p);
|
||||
static void setNodeRT(Node* pNode, const cocos2d::Point& p);
|
||||
static void setNodeLB(Node* pNode, const cocos2d::Point& p);
|
||||
static void setNodeRB(Node* pNode, const cocos2d::Point& p);
|
||||
|
||||
/// ratio position
|
||||
static void setNodeNormalizedLT(Node* pNode, const cocos2d::Point& ratio);
|
||||
static void setNodeNormalizedRT(Node* pNode, const cocos2d::Point& ratio);
|
||||
static void setNodeNormalizedLB(Node* pNode, const cocos2d::Point& ratio);
|
||||
static void setNodeNormalizedRB(Node* pNode, const cocos2d::Point& ratio);
|
||||
|
||||
static void setNodeNormalizedTop(Node* pNode, const float ratioTop);
|
||||
|
||||
static void setNodeNormalizedPositionX(cocos2d::Node* pNode, float ratio);
|
||||
|
||||
static void setNodeNormalizedPositionY(cocos2d::Node* pNode, float ratio);
|
||||
static void setNodeNormalizedPosition(Node* pNode, const cocos2d::Point& ratio);
|
||||
};
|
||||
|
||||
|
||||
/// Get node group size
|
||||
static Size getNodeGroupSize(const std::vector<Node*>& nodes);
|
||||
static cocos2d::Size getNodeGroupSize(const std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
static Size getNodeGroupScaledSize(const std::vector<Node*>& nodes);
|
||||
static cocos2d::Size getNodeGroupScaledSize(const std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
/// Set nodes group size
|
||||
static void setNodeGroupSize(const std::vector<Node*>& nodes, const cocos2d::Size& newSize);
|
||||
static void setNodeGroupSize(const std::vector<cocos2d::Node*>& nodes, const cocos2d::Size& newSize);
|
||||
|
||||
/// Get Node group left
|
||||
static float getNodeGroupLeft(const std::vector<Node*>& nodes);
|
||||
static float getNodeGroupLeft(const std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
/// Get node group top
|
||||
static float getNodeGroupTop(const std::vector<Node*>& nodes);
|
||||
static float getNodeGroupTop(const std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
/// Get node group right
|
||||
static float getNodeGroupRight(const std::vector<Node*>& nodes);
|
||||
static float getNodeGroupRight(const std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
/// Get node group bottom
|
||||
static float getNodeGroupBottom(const std::vector<Node*>& nodes);
|
||||
static float getNodeGroupBottom(const std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
/*
|
||||
** setNodeGroupLeft
|
||||
**
|
||||
*/
|
||||
static void setNodeGroupLeft(const std::vector<Node*>& nodes, float left);
|
||||
static void setNodeGroupLeft(const std::vector<cocos2d::Node*>& nodes, float left);
|
||||
|
||||
/*
|
||||
** setNodeGroupLeft
|
||||
**
|
||||
*/
|
||||
static void setNodeGroupTop(const std::vector<Node*>& nodes, float top);
|
||||
static void setNodeGroupTop(const std::vector<cocos2d::Node*>& nodes, float top);
|
||||
|
||||
static void setNodeGroupLT(const std::vector<Node*>& nodes, const cocos2d::Vec2& p);
|
||||
static void setNodeGroupLT(const std::vector<cocos2d::Node*>& nodes, const cocos2d::Vec2& p);
|
||||
|
||||
/*
|
||||
** setNodeGroupRight
|
||||
**
|
||||
*/
|
||||
static void setNodeGroupRight(const std::vector<Node*>& nodes, float right);
|
||||
static void setNodeGroupRight(const std::vector<cocos2d::Node*>& nodes, float right);
|
||||
|
||||
/*
|
||||
** setNodeGroupRight
|
||||
**
|
||||
*/
|
||||
static void setNodeGroupBottom(const std::vector<Node*>& nodes, float bottom);
|
||||
static void setNodeGroupBottom(const std::vector<cocos2d::Node*>& nodes, float bottom);
|
||||
|
||||
//// move node group, use UI direction
|
||||
static void moveNodeGroupHorizontally(const std::vector<Node*>& nodes, float delta);
|
||||
static void moveNodeGroupVertically(const std::vector<Node*>& nodes, float delta);
|
||||
static void moveNodeGroupHorizontally(const std::vector<cocos2d::Node*>& nodes, float delta);
|
||||
static void moveNodeGroupVertically(const std::vector<cocos2d::Node*>& nodes, float delta);
|
||||
|
||||
/* @brief: group layout and alignment
|
||||
** @remark:
|
||||
|
@ -693,145 +621,210 @@ namespace LayoutHelper {
|
|||
/// Center horiz to parent
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void centerHorizontally(const std::vector<Node*>& nodes);
|
||||
static void centerHorizontally(const std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
/// <summary>
|
||||
/// Center vertical to parent
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void centerVertically(const std::vector<Node*>& nodes);
|
||||
static void centerVertically(const std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
/// <summary>
|
||||
/// Center to parent
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void centerToParent(const std::vector<Node*>& nodes);
|
||||
static void centerToParent(const std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
/// <summary>
|
||||
/// Align lefts
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void alignLefts(const std::vector<Node*>& nodes);
|
||||
static void alignLefts(const std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
/// <summary>
|
||||
/// Align rights
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void alignRights(const std::vector<Node*>& nodes);
|
||||
static void alignRights(const std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
/// <summary>
|
||||
/// Align tops
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void alignTops(const std::vector<Node*>& nodes);
|
||||
static void alignTops(const std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
/// <summary>
|
||||
/// Align bottoms
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void alignBottoms(const std::vector<Node*>& nodes);
|
||||
static void alignBottoms(const std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
/// <summary>
|
||||
/// Align horiz
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void alignHorizontals(const std::vector<Node*>& nodes);
|
||||
static void alignHorizontals(const std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
/// <summary>
|
||||
/// Align vertical
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void alignVerticals(const std::vector<Node*>& nodes);
|
||||
static void alignVerticals(const std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
/// <summary>
|
||||
/// Align centers
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void alignCenters(const std::vector<Node*>& nodes);
|
||||
static void alignCenters(const std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
/// <summary>
|
||||
/// Make same width
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void makeSameWidth(const std::vector<Node*>& nodes);
|
||||
static void makeSameWidth(const std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
/// <summary>
|
||||
/// Make same height
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void makeSameHeight(const std::vector<Node*>& nodes);
|
||||
static void makeSameHeight(const std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
/// <summary>
|
||||
/// Make same size
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void makeSameSize(const std::vector<Node*>& nodes);
|
||||
static void makeSameSize(const std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
/// <summary>
|
||||
/// Make horiz spacing equal
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void makeHorizontalSpacingEqual(std::vector<Node*>& nodes);
|
||||
static void makeHorizontalSpacingEqual(std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
/// <summary>
|
||||
/// Make vertical spacing equal
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void makeVerticalSpacingEqual(std::vector<Node*>& nodes);
|
||||
static void makeVerticalSpacingEqual(std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
/// <summary>
|
||||
/// Increease horiz spacing
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void increaseHorizontalSpacing(std::vector<Node*>& nodes, float theSpacing);
|
||||
static void increaseHorizontalSpacing(std::vector<cocos2d::Node*>& nodes, float theSpacing);
|
||||
|
||||
/// <summary>
|
||||
/// Increase vertical spacing
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void increaseVerticalSpacing(std::vector<Node*>& nodes, float theSpacing);
|
||||
static void increaseVerticalSpacing(std::vector<cocos2d::Node*>& nodes, float theSpacing);
|
||||
|
||||
/// <summary>
|
||||
/// Decrease horiz spacing
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void decreaseHorizontalSpacing(std::vector<Node*>& nodes, float theSpacing);
|
||||
static void decreaseHorizontalSpacing(std::vector<cocos2d::Node*>& nodes, float theSpacing);
|
||||
|
||||
/// <summary>
|
||||
/// Decrease vertical spacing
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void decreaseVerticalSpacing(std::vector<Node*>& nodes, float theSpacing);
|
||||
static void decreaseVerticalSpacing(std::vector<cocos2d::Node*>& nodes, float theSpacing);
|
||||
|
||||
/// <summary>
|
||||
/// Remove horiz spacing
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void removeHorizontalSpacing(const std::vector<Node*>& nodes);
|
||||
static void removeHorizontalSpacing(const std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
/// <summary>
|
||||
/// Remove Vertical spacing
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void removeVerticalSpacing(const std::vector<Node*>& nodes);
|
||||
static void removeVerticalSpacing(const std::vector<cocos2d::Node*>& nodes);
|
||||
|
||||
/// <summary>
|
||||
/// maybe for internal use
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void makeHorizontalSpacingEqual(const std::vector<Node*>& nodes, float theSpacing);
|
||||
static void makeHorizontalSpacingEqual(const std::vector<cocos2d::Node*>& nodes, float theSpacing);
|
||||
|
||||
/// <summary>
|
||||
/// maybe for internal use
|
||||
/// </summary>
|
||||
/// <param name="nodes"></param>
|
||||
static void makeVerticalSpacingEqual(const std::vector<Node*>& nodes, float theSpacing);
|
||||
static void makeVerticalSpacingEqual(const std::vector<cocos2d::Node*>& nodes, float theSpacing);
|
||||
|
||||
/// <summary>
|
||||
/// CLASS VisibleRect
|
||||
/// </summary>
|
||||
class CC_DLL VisibleRect
|
||||
{
|
||||
public:
|
||||
static void refresh(void);
|
||||
|
||||
}; /* STATIC CLASS nodes_layout */
|
||||
static cocos2d::Rect getScreenVisibleRect();
|
||||
static cocos2d::Size size();
|
||||
static cocos2d::Point left();
|
||||
static cocos2d::Point right();
|
||||
static cocos2d::Point top();
|
||||
static cocos2d::Point bottom();
|
||||
static cocos2d::Point center();
|
||||
static cocos2d::Point leftTop();
|
||||
static cocos2d::Point rightTop();
|
||||
static cocos2d::Point leftBottom();
|
||||
static cocos2d::Point rightBottom();
|
||||
|
||||
// ------- The APIs for set layout node in visible screen rect ------
|
||||
static void setNodePosition(cocos2d::Node* pNode, const cocos2d::Point& p)
|
||||
{
|
||||
setNodeNormalizedPosition(pNode, cocos2d::Vec2(p.x / s_designSize.width * s_adjustedScale, p.y / s_designSize.height * s_adjustedScale));
|
||||
}
|
||||
static void centerNode(cocos2d::Node* pNode)
|
||||
{
|
||||
setNodeNormalizedPosition(pNode, cocos2d::Vec2(.5f, .5f));
|
||||
}
|
||||
static void centerNodeX(cocos2d::Node* pNode)
|
||||
{
|
||||
setNodeNormalizedPositionX(pNode, .5f);
|
||||
}
|
||||
static void centerNodeY(cocos2d::Node* pNode)
|
||||
{
|
||||
setNodeNormalizedPositionY(pNode, .5f);
|
||||
}
|
||||
|
||||
using namespace LayoutHelper;
|
||||
static void setNodeLeft(cocos2d::Node* pNode, float left);
|
||||
static void setNodeTop(cocos2d::Node* pNode, float top);
|
||||
static void setNodeRight(cocos2d::Node* pNode, float right);
|
||||
static void setNodeBottom(cocos2d::Node* pNode, float bottom);
|
||||
|
||||
static float getNodeLeft(cocos2d::Node* pNode);
|
||||
static float getNodeTop(cocos2d::Node* pNode);
|
||||
static float getNodeRight(cocos2d::Node* pNode);
|
||||
static float getNodeBottom(cocos2d::Node* pNode);
|
||||
|
||||
static void setNodeLT(cocos2d::Node* pNode, const cocos2d::Point& p);
|
||||
static void setNodeRT(cocos2d::Node* pNode, const cocos2d::Point& p);
|
||||
static void setNodeLB(cocos2d::Node* pNode, const cocos2d::Point& p);
|
||||
static void setNodeRB(cocos2d::Node* pNode, const cocos2d::Point& p);
|
||||
|
||||
/// ratio position
|
||||
static void setNodeNormalizedLT(cocos2d::Node* pNode, const cocos2d::Point& ratio);
|
||||
static void setNodeNormalizedRT(cocos2d::Node* pNode, const cocos2d::Point& ratio);
|
||||
static void setNodeNormalizedLB(cocos2d::Node* pNode, const cocos2d::Point& ratio);
|
||||
static void setNodeNormalizedRB(cocos2d::Node* pNode, const cocos2d::Point& ratio);
|
||||
|
||||
static void setNodeNormalizedTop(cocos2d::Node* pNode, const float ratioTop);
|
||||
|
||||
static void setNodeNormalizedPositionX(cocos2d::Node* pNode, float ratio);
|
||||
|
||||
static void setNodeNormalizedPositionY(cocos2d::Node* pNode, float ratio);
|
||||
static void setNodeNormalizedPosition(cocos2d::Node* pNode, const cocos2d::Point& ratio);
|
||||
|
||||
private:
|
||||
static void lazyInit();
|
||||
static cocos2d::Rect s_ScreenVisibleRect;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue