Magic_Game/core/Shape/Shape.cpp

121 lines
2.1 KiB
C++
Raw Normal View History

2018-02-03 22:04:43 +08:00
#include "..\eshape.h"
#include "..\emanagers.h"
#include "..\enodes.h"
e2d::Shape::Shape()
2018-02-03 22:04:43 +08:00
: m_nCategoryBitmask(0)
, m_nCollisionBitmask(0)
, m_bIsVisiable(true)
, m_nColor(Color::RED)
2018-02-03 22:04:43 +08:00
, m_fOpacity(1)
, m_pParentNode(nullptr)
, m_pTransformedShape(nullptr)
, m_bEnable(true)
{
}
e2d::Shape::~Shape()
2018-02-03 22:04:43 +08:00
{
SafeReleaseInterface(&m_pTransformedShape);
}
e2d::Node * e2d::Shape::getParentNode() const
2018-02-03 22:04:43 +08:00
{
return m_pParentNode;
}
UINT32 e2d::Shape::getCategoryBitmask() const
2018-02-03 22:04:43 +08:00
{
return m_nCategoryBitmask;
}
UINT32 e2d::Shape::getCollisionBitmask() const
2018-02-03 22:04:43 +08:00
{
return m_nCollisionBitmask;
}
void e2d::Shape::setCategoryBitmask(UINT32 mask)
2018-02-03 22:04:43 +08:00
{
m_nCategoryBitmask = mask;
}
void e2d::Shape::setCollisionBitmask(UINT32 mask)
2018-02-03 22:04:43 +08:00
{
m_nCollisionBitmask = mask;
}
void e2d::Shape::setEnable(bool bEnable)
2018-02-03 22:04:43 +08:00
{
m_bEnable = bEnable;
}
void e2d::Shape::setVisiable(bool bVisiable)
2018-02-03 22:04:43 +08:00
{
m_bIsVisiable = bVisiable;
}
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
}
void e2d::Shape::_render()
2018-02-03 22:04:43 +08:00
{
if (m_pTransformedShape && m_bEnable)
{
ID2D1SolidColorBrush * pBrush = Renderer::getSolidColorBrush();
2018-02-03 22:04:43 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˢ
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>״
Renderer::getRenderTarget()->DrawGeometry(m_pTransformedShape, pBrush);
2018-02-03 22:04:43 +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;
}
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>
Renderer::getID2D1Factory()->CreateTransformedGeometry(
2018-02-03 22:04:43 +08:00
_getD2dGeometry(),
m_pParentNode->m_MatriFinal,
&m_pTransformedShape
);
ShapeManager::__updateShape(this);
2018-02-03 22:04:43 +08:00
}
}