2018-02-03 22:04:43 +08:00
|
|
|
|
#include "..\eshape.h"
|
|
|
|
|
|
#include "..\emanagers.h"
|
|
|
|
|
|
#include "..\enodes.h"
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::Shape::Shape()
|
2018-02-03 22:04:43 +08:00
|
|
|
|
: m_nCategoryBitmask(0)
|
|
|
|
|
|
, m_nCollisionBitmask(0)
|
|
|
|
|
|
, m_bIsVisiable(true)
|
2018-02-07 16:37:12 +08:00
|
|
|
|
, m_nColor(Color::RED)
|
2018-02-03 22:04:43 +08:00
|
|
|
|
, m_fOpacity(1)
|
|
|
|
|
|
, m_pParentNode(nullptr)
|
|
|
|
|
|
, m_pTransformedShape(nullptr)
|
|
|
|
|
|
, m_bEnable(true)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::Shape::~Shape()
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
|
|
|
|
|
SafeReleaseInterface(&m_pTransformedShape);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
e2d::Node * e2d::Shape::getParentNode() const
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
|
|
|
|
|
return m_pParentNode;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
UINT32 e2d::Shape::getCategoryBitmask() const
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
|
|
|
|
|
return m_nCategoryBitmask;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
UINT32 e2d::Shape::getCollisionBitmask() const
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
|
|
|
|
|
return m_nCollisionBitmask;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Shape::setCategoryBitmask(UINT32 mask)
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
|
|
|
|
|
m_nCategoryBitmask = mask;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Shape::setCollisionBitmask(UINT32 mask)
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
|
|
|
|
|
m_nCollisionBitmask = mask;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Shape::setEnable(bool bEnable)
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
|
|
|
|
|
m_bEnable = bEnable;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Shape::setVisiable(bool bVisiable)
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
|
|
|
|
|
m_bIsVisiable = bVisiable;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Shape::setColor(UINT32 color)
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
|
|
|
|
|
m_nColor = color;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-27 21:07:43 +08:00
|
|
|
|
void e2d::Shape::setOpacity(double opacity)
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
2018-02-27 21:07:43 +08:00
|
|
|
|
m_fOpacity = min(max(static_cast<float>(opacity), 0), 1);
|
2018-02-03 22:04:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Shape::_render()
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (m_pTransformedShape && m_bEnable)
|
|
|
|
|
|
{
|
2018-02-07 16:37:12 +08:00
|
|
|
|
ID2D1SolidColorBrush * pBrush = Renderer::getSolidColorBrush();
|
2018-02-03 22:04:43 +08:00
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˢ
|
2018-02-07 16:37:12 +08:00
|
|
|
|
Renderer::getRenderTarget()->CreateSolidColorBrush(
|
2018-02-03 22:04:43 +08:00
|
|
|
|
D2D1::ColorF(
|
|
|
|
|
|
m_nColor,
|
|
|
|
|
|
m_fOpacity),
|
|
|
|
|
|
&pBrush
|
|
|
|
|
|
);
|
|
|
|
|
|
// <20><><EFBFBD>Ƽ<EFBFBD><C6BC><EFBFBD><EFBFBD><EFBFBD>״
|
2018-02-07 16:37:12 +08:00
|
|
|
|
Renderer::getRenderTarget()->DrawGeometry(m_pTransformedShape, pBrush);
|
2018-02-03 22:04:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
int e2d::Shape::getRelationWith(Shape * pShape) const
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (m_pTransformedShape && pShape->m_pTransformedShape)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_bEnable && pShape->m_bEnable)
|
|
|
|
|
|
{
|
|
|
|
|
|
D2D1_GEOMETRY_RELATION relation;
|
|
|
|
|
|
|
|
|
|
|
|
m_pTransformedShape->CompareWithGeometry(
|
|
|
|
|
|
pShape->m_pTransformedShape,
|
|
|
|
|
|
D2D1::Matrix3x2F::Identity(),
|
|
|
|
|
|
&relation
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
return relation;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
void e2d::Shape::_transform()
|
2018-02-03 22:04:43 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (m_pParentNode && m_bEnable)
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20>ͷ<EFBFBD>ԭ<EFBFBD><D4AD>״
|
|
|
|
|
|
SafeReleaseInterface(&m_pTransformedShape);
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD>ݸ<EFBFBD><DDB8>ڵ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
|
2018-02-07 16:37:12 +08:00
|
|
|
|
Renderer::getID2D1Factory()->CreateTransformedGeometry(
|
2018-02-03 22:04:43 +08:00
|
|
|
|
_getD2dGeometry(),
|
|
|
|
|
|
m_pParentNode->m_MatriFinal,
|
|
|
|
|
|
&m_pTransformedShape
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2018-02-07 16:37:12 +08:00
|
|
|
|
ShapeManager::__updateShape(this);
|
2018-02-03 22:04:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|