Node has a default shape now.
This commit is contained in:
parent
b583ad562f
commit
cddfd5b5cd
|
|
@ -45,6 +45,11 @@ void e2d::ShapeManager::__addShape(Shape * pShape)
|
|||
{
|
||||
if (pShape)
|
||||
{
|
||||
if (pShape->m_pParentNode)
|
||||
{
|
||||
WARN_IF(true, "ShapeManager::__addShape Failed! The shape is already added.");
|
||||
return;
|
||||
}
|
||||
pShape->retain();
|
||||
s_vShapes.push_back(pShape);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
// 默认中心点位置
|
||||
static float s_fDefaultPiovtX = 0;
|
||||
static float s_fDefaultPiovtY = 0;
|
||||
static bool s_fDefaultShapeEnabled = true;
|
||||
|
||||
e2d::Node::Node()
|
||||
: m_nOrder(0)
|
||||
|
|
@ -36,6 +37,11 @@ e2d::Node::Node()
|
|||
, m_bTransformNeeded(false)
|
||||
, m_bAutoUpdate(true)
|
||||
{
|
||||
if (s_fDefaultShapeEnabled)
|
||||
{
|
||||
auto rect = new Rect(this);
|
||||
this->setShape(rect);
|
||||
}
|
||||
}
|
||||
|
||||
e2d::Node::~Node()
|
||||
|
|
@ -825,27 +831,24 @@ std::vector<e2d::Action*> e2d::Node::getActions(const String & strActionName)
|
|||
return std::move(actions);
|
||||
}
|
||||
|
||||
bool e2d::Node::isPointIn(Point point)
|
||||
bool e2d::Node::isPointIn(Point point) const
|
||||
{
|
||||
if (m_bTransformNeeded)
|
||||
{
|
||||
_updateTransform(this);
|
||||
}
|
||||
// 为节点创建一个形状
|
||||
ID2D1RectangleGeometry * rect;
|
||||
Renderer::getID2D1Factory()->CreateRectangleGeometry(
|
||||
D2D1::RectF(0, 0, m_fWidth * m_fScaleX, m_fHeight * m_fScaleY),
|
||||
D2D1::RectF(0, 0, m_fWidth, m_fHeight),
|
||||
&rect
|
||||
);
|
||||
// 判断点是否在形状内
|
||||
BOOL ret;
|
||||
BOOL ret = 0;
|
||||
rect->FillContainsPoint(
|
||||
D2D1::Point2F(
|
||||
static_cast<float>(point.x),
|
||||
static_cast<float>(point.y)),
|
||||
&m_MatriFinal,
|
||||
m_MatriFinal,
|
||||
&ret
|
||||
);
|
||||
|
||||
if (ret)
|
||||
{
|
||||
return true;
|
||||
|
|
@ -868,7 +871,7 @@ bool e2d::Node::isIntersectWith(Node * pNode) const
|
|||
|
||||
// 根据自身大小位置创建矩形
|
||||
Renderer::getID2D1Factory()->CreateRectangleGeometry(
|
||||
D2D1::RectF(0, 0, m_fWidth * m_fScaleX, m_fHeight * m_fScaleY),
|
||||
D2D1::RectF(0, 0, m_fWidth, m_fHeight),
|
||||
&pRect1
|
||||
);
|
||||
// 根据二维矩阵进行转换
|
||||
|
|
@ -879,7 +882,7 @@ bool e2d::Node::isIntersectWith(Node * pNode) const
|
|||
);
|
||||
// 根据相比较节点的大小位置创建矩形
|
||||
Renderer::getID2D1Factory()->CreateRectangleGeometry(
|
||||
D2D1::RectF(0, 0, pNode->m_fWidth * pNode->m_fScaleX, pNode->m_fHeight * pNode->m_fScaleY),
|
||||
D2D1::RectF(0, 0, pNode->m_fWidth, pNode->m_fHeight),
|
||||
&pRect2
|
||||
);
|
||||
// 获取相交状态
|
||||
|
|
@ -903,6 +906,11 @@ void e2d::Node::setDefaultPiovt(double defaultPiovtX, double defaultPiovtY)
|
|||
s_fDefaultPiovtY = min(max(static_cast<float>(defaultPiovtY), 0), 1);
|
||||
}
|
||||
|
||||
void e2d::Node::setDefaultShapeEnable(bool bEnable)
|
||||
{
|
||||
s_fDefaultShapeEnabled = bEnable;
|
||||
}
|
||||
|
||||
void e2d::Node::resumeAllActions()
|
||||
{
|
||||
ActionManager::resumeAllActionsBindedWith(this);
|
||||
|
|
|
|||
|
|
@ -45,6 +45,21 @@ void e2d::Circle::_setCircle(Point center, double radius)
|
|||
);
|
||||
}
|
||||
|
||||
void e2d::Circle::_resize()
|
||||
{
|
||||
if (m_pParentNode && m_bEnable)
|
||||
{
|
||||
double minSide = min(m_pParentNode->getRealWidth(), m_pParentNode->getRealHeight());
|
||||
this->_setCircle(
|
||||
Point(
|
||||
m_pParentNode->getRealWidth() / 2,
|
||||
m_pParentNode->getRealHeight() / 2
|
||||
),
|
||||
minSide / 2
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ID2D1EllipseGeometry * e2d::Circle::_getD2dGeometry() const
|
||||
{
|
||||
return m_pD2dCircle;
|
||||
|
|
|
|||
|
|
@ -45,6 +45,21 @@ void e2d::Ellipse::_setEllipse(Point center, double radiusX, double radiusY)
|
|||
);
|
||||
}
|
||||
|
||||
void e2d::Ellipse::_resize()
|
||||
{
|
||||
if (m_pParentNode && m_bEnable)
|
||||
{
|
||||
this->_setEllipse(
|
||||
Point(
|
||||
m_pParentNode->getWidth() / 2,
|
||||
m_pParentNode->getHeight() / 2
|
||||
),
|
||||
m_pParentNode->getWidth() / 2,
|
||||
m_pParentNode->getHeight() / 2
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ID2D1EllipseGeometry * e2d::Ellipse::_getD2dGeometry() const
|
||||
{
|
||||
return m_pD2dEllipse;
|
||||
|
|
|
|||
|
|
@ -42,6 +42,19 @@ void e2d::Rect::_setRect(double left, double top, double right, double bottom)
|
|||
);
|
||||
}
|
||||
|
||||
void e2d::Rect::_resize()
|
||||
{
|
||||
if (m_pParentNode && m_bEnable)
|
||||
{
|
||||
this->_setRect(
|
||||
0,
|
||||
0,
|
||||
m_pParentNode->getRealWidth(),
|
||||
m_pParentNode->getRealHeight()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ID2D1RectangleGeometry * e2d::Rect::_getD2dGeometry() const
|
||||
{
|
||||
return m_pD2dRectangle;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ e2d::Shape::Shape()
|
|||
, m_pParentNode(nullptr)
|
||||
, m_pTransformedShape(nullptr)
|
||||
, m_bEnable(true)
|
||||
, m_bAutoResize(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -64,6 +65,11 @@ void e2d::Shape::setOpacity(double opacity)
|
|||
m_fOpacity = min(max(static_cast<float>(opacity), 0), 1);
|
||||
}
|
||||
|
||||
void e2d::Shape::setAutoResize(bool bEnable)
|
||||
{
|
||||
m_bAutoResize = bEnable;
|
||||
}
|
||||
|
||||
void e2d::Shape::_render()
|
||||
{
|
||||
if (m_pTransformedShape && m_bEnable)
|
||||
|
|
@ -105,6 +111,11 @@ void e2d::Shape::_transform()
|
|||
{
|
||||
if (m_pParentNode && m_bEnable)
|
||||
{
|
||||
if (m_bAutoResize)
|
||||
{
|
||||
this->_resize();
|
||||
}
|
||||
|
||||
// ÊÍ·ÅÔÐÎ×´
|
||||
SafeReleaseInterface(&m_pTransformedShape);
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public:
|
|||
// 判断点是否在节点内
|
||||
virtual bool isPointIn(
|
||||
Point point
|
||||
);
|
||||
) const;
|
||||
|
||||
// 判断两节点是否相交
|
||||
virtual bool isIntersectWith(
|
||||
|
|
@ -368,6 +368,11 @@ public:
|
|||
double defaultPiovtY
|
||||
);
|
||||
|
||||
// 设置节点是否包含默认形状(默认打开)
|
||||
static void setDefaultShapeEnable(
|
||||
bool bEnable
|
||||
);
|
||||
|
||||
protected:
|
||||
// 更新节点
|
||||
void _update();
|
||||
|
|
|
|||
|
|
@ -64,10 +64,18 @@ public:
|
|||
double opacity
|
||||
);
|
||||
|
||||
// 设置大小跟随
|
||||
void setAutoResize(
|
||||
bool bEnable
|
||||
);
|
||||
|
||||
protected:
|
||||
// ת»»ÐÎ×´
|
||||
virtual void _transform();
|
||||
|
||||
// 重设大小
|
||||
virtual void _resize() = 0;
|
||||
|
||||
// äÖȾÐÎ×´
|
||||
virtual void _render();
|
||||
|
||||
|
|
@ -77,6 +85,7 @@ protected:
|
|||
protected:
|
||||
bool m_bEnable;
|
||||
bool m_bIsVisiable;
|
||||
bool m_bAutoResize;
|
||||
UINT32 m_nCategoryBitmask;
|
||||
UINT32 m_nCollisionBitmask;
|
||||
UINT32 m_nColor;
|
||||
|
|
@ -116,6 +125,9 @@ protected:
|
|||
double bottom
|
||||
);
|
||||
|
||||
// 重设大小
|
||||
virtual void _resize();
|
||||
|
||||
virtual ID2D1RectangleGeometry * _getD2dGeometry() const override;
|
||||
|
||||
protected:
|
||||
|
|
@ -149,6 +161,9 @@ protected:
|
|||
double radius
|
||||
);
|
||||
|
||||
// 重设大小
|
||||
virtual void _resize();
|
||||
|
||||
virtual ID2D1EllipseGeometry * _getD2dGeometry() const override;
|
||||
|
||||
protected:
|
||||
|
|
@ -184,6 +199,9 @@ protected:
|
|||
double radiusY
|
||||
);
|
||||
|
||||
// 重设大小
|
||||
virtual void _resize();
|
||||
|
||||
virtual ID2D1EllipseGeometry * _getD2dGeometry() const override;
|
||||
|
||||
protected:
|
||||
|
|
|
|||
Loading…
Reference in New Issue