2019-11-24 23:15:56 +08:00
|
|
|
//
|
2020-08-04 00:14:35 +08:00
|
|
|
// Copyright (c) 2014-2020 Simdsoft Limited - All Rights Reserved
|
|
|
|
// This module is used by x-studio UI Editor to layout UI elements
|
2019-11-24 23:15:56 +08:00
|
|
|
// It's very useful for programer to operate UI elements in runtime,
|
|
|
|
// so, we publish it to here.
|
|
|
|
// usage:
|
2020-08-04 00:14:35 +08:00
|
|
|
// #include "ui/LayoutHelper.h"
|
2020-08-26 12:46:41 +08:00
|
|
|
// LayoutHelper::centerNode(node); // the node should be already have parent.
|
|
|
|
// LayoutHelper::makeVerticalSpacingEqual(nodes); // all the nodes shoud be in the same parent.
|
2021-12-25 10:04:45 +08:00
|
|
|
//
|
2020-08-04 00:14:35 +08:00
|
|
|
#pragma once
|
|
|
|
#ifndef _LAYOUTHELPER_H_
|
2021-12-25 10:04:45 +08:00
|
|
|
# define _LAYOUTHELPER_H_
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-10-12 00:15:09 +08:00
|
|
|
# include "axmol.h"
|
2021-12-25 10:04:45 +08:00
|
|
|
# include "base/ccMacros.h"
|
2019-11-24 23:15:56 +08:00
|
|
|
|
|
|
|
// f(x) = s * a + x
|
2021-12-25 10:04:45 +08:00
|
|
|
# define adjust_coord(__sz__, __achor__, __coord__) ((__sz__) * (__achor__) + (__coord__))
|
2019-11-24 23:15:56 +08:00
|
|
|
|
|
|
|
// f(y) = y - s * a
|
2021-12-25 10:04:45 +08:00
|
|
|
# define adjust_coord_r(__sz__, __achor__, __coord__) ((__coord__) - (__sz__) * (__achor__))
|
2019-11-24 23:15:56 +08:00
|
|
|
|
|
|
|
// f(x) = S - (s - s * a + x)
|
2021-12-25 10:04:45 +08:00
|
|
|
# define adjust_coord_neg(__SZ__, __sz__, __achor__, __coord__) \
|
|
|
|
((__SZ__) - ((__sz__) - (__sz__) * (__achor__) + (__coord__)))
|
2019-11-24 23:15:56 +08:00
|
|
|
|
|
|
|
// f(y) = S - (s - s * a + y)
|
2021-12-25 10:04:45 +08:00
|
|
|
# define adjust_coord_neg_r adjust_coord_neg
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
# define center_coord(__SZ__, __sz__, __achor__) (((__SZ__) - (__sz__) + 2 * (__sz__) * (__achor__)) * 0.5f)
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
// inline Vec2 operator*(const Vec2& left, const ax::Vec2& right)
|
2021-10-23 23:27:14 +08:00
|
|
|
//{
|
2021-12-25 10:04:45 +08:00
|
|
|
// return Vec2(left.width * right.x, left.height * right.y);
|
|
|
|
// }
|
2021-10-23 23:27:14 +08:00
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
struct AX_DLL LayoutHelper
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
|
2021-10-23 23:27:14 +08:00
|
|
|
static Vec2 s_designSize;
|
2020-08-26 12:46:41 +08:00
|
|
|
static float s_adjustedScale;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// adatpe design size with fixed edge, normally, use this function for screen adatpe
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="designSize"></param>
|
2021-10-23 23:27:14 +08:00
|
|
|
static void setDesignSizeFixedEdge(const Vec2& designSize);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// adapte design size with no border
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="designSize"></param>
|
2021-10-23 23:27:14 +08:00
|
|
|
static void setDesignSizeNoBorder(const Vec2& designSize);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static ax::Vec2 getVisibleOrigin(void);
|
2021-10-23 23:27:14 +08:00
|
|
|
static Vec2 getVisibleSize(void);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// align type defination
|
2021-12-25 10:04:45 +08:00
|
|
|
enum AlignType
|
|
|
|
{
|
|
|
|
ALIGN_NONE = 1 >> 1,
|
2020-08-26 12:46:41 +08:00
|
|
|
ALIGN_XCENTER = 1,
|
|
|
|
ALIGN_YCENTER = 1 << 1,
|
2021-12-25 10:04:45 +08:00
|
|
|
ALIGN_LEFT = 1 << 2,
|
|
|
|
ALIGN_RIGHT = 1 << 3,
|
|
|
|
ALIGN_TOP = 1 << 4,
|
|
|
|
ALIGN_BOTTOM = 1 << 5,
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
ALIGN_CENTER = ALIGN_XCENTER | ALIGN_YCENTER,
|
2021-12-25 10:04:45 +08:00
|
|
|
ALIGN_CT = ALIGN_XCENTER | ALIGN_TOP, // center top
|
|
|
|
ALIGN_CB = ALIGN_XCENTER | ALIGN_BOTTOM, // center bottom
|
2020-08-26 12:46:41 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ALIGN_LC = ALIGN_LEFT | ALIGN_YCENTER, // left center
|
|
|
|
ALIGN_LT = ALIGN_LEFT | ALIGN_TOP, // left top
|
|
|
|
ALIGN_LB = ALIGN_LEFT | ALIGN_BOTTOM, // left bottom
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
ALIGN_RC = ALIGN_RIGHT | ALIGN_YCENTER, // right center
|
|
|
|
ALIGN_RT = ALIGN_RIGHT | ALIGN_TOP, // right top
|
|
|
|
ALIGN_RB = ALIGN_RIGHT | ALIGN_BOTTOM, // right bottom
|
2019-11-24 23:15:56 +08:00
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
# define isIgnoreX(align) (align != ALIGN_LEFT) && (align != ALIGN_RIGHT)
|
|
|
|
# define isIgnoreY(align) (align != ALIGN_TOP) && (align != ALIGN_BOTTOM)
|
|
|
|
# define isIgnoreXY(align) (align == ALIGN_CENTER)
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static ax::Vec2 getScale2D(ax::Node* pNode)
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
2022-08-08 18:02:17 +08:00
|
|
|
return ax::Vec2(pNode->getScaleX(), pNode->getScaleY());
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static float getNodeLeftX(ax::Node* pNode)
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
return pNode->getPositionX() - pNode->getAnchorPoint().x * pNode->getContentSize().width * pNode->getScaleX();
|
|
|
|
}
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static float getNodeRightX(ax::Node* pNode)
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
|
|
|
return pNode->getPositionX() +
|
|
|
|
(1 - pNode->getAnchorPoint().x) * pNode->getContentSize().width * pNode->getScaleX();
|
2020-08-26 12:46:41 +08:00
|
|
|
}
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static float getNodeTopY(ax::Node* pNode)
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
|
|
|
return pNode->getPositionY() +
|
|
|
|
(1 - pNode->getAnchorPoint().y) * pNode->getContentSize().height * pNode->getScaleY();
|
2020-08-26 12:46:41 +08:00
|
|
|
}
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static float getNodeBottomY(ax::Node* pNode)
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
return pNode->getPositionY() + pNode->getAnchorPoint().y * pNode->getContentSize().height * pNode->getScaleY();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* @brief: nodes_layout set node position
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
** @brief: setNodePosition with achor point modified
|
|
|
|
** @params
|
|
|
|
** pNode: the node to be set
|
|
|
|
** align: align type, see enum AlighType
|
|
|
|
** x: specify coord x.so
|
|
|
|
** y: specify coord y.
|
|
|
|
*/
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodePosition(ax::Node* pNode, const int align, float x, float y)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
|
|
|
const AlignType alignType = (const AlignType)align;
|
2021-12-25 10:04:45 +08:00
|
|
|
if (alignType == ALIGN_NONE)
|
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
pNode->setPosition(x, y);
|
|
|
|
return;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
if (alignType & ALIGN_XCENTER)
|
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
centerNodeX(pNode);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
if (alignType & ALIGN_YCENTER)
|
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
centerNodeY(pNode);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
if (alignType & ALIGN_LEFT)
|
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
setNodeLeft(pNode, x);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
if (alignType & ALIGN_RIGHT)
|
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
setNodeRight(pNode, x);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
if (alignType & ALIGN_TOP)
|
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
setNodeTop(pNode, y);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
if (alignType & ALIGN_BOTTOM)
|
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
setNodeBottom(pNode, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** @brief: setNodePosition with achor point modified
|
|
|
|
** @params
|
|
|
|
** pNode: the node to be set
|
|
|
|
** achorPoint: specify new achor point for the node
|
|
|
|
** align: align type, see enum AlighType
|
|
|
|
** x: specify coord x.
|
|
|
|
** y: specify coord y.
|
|
|
|
**
|
|
|
|
*/
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodePosition(ax::Node* pNode,
|
|
|
|
const ax::Point& anchorPoint,
|
2021-12-25 10:04:45 +08:00
|
|
|
const int align,
|
|
|
|
float x,
|
|
|
|
float y)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
|
|
|
pNode->setAnchorPoint(anchorPoint);
|
|
|
|
setNodePosition(pNode, align, x, y);
|
|
|
|
}
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodePosition(ax::Node* pNode, const int align, float value = 0.0f)
|
2021-12-25 10:04:45 +08:00
|
|
|
{ // ignore x or y
|
2020-08-26 12:46:41 +08:00
|
|
|
setNodePosition(pNode, align, value, value);
|
|
|
|
}
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodePosition(ax::Node* pNode,
|
|
|
|
const ax::Point& anchorPoint,
|
2021-12-25 10:04:45 +08:00
|
|
|
const int align,
|
|
|
|
float value = 0.0f)
|
|
|
|
{ // ignore x or y
|
2020-08-26 12:46:41 +08:00
|
|
|
setNodePosition(pNode, anchorPoint, align, value, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// @version 1
|
2022-08-08 18:02:17 +08:00
|
|
|
static void centerNodeX(ax::Node* pNode)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* pNodeParent = pNode->getParent();
|
2020-08-26 12:46:41 +08:00
|
|
|
if (pNodeParent)
|
|
|
|
{
|
|
|
|
centerNodeX(pNode, pNodeParent->getContentSize());
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void centerNodeY(ax::Node* pNode)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* pNodeParent = pNode->getParent();
|
2020-08-26 12:46:41 +08:00
|
|
|
if ((pNodeParent))
|
|
|
|
{
|
|
|
|
centerNodeY(pNode, pNodeParent->getContentSize());
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void centerNode(ax::Node* pNode)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* pNodeParent = pNode->getParent();
|
2020-08-26 12:46:41 +08:00
|
|
|
if ((pNodeParent))
|
|
|
|
{
|
|
|
|
centerNode(pNode, pNodeParent->getContentSize());
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// @version 2
|
2022-08-08 18:02:17 +08:00
|
|
|
static void centerNodeX(ax::Node* pNode, const Vec2& parentSize)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(pNode);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Vec2 size = pNode->getContentSize() * getScale2D(pNode);
|
2020-08-26 12:46:41 +08:00
|
|
|
float achorX = 0.0f;
|
|
|
|
if (!pNode->isIgnoreAnchorPointForPosition())
|
|
|
|
{
|
|
|
|
achorX = pNode->getAnchorPoint().x;
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
pNode->setPositionX(center_coord(parentSize.width, size.width, achorX) /*parentSize.width * 0.5f*/);
|
2020-08-26 12:46:41 +08:00
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void centerNodeY(ax::Node* pNode, const Vec2& parentSize)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(pNode);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Vec2 size = pNode->getContentSize() * getScale2D(pNode);
|
2020-08-26 12:46:41 +08:00
|
|
|
float achorY = 0.0f;
|
|
|
|
if (!pNode->isIgnoreAnchorPointForPosition())
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
achorY = pNode->getAnchorPoint().y;
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
pNode->setPositionY(center_coord(parentSize.height, size.height, achorY));
|
|
|
|
}
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void centerNode(ax::Node* pNode, const Vec2& parentSize)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(pNode);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Vec2 size = pNode->getContentSize() * getScale2D(pNode);
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Point achor = ax::Vec2::ZERO;
|
2020-08-26 12:46:41 +08:00
|
|
|
if (!pNode->isIgnoreAnchorPointForPosition())
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
achor = pNode->getAnchorPoint();
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2022-08-08 18:02:17 +08:00
|
|
|
pNode->setPosition(ax::Vec2(center_coord(parentSize.width, size.width, achor.x),
|
2021-12-25 10:04:45 +08:00
|
|
|
center_coord(parentSize.height, size.height, achor.y)));
|
2020-08-26 12:46:41 +08:00
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2020-08-26 12:46:41 +08:00
|
|
|
// @version 1
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeLeft(ax::Node* pNode, float left, float anchor = 0.0f)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* pNodeParent = pNode->getParent();
|
2020-08-26 12:46:41 +08:00
|
|
|
if ((pNodeParent))
|
|
|
|
{
|
|
|
|
setNodeLeft(pNode, pNodeParent->getContentSize(), left, anchor);
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static float getNodeLeft(ax::Node* pNode, float anchor = 0.0f)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* pNodeParent = pNode->getParent();
|
2020-08-26 12:46:41 +08:00
|
|
|
if ((pNodeParent))
|
|
|
|
{
|
|
|
|
return getNodeLeft(pNode, pNodeParent->getContentSize(), anchor);
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
return 0.0f;
|
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeTop(ax::Node* pNode, float top, float anchor = 0.0f)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* pNodeParent = pNode->getParent();
|
2020-08-26 12:46:41 +08:00
|
|
|
if ((pNodeParent))
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
setNodeTop(pNode, pNodeParent->getContentSize(), top, anchor);
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static float getNodeTop(ax::Node* pNode, float anchor = 0.0f)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* pNodeParent = pNode->getParent();
|
2020-08-26 12:46:41 +08:00
|
|
|
if ((pNodeParent))
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
return getNodeTop(pNode, pNodeParent->getContentSize(), anchor);
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
return 0.0f;
|
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeRight(ax::Node* pNode, float right)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* pNodeParent = pNode->getParent();
|
2020-08-26 12:46:41 +08:00
|
|
|
if ((pNodeParent))
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
setNodeRight(pNode, pNodeParent->getContentSize(), right);
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
}
|
2022-08-08 18:02:17 +08:00
|
|
|
static float getNodeRight(ax::Node* pNode, float anchor = 0.0f)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* pNodeParent = pNode->getParent();
|
2020-08-26 12:46:41 +08:00
|
|
|
if ((pNodeParent))
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
return getNodeRight(pNode, pNodeParent->getContentSize(), anchor);
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
return 0.0f;
|
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeBottom(ax::Node* pNode, float bottom, float anchor = .0f)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* pNodeParent = pNode->getParent();
|
2020-08-26 12:46:41 +08:00
|
|
|
if ((pNodeParent))
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
setNodeBottom(pNode, pNodeParent->getContentSize(), bottom, anchor);
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static float getNodeBottom(ax::Node* pNode, float anchor = 0.0f)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* pNodeParent = pNode->getParent();
|
2020-08-26 12:46:41 +08:00
|
|
|
if ((pNodeParent))
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
return getNodeBottom(pNode, pNodeParent->getContentSize(), anchor);
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
return 0.0f;
|
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeLB(ax::Node* pNode, const ax::Point& p)
|
2021-12-25 10:04:45 +08:00
|
|
|
{ // left bottom
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* pNodeParent = pNode->getParent();
|
2020-08-26 12:46:41 +08:00
|
|
|
if ((pNodeParent))
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
setNodeLB(pNode, pNodeParent->getContentSize(), p);
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeRB(ax::Node* pNode, const ax::Point& p)
|
2021-12-25 10:04:45 +08:00
|
|
|
{ // right bottom
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* pNodeParent = pNode->getParent();
|
2020-08-26 12:46:41 +08:00
|
|
|
if ((pNodeParent))
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
setNodeRB(pNode, pNodeParent->getContentSize(), p);
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeLT(ax::Node* pNode, const ax::Point& p)
|
2021-12-25 10:04:45 +08:00
|
|
|
{ // left top
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* pNodeParent = pNode->getParent();
|
2020-08-26 12:46:41 +08:00
|
|
|
if ((pNodeParent))
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
setNodeLT(pNode, pNodeParent->getContentSize(), p);
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeRT(ax::Node* pNode, const ax::Point& p)
|
2021-12-25 10:04:45 +08:00
|
|
|
{ // right top
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* pNodeParent = pNode->getParent();
|
2020-08-26 12:46:41 +08:00
|
|
|
if ((pNodeParent))
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
setNodeRT(pNode, pNodeParent->getContentSize(), p);
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// @version 2 used as internal interfaces
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeLeft(ax::Node* pNode, const Vec2& parentSize, float left, float anchor = 0.0f)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(pNode);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Vec2 size = pNode->getContentSize() * getScale2D(pNode);
|
2020-08-26 12:46:41 +08:00
|
|
|
float achorX = 0.0f;
|
|
|
|
if (!pNode->isIgnoreAnchorPointForPosition())
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
achorX = pNode->getAnchorPoint().x;
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
pNode->setPositionX(adjust_coord(size.width, achorX, left) - size.width * anchor);
|
|
|
|
}
|
2022-08-08 18:02:17 +08:00
|
|
|
static float getNodeLeft(ax::Node* pNode, const Vec2& parentSize, float anchor = 0.0f)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(pNode);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Vec2 size = pNode->getContentSize() * getScale2D(pNode);
|
2020-08-26 12:46:41 +08:00
|
|
|
float achorX = 0.0f;
|
|
|
|
if (!pNode->isIgnoreAnchorPointForPosition())
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
achorX = pNode->getAnchorPoint().x;
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
return adjust_coord_r(size.width, achorX, pNode->getPositionX()) + anchor * size.width;
|
|
|
|
}
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeTop(ax::Node* pNode, const Vec2& parentSize, float top, float anchor = 0.0f)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(pNode);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Vec2 size = pNode->getContentSize() * getScale2D(pNode);
|
2020-08-26 12:46:41 +08:00
|
|
|
float achorY = 0.0f;
|
|
|
|
if (!pNode->isIgnoreAnchorPointForPosition())
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
achorY = pNode->getAnchorPoint().y;
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
pNode->setPositionY(adjust_coord_neg(parentSize.height, size.height, achorY, top) - size.height * anchor);
|
|
|
|
}
|
2022-08-08 18:02:17 +08:00
|
|
|
static float getNodeTop(ax::Node* pNode, const Vec2& parentSize, float anchor = 0.0f)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(pNode);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Vec2 size = pNode->getContentSize() * getScale2D(pNode);
|
2020-08-26 12:46:41 +08:00
|
|
|
float achorY = 0.0f;
|
|
|
|
if (!pNode->isIgnoreAnchorPointForPosition())
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
achorY = pNode->getAnchorPoint().y;
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
return adjust_coord_neg_r(parentSize.height, size.height, achorY, pNode->getPositionY()) + size.height * anchor;
|
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeRight(ax::Node* pNode, const Vec2& parentSize, float right)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(pNode);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Vec2 size = pNode->getContentSize() * getScale2D(pNode);
|
2020-08-26 12:46:41 +08:00
|
|
|
float achorX = 0.0f;
|
|
|
|
if (!pNode->isIgnoreAnchorPointForPosition())
|
|
|
|
{
|
|
|
|
achorX = pNode->getAnchorPoint().x;
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
pNode->setPositionX(adjust_coord_neg(parentSize.width, size.width, achorX, right));
|
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static float getNodeRight(ax::Node* pNode, const Vec2& parentSize, float anchor = 0.0f)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(pNode);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Vec2 size = pNode->getContentSize() * getScale2D(pNode);
|
2020-08-26 12:46:41 +08:00
|
|
|
float achorX = 0.0f;
|
|
|
|
if (!pNode->isIgnoreAnchorPointForPosition())
|
|
|
|
{
|
|
|
|
achorX = pNode->getAnchorPoint().x;
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
return adjust_coord_neg_r(parentSize.width, size.width, achorX, pNode->getPositionX()) + anchor * size.width;
|
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeBottom(ax::Node* pNode, const Vec2& parentSize, float bottom, float anchor = 0.0f)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(pNode);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Vec2 size = pNode->getContentSize() * getScale2D(pNode);
|
2020-08-26 12:46:41 +08:00
|
|
|
float achorY = 0.0f;
|
|
|
|
if (!pNode->isIgnoreAnchorPointForPosition())
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
achorY = pNode->getAnchorPoint().y;
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
pNode->setPositionY(adjust_coord(size.height, achorY, bottom) - anchor * size.height);
|
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static float getNodeBottom(ax::Node* pNode, const Vec2& parentSize, float anchor = 0.f)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(pNode);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Vec2 size = pNode->getContentSize() * getScale2D(pNode);
|
2020-08-26 12:46:41 +08:00
|
|
|
float achorY = 0.0f;
|
|
|
|
if (!pNode->isIgnoreAnchorPointForPosition())
|
2019-11-24 23:15:56 +08:00
|
|
|
{
|
2020-08-26 12:46:41 +08:00
|
|
|
achorY = pNode->getAnchorPoint().y;
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
return adjust_coord_r(size.height, achorY, pNode->getPositionY()) + size.height * anchor;
|
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeLB(ax::Node* pNode, const Vec2& parentSize, const ax::Point& p)
|
2021-12-25 10:04:45 +08:00
|
|
|
{ // left bottom
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(pNode);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Vec2 size = pNode->getContentSize() * getScale2D(pNode);
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Point achorPoint = ax::Vec2::ZERO;
|
2020-08-26 12:46:41 +08:00
|
|
|
if (!pNode->isIgnoreAnchorPointForPosition())
|
|
|
|
{
|
|
|
|
achorPoint = pNode->getAnchorPoint();
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
pNode->setPosition(
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Vec2(adjust_coord(size.width, achorPoint.x, p.x), adjust_coord(size.height, achorPoint.y, p.y)));
|
2020-08-26 12:46:41 +08:00
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeRB(ax::Node* pNode, const Vec2& parentSize, const ax::Point& p)
|
2021-12-25 10:04:45 +08:00
|
|
|
{ // right bottom
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(pNode);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Vec2 size = pNode->getContentSize() * getScale2D(pNode);
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Point achorPoint = ax::Vec2::ZERO;
|
2020-08-26 12:46:41 +08:00
|
|
|
if (!pNode->isIgnoreAnchorPointForPosition())
|
|
|
|
{
|
|
|
|
achorPoint = pNode->getAnchorPoint();
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2022-08-08 18:02:17 +08:00
|
|
|
pNode->setPosition(ax::Vec2(adjust_coord_neg(parentSize.width, size.width, achorPoint.x, p.x),
|
2021-12-25 10:04:45 +08:00
|
|
|
adjust_coord(size.height, achorPoint.y, p.y)));
|
2020-08-26 12:46:41 +08:00
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeLT(ax::Node* pNode, const Vec2& parentSize, const ax::Point& p)
|
2021-12-25 10:04:45 +08:00
|
|
|
{ // left top
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(pNode);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Vec2 size = pNode->getContentSize() * getScale2D(pNode);
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Point achorPoint = ax::Vec2::ZERO;
|
2020-08-26 12:46:41 +08:00
|
|
|
if (!pNode->isIgnoreAnchorPointForPosition())
|
|
|
|
{
|
|
|
|
achorPoint = pNode->getAnchorPoint();
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2022-08-08 18:02:17 +08:00
|
|
|
pNode->setPosition(ax::Vec2(adjust_coord(size.width, achorPoint.x, p.x),
|
2021-12-25 10:04:45 +08:00
|
|
|
adjust_coord_neg(parentSize.height, size.height, achorPoint.y, p.y)));
|
2020-08-26 12:46:41 +08:00
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeRT(ax::Node* pNode, const Vec2& parentSize, const ax::Point& p)
|
2021-12-25 10:04:45 +08:00
|
|
|
{ // right top
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(pNode);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Vec2 size = pNode->getContentSize() * getScale2D(pNode);
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Point achorPoint = ax::Vec2::ZERO;
|
2020-08-26 12:46:41 +08:00
|
|
|
if (!pNode->isIgnoreAnchorPointForPosition())
|
|
|
|
{
|
|
|
|
achorPoint = pNode->getAnchorPoint();
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2022-08-08 18:02:17 +08:00
|
|
|
pNode->setPosition(ax::Vec2(adjust_coord_neg(parentSize.width, size.width, achorPoint.x, p.x),
|
2021-12-25 10:04:45 +08:00
|
|
|
adjust_coord_neg(parentSize.height, size.height, achorPoint.y, p.y)));
|
2020-08-26 12:46:41 +08:00
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2020-08-26 12:46:41 +08:00
|
|
|
/* set node position as normalized: @version 1 */
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeNormalizedPositionX(ax::Node* pNode, float ratio)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* pNodeParent = pNode->getParent();
|
2020-08-26 12:46:41 +08:00
|
|
|
if ((pNodeParent))
|
|
|
|
{
|
|
|
|
setNodeNormalizedPositionX(pNode, pNodeParent->getContentSize(), ratio);
|
|
|
|
}
|
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeNormalizedPositionY(ax::Node* pNode, float ratio)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* pNodeParent = pNode->getParent();
|
2020-08-26 12:46:41 +08:00
|
|
|
if ((pNodeParent))
|
|
|
|
{
|
|
|
|
setNodeNormalizedPositionY(pNode, pNodeParent->getContentSize(), ratio);
|
|
|
|
}
|
|
|
|
}
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeNormalizedPosition(ax::Node* pNode, const ax::Point& ratio)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* pNodeParent = pNode->getParent();
|
2020-08-26 12:46:41 +08:00
|
|
|
if ((pNodeParent))
|
|
|
|
{
|
|
|
|
setNodeNormalizedPosition(pNode, pNodeParent->getContentSize(), ratio);
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2020-08-26 12:46:41 +08:00
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2020-08-26 12:46:41 +08:00
|
|
|
/* set node position as normalized: @version 2 */
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeNormalizedPositionX(ax::Node* pNode, const Vec2& parentSize, float ratio)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(pNode);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2020-08-26 12:46:41 +08:00
|
|
|
pNode->setPositionX(parentSize.width * ratio);
|
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeNormalizedPositionY(ax::Node* pNode, const Vec2& parentSize, float ratio)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(pNode);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2020-08-26 12:46:41 +08:00
|
|
|
pNode->setPositionY(parentSize.height * ratio);
|
|
|
|
}
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeNormalizedPosition(ax::Node* pNode, const Vec2& parentSize, const ax::Point& ratio)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_ASSERT(pNode);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
pNode->setPosition(ax::Point(parentSize.width * ratio.x, parentSize.height * ratio.y));
|
2020-08-26 12:46:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Get node group size
|
2022-08-08 18:02:17 +08:00
|
|
|
static Vec2 getNodeGroupSize(const std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static Vec2 getNodeGroupScaledSize(const std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// Set nodes group size
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeGroupSize(const std::vector<ax::Node*>& nodes, const Vec2& newSize);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// Get Node group left
|
2022-08-08 18:02:17 +08:00
|
|
|
static float getNodeGroupLeft(const std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// Get node group top
|
2022-08-08 18:02:17 +08:00
|
|
|
static float getNodeGroupTop(const std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// Get node group right
|
2022-08-08 18:02:17 +08:00
|
|
|
static float getNodeGroupRight(const std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// Get node group bottom
|
2022-08-08 18:02:17 +08:00
|
|
|
static float getNodeGroupBottom(const std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
** setNodeGroupLeft
|
|
|
|
**
|
|
|
|
*/
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeGroupLeft(const std::vector<ax::Node*>& nodes, float left);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
** setNodeGroupLeft
|
|
|
|
**
|
|
|
|
*/
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeGroupTop(const std::vector<ax::Node*>& nodes, float top);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeGroupLT(const std::vector<ax::Node*>& nodes, const ax::Vec2& p);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
** setNodeGroupRight
|
|
|
|
**
|
|
|
|
*/
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeGroupRight(const std::vector<ax::Node*>& nodes, float right);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
** setNodeGroupRight
|
|
|
|
**
|
|
|
|
*/
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeGroupBottom(const std::vector<ax::Node*>& nodes, float bottom);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
//// move node group, use UI direction
|
2022-08-08 18:02:17 +08:00
|
|
|
static void moveNodeGroupHorizontally(const std::vector<ax::Node*>& nodes, float delta);
|
|
|
|
static void moveNodeGroupVertically(const std::vector<ax::Node*>& nodes, float delta);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/* @brief: group layout and alignment
|
|
|
|
** @remark:
|
|
|
|
*/
|
|
|
|
/// <summary>
|
|
|
|
/// Center horiz to parent
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void centerHorizontally(const std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Center vertical to parent
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void centerVertically(const std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Center to parent
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void centerToParent(const std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Align lefts
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void alignLefts(const std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Align rights
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void alignRights(const std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Align tops
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void alignTops(const std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Align bottoms
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void alignBottoms(const std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Align horiz
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void alignHorizontals(const std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Align vertical
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void alignVerticals(const std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Align centers
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void alignCenters(const std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Make same width
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void makeSameWidth(const std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Make same height
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void makeSameHeight(const std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Make same size
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void makeSameSize(const std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Make horiz spacing equal
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void makeHorizontalSpacingEqual(std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Make vertical spacing equal
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void makeVerticalSpacingEqual(std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Increease horiz spacing
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void increaseHorizontalSpacing(std::vector<ax::Node*>& nodes, float theSpacing);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Increase vertical spacing
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void increaseVerticalSpacing(std::vector<ax::Node*>& nodes, float theSpacing);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Decrease horiz spacing
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void decreaseHorizontalSpacing(std::vector<ax::Node*>& nodes, float theSpacing);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Decrease vertical spacing
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void decreaseVerticalSpacing(std::vector<ax::Node*>& nodes, float theSpacing);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Remove horiz spacing
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void removeHorizontalSpacing(const std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Remove Vertical spacing
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void removeVerticalSpacing(const std::vector<ax::Node*>& nodes);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// maybe for internal use
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void makeHorizontalSpacingEqual(const std::vector<ax::Node*>& nodes, float theSpacing);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// maybe for internal use
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="nodes"></param>
|
2022-08-08 18:02:17 +08:00
|
|
|
static void makeVerticalSpacingEqual(const std::vector<ax::Node*>& nodes, float theSpacing);
|
2020-08-26 12:46:41 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// CLASS VisibleRect
|
|
|
|
/// </summary>
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_DLL VisibleRect
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
static void refresh(void);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static ax::Rect getScreenVisibleRect();
|
2021-10-23 23:27:14 +08:00
|
|
|
static Vec2 size();
|
2022-08-08 18:02:17 +08:00
|
|
|
static ax::Point left();
|
|
|
|
static ax::Point right();
|
|
|
|
static ax::Point top();
|
|
|
|
static ax::Point bottom();
|
|
|
|
static ax::Point center();
|
|
|
|
static ax::Point leftTop();
|
|
|
|
static ax::Point rightTop();
|
|
|
|
static ax::Point leftBottom();
|
|
|
|
static ax::Point rightBottom();
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
// ------- The APIs for set layout node in visible screen rect ------
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodePosition(ax::Node* pNode, const ax::Point& p)
|
2020-08-26 12:46:41 +08:00
|
|
|
{
|
2022-08-08 18:02:17 +08:00
|
|
|
setNodeNormalizedPosition(pNode, ax::Vec2(p.x / s_designSize.width * s_adjustedScale,
|
2021-12-25 10:04:45 +08:00
|
|
|
p.y / s_designSize.height * s_adjustedScale));
|
2019-11-24 23:15:56 +08:00
|
|
|
}
|
2022-08-08 18:02:17 +08:00
|
|
|
static void centerNode(ax::Node* pNode) { setNodeNormalizedPosition(pNode, ax::Vec2(.5f, .5f)); }
|
|
|
|
static void centerNodeX(ax::Node* pNode) { setNodeNormalizedPositionX(pNode, .5f); }
|
|
|
|
static void centerNodeY(ax::Node* pNode) { setNodeNormalizedPositionY(pNode, .5f); }
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeLeft(ax::Node* pNode, float left);
|
|
|
|
static void setNodeTop(ax::Node* pNode, float top);
|
|
|
|
static void setNodeRight(ax::Node* pNode, float right);
|
|
|
|
static void setNodeBottom(ax::Node* pNode, float bottom);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static float getNodeLeft(ax::Node* pNode);
|
|
|
|
static float getNodeTop(ax::Node* pNode);
|
|
|
|
static float getNodeRight(ax::Node* pNode);
|
|
|
|
static float getNodeBottom(ax::Node* pNode);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeLT(ax::Node* pNode, const ax::Point& p);
|
|
|
|
static void setNodeRT(ax::Node* pNode, const ax::Point& p);
|
|
|
|
static void setNodeLB(ax::Node* pNode, const ax::Point& p);
|
|
|
|
static void setNodeRB(ax::Node* pNode, const ax::Point& p);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2020-08-26 12:46:41 +08:00
|
|
|
/// ratio position
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeNormalizedLT(ax::Node* pNode, const ax::Point& ratio);
|
|
|
|
static void setNodeNormalizedRT(ax::Node* pNode, const ax::Point& ratio);
|
|
|
|
static void setNodeNormalizedLB(ax::Node* pNode, const ax::Point& ratio);
|
|
|
|
static void setNodeNormalizedRB(ax::Node* pNode, const ax::Point& ratio);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeNormalizedTop(ax::Node* pNode, const float ratioTop);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeNormalizedPositionX(ax::Node* pNode, float ratio);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static void setNodeNormalizedPositionY(ax::Node* pNode, float ratio);
|
|
|
|
static void setNodeNormalizedPosition(ax::Node* pNode, const ax::Point& ratio);
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2020-08-26 12:46:41 +08:00
|
|
|
private:
|
|
|
|
static void lazyInit();
|
2022-08-08 18:02:17 +08:00
|
|
|
static ax::Rect s_ScreenVisibleRect;
|
2020-08-26 12:46:41 +08:00
|
|
|
};
|
|
|
|
};
|
2019-11-24 23:15:56 +08:00
|
|
|
|
|
|
|
#endif
|