new feature: shape

Shape change into collider
This commit is contained in:
Nomango 2018-04-02 23:01:38 +08:00
parent 349ddedb3c
commit 02ccbff4eb
72 changed files with 1313 additions and 587 deletions

View File

@ -1,5 +1,5 @@
#include "..\eactions.h" #include "..\eaction.h"
#include "..\emanagers.h" #include "..\emanager.h"
e2d::Action::Action() e2d::Action::Action()
: m_bRunning(false) : m_bRunning(false)

View File

@ -1,4 +1,4 @@
#include "..\eactions.h" #include "..\eaction.h"
e2d::ActionDelay::ActionDelay(double duration) e2d::ActionDelay::ActionDelay(double duration)
{ {

View File

@ -1,4 +1,4 @@
#include "..\eactions.h" #include "..\eaction.h"
e2d::ActionFunc::ActionFunc(Function func) : e2d::ActionFunc::ActionFunc(Function func) :
m_Callback(func) m_Callback(func)

View File

@ -1,4 +1,4 @@
#include "..\eactions.h" #include "..\eaction.h"
e2d::ActionGradual::ActionGradual(double duration) e2d::ActionGradual::ActionGradual(double duration)
: m_fRateOfProgress(0) : m_fRateOfProgress(0)

View File

@ -1,5 +1,5 @@
#include "..\eactions.h" #include "..\eaction.h"
#include "..\emanagers.h" #include "..\emanager.h"
e2d::ActionLoop::ActionLoop(Action * action, int times /* = -1 */) e2d::ActionLoop::ActionLoop(Action * action, int times /* = -1 */)
: m_pAction(action) : m_pAction(action)

View File

@ -1,4 +1,4 @@
#include "..\eactions.h" #include "..\eaction.h"
e2d::ActionMoveBy::ActionMoveBy(double duration, Vector vector) : e2d::ActionMoveBy::ActionMoveBy(double duration, Vector vector) :

View File

@ -1,4 +1,4 @@
#include "..\eactions.h" #include "..\eaction.h"
e2d::ActionMoveTo::ActionMoveTo(double duration, Point pos) : e2d::ActionMoveTo::ActionMoveTo(double duration, Point pos) :
ActionMoveBy(duration, Vector()) ActionMoveBy(duration, Vector())

View File

@ -1,4 +1,4 @@
#include "..\eactions.h" #include "..\eaction.h"
e2d::ActionOpacityBy::ActionOpacityBy(double duration, double opacity) : e2d::ActionOpacityBy::ActionOpacityBy(double duration, double opacity) :

View File

@ -1,4 +1,4 @@
#include "..\eactions.h" #include "..\eaction.h"
e2d::ActionOpacityTo::ActionOpacityTo(double duration, double opacity) : e2d::ActionOpacityTo::ActionOpacityTo(double duration, double opacity) :

View File

@ -1,4 +1,4 @@
#include "..\eactions.h" #include "..\eaction.h"
e2d::ActionRotateBy::ActionRotateBy(double duration, double rotation) : e2d::ActionRotateBy::ActionRotateBy(double duration, double rotation) :

View File

@ -1,4 +1,4 @@
#include "..\eactions.h" #include "..\eaction.h"
e2d::ActionRotateTo::ActionRotateTo(double duration, double rotation) : e2d::ActionRotateTo::ActionRotateTo(double duration, double rotation) :

View File

@ -1,4 +1,4 @@
#include "..\eactions.h" #include "..\eaction.h"
e2d::ActionScaleBy::ActionScaleBy(double duration, double scale) e2d::ActionScaleBy::ActionScaleBy(double duration, double scale)

View File

@ -1,4 +1,4 @@
#include "..\eactions.h" #include "..\eaction.h"
e2d::ActionScaleTo::ActionScaleTo(double duration, double scale) e2d::ActionScaleTo::ActionScaleTo(double duration, double scale)
: ActionScaleBy(duration, 0, 0) : ActionScaleBy(duration, 0, 0)

View File

@ -1,4 +1,4 @@
#include "..\eactions.h" #include "..\eaction.h"
e2d::ActionSequence::ActionSequence() e2d::ActionSequence::ActionSequence()
: m_nActionIndex(0) : m_nActionIndex(0)

View File

@ -1,4 +1,4 @@
#include "..\eactions.h" #include "..\eaction.h"
e2d::ActionTwo::ActionTwo(Action * pActionFirst, Action * pActionSecond, bool bAtSameTime/* = false*/) e2d::ActionTwo::ActionTwo(Action * pActionFirst, Action * pActionSecond, bool bAtSameTime/* = false*/)
: m_pFirstAction(pActionFirst) : m_pFirstAction(pActionFirst)

View File

@ -1,4 +1,4 @@
#include "..\eactions.h" #include "..\eaction.h"
e2d::Animation::Animation() e2d::Animation::Animation()
: m_nFrameIndex(0) : m_nFrameIndex(0)

View File

@ -1,5 +1,5 @@
#include "..\ebase.h" #include "..\ebase.h"
#include "..\emanagers.h" #include "..\emanager.h"
// ¿ØÖÆÓÎÏ·ÖÕÖ¹ // ¿ØÖÆÓÎÏ·ÖÕÖ¹

View File

@ -1,6 +1,6 @@
#include "..\ebase.h" #include "..\ebase.h"
#include "..\etools.h" #include "..\etool.h"
#include "..\emanagers.h" #include "..\emanager.h"
#pragma comment(lib, "dinput8.lib") #pragma comment(lib, "dinput8.lib")

View File

@ -1,5 +1,5 @@
#include "..\ebase.h" #include "..\ebase.h"
#include "..\emanagers.h" #include "..\emanager.h"
static ID2D1Factory * s_pDirect2dFactory = nullptr; static ID2D1Factory * s_pDirect2dFactory = nullptr;
static ID2D1HwndRenderTarget * s_pRenderTarget = nullptr; static ID2D1HwndRenderTarget * s_pRenderTarget = nullptr;

View File

@ -1,5 +1,5 @@
#include "..\ebase.h" #include "..\ebase.h"
#include "..\emanagers.h" #include "..\emanager.h"
#include <imm.h> #include <imm.h>
#pragma comment (lib ,"imm32.lib") #pragma comment (lib ,"imm32.lib")

109
core/Collider/Collider.cpp Normal file
View File

@ -0,0 +1,109 @@
#include "..\ecollider.h"
#include "..\emanager.h"
#include "..\enode.h"
e2d::Collider::Collider()
: m_bIsVisiable(true)
, m_nColor(Color::RED)
, m_fOpacity(1)
, m_pParentNode(nullptr)
, m_pTransformedGeometry(nullptr)
, m_bEnable(true)
, m_bAutoResize(true)
{
}
e2d::Collider::~Collider()
{
SafeReleaseInterface(&m_pTransformedGeometry);
}
e2d::Node * e2d::Collider::getParentNode() const
{
return m_pParentNode;
}
void e2d::Collider::setEnable(bool bEnable)
{
m_bEnable = bEnable;
}
void e2d::Collider::setVisiable(bool bVisiable)
{
m_bIsVisiable = bVisiable;
}
void e2d::Collider::setColor(UINT32 color)
{
m_nColor = color;
}
void e2d::Collider::setOpacity(double opacity)
{
m_fOpacity = min(max(static_cast<float>(opacity), 0), 1);
}
void e2d::Collider::setAutoResize(bool bEnable)
{
m_bAutoResize = bEnable;
}
void e2d::Collider::_render()
{
if (m_pTransformedGeometry && m_bEnable)
{
ID2D1SolidColorBrush * pBrush = Renderer::getSolidColorBrush();
// 눼쉔뺌岬
Renderer::getRenderTarget()->CreateSolidColorBrush(
D2D1::ColorF(
m_nColor,
m_fOpacity),
&pBrush
);
// 삥齡섯부툭旒竟
Renderer::getRenderTarget()->DrawGeometry(m_pTransformedGeometry, pBrush);
}
}
int e2d::Collider::getRelationWith(Collider * pCollider) const
{
if (m_pTransformedGeometry && pCollider->m_pTransformedGeometry)
{
if (m_bEnable && pCollider->m_bEnable)
{
D2D1_GEOMETRY_RELATION relation;
m_pTransformedGeometry->CompareWithGeometry(
pCollider->m_pTransformedGeometry,
D2D1::Matrix3x2F::Identity(),
&relation
);
return relation;
}
}
return Relation::UNKNOWN;
}
void e2d::Collider::_transform()
{
if (m_pParentNode && m_bEnable)
{
if (m_bAutoResize)
{
this->_resize();
}
// 姦렴覩툭旒竟
SafeReleaseInterface(&m_pTransformedGeometry);
// 몽앴만쌘듐瘻뻣섯부暠近
Renderer::getID2D1Factory()->CreateTransformedGeometry(
getD2dGeometry(),
m_pParentNode->m_MatriFinal,
&m_pTransformedGeometry
);
ColliderManager::__updateCollider(this);
}
}

View File

@ -1,18 +1,18 @@
#include "..\eshape.h" #include "..\ecollider.h"
#include "..\enodes.h" #include "..\enode.h"
e2d::ShapeCircle::ShapeCircle() e2d::ColliderCircle::ColliderCircle()
: m_pD2dCircle(nullptr) : m_pD2dCircle(nullptr)
{ {
} }
e2d::ShapeCircle::ShapeCircle(Point center, double radius) e2d::ColliderCircle::ColliderCircle(Point center, double radius)
: m_pD2dCircle(nullptr) : m_pD2dCircle(nullptr)
{ {
this->setCircle(center, radius); this->setCircle(center, radius);
} }
e2d::ShapeCircle::ShapeCircle(Node * node) e2d::ColliderCircle::ColliderCircle(Node * node)
: m_pD2dCircle(nullptr) : m_pD2dCircle(nullptr)
{ {
double minSide = min(node->getRealWidth(), node->getRealHeight()); double minSide = min(node->getRealWidth(), node->getRealHeight());
@ -25,12 +25,12 @@ e2d::ShapeCircle::ShapeCircle(Node * node)
); );
} }
e2d::ShapeCircle::~ShapeCircle() e2d::ColliderCircle::~ColliderCircle()
{ {
SafeReleaseInterface(&m_pD2dCircle); SafeReleaseInterface(&m_pD2dCircle);
} }
void e2d::ShapeCircle::setCircle(Point center, double radius) void e2d::ColliderCircle::setCircle(Point center, double radius)
{ {
SafeReleaseInterface(&m_pD2dCircle); SafeReleaseInterface(&m_pD2dCircle);
@ -45,7 +45,7 @@ void e2d::ShapeCircle::setCircle(Point center, double radius)
); );
} }
void e2d::ShapeCircle::_resize() void e2d::ColliderCircle::_resize()
{ {
if (m_pParentNode && m_bEnable) if (m_pParentNode && m_bEnable)
{ {
@ -60,7 +60,7 @@ void e2d::ShapeCircle::_resize()
} }
} }
ID2D1EllipseGeometry * e2d::ShapeCircle::getD2dGeometry() const ID2D1EllipseGeometry * e2d::ColliderCircle::getD2dGeometry() const
{ {
return m_pD2dCircle; return m_pD2dCircle;
} }

View File

