Sync LayoutHelper APIs

This commit is contained in:
halx99 2020-08-26 12:46:41 +08:00
parent c596975a93
commit 6be52c29e7
3 changed files with 1005 additions and 1030 deletions

View File

@ -80,7 +80,7 @@ set(COCOS_UI_HEADER
ui/UIAbstractCheckButton.h ui/UIAbstractCheckButton.h
ui/UIButton.h ui/UIButton.h
ui/UICheckBox.h ui/UICheckBox.h
# ui/UIDeprecated.h ui/LayoutHelper.h
ui/UIHBox.h ui/UIHBox.h
ui/UIHelper.h ui/UIHelper.h
ui/UIImageView.h ui/UIImageView.h
@ -115,7 +115,7 @@ set(COCOS_UI_SRC
ui/UIAbstractCheckButton.cpp ui/UIAbstractCheckButton.cpp
ui/UICheckBox.cpp ui/UICheckBox.cpp
ui/UIRadioButton.cpp ui/UIRadioButton.cpp
# ui/UIDeprecated.cpp ui/LayoutHelper.cpp
ui/UIHBox.cpp ui/UIHBox.cpp
ui/UIHelper.cpp ui/UIHelper.cpp
ui/UIImageView.cpp ui/UIImageView.cpp

View File

@ -1,156 +1,16 @@
// //
//
// Copyright (c) 2014-2020 Simdsoft Limited - All Rights Reserved // Copyright (c) 2014-2020 Simdsoft Limited - All Rights Reserved
// //
#include "LayoutHelper.h" #include "ui/LayoutHelper.h"
namespace LayoutHelper { USING_NS_CC;
cocos2d::Rect ScreenVisibleRect::s_ScreenVisibleRect;
/// x-studio365: when design resolution changed, should call this func. Size LayoutHelper::s_designSize;
void ScreenVisibleRect::refresh(void) float LayoutHelper::s_adjustedScale = 1.0f;
void LayoutHelper::setDesignSizeFixedEdge(const Size& designSize)
{ {
auto director = Director::getInstance(); LayoutHelper::s_designSize = designSize;
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;
// Set the design resolution//分辨率的大小 // Set the design resolution//分辨率的大小
GLView* pEGLView = Director::getInstance()->getOpenGLView(); 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(); // save smart size
return cocos2d::Vec2((adjustedDesignSize.width - nodes_layout::designSize.width) * .5f, LayoutHelper::s_designSize = designSize;
(adjustedDesignSize.height - nodes_layout::designSize.height) * .5f);
// 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::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::Size nodes_layout::getVisibleSize(void) 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 /// Get node group size
Size nodes_layout::getNodeGroupSize(const std::vector<Node*>& nodes) Size LayoutHelper::getNodeGroupSize(const std::vector<Node*>& nodes)
{ {
if (nodes.empty()) if (nodes.empty())
{ {
@ -225,7 +113,7 @@ Size nodes_layout::getNodeGroupSize(const std::vector<Node*>& nodes)
} }
/// Set nodes group size /// 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); cocos2d::Size groupSize = getNodeGroupScaledSize(nodes);
if (groupSize.height == 0 || groupSize.width == 0 || newSize.width == 0 || newSize.height == 0) 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()) if (nodes.empty())
{ {
@ -266,8 +154,8 @@ Size nodes_layout::getNodeGroupScaledSize(const std::vector<Node*>& nodes)
auto scale = getScale2D(nodes[0]); auto scale = getScale2D(nodes[0]);
// group nodes locators // group nodes locators
float minX = nodes_layout::getNodeLeft(nodes[0]), maxX = nodes_layout::getNodeLeft(nodes[0]) + nodes[0]->getContentSize().width * scale.x; float minX = LayoutHelper::getNodeLeft(nodes[0]), maxX = LayoutHelper::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 minY = LayoutHelper::getNodeTop(nodes[0]), maxY = LayoutHelper::getNodeTop(nodes[0]) + nodes[0]->getContentSize().height * scale.y;
float x = 0.0f, y = 0.0f; float x = 0.0f, y = 0.0f;
// float width = 0.0f, height = 0.f; // float width = 0.0f, height = 0.f;
for (size_t index = 1; index < nodes.size(); ++index) { 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); scale = getScale2D(child);
if (minX >(x = nodes_layout::getNodeLeft(child))) if (minX >(x = LayoutHelper::getNodeLeft(child)))
{ {
minX = x; minX = x;
} }
@ -284,7 +172,7 @@ Size nodes_layout::getNodeGroupScaledSize(const std::vector<Node*>& nodes)
maxX = x + child->getContentSize().width * scale.x; maxX = x + child->getContentSize().width * scale.x;
} }
if (minY >(y = nodes_layout::getNodeTop(child))) if (minY >(y = LayoutHelper::getNodeTop(child)))
{ {
minY = y; minY = y;
} }
@ -301,7 +189,7 @@ Size nodes_layout::getNodeGroupScaledSize(const std::vector<Node*>& nodes)
} }
/// Get Node group left /// 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; size_t index = 0;
float minLeft = getNodeLeft(nodes[index]); float minLeft = getNodeLeft(nodes[index]);
@ -316,7 +204,7 @@ float nodes_layout::getNodeGroupLeft(const std::vector<Node*>& nodes)
} }
/// Get node group top /// 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; size_t index = 0;
float minTop = getNodeTop(nodes[index]); float minTop = getNodeTop(nodes[index]);
@ -331,7 +219,7 @@ float nodes_layout::getNodeGroupTop(const std::vector<Node*>& nodes)
} }
/// Get node group right /// 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; size_t index = 0;
float minRight = getNodeRight(nodes[index]); float minRight = getNodeRight(nodes[index]);
@ -346,7 +234,7 @@ float nodes_layout::getNodeGroupRight(const std::vector<Node*>& nodes)
} }
/// Get node group bottom /// 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; size_t index = 0;
float minBottom = getNodeBottom(nodes[index]); float minBottom = getNodeBottom(nodes[index]);
@ -364,7 +252,7 @@ float nodes_layout::getNodeGroupBottom(const std::vector<Node*>& nodes)
** setNodeGroupLeft ** 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); float delta = left - getNodeGroupLeft(nodes);
@ -378,7 +266,7 @@ void nodes_layout::setNodeGroupLeft(const std::vector<Node*>& nodes, float left)
** setNodeGroupLeft ** 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); 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 deltaL = p.x - getNodeGroupLeft(nodes);
float deltaT = p.y - getNodeGroupTop(nodes); float deltaT = p.y - getNodeGroupTop(nodes);
@ -403,7 +291,7 @@ void nodes_layout::setNodeGroupLT(const std::vector<Node*>& nodes, const cocos2d
** setNodeGroupRight ** 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); float delta = right - getNodeGroupRight(nodes);
@ -417,7 +305,7 @@ void nodes_layout::setNodeGroupRight(const std::vector<Node*>& nodes, float righ
** setNodeGroupRight ** 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); 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) 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) for (auto node : nodes)
{ {
@ -450,7 +338,7 @@ void nodes_layout::moveNodeGroupVertically(const std::vector<Node*>& nodes, floa
/// 水平居中 /// 水平居中
/// </summary> /// </summary>
/// <param name="nodes"></param> /// <param name="nodes"></param>
void nodes_layout::centerHorizontally(const std::vector<Node*>& nodes) void LayoutHelper::centerHorizontally(const std::vector<Node*>& nodes)
{ {
if (nodes.empty()) if (nodes.empty())
{ {
@ -508,7 +396,7 @@ void nodes_layout::centerHorizontally(const std::vector<Node*>& nodes)
/// 垂直居中 /// 垂直居中
/// </summary> /// </summary>
/// <param name="nodes"></param> /// <param name="nodes"></param>
void nodes_layout::centerVertically(const std::vector<Node*>& nodes) void LayoutHelper::centerVertically(const std::vector<Node*>& nodes)
{ {
if (nodes.empty()) if (nodes.empty())
{ {
@ -552,7 +440,7 @@ void nodes_layout::centerVertically(const std::vector<Node*>& nodes)
/// 居中 /// 居中
/// </summary> /// </summary>
/// <param name="nodes"></param> /// <param name="nodes"></param>
void nodes_layout::centerHoriVerti(const std::vector<Node*>& nodes) void LayoutHelper::centerToParent(const std::vector<Node*>& nodes)
{ {
if (nodes.empty()) if (nodes.empty())
{ {
@ -560,7 +448,7 @@ void nodes_layout::centerHoriVerti(const std::vector<Node*>& nodes)
} }
else if (nodes.size() == 1) else if (nodes.size() == 1)
{ {
centerNode(nodes[0]); LayoutHelper::centerNode(nodes[0]);
return; return;
} }
@ -607,7 +495,7 @@ void nodes_layout::centerHoriVerti(const std::vector<Node*>& nodes)
/// 左对齐 /// 左对齐
/// </summary> /// </summary>
/// <param name="nodes"></param> /// <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) if (nodes.size() < 2)
return; return;
@ -633,7 +521,7 @@ void nodes_layout::alignLefts(const std::vector<Node*>& nodes)
/// 右对齐 /// 右对齐
/// </summary> /// </summary>
/// <param name="nodes"></param> /// <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) if (nodes.size() < 2)
return; return;
@ -660,7 +548,7 @@ void nodes_layout::alignRights(const std::vector<Node*>& nodes)
/// 顶端对齐 /// 顶端对齐
/// </summary> /// </summary>
/// <param name="nodes"></param> /// <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) if (nodes.size() < 2)
return; return;
@ -686,7 +574,7 @@ void nodes_layout::alignTops(const std::vector<Node*>& nodes)
/// 底端对齐 /// 底端对齐
/// </summary> /// </summary>
/// <param name="nodes"></param> /// <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) if (nodes.size() < 2)
return; return;
@ -712,7 +600,7 @@ void nodes_layout::alignBottoms(const std::vector<Node*>& nodes)
/// 水平对齐 /// 水平对齐
/// </summary> /// </summary>
/// <param name="nodes"></param> /// <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) if (nodes.size() < 2)
return; return;
@ -745,7 +633,7 @@ void nodes_layout::alignHorizontals(const std::vector<Node*>& nodes)
/// 垂直对齐 /// 垂直对齐
/// </summary> /// </summary>
/// <param name="nodes"></param> /// <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) if (nodes.size() < 2)
return; return;
@ -778,7 +666,7 @@ void nodes_layout::alignVerticals(const std::vector<Node*>& nodes)
/// 中心原点对齐 /// 中心原点对齐
/// </summary> /// </summary>
/// <param name="nodes"></param> /// <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) if (nodes.size() < 2)
return; return;
@ -791,7 +679,7 @@ void nodes_layout::alignCenters(const std::vector<Node*>& nodes)
/// 使宽度相等 /// 使宽度相等
/// </summary> /// </summary>
/// <param name="nodes"></param> /// <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) if (nodes.size() < 2)
return; return;
@ -817,7 +705,7 @@ void nodes_layout::makeSameWidth(const std::vector<Node*>& nodes)
/// 使高度相等 /// 使高度相等
/// </summary> /// </summary>
/// <param name="nodes"></param> /// <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) if (nodes.size() < 2)
return; return;
@ -843,7 +731,7 @@ void nodes_layout::makeSameHeight(const std::vector<Node*>& nodes)
/// 使得大小相等 /// 使得大小相等
/// </summary> /// </summary>
/// <param name="nodes"></param> /// <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) if (nodes.size() < 2)
return; return;
@ -856,7 +744,7 @@ void nodes_layout::makeSameSize(const std::vector<Node*>& nodes)
/// 使水平间距相等 /// 使水平间距相等
/// </summary> /// </summary>
/// <param name="nodes"></param> /// <param name="nodes"></param>
void nodes_layout::makeHorizontalSpacingEqual(std::vector<Node*>& nodes) void LayoutHelper::makeHorizontalSpacingEqual(std::vector<Node*>& nodes)
{ {
if (nodes.size() < 3) if (nodes.size() < 3)
return; return;
@ -883,14 +771,14 @@ void nodes_layout::makeHorizontalSpacingEqual(std::vector<Node*>& nodes)
if (avgHSpacing < 0.0f) avgHSpacing = 0.0f; if (avgHSpacing < 0.0f) avgHSpacing = 0.0f;
nodes_layout::makeHorizontalSpacingEqual(nodes, avgHSpacing); LayoutHelper::makeHorizontalSpacingEqual(nodes, avgHSpacing);
} }
/// <summary> /// <summary>
/// 使水平间距相等 /// 使水平间距相等
/// </summary> /// </summary>
/// <param name="nodes"></param> /// <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; Node* child, *childNext;
for (size_t index = 0; index < nodes.size() - 1; ++index) 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> /// </summary>
/// <param name="nodes"></param> /// <param name="nodes"></param>
void nodes_layout::makeVerticalSpacingEqual(std::vector<Node*>& nodes) void LayoutHelper::makeVerticalSpacingEqual(std::vector<Node*>& nodes)
{ {
if (nodes.size() < 3) if (nodes.size() < 3)
return; return;
@ -931,10 +819,10 @@ void nodes_layout::makeVerticalSpacingEqual(std::vector<Node*>& nodes)
if (avgVSpacing < 0.0f) avgVSpacing = 0.0f; 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) if (nodes.size() < 2)
return; 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) if (nodes.size() < 2)
return; 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); 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); 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>
/// 使垂直间距相等 /// 使垂直间距相等
/// </summary> /// </summary>
/// <param name="nodes"></param> /// <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; Node* child, *childNext;
for (size_t index = 0; index < nodes.size() - 1; ++index) 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 // ----------------- LayoutHelper::VisibleRect --------------------------
float nodes_layout::scr::getNodeLeft(Node* pNode)
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); auto ptWorld = pNode->getParent()->convertToWorldSpace(ptLocal);
return ptWorld.x; 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); auto ptWorld = pNode->getParent()->convertToWorldSpace(ptLocal);
return ptWorld.y; 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 ptWorld = pNode->getParent()->convertToWorldSpace(ptLocal);
auto ScreenVisibleRect = ScreenVisibleRect::getScreenVisibleRect(); auto visibleRect = LayoutHelper::VisibleRect::getScreenVisibleRect();
return ScreenVisibleRect.size.width - ptWorld.x; 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 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); CC_ASSERT(pNode);
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize(); 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); Size size = pNode->getContentSize() * getScale2D(pNode);
cocos2d::Point achorPoint = Vec2::ZERO; cocos2d::Point achorPoint = Vec2::ZERO;
if (!pNode->isIgnoreAnchorPointForPosition()) if (!pNode->isIgnoreAnchorPointForPosition())
@ -1049,11 +1033,11 @@ void nodes_layout::scr::setNodeLeft(Node* pNode, float left)
pNode->setPositionX(ptLocal.x); pNode->setPositionX(ptLocal.x);
} }
void nodes_layout::scr::setNodeTop(Node* pNode, float top) void LayoutHelper::VisibleRect::setNodeTop(Node* pNode, float top)
{ {
CC_ASSERT(pNode); CC_ASSERT(pNode);
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize(); 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); Size size = pNode->getContentSize() * getScale2D(pNode);
cocos2d::Point achorPoint = Vec2::ZERO; cocos2d::Point achorPoint = Vec2::ZERO;
if (!pNode->isIgnoreAnchorPointForPosition()) if (!pNode->isIgnoreAnchorPointForPosition())
@ -1066,11 +1050,11 @@ void nodes_layout::scr::setNodeTop(Node* pNode, float top)
pNode->setPositionY(ptLocal.y); pNode->setPositionY(ptLocal.y);
} }
void nodes_layout::scr::setNodeRight(Node* pNode, float right) void LayoutHelper::VisibleRect::setNodeRight(Node* pNode, float right)
{ {
CC_ASSERT(pNode); CC_ASSERT(pNode);
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize(); 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); Size size = pNode->getContentSize() * getScale2D(pNode);
cocos2d::Point achorPoint = Vec2::ZERO; cocos2d::Point achorPoint = Vec2::ZERO;
if (!pNode->isIgnoreAnchorPointForPosition()) if (!pNode->isIgnoreAnchorPointForPosition())
@ -1082,11 +1066,11 @@ void nodes_layout::scr::setNodeRight(Node* pNode, float right)
auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld); auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld);
pNode->setPositionX(ptLocal.x); pNode->setPositionX(ptLocal.x);
} }
void nodes_layout::scr::setNodeBottom(Node* pNode, float bottom) void LayoutHelper::VisibleRect::setNodeBottom(Node* pNode, float bottom)
{ {
CC_ASSERT(pNode); CC_ASSERT(pNode);
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize(); 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); Size size = pNode->getContentSize() * getScale2D(pNode);
cocos2d::Point achorPoint = Vec2::ZERO; cocos2d::Point achorPoint = Vec2::ZERO;
if (!pNode->isIgnoreAnchorPointForPosition()) 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); CC_ASSERT(pNode);
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize(); 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); Size size = pNode->getContentSize() * getScale2D(pNode);
cocos2d::Point achorPoint = Vec2::ZERO; cocos2d::Point achorPoint = Vec2::ZERO;
if (!pNode->isIgnoreAnchorPointForPosition()) if (!pNode->isIgnoreAnchorPointForPosition())
@ -1117,11 +1101,11 @@ void nodes_layout::scr::setNodeLT(Node* pNode, const cocos2d::Point& p)
auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld); auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld);
pNode->setPosition(ptLocal); 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 { // right top
CC_ASSERT(pNode); CC_ASSERT(pNode);
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize(); 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); Size size = pNode->getContentSize() * getScale2D(pNode);
cocos2d::Point achorPoint = Vec2::ZERO; cocos2d::Point achorPoint = Vec2::ZERO;
if (!pNode->isIgnoreAnchorPointForPosition()) if (!pNode->isIgnoreAnchorPointForPosition())
@ -1133,11 +1117,11 @@ void nodes_layout::scr::setNodeRT(Node* pNode, const cocos2d::Point& p)
auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld); auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld);
pNode->setPosition(ptLocal); 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 { // left bottom
CC_ASSERT(pNode); CC_ASSERT(pNode);
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize(); 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); Size size = pNode->getContentSize() * getScale2D(pNode);
cocos2d::Point achorPoint = Vec2::ZERO; cocos2d::Point achorPoint = Vec2::ZERO;
if (!pNode->isIgnoreAnchorPointForPosition()) if (!pNode->isIgnoreAnchorPointForPosition())
@ -1149,11 +1133,11 @@ void nodes_layout::scr::setNodeLB(Node* pNode, const cocos2d::Point& p)
auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld); auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld);
pNode->setPosition(ptLocal); 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 { // right bottom
CC_ASSERT(pNode); CC_ASSERT(pNode);
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize(); 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::Size size = pNode->getContentSize() * getScale2D(pNode);
cocos2d::Point achorPoint = Vec2::ZERO; cocos2d::Point achorPoint = Vec2::ZERO;
if (!pNode->isIgnoreAnchorPointForPosition()) if (!pNode->isIgnoreAnchorPointForPosition())
@ -1168,14 +1152,14 @@ void nodes_layout::scr::setNodeRB(Node* pNode, const cocos2d::Point& p)
} }
/// ratio position /// 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); CC_ASSERT(pNode);
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize(); 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::Point p = cocos2d::Vec2(vscrSize.width * ratio.x, vscrSize.height * ratio.y);
cocos2d::Size size = pNode->getContentSize() * getScale2D(pNode); 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); auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld);
pNode->setPosition(ptLocal); 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 { // right top
CC_ASSERT(pNode); CC_ASSERT(pNode);
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize(); 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::Point p = cocos2d::Vec2(vscrSize.width * ratio.x, vscrSize.height * ratio.y);
cocos2d::Size size = pNode->getContentSize() * getScale2D(pNode); 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); auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld);
pNode->setPosition(ptLocal); 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 { // left bottom
CC_ASSERT(pNode); CC_ASSERT(pNode);
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize(); 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::Point p = cocos2d::Vec2(vscrSize.width * ratio.x, vscrSize.height * ratio.y);
cocos2d::Size size = pNode->getContentSize() * getScale2D(pNode); 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); auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld);
pNode->setPosition(ptLocal); 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 { // right bottom
CC_ASSERT(pNode); CC_ASSERT(pNode);
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize(); 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::Point p = cocos2d::Vec2(vscrSize.width * ratio.x, vscrSize.height * ratio.y);
cocos2d::Size size = pNode->getContentSize() * getScale2D(pNode); 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); pNode->setPosition(ptLocal);
} }
void nodes_layout::scr::setNodeNormalizedTop(Node* pNode, const float ratioTop) void LayoutHelper::VisibleRect::setNodeNormalizedTop(Node* pNode, const float ratioTop)
{ // right top { // right top
CC_ASSERT(pNode); CC_ASSERT(pNode);
cocos2d::Size scrSize = Director::getInstance()->getOpenGLView()->getDesignResolutionSize(); 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; float top = vscrSize.width * ratioTop;
cocos2d::Size size = pNode->getContentSize() * getScale2D(pNode); 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); 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); CC_ASSERT(pNode);
cocos2d::Rect ScreenVisibleRect = LayoutHelper::ScreenVisibleRect::getScreenVisibleRect(); cocos2d::Rect visibleRect = LayoutHelper::LayoutHelper::VisibleRect::getScreenVisibleRect();
cocos2d::Point ptWorld(ScreenVisibleRect.size.width * ratio + ScreenVisibleRect.origin.x, 0); cocos2d::Point ptWorld(visibleRect.size.width * ratio + visibleRect.origin.x, 0);
auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld); auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld);
pNode->setPositionX(ptLocal.x); 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); 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); auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld);
pNode->setPositionY(ptLocal.y); 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); CC_ASSERT(pNode);
pNode->setIgnoreAnchorPointForPosition(false); pNode->setIgnoreAnchorPointForPosition(false);
pNode->setAnchorPoint(cocos2d::Vec2(.5f, .5f)); pNode->setAnchorPoint(cocos2d::Vec2(.5f, .5f));
cocos2d::Rect ScreenVisibleRect = LayoutHelper::ScreenVisibleRect::getScreenVisibleRect(); cocos2d::Rect visibleRect = LayoutHelper::LayoutHelper::VisibleRect::getScreenVisibleRect();
cocos2d::Point ptWorld(ScreenVisibleRect.size.width * ratio.x + ScreenVisibleRect.origin.x, ScreenVisibleRect.size.height * ratio.y + ScreenVisibleRect.origin.y); 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); auto ptLocal = pNode->getParent()->convertToNodeSpace(ptWorld);
pNode->setPosition(ptLocal); pNode->setPosition(ptLocal);
} }
}

File diff suppressed because it is too large Load Diff