diff --git a/Easy2D/Node/ESpriteFrame.cpp b/Easy2D/Common/ESpriteFrame.cpp similarity index 98% rename from Easy2D/Node/ESpriteFrame.cpp rename to Easy2D/Common/ESpriteFrame.cpp index a8fb8dfb..d4d61043 100644 --- a/Easy2D/Node/ESpriteFrame.cpp +++ b/Easy2D/Common/ESpriteFrame.cpp @@ -1,4 +1,4 @@ -#include "..\enodes.h" +#include "..\ecommon.h" e2d::ESpriteFrame::ESpriteFrame() : m_fSourceClipX(0) diff --git a/Easy2D/Easy2D.vcxproj b/Easy2D/Easy2D.vcxproj index 0e0414bf..1482d9df 100644 --- a/Easy2D/Easy2D.vcxproj +++ b/Easy2D/Easy2D.vcxproj @@ -238,7 +238,6 @@ - diff --git a/Easy2D/Easy2D.vcxproj.filters b/Easy2D/Easy2D.vcxproj.filters index 30b95085..b613d558 100644 --- a/Easy2D/Easy2D.vcxproj.filters +++ b/Easy2D/Easy2D.vcxproj.filters @@ -99,9 +99,6 @@ Action - - Node - Action diff --git a/Easy2D/Geometry/EPhysicsMsg.cpp b/Easy2D/Geometry/EPhysicsMsg.cpp index 745070a7..a9ecd51e 100644 --- a/Easy2D/Geometry/EPhysicsMsg.cpp +++ b/Easy2D/Geometry/EPhysicsMsg.cpp @@ -1,4 +1,4 @@ -#include "..\egeometry.h" +#include "..\ecommon.h" e2d::EPhysicsMsg::INTERSECT_RELATION e2d::EPhysicsMsg::s_nRelation = e2d::EPhysicsMsg::INTERSECT_RELATION::UNKNOWN; e2d::EGeometry * e2d::EPhysicsMsg::s_pActiveGeometry = nullptr; diff --git a/Easy2D/Listener/EListener.cpp b/Easy2D/Listener/EListener.cpp index c94a895e..3efbfe6a 100644 --- a/Easy2D/Listener/EListener.cpp +++ b/Easy2D/Listener/EListener.cpp @@ -4,6 +4,7 @@ e2d::EListener::EListener() : m_bRunning(false) , m_bAlways(false) , m_pParentNode(nullptr) + , m_bSwallow(false) { } @@ -43,6 +44,11 @@ void e2d::EListener::setName(const EString & name) m_sName = name; } +void e2d::EListener::setSwallow(bool bSwallow) +{ + m_bSwallow = bSwallow; +} + void e2d::EListener::setAlwaysWorking(bool bAlways) { m_bAlways = bAlways; diff --git a/Easy2D/Manager/EMsgManager.cpp b/Easy2D/Manager/EMsgManager.cpp index 1adb511c..cae83a79 100644 --- a/Easy2D/Manager/EMsgManager.cpp +++ b/Easy2D/Manager/EMsgManager.cpp @@ -16,10 +16,15 @@ void e2d::EMsgManager::MouseProc(UINT message, WPARAM wParam, LPARAM lParam) EMouseMsg::s_nMsg = message; EMouseMsg::s_wParam = wParam; EMouseMsg::s_lParam = lParam; + + if (s_vMouseListeners.empty()) return; + // 执行鼠标消息监听函数 - for (size_t i = 0; i < s_vMouseListeners.size(); i++) + EVector::size_type i = s_vMouseListeners.size(); + + do { - auto &mlistener = s_vMouseListeners[i]; + auto &mlistener = s_vMouseListeners[--i]; if (EApp::isPaused() && !mlistener->m_bAlways) continue; @@ -30,9 +35,12 @@ void e2d::EMsgManager::MouseProc(UINT message, WPARAM wParam, LPARAM lParam) mlistener->getParentNode()->getParentScene() == EApp::getCurrentScene()) { mlistener->_callOn(); + + if (mlistener->m_bSwallow) + break; } } - } + } while (i != 0); } void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam) @@ -41,10 +49,15 @@ void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam) EKeyboardMsg::s_nMsg = message; EKeyboardMsg::s_wParam = wParam; EKeyboardMsg::s_lParam = lParam; + + if (s_vKeyboardListeners.empty()) return; + // 执行按键消息监听函数 - for (size_t i = 0; i < s_vKeyboardListeners.size(); i++) + EVector::size_type i = s_vKeyboardListeners.size(); + + do { - auto &klistener = s_vKeyboardListeners[i]; + auto &klistener = s_vKeyboardListeners[--i]; if (EApp::isPaused() && !klistener->m_bAlways) continue; @@ -55,9 +68,12 @@ void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam) klistener->getParentNode()->getParentScene() == EApp::getCurrentScene()) { klistener->_callOn(); + + if (klistener->m_bSwallow) + break; } } - } + } while (i != 0); } void e2d::EMsgManager::bindListener(e2d::EListenerMouse * listener, EScene * pParentScene) diff --git a/Easy2D/ecommon.h b/Easy2D/ecommon.h index 530087f6..cd803610 100644 --- a/Easy2D/ecommon.h +++ b/Easy2D/ecommon.h @@ -307,6 +307,37 @@ public: }; +class EGeometry; + +// 物理消息 +class EPhysicsMsg +{ +public: + enum INTERSECT_RELATION + { + UNKNOWN = 0, /* 关系不确定 */ + DISJOINT = 1, /* 没有交集 */ + IS_CONTAINED = 2, /* 完全被包含 */ + CONTAINS = 3, /* 完全包含 */ + OVERLAP = 4 /* 部分重叠 */ + }; + + // 获取当前物理碰撞消息类型 + static INTERSECT_RELATION getMsg(); + + // 获取主动方 + static EGeometry * getActiveGeometry(); + + // 获取被动方 + static EGeometry * getPassiveGeometry(); + +public: + static INTERSECT_RELATION s_nRelation; + static EGeometry * s_pActiveGeometry; + static EGeometry * s_pPassiveGeometry; +}; + + class EObjectManager; class EObject @@ -470,4 +501,91 @@ protected: ID2D1Bitmap * m_pBitmap; }; + +class ESpriteFrame : + public EObject +{ + friend ESprite; + +public: + // 创建空的精灵帧 + ESpriteFrame(); + + // 创建空的精灵帧 + ESpriteFrame( + ETexture * texture + ); + + // 创建空的精灵帧 + ESpriteFrame( + const EString & imageFileName + ); + + // 创建空的精灵帧 + ESpriteFrame( + LPCTSTR resourceName, + LPCTSTR resourceType + ); + + // 创建空的精灵帧 + ESpriteFrame( + ETexture * texture, + float x, + float y, + float width, + float height + ); + + // 创建空的精灵帧 + ESpriteFrame( + const EString & imageFileName, + float x, + float y, + float width, + float height + ); + + // 创建空的精灵帧 + ESpriteFrame( + LPCTSTR resourceName, + LPCTSTR resourceType, + float x, + float y, + float width, + float height + ); + + virtual ~ESpriteFrame(); + + // 获取宽度 + float getWidth() const; + + // 获取高度 + float getHeight() const; + + // 获取纹理 + ETexture * getTexture() const; + +protected: + // 获取纹理 + void _setTexture( + ETexture * texture + ); + + // 裁剪纹理 + void _clipTexture( + float x, + float y, + float width, + float height + ); + +protected: + float m_fSourceClipX; + float m_fSourceClipY; + float m_fSourceClipWidth; + float m_fSourceClipHeight; + ETexture * m_pTexture; +}; + } \ No newline at end of file diff --git a/Easy2D/egeometry.h b/Easy2D/egeometry.h index 27b0e53a..582d248e 100644 --- a/Easy2D/egeometry.h +++ b/Easy2D/egeometry.h @@ -7,36 +7,7 @@ namespace e2d class EPhysicsManager; class ENode; -class EGeometry; -class EPhysicsMsg -{ - friend EPhysicsManager; - -public: - enum INTERSECT_RELATION - { - UNKNOWN = 0, /* 关系不确定 */ - DISJOINT = 1, /* 没有交集 */ - IS_CONTAINED = 2, /* 完全被包含 */ - CONTAINS = 3, /* 完全包含 */ - OVERLAP = 4 /* 部分重叠 */ - }; - - // 获取当前物理碰撞消息类型 - static INTERSECT_RELATION getMsg(); - - // 获取主动方 - static EGeometry * getActiveGeometry(); - - // 获取被动方 - static EGeometry * getPassiveGeometry(); - -public: - static INTERSECT_RELATION s_nRelation; - static EGeometry * s_pActiveGeometry; - static EGeometry * s_pPassiveGeometry; -}; class EGeometry : public EObject diff --git a/Easy2D/elisteners.h b/Easy2D/elisteners.h index f447ac6f..6c85d892 100644 --- a/Easy2D/elisteners.h +++ b/Easy2D/elisteners.h @@ -42,6 +42,11 @@ public: const EString &name ); + // 设置监听器吞噬消息 + void setSwallow( + bool bSwallow + ); + // 设置监听器在游戏暂停时继续工作 void setAlwaysWorking( bool bAlways @@ -65,6 +70,7 @@ protected: EString m_sName; bool m_bRunning; bool m_bAlways; + bool m_bSwallow; ENode * m_pParentNode; }; diff --git a/Easy2D/enodes.h b/Easy2D/enodes.h index 2e92426c..d1f0d657 100644 --- a/Easy2D/enodes.h +++ b/Easy2D/enodes.h @@ -392,93 +392,6 @@ protected: }; -class ESpriteFrame : - public EObject -{ - friend ESprite; - -public: - // 创建空的精灵帧 - ESpriteFrame(); - - // 创建空的精灵帧 - ESpriteFrame( - ETexture * texture - ); - - // 创建空的精灵帧 - ESpriteFrame( - const EString & imageFileName - ); - - // 创建空的精灵帧 - ESpriteFrame( - LPCTSTR resourceName, - LPCTSTR resourceType - ); - - // 创建空的精灵帧 - ESpriteFrame( - ETexture * texture, - float x, - float y, - float width, - float height - ); - - // 创建空的精灵帧 - ESpriteFrame( - const EString & imageFileName, - float x, - float y, - float width, - float height - ); - - // 创建空的精灵帧 - ESpriteFrame( - LPCTSTR resourceName, - LPCTSTR resourceType, - float x, - float y, - float width, - float height - ); - - virtual ~ESpriteFrame(); - - // 获取宽度 - float getWidth() const; - - // 获取高度 - float getHeight() const; - - // 获取纹理 - ETexture * getTexture() const; - -protected: - // 获取纹理 - void _setTexture( - ETexture * texture - ); - - // 裁剪纹理 - void _clipTexture( - float x, - float y, - float width, - float height - ); - -protected: - float m_fSourceClipX; - float m_fSourceClipY; - float m_fSourceClipWidth; - float m_fSourceClipHeight; - ETexture * m_pTexture; -}; - - class ESprite : public ENode {