@ -1,18 +1,18 @@
#include "..\eshape.h" #include "..\ecollider.h"
#include "..\enodes.h" #include "..\enode.h"
e2d::ShapeEllipse::ShapeEllipse() e2d::ColliderEllipse::ColliderEllipse()
: m_pD2dEllipse(nullptr) : m_pD2dEllipse(nullptr)
{ {
} }
e2d::ShapeEllipse::ShapeEllipse(Point center, double radiusX, double radiusY) e2d::ColliderEllipse::ColliderEllipse(Point center, double radiusX, double radiusY)
: m_pD2dEllipse(nullptr) : m_pD2dEllipse(nullptr)
{ {
this->setEllipse(center, radiusX, radiusY); this->setEllipse(center, radiusX, radiusY);
} }
e2d::ShapeEllipse::ShapeEllipse(Node * node) e2d::ColliderEllipse::ColliderEllipse(Node * node)
: m_pD2dEllipse(nullptr) : m_pD2dEllipse(nullptr)
{ {
this->setEllipse( this->setEllipse(
@ -25,12 +25,12 @@ e2d::ShapeEllipse::ShapeEllipse(Node * node)
); );
} }
e2d::ShapeEllipse::~ShapeEllipse() e2d::ColliderEllipse::~ColliderEllipse()
{ {
SafeReleaseInterface(&m_pD2dEllipse); SafeReleaseInterface(&m_pD2dEllipse);
} }
void e2d::ShapeEllipse::setEllipse(Point center, double radiusX, double radiusY) void e2d::ColliderEllipse::setEllipse(Point center, double radiusX, double radiusY)
{ {
SafeReleaseInterface(&m_pD2dEllipse); SafeReleaseInterface(&m_pD2dEllipse);
@ -45,7 +45,7 @@ void e2d::ShapeEllipse::setEllipse(Point center, double radiusX, double radiusY)
); );
} }
void e2d::ShapeEllipse::_resize() void e2d::ColliderEllipse::_resize()
{ {
if (m_pParentNode && m_bEnable) if (m_pParentNode && m_bEnable)
{ {
@ -60,7 +60,7 @@ void e2d::ShapeEllipse::_resize()
} }
} }
ID2D1EllipseGeometry * e2d::ShapeEllipse::getD2dGeometry() const ID2D1EllipseGeometry * e2d::ColliderEllipse::getD2dGeometry() const
{ {
return m_pD2dEllipse; return m_pD2dEllipse;
} }

View File

@ -0,0 +1,51 @@
#include "..\ecollider.h"
#include "..\enode.h"
e2d::ColliderRect::ColliderRect()
: m_pD2dRectangle(nullptr)
{
}
e2d::ColliderRect::ColliderRect(double x, double y, double width, double height)
: m_pD2dRectangle(nullptr)
{
this->setRect(x, y, x + width, y + height);
}
e2d::ColliderRect::ColliderRect(Node * node)
: m_pD2dRectangle(nullptr)
{
this->setRect(0, 0, node->getRealWidth(), node->getRealHeight());
}
e2d::ColliderRect::~ColliderRect()
{
SafeReleaseInterface(&m_pD2dRectangle);
}
void e2d::ColliderRect::setRect(double left, double top, double right, double bottom)
{
SafeReleaseInterface(&m_pD2dRectangle);
Renderer::getID2D1Factory()->CreateRectangleGeometry(
D2D1::RectF(
static_cast<float>(left),
static_cast<float>(top),
static_cast<float>(right),
static_cast<float>(bottom)),
&m_pD2dRectangle
);
}
void e2d::ColliderRect::_resize()
{
if (m_pParentNode && m_bEnable)
{
this->setRect( 0, 0, m_pParentNode->getRealWidth(), m_pParentNode->getRealHeight());
}
}
ID2D1RectangleGeometry * e2d::ColliderRect::getD2dGeometry() const
{
return m_pD2dRectangle;
}

View File

@ -1,4 +1,4 @@
#include "..\enodes.h" #include "..\enode.h"
e2d::Font::Font() e2d::Font::Font()
: fontFamily("") : fontFamily("")

View File

@ -1,4 +1,4 @@
#include "..\enodes.h" #include "..\enode.h"
#include <map> #include <map>
static std::map<size_t, ID2D1Bitmap*> s_mBitmapsFromFile; static std::map<size_t, ID2D1Bitmap*> s_mBitmapsFromFile;

View File

@ -1,5 +1,5 @@
#include "..\ebase.h" #include "..\ebase.h"
#include "..\emanagers.h" #include "..\emanager.h"
e2d::Object::Object() e2d::Object::Object()
: m_nRefCount(0) : m_nRefCount(0)

View File

@ -1,12 +1,12 @@
#include "..\ebase.h" #include "..\ebase.h"
#include "..\enodes.h" #include "..\enode.h"
#include "..\emanagers.h" #include "..\emanager.h"
e2d::Scene::Scene() e2d::Scene::Scene()
: m_bWillSave(true) : m_bWillSave(true)
, m_bAutoUpdate(true) , m_bAutoUpdate(true)
, m_bSortNeeded(false) , m_bSortNeeded(false)
, m_bShapeVisiable(false) , m_bColliderVisiable(false)
, m_pRoot(new Node()) , m_pRoot(new Node())
{ {
m_pRoot->retain(); m_pRoot->retain();
@ -23,12 +23,12 @@ void e2d::Scene::_render()
{ {
m_pRoot->_render(); m_pRoot->_render();
if (m_bShapeVisiable) if (m_bColliderVisiable)
{ {
// 恢复矩阵转换 // 恢复矩阵转换
Renderer::getRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity()); Renderer::getRenderTarget()->SetTransform(D2D1::Matrix3x2F::Identity());
// 绘制所有几何图形 // 绘制所有几何图形
m_pRoot->_drawShape(); m_pRoot->_drawCollider();
} }
} }
@ -73,7 +73,7 @@ e2d::Node * e2d::Scene::getRoot() const
return m_pRoot; return m_pRoot;
} }
void e2d::Scene::showOutline(bool visiable) void e2d::Scene::showCollider(bool visiable)
{ {
m_bShapeVisiable = visiable; m_bColliderVisiable = visiable;
} }

View File

@ -57,6 +57,17 @@ e2d::String e2d::String::parse(int value)
return std::move(tmp); return std::move(tmp);
} }
e2d::String e2d::String::parse(unsigned int value)
{
String tmp;
#if HIGHER_THAN_VS2010
tmp.m_str = std::to_wstring(value);
#else
tmp.m_str = std::to_wstring(static_cast<long long>(value));
#endif
return std::move(tmp);
}
e2d::String e2d::String::parse(float value) e2d::String e2d::String::parse(float value)
{ {
String tmp; String tmp;
@ -303,6 +314,12 @@ e2d::String & e2d::String::operator<<(int value)
return (*this); return (*this);
} }
e2d::String & e2d::String::operator<<(unsigned int value)
{
(*this) += String::parse(value);
return (*this);
}
e2d::String & e2d::String::operator<<(float value) e2d::String & e2d::String::operator<<(float value)
{ {
(*this) += String::parse(value); (*this) += String::parse(value);

View File

@ -1,5 +1,5 @@
#include "..\emanagers.h" #include "..\emanager.h"
#include "..\eactions.h" #include "..\eaction.h"
static std::vector<e2d::Action*> s_vActions; static std::vector<e2d::Action*> s_vActions;
static std::vector<e2d::Action*> s_vRunningActions; static std::vector<e2d::Action*> s_vRunningActions;

View File

@ -1,10 +1,10 @@
#include "..\emanagers.h" #include "..\emanager.h"
#include "..\enodes.h" #include "..\enode.h"
#include "..\eshape.h" #include "..\ecollider.h"
#include "..\etools.h" #include "..\etool.h"
// 形状集合 // 碰撞体集合
static std::vector<e2d::ShapeBase*> s_vShapes; static std::vector<e2d::Collider*> s_vColliders;
// 监听器容器 // 监听器容器
static std::vector<e2d::CollisionListener*> s_vListeners; static std::vector<e2d::CollisionListener*> s_vListeners;
// 碰撞触发状态 // 碰撞触发状态
@ -14,12 +14,12 @@ static e2d::Node * s_pActiveNode = nullptr;
static e2d::Node * s_pPassiveNode = nullptr; static e2d::Node * s_pPassiveNode = nullptr;
void e2d::CollisionManager::setEnable(bool bEnable) void e2d::ColliderManager::setEnable(bool bEnable)
{ {
s_bCollisionEnable = bEnable; s_bCollisionEnable = bEnable;
} }
void e2d::CollisionManager::__update() void e2d::ColliderManager::__update()
{ {
if (s_vListeners.size() == 0) if (s_vListeners.size() == 0)
return; return;
@ -40,28 +40,28 @@ void e2d::CollisionManager::__update()
} }
} }
void e2d::CollisionManager::__updateShape(e2d::ShapeBase * pActiveShape) void e2d::ColliderManager::__updateCollider(e2d::Collider * pActiveCollider)
{ {
// 判断碰撞触发是否打开 // 判断碰撞触发是否打开
if (!s_bCollisionEnable) if (!s_bCollisionEnable)
return; return;
Node* pActiveNode = pActiveShape->m_pParentNode; Node* pActiveNode = pActiveCollider->m_pParentNode;
if (pActiveNode) if (pActiveNode)
{ {
// 获取节点所在场景 // 获取节点所在场景
Scene* pCurrentScene = pActiveNode->getParentScene(); Scene* pCurrentScene = pActiveNode->getParentScene();
// 判断与其他形状的交集情况 // 判断与其他碰撞体的交集情况
for (size_t i = 0; i < s_vShapes.size(); i++) for (size_t i = 0; i < s_vColliders.size(); i++)
{ {
auto pPassiveShape = s_vShapes[i]; auto pPassiveCollider = s_vColliders[i];
// 判断两个形状是否是同一个对象 // 判断两个碰撞体是否是同一个对象
if (pActiveShape == pPassiveShape) if (pActiveCollider == pPassiveCollider)
continue; continue;
// 获取被碰撞节点 // 获取被碰撞节点
Node* pPassiveNode = pPassiveShape->m_pParentNode; Node* pPassiveNode = pPassiveCollider->m_pParentNode;
// 判断两节点是否处于同一场景中 // 判断两节点是否处于同一场景中
if (pPassiveNode && if (pPassiveNode &&
pPassiveNode->getParentScene() == pCurrentScene) pPassiveNode->getParentScene() == pCurrentScene)
@ -77,8 +77,8 @@ void e2d::CollisionManager::__updateShape(e2d::ShapeBase * pActiveShape)
if (IsCollideWith(pActiveNode, pPassiveNode->getHashName())) if (IsCollideWith(pActiveNode, pPassiveNode->getHashName()))
{ {
// 判断两形状交集情况 // 判断两碰撞体交集情况
int relation = pActiveShape->getRelationWith(pPassiveShape); int relation = pActiveCollider->getRelationWith(pPassiveCollider);
// 忽略 UNKNOWN 和 DISJOINT 情况 // 忽略 UNKNOWN 和 DISJOINT 情况
if (relation != Relation::UNKNOWN && relation != Relation::DISJOINT) if (relation != Relation::UNKNOWN && relation != Relation::DISJOINT)
{ {
@ -86,8 +86,8 @@ void e2d::CollisionManager::__updateShape(e2d::ShapeBase * pActiveShape)
s_pPassiveNode = pPassiveNode; s_pPassiveNode = pPassiveNode;
pActiveNode->onCollide(pPassiveNode); pActiveNode->onCollide(pPassiveNode);
pPassiveNode->onCollide(pActiveNode); pPassiveNode->onCollide(pActiveNode);
pCurrentScene->onCollide(); pCurrentScene->onCollide(pActiveNode, pPassiveNode);
CollisionManager::__update(); ColliderManager::__update();
} }
} }
} }
@ -97,7 +97,7 @@ void e2d::CollisionManager::__updateShape(e2d::ShapeBase * pActiveShape)
s_pPassiveNode = nullptr; s_pPassiveNode = nullptr;
} }
void e2d::CollisionManager::__add(CollisionListener * pListener) void e2d::ColliderManager::__add(CollisionListener * pListener)
{ {
WARN_IF(pListener == nullptr, "CollisionListener NULL pointer exception!"); WARN_IF(pListener == nullptr, "CollisionListener NULL pointer exception!");
@ -126,12 +126,12 @@ void e2d::CollisionManager::__add(CollisionListener * pListener)
} }
} }
void e2d::CollisionManager::add(Function func, String name) void e2d::ColliderManager::add(Function func, String name)
{ {
(new CollisionListener(func, name))->start(); (new CollisionListener(func, name))->start();
} }
void e2d::CollisionManager::start(String name) void e2d::ColliderManager::start(String name)
{ {
FOR_LOOP(pListener, s_vListeners) FOR_LOOP(pListener, s_vListeners)
{ {
@ -142,7 +142,7 @@ void e2d::CollisionManager::start(String name)
} }
} }
void e2d::CollisionManager::stop(String name) void e2d::ColliderManager::stop(String name)
{ {
FOR_LOOP(pListener, s_vListeners) FOR_LOOP(pListener, s_vListeners)
{ {
@ -153,7 +153,7 @@ void e2d::CollisionManager::stop(String name)
} }
} }
void e2d::CollisionManager::clear(String name) void e2d::ColliderManager::clear(String name)
{ {
FOR_LOOP(pListener, s_vListeners) FOR_LOOP(pListener, s_vListeners)
{ {
@ -164,7 +164,7 @@ void e2d::CollisionManager::clear(String name)
} }
} }
void e2d::CollisionManager::startAll() void e2d::ColliderManager::startAll()
{ {
FOR_LOOP(pListener, s_vListeners) FOR_LOOP(pListener, s_vListeners)
{ {
@ -172,7 +172,7 @@ void e2d::CollisionManager::startAll()
} }
} }
void e2d::CollisionManager::stopAll() void e2d::ColliderManager::stopAll()
{ {
FOR_LOOP(pListener, s_vListeners) FOR_LOOP(pListener, s_vListeners)
{ {
@ -180,7 +180,7 @@ void e2d::CollisionManager::stopAll()
} }
} }
void e2d::CollisionManager::clearAll() void e2d::ColliderManager::clearAll()
{ {
FOR_LOOP(pListener, s_vListeners) FOR_LOOP(pListener, s_vListeners)
{ {
@ -188,7 +188,7 @@ void e2d::CollisionManager::clearAll()
} }
} }
std::vector<e2d::CollisionListener*> e2d::CollisionManager::get(String name) std::vector<e2d::CollisionListener*> e2d::ColliderManager::get(String name)
{ {
std::vector<CollisionListener*> vListeners; std::vector<CollisionListener*> vListeners;
FOR_LOOP(pListener, s_vListeners) FOR_LOOP(pListener, s_vListeners)
@ -201,12 +201,22 @@ std::vector<e2d::CollisionListener*> e2d::CollisionManager::get(String name)
return std::move(vListeners); return std::move(vListeners);
} }
std::vector<e2d::CollisionListener*> e2d::CollisionManager::getAll() std::vector<e2d::CollisionListener*> e2d::ColliderManager::getAll()
{ {
return s_vListeners; return s_vListeners;
} }
e2d::Node* e2d::CollisionManager::isCausedBy(Node * pNode) e2d::Node * e2d::ColliderManager::getActiveNode()
{
return s_pActiveNode;
}
e2d::Node * e2d::ColliderManager::getPassiveNode()
{
return s_pPassiveNode;
}
e2d::Node* e2d::ColliderManager::isCausedBy(Node * pNode)
{ {
if (s_pActiveNode == pNode) if (s_pActiveNode == pNode)
return s_pPassiveNode; return s_pPassiveNode;
@ -215,7 +225,7 @@ e2d::Node* e2d::CollisionManager::isCausedBy(Node * pNode)
return nullptr; return nullptr;
} }
e2d::Node* e2d::CollisionManager::isCausedBy(String name) e2d::Node* e2d::ColliderManager::isCausedBy(String name)
{ {
if (s_pActiveNode->getName() == name) if (s_pActiveNode->getName() == name)
return s_pActiveNode; return s_pActiveNode;
@ -224,30 +234,30 @@ e2d::Node* e2d::CollisionManager::isCausedBy(String name)
return nullptr; return nullptr;
} }
void e2d::CollisionManager::__addShape(ShapeBase * pShape) void e2d::ColliderManager::__addCollider(Collider * pCollider)
{ {
if (pShape) if (pCollider)
{ {
if (pShape->m_pParentNode) if (pCollider->m_pParentNode)
{ {
WARN_IF(true, "CollisionManager::__add Failed! The shape is already added."); WARN_IF(true, "ColliderManager::__add Failed! The shape is already added.");
return; return;
} }
pShape->retain(); pCollider->retain();
s_vShapes.push_back(pShape); s_vColliders.push_back(pCollider);
} }
} }
void e2d::CollisionManager::__removeShape(ShapeBase * pShape) void e2d::ColliderManager::__removeCollider(Collider * pCollider)
{ {
if (pShape) if (pCollider)
{ {
for (size_t i = 0; i < s_vShapes.size(); i++) for (size_t i = 0; i < s_vColliders.size(); i++)
{ {
if (s_vShapes[i] == pShape) if (s_vColliders[i] == pCollider)
{ {
SafeRelease(&pShape); SafeRelease(&pCollider);
s_vShapes.erase(s_vShapes.begin() + i); s_vColliders.erase(s_vColliders.begin() + i);
return; return;
} }
} }

View File

@ -1,5 +1,5 @@
#include "..\emanagers.h" #include "..\emanager.h"
#include "..\etools.h" #include "..\etool.h"
// 监听器容器 // 监听器容器
static std::vector<e2d::InputListener*> s_vListeners; static std::vector<e2d::InputListener*> s_vListeners;

View File

@ -1,5 +1,5 @@
#include "..\emanagers.h" #include "..\emanager.h"
#include "..\etools.h" #include "..\etool.h"
#include <map> #include <map>
#if HIGHER_THAN_VS2010 #if HIGHER_THAN_VS2010

View File

@ -1,4 +1,4 @@
#include "..\emanagers.h" #include "..\emanager.h"
#include "..\ebase.h" #include "..\ebase.h"
// ObjectManager 释放池的实现机制: // ObjectManager 释放池的实现机制:

View File

@ -1,6 +1,6 @@
#include "..\emanagers.h" #include "..\emanager.h"
#include "..\ebase.h" #include "..\ebase.h"
#include "..\etransitions.h" #include "..\etransition.h"
static e2d::Scene * s_pCurrentScene = nullptr; static e2d::Scene * s_pCurrentScene = nullptr;
static e2d::Scene * s_pNextScene = nullptr; static e2d::Scene * s_pNextScene = nullptr;

View File

@ -1,6 +1,6 @@
#include "..\emanagers.h" #include "..\emanager.h"
#include "..\etools.h" #include "..\etool.h"
#include "..\enodes.h" #include "..\enode.h"
static std::vector<e2d::Timer*> s_vTimers; static std::vector<e2d::Timer*> s_vTimers;

View File

@ -1,5 +1,5 @@
#include "..\enodes.h" #include "..\enode.h"
#include "..\emanagers.h" #include "..\emanager.h"
#define SAFE_SETTER(pointer, func, ...) if (pointer) { pointer->##func(__VA_ARGS__); } #define SAFE_SETTER(pointer, func, ...) if (pointer) { pointer->##func(__VA_ARGS__); }

View File

@ -1,4 +1,4 @@
#include "..\enodes.h" #include "..\enode.h"
e2d::ButtonToggle::ButtonToggle() e2d::ButtonToggle::ButtonToggle()
: Button() : Button()

View File

@ -1,10 +1,22 @@
#include "..\enodes.h" #include "..\enode.h"
e2d::Menu::Menu() e2d::Menu::Menu()
: m_bEnable(true) : m_bEnable(true)
{ {
} }
#if HIGHER_THAN_VS2012
e2d::Menu::Menu(const InitList<Button*>& vButtons)
: m_bEnable(true)
{
FOR_LOOP(button, vButtons)
{
this->addButton(button);
}
}
#else
e2d::Menu::Menu(int number, Button * button1, ...) e2d::Menu::Menu(int number, Button * button1, ...)
: m_bEnable(true) : m_bEnable(true)
{ {
@ -17,6 +29,7 @@ e2d::Menu::Menu(int number, Button * button1, ...)
number--; number--;
} }
} }
#endif
bool e2d::Menu::isEnable() const bool e2d::Menu::isEnable() const
{ {

View File

@ -1,14 +1,14 @@
#include "..\enodes.h" #include "..\enode.h"
#include "..\emanagers.h" #include "..\emanager.h"
#include "..\etools.h" #include "..\etool.h"
#include "..\eactions.h" #include "..\eaction.h"
#include "..\eshape.h" #include "..\ecollider.h"
#include <algorithm> #include <algorithm>
// 默认中心点位置 // 默认中心点位置
static float s_fDefaultPiovtX = 0; static float s_fDefaultPiovtX = 0;
static float s_fDefaultPiovtY = 0; static float s_fDefaultPiovtY = 0;
static bool s_fDefaultShapeEnabled = true; static bool s_fDefaultColliderEnabled = true;
e2d::Node::Node() e2d::Node::Node()
: m_nOrder(0) : m_nOrder(0)
@ -29,7 +29,7 @@ e2d::Node::Node()
, m_MatriFinal(D2D1::Matrix3x2F::Identity()) , m_MatriFinal(D2D1::Matrix3x2F::Identity())
, m_bVisiable(true) , m_bVisiable(true)
, m_bDisplayedInScene(false) , m_bDisplayedInScene(false)
, m_pShape(nullptr) , m_pCollider(nullptr)
, m_pParent(nullptr) , m_pParent(nullptr)
, m_pParentScene(nullptr) , m_pParentScene(nullptr)
, m_nHashName(0) , m_nHashName(0)
@ -37,17 +37,17 @@ e2d::Node::Node()
, m_bTransformNeeded(false) , m_bTransformNeeded(false)
, m_bAutoUpdate(true) , m_bAutoUpdate(true)
{ {
if (s_fDefaultShapeEnabled) if (s_fDefaultColliderEnabled)
{ {
auto rect = new ShapeRectangle(this); auto rect = new ColliderRect(this);
this->setShape(rect); this->setCollider(rect);
} }
} }
e2d::Node::~Node() e2d::Node::~Node()
{ {
ActionManager::__clearAllBindedWith(this); ActionManager::__clearAllBindedWith(this);
CollisionManager::__removeShape(m_pShape); ColliderManager::__removeCollider(m_pCollider);
FOR_LOOP(child, m_vChildren) FOR_LOOP(child, m_vChildren)
{ {
SafeRelease(&child); SafeRelease(&child);
@ -165,18 +165,18 @@ void e2d::Node::_render()
} }
} }
void e2d::Node::_drawShape() void e2d::Node::_drawCollider()
{ {
// 绘制自身的几何形状 // 绘制自身的几何碰撞体
if (m_pShape && m_pShape->m_bIsVisiable) if (m_pCollider && m_pCollider->m_bIsVisiable)
{ {
m_pShape->_render(); m_pCollider->_render();
} }
// 绘制所有子节点的几何形状 // 绘制所有子节点的几何碰撞体
FOR_LOOP(child, m_vChildren) FOR_LOOP(child, m_vChildren)
{ {
child->_drawShape(); child->_drawCollider();
} }
} }
@ -250,10 +250,10 @@ void e2d::Node::_updateTransform(Node * node)
{ {
// 计算自身的转换矩阵 // 计算自身的转换矩阵
node->_updateTransform(); node->_updateTransform();
// 绑定于自身的形状也进行相应转换 // 绑定于自身的碰撞体也进行相应转换
if (node->m_pShape) if (node->m_pCollider)
{ {
node->m_pShape->_transform(); node->m_pCollider->_transform();
} }
// 遍历子节点下的所有节点 // 遍历子节点下的所有节点
node->_updateChildrenTransform(); node->_updateChildrenTransform();
@ -378,9 +378,9 @@ double e2d::Node::getOpacity() const
return m_fRealOpacity; return m_fRealOpacity;
} }
e2d::ShapeBase * e2d::Node::getShape() const e2d::Collider * e2d::Node::getCollider() const
{ {
return m_pShape; return m_pCollider;
} }
int e2d::Node::getOrder() const int e2d::Node::getOrder() const
@ -547,28 +547,28 @@ void e2d::Node::setSize(Size size)
this->setSize(size.width, size.height); this->setSize(size.width, size.height);
} }
void e2d::Node::setShape(int type) void e2d::Node::setCollider(int nColliderType)
{ {
switch (type) switch (nColliderType)
{ {
case Shape::RECTANGLE: case ColliderType::RECT:
{ {
auto rect = new ShapeRectangle(this); auto rect = new ColliderRect(this);
this->setShape(rect); this->setCollider(rect);
break; break;
} }
case Shape::CIRCLE: case ColliderType::CIRCLE:
{ {
auto rect = new ShapeCircle(this); auto rect = new ColliderCircle(this);
this->setShape(rect); this->setCollider(rect);
break; break;
} }
case Shape::ELLIPSE: case ColliderType::ELLIPSE:
{ {
auto rect = new ShapeEllipse(this); auto rect = new ColliderEllipse(this);
this->setShape(rect); this->setCollider(rect);
break; break;
} }
@ -577,42 +577,42 @@ void e2d::Node::setShape(int type)
} }
} }
void e2d::Node::setShape(ShapeBase * pShape) void e2d::Node::setCollider(Collider * pCollider)
{ {
// 删除旧的形状 // 删除旧的碰撞体
CollisionManager::__removeShape(m_pShape); ColliderManager::__removeCollider(m_pCollider);
// 添加新的形状 // 添加新的碰撞体
CollisionManager::__addShape(pShape); ColliderManager::__addCollider(pCollider);
if (pShape) if (pCollider)
{ {
// 双向绑定 // 双向绑定
this->m_pShape = pShape; this->m_pCollider = pCollider;
pShape->m_pParentNode = this; pCollider->m_pParentNode = this;
} }
else else
{ {
this->m_pShape = nullptr; this->m_pCollider = nullptr;
} }
} }
void e2d::Node::addCollider(String collliderName) void e2d::Node::addColliableName(String collliderName)
{ {
unsigned int hash = collliderName.getHashCode(); unsigned int hash = collliderName.getHashCode();
m_vColliders.insert(hash); m_vColliders.insert(hash);
} }
#if HIGHER_THAN_VS2012 #if HIGHER_THAN_VS2012
void e2d::Node::addCollider(const InitList<String>& vCollliderName) void e2d::Node::addColliableName(const InitList<String>& vCollliderName)
{ {
for (const auto &name : vCollliderName) for (const auto &name : vCollliderName)
{ {
this->addCollider(name); this->addColliableName(name);
} }
} }
#endif #endif
void e2d::Node::removeCollider(String collliderName) void e2d::Node::removeColliableName(String collliderName)
{ {
unsigned int hash = collliderName.getHashCode(); unsigned int hash = collliderName.getHashCode();
m_vColliders.erase(hash); m_vColliders.erase(hash);
@ -887,10 +887,10 @@ std::vector<e2d::Action*> e2d::Node::getActions(String strActionName)
bool e2d::Node::isPointIn(Point point) const bool e2d::Node::isPointIn(Point point) const
{ {
BOOL ret = 0; BOOL ret = 0;
// 如果存在形状,用形状判断 // 如果存在碰撞体,用碰撞体判断
if (m_pShape) if (m_pCollider)
{ {
m_pShape->getD2dGeometry()->FillContainsPoint( m_pCollider->getD2dGeometry()->FillContainsPoint(
D2D1::Point2F( D2D1::Point2F(
static_cast<float>(point.x), static_cast<float>(point.x),
static_cast<float>(point.y)), static_cast<float>(point.y)),
@ -900,13 +900,13 @@ bool e2d::Node::isPointIn(Point point) const
} }
else else
{ {
// 为节点创建一个临时形状 // 为节点创建一个临时碰撞体
ID2D1RectangleGeometry * rect; ID2D1RectangleGeometry * rect;
Renderer::getID2D1Factory()->CreateRectangleGeometry( Renderer::getID2D1Factory()->CreateRectangleGeometry(
D2D1::RectF(0, 0, m_fWidth, m_fHeight), D2D1::RectF(0, 0, m_fWidth, m_fHeight),
&rect &rect
); );
// 判断点是否在形状 // 判断点是否在碰撞体
rect->FillContainsPoint( rect->FillContainsPoint(
D2D1::Point2F( D2D1::Point2F(
static_cast<float>(point.x), static_cast<float>(point.x),
@ -914,7 +914,7 @@ bool e2d::Node::isPointIn(Point point) const
m_MatriFinal, m_MatriFinal,
&ret &ret
); );
// 删除临时创建的形状 // 删除临时创建的碰撞体
SafeReleaseInterface(&rect); SafeReleaseInterface(&rect);
} }
@ -933,10 +933,10 @@ bool e2d::Node::isPointIn(Point point) const
bool e2d::Node::isIntersectWith(const Node * pNode) const bool e2d::Node::isIntersectWith(const Node * pNode) const
{ {
// 如果存在形状,用形状判断 // 如果存在碰撞体,用碰撞体判断
if (this->m_pShape && pNode->m_pShape) if (this->m_pCollider && pNode->m_pCollider)
{ {
int relation = this->m_pShape->getRelationWith(pNode->m_pShape); int relation = this->m_pCollider->getRelationWith(pNode->m_pCollider);
if ((relation != Relation::UNKNOWN) && if ((relation != Relation::UNKNOWN) &&
(relation != Relation::DISJOINT)) (relation != Relation::DISJOINT))
{ {
@ -945,10 +945,10 @@ bool e2d::Node::isIntersectWith(const Node * pNode) const
} }
else else
{ {
// 为节点创建一个临时形状 // 为节点创建一个临时碰撞体
ID2D1RectangleGeometry * pRect1; ID2D1RectangleGeometry * pRect1;
ID2D1RectangleGeometry * pRect2; ID2D1RectangleGeometry * pRect2;
ID2D1TransformedGeometry * pShape; ID2D1TransformedGeometry * pCollider;
D2D1_GEOMETRY_RELATION relation; D2D1_GEOMETRY_RELATION relation;
// 根据自身大小位置创建矩形 // 根据自身大小位置创建矩形
@ -960,7 +960,7 @@ bool e2d::Node::isIntersectWith(const Node * pNode) const
Renderer::getID2D1Factory()->CreateTransformedGeometry( Renderer::getID2D1Factory()->CreateTransformedGeometry(
pRect1, pRect1,
m_MatriFinal, m_MatriFinal,
&pShape &pCollider
); );
// 根据相比较节点的大小位置创建矩形 // 根据相比较节点的大小位置创建矩形
Renderer::getID2D1Factory()->CreateRectangleGeometry( Renderer::getID2D1Factory()->CreateRectangleGeometry(
@ -968,15 +968,15 @@ bool e2d::Node::isIntersectWith(const Node * pNode) const
&pRect2 &pRect2
); );
// 获取相交状态 // 获取相交状态
pShape->CompareWithGeometry( pCollider->CompareWithGeometry(
pRect2, pRect2,
pNode->m_MatriFinal, pNode->m_MatriFinal,
&relation &relation
); );
// 删除临时创建的形状 // 删除临时创建的碰撞体
SafeReleaseInterface(&pRect1); SafeReleaseInterface(&pRect1);
SafeReleaseInterface(&pRect2); SafeReleaseInterface(&pRect2);
SafeReleaseInterface(&pShape); SafeReleaseInterface(&pCollider);
if ((relation != D2D1_GEOMETRY_RELATION_UNKNOWN) && if ((relation != D2D1_GEOMETRY_RELATION_UNKNOWN) &&
(relation != D2D1_GEOMETRY_RELATION_DISJOINT)) (relation != D2D1_GEOMETRY_RELATION_DISJOINT))
{ {
@ -1009,9 +1009,9 @@ void e2d::Node::setDefaultPiovt(double defaultPiovtX, double defaultPiovtY)
s_fDefaultPiovtY = min(max(static_cast<float>(defaultPiovtY), 0), 1); s_fDefaultPiovtY = min(max(static_cast<float>(defaultPiovtY), 0), 1);
} }
void e2d::Node::setDefaultShapeEnable(bool bEnable) void e2d::Node::setDefaultColliderEnable(bool bEnable)
{ {
s_fDefaultShapeEnabled = bEnable; s_fDefaultColliderEnabled = bEnable;
} }
void e2d::Node::resumeAllActions() void e2d::Node::resumeAllActions()

View File

@ -0,0 +1,59 @@
#include "..\..\eshape.h"
e2d::Circle::Circle()
: m_fRadius(0)
{
this->setPivot(0.5, 0.5);
}
e2d::Circle::Circle(double radius)
{
this->setRadius(radius);
this->setPivot(0.5, 0.5);
}
e2d::Circle::Circle(Point center, double radius)
{
this->setRadius(radius);
this->setPos(center);
this->setPivot(0.5, 0.5);
}
e2d::Circle::Circle(double centerX, double centerY, double radius)
{
this->setRadius(radius);
this->setPos(centerX, centerY);
this->setPivot(0.5, 0.5);
}
e2d::Circle::~Circle()
{
}
double e2d::Circle::getRadius() const
{
return m_fRadius;
}
void e2d::Circle::setRadius(double radius)
{
m_fRadius = static_cast<float>(radius);
Node::setSize(radius * 2, radius * 2);
}
void e2d::Circle::_renderLine()
{
Renderer::getRenderTarget()->DrawEllipse(
D2D1::Ellipse(D2D1::Point2F(m_fRadius, m_fRadius), m_fRadius, m_fRadius),
Renderer::getSolidColorBrush(),
m_fStrokeWidth
);
}
void e2d::Circle::_renderFill()
{
Renderer::getRenderTarget()->FillEllipse(
D2D1::Ellipse(D2D1::Point2F(m_fRadius, m_fRadius), m_fRadius, m_fRadius),
Renderer::getSolidColorBrush()
);
}

View File

@ -0,0 +1,74 @@
#include "..\..\eshape.h"
e2d::Ellipse::Ellipse()
: m_fRadiusX(0)
, m_fRadiusY(0)
{
this->setPivot(0.5, 0.5);
}
e2d::Ellipse::Ellipse(double radiusX, double radiusY)
{
this->setRadiusX(radiusX);
this->setRadiusY(radiusY);
this->setPivot(0.5, 0.5);
}
e2d::Ellipse::Ellipse(Point center, double radiusX, double radiusY)
{
this->setRadiusX(radiusX);
this->setRadiusY(radiusY);
this->setPos(center);
this->setPivot(0.5, 0.5);
}
e2d::Ellipse::Ellipse(double centerX, double centerY, double radiusX, double radiusY)
{
this->setRadiusX(radiusX);
this->setRadiusY(radiusY);
this->setPos(centerX, centerY);
this->setPivot(0.5, 0.5);
}
e2d::Ellipse::~Ellipse()
{
}
double e2d::Ellipse::getRadiusX() const
{
return m_fRadiusX;
}
double e2d::Ellipse::getRadiusY() const
{
return m_fRadiusY;
}
void e2d::Ellipse::setRadiusX(double radiusX)
{
m_fRadiusX = static_cast<float>(radiusX);
Node::setWidth(radiusX * 2);
}
void e2d::Ellipse::setRadiusY(double radiusY)
{
m_fRadiusY = static_cast<float>(radiusY);
Node::setHeight(radiusY * 2);
}
void e2d::Ellipse::_renderLine()
{
Renderer::getRenderTarget()->DrawEllipse(
D2D1::Ellipse(D2D1::Point2F(m_fRadiusX, m_fRadiusY), m_fRadiusX, m_fRadiusY),
Renderer::getSolidColorBrush(),
m_fStrokeWidth
);
}
void e2d::Ellipse::_renderFill()
{
Renderer::getRenderTarget()->FillEllipse(
D2D1::Ellipse(D2D1::Point2F(m_fRadiusX, m_fRadiusY), m_fRadiusX, m_fRadiusY),
Renderer::getSolidColorBrush()
);
}

50
core/Node/Shape/Rect.cpp Normal file
View File

@ -0,0 +1,50 @@
#include "..\..\eshape.h"
e2d::Rect::Rect()
{
}
e2d::Rect::Rect(double width, double height)
{
this->setSize(width, height);
}
e2d::Rect::Rect(Size size)
{
this->setSize(size);
}
e2d::Rect::Rect(double top, double left, double width, double height)
{
this->setPivot(0, 0);
this->setPos(top, left);
this->setSize(width, height);
}
e2d::Rect::Rect(Point topLeft, Size size)
{
this->setPivot(0, 0);
this->setPos(topLeft);
this->setSize(size);
}
e2d::Rect::~Rect()
{
}
void e2d::Rect::_renderLine()
{
Renderer::getRenderTarget()->DrawRectangle(
D2D1::RectF(0, 0, m_fWidth, m_fHeight),
Renderer::getSolidColorBrush(),
m_fStrokeWidth
);
}
void e2d::Rect::_renderFill()
{
Renderer::getRenderTarget()->FillRectangle(
D2D1::RectF(0, 0, m_fWidth, m_fHeight),
Renderer::getSolidColorBrush()
);
}

View File

@ -0,0 +1,80 @@
#include "..\..\eshape.h"
e2d::RoundRect::RoundRect()
: m_fRadiusX(0)
, m_fRadiusY(0)
{
}
e2d::RoundRect::RoundRect(double width, double height, double radiusX, double radiusY)
: m_fRadiusX(static_cast<float>(radiusX))
, m_fRadiusY(static_cast<float>(radiusY))
{
this->setSize(width, height);
}
e2d::RoundRect::RoundRect(Size size, double radiusX, double radiusY)
: m_fRadiusX(static_cast<float>(radiusX))
, m_fRadiusY(static_cast<float>(radiusY))
{
this->setSize(size);
}
e2d::RoundRect::RoundRect(double top, double left, double width, double height, double radiusX, double radiusY)
: m_fRadiusX(static_cast<float>(radiusX))
, m_fRadiusY(static_cast<float>(radiusY))
{
this->setPivot(0, 0);
this->setPos(top, left);
this->setSize(width, height);
}
e2d::RoundRect::RoundRect(Point topLeft, Size size, double radiusX, double radiusY)
: m_fRadiusX(static_cast<float>(radiusX))
, m_fRadiusY(static_cast<float>(radiusY))
{
this->setPivot(0, 0);
this->setPos(topLeft);
this->setSize(size);
}
e2d::RoundRect::~RoundRect()
{
}
double e2d::RoundRect::getRadiusX() const
{
return m_fRadiusX;
}
double e2d::RoundRect::getRadiusY() const
{
return m_fRadiusY;
}
void e2d::RoundRect::setRadiusX(double radiusX)
{
m_fRadiusX = static_cast<float>(radiusX);
}
void e2d::RoundRect::setRadiusY(double radiusY)
{
m_fRadiusY = static_cast<float>(radiusY);
}
void e2d::RoundRect::_renderLine()
{
Renderer::getRenderTarget()->DrawRoundedRectangle(
D2D1::RoundedRect(D2D1::RectF(0, 0, m_fWidth, m_fHeight), m_fRadiusX, m_fRadiusY),
Renderer::getSolidColorBrush(),
m_fStrokeWidth
);
}
void e2d::RoundRect::_renderFill()
{
Renderer::getRenderTarget()->FillRoundedRectangle(
D2D1::RoundedRect(D2D1::RectF(0, 0, m_fWidth, m_fHeight), m_fRadiusX, m_fRadiusY),
Renderer::getSolidColorBrush()
);
}

86
core/Node/Shape/Shape.cpp Normal file
View File

@ -0,0 +1,86 @@
#include "..\..\eshape.h"
e2d::Shape::Shape()
: m_nStyle(ShapeStyle::SOLID)
, m_nFillColor(Color::WHITE)
, m_nLineColor(Color::BLUE)
, m_fStrokeWidth(1)
{
}
e2d::Shape::~Shape()
{
}
void e2d::Shape::onRender()
{
switch (m_nStyle)
{
case ShapeStyle::FILL:
{
Renderer::getSolidColorBrush()->SetColor(D2D1::ColorF(m_nFillColor, m_fDisplayOpacity));
this->_renderFill();
Renderer::getSolidColorBrush()->SetColor(D2D1::ColorF(m_nLineColor, m_fDisplayOpacity));
this->_renderLine();
break;
}
case ShapeStyle::ROUND:
{
Renderer::getSolidColorBrush()->SetColor(D2D1::ColorF(m_nLineColor, m_fDisplayOpacity));
this->_renderLine();
break;
}
case ShapeStyle::SOLID:
{
Renderer::getSolidColorBrush()->SetColor(D2D1::ColorF(m_nFillColor, m_fDisplayOpacity));
this->_renderFill();
break;
}
default:
break;
}
}
UINT32 e2d::Shape::getFillColor() const
{
return m_nFillColor;
}
UINT32 e2d::Shape::getLineColor() const
{
return m_nLineColor;
}
double e2d::Shape::getStrokeWidth() const
{
return m_fStrokeWidth;
}
int e2d::Shape::getStyle() const
{
return m_nStyle;
}
void e2d::Shape::setFillColor(UINT32 fillColor)
{
m_nFillColor = fillColor;
}
void e2d::Shape::setLineColor(UINT32 lineColor)
{
m_nLineColor = lineColor;
}
void e2d::Shape::setStrokeWidth(double strokeWidth)
{
m_fStrokeWidth = static_cast<float>(strokeWidth);
}
void e2d::Shape::setStyle(int style)
{
m_nStyle = style;
}

View File

@ -1,4 +1,4 @@
#include "..\enodes.h" #include "..\enode.h"
e2d::Sprite::Sprite() e2d::Sprite::Sprite()

View File

@ -1,4 +1,4 @@
#include "..\enodes.h" #include "..\enode.h"
e2d::Text::Text() e2d::Text::Text()

View File

@ -1,109 +0,0 @@
#include "..\eshape.h"
#include "..\emanagers.h"
#include "..\enodes.h"
e2d::ShapeBase::ShapeBase()
: m_bIsVisiable(true)
, m_nColor(Color::RED)
, m_fOpacity(1)
, m_pParentNode(nullptr)
, m_pTransformedShape(nullptr)
, m_bEnable(true)
, m_bAutoResize(true)
{
}
e2d::ShapeBase::~ShapeBase()
{
SafeReleaseInterface(&m_pTransformedShape);
}
e2d::Node * e2d::ShapeBase::getParentNode() const
{
return m_pParentNode;
}
void e2d::ShapeBase::setEnable(bool bEnable)
{
m_bEnable = bEnable;
}
void e2d::ShapeBase::setVisiable(bool bVisiable)
{
m_bIsVisiable = bVisiable;
}
void e2d::ShapeBase::setColor(UINT32 color)
{
m_nColor = color;
}
void e2d::ShapeBase::setOpacity(double opacity)
{
m_fOpacity = min(max(static_cast<float>(opacity), 0), 1);
}
void e2d::ShapeBase::setAutoResize(bool bEnable)
{
m_bAutoResize = bEnable;
}
void e2d::ShapeBase::_render()
{
if (m_pTransformedShape && m_bEnable)
{
ID2D1SolidColorBrush * pBrush = Renderer::getSolidColorBrush();
// 눼쉔뺌岬
Renderer::getRenderTarget()->CreateSolidColorBrush(
D2D1::ColorF(
m_nColor,
m_fOpacity),
&pBrush
);
// 삥齡섯부近榴
Renderer::getRenderTarget()->DrawGeometry(m_pTransformedShape, pBrush);
}
}
int e2d::ShapeBase::getRelationWith(ShapeBase * pShape) const
{
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 Relation::UNKNOWN;
}
void e2d::ShapeBase::_transform()
{
if (m_pParentNode && m_bEnable)
{
if (m_bAutoResize)
{
this->_resize();
}
// 姦렴覩近榴
SafeReleaseInterface(&m_pTransformedShape);
// 몽앴만쌘듐瘻뻣섯부暠近
Renderer::getID2D1Factory()->CreateTransformedGeometry(
getD2dGeometry(),
m_pParentNode->m_MatriFinal,
&m_pTransformedShape
);
CollisionManager::__updateShape(this);
}
}

View File

@ -1,61 +0,0 @@
#include "..\eshape.h"
#include "..\enodes.h"
e2d::ShapeRectangle::ShapeRectangle()
: m_pD2dRectangle(nullptr)
{
}
e2d::ShapeRectangle::ShapeRectangle(double x, double y, double width, double height)
: m_pD2dRectangle(nullptr)
{
this->setRect(x, y, x + width, y + height);
}
e2d::ShapeRectangle::ShapeRectangle(Node * node)
: m_pD2dRectangle(nullptr)
{
this->setRect(
0,
0,
node->getRealWidth(),
node->getRealHeight()
);
}
e2d::ShapeRectangle::~ShapeRectangle()
{
SafeReleaseInterface(&m_pD2dRectangle);
}
void e2d::ShapeRectangle::setRect(double left, double top, double right, double bottom)
{
SafeReleaseInterface(&m_pD2dRectangle);
Renderer::getID2D1Factory()->CreateRectangleGeometry(
D2D1::RectF(
static_cast<float>(left),
static_cast<float>(top),
static_cast<float>(right),
static_cast<float>(bottom)),
&m_pD2dRectangle
);
}
void e2d::ShapeRectangle::_resize()
{
if (m_pParentNode && m_bEnable)
{
this->setRect(
0,
0,
m_pParentNode->getRealWidth(),
m_pParentNode->getRealHeight()
);
}
}
ID2D1RectangleGeometry * e2d::ShapeRectangle::getD2dGeometry() const
{
return m_pD2dRectangle;
}

View File

@ -1,24 +1,24 @@
#include "..\etools.h" #include "..\etool.h"
#include "..\emanagers.h" #include "..\emanager.h"
e2d::CollisionListener::CollisionListener() e2d::CollisionListener::CollisionListener()
: Listener() : Listener()
{ {
CollisionManager::__add(this); ColliderManager::__add(this);
} }
e2d::CollisionListener::CollisionListener(Function func) e2d::CollisionListener::CollisionListener(Function func)
: Listener() : Listener()
, m_callback(func) , m_callback(func)
{ {
CollisionManager::__add(this); ColliderManager::__add(this);
} }
e2d::CollisionListener::CollisionListener(Function func, String name) e2d::CollisionListener::CollisionListener(Function func, String name)
: Listener(name) : Listener(name)
, m_callback(func) , m_callback(func)
{ {
CollisionManager::__add(this); ColliderManager::__add(this);
} }
void e2d::CollisionListener::_update() void e2d::CollisionListener::_update()

View File

@ -1,4 +1,4 @@
#include "..\etools.h" #include "..\etool.h"
static e2d::String s_sDefaultFileName = L"DefaultData.ini"; static e2d::String s_sDefaultFileName = L"DefaultData.ini";

View File

@ -1,5 +1,5 @@
#include "..\etools.h" #include "..\etool.h"
#include "..\emanagers.h" #include "..\emanager.h"
e2d::InputListener::InputListener() e2d::InputListener::InputListener()
: Listener() : Listener()

View File

@ -1,4 +1,4 @@
#include "..\etools.h" #include "..\etool.h"
e2d::Listener::Listener() e2d::Listener::Listener()
: m_bRunning(false) : m_bRunning(false)

View File

@ -1,5 +1,5 @@
#include "..\etools.h" #include "..\etool.h"
#include "..\emanagers.h" #include "..\emanager.h"
using namespace e2d; using namespace e2d;

View File

@ -1,4 +1,4 @@
#include "..\etools.h" #include "..\etool.h"
#include <algorithm> #include <algorithm>
#include <commdlg.h> #include <commdlg.h>

View File

@ -1,4 +1,4 @@
#include "..\etools.h" #include "..\etool.h"
std::default_random_engine &e2d::Random::getEngine() std::default_random_engine &e2d::Random::getEngine()
{ {

View File

@ -1,6 +1,6 @@
#include "..\etools.h" #include "..\etool.h"
#include "..\enodes.h" #include "..\enode.h"
#include "..\emanagers.h" #include "..\emanager.h"
e2d::Timer::Timer(Function func, String name, double interval /* = 0 */, int updateTimes /* = -1 */, bool atOnce /* = false */, bool autoRelease /* = false */) e2d::Timer::Timer(Function func, String name, double interval /* = 0 */, int updateTimes /* = -1 */, bool atOnce /* = false */, bool autoRelease /* = false */)
: m_bRunning(false) : m_bRunning(false)

View File

@ -1,5 +1,5 @@
#include "..\ebase.h" #include "..\ebase.h"
#include "..\etransitions.h" #include "..\etransition.h"
e2d::Transition::Transition(double duration) e2d::Transition::Transition(double duration)
: m_bEnd(false) : m_bEnd(false)

View File

@ -1,5 +1,5 @@
#include "..\etransitions.h" #include "..\etransition.h"
#include "..\enodes.h" #include "..\enode.h"
e2d::TransitionEmerge::TransitionEmerge(double duration) e2d::TransitionEmerge::TransitionEmerge(double duration)
: Transition(duration) : Transition(duration)

View File

@ -1,5 +1,5 @@
#include "..\etransitions.h" #include "..\etransition.h"
#include "..\enodes.h" #include "..\enode.h"
e2d::TransitionFade::TransitionFade(double fadeOutDuration, double fadeInDuration) e2d::TransitionFade::TransitionFade(double fadeOutDuration, double fadeInDuration)
: Transition(0) : Transition(0)

View File

@ -1,5 +1,5 @@
#include "..\etransitions.h" #include "..\etransition.h"
#include "..\enodes.h" #include "..\enode.h"
e2d::TransitionMove::TransitionMove(double duration, MOVE_DIRECT direct) e2d::TransitionMove::TransitionMove(double duration, MOVE_DIRECT direct)
: Transition(duration) : Transition(duration)

View File

@ -1,5 +1,5 @@
#pragma once #pragma once
#include "enodes.h" #include "enode.h"
namespace e2d namespace e2d
{ {

View File

@ -20,12 +20,13 @@
#include "emacros.h" #include "emacros.h"
#include "ecommon.h" #include "ecommon.h"
#include "ebase.h" #include "ebase.h"
#include "emanagers.h" #include "emanager.h"
#include "enodes.h" #include "enode.h"
#include "etools.h"
#include "eactions.h"
#include "etransitions.h"
#include "eshape.h" #include "eshape.h"
#include "etool.h"
#include "eaction.h"
#include "etransition.h"
#include "ecollider.h"
#if defined(DEBUG) || defined(_DEBUG) #if defined(DEBUG) || defined(_DEBUG)

202
core/ecollider.h Normal file
View File

@ -0,0 +1,202 @@
#pragma once
#include "ebase.h"
namespace e2d
{
class ColliderManager;
// 碰撞体
class Collider :
public Object
{
friend ColliderManager;
friend Node;
public:
Collider();
virtual ~Collider();
// 判断两碰撞体的交集关系
virtual int getRelationWith(
Collider * pCollider
) const;
// 获取父节点
Node * getParentNode() const;
// 启用或关闭该碰撞体
virtual void setEnable(
bool bEnable
);
// 设置碰撞体的可见性
void setVisiable(
bool bVisiable
);
// 设置绘制颜色
void setColor(
UINT32 color
);
// 设置绘制透明度
void setOpacity(
double opacity
);
// 设置大小跟随
void setAutoResize(
bool bEnable
);
// 获取 ID2D1Geometry 对象
virtual ID2D1Geometry * getD2dGeometry() const = 0;
protected:
// 转换碰撞体
virtual void _transform();
// 重设大小
virtual void _resize() = 0;
// 渲染碰撞体
virtual void _render();
protected:
bool m_bEnable;
bool m_bIsVisiable;
bool m_bAutoResize;
UINT32 m_nColor;
float m_fOpacity;
Node * m_pParentNode;
ID2D1TransformedGeometry * m_pTransformedGeometry;
};
// 矩形
class ColliderRect :
public Collider
{
public:
// 创建一个默认矩形
ColliderRect();
// 根据左上角坐标和宽高创建矩形
ColliderRect(
double x,
double y,
double width,
double height
);
// 创建一个和节点位置大小相同的矩形
ColliderRect(
Node * node
);
virtual ~ColliderRect();
// 修改矩形大小
void setRect(
double left,
double top,
double right,
double bottom
);
// 获取 ID2D1Geometry 对象
virtual ID2D1RectangleGeometry * getD2dGeometry() const override;
protected:
// 重设大小
virtual void _resize();
protected:
ID2D1RectangleGeometry * m_pD2dRectangle;
};
// 圆形
class ColliderCircle :
public Collider
{
public:
// 创建一个默认圆形
ColliderCircle();
// 根据圆心和半径创建圆形
ColliderCircle(
Point center,
double radius
);
// 创建一个和节点位置大小相同的圆形
ColliderCircle(
Node * node
);
virtual ~ColliderCircle();
// 修改圆形大小
void setCircle(
Point center,
double radius
);
// 获取 ID2D1Geometry 对象
virtual ID2D1EllipseGeometry * getD2dGeometry() const override;
protected:
// 重设大小
virtual void _resize();
protected:
ID2D1EllipseGeometry * m_pD2dCircle;
};
// 椭圆形
class ColliderEllipse :
public Collider
{
public:
// 创建一个默认椭圆
ColliderEllipse();
// 根据圆心和半径创建椭圆
ColliderEllipse(
Point center,
double radiusX,
double radiusY
);
// 创建一个和节点位置大小相同的椭圆
ColliderEllipse(
Node * node
);
virtual ~ColliderEllipse();
// 修改椭圆大小
void setEllipse(
Point center,
double radiusX,
double radiusY
);
// 获取 ID2D1Geometry 对象
virtual ID2D1EllipseGeometry * getD2dGeometry() const override;
protected:
// 重设大小
virtual void _resize();
protected:
ID2D1EllipseGeometry * m_pD2dEllipse;
};
}

View File

@ -75,7 +75,7 @@ struct Size
// 字符串 // 字符串
class String class String final
{ {
public: public:
String(); String();
@ -137,6 +137,7 @@ public:
// 数字类型转字符串 // 数字类型转字符串
static String parse(int value); static String parse(int value);
static String parse(unsigned int value);
static String parse(float value); static String parse(float value);
static String parse(double value); static String parse(double value);
@ -184,6 +185,7 @@ public:
String& operator<< (const wchar_t *); String& operator<< (const wchar_t *);
String& operator<< (wchar_t *); String& operator<< (wchar_t *);
String& operator<< (int value); String& operator<< (int value);
String& operator<< (unsigned int value);
String& operator<< (float value); String& operator<< (float value);
String& operator<< (double value); String& operator<< (double value);
@ -379,7 +381,7 @@ public:
}; };
// 形状交集关系 // 碰撞体交集关系
class Relation class Relation
{ {
public: public:
@ -394,13 +396,26 @@ public:
}; };
// 形状类别 // 形状样式
class Shape class ShapeStyle
{ {
public: public:
enum : int enum : int
{ {
RECTANGLE, /* 矩形 */ SOLID, /* 填充 */
ROUND, /* 轮廓 */
FILL, /* 轮廓 + 填充 */
};
};
// 碰撞体类别
class ColliderType
{
public:
enum : int
{
RECT, /* 矩形 */
CIRCLE, /* 圆形 */ CIRCLE, /* 圆形 */
ELLIPSE /* 椭圆形 */ ELLIPSE /* 椭圆形 */
}; };
@ -565,7 +580,10 @@ public:
virtual void onExit() {} virtual void onExit() {}
// 重写这个函数,它将在碰撞发生时自动执行 // 重写这个函数,它将在碰撞发生时自动执行
virtual void onCollide() {} virtual void onCollide(
Node* pActiveNode, /* 碰撞发生时的主动体 */
Node* pPassiveNode /* 碰撞发生时的被动体 */
) {}
// 重写这个函数,它将在关闭窗口时执行(返回 false 将阻止窗口关闭) // 重写这个函数,它将在关闭窗口时执行(返回 false 将阻止窗口关闭)
virtual bool onCloseWindow() { return true; } virtual bool onCloseWindow() { return true; }
@ -601,7 +619,7 @@ public:
Node * getRoot() const; Node * getRoot() const;
// 开启或关闭节点轮廓渲染 // 开启或关闭节点轮廓渲染
void showOutline( void showCollider(
bool visiable = true bool visiable = true
); );
@ -616,7 +634,7 @@ protected:
bool m_bAutoUpdate; bool m_bAutoUpdate;
bool m_bSortNeeded; bool m_bSortNeeded;
bool m_bWillSave; bool m_bWillSave;
bool m_bShapeVisiable; bool m_bColliderVisiable;
Node * m_pRoot; Node * m_pRoot;
}; };

View File

@ -12,13 +12,13 @@ class Node;
class Timer; class Timer;
class Action; class Action;
class Music; class Music;
class ShapeBase; class Collider;
class Transition; class Transition;
class InputListener; class InputListener;
class CollisionListener; class CollisionListener;
// 对象管理器 // 对象管理器
class ObjectManager class ObjectManager final
{ {
friend Game; friend Game;
@ -41,7 +41,7 @@ private:
// 场景管理器 // 场景管理器
class SceneManager class SceneManager final
{ {
friend Game; friend Game;
friend Renderer; friend Renderer;
@ -87,7 +87,7 @@ private:
// 定时器管理器 // 定时器管理器
class TimerManager class TimerManager final
{ {
friend Game; friend Game;
friend Node; friend Node;
@ -150,7 +150,7 @@ private:
// 动作管理器 // 动作管理器
class ActionManager class ActionManager final
{ {
friend Game; friend Game;
friend Node; friend Node;
@ -235,7 +235,7 @@ private:
// 音乐管理工具 // 音乐管理工具
class MusicManager class MusicManager final
{ {
friend Game; friend Game;
@ -305,7 +305,7 @@ private:
// 键盘和鼠标消息管理器 // 键盘和鼠标消息管理器
class InputManager class InputManager final
{ {
friend Input; friend Input;
friend InputListener; friend InputListener;
@ -361,10 +361,10 @@ private:
// 碰撞管理器 // 碰撞管理器
class CollisionManager class ColliderManager final
{ {
friend Node; friend Node;
friend ShapeBase; friend Collider;
friend CollisionListener; friend CollisionListener;
public: public:
@ -411,6 +411,12 @@ public:
// 获取全部监听器 // 获取全部监听器
static std::vector<CollisionListener*> getAll(); static std::vector<CollisionListener*> getAll();
// 获取碰撞发生时的主动体
static Node * getActiveNode();
// 获取碰撞发生时的被动体
static Node * getPassiveNode();
// 判断碰撞是否由该节点引发(如果是,返回与其相撞的节点指针,否则返回空) // 判断碰撞是否由该节点引发(如果是,返回与其相撞的节点指针,否则返回空)
static Node * isCausedBy( static Node * isCausedBy(
Node * pNode Node * pNode
@ -430,19 +436,19 @@ private:
// 更新监听器 // 更新监听器
static void __update(); static void __update();
// 更新形状 // 更新碰撞体
static void __updateShape( static void __updateCollider(
ShapeBase * pActiveShape Collider * pActiveCollider
); );
// 添加形状 // 添加碰撞体
static void __addShape( static void __addCollider(
ShapeBase * pShape Collider * pCollider
); );
// 删除已绑定的形状 // 删除已绑定的碰撞体
static void __removeShape( static void __removeCollider(
ShapeBase * pShape Collider * pCollider
); );
}; };

View File

@ -7,16 +7,16 @@ namespace e2d
class Action; class Action;
class Transition; class Transition;
class ShapeBase; class Collider;
class CollisionManager; class ColliderManager;
class Node : class Node :
public Object public Object
{ {
friend Scene; friend Scene;
friend ShapeBase; friend Collider;
friend Transition; friend Transition;
friend CollisionManager; friend ColliderManager;
public: public:
Node(); Node();
@ -116,8 +116,8 @@ public:
// 获取节点透明度 // 获取节点透明度
virtual double getOpacity() const; virtual double getOpacity() const;
// 获取节点形状 // 获取节点碰撞体
virtual ShapeBase * getShape() const; virtual Collider * getCollider() const;
// 获取父节点 // 获取父节点
virtual Node * getParent() const; virtual Node * getParent() const;
@ -291,50 +291,50 @@ public:
); );
// 修改节点宽度 // 修改节点宽度
void setWidth( virtual void setWidth(
double width double width
); );
// 修改节点高度 // 修改节点高度
void setHeight( virtual void setHeight(
double height double height
); );
// 修改节点大小 // 修改节点大小
void setSize( virtual void setSize(
double width, double width,
double height double height
); );
// 修改节点大小 // 修改节点大小
void setSize( virtual void setSize(
Size size Size size
); );
// 设置节点形状 // 设置碰撞体
virtual void setShape( virtual void setCollider(
int type int nColliderType
); );
// 设置节点形状 // 设置碰撞体
virtual void setShape( virtual void setCollider(
ShapeBase * pShape Collider * pCollider
); );
// 添加可碰撞节点的名称 // 添加可碰撞节点的名称
virtual void addCollider( virtual void addColliableName(
String collliderName String collliderName
); );
#if HIGHER_THAN_VS2012 #if HIGHER_THAN_VS2012
// 添加多个可碰撞节点的名称 // 添加多个可碰撞节点的名称
virtual void addCollider( virtual void addColliableName(
const InitList<String>& vCollliderName /* 名称数组 */ const InitList<String>& vCollliderName /* 名称数组 */
); );
#endif #endif
// 移除可碰撞节点的名称 // 移除可碰撞节点的名称
virtual void removeCollider( virtual void removeColliableName(
String collliderName String collliderName
); );
@ -397,8 +397,8 @@ public:
double defaultPiovtY double defaultPiovtY
); );
// 设置节点是否包含默认形状(默认打开) // 设置节点是否包含默认碰撞体(默认打开)
static void setDefaultShapeEnable( static void setDefaultColliderEnable(
bool bEnable bool bEnable
); );
@ -410,7 +410,7 @@ protected:
void _render(); void _render();
// 渲染图形 // 渲染图形
void _drawShape(); void _drawCollider();
// 节点被添加到场景时的执行程序 // 节点被添加到场景时的执行程序
void _onEnter(); void _onEnter();
@ -460,7 +460,7 @@ protected:
bool m_bDisplayedInScene; bool m_bDisplayedInScene;
bool m_bSortChildrenNeeded; bool m_bSortChildrenNeeded;
bool m_bTransformNeeded; bool m_bTransformNeeded;
ShapeBase * m_pShape; Collider * m_pCollider;
Scene * m_pParentScene; Scene * m_pParentScene;
Node * m_pParent; Node * m_pParent;
D2D1::Matrix3x2F m_MatriInitial; D2D1::Matrix3x2F m_MatriInitial;
@ -885,12 +885,19 @@ public:
// 创建空菜单 // 创建空菜单
Menu(); Menu();
#if HIGHER_THAN_VS2012
// 创建菜单
Menu(
const InitList<Button*>& vButtons /* 按钮数组 */
);
#else
// 创建菜单 // 创建菜单
Menu( Menu(
int number, /* 菜单中按钮的数量 */ int number, /* 菜单中按钮的数量 */
Button * button1, /* 第一个按钮 */ Button * button1, /* 第一个按钮 */
... ...
); );
#endif
// 获取菜单是否禁用 // 获取菜单是否禁用
bool isEnable() const; bool isEnable() const;

View File

@ -1,202 +1,290 @@
#pragma once #pragma once
#include "ebase.h" #include "enode.h"
namespace e2d namespace e2d
{ {
class CollisionManager;
// ĐÎ×´ // ĐÎ×´
class ShapeBase : class Shape :
public Object public Node
{ {
friend CollisionManager;
friend Node;
public: public:
ShapeBase(); Shape();
virtual ~ShapeBase(); virtual ~Shape();
// 判断两形状的交集关系 // 获取样式
virtual int getRelationWith( int getStyle() const;
ShapeBase * pShape
) const;
// 获取父节点 // 获取填充颜色
Node * getParentNode() const; UINT32 getFillColor() const;
// 启用或关闭该形状 // 获取线条颜色
virtual void setEnable( UINT32 getLineColor() const;
bool bEnable
// 获取线条宽度
double getStrokeWidth() const;
// 设置填充颜色
void setFillColor(
UINT32 fillColor
); );
// 设置形状的可见性 // 设置线条颜色
void setVisiable( void setLineColor(
bool bVisiable UINT32 lineColor
); );
// 设置绘制颜色 // 设置线条宽度
void setColor( void setStrokeWidth(
UINT32 color double strokeWidth
); );
// 设置绘制透明度 // 设置样式
void setOpacity( void setStyle(int style);
double opacity
);
// 设置大小跟随
void setAutoResize(
bool bEnable
);
// 获取 ID2D1Geometry 对象
virtual ID2D1Geometry * getD2dGeometry() const = 0;
protected:
// 转换形状
virtual void _transform();
// 重设大小
virtual void _resize() = 0;
// äÖČžĐÎ×´ // äÖČžĐÎ×´
virtual void _render(); virtual void onRender() override;
protected: protected:
bool m_bEnable; // 渲染轮廓
bool m_bIsVisiable; virtual void _renderLine() = 0;
bool m_bAutoResize;
UINT32 m_nColor; // 渲染填充色
float m_fOpacity; virtual void _renderFill() = 0;
Node * m_pParentNode;
ID2D1TransformedGeometry * m_pTransformedShape; protected:
int m_nStyle;
float m_fStrokeWidth;
UINT32 m_nLineColor;
UINT32 m_nFillColor;
}; };
// žŘĐÎ // žŘĐÎ
class ShapeRectangle : class Rect :
public ShapeBase public Shape
{ {
public: public:
// 创建一个默认矩形 Rect();
ShapeRectangle();
// 根据左上角坐标和宽高创建矩形 Rect(
ShapeRectangle( double width, /* 宽度 */
double x, double height /* 高度 */
double y,
double width,
double height
); );
// 创建一个和节点位置大小相同的矩形 Rect(
ShapeRectangle( Size size /* 宽度和高度 */
Node * node
); );
virtual ~ShapeRectangle(); Rect(
double top, /* 左上角横坐标 */
// 修改矩形大小 double left, /* 左上角纵坐标 */
void setRect( double width, /* 宽度 */
double left, double height /* 高度 */
double top,
double right,
double bottom
); );
// 获取 ID2D1Geometry 对象 Rect(
virtual ID2D1RectangleGeometry * getD2dGeometry() const override; Point topLeft, /* 左上角坐标 */
Size size /* 宽度和高度 */
);
virtual ~Rect();
protected: protected:
// 重设大小 // 渲染轮廓
virtual void _resize(); virtual void _renderLine() override;
// 渲染填充色
virtual void _renderFill() override;
};
// 圆角矩形
class RoundRect :
public Shape
{
public:
RoundRect();
RoundRect(
double width, /* 宽度 */
double height, /* 高度 */
double radiusX, /* 圆角半径 */
double radiusY /* 圆角半径 */
);
RoundRect(
Size size, /* 宽度和高度 */
double radiusX, /* 圆角半径 */
double radiusY /* 圆角半径 */
);
RoundRect(
double top, /* 左上角横坐标 */
double left, /* 左上角纵坐标 */
double width, /* 宽度 */
double height, /* 高度 */
double radiusX, /* 圆角半径 */
double radiusY /* 圆角半径 */
);
RoundRect(
Point topLeft, /* 左上角坐标 */
Size size, /* 宽度和高度 */
double radiusX, /* 圆角半径 */
double radiusY /* 圆角半径 */
);
virtual ~RoundRect();
// 获取圆角半径
double getRadiusX() const;
// 获取圆角半径
double getRadiusY() const;
// 设置圆角半径
virtual void setRadiusX(
double radiusX
);
// 设置圆角半径
virtual void setRadiusY(
double radiusY
);
protected: protected:
ID2D1RectangleGeometry * m_pD2dRectangle; // 渲染轮廓
virtual void _renderLine() override;
// 渲染填充色
virtual void _renderFill() override;
protected:
float m_fRadiusX;
float m_fRadiusY;
}; };
// Ô˛ĐÎ // Ô˛ĐÎ
class ShapeCircle : class Circle :
public ShapeBase public Shape
{ {
public: public:
// 创建一个默认圆形 Circle();
ShapeCircle();
// 根据圆心和半径创建圆形 Circle(
ShapeCircle( double radius /* 半径 */
Point center, );
Circle(
Point center, /* 圆心坐标 */
double radius /* 半径 */
);
Circle(
double centerX, /* 圆心横坐标 */
double centerY, /* 圆心纵坐标 */
double radius /* 半径 */
);
virtual ~Circle();
// 获取半径
double getRadius() const;
// 设置半径
virtual void setRadius(
double radius double radius
); );
// 创建一个和节点位置大小相同的圆形 public:
ShapeCircle( // 禁用的函数
Node * node void setWidth() {}
);
virtual ~ShapeCircle(); // 禁用的函数
void setHeight() {}
// 修改圆形大小 // 禁用的函数
void setCircle( void setSize() {}
Point center,
double radius
);
// 获取 ID2D1Geometry 对象
virtual ID2D1EllipseGeometry * getD2dGeometry() const override;
protected: protected:
// 重设大小 // 渲染轮廓
virtual void _resize(); virtual void _renderLine() override;
// 渲染填充色
virtual void _renderFill() override;
protected: protected:
ID2D1EllipseGeometry * m_pD2dCircle; float m_fRadius;
}; };
// ÍÖÔ˛ĐÎ // ÍÖÔ˛ĐÎ
class ShapeEllipse : class Ellipse :
public ShapeBase public Shape
{ {
public: public:
// 创建一个默认椭圆 Ellipse();
ShapeEllipse();
// 根据圆心和半径创建椭圆 Ellipse(
ShapeEllipse( double radiusX, /* 横轴半径 */
Point center, double radiusY /* 纵轴半径 */
double radiusX, );
Ellipse(
Point center, /* 圆心坐标 */
double radiusX, /* 横轴半径 */
double radiusY /* 纵轴半径 */
);
Ellipse(
double centerX, /* 圆心横坐标 */
double centerY, /* 圆心纵坐标 */
double radiusX, /* 横轴半径 */
double radiusY /* 纵轴半径 */
);
virtual ~Ellipse();
// 获取横轴半径
double getRadiusX() const;
// 获取纵轴半径
double getRadiusY() const;
// 设置横轴半径
virtual void setRadiusX(
double radiusX
);
// 设置纵轴半径
virtual void setRadiusY(
double radiusY double radiusY
); );
// 创建一个和节点位置大小相同的椭圆 public:
ShapeEllipse( // 禁用的函数
Node * node void setWidth() {}
);
virtual ~ShapeEllipse(); // 禁用的函数
void setHeight() {}
// 修改椭圆大小 // 禁用的函数
void setEllipse( void setSize() {}
Point center,
double radiusX,
double radiusY
);
// 获取 ID2D1Geometry 对象
virtual ID2D1EllipseGeometry * getD2dGeometry() const override;
protected: protected:
// 重设大小 // 渲染轮廓
virtual void _resize(); virtual void _renderLine() override;
// 渲染填充色
virtual void _renderFill() override;
protected: protected:
ID2D1EllipseGeometry * m_pD2dEllipse; float m_fRadiusX;
float m_fRadiusY;
}; };
} }

View File

@ -8,7 +8,7 @@ namespace e2d
class TimerManager; class TimerManager;
class MusicManager; class MusicManager;
class InputManager; class InputManager;
class CollisionManager; class ColliderManager;
// 随机数产生器 // 随机数产生器
class Random class Random
@ -196,7 +196,7 @@ protected:
class CollisionListener class CollisionListener
: public Listener : public Listener
{ {
friend CollisionManager; friend ColliderManager;
public: public:
CollisionListener(); CollisionListener();

View File

@ -211,6 +211,10 @@
<ClCompile Include="..\..\core\Base\Renderer.cpp" /> <ClCompile Include="..\..\core\Base\Renderer.cpp" />
<ClCompile Include="..\..\core\Base\Time.cpp" /> <ClCompile Include="..\..\core\Base\Time.cpp" />
<ClCompile Include="..\..\core\Base\Window.cpp" /> <ClCompile Include="..\..\core\Base\Window.cpp" />
<ClCompile Include="..\..\core\Collider\Collider.cpp" />
<ClCompile Include="..\..\core\Collider\ColliderCircle.cpp" />
<ClCompile Include="..\..\core\Collider\ColliderEllipse.cpp" />
<ClCompile Include="..\..\core\Collider\ColliderRect.cpp" />
<ClCompile Include="..\..\core\Common\Font.cpp" /> <ClCompile Include="..\..\core\Common\Font.cpp" />
<ClCompile Include="..\..\core\Common\Object.cpp" /> <ClCompile Include="..\..\core\Common\Object.cpp" />
<ClCompile Include="..\..\core\Common\Point.cpp" /> <ClCompile Include="..\..\core\Common\Point.cpp" />
@ -222,19 +226,20 @@
<ClCompile Include="..\..\core\Manager\InputManager.cpp" /> <ClCompile Include="..\..\core\Manager\InputManager.cpp" />
<ClCompile Include="..\..\core\Manager\MusicManager.cpp" /> <ClCompile Include="..\..\core\Manager\MusicManager.cpp" />
<ClCompile Include="..\..\core\Manager\ObjectManager.cpp" /> <ClCompile Include="..\..\core\Manager\ObjectManager.cpp" />
<ClCompile Include="..\..\core\Manager\CollisionManager.cpp" /> <ClCompile Include="..\..\core\Manager\ColliderManager.cpp" />
<ClCompile Include="..\..\core\Manager\SceneManager.cpp" /> <ClCompile Include="..\..\core\Manager\SceneManager.cpp" />
<ClCompile Include="..\..\core\Manager\TimerManager.cpp" /> <ClCompile Include="..\..\core\Manager\TimerManager.cpp" />
<ClCompile Include="..\..\core\Node\Button.cpp" /> <ClCompile Include="..\..\core\Node\Button.cpp" />
<ClCompile Include="..\..\core\Node\ButtonToggle.cpp" /> <ClCompile Include="..\..\core\Node\ButtonToggle.cpp" />
<ClCompile Include="..\..\core\Node\Menu.cpp" /> <ClCompile Include="..\..\core\Node\Menu.cpp" />
<ClCompile Include="..\..\core\Node\Node.cpp" /> <ClCompile Include="..\..\core\Node\Node.cpp" />
<ClCompile Include="..\..\core\Node\Shape\Circle.cpp" />
<ClCompile Include="..\..\core\Node\Shape\Ellipse.cpp" />
<ClCompile Include="..\..\core\Node\Shape\Rect.cpp" />
<ClCompile Include="..\..\core\Node\Shape\RoundRect.cpp" />
<ClCompile Include="..\..\core\Node\Shape\Shape.cpp" />
<ClCompile Include="..\..\core\Node\Sprite.cpp" /> <ClCompile Include="..\..\core\Node\Sprite.cpp" />
<ClCompile Include="..\..\core\Node\Text.cpp" /> <ClCompile Include="..\..\core\Node\Text.cpp" />
<ClCompile Include="..\..\core\Shape\ShapeBase.cpp" />
<ClCompile Include="..\..\core\Shape\ShapeCircle.cpp" />
<ClCompile Include="..\..\core\Shape\ShapeEllipse.cpp" />
<ClCompile Include="..\..\core\Shape\ShapeRectangle.cpp" />
<ClCompile Include="..\..\core\Tool\CollisionListener.cpp" /> <ClCompile Include="..\..\core\Tool\CollisionListener.cpp" />
<ClCompile Include="..\..\core\Tool\Data.cpp" /> <ClCompile Include="..\..\core\Tool\Data.cpp" />
<ClCompile Include="..\..\core\Tool\InputListener.cpp" /> <ClCompile Include="..\..\core\Tool\InputListener.cpp" />
@ -249,16 +254,17 @@
<ClCompile Include="..\..\core\Transition\TransitionMove.cpp" /> <ClCompile Include="..\..\core\Transition\TransitionMove.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\core\eactions.h" /> <ClInclude Include="..\..\core\eaction.h" />
<ClInclude Include="..\..\core\easy2d.h" /> <ClInclude Include="..\..\core\easy2d.h" />
<ClInclude Include="..\..\core\ebase.h" /> <ClInclude Include="..\..\core\ebase.h" />
<ClInclude Include="..\..\core\ecommon.h" /> <ClInclude Include="..\..\core\ecommon.h" />
<ClInclude Include="..\..\core\eshape.h" /> <ClInclude Include="..\..\core\ecollider.h" />
<ClInclude Include="..\..\core\emacros.h" /> <ClInclude Include="..\..\core\emacros.h" />
<ClInclude Include="..\..\core\emanagers.h" /> <ClInclude Include="..\..\core\emanager.h" />
<ClInclude Include="..\..\core\enodes.h" /> <ClInclude Include="..\..\core\enode.h" />
<ClInclude Include="..\..\core\etools.h" /> <ClInclude Include="..\..\core\eshape.h" />
<ClInclude Include="..\..\core\etransitions.h" /> <ClInclude Include="..\..\core\etool.h" />
<ClInclude Include="..\..\core\etransition.h" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

View File

@ -22,8 +22,11 @@
<Filter Include="Common"> <Filter Include="Common">
<UniqueIdentifier>{be5d9314-b00a-4f11-bd2a-1f720dc32407}</UniqueIdentifier> <UniqueIdentifier>{be5d9314-b00a-4f11-bd2a-1f720dc32407}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="Shape"> <Filter Include="Collider">
<UniqueIdentifier>{d5f86335-f3a0-450d-92a3-7edd9348d995}</UniqueIdentifier> <UniqueIdentifier>{765a2a00-5764-40f9-a15d-17b0640c6b53}</UniqueIdentifier>
</Filter>
<Filter Include="Node\Shape">
<UniqueIdentifier>{eb72b49a-5b2f-4fc0-9ad2-8f5e02efac6f}</UniqueIdentifier>
</Filter> </Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -168,21 +171,9 @@
<ClCompile Include="..\..\core\Tool\Path.cpp"> <ClCompile Include="..\..\core\Tool\Path.cpp">
<Filter>Tool</Filter> <Filter>Tool</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\Shape\ShapeRectangle.cpp">
<Filter>Shape</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Shape\ShapeEllipse.cpp">
<Filter>Shape</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Shape\ShapeCircle.cpp">
<Filter>Shape</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Tool\InputListener.cpp"> <ClCompile Include="..\..\core\Tool\InputListener.cpp">
<Filter>Tool</Filter> <Filter>Tool</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\Manager\CollisionManager.cpp">
<Filter>Manager</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Tool\CollisionListener.cpp"> <ClCompile Include="..\..\core\Tool\CollisionListener.cpp">
<Filter>Tool</Filter> <Filter>Tool</Filter>
</ClCompile> </ClCompile>
@ -195,20 +186,48 @@
<ClCompile Include="..\..\core\Action\ActionFunc.cpp"> <ClCompile Include="..\..\core\Action\ActionFunc.cpp">
<Filter>Action</Filter> <Filter>Action</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\core\Shape\ShapeBase.cpp"> <ClCompile Include="..\..\core\Collider\Collider.cpp">
<Filter>Shape</Filter> <Filter>Collider</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Collider\ColliderCircle.cpp">
<Filter>Collider</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Collider\ColliderEllipse.cpp">
<Filter>Collider</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Collider\ColliderRect.cpp">
<Filter>Collider</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Manager\ColliderManager.cpp">
<Filter>Manager</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Node\Shape\Shape.cpp">
<Filter>Node\Shape</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Node\Shape\Circle.cpp">
<Filter>Node\Shape</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Node\Shape\Rect.cpp">
<Filter>Node\Shape</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Node\Shape\RoundRect.cpp">
<Filter>Node\Shape</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Node\Shape\Ellipse.cpp">
<Filter>Node\Shape</Filter>
</ClCompile> </ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\..\core\etools.h" />
<ClInclude Include="..\..\core\enodes.h" />
<ClInclude Include="..\..\core\emacros.h" /> <ClInclude Include="..\..\core\emacros.h" />
<ClInclude Include="..\..\core\ecommon.h" /> <ClInclude Include="..\..\core\ecommon.h" />
<ClInclude Include="..\..\core\ebase.h" /> <ClInclude Include="..\..\core\ebase.h" />
<ClInclude Include="..\..\core\easy2d.h" /> <ClInclude Include="..\..\core\easy2d.h" />
<ClInclude Include="..\..\core\eactions.h" /> <ClInclude Include="..\..\core\ecollider.h" />
<ClInclude Include="..\..\core\etransitions.h" />
<ClInclude Include="..\..\core\emanagers.h" />
<ClInclude Include="..\..\core\eshape.h" /> <ClInclude Include="..\..\core\eshape.h" />
<ClInclude Include="..\..\core\etransition.h" />
<ClInclude Include="..\..\core\emanager.h" />
<ClInclude Include="..\..\core\enode.h" />
<ClInclude Include="..\..\core\etool.h" />
<ClInclude Include="..\..\core\eaction.h" />
</ItemGroup> </ItemGroup>
</Project> </Project>