diff --git a/core/Action/Action.cpp b/core/Action/Action.cpp index 7102b355..4dc35777 100644 --- a/core/Action/Action.cpp +++ b/core/Action/Action.cpp @@ -1,5 +1,5 @@ -#include "..\eactions.h" -#include "..\emanagers.h" +#include "..\eaction.h" +#include "..\emanager.h" e2d::Action::Action() : m_bRunning(false) diff --git a/core/Action/ActionDelay.cpp b/core/Action/ActionDelay.cpp index 5c8e7fa7..0f2c2ac4 100644 --- a/core/Action/ActionDelay.cpp +++ b/core/Action/ActionDelay.cpp @@ -1,4 +1,4 @@ -#include "..\eactions.h" +#include "..\eaction.h" e2d::ActionDelay::ActionDelay(double duration) { diff --git a/core/Action/ActionFunc.cpp b/core/Action/ActionFunc.cpp index 28b5e06d..0c5ba799 100644 --- a/core/Action/ActionFunc.cpp +++ b/core/Action/ActionFunc.cpp @@ -1,4 +1,4 @@ -#include "..\eactions.h" +#include "..\eaction.h" e2d::ActionFunc::ActionFunc(Function func) : m_Callback(func) diff --git a/core/Action/ActionGradual.cpp b/core/Action/ActionGradual.cpp index 370f4c89..06fddf34 100644 --- a/core/Action/ActionGradual.cpp +++ b/core/Action/ActionGradual.cpp @@ -1,4 +1,4 @@ -#include "..\eactions.h" +#include "..\eaction.h" e2d::ActionGradual::ActionGradual(double duration) : m_fRateOfProgress(0) diff --git a/core/Action/ActionLoop.cpp b/core/Action/ActionLoop.cpp index 882878b6..80b5ec33 100644 --- a/core/Action/ActionLoop.cpp +++ b/core/Action/ActionLoop.cpp @@ -1,5 +1,5 @@ -#include "..\eactions.h" -#include "..\emanagers.h" +#include "..\eaction.h" +#include "..\emanager.h" e2d::ActionLoop::ActionLoop(Action * action, int times /* = -1 */) : m_pAction(action) diff --git a/core/Action/ActionMoveBy.cpp b/core/Action/ActionMoveBy.cpp index 64c581d8..fb0cbb7d 100644 --- a/core/Action/ActionMoveBy.cpp +++ b/core/Action/ActionMoveBy.cpp @@ -1,4 +1,4 @@ -#include "..\eactions.h" +#include "..\eaction.h" e2d::ActionMoveBy::ActionMoveBy(double duration, Vector vector) : diff --git a/core/Action/ActionMoveTo.cpp b/core/Action/ActionMoveTo.cpp index 2acc55c3..d3e5472a 100644 --- a/core/Action/ActionMoveTo.cpp +++ b/core/Action/ActionMoveTo.cpp @@ -1,4 +1,4 @@ -#include "..\eactions.h" +#include "..\eaction.h" e2d::ActionMoveTo::ActionMoveTo(double duration, Point pos) : ActionMoveBy(duration, Vector()) diff --git a/core/Action/ActionOpacityBy.cpp b/core/Action/ActionOpacityBy.cpp index 8eb2dcc3..5b284ac8 100644 --- a/core/Action/ActionOpacityBy.cpp +++ b/core/Action/ActionOpacityBy.cpp @@ -1,4 +1,4 @@ -#include "..\eactions.h" +#include "..\eaction.h" e2d::ActionOpacityBy::ActionOpacityBy(double duration, double opacity) : diff --git a/core/Action/ActionOpacityTo.cpp b/core/Action/ActionOpacityTo.cpp index b5dbb73c..1938d1b7 100644 --- a/core/Action/ActionOpacityTo.cpp +++ b/core/Action/ActionOpacityTo.cpp @@ -1,4 +1,4 @@ -#include "..\eactions.h" +#include "..\eaction.h" e2d::ActionOpacityTo::ActionOpacityTo(double duration, double opacity) : diff --git a/core/Action/ActionRotateBy.cpp b/core/Action/ActionRotateBy.cpp index ce7677b5..cf86ddb3 100644 --- a/core/Action/ActionRotateBy.cpp +++ b/core/Action/ActionRotateBy.cpp @@ -1,4 +1,4 @@ -#include "..\eactions.h" +#include "..\eaction.h" e2d::ActionRotateBy::ActionRotateBy(double duration, double rotation) : diff --git a/core/Action/ActionRotateTo.cpp b/core/Action/ActionRotateTo.cpp index badf400d..4943c186 100644 --- a/core/Action/ActionRotateTo.cpp +++ b/core/Action/ActionRotateTo.cpp @@ -1,4 +1,4 @@ -#include "..\eactions.h" +#include "..\eaction.h" e2d::ActionRotateTo::ActionRotateTo(double duration, double rotation) : diff --git a/core/Action/ActionScaleBy.cpp b/core/Action/ActionScaleBy.cpp index 55716504..51d6af57 100644 --- a/core/Action/ActionScaleBy.cpp +++ b/core/Action/ActionScaleBy.cpp @@ -1,4 +1,4 @@ -#include "..\eactions.h" +#include "..\eaction.h" e2d::ActionScaleBy::ActionScaleBy(double duration, double scale) diff --git a/core/Action/ActionScaleTo.cpp b/core/Action/ActionScaleTo.cpp index 5071045c..01c40982 100644 --- a/core/Action/ActionScaleTo.cpp +++ b/core/Action/ActionScaleTo.cpp @@ -1,4 +1,4 @@ -#include "..\eactions.h" +#include "..\eaction.h" e2d::ActionScaleTo::ActionScaleTo(double duration, double scale) : ActionScaleBy(duration, 0, 0) diff --git a/core/Action/ActionSequence.cpp b/core/Action/ActionSequence.cpp index ab8abb7f..2735dcd7 100644 --- a/core/Action/ActionSequence.cpp +++ b/core/Action/ActionSequence.cpp @@ -1,4 +1,4 @@ -#include "..\eactions.h" +#include "..\eaction.h" e2d::ActionSequence::ActionSequence() : m_nActionIndex(0) diff --git a/core/Action/ActionTwo.cpp b/core/Action/ActionTwo.cpp index 083d0d88..8d1823a6 100644 --- a/core/Action/ActionTwo.cpp +++ b/core/Action/ActionTwo.cpp @@ -1,4 +1,4 @@ -#include "..\eactions.h" +#include "..\eaction.h" e2d::ActionTwo::ActionTwo(Action * pActionFirst, Action * pActionSecond, bool bAtSameTime/* = false*/) : m_pFirstAction(pActionFirst) diff --git a/core/Action/Animation.cpp b/core/Action/Animation.cpp index a94a237f..eac446ca 100644 --- a/core/Action/Animation.cpp +++ b/core/Action/Animation.cpp @@ -1,4 +1,4 @@ -#include "..\eactions.h" +#include "..\eaction.h" e2d::Animation::Animation() : m_nFrameIndex(0) diff --git a/core/Base/Game.cpp b/core/Base/Game.cpp index e7fa57e2..89a1ef6f 100644 --- a/core/Base/Game.cpp +++ b/core/Base/Game.cpp @@ -1,5 +1,5 @@ #include "..\ebase.h" -#include "..\emanagers.h" +#include "..\emanager.h" // 控制游戏终止 diff --git a/core/Base/Input.cpp b/core/Base/Input.cpp index 452454d7..7f70c396 100644 --- a/core/Base/Input.cpp +++ b/core/Base/Input.cpp @@ -1,6 +1,6 @@ #include "..\ebase.h" -#include "..\etools.h" -#include "..\emanagers.h" +#include "..\etool.h" +#include "..\emanager.h" #pragma comment(lib, "dinput8.lib") diff --git a/core/Base/Renderer.cpp b/core/Base/Renderer.cpp index db2a5e1c..3db2669c 100644 --- a/core/Base/Renderer.cpp +++ b/core/Base/Renderer.cpp @@ -1,5 +1,5 @@ #include "..\ebase.h" -#include "..\emanagers.h" +#include "..\emanager.h" static ID2D1Factory * s_pDirect2dFactory = nullptr; static ID2D1HwndRenderTarget * s_pRenderTarget = nullptr; diff --git a/core/Base/Window.cpp b/core/Base/Window.cpp index 9c76b253..987c43fd 100644 --- a/core/Base/Window.cpp +++ b/core/Base/Window.cpp @@ -1,5 +1,5 @@ #include "..\ebase.h" -#include "..\emanagers.h" +#include "..\emanager.h" #include #pragma comment (lib ,"imm32.lib") diff --git a/core/Collider/Collider.cpp b/core/Collider/Collider.cpp new file mode 100644 index 00000000..313a78e6 --- /dev/null +++ b/core/Collider/Collider.cpp @@ -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(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); + } +} diff --git a/core/Shape/ShapeCircle.cpp b/core/Collider/ColliderCircle.cpp similarity index 69% rename from core/Shape/ShapeCircle.cpp rename to core/Collider/ColliderCircle.cpp index e4ed7ba3..c73ef4ed 100644 --- a/core/Shape/ShapeCircle.cpp +++ b/core/Collider/ColliderCircle.cpp @@ -1,18 +1,18 @@ -#include "..\eshape.h" -#include "..\enodes.h" +#include "..\ecollider.h" +#include "..\enode.h" -e2d::ShapeCircle::ShapeCircle() +e2d::ColliderCircle::ColliderCircle() : m_pD2dCircle(nullptr) { } -e2d::ShapeCircle::ShapeCircle(Point center, double radius) +e2d::ColliderCircle::ColliderCircle(Point center, double radius) : m_pD2dCircle(nullptr) { this->setCircle(center, radius); } -e2d::ShapeCircle::ShapeCircle(Node * node) +e2d::ColliderCircle::ColliderCircle(Node * node) : m_pD2dCircle(nullptr) { 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); } -void e2d::ShapeCircle::setCircle(Point center, double radius) +void e2d::ColliderCircle::setCircle(Point center, double radius) { 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) { @@ -60,7 +60,7 @@ void e2d::ShapeCircle::_resize() } } -ID2D1EllipseGeometry * e2d::ShapeCircle::getD2dGeometry() const +ID2D1EllipseGeometry * e2d::ColliderCircle::getD2dGeometry() const { return m_pD2dCircle; } diff --git a/core/Shape/ShapeEllipse.cpp b/core/Collider/ColliderEllipse.cpp similarity index 65% rename from core/Shape/ShapeEllipse.cpp rename to core/Collider/ColliderEllipse.cpp index 2d129678..7ab01daa 100644 --- a/core/Shape/ShapeEllipse.cpp +++ b/core/Collider/ColliderEllipse.cpp @@ -1,18 +1,18 @@ -#include "..\eshape.h" -#include "..\enodes.h" +#include "..\ecollider.h" +#include "..\enode.h" -e2d::ShapeEllipse::ShapeEllipse() +e2d::ColliderEllipse::ColliderEllipse() : m_pD2dEllipse(nullptr) { } -e2d::ShapeEllipse::ShapeEllipse(Point center, double radiusX, double radiusY) +e2d::ColliderEllipse::ColliderEllipse(Point center, double radiusX, double radiusY) : m_pD2dEllipse(nullptr) { this->setEllipse(center, radiusX, radiusY); } -e2d::ShapeEllipse::ShapeEllipse(Node * node) +e2d::ColliderEllipse::ColliderEllipse(Node * node) : m_pD2dEllipse(nullptr) { this->setEllipse( @@ -25,12 +25,12 @@ e2d::ShapeEllipse::ShapeEllipse(Node * node) ); } -e2d::ShapeEllipse::~ShapeEllipse() +e2d::ColliderEllipse::~ColliderEllipse() { 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); @@ -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) { @@ -60,7 +60,7 @@ void e2d::ShapeEllipse::_resize() } } -ID2D1EllipseGeometry * e2d::ShapeEllipse::getD2dGeometry() const +ID2D1EllipseGeometry * e2d::ColliderEllipse::getD2dGeometry() const { return m_pD2dEllipse; } diff --git a/core/Collider/ColliderRect.cpp b/core/Collider/ColliderRect.cpp new file mode 100644 index 00000000..0767c518 --- /dev/null +++ b/core/Collider/ColliderRect.cpp @@ -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(left), + static_cast(top), + static_cast(right), + static_cast(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; +} diff --git a/core/Common/Font.cpp b/core/Common/Font.cpp index 88c53ff4..7a3fe1e2 100644 --- a/core/Common/Font.cpp +++ b/core/Common/Font.cpp @@ -1,4 +1,4 @@ -#include "..\enodes.h" +#include "..\enode.h" e2d::Font::Font() : fontFamily("") diff --git a/core/Common/Image.cpp b/core/Common/Image.cpp index 4a0f6139..348841b7 100644 --- a/core/Common/Image.cpp +++ b/core/Common/Image.cpp @@ -1,4 +1,4 @@ -#include "..\enodes.h" +#include "..\enode.h" #include static std::map s_mBitmapsFromFile; diff --git a/core/Common/Object.cpp b/core/Common/Object.cpp index 5e4b42b8..cb30430c 100644 --- a/core/Common/Object.cpp +++ b/core/Common/Object.cpp @@ -1,5 +1,5 @@ #include "..\ebase.h" -#include "..\emanagers.h" +#include "..\emanager.h" e2d::Object::Object() : m_nRefCount(0) diff --git a/core/Common/Scene.cpp b/core/Common/Scene.cpp index a6a95283..25532479 100644 --- a/core/Common/Scene.cpp +++ b/core/Common/Scene.cpp @@ -1,12 +1,12 @@ #include "..\ebase.h" -#include "..\enodes.h" -#include "..\emanagers.h" +#include "..\enode.h" +#include "..\emanager.h" e2d::Scene::Scene() : m_bWillSave(true) , m_bAutoUpdate(true) , m_bSortNeeded(false) - , m_bShapeVisiable(false) + , m_bColliderVisiable(false) , m_pRoot(new Node()) { m_pRoot->retain(); @@ -23,12 +23,12 @@ void e2d::Scene::_render() { m_pRoot->_render(); - if (m_bShapeVisiable) + if (m_bColliderVisiable) { // 恢复矩阵转换 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; } -void e2d::Scene::showOutline(bool visiable) +void e2d::Scene::showCollider(bool visiable) { - m_bShapeVisiable = visiable; + m_bColliderVisiable = visiable; } diff --git a/core/Common/String.cpp b/core/Common/String.cpp index c655ab08..9374d87e 100644 --- a/core/Common/String.cpp +++ b/core/Common/String.cpp @@ -57,6 +57,17 @@ e2d::String e2d::String::parse(int value) 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(value)); +#endif + return std::move(tmp); +} + e2d::String e2d::String::parse(float value) { String tmp; @@ -303,6 +314,12 @@ e2d::String & e2d::String::operator<<(int value) return (*this); } +e2d::String & e2d::String::operator<<(unsigned int value) +{ + (*this) += String::parse(value); + return (*this); +} + e2d::String & e2d::String::operator<<(float value) { (*this) += String::parse(value); diff --git a/core/Manager/ActionManager.cpp b/core/Manager/ActionManager.cpp index 6624957a..80bdff08 100644 --- a/core/Manager/ActionManager.cpp +++ b/core/Manager/ActionManager.cpp @@ -1,5 +1,5 @@ -#include "..\emanagers.h" -#include "..\eactions.h" +#include "..\emanager.h" +#include "..\eaction.h" static std::vector s_vActions; static std::vector s_vRunningActions; diff --git a/core/Manager/CollisionManager.cpp b/core/Manager/ColliderManager.cpp similarity index 60% rename from core/Manager/CollisionManager.cpp rename to core/Manager/ColliderManager.cpp index b0ca1cf6..00329c2d 100644 --- a/core/Manager/CollisionManager.cpp +++ b/core/Manager/ColliderManager.cpp @@ -1,10 +1,10 @@ -#include "..\emanagers.h" -#include "..\enodes.h" -#include "..\eshape.h" -#include "..\etools.h" +#include "..\emanager.h" +#include "..\enode.h" +#include "..\ecollider.h" +#include "..\etool.h" -// 形状集合 -static std::vector s_vShapes; +// 碰撞体集合 +static std::vector s_vColliders; // 监听器容器 static std::vector s_vListeners; // 碰撞触发状态 @@ -14,12 +14,12 @@ static e2d::Node * s_pActiveNode = nullptr; static e2d::Node * s_pPassiveNode = nullptr; -void e2d::CollisionManager::setEnable(bool bEnable) +void e2d::ColliderManager::setEnable(bool bEnable) { s_bCollisionEnable = bEnable; } -void e2d::CollisionManager::__update() +void e2d::ColliderManager::__update() { if (s_vListeners.size() == 0) 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) return; - Node* pActiveNode = pActiveShape->m_pParentNode; + Node* pActiveNode = pActiveCollider->m_pParentNode; if (pActiveNode) { // 获取节点所在场景 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]; - // 判断两个形状是否是同一个对象 - if (pActiveShape == pPassiveShape) + auto pPassiveCollider = s_vColliders[i]; + // 判断两个碰撞体是否是同一个对象 + if (pActiveCollider == pPassiveCollider) continue; // 获取被碰撞节点 - Node* pPassiveNode = pPassiveShape->m_pParentNode; + Node* pPassiveNode = pPassiveCollider->m_pParentNode; // 判断两节点是否处于同一场景中 if (pPassiveNode && pPassiveNode->getParentScene() == pCurrentScene) @@ -77,8 +77,8 @@ void e2d::CollisionManager::__updateShape(e2d::ShapeBase * pActiveShape) if (IsCollideWith(pActiveNode, pPassiveNode->getHashName())) { - // 判断两形状交集情况 - int relation = pActiveShape->getRelationWith(pPassiveShape); + // 判断两碰撞体交集情况 + int relation = pActiveCollider->getRelationWith(pPassiveCollider); // 忽略 UNKNOWN 和 DISJOINT 情况 if (relation != Relation::UNKNOWN && relation != Relation::DISJOINT) { @@ -86,8 +86,8 @@ void e2d::CollisionManager::__updateShape(e2d::ShapeBase * pActiveShape) s_pPassiveNode = pPassiveNode; pActiveNode->onCollide(pPassiveNode); pPassiveNode->onCollide(pActiveNode); - pCurrentScene->onCollide(); - CollisionManager::__update(); + pCurrentScene->onCollide(pActiveNode, pPassiveNode); + ColliderManager::__update(); } } } @@ -97,7 +97,7 @@ void e2d::CollisionManager::__updateShape(e2d::ShapeBase * pActiveShape) s_pPassiveNode = nullptr; } -void e2d::CollisionManager::__add(CollisionListener * pListener) +void e2d::ColliderManager::__add(CollisionListener * pListener) { 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(); } -void e2d::CollisionManager::start(String name) +void e2d::ColliderManager::start(String name) { 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) { @@ -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) { @@ -164,7 +164,7 @@ void e2d::CollisionManager::clear(String name) } } -void e2d::CollisionManager::startAll() +void e2d::ColliderManager::startAll() { 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) { @@ -180,7 +180,7 @@ void e2d::CollisionManager::stopAll() } } -void e2d::CollisionManager::clearAll() +void e2d::ColliderManager::clearAll() { FOR_LOOP(pListener, s_vListeners) { @@ -188,7 +188,7 @@ void e2d::CollisionManager::clearAll() } } -std::vector e2d::CollisionManager::get(String name) +std::vector e2d::ColliderManager::get(String name) { std::vector vListeners; FOR_LOOP(pListener, s_vListeners) @@ -201,12 +201,22 @@ std::vector e2d::CollisionManager::get(String name) return std::move(vListeners); } -std::vector e2d::CollisionManager::getAll() +std::vector e2d::ColliderManager::getAll() { 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) return s_pPassiveNode; @@ -215,7 +225,7 @@ e2d::Node* e2d::CollisionManager::isCausedBy(Node * pNode) return nullptr; } -e2d::Node* e2d::CollisionManager::isCausedBy(String name) +e2d::Node* e2d::ColliderManager::isCausedBy(String name) { if (s_pActiveNode->getName() == name) return s_pActiveNode; @@ -224,30 +234,30 @@ e2d::Node* e2d::CollisionManager::isCausedBy(String name) 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; } - pShape->retain(); - s_vShapes.push_back(pShape); + pCollider->retain(); + 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); - s_vShapes.erase(s_vShapes.begin() + i); + SafeRelease(&pCollider); + s_vColliders.erase(s_vColliders.begin() + i); return; } } diff --git a/core/Manager/InputManager.cpp b/core/Manager/InputManager.cpp index 4f04e304..93a7b6c3 100644 --- a/core/Manager/InputManager.cpp +++ b/core/Manager/InputManager.cpp @@ -1,5 +1,5 @@ -#include "..\emanagers.h" -#include "..\etools.h" +#include "..\emanager.h" +#include "..\etool.h" // 监听器容器 static std::vector s_vListeners; diff --git a/core/Manager/MusicManager.cpp b/core/Manager/MusicManager.cpp index 52a873df..b3367718 100644 --- a/core/Manager/MusicManager.cpp +++ b/core/Manager/MusicManager.cpp @@ -1,5 +1,5 @@ -#include "..\emanagers.h" -#include "..\etools.h" +#include "..\emanager.h" +#include "..\etool.h" #include #if HIGHER_THAN_VS2010 diff --git a/core/Manager/ObjectManager.cpp b/core/Manager/ObjectManager.cpp index cba4928d..7986516e 100644 --- a/core/Manager/ObjectManager.cpp +++ b/core/Manager/ObjectManager.cpp @@ -1,4 +1,4 @@ -#include "..\emanagers.h" +#include "..\emanager.h" #include "..\ebase.h" // ObjectManager 释放池的实现机制: diff --git a/core/Manager/SceneManager.cpp b/core/Manager/SceneManager.cpp index fc56ba52..d086bbe1 100644 --- a/core/Manager/SceneManager.cpp +++ b/core/Manager/SceneManager.cpp @@ -1,6 +1,6 @@ -#include "..\emanagers.h" +#include "..\emanager.h" #include "..\ebase.h" -#include "..\etransitions.h" +#include "..\etransition.h" static e2d::Scene * s_pCurrentScene = nullptr; static e2d::Scene * s_pNextScene = nullptr; diff --git a/core/Manager/TimerManager.cpp b/core/Manager/TimerManager.cpp index 9c6d2a2c..3d07d2ab 100644 --- a/core/Manager/TimerManager.cpp +++ b/core/Manager/TimerManager.cpp @@ -1,6 +1,6 @@ -#include "..\emanagers.h" -#include "..\etools.h" -#include "..\enodes.h" +#include "..\emanager.h" +#include "..\etool.h" +#include "..\enode.h" static std::vector s_vTimers; diff --git a/core/Node/Button.cpp b/core/Node/Button.cpp index 437d0893..14aeb281 100644 --- a/core/Node/Button.cpp +++ b/core/Node/Button.cpp @@ -1,5 +1,5 @@ -#include "..\enodes.h" -#include "..\emanagers.h" +#include "..\enode.h" +#include "..\emanager.h" #define SAFE_SETTER(pointer, func, ...) if (pointer) { pointer->##func(__VA_ARGS__); } diff --git a/core/Node/ButtonToggle.cpp b/core/Node/ButtonToggle.cpp index edc2ecf6..22b9f997 100644 --- a/core/Node/ButtonToggle.cpp +++ b/core/Node/ButtonToggle.cpp @@ -1,4 +1,4 @@ -#include "..\enodes.h" +#include "..\enode.h" e2d::ButtonToggle::ButtonToggle() : Button() diff --git a/core/Node/Menu.cpp b/core/Node/Menu.cpp index 9828a5ac..0a7702bf 100644 --- a/core/Node/Menu.cpp +++ b/core/Node/Menu.cpp @@ -1,10 +1,22 @@ -#include "..\enodes.h" +#include "..\enode.h" e2d::Menu::Menu() : m_bEnable(true) { } +#if HIGHER_THAN_VS2012 +e2d::Menu::Menu(const InitList& vButtons) + : m_bEnable(true) +{ + FOR_LOOP(button, vButtons) + { + this->addButton(button); + } +} + +#else + e2d::Menu::Menu(int number, Button * button1, ...) : m_bEnable(true) { @@ -17,6 +29,7 @@ e2d::Menu::Menu(int number, Button * button1, ...) number--; } } +#endif bool e2d::Menu::isEnable() const { diff --git a/core/Node/Node.cpp b/core/Node/Node.cpp index 6a60b0b0..03a7fdc1 100644 --- a/core/Node/Node.cpp +++ b/core/Node/Node.cpp @@ -1,14 +1,14 @@ -#include "..\enodes.h" -#include "..\emanagers.h" -#include "..\etools.h" -#include "..\eactions.h" -#include "..\eshape.h" +#include "..\enode.h" +#include "..\emanager.h" +#include "..\etool.h" +#include "..\eaction.h" +#include "..\ecollider.h" #include // 默认中心点位置 static float s_fDefaultPiovtX = 0; static float s_fDefaultPiovtY = 0; -static bool s_fDefaultShapeEnabled = true; +static bool s_fDefaultColliderEnabled = true; e2d::Node::Node() : m_nOrder(0) @@ -29,7 +29,7 @@ e2d::Node::Node() , m_MatriFinal(D2D1::Matrix3x2F::Identity()) , m_bVisiable(true) , m_bDisplayedInScene(false) - , m_pShape(nullptr) + , m_pCollider(nullptr) , m_pParent(nullptr) , m_pParentScene(nullptr) , m_nHashName(0) @@ -37,17 +37,17 @@ e2d::Node::Node() , m_bTransformNeeded(false) , m_bAutoUpdate(true) { - if (s_fDefaultShapeEnabled) + if (s_fDefaultColliderEnabled) { - auto rect = new ShapeRectangle(this); - this->setShape(rect); + auto rect = new ColliderRect(this); + this->setCollider(rect); } } e2d::Node::~Node() { ActionManager::__clearAllBindedWith(this); - CollisionManager::__removeShape(m_pShape); + ColliderManager::__removeCollider(m_pCollider); FOR_LOOP(child, m_vChildren) { 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) { - child->_drawShape(); + child->_drawCollider(); } } @@ -250,10 +250,10 @@ void e2d::Node::_updateTransform(Node * node) { // 计算自身的转换矩阵 node->_updateTransform(); - // 绑定于自身的形状也进行相应转换 - if (node->m_pShape) + // 绑定于自身的碰撞体也进行相应转换 + if (node->m_pCollider) { - node->m_pShape->_transform(); + node->m_pCollider->_transform(); } // 遍历子节点下的所有节点 node->_updateChildrenTransform(); @@ -378,9 +378,9 @@ double e2d::Node::getOpacity() const 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 @@ -547,28 +547,28 @@ void e2d::Node::setSize(Size size) 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); - this->setShape(rect); + auto rect = new ColliderRect(this); + this->setCollider(rect); break; } - case Shape::CIRCLE: + case ColliderType::CIRCLE: { - auto rect = new ShapeCircle(this); - this->setShape(rect); + auto rect = new ColliderCircle(this); + this->setCollider(rect); break; } - case Shape::ELLIPSE: + case ColliderType::ELLIPSE: { - auto rect = new ShapeEllipse(this); - this->setShape(rect); + auto rect = new ColliderEllipse(this); + this->setCollider(rect); 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); - // 添加新的形状 - CollisionManager::__addShape(pShape); + // 删除旧的碰撞体 + ColliderManager::__removeCollider(m_pCollider); + // 添加新的碰撞体 + ColliderManager::__addCollider(pCollider); - if (pShape) + if (pCollider) { // 双向绑定 - this->m_pShape = pShape; - pShape->m_pParentNode = this; + this->m_pCollider = pCollider; + pCollider->m_pParentNode = this; } 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(); m_vColliders.insert(hash); } #if HIGHER_THAN_VS2012 -void e2d::Node::addCollider(const InitList& vCollliderName) +void e2d::Node::addColliableName(const InitList& vCollliderName) { for (const auto &name : vCollliderName) { - this->addCollider(name); + this->addColliableName(name); } } #endif -void e2d::Node::removeCollider(String collliderName) +void e2d::Node::removeColliableName(String collliderName) { unsigned int hash = collliderName.getHashCode(); m_vColliders.erase(hash); @@ -887,10 +887,10 @@ std::vector e2d::Node::getActions(String strActionName) bool e2d::Node::isPointIn(Point point) const { BOOL ret = 0; - // 如果存在形状,用形状判断 - if (m_pShape) + // 如果存在碰撞体,用碰撞体判断 + if (m_pCollider) { - m_pShape->getD2dGeometry()->FillContainsPoint( + m_pCollider->getD2dGeometry()->FillContainsPoint( D2D1::Point2F( static_cast(point.x), static_cast(point.y)), @@ -900,13 +900,13 @@ bool e2d::Node::isPointIn(Point point) const } else { - // 为节点创建一个临时形状 + // 为节点创建一个临时碰撞体 ID2D1RectangleGeometry * rect; Renderer::getID2D1Factory()->CreateRectangleGeometry( D2D1::RectF(0, 0, m_fWidth, m_fHeight), &rect ); - // 判断点是否在形状内 + // 判断点是否在碰撞体内 rect->FillContainsPoint( D2D1::Point2F( static_cast(point.x), @@ -914,7 +914,7 @@ bool e2d::Node::isPointIn(Point point) const m_MatriFinal, &ret ); - // 删除临时创建的形状 + // 删除临时创建的碰撞体 SafeReleaseInterface(&rect); } @@ -933,10 +933,10 @@ bool e2d::Node::isPointIn(Point point) 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) && (relation != Relation::DISJOINT)) { @@ -945,10 +945,10 @@ bool e2d::Node::isIntersectWith(const Node * pNode) const } else { - // 为节点创建一个临时形状 + // 为节点创建一个临时碰撞体 ID2D1RectangleGeometry * pRect1; ID2D1RectangleGeometry * pRect2; - ID2D1TransformedGeometry * pShape; + ID2D1TransformedGeometry * pCollider; D2D1_GEOMETRY_RELATION relation; // 根据自身大小位置创建矩形 @@ -960,7 +960,7 @@ bool e2d::Node::isIntersectWith(const Node * pNode) const Renderer::getID2D1Factory()->CreateTransformedGeometry( pRect1, m_MatriFinal, - &pShape + &pCollider ); // 根据相比较节点的大小位置创建矩形 Renderer::getID2D1Factory()->CreateRectangleGeometry( @@ -968,15 +968,15 @@ bool e2d::Node::isIntersectWith(const Node * pNode) const &pRect2 ); // 获取相交状态 - pShape->CompareWithGeometry( + pCollider->CompareWithGeometry( pRect2, pNode->m_MatriFinal, &relation ); - // 删除临时创建的形状 + // 删除临时创建的碰撞体 SafeReleaseInterface(&pRect1); SafeReleaseInterface(&pRect2); - SafeReleaseInterface(&pShape); + SafeReleaseInterface(&pCollider); if ((relation != D2D1_GEOMETRY_RELATION_UNKNOWN) && (relation != D2D1_GEOMETRY_RELATION_DISJOINT)) { @@ -1009,9 +1009,9 @@ void e2d::Node::setDefaultPiovt(double defaultPiovtX, double defaultPiovtY) s_fDefaultPiovtY = min(max(static_cast(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() diff --git a/core/Node/Shape/Circle.cpp b/core/Node/Shape/Circle.cpp new file mode 100644 index 00000000..fd8da981 --- /dev/null +++ b/core/Node/Shape/Circle.cpp @@ -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(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() + ); +} diff --git a/core/Node/Shape/Ellipse.cpp b/core/Node/Shape/Ellipse.cpp new file mode 100644 index 00000000..db50050c --- /dev/null +++ b/core/Node/Shape/Ellipse.cpp @@ -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(radiusX); + Node::setWidth(radiusX * 2); +} + +void e2d::Ellipse::setRadiusY(double radiusY) +{ + m_fRadiusY = static_cast(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() + ); +} diff --git a/core/Node/Shape/Rect.cpp b/core/Node/Shape/Rect.cpp new file mode 100644 index 00000000..46b2329f --- /dev/null +++ b/core/Node/Shape/Rect.cpp @@ -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() + ); +} diff --git a/core/Node/Shape/RoundRect.cpp b/core/Node/Shape/RoundRect.cpp new file mode 100644 index 00000000..bdeb1a1c --- /dev/null +++ b/core/Node/Shape/RoundRect.cpp @@ -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(radiusX)) + , m_fRadiusY(static_cast(radiusY)) +{ + this->setSize(width, height); +} + +e2d::RoundRect::RoundRect(Size size, double radiusX, double radiusY) + : m_fRadiusX(static_cast(radiusX)) + , m_fRadiusY(static_cast(radiusY)) +{ + this->setSize(size); +} + +e2d::RoundRect::RoundRect(double top, double left, double width, double height, double radiusX, double radiusY) + : m_fRadiusX(static_cast(radiusX)) + , m_fRadiusY(static_cast(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(radiusX)) + , m_fRadiusY(static_cast(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(radiusX); +} + +void e2d::RoundRect::setRadiusY(double radiusY) +{ + m_fRadiusY = static_cast(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() + ); +} diff --git a/core/Node/Shape/Shape.cpp b/core/Node/Shape/Shape.cpp new file mode 100644 index 00000000..38329226 --- /dev/null +++ b/core/Node/Shape/Shape.cpp @@ -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(strokeWidth); +} + +void e2d::Shape::setStyle(int style) +{ + m_nStyle = style; +} diff --git a/core/Node/Sprite.cpp b/core/Node/Sprite.cpp index b5a88bd8..938de964 100644 --- a/core/Node/Sprite.cpp +++ b/core/Node/Sprite.cpp @@ -1,4 +1,4 @@ -#include "..\enodes.h" +#include "..\enode.h" e2d::Sprite::Sprite() diff --git a/core/Node/Text.cpp b/core/Node/Text.cpp index d9797f29..295eb03d 100644 --- a/core/Node/Text.cpp +++ b/core/Node/Text.cpp @@ -1,4 +1,4 @@ -#include "..\enodes.h" +#include "..\enode.h" e2d::Text::Text() diff --git a/core/Shape/ShapeBase.cpp b/core/Shape/ShapeBase.cpp deleted file mode 100644 index d3f299fa..00000000 --- a/core/Shape/ShapeBase.cpp +++ /dev/null @@ -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(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); - } -} diff --git a/core/Shape/ShapeRectangle.cpp b/core/Shape/ShapeRectangle.cpp deleted file mode 100644 index 1d66c391..00000000 --- a/core/Shape/ShapeRectangle.cpp +++ /dev/null @@ -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(left), - static_cast(top), - static_cast(right), - static_cast(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; -} diff --git a/core/Tool/CollisionListener.cpp b/core/Tool/CollisionListener.cpp index 37105b89..73fb683c 100644 --- a/core/Tool/CollisionListener.cpp +++ b/core/Tool/CollisionListener.cpp @@ -1,24 +1,24 @@ -#include "..\etools.h" -#include "..\emanagers.h" +#include "..\etool.h" +#include "..\emanager.h" e2d::CollisionListener::CollisionListener() : Listener() { - CollisionManager::__add(this); + ColliderManager::__add(this); } e2d::CollisionListener::CollisionListener(Function func) : Listener() , m_callback(func) { - CollisionManager::__add(this); + ColliderManager::__add(this); } e2d::CollisionListener::CollisionListener(Function func, String name) : Listener(name) , m_callback(func) { - CollisionManager::__add(this); + ColliderManager::__add(this); } void e2d::CollisionListener::_update() diff --git a/core/Tool/Data.cpp b/core/Tool/Data.cpp index 4fc5dce4..78d870e6 100644 --- a/core/Tool/Data.cpp +++ b/core/Tool/Data.cpp @@ -1,4 +1,4 @@ -#include "..\etools.h" +#include "..\etool.h" static e2d::String s_sDefaultFileName = L"DefaultData.ini"; diff --git a/core/Tool/InputListener.cpp b/core/Tool/InputListener.cpp index da1c5a19..03a67ddd 100644 --- a/core/Tool/InputListener.cpp +++ b/core/Tool/InputListener.cpp @@ -1,5 +1,5 @@ -#include "..\etools.h" -#include "..\emanagers.h" +#include "..\etool.h" +#include "..\emanager.h" e2d::InputListener::InputListener() : Listener() diff --git a/core/Tool/Listener.cpp b/core/Tool/Listener.cpp index 9b55cc20..f693c161 100644 --- a/core/Tool/Listener.cpp +++ b/core/Tool/Listener.cpp @@ -1,4 +1,4 @@ -#include "..\etools.h" +#include "..\etool.h" e2d::Listener::Listener() : m_bRunning(false) diff --git a/core/Tool/Music.cpp b/core/Tool/Music.cpp index d295ebc3..87379e01 100644 --- a/core/Tool/Music.cpp +++ b/core/Tool/Music.cpp @@ -1,5 +1,5 @@ -#include "..\etools.h" -#include "..\emanagers.h" +#include "..\etool.h" +#include "..\emanager.h" using namespace e2d; diff --git a/core/Tool/Path.cpp b/core/Tool/Path.cpp index 796f912f..0317f140 100644 --- a/core/Tool/Path.cpp +++ b/core/Tool/Path.cpp @@ -1,4 +1,4 @@ -#include "..\etools.h" +#include "..\etool.h" #include #include diff --git a/core/Tool/Random.cpp b/core/Tool/Random.cpp index eb8112d8..2356c50a 100644 --- a/core/Tool/Random.cpp +++ b/core/Tool/Random.cpp @@ -1,4 +1,4 @@ -#include "..\etools.h" +#include "..\etool.h" std::default_random_engine &e2d::Random::getEngine() { diff --git a/core/Tool/Timer.cpp b/core/Tool/Timer.cpp index cdbe5457..797c197e 100644 --- a/core/Tool/Timer.cpp +++ b/core/Tool/Timer.cpp @@ -1,6 +1,6 @@ -#include "..\etools.h" -#include "..\enodes.h" -#include "..\emanagers.h" +#include "..\etool.h" +#include "..\enode.h" +#include "..\emanager.h" e2d::Timer::Timer(Function func, String name, double interval /* = 0 */, int updateTimes /* = -1 */, bool atOnce /* = false */, bool autoRelease /* = false */) : m_bRunning(false) diff --git a/core/Transition/Transition.cpp b/core/Transition/Transition.cpp index 34e963d2..38ba59e2 100644 --- a/core/Transition/Transition.cpp +++ b/core/Transition/Transition.cpp @@ -1,5 +1,5 @@ #include "..\ebase.h" -#include "..\etransitions.h" +#include "..\etransition.h" e2d::Transition::Transition(double duration) : m_bEnd(false) diff --git a/core/Transition/TransitionEmerge.cpp b/core/Transition/TransitionEmerge.cpp index 609a24c0..560096eb 100644 --- a/core/Transition/TransitionEmerge.cpp +++ b/core/Transition/TransitionEmerge.cpp @@ -1,5 +1,5 @@ -#include "..\etransitions.h" -#include "..\enodes.h" +#include "..\etransition.h" +#include "..\enode.h" e2d::TransitionEmerge::TransitionEmerge(double duration) : Transition(duration) diff --git a/core/Transition/TransitionFade.cpp b/core/Transition/TransitionFade.cpp index 673d0d71..40fa89c0 100644 --- a/core/Transition/TransitionFade.cpp +++ b/core/Transition/TransitionFade.cpp @@ -1,5 +1,5 @@ -#include "..\etransitions.h" -#include "..\enodes.h" +#include "..\etransition.h" +#include "..\enode.h" e2d::TransitionFade::TransitionFade(double fadeOutDuration, double fadeInDuration) : Transition(0) diff --git a/core/Transition/TransitionMove.cpp b/core/Transition/TransitionMove.cpp index b75a63f7..b597ad78 100644 --- a/core/Transition/TransitionMove.cpp +++ b/core/Transition/TransitionMove.cpp @@ -1,5 +1,5 @@ -#include "..\etransitions.h" -#include "..\enodes.h" +#include "..\etransition.h" +#include "..\enode.h" e2d::TransitionMove::TransitionMove(double duration, MOVE_DIRECT direct) : Transition(duration) diff --git a/core/eactions.h b/core/eaction.h similarity index 99% rename from core/eactions.h rename to core/eaction.h index 8dc1671e..feccbabe 100644 --- a/core/eactions.h +++ b/core/eaction.h @@ -1,5 +1,5 @@ #pragma once -#include "enodes.h" +#include "enode.h" namespace e2d { diff --git a/core/easy2d.h b/core/easy2d.h index 013eb464..382a53e7 100644 --- a/core/easy2d.h +++ b/core/easy2d.h @@ -20,12 +20,13 @@ #include "emacros.h" #include "ecommon.h" #include "ebase.h" -#include "emanagers.h" -#include "enodes.h" -#include "etools.h" -#include "eactions.h" -#include "etransitions.h" +#include "emanager.h" +#include "enode.h" #include "eshape.h" +#include "etool.h" +#include "eaction.h" +#include "etransition.h" +#include "ecollider.h" #if defined(DEBUG) || defined(_DEBUG) diff --git a/core/ecollider.h b/core/ecollider.h new file mode 100644 index 00000000..db9a7632 --- /dev/null +++ b/core/ecollider.h @@ -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; +}; + +} \ No newline at end of file diff --git a/core/ecommon.h b/core/ecommon.h index 1bfdc055..33927b3d 100644 --- a/core/ecommon.h +++ b/core/ecommon.h @@ -75,7 +75,7 @@ struct Size // 字符串 -class String +class String final { public: String(); @@ -137,6 +137,7 @@ public: // 数字类型转字符串 static String parse(int value); + static String parse(unsigned int value); static String parse(float value); static String parse(double value); @@ -184,6 +185,7 @@ public: String& operator<< (const wchar_t *); String& operator<< (wchar_t *); String& operator<< (int value); + String& operator<< (unsigned int value); String& operator<< (float value); String& operator<< (double value); @@ -379,7 +381,7 @@ public: }; -// 形状交集关系 +// 碰撞体交集关系 class Relation { public: @@ -394,13 +396,26 @@ public: }; -// 形状类别 -class Shape +// 形状样式 +class ShapeStyle { public: enum : int { - RECTANGLE, /* 矩形 */ + SOLID, /* 填充 */ + ROUND, /* 轮廓 */ + FILL, /* 轮廓 + 填充 */ + }; +}; + + +// 碰撞体类别 +class ColliderType +{ +public: + enum : int + { + RECT, /* 矩形 */ CIRCLE, /* 圆形 */ ELLIPSE /* 椭圆形 */ }; @@ -565,7 +580,10 @@ public: virtual void onExit() {} // 重写这个函数,它将在碰撞发生时自动执行 - virtual void onCollide() {} + virtual void onCollide( + Node* pActiveNode, /* 碰撞发生时的主动体 */ + Node* pPassiveNode /* 碰撞发生时的被动体 */ + ) {} // 重写这个函数,它将在关闭窗口时执行(返回 false 将阻止窗口关闭) virtual bool onCloseWindow() { return true; } @@ -601,7 +619,7 @@ public: Node * getRoot() const; // 开启或关闭节点轮廓渲染 - void showOutline( + void showCollider( bool visiable = true ); @@ -616,7 +634,7 @@ protected: bool m_bAutoUpdate; bool m_bSortNeeded; bool m_bWillSave; - bool m_bShapeVisiable; + bool m_bColliderVisiable; Node * m_pRoot; }; diff --git a/core/emanagers.h b/core/emanager.h similarity index 91% rename from core/emanagers.h rename to core/emanager.h index ca78f9be..9ec6d9b2 100644 --- a/core/emanagers.h +++ b/core/emanager.h @@ -12,13 +12,13 @@ class Node; class Timer; class Action; class Music; -class ShapeBase; +class Collider; class Transition; class InputListener; class CollisionListener; // 对象管理器 -class ObjectManager +class ObjectManager final { friend Game; @@ -41,7 +41,7 @@ private: // 场景管理器 -class SceneManager +class SceneManager final { friend Game; friend Renderer; @@ -87,7 +87,7 @@ private: // 定时器管理器 -class TimerManager +class TimerManager final { friend Game; friend Node; @@ -150,7 +150,7 @@ private: // 动作管理器 -class ActionManager +class ActionManager final { friend Game; friend Node; @@ -235,7 +235,7 @@ private: // 音乐管理工具 -class MusicManager +class MusicManager final { friend Game; @@ -305,7 +305,7 @@ private: // 键盘和鼠标消息管理器 -class InputManager +class InputManager final { friend Input; friend InputListener; @@ -361,10 +361,10 @@ private: // 碰撞管理器 -class CollisionManager +class ColliderManager final { friend Node; - friend ShapeBase; + friend Collider; friend CollisionListener; public: @@ -411,13 +411,19 @@ public: // 获取全部监听器 static std::vector getAll(); + // 获取碰撞发生时的主动体 + static Node * getActiveNode(); + + // 获取碰撞发生时的被动体 + static Node * getPassiveNode(); + // 判断碰撞是否由该节点引发(如果是,返回与其相撞的节点指针,否则返回空) - static Node* isCausedBy( + static Node * isCausedBy( Node * pNode ); // 判断发生碰撞的节点名称是否相同(若相同返回其指针,否则返回空) - static Node* isCausedBy( + static Node * isCausedBy( String name ); @@ -430,19 +436,19 @@ private: // 更新监听器 static void __update(); - // 更新形状 - static void __updateShape( - ShapeBase * pActiveShape + // 更新碰撞体 + static void __updateCollider( + Collider * pActiveCollider ); - // 添加形状 - static void __addShape( - ShapeBase * pShape + // 添加碰撞体 + static void __addCollider( + Collider * pCollider ); - // 删除已绑定的形状 - static void __removeShape( - ShapeBase * pShape + // 删除已绑定的碰撞体 + static void __removeCollider( + Collider * pCollider ); }; diff --git a/core/enodes.h b/core/enode.h similarity index 95% rename from core/enodes.h rename to core/enode.h index 68b0c3da..2865db84 100644 --- a/core/enodes.h +++ b/core/enode.h @@ -7,16 +7,16 @@ namespace e2d class Action; class Transition; -class ShapeBase; -class CollisionManager; +class Collider; +class ColliderManager; class Node : public Object { friend Scene; - friend ShapeBase; + friend Collider; friend Transition; - friend CollisionManager; + friend ColliderManager; public: Node(); @@ -116,8 +116,8 @@ public: // 获取节点透明度 virtual double getOpacity() const; - // 获取节点形状 - virtual ShapeBase * getShape() const; + // 获取节点碰撞体 + virtual Collider * getCollider() const; // 获取父节点 virtual Node * getParent() const; @@ -291,50 +291,50 @@ public: ); // 修改节点宽度 - void setWidth( + virtual void setWidth( double width ); // 修改节点高度 - void setHeight( + virtual void setHeight( double height ); // 修改节点大小 - void setSize( + virtual void setSize( double width, double height ); // 修改节点大小 - void setSize( + virtual void setSize( Size size ); - // 设置节点形状 - virtual void setShape( - int type + // 设置碰撞体 + virtual void setCollider( + int nColliderType ); - // 设置节点形状 - virtual void setShape( - ShapeBase * pShape + // 设置碰撞体 + virtual void setCollider( + Collider * pCollider ); // 添加可碰撞节点的名称 - virtual void addCollider( + virtual void addColliableName( String collliderName ); #if HIGHER_THAN_VS2012 // 添加多个可碰撞节点的名称 - virtual void addCollider( + virtual void addColliableName( const InitList& vCollliderName /* 名称数组 */ ); #endif // 移除可碰撞节点的名称 - virtual void removeCollider( + virtual void removeColliableName( String collliderName ); @@ -397,8 +397,8 @@ public: double defaultPiovtY ); - // 设置节点是否包含默认形状(默认打开) - static void setDefaultShapeEnable( + // 设置节点是否包含默认碰撞体(默认打开) + static void setDefaultColliderEnable( bool bEnable ); @@ -410,7 +410,7 @@ protected: void _render(); // 渲染图形 - void _drawShape(); + void _drawCollider(); // 节点被添加到场景时的执行程序 void _onEnter(); @@ -460,7 +460,7 @@ protected: bool m_bDisplayedInScene; bool m_bSortChildrenNeeded; bool m_bTransformNeeded; - ShapeBase * m_pShape; + Collider * m_pCollider; Scene * m_pParentScene; Node * m_pParent; D2D1::Matrix3x2F m_MatriInitial; @@ -885,12 +885,19 @@ public: // 创建空菜单 Menu(); +#if HIGHER_THAN_VS2012 + // 创建菜单 + Menu( + const InitList& vButtons /* 按钮数组 */ + ); +#else // 创建菜单 Menu( int number, /* 菜单中按钮的数量 */ Button * button1, /* 第一个按钮 */ ... ); +#endif // 获取菜单是否禁用 bool isEnable() const; diff --git a/core/eshape.h b/core/eshape.h index eaced236..1a2ea67d 100644 --- a/core/eshape.h +++ b/core/eshape.h @@ -1,202 +1,290 @@ #pragma once -#include "ebase.h" - +#include "enode.h" namespace e2d { -class CollisionManager; - // 形状 -class ShapeBase : - public Object +class Shape : + public Node { - friend CollisionManager; - friend Node; - public: - ShapeBase(); + Shape(); - virtual ~ShapeBase(); + virtual ~Shape(); - // 判断两形状的交集关系 - virtual int getRelationWith( - ShapeBase * pShape - ) const; + // 获取样式 + int getStyle() const; - // 获取父节点 - Node * getParentNode() const; + // 获取填充颜色 + UINT32 getFillColor() const; - // 启用或关闭该形状 - virtual void setEnable( - bool bEnable + // 获取线条颜色 + UINT32 getLineColor() const; + + // 获取线条宽度 + double getStrokeWidth() const; + + // 设置填充颜色 + void setFillColor( + UINT32 fillColor ); - // 设置形状的可见性 - void setVisiable( - bool bVisiable + // 设置线条颜色 + void setLineColor( + UINT32 lineColor ); - // 设置绘制颜色 - void setColor( - UINT32 color + // 设置线条宽度 + void setStrokeWidth( + double strokeWidth ); - // 设置绘制透明度 - void setOpacity( - double opacity - ); - - // 设置大小跟随 - void setAutoResize( - bool bEnable - ); - - // 获取 ID2D1Geometry 对象 - virtual ID2D1Geometry * getD2dGeometry() const = 0; - -protected: - // 转换形状 - virtual void _transform(); - - // 重设大小 - virtual void _resize() = 0; + // 设置样式 + void setStyle(int style); // 渲染形状 - virtual void _render(); + virtual void onRender() override; protected: - bool m_bEnable; - bool m_bIsVisiable; - bool m_bAutoResize; - UINT32 m_nColor; - float m_fOpacity; - Node * m_pParentNode; - ID2D1TransformedGeometry * m_pTransformedShape; + // 渲染轮廓 + virtual void _renderLine() = 0; + + // 渲染填充色 + virtual void _renderFill() = 0; + +protected: + int m_nStyle; + float m_fStrokeWidth; + UINT32 m_nLineColor; + UINT32 m_nFillColor; }; // 矩形 -class ShapeRectangle : - public ShapeBase +class Rect : + public Shape { public: - // 创建一个默认矩形 - ShapeRectangle(); + Rect(); - // 根据左上角坐标和宽高创建矩形 - ShapeRectangle( - double x, - double y, - double width, - double height + Rect( + double width, /* 宽度 */ + double height /* 高度 */ ); - // 创建一个和节点位置大小相同的矩形 - ShapeRectangle( - Node * node + Rect( + Size size /* 宽度和高度 */ ); - virtual ~ShapeRectangle(); - - // 修改矩形大小 - void setRect( - double left, - double top, - double right, - double bottom + Rect( + double top, /* 左上角横坐标 */ + double left, /* 左上角纵坐标 */ + double width, /* 宽度 */ + double height /* 高度 */ ); - // 获取 ID2D1Geometry 对象 - virtual ID2D1RectangleGeometry * getD2dGeometry() const override; + Rect( + Point topLeft, /* 左上角坐标 */ + Size size /* 宽度和高度 */ + ); + + virtual ~Rect(); 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: - ID2D1RectangleGeometry * m_pD2dRectangle; + // 渲染轮廓 + virtual void _renderLine() override; + + // 渲染填充色 + virtual void _renderFill() override; + +protected: + float m_fRadiusX; + float m_fRadiusY; }; // 圆形 -class ShapeCircle : - public ShapeBase +class Circle : + public Shape { public: - // 创建一个默认圆形 - ShapeCircle(); + Circle(); - // 根据圆心和半径创建圆形 - ShapeCircle( - Point center, + Circle( + double radius /* 半径 */ + ); + + Circle( + Point center, /* 圆心坐标 */ + double radius /* 半径 */ + ); + + Circle( + double centerX, /* 圆心横坐标 */ + double centerY, /* 圆心纵坐标 */ + double radius /* 半径 */ + ); + + virtual ~Circle(); + + // 获取半径 + double getRadius() const; + + // 设置半径 + virtual void setRadius( double radius ); - // 创建一个和节点位置大小相同的圆形 - ShapeCircle( - Node * node - ); +public: + // 禁用的函数 + void setWidth() {} - virtual ~ShapeCircle(); + // 禁用的函数 + void setHeight() {} - // 修改圆形大小 - void setCircle( - Point center, - double radius - ); - - // 获取 ID2D1Geometry 对象 - virtual ID2D1EllipseGeometry * getD2dGeometry() const override; + // 禁用的函数 + void setSize() {} protected: - // 重设大小 - virtual void _resize(); + // 渲染轮廓 + virtual void _renderLine() override; + + // 渲染填充色 + virtual void _renderFill() override; protected: - ID2D1EllipseGeometry * m_pD2dCircle; + float m_fRadius; }; // 椭圆形 -class ShapeEllipse : - public ShapeBase +class Ellipse : + public Shape { public: - // 创建一个默认椭圆 - ShapeEllipse(); + Ellipse(); - // 根据圆心和半径创建椭圆 - ShapeEllipse( - Point center, - double radiusX, + Ellipse( + double radiusX, /* 横轴半径 */ + double radiusY /* 纵轴半径 */ + ); + + 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 ); - // 创建一个和节点位置大小相同的椭圆 - ShapeEllipse( - Node * node - ); +public: + // 禁用的函数 + void setWidth() {} - virtual ~ShapeEllipse(); + // 禁用的函数 + void setHeight() {} - // 修改椭圆大小 - void setEllipse( - Point center, - double radiusX, - double radiusY - ); - - // 获取 ID2D1Geometry 对象 - virtual ID2D1EllipseGeometry * getD2dGeometry() const override; + // 禁用的函数 + void setSize() {} protected: - // 重设大小 - virtual void _resize(); + // 渲染轮廓 + virtual void _renderLine() override; + + // 渲染填充色 + virtual void _renderFill() override; protected: - ID2D1EllipseGeometry * m_pD2dEllipse; + float m_fRadiusX; + float m_fRadiusY; }; } \ No newline at end of file diff --git a/core/etools.h b/core/etool.h similarity index 99% rename from core/etools.h rename to core/etool.h index a03848be..6918c7cf 100644 --- a/core/etools.h +++ b/core/etool.h @@ -8,7 +8,7 @@ namespace e2d class TimerManager; class MusicManager; class InputManager; -class CollisionManager; +class ColliderManager; // 随机数产生器 class Random @@ -196,7 +196,7 @@ protected: class CollisionListener : public Listener { - friend CollisionManager; + friend ColliderManager; public: CollisionListener(); diff --git a/core/etransitions.h b/core/etransition.h similarity index 100% rename from core/etransitions.h rename to core/etransition.h diff --git a/project/vs2017/Easy2D.vcxproj b/project/vs2017/Easy2D.vcxproj index 45e04270..fd810b6a 100644 --- a/project/vs2017/Easy2D.vcxproj +++ b/project/vs2017/Easy2D.vcxproj @@ -211,6 +211,10 @@ + + + + @@ -222,19 +226,20 @@ - + + + + + + - - - - @@ -249,16 +254,17 @@ - + - + - - - - + + + + + diff --git a/project/vs2017/Easy2D.vcxproj.filters b/project/vs2017/Easy2D.vcxproj.filters index 7bf79952..22397e8a 100644 --- a/project/vs2017/Easy2D.vcxproj.filters +++ b/project/vs2017/Easy2D.vcxproj.filters @@ -22,8 +22,11 @@ {be5d9314-b00a-4f11-bd2a-1f720dc32407} - - {d5f86335-f3a0-450d-92a3-7edd9348d995} + + {765a2a00-5764-40f9-a15d-17b0640c6b53} + + + {eb72b49a-5b2f-4fc0-9ad2-8f5e02efac6f} @@ -168,21 +171,9 @@ Tool - - Shape - - - Shape - - - Shape - Tool - - Manager - Tool @@ -195,20 +186,48 @@ Action - - Shape + + Collider + + + Collider + + + Collider + + + Collider + + + Manager + + + Node\Shape + + + Node\Shape + + + Node\Shape + + + Node\Shape + + + Node\Shape - - - - - + + + + + + \ No newline at end of file