Magic_Game/core/Shape/ShapeBase.cpp

110 lines
2.0 KiB
C++
Raw Normal View History

2018-02-03 22:04:43 +08:00
#include "..\eshape.h"
#include "..\emanagers.h"
#include "..\enodes.h"
2018-04-01 00:04:33 +08:00
e2d::ShapeBase::ShapeBase()
: 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)
2018-03-07 20:14:58 +08:00
, m_bAutoResize(true)
2018-02-03 22:04:43 +08:00
{
}
2018-04-01 00:04:33 +08:00
e2d::ShapeBase::~ShapeBase()
2018-02-03 22:04:43 +08:00
{
SafeReleaseInterface(&m_pTransformedShape);
}
2018-04-01 00:04:33 +08:00
e2d::Node * e2d::ShapeBase::getParentNode() const
2018-02-03 22:04:43 +08:00
{
return m_pParentNode;
}
2018-04-01 00:04:33 +08:00
void e2d::ShapeBase::setEnable(bool bEnable)
2018-02-03 22:04:43 +08:00
{
m_bEnable = bEnable;
}
2018-04-01 00:04:33 +08:00
void e2d::ShapeBase::setVisiable(bool bVisiable)
2018-02-03 22:04:43 +08:00
{
m_bIsVisiable = bVisiable;
}
2018-04-01 00:04:33 +08:00
void e2d::ShapeBase::setColor(UINT32 color)
2018-02-03 22:04:43 +08:00
{
m_nColor = color;
}
2018-04-01 00:04:33 +08:00
void e2d::ShapeBase::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-04-01 00:04:33 +08:00
void e2d::ShapeBase::setAutoResize(bool bEnable)
2018-03-07 20:14:58 +08:00
{
m_bAutoResize = bEnable;
}
2018-04-01 00:04:33 +08:00
void e2d::ShapeBase::_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
}
}
2018-04-01 23:08:11 +08:00
int e2d::ShapeBase::getRelationWith(ShapeBase * 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
);
2018-04-01 23:08:11 +08:00
return relation;
2018-02-03 22:04:43 +08:00
}
}
2018-03-31 22:34:18 +08:00
return Relation::UNKNOWN;
2018-02-03 22:04:43 +08:00
}
2018-04-01 00:04:33 +08:00
void e2d::ShapeBase::_transform()
2018-02-03 22:04:43 +08:00
{
if (m_pParentNode && m_bEnable)
{
2018-03-07 20:14:58 +08:00
if (m_bAutoResize)
{
this->_resize();
}
2018-02-03 22:04:43 +08:00
// <20>ͷ<EFBFBD>ԭ<EFBFBD><D4AD>״
SafeReleaseInterface(&m_pTransformedShape);
// <20><><EFBFBD>ݸ<EFBFBD><DDB8>ڵ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
Renderer::getID2D1Factory()->CreateTransformedGeometry(
getD2dGeometry(),
2018-02-03 22:04:43 +08:00
m_pParentNode->m_MatriFinal,
&m_pTransformedShape
);
CollisionManager::__updateShape(this);
2018-02-03 22:04:43 +08:00
}
}