From 508a3e0fabc31775922bc099e81fbc4dff9e014e Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Thu, 26 Oct 2017 17:17:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86Geometry=E7=B1=BB?= =?UTF-8?q?=EF=BC=9B=E9=87=8D=E6=95=B4=E4=BA=86=E7=9B=91=E5=90=AC=E5=99=A8?= =?UTF-8?q?=E5=92=8C=E5=AE=9A=E6=97=B6=E5=99=A8=E7=9A=84=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Easy2D/Base/EApp.cpp | 19 +- Easy2D/Base/EObject.cpp | 2 +- Easy2D/Base/EScene.cpp | 11 +- Easy2D/Common/EKeyboardMsg.cpp | 59 ++ Easy2D/Common/EMouseMsg.cpp | 58 ++ Easy2D/Easy2D.vcxproj | 12 +- Easy2D/Easy2D.vcxproj.filters | 34 +- Easy2D/Geometry/ECircle.cpp | 32 + Easy2D/Geometry/EEllipse.cpp | 32 + Easy2D/Geometry/EGeometry.cpp | 28 + Easy2D/Geometry/ERectangle.cpp | 43 ++ Easy2D/Listener/ECollisionListener.cpp | 0 Easy2D/Listener/EKeyboardListener.cpp | 3 +- Easy2D/Listener/EKeyboardPressListener.cpp | 2 +- Easy2D/Listener/EListener.cpp | 8 +- Easy2D/Listener/EMouseClickListener.cpp | 2 +- Easy2D/Listener/EMouseDoubleClickListener.cpp | 2 +- Easy2D/Listener/EMouseDragListener.cpp | 2 +- Easy2D/Listener/EMouseListener.cpp | 3 +- Easy2D/Listener/EMousePressListener.cpp | 2 +- Easy2D/Manager/EActionManager.cpp | 2 +- Easy2D/Manager/EMsgManager.cpp | 263 +------- Easy2D/Manager/EObjectManager.cpp | 3 +- Easy2D/Manager/EPhysicsManager.cpp | 26 + Easy2D/Manager/ETimerManager.cpp | 70 +- Easy2D/Node/EButton.cpp | 3 +- Easy2D/Node/EFont.cpp | 20 +- Easy2D/Node/ENode.cpp | 23 +- Easy2D/Node/ESprite.cpp | 18 +- Easy2D/Node/EText.cpp | 23 +- Easy2D/Tool/ETimer.cpp | 7 +- Easy2D/Transition/ETransitionEmerge.cpp | 2 +- Easy2D/Transition/ETransitionFade.cpp | 2 +- Easy2D/Transition/ETransitionMove.cpp | 2 +- Easy2D/Transition/ETransitionScale.cpp | 2 +- Easy2D/Transition/ETransitionScaleEmerge.cpp | 2 +- Easy2D/easy2d.h | 4 +- Easy2D/ebase.h | 10 +- Easy2D/ecommon.h | 235 +++++-- Easy2D/egeometry.h | 114 ++++ Easy2D/elisteners.h | 324 +++++++++ Easy2D/emanagers.h | 331 ++++++++++ Easy2D/emsg.h | 615 ------------------ Easy2D/enodes.h | 60 +- Easy2D/etools.h | 160 ----- 45 files changed, 1452 insertions(+), 1223 deletions(-) create mode 100644 Easy2D/Common/EKeyboardMsg.cpp create mode 100644 Easy2D/Common/EMouseMsg.cpp create mode 100644 Easy2D/Geometry/ECircle.cpp create mode 100644 Easy2D/Geometry/EEllipse.cpp create mode 100644 Easy2D/Geometry/EGeometry.cpp create mode 100644 Easy2D/Geometry/ERectangle.cpp create mode 100644 Easy2D/Listener/ECollisionListener.cpp create mode 100644 Easy2D/Manager/EPhysicsManager.cpp create mode 100644 Easy2D/egeometry.h create mode 100644 Easy2D/elisteners.h create mode 100644 Easy2D/emanagers.h delete mode 100644 Easy2D/emsg.h diff --git a/Easy2D/Base/EApp.cpp b/Easy2D/Base/EApp.cpp index 29399b4a..e15455e6 100644 --- a/Easy2D/Base/EApp.cpp +++ b/Easy2D/Base/EApp.cpp @@ -1,12 +1,11 @@ #include "..\ebase.h" #include "..\Win\winbase.h" -#include "..\emsg.h" -#include "..\etools.h" +#include "..\emanagers.h" #include "..\enodes.h" #include "..\etransitions.h" #include #include -#include +#include #pragma comment (lib ,"imm32.lib") using namespace std::this_thread; @@ -75,7 +74,7 @@ bool e2d::EApp::init(const EString &title, UINT32 width, UINT32 height, EWindowS // 注册窗口类 WNDCLASSEX wcex = { sizeof(WNDCLASSEX) }; UINT style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; - if (wStyle.NO_CLOSE) + if (wStyle.m_bNoClose) { style |= CS_NOCLOSE; } @@ -88,9 +87,9 @@ bool e2d::EApp::init(const EString &title, UINT32 width, UINT32 height, EWindowS wcex.lpszMenuName = NULL; wcex.hCursor = LoadCursor(NULL, IDI_APPLICATION); wcex.lpszClassName = L"Easy2DApp"; - if (wStyle.ICON_ID) + if (wStyle.m_pIconID) { - wcex.hIcon = (HICON)::LoadImage(GetModuleHandle(NULL), wStyle.ICON_ID, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE); + wcex.hIcon = (HICON)::LoadImage(GetModuleHandle(NULL), wStyle.m_pIconID, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE); } RegisterClassEx(&wcex); @@ -117,12 +116,12 @@ bool e2d::EApp::init(const EString &title, UINT32 width, UINT32 height, EWindowS // 创建窗口样式 DWORD dwStyle = WS_OVERLAPPED | WS_SYSMENU; - if (!wStyle.NO_MINI_SIZE) + if (!wStyle.m_bNoMiniSize) { dwStyle |= WS_MINIMIZEBOX; } // 保存窗口是否置顶显示 - m_bTopMost = wStyle.TOP_MOST; + m_bTopMost = wStyle.m_bTopMost; // 保存窗口名称 m_sTitle = title; // 创建窗口 @@ -366,7 +365,7 @@ void e2d::EApp::_onRender() // 开始绘图 GetRenderTarget()->BeginDraw(); // 使用背景色清空屏幕 - GetRenderTarget()->Clear(D2D1::ColorF(m_ClearColor.value)); + GetRenderTarget()->Clear(D2D1::ColorF(m_ClearColor)); // 绘制当前场景 if (m_pCurrentScene) { @@ -528,7 +527,7 @@ e2d::EString e2d::EApp::getAppName() return s_pInstance->m_sAppName; } -void e2d::EApp::setBkColor(EColor color) +void e2d::EApp::setBkColor(UINT32 color) { get()->m_ClearColor = color; } diff --git a/Easy2D/Base/EObject.cpp b/Easy2D/Base/EObject.cpp index bbe42644..cf0097f7 100644 --- a/Easy2D/Base/EObject.cpp +++ b/Easy2D/Base/EObject.cpp @@ -1,5 +1,5 @@ #include "..\ebase.h" -#include "..\etools.h" +#include "..\emanagers.h" e2d::EObject::EObject() : m_nRefCount(0) diff --git a/Easy2D/Base/EScene.cpp b/Easy2D/Base/EScene.cpp index c4b39a38..2ab3c1ed 100644 --- a/Easy2D/Base/EScene.cpp +++ b/Easy2D/Base/EScene.cpp @@ -1,7 +1,8 @@ #include "..\ebase.h" #include "..\enodes.h" -#include "..\emsg.h" +#include "..\emanagers.h" #include "..\etools.h" +#include "..\eactions.h" #include e2d::EScene::EScene() @@ -17,9 +18,6 @@ e2d::EScene::EScene() e2d::EScene::~EScene() { - ETimerManager::_clearAllTimersBindedWith(this); - EMsgManager::_clearAllMouseListenersBindedWith(this); - EMsgManager::_clearAllKeyboardListenersBindedWith(this); SafeReleaseAndClear(&m_pRoot); } @@ -91,6 +89,11 @@ void e2d::EScene::clearAllChildren() m_pRoot->clearAllChildren(); } +void e2d::EScene::runAction(EAction * action) +{ + this->m_pRoot->runAction(action); +} + void e2d::EScene::bindListener(EMouseListener * listener) { EMsgManager::bindListener(listener, this); diff --git a/Easy2D/Common/EKeyboardMsg.cpp b/Easy2D/Common/EKeyboardMsg.cpp new file mode 100644 index 00000000..64f54c1b --- /dev/null +++ b/Easy2D/Common/EKeyboardMsg.cpp @@ -0,0 +1,59 @@ +#include "..\ecommon.h" + +static e2d::EKeyboardMsg s_KeyboardMsg; + +e2d::EKeyboardMsg::KEYBOARD_MSG e2d::EKeyboardMsg::getMsg() +{ + return KEYBOARD_MSG(s_KeyboardMsg.m_nMsg); +} + +e2d::EKeyboardMsg::KEY e2d::EKeyboardMsg::getVal() +{ + return KEY(s_KeyboardMsg.m_wParam); +} + +DWORD e2d::EKeyboardMsg::getCount() +{ + return (((DWORD)s_KeyboardMsg.m_lParam) & 0x0000FFFF); +} + +bool e2d::EKeyboardMsg::isKeyDown(KEY key) +{ + if (::GetAsyncKeyState((int)key) & 0x8000) + { + return true; + } + return false; +} + +bool e2d::EKeyboardMsg::isCapitalLockOn() +{ + if (::GetKeyState(VK_CAPITAL) & 0x0001) + { + return true; + } + return false; +} + +bool e2d::EKeyboardMsg::isNumpadLockOn() +{ + if (::GetKeyState(VK_NUMLOCK) & 0x0001) + { + return true; + } + return false; +} + +bool e2d::EKeyboardMsg::isScrollLockOn() +{ + if (::GetKeyState(VK_SCROLL) & 0x0001) + { + return true; + } + return false; +} + +e2d::EKeyboardMsg & e2d::EKeyboardMsg::getKeyboardMsg() +{ + return s_KeyboardMsg; +} diff --git a/Easy2D/Common/EMouseMsg.cpp b/Easy2D/Common/EMouseMsg.cpp new file mode 100644 index 00000000..efe4110e --- /dev/null +++ b/Easy2D/Common/EMouseMsg.cpp @@ -0,0 +1,58 @@ +#include "..\ecommon.h" + +static e2d::EMouseMsg s_MouseMsg; + +DWORD e2d::EMouseMsg::getPosX() +{ + return LOWORD(s_MouseMsg.m_lParam); +} + +DWORD e2d::EMouseMsg::getPosY() +{ + return HIWORD(s_MouseMsg.m_lParam); +} + +e2d::EPoint e2d::EMouseMsg::getPos() +{ + return EPoint(LOWORD(s_MouseMsg.m_lParam), HIWORD(s_MouseMsg.m_lParam)); +} + +bool e2d::EMouseMsg::isLButtonDown() +{ + return GET_KEYSTATE_WPARAM(s_MouseMsg.m_wParam) == MK_LBUTTON; +} + +bool e2d::EMouseMsg::isMButtonDown() +{ + return GET_KEYSTATE_WPARAM(s_MouseMsg.m_wParam) == MK_MBUTTON; +} + +bool e2d::EMouseMsg::isRButtonDown() +{ + return GET_KEYSTATE_WPARAM(s_MouseMsg.m_wParam) == MK_RBUTTON; +} + +bool e2d::EMouseMsg::isShiftDown() +{ + return GET_KEYSTATE_WPARAM(s_MouseMsg.m_wParam) == MK_SHIFT; +} + +bool e2d::EMouseMsg::isCtrlDown() +{ + return GET_KEYSTATE_WPARAM(s_MouseMsg.m_wParam) == MK_CONTROL; +} + +DWORD e2d::EMouseMsg::getWheelDelta() +{ + return GET_WHEEL_DELTA_WPARAM(s_MouseMsg.m_wParam); +} + +e2d::EMouseMsg::MOUSE_MSG e2d::EMouseMsg::getMsg() +{ + return MOUSE_MSG(s_MouseMsg.m_nMsg); +} + +e2d::EMouseMsg & e2d::EMouseMsg::getMouseMsg() +{ + return s_MouseMsg; +} diff --git a/Easy2D/Easy2D.vcxproj b/Easy2D/Easy2D.vcxproj index 59c39c00..2f1a36cb 100644 --- a/Easy2D/Easy2D.vcxproj +++ b/Easy2D/Easy2D.vcxproj @@ -210,6 +210,13 @@ + + + + + + + @@ -221,6 +228,7 @@ + @@ -245,8 +253,10 @@ + + - + diff --git a/Easy2D/Easy2D.vcxproj.filters b/Easy2D/Easy2D.vcxproj.filters index 3f90ce09..edd343c0 100644 --- a/Easy2D/Easy2D.vcxproj.filters +++ b/Easy2D/Easy2D.vcxproj.filters @@ -25,6 +25,12 @@ {b9bb1728-5106-4574-998e-8564b49cb4a1} + + {d5f86335-f3a0-450d-92a3-7edd9348d995} + + + {be5d9314-b00a-4f11-bd2a-1f720dc32407} + @@ -174,6 +180,30 @@ Tool + + Geometry + + + Geometry + + + Geometry + + + Geometry + + + Listener + + + Common + + + Common + + + Manager + @@ -185,8 +215,10 @@ - + + + \ No newline at end of file diff --git a/Easy2D/Geometry/ECircle.cpp b/Easy2D/Geometry/ECircle.cpp new file mode 100644 index 00000000..cb8aaf55 --- /dev/null +++ b/Easy2D/Geometry/ECircle.cpp @@ -0,0 +1,32 @@ +#include "..\egeometry.h" +#include "..\Win\winbase.h" + +e2d::ECircle::ECircle() +{ + this->_setCircle(EPoint(), 0); +} + +e2d::ECircle::ECircle(EPoint center, float radius) +{ + this->_setCircle(center, radius); +} + +void e2d::ECircle::_setCircle(EPoint center, float radius) +{ + SafeReleaseInterface(&m_pD2dCircle); + + GetFactory()->CreateEllipseGeometry( + D2D1::Ellipse( + D2D1::Point2F( + center.x, + center.y), + radius, + radius), + &m_pD2dCircle + ); +} + +ID2D1EllipseGeometry * e2d::ECircle::_getD2dGeometry() const +{ + return m_pD2dCircle; +} diff --git a/Easy2D/Geometry/EEllipse.cpp b/Easy2D/Geometry/EEllipse.cpp new file mode 100644 index 00000000..7892102f --- /dev/null +++ b/Easy2D/Geometry/EEllipse.cpp @@ -0,0 +1,32 @@ +#include "..\egeometry.h" +#include "..\Win\winbase.h" + +e2d::EEllipse::EEllipse() +{ + this->_setEllipse(EPoint(), 0, 0); +} + +e2d::EEllipse::EEllipse(EPoint center, float radiusX, float radiusY) +{ + this->_setEllipse(center, radiusX, radiusY); +} + +void e2d::EEllipse::_setEllipse(EPoint center, float radiusX, float radiusY) +{ + SafeReleaseInterface(&m_pD2dEllipse); + + GetFactory()->CreateEllipseGeometry( + D2D1::Ellipse( + D2D1::Point2F( + center.x, + center.y), + radiusX, + radiusY), + &m_pD2dEllipse + ); +} + +ID2D1EllipseGeometry * e2d::EEllipse::_getD2dGeometry() const +{ + return m_pD2dEllipse; +} diff --git a/Easy2D/Geometry/EGeometry.cpp b/Easy2D/Geometry/EGeometry.cpp new file mode 100644 index 00000000..44636c8b --- /dev/null +++ b/Easy2D/Geometry/EGeometry.cpp @@ -0,0 +1,28 @@ +#include "..\egeometry.h" +#include "..\Win\winbase.h" + +e2d::EGeometry::EGeometry() + : m_bTransformed(true) + , m_pParentNode(nullptr) +{ +} + +bool e2d::EGeometry::_isCollisionWith(EGeometry * pGeometry) +{ + D2D1_GEOMETRY_RELATION relation; + + HRESULT hr = this->_getD2dGeometry()->CompareWithGeometry( + pGeometry->_getD2dGeometry(), + D2D1::Matrix3x2F::Identity(), + &relation + ); + + if (SUCCEEDED(hr)) + { + return (relation == D2D1_GEOMETRY_RELATION::D2D1_GEOMETRY_RELATION_OVERLAP) || + (relation == D2D1_GEOMETRY_RELATION::D2D1_GEOMETRY_RELATION_CONTAINS) || + (relation == D2D1_GEOMETRY_RELATION::D2D1_GEOMETRY_RELATION_IS_CONTAINED); + } + + return false; +} \ No newline at end of file diff --git a/Easy2D/Geometry/ERectangle.cpp b/Easy2D/Geometry/ERectangle.cpp new file mode 100644 index 00000000..0c528a59 --- /dev/null +++ b/Easy2D/Geometry/ERectangle.cpp @@ -0,0 +1,43 @@ +#include "..\egeometry.h" +#include "..\enodes.h" +#include "..\Win\winbase.h" + +e2d::ERectangle::ERectangle() +{ + this->_setRect(0, 0, 0, 0); +} + +e2d::ERectangle::ERectangle(float x, float y, float width, float height) +{ + this->_setRect(x, y, x + width, y + height); +} + +e2d::ERectangle::ERectangle(ENode * node) +{ + // 计算左上角坐标 + D2D1_POINT_2F upperLeftCorner = D2D1::Point2F( + node->getPosX() - node->getRealWidth() * node->getAnchorX(), + node->getPosY() - node->getRealHeight() * node->getAnchorY() + ); + this->_setRect( + upperLeftCorner.x, + upperLeftCorner.y, + upperLeftCorner.x + node->getRealWidth(), + upperLeftCorner.y + node->getRealHeight() + ); +} + +void e2d::ERectangle::_setRect(float left, float top, float right, float bottom) +{ + SafeReleaseInterface(&m_pD2dRectangle); + + GetFactory()->CreateRectangleGeometry( + D2D1::RectF(left, top, right, bottom), + &m_pD2dRectangle + ); +} + +ID2D1RectangleGeometry * e2d::ERectangle::_getD2dGeometry() const +{ + return m_pD2dRectangle; +} diff --git a/Easy2D/Listener/ECollisionListener.cpp b/Easy2D/Listener/ECollisionListener.cpp new file mode 100644 index 00000000..e69de29b diff --git a/Easy2D/Listener/EKeyboardListener.cpp b/Easy2D/Listener/EKeyboardListener.cpp index a95610a4..9b4145fa 100644 --- a/Easy2D/Listener/EKeyboardListener.cpp +++ b/Easy2D/Listener/EKeyboardListener.cpp @@ -1,4 +1,5 @@ -#include "..\emsg.h" +#include "..\elisteners.h" +#include "..\emanagers.h" e2d::EKeyboardListener::EKeyboardListener() : EListener() diff --git a/Easy2D/Listener/EKeyboardPressListener.cpp b/Easy2D/Listener/EKeyboardPressListener.cpp index 7935ecc7..b6990598 100644 --- a/Easy2D/Listener/EKeyboardPressListener.cpp +++ b/Easy2D/Listener/EKeyboardPressListener.cpp @@ -1,4 +1,4 @@ -#include "..\emsg.h" +#include "..\elisteners.h" e2d::EKeyboardPressListener::EKeyboardPressListener() : EKeyboardListener() diff --git a/Easy2D/Listener/EListener.cpp b/Easy2D/Listener/EListener.cpp index aa6bb54a..5c033f2e 100644 --- a/Easy2D/Listener/EListener.cpp +++ b/Easy2D/Listener/EListener.cpp @@ -1,9 +1,8 @@ -#include "..\emsg.h" +#include "..\elisteners.h" e2d::EListener::EListener() : m_bRunning(false) , m_bAlways(false) - , m_pParentScene(nullptr) , m_pParentNode(nullptr) { } @@ -34,11 +33,6 @@ e2d::EString e2d::EListener::getName() const return m_sName; } -e2d::EScene * e2d::EListener::getParentScene() const -{ - return m_pParentScene; -} - e2d::ENode * e2d::EListener::getParentNode() const { return m_pParentNode; diff --git a/Easy2D/Listener/EMouseClickListener.cpp b/Easy2D/Listener/EMouseClickListener.cpp index c76890a4..e1717c1b 100644 --- a/Easy2D/Listener/EMouseClickListener.cpp +++ b/Easy2D/Listener/EMouseClickListener.cpp @@ -1,4 +1,4 @@ -#include "..\emsg.h" +#include "..\elisteners.h" e2d::EMouseClickListener::EMouseClickListener() : EMouseListener() diff --git a/Easy2D/Listener/EMouseDoubleClickListener.cpp b/Easy2D/Listener/EMouseDoubleClickListener.cpp index 26679aff..e353d731 100644 --- a/Easy2D/Listener/EMouseDoubleClickListener.cpp +++ b/Easy2D/Listener/EMouseDoubleClickListener.cpp @@ -1,4 +1,4 @@ -#include "..\emsg.h" +#include "..\elisteners.h" e2d::EMouseDoubleClickListener::EMouseDoubleClickListener() : EMouseListener() diff --git a/Easy2D/Listener/EMouseDragListener.cpp b/Easy2D/Listener/EMouseDragListener.cpp index c2d1ac20..a56c54a2 100644 --- a/Easy2D/Listener/EMouseDragListener.cpp +++ b/Easy2D/Listener/EMouseDragListener.cpp @@ -1,4 +1,4 @@ -#include "..\emsg.h" +#include "..\elisteners.h" e2d::EMouseDragListener::EMouseDragListener() : EMouseListener() diff --git a/Easy2D/Listener/EMouseListener.cpp b/Easy2D/Listener/EMouseListener.cpp index e10f8bf8..ff4f6d72 100644 --- a/Easy2D/Listener/EMouseListener.cpp +++ b/Easy2D/Listener/EMouseListener.cpp @@ -1,4 +1,5 @@ -#include "..\emsg.h" +#include "..\elisteners.h" +#include "..\emanagers.h" e2d::EMouseListener::EMouseListener() : EListener() diff --git a/Easy2D/Listener/EMousePressListener.cpp b/Easy2D/Listener/EMousePressListener.cpp index 1f71b219..c2c369ab 100644 --- a/Easy2D/Listener/EMousePressListener.cpp +++ b/Easy2D/Listener/EMousePressListener.cpp @@ -1,4 +1,4 @@ -#include "..\emsg.h" +#include "..\elisteners.h" e2d::EMousePressListener::EMousePressListener() : EMouseListener() diff --git a/Easy2D/Manager/EActionManager.cpp b/Easy2D/Manager/EActionManager.cpp index 128452c8..3a53a2c8 100644 --- a/Easy2D/Manager/EActionManager.cpp +++ b/Easy2D/Manager/EActionManager.cpp @@ -1,4 +1,4 @@ -#include "..\etools.h" +#include "..\emanagers.h" #include "..\eactions.h" #include "..\Win\winbase.h" diff --git a/Easy2D/Manager/EMsgManager.cpp b/Easy2D/Manager/EMsgManager.cpp index b7635e56..d0286fa9 100644 --- a/Easy2D/Manager/EMsgManager.cpp +++ b/Easy2D/Manager/EMsgManager.cpp @@ -1,12 +1,9 @@ -#include "..\emsg.h" +#include "..\emanagers.h" +#include "..\elisteners.h" #include "..\enodes.h" #include "..\Win\winbase.h" -// 鼠标消息 -e2d::EMouseMsg s_MouseMsg; -// 按键消息 -e2d::EKeyboardMsg s_KeyboardMsg; // 鼠标消息监听器 e2d::EVector s_vMouseListeners; // 按键消息监听器 @@ -16,9 +13,9 @@ e2d::EVector s_vKeyboardListeners; void e2d::EMsgManager::MouseProc(UINT message, WPARAM wParam, LPARAM lParam) { // 保存鼠标消息 - s_MouseMsg.m_nMsg = message; - s_MouseMsg.m_wParam = wParam; - s_MouseMsg.m_lParam = lParam; + EMouseMsg::getMouseMsg().m_nMsg = message; + EMouseMsg::getMouseMsg().m_wParam = wParam; + EMouseMsg::getMouseMsg().m_lParam = lParam; // 执行鼠标消息监听函数 for (size_t i = 0; i < s_vMouseListeners.size(); i++) { @@ -29,8 +26,8 @@ void e2d::EMsgManager::MouseProc(UINT message, WPARAM wParam, LPARAM lParam) if (mlistener->isRunning()) { - if (mlistener->getParentScene() == EApp::getCurrentScene() || - (mlistener->getParentNode() && mlistener->getParentNode()->getParentScene() == EApp::getCurrentScene())) + if (mlistener->getParentNode() && + mlistener->getParentNode()->getParentScene() == EApp::getCurrentScene()) { mlistener->_callOn(); } @@ -41,9 +38,9 @@ void e2d::EMsgManager::MouseProc(UINT message, WPARAM wParam, LPARAM lParam) void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam) { // 保存按键消息 - s_KeyboardMsg.m_nMsg = message; - s_KeyboardMsg.m_wParam = wParam; - s_KeyboardMsg.m_lParam = lParam; + EKeyboardMsg::getKeyboardMsg().m_nMsg = message; + EKeyboardMsg::getKeyboardMsg().m_wParam = wParam; + EKeyboardMsg::getKeyboardMsg().m_lParam = lParam; // 执行按键消息监听函数 for (size_t i = 0; i < s_vKeyboardListeners.size(); i++) { @@ -54,8 +51,8 @@ void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam) if (klistener->isRunning()) { - if (klistener->getParentScene() == EApp::getCurrentScene() || - (klistener->getParentNode() && klistener->getParentNode()->getParentScene() == EApp::getCurrentScene())) + if (klistener->getParentNode() && + klistener->getParentNode()->getParentScene() == EApp::getCurrentScene()) { klistener->_callOn(); } @@ -63,159 +60,28 @@ void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam) } } - -DWORD e2d::EMouseMsg::getPosX() -{ - return LOWORD(s_MouseMsg.m_lParam); -} - -DWORD e2d::EMouseMsg::getPosY() -{ - return HIWORD(s_MouseMsg.m_lParam); -} - -e2d::EPoint e2d::EMouseMsg::getPos() -{ - return EPoint(LOWORD(s_MouseMsg.m_lParam), HIWORD(s_MouseMsg.m_lParam)); -} - -bool e2d::EMouseMsg::isLButtonDown() -{ - return GET_KEYSTATE_WPARAM(s_MouseMsg.m_wParam) == MK_LBUTTON; -} - -bool e2d::EMouseMsg::isMButtonDown() -{ - return GET_KEYSTATE_WPARAM(s_MouseMsg.m_wParam) == MK_MBUTTON; -} - -bool e2d::EMouseMsg::isRButtonDown() -{ - return GET_KEYSTATE_WPARAM(s_MouseMsg.m_wParam) == MK_RBUTTON; -} - -bool e2d::EMouseMsg::isShiftDown() -{ - return GET_KEYSTATE_WPARAM(s_MouseMsg.m_wParam) == MK_SHIFT; -} - -bool e2d::EMouseMsg::isCtrlDown() -{ - return GET_KEYSTATE_WPARAM(s_MouseMsg.m_wParam) == MK_CONTROL; -} - -DWORD e2d::EMouseMsg::getWheelDelta() -{ - return GET_WHEEL_DELTA_WPARAM(s_MouseMsg.m_wParam); -} - -e2d::EMouseMsg::MOUSE_MSG e2d::EMouseMsg::getMsg() -{ - return MOUSE_MSG(s_MouseMsg.m_nMsg); -} - - - -e2d::EKeyboardMsg::KEYBOARD_MSG e2d::EKeyboardMsg::getMsg() -{ - return KEYBOARD_MSG(s_KeyboardMsg.m_nMsg); -} - -e2d::EKeyboardMsg::KEY e2d::EKeyboardMsg::getVal() -{ - return KEY(s_KeyboardMsg.m_wParam); -} - -DWORD e2d::EKeyboardMsg::getCount() -{ - return (((DWORD)s_KeyboardMsg.m_lParam) & 0x0000FFFF); -} - -bool e2d::EKeyboardMsg::isKeyDown(KEY key) -{ - if (::GetAsyncKeyState((int)key) & 0x8000) - { - return true; - } - return false; -} - -bool e2d::EKeyboardMsg::isCapitalLockOn() -{ - if (::GetKeyState(VK_CAPITAL) & 0x0001) - { - return true; - } - return false; -} - -bool e2d::EKeyboardMsg::isNumpadLockOn() -{ - if (::GetKeyState(VK_NUMLOCK) & 0x0001) - { - return true; - } - return false; -} - -bool e2d::EKeyboardMsg::isScrollLockOn() -{ - if (::GetKeyState(VK_SCROLL) & 0x0001) - { - return true; - } - return false; -} - void e2d::EMsgManager::bindListener(e2d::EMouseListener * listener, EScene * pParentScene, bool always /* = false */) { - ASSERT( - (!listener->m_pParentNode) && (!listener->m_pParentScene), - "The listener is already binded, it cannot bind again!" - ); - WARN_IF(listener == nullptr, "EMouseListener NULL pointer exception!"); - WARN_IF(pParentScene == nullptr, "Bind EMouseListener with a NULL EScene pointer!"); - - if (listener && pParentScene) - { - listener->start(); - listener->retain(); - listener->m_pParentScene = pParentScene; - listener->m_bAlways = always; - s_vMouseListeners.push_back(listener); - } + EMsgManager::bindListener(listener, pParentScene->getRoot(), always); } void e2d::EMsgManager::bindListener(EKeyboardListener * listener, EScene * pParentScene, bool always /* = false */) { - ASSERT( - (!listener->m_pParentNode) && (!listener->m_pParentScene), - "The listener is already binded, it cannot bind again!" - ); - WARN_IF(listener == nullptr, "EKeyboardListener NULL pointer exception!"); - WARN_IF(pParentScene == nullptr, "Bind EKeyboardListener with a NULL EScene pointer!"); - - if (listener && pParentScene) - { - listener->start(); - listener->retain(); - listener->m_pParentScene = pParentScene; - listener->m_bAlways = always; - s_vKeyboardListeners.push_back(listener); - } + EMsgManager::bindListener(listener, pParentScene->getRoot(), always); } void e2d::EMsgManager::bindListener(EMouseListener * listener, ENode * pParentNode, bool always /* = false */) { - ASSERT( - (!listener->m_pParentNode) && (!listener->m_pParentScene), - "The listener is already binded, it cannot bind again!" - ); WARN_IF(listener == nullptr, "EMouseListener NULL pointer exception!"); WARN_IF(pParentNode == nullptr, "Bind EMouseListener with a NULL ENode pointer!"); if (listener && pParentNode) { + ASSERT( + !listener->m_pParentNode, + "The listener is already binded, it cannot bind again!" + ); + listener->start(); listener->retain(); listener->m_bAlways = always; @@ -226,15 +92,16 @@ void e2d::EMsgManager::bindListener(EMouseListener * listener, ENode * pParentNo void e2d::EMsgManager::bindListener(EKeyboardListener * listener, ENode * pParentNode, bool always /* = false */) { - ASSERT( - (!listener->m_pParentNode) && (!listener->m_pParentScene), - "The listener is already binded, it cannot bind again!" - ); WARN_IF(listener == nullptr, "EKeyboardListener NULL pointer exception!"); WARN_IF(pParentNode == nullptr, "Bind EKeyboardListener with a NULL ENode pointer!"); if (listener && pParentNode) { + ASSERT( + !listener->m_pParentNode, + "The listener is already binded, it cannot bind again!" + ); + listener->start(); listener->retain(); listener->m_pParentNode = pParentNode; @@ -327,32 +194,12 @@ void e2d::EMsgManager::delKeyboardListeners(const EString & name) void e2d::EMsgManager::startAllMouseListenersBindedWith(EScene * pParentScene) { - for (auto l : s_vMouseListeners) - { - if (l->getParentScene() == pParentScene) - { - l->start(); - } - } - for (auto child : pParentScene->getChildren()) - { - EMsgManager::startAllMouseListenersBindedWith(child); - } + EMsgManager::startAllMouseListenersBindedWith(pParentScene->getRoot()); } void e2d::EMsgManager::stopAllMouseListenersBindedWith(EScene * pParentScene) { - for (auto l : s_vMouseListeners) - { - if (l->getParentScene() == pParentScene) - { - l->stop(); - } - } - for (auto child : pParentScene->getChildren()) - { - EMsgManager::stopAllMouseListenersBindedWith(child); - } + EMsgManager::stopAllMouseListenersBindedWith(pParentScene->getRoot()); } void e2d::EMsgManager::startAllMouseListenersBindedWith(ENode * pParentNode) @@ -387,32 +234,12 @@ void e2d::EMsgManager::stopAllMouseListenersBindedWith(ENode * pParentNode) void e2d::EMsgManager::startAllKeyboardListenersBindedWith(EScene * pParentScene) { - for (auto l : s_vKeyboardListeners) - { - if (l->getParentScene() == pParentScene) - { - l->start(); - } - } - for (auto child : pParentScene->getChildren()) - { - EMsgManager::startAllKeyboardListenersBindedWith(child); - } + EMsgManager::startAllKeyboardListenersBindedWith(pParentScene->getRoot()); } void e2d::EMsgManager::stopAllKeyboardListenersBindedWith(EScene * pParentScene) { - for (auto l : s_vKeyboardListeners) - { - if (l->getParentScene() == pParentScene) - { - l->stop(); - } - } - for (auto child : pParentScene->getChildren()) - { - EMsgManager::stopAllKeyboardListenersBindedWith(child); - } + EMsgManager::stopAllKeyboardListenersBindedWith(pParentScene->getRoot()); } void e2d::EMsgManager::startAllKeyboardListenersBindedWith(ENode * pParentNode) @@ -445,40 +272,6 @@ void e2d::EMsgManager::stopAllKeyboardListenersBindedWith(ENode * pParentNode) } } -void e2d::EMsgManager::_clearAllMouseListenersBindedWith(EScene * pParentScene) -{ - for (size_t i = 0; i < s_vMouseListeners.size();) - { - auto t = s_vMouseListeners[i]; - if (t->getParentScene() == pParentScene) - { - SafeReleaseAndClear(&t); - s_vMouseListeners.erase(s_vMouseListeners.begin() + i); - } - else - { - i++; - } - } -} - -void e2d::EMsgManager::_clearAllKeyboardListenersBindedWith(EScene * pParentScene) -{ - for (size_t i = 0; i < s_vKeyboardListeners.size();) - { - auto t = s_vKeyboardListeners[i]; - if (t->getParentScene() == pParentScene) - { - SafeReleaseAndClear(&t); - s_vKeyboardListeners.erase(s_vKeyboardListeners.begin() + i); - } - else - { - i++; - } - } -} - void e2d::EMsgManager::_clearAllMouseListenersBindedWith(ENode * pParentNode) { for (size_t i = 0; i < s_vMouseListeners.size();) diff --git a/Easy2D/Manager/EObjectManager.cpp b/Easy2D/Manager/EObjectManager.cpp index c2059524..fbfdd767 100644 --- a/Easy2D/Manager/EObjectManager.cpp +++ b/Easy2D/Manager/EObjectManager.cpp @@ -1,4 +1,5 @@ -#include "..\etools.h" +#include "..\emanagers.h" +#include "..\ebase.h" // EObjectManager 释放池的实现机制: // EObject 类中的引用计数(m_nRefCount)保证了指针的使用安全 diff --git a/Easy2D/Manager/EPhysicsManager.cpp b/Easy2D/Manager/EPhysicsManager.cpp new file mode 100644 index 00000000..e46a2366 --- /dev/null +++ b/Easy2D/Manager/EPhysicsManager.cpp @@ -0,0 +1,26 @@ +#include "..\emanagers.h" +#include "..\egeometry.h" + +e2d::EVector s_vGeometries; + +void e2d::EPhysicsManager::bindWith(EGeometry * geometry, ENode * node) +{ + WARN_IF(geometry == nullptr, "EGeometry NULL pointer exception!"); + WARN_IF(node == nullptr, "EGeometry add to a NULL ENode pointer!"); + + if (geometry && node) + { + ASSERT( + !geometry->m_pParentNode, + "The geometry is already added, it cannot bind again!" + ); + + geometry->retain(); + geometry->m_pParentNode = node; + s_vGeometries.push_back(geometry); + } +} + +void e2d::EPhysicsManager::PhysicsProc() +{ +} diff --git a/Easy2D/Manager/ETimerManager.cpp b/Easy2D/Manager/ETimerManager.cpp index 3a9e6c44..4c7d1670 100644 --- a/Easy2D/Manager/ETimerManager.cpp +++ b/Easy2D/Manager/ETimerManager.cpp @@ -1,3 +1,4 @@ +#include "..\emanagers.h" #include "..\etools.h" #include "..\enodes.h" #include "..\Win\winbase.h" @@ -15,8 +16,8 @@ void e2d::ETimerManager::TimerProc() auto &t = s_vTimers[i]; if (t->isRunning()) { - if (t->getParentScene() == EApp::getCurrentScene() || - (t->getParentNode() && (t->getParentNode()->getParentScene() == EApp::getCurrentScene()))) + if (t->getParentNode() && + t->getParentNode()->getParentScene() == EApp::getCurrentScene()) { if (t->_isReady()) { @@ -29,33 +30,21 @@ void e2d::ETimerManager::TimerProc() void e2d::ETimerManager::bindTimer(ETimer * timer, EScene * pParentScene) { - ASSERT( - (!timer->m_pParentScene) && (!timer->m_pParentNode), - "The timer is already binded, it cannot bind again!" - ); - WARN_IF(timer == nullptr, "ETimer NULL pointer exception!"); - WARN_IF(pParentScene == nullptr, "Bind ETimer with a NULL EScene pointer!"); - - if (timer && pParentScene) - { - timer->start(); - timer->retain(); - timer->m_pParentScene = pParentScene; - s_vTimers.push_back(timer); - } + ETimerManager::bindTimer(timer, pParentScene->getRoot()); } void e2d::ETimerManager::bindTimer(ETimer * timer, ENode * pParentNode) { - ASSERT( - (!timer->m_pParentScene) && (!timer->m_pParentNode), - "The timer is already binded, it cannot bind again!" - ); WARN_IF(timer == nullptr, "ETimer NULL pointer exception!"); WARN_IF(pParentNode == nullptr, "Bind ETimer with a NULL ENode pointer!"); if (timer && pParentNode) { + ASSERT( + !timer->m_pParentNode, + "The timer is already binded, it cannot bind again!" + ); + timer->start(); timer->retain(); timer->m_pParentNode = pParentNode; @@ -104,49 +93,12 @@ void e2d::ETimerManager::delTimers(const EString & name) void e2d::ETimerManager::startAllTimersBindedWith(EScene * pParentScene) { - for (auto t : s_vTimers) - { - if (t->getParentScene() == pParentScene) - { - t->start(); - } - } - for (auto child : pParentScene->getChildren()) - { - ETimerManager::startAllTimersBindedWith(child); - } + ETimerManager::startAllTimersBindedWith(pParentScene->getRoot()); } void e2d::ETimerManager::stopAllTimersBindedWith(EScene * pParentScene) { - for (auto t : s_vTimers) - { - if (t->getParentScene() == pParentScene) - { - t->stop(); - } - } - for (auto child : pParentScene->getChildren()) - { - ETimerManager::stopAllTimersBindedWith(child); - } -} - -void e2d::ETimerManager::_clearAllTimersBindedWith(EScene * pParentScene) -{ - for (size_t i = 0; i < s_vTimers.size();) - { - auto t = s_vTimers[i]; - if (t->getParentScene() == pParentScene) - { - SafeReleaseAndClear(&t); - s_vTimers.erase(s_vTimers.begin() + i); - } - else - { - i++; - } - } + ETimerManager::stopAllTimersBindedWith(pParentScene->getRoot()); } void e2d::ETimerManager::startAllTimersBindedWith(ENode * pParentNode) diff --git a/Easy2D/Node/EButton.cpp b/Easy2D/Node/EButton.cpp index 8392ed37..f7402d4e 100644 --- a/Easy2D/Node/EButton.cpp +++ b/Easy2D/Node/EButton.cpp @@ -1,5 +1,6 @@ #include "..\enodes.h" -#include "..\emsg.h" +#include "..\elisteners.h" +#include "..\emanagers.h" #include "..\Win\winbase.h" e2d::EButton::EButton() diff --git a/Easy2D/Node/EFont.cpp b/Easy2D/Node/EFont.cpp index 69515376..92c2c4d9 100644 --- a/Easy2D/Node/EFont.cpp +++ b/Easy2D/Node/EFont.cpp @@ -3,6 +3,7 @@ e2d::EFont::EFont() : m_pTextFormat(nullptr) + , m_Color(EColor::WHITE) , m_fFontSize(22) , m_FontWeight(EFontWeight::REGULAR) , m_bItalic(false) @@ -10,10 +11,11 @@ e2d::EFont::EFont() { } -e2d::EFont::EFont(EString fontFamily, float fontSize, EFontWeight fontWeight, bool italic) +e2d::EFont::EFont(EString fontFamily, float fontSize /* = 22 */, UINT32 color /* = EColor::WHITE */, UINT32 fontWeight, bool italic /* = false */) { this->setFamily(fontFamily); this->setSize(fontSize); + this->setColor(color); this->setWeight(fontWeight); this->setItalic(italic); } @@ -28,11 +30,16 @@ float e2d::EFont::getFontSize() const return m_fFontSize; } -e2d::EFontWeight e2d::EFont::getFontWeight() const +UINT32 e2d::EFont::getFontWeight() const { return m_FontWeight; } +UINT32 e2d::EFont::getColor() const +{ + return m_Color; +} + bool e2d::EFont::isItalic() const { return m_bItalic; @@ -50,12 +57,17 @@ void e2d::EFont::setSize(float fontSize) m_bRecreateNeeded = true; } -void e2d::EFont::setWeight(EFontWeight fontWeight) +void e2d::EFont::setWeight(UINT32 fontWeight) { m_FontWeight = fontWeight; m_bRecreateNeeded = true; } +void e2d::EFont::setColor(UINT32 color) +{ + m_Color = color; +} + void e2d::EFont::setItalic(bool value) { m_bItalic = value; @@ -69,7 +81,7 @@ void e2d::EFont::_initTextFormat() HRESULT hr = GetDirectWriteFactory()->CreateTextFormat( m_sFontFamily.c_str(), NULL, // Font collection(NULL sets it to the system font collection) - DWRITE_FONT_WEIGHT(m_FontWeight.value), + DWRITE_FONT_WEIGHT(m_FontWeight), m_bItalic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, m_fFontSize, diff --git a/Easy2D/Node/ENode.cpp b/Easy2D/Node/ENode.cpp index e3361016..67a96ec6 100644 --- a/Easy2D/Node/ENode.cpp +++ b/Easy2D/Node/ENode.cpp @@ -1,7 +1,8 @@ #include "..\enodes.h" -#include "..\emsg.h" +#include "..\emanagers.h" #include "..\etools.h" #include "..\eactions.h" +#include "..\egeometry.h" #include "..\Win\winbase.h" #include @@ -19,6 +20,7 @@ e2d::ENode::ENode() , m_Matri(D2D1::Matrix3x2F::Identity()) , m_bVisiable(true) , m_bDisplayedInScene(false) + , m_pGeometry(nullptr) , m_pParent(nullptr) , m_pParentScene(nullptr) , m_nHashName(0) @@ -43,6 +45,7 @@ e2d::ENode::~ENode() { SafeReleaseAndClear(&child); } + SafeReleaseAndClear(&m_pGeometry); } void e2d::ENode::onEnter() @@ -190,11 +193,14 @@ void e2d::ENode::_updateChildrenTransform() void e2d::ENode::_updateTransform(ENode * node) { + // 计算自身的转换矩阵 node->_updateTransformToReal(); + // 和父节点矩阵相乘 if (node->m_pParent) { node->m_Matri = node->m_Matri * node->m_pParent->m_Matri; } + // 转换矩阵后判断 // 遍历子节点下的所有节点 node->_updateChildrenTransform(); node->m_bTransformChildrenNeeded = false; @@ -267,6 +273,16 @@ e2d::ESize e2d::ENode::getRealSize() const return m_Size; } +float e2d::ENode::getAnchorX() const +{ + return m_fAnchorX; +} + +float e2d::ENode::getAnchorY() const +{ + return m_fAnchorY; +} + e2d::ESize e2d::ENode::getSize() const { return ESize(getWidth(), getHeight()); @@ -456,6 +472,11 @@ void e2d::ENode::setAnchor(float anchorX, float anchorY) m_bTransformChildrenNeeded = true; } +void e2d::ENode::setGeometry(EGeometry * geometry) +{ + EPhysicsManager::bindWith(geometry, this); +} + void e2d::ENode::addChild(ENode * child, int order /* = 0 */) { WARN_IF(child == nullptr, "ENode::addChild NULL pointer exception."); diff --git a/Easy2D/Node/ESprite.cpp b/Easy2D/Node/ESprite.cpp index 66cffd9a..9c637e4a 100644 --- a/Easy2D/Node/ESprite.cpp +++ b/Easy2D/Node/ESprite.cpp @@ -24,24 +24,24 @@ e2d::ESprite::ESprite(ESpriteFrame * spriteFrame) e2d::ESprite::ESprite(const EString & imageFileName) : ESprite() { - loadFrom(new ETexture(imageFileName)); + loadFrom(imageFileName); } e2d::ESprite::ESprite(const EString & imageFileName, float x, float y, float width, float height) { - loadFrom(new ETexture(imageFileName)); + loadFrom(imageFileName); clip(x, y, width, height); } e2d::ESprite::ESprite(const EString & resourceName, const EString & resourceType) : ESprite() { - loadFrom(new ETexture(resourceName, resourceType)); + loadFrom(resourceName, resourceType); } e2d::ESprite::ESprite(const EString & resourceName, const EString & resourceType, float x, float y, float width, float height) { - loadFrom(new ETexture(resourceName, resourceType)); + loadFrom(resourceName, resourceType); clip(x, y, width, height); } @@ -64,6 +64,16 @@ void e2d::ESprite::loadFrom(ETexture * texture) } } +void e2d::ESprite::loadFrom(const EString & imageFileName) +{ + loadFrom(new ETexture(imageFileName)); +} + +void e2d::ESprite::loadFrom(const EString & resourceName, const EString & resourceType) +{ + loadFrom(new ETexture(resourceName, resourceType)); +} + void e2d::ESprite::loadFrom(ETexture * texture, float x, float y, float width, float height) { loadFrom(texture); diff --git a/Easy2D/Node/EText.cpp b/Easy2D/Node/EText.cpp index 77707766..dfedb8cf 100644 --- a/Easy2D/Node/EText.cpp +++ b/Easy2D/Node/EText.cpp @@ -2,8 +2,7 @@ #include "..\Win\winbase.h" e2d::EText::EText() - : m_Color(EColor::WHITE) - , m_bWordWrapping(false) + : m_bWordWrapping(false) , m_pFont(nullptr) , m_fWordWrappingWidth(0) { @@ -23,19 +22,17 @@ e2d::EText::EText(EFont * font) this->setFont(font); } -e2d::EText::EText(const EString & text, EColor color, EFont * font) +e2d::EText::EText(const EString & text, EFont * font) : EText() { this->setText(text); - this->setColor(color); this->setFont(font); } -e2d::EText::EText(const EString & text, EColor color, EString fontFamily, float fontSize, EFontWeight fontWeight, bool italic) +e2d::EText::EText(const EString & text, EString fontFamily, float fontSize, UINT32 color, UINT32 fontWeight, bool italic) { this->setText(text); - this->setColor(color); - this->setFont(new EFont(fontFamily, fontSize, fontWeight, italic)); + this->setFont(new EFont(fontFamily, fontSize, color, fontWeight, italic)); } e2d::EText::~EText() @@ -58,11 +55,6 @@ float e2d::EText::getRealWidth() const return m_fWordWrappingWidth; } -e2d::EColor e2d::EText::getColor() const -{ - return m_Color; -} - e2d::EFont * e2d::EText::getFont() const { return m_pFont; @@ -74,11 +66,6 @@ void e2d::EText::setText(const EString & text) _initTextLayout(); } -void e2d::EText::setColor(EColor color) -{ - m_Color = color; -} - void e2d::EText::setFont(EFont * font) { if (font) @@ -105,7 +92,7 @@ void e2d::EText::setWordWrappingWidth(float wordWrapWidth) void e2d::EText::_onRender() { - GetSolidColorBrush()->SetColor(D2D1::ColorF(m_Color.value, m_fDisplayOpacity)); + GetSolidColorBrush()->SetColor(D2D1::ColorF(m_pFont->m_Color, m_fDisplayOpacity)); GetRenderTarget()->DrawTextW( m_sText.c_str(), UINT32(m_sText.length()), diff --git a/Easy2D/Tool/ETimer.cpp b/Easy2D/Tool/ETimer.cpp index 2aa2f5b5..a3a0353b 100644 --- a/Easy2D/Tool/ETimer.cpp +++ b/Easy2D/Tool/ETimer.cpp @@ -1,10 +1,10 @@ #include "..\etools.h" +#include "..\emanagers.h" #include "..\Win\winbase.h" e2d::ETimer::ETimer() : m_bRunning(false) , m_nRunTimes(0) - , m_pParentScene(nullptr) , m_pParentNode(nullptr) , m_Callback([](int) {}) , m_nInterval(0) @@ -53,11 +53,6 @@ e2d::EString e2d::ETimer::getName() const return m_sName; } -e2d::EScene * e2d::ETimer::getParentScene() const -{ - return m_pParentScene; -} - e2d::ENode * e2d::ETimer::getParentNode() const { return m_pParentNode; diff --git a/Easy2D/Transition/ETransitionEmerge.cpp b/Easy2D/Transition/ETransitionEmerge.cpp index 5d27eb84..246963dd 100644 --- a/Easy2D/Transition/ETransitionEmerge.cpp +++ b/Easy2D/Transition/ETransitionEmerge.cpp @@ -1,6 +1,6 @@ #include "..\etransitions.h" #include "..\eactions.h" -#include "..\etools.h" +#include "..\emanagers.h" e2d::ETransitionEmerge::ETransitionEmerge(float emergeDuration) : m_fEmergeDuration(emergeDuration) diff --git a/Easy2D/Transition/ETransitionFade.cpp b/Easy2D/Transition/ETransitionFade.cpp index 05ac9070..961361a9 100644 --- a/Easy2D/Transition/ETransitionFade.cpp +++ b/Easy2D/Transition/ETransitionFade.cpp @@ -1,6 +1,6 @@ #include "..\etransitions.h" #include "..\eactions.h" -#include "..\etools.h" +#include "..\emanagers.h" e2d::ETransitionFade::ETransitionFade(float fadeOutDuration, float fadeInDuration) : m_fFadeOutDuration(fadeOutDuration) diff --git a/Easy2D/Transition/ETransitionMove.cpp b/Easy2D/Transition/ETransitionMove.cpp index 77bcbd4f..d2d88a4b 100644 --- a/Easy2D/Transition/ETransitionMove.cpp +++ b/Easy2D/Transition/ETransitionMove.cpp @@ -1,6 +1,6 @@ #include "..\etransitions.h" #include "..\eactions.h" -#include "..\etools.h" +#include "..\emanagers.h" e2d::ETransitionMove::ETransitionMove(float moveDuration, MOVE_DIRECT direct) : m_fMoveDuration(moveDuration) diff --git a/Easy2D/Transition/ETransitionScale.cpp b/Easy2D/Transition/ETransitionScale.cpp index ec547fc2..6dfb2515 100644 --- a/Easy2D/Transition/ETransitionScale.cpp +++ b/Easy2D/Transition/ETransitionScale.cpp @@ -1,6 +1,6 @@ #include "..\etransitions.h" #include "..\eactions.h" -#include "..\etools.h" +#include "..\emanagers.h" e2d::ETransitionScale::ETransitionScale(float scaleOutDuration, float scaleInDuration) : m_fScaleOutDuration(scaleOutDuration) diff --git a/Easy2D/Transition/ETransitionScaleEmerge.cpp b/Easy2D/Transition/ETransitionScaleEmerge.cpp index 3d0b0b7e..90f1f278 100644 --- a/Easy2D/Transition/ETransitionScaleEmerge.cpp +++ b/Easy2D/Transition/ETransitionScaleEmerge.cpp @@ -1,6 +1,6 @@ #include "..\etransitions.h" #include "..\eactions.h" -#include "..\etools.h" +#include "..\emanagers.h" e2d::ETransitionScaleEmerge::ETransitionScaleEmerge(float duration, SCALE_EMERGE_MODE mode) : m_fDuration(duration) diff --git a/Easy2D/easy2d.h b/Easy2D/easy2d.h index 76c3a9de..223b2079 100644 --- a/Easy2D/easy2d.h +++ b/Easy2D/easy2d.h @@ -19,11 +19,13 @@ #include "emacros.h" #include "ecommon.h" #include "ebase.h" +#include "emanagers.h" #include "enodes.h" -#include "emsg.h" +#include "elisteners.h" #include "etools.h" #include "eactions.h" #include "etransitions.h" +#include "egeometry.h" #if defined(DEBUG) || defined(_DEBUG) diff --git a/Easy2D/ebase.h b/Easy2D/ebase.h index 862f6985..04bbabae 100644 --- a/Easy2D/ebase.h +++ b/Easy2D/ebase.h @@ -13,6 +13,7 @@ class ENode; class EObjectManager; class EMouseListener; class EKeyboardListener; +class EAction; class ETransition; class EApp @@ -143,7 +144,7 @@ public: // 修改窗口背景色 static void setBkColor( - EColor color + UINT32 color ); // 设置程序是否响应输入法 @@ -200,7 +201,7 @@ protected: bool m_bTopMost; EString m_sTitle; EString m_sAppName; - EColor m_ClearColor; + UINT32 m_ClearColor; LONGLONG nAnimationInterval; EScene * m_pCurrentScene; EScene * m_pNextScene; @@ -292,6 +293,11 @@ public: // 清空所有子成员 void clearAllChildren(); + // 执行动画 + void runAction( + EAction * action + ); + // 绑定鼠标消息监听器 void bindListener(EMouseListener * listener); diff --git a/Easy2D/ecommon.h b/Easy2D/ecommon.h index 723b8968..1de5cf97 100644 --- a/Easy2D/ecommon.h +++ b/Easy2D/ecommon.h @@ -7,52 +7,51 @@ namespace e2d { -typedef std::wstring EString; - -template -using EVector = std::vector; - struct EWindowStyle { + LPCTSTR m_pIconID; /* 程序图标 ID */ + bool m_bNoClose; /* 禁用关闭按钮 */ + bool m_bNoMiniSize; /* 禁用最小化按钮 */ + bool m_bTopMost; /* 窗口置顶 */ + EWindowStyle() { - ICON_ID = 0; - NO_CLOSE = false; - NO_MINI_SIZE = false; - TOP_MOST = false; + m_pIconID = 0; + m_bNoClose = false; + m_bNoMiniSize = false; + m_bTopMost = false; } EWindowStyle( - LPCTSTR ICON_ID + LPCTSTR pIconID ) { - this->ICON_ID = ICON_ID; - NO_CLOSE = false; - NO_MINI_SIZE = false; - TOP_MOST = false; + m_pIconID = pIconID; + m_bNoClose = false; + m_bNoMiniSize = false; + m_bTopMost = false; } EWindowStyle( - LPCTSTR ICON_ID, - bool NO_CLOSE, - bool NO_MINI_SIZE, - bool TOP_MOST + LPCTSTR pIconID, + bool bNoClose, + bool bNoMiniSize, + bool bTopMost ) { - this->ICON_ID = ICON_ID; - this->NO_CLOSE = NO_CLOSE; - this->NO_MINI_SIZE = NO_MINI_SIZE; - this->TOP_MOST = TOP_MOST; + m_pIconID = pIconID; + m_bNoClose = bNoClose; + m_bNoMiniSize = bNoMiniSize; + m_bTopMost = bTopMost; } - - LPCTSTR ICON_ID; /* 程序图标 ID */ - bool NO_CLOSE; /* 禁用关闭按钮 */ - bool NO_MINI_SIZE; /* 禁用最小化按钮 */ - bool TOP_MOST; /* 窗口置顶 */ }; + struct EPoint { + float x; + float y; + EPoint() { x = 0; @@ -74,15 +73,15 @@ struct EPoint { return EPoint(x - p.x, y - p.y); } - - float x; - float y; }; typedef EPoint EVec; struct ESize { + float width; + float height; + ESize() { width = 0; @@ -104,46 +103,43 @@ struct ESize { return ESize(width - size.width, height - size.height); } - - float width; - float height; }; +typedef std::wstring EString; + +template +using EVector = std::vector; + // 定时器回调函数(参数为该定时器被调用的次数,从 0 开始) typedef std::function TIMER_CALLBACK; + // 按钮点击回调函数 typedef std::function BUTTON_CLICK_CALLBACK; + // 按键消息监听回调函数 typedef std::function KEY_LISTENER_CALLBACK; + // 鼠标消息监听回调函数 typedef std::function MOUSE_LISTENER_CALLBACK; + // 鼠标点击消息监听回调函数(参数为点击位置) typedef std::function MOUSE_CLICK_LISTENER_CALLBACK; + // 鼠标按下消息监听回调函数(参数为按下位置) typedef MOUSE_CLICK_LISTENER_CALLBACK MOUSE_PRESS_LISTENER_CALLBACK; + // 鼠标双击消息监听回调函数(参数为双击位置) typedef MOUSE_CLICK_LISTENER_CALLBACK MOUSE_DBLCLK_LISTENER_CALLBACK; + // 鼠标拖动消息监听函数(参数为拖动前位置和拖动后位置) typedef std::function MOUSE_DRAG_LISTENER_CALLBACK; - class EColor { public: - - EColor() - { - value = VALUE::WHITE; - } - - EColor(int color) - { - value = VALUE(color); - } - - enum VALUE + enum COMMON_VALUE { ALICE_BLUE = 0xF0F8FF, ANTIQUE_WHITE = 0xFAEBD7, @@ -286,26 +282,13 @@ public: YELLOW = 0xFFFF00, YELLOW_GREEN = 0x9ACD32 }; - - VALUE value; }; class EFontWeight { public: - - EFontWeight() - { - value = VALUE::REGULAR; - } - - EFontWeight(int fontWeight) - { - value = VALUE(fontWeight); - } - - enum VALUE + enum COMMON_VALUE { THIN = 100, EXTRA_LIGHT = 200, @@ -325,8 +308,138 @@ public: EXTRA_BLACK = 950, ULTRA_BLACK = 950 }; +}; - VALUE value; + +// 鼠标消息 +class EMouseMsg +{ +public: + // 鼠标消息集合 + enum MOUSE_MSG + { + MOVE = 0x0200, // 鼠标移动 + LBUTTON_DOWN, // 鼠标左键按下 + LBUTTON_UP, // 鼠标左键抬起 + LBUTTON_DBLCLK, // 鼠标左键双击 + RBUTTON_DOWN, // 鼠标右键按下 + RBUTTON_UP, // 鼠标右键抬起 + RBUTTON_DBLCLK, // 鼠标右键双击 + MBUTTON_DOWN, // 鼠标中键按下 + MBUTTON_UP, // 鼠标中键抬起 + MBUTTON_DBLCLK, // 鼠标中键双击 + WHEEL // 滑动滚轮 + }; + + // 获取鼠标横坐标 + static DWORD getPosX(); + + // 获取鼠标纵坐标 + static DWORD getPosY(); + + // 获取鼠标坐标 + static EPoint getPos(); + + // 获取鼠标左键按下状态 + static bool isLButtonDown(); + + // 获取鼠标中键按下状态 + static bool isMButtonDown(); + + // 获取鼠标右键按下状态 + static bool isRButtonDown(); + + // 获取 Shift 按键状态 + static bool isShiftDown(); + + // 获取 Ctrl 按键状态 + static bool isCtrlDown(); + + // 获取鼠标滚轮值 + static DWORD getWheelDelta(); + + // 获取当前鼠标消息类型 + static MOUSE_MSG getMsg(); + + // 获取当前鼠标消息 + static EMouseMsg & getMouseMsg(); + +public: + UINT m_nMsg = 0; + WPARAM m_wParam = 0; + LPARAM m_lParam = 0; +}; + + +// 按键消息 +class EKeyboardMsg +{ +public: + // 按键消息类型集合 + enum KEYBOARD_MSG + { + KEY_DOWN = 0x0100, // 按下 + KEY_UP // 抬起 + }; + + // 按键键值集合 + enum class KEY + { + A = 'A', B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, // 字母键值 + NUM0 = '0', NUM1, NUM2, NUM3, NUM4, NUM5, NUM6, NUM7, NUM8, NUM9, // 数字键值 + NUMPAD0 = 0x60, NUMPAD1, NUMPAD2, NUMPAD3, NUMPAD4, NUMPAD5, NUMPAD6, NUMPAD7, NUMPAD8, NUMPAD9, // 数字小键盘键值 + F1 = 0x70, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, // F键键值 + MULTIPLY, // 乘号键键值 + ADD, // 加号键键值 + SEPARATOR, // 分割键键值 + SUBTRACT, // 减号键键值 + DECIMAL, // 小数点键键值 + DIVIDE, // 除号键键值 + TAB = 0x09, // TAB 键键值 + ENTER = 0x0D, // 回车键键值 + SHIFT, CTRL, // SHIFT 键键值 + ESC = 0x1B, // ESCAPE 键键值 + SPACE = 0x20, // 空格键键值 + PAGE_UP, // PageUp 键键值 + PAGE_DOWN, // PageDown 键键值 + END, // End 键键值 + HOME, // Home 键键值 + LEFT, // 左键键值 + UP, // 上键键值 + RIGHT, // 右键键值 + DOWN // 下键键值 + }; + + // 获取按键消息类型 + static KEYBOARD_MSG getMsg(); + + // 获取键值 + static KEY getVal(); + + // 获取按键消息的计数 + static DWORD getCount(); + + // 获取特定按键的状态 + static bool isKeyDown( + KEY key + ); + + // 获取大小写锁定状态 + static bool isCapitalLockOn(); + + // 获取数字小键盘锁定状态 + static bool isNumpadLockOn(); + + // 获取滑动锁定状态 + static bool isScrollLockOn(); + + // 获取当前按键消息 + static EKeyboardMsg & getKeyboardMsg(); + +public: + UINT m_nMsg = 0; + WPARAM m_wParam = 0; + LPARAM m_lParam = 0; }; } \ No newline at end of file diff --git a/Easy2D/egeometry.h b/Easy2D/egeometry.h new file mode 100644 index 00000000..c5b4a76a --- /dev/null +++ b/Easy2D/egeometry.h @@ -0,0 +1,114 @@ +#pragma once +#include "ebase.h" + + +namespace e2d +{ + +class EPhysicsManager; + +class EGeometry : + public EObject +{ + friend EPhysicsManager; +public: + EGeometry(); + +protected: + virtual bool _isCollisionWith( + EGeometry * pGeometry + ); + + virtual ID2D1Geometry * _getD2dGeometry() const = 0; + +protected: + bool m_bTransformed; + ENode * m_pParentNode; +}; + + +class ERectangle : + public EGeometry +{ +public: + // 创建一个空矩形 + ERectangle(); + + // 根据左上角坐标和宽高创建矩形 + ERectangle( + float x, + float y, + float width, + float height + ); + + // 创建一个和节点位置大小相同的矩形 + ERectangle( + ENode * node + ); + +protected: + void _setRect( + float left, + float top, + float right, + float bottom + ); + + virtual ID2D1RectangleGeometry * _getD2dGeometry() const override; + +protected: + ID2D1RectangleGeometry * m_pD2dRectangle; +}; + + +class ECircle : + public EGeometry +{ +public: + ECircle(); + + ECircle( + EPoint center, + float radius + ); + +protected: + void _setCircle( + EPoint center, + float radius + ); + + virtual ID2D1EllipseGeometry * _getD2dGeometry() const override; + +protected: + ID2D1EllipseGeometry * m_pD2dCircle; +}; + + +class EEllipse : + public EGeometry +{ +public: + EEllipse(); + + EEllipse( + EPoint center, + float radiusX, + float radiusY + ); + +protected: + void _setEllipse( + EPoint center, + float radiusX, + float radiusY + ); + + virtual ID2D1EllipseGeometry * _getD2dGeometry() const override; + +protected: + ID2D1EllipseGeometry * m_pD2dEllipse; +}; + +} \ No newline at end of file diff --git a/Easy2D/elisteners.h b/Easy2D/elisteners.h new file mode 100644 index 00000000..4283c062 --- /dev/null +++ b/Easy2D/elisteners.h @@ -0,0 +1,324 @@ +#pragma once +#include "ebase.h" + +namespace e2d +{ + +class ENode; +class EMsgManager; + + +// 监听器 +class EListener : + public EObject +{ + friend EMsgManager; + +public: + EListener(); + + EListener( + const EString &name + ); + + // 获取监听器状态 + bool isRunning() const; + + // 启动监听 + void start(); + + // 停止监听 + void stop(); + + // 获取监听器名称 + EString getName() const; + + // 获取监听器所在节点 + ENode * getParentNode() const; + + // 设置监听器名称 + void setName( + const EString &name + ); + + // 绑定监听器到场景 + virtual void bindWith( + EScene * pParentScene + ) = 0; + + // 绑定监听器到节点 + virtual void bindWith( + ENode * pParentNode + ) = 0; + +protected: + // 执行监听器回调函数 + virtual void _callOn() = 0; + +protected: + EString m_sName; + bool m_bRunning; + bool m_bAlways; + ENode * m_pParentNode; +}; + + +// 鼠标消息监听器 +class EMouseListener : + public EListener +{ + friend EMsgManager; + +public: + EMouseListener(); + + EMouseListener( + const EString &name + ); + + EMouseListener( + const MOUSE_LISTENER_CALLBACK &callback + ); + + EMouseListener( + const EString &name, + const MOUSE_LISTENER_CALLBACK &callback + ); + + // 设置监听器回调函数 + void setCallback( + const MOUSE_LISTENER_CALLBACK &callback + ); + + // 绑定监听器到场景 + virtual void bindWith( + EScene * pParentScene + ) override; + + // 绑定监听器到节点 + virtual void bindWith( + ENode * pParentNode + ) override; + +protected: + // 执行监听器回调函数 + virtual void _callOn() override; + +protected: + MOUSE_LISTENER_CALLBACK m_Callback; +}; + + +// 鼠标按下消息监听器 +class EMousePressListener : + public EMouseListener +{ +public: + EMousePressListener(); + + EMousePressListener( + const EString &name + ); + + EMousePressListener( + const MOUSE_PRESS_LISTENER_CALLBACK &callback + ); + + EMousePressListener( + const EString &name, + const MOUSE_PRESS_LISTENER_CALLBACK &callback + ); + + // 设置监听器回调函数 + void setCallback( + const MOUSE_PRESS_LISTENER_CALLBACK &callback + ); + +protected: + // 执行监听器回调函数 + virtual void _callOn() override; + +protected: + MOUSE_PRESS_LISTENER_CALLBACK m_Callback; +}; + + +// 鼠标点击消息监听器 +class EMouseClickListener : + public EMouseListener +{ +public: + EMouseClickListener(); + + EMouseClickListener( + const EString &name + ); + + EMouseClickListener( + const MOUSE_CLICK_LISTENER_CALLBACK &callback + ); + + EMouseClickListener( + const EString &name, + const MOUSE_CLICK_LISTENER_CALLBACK &callback + ); + + // 设置监听器回调函数 + void setCallback( + const MOUSE_CLICK_LISTENER_CALLBACK &callback + ); + +protected: + // 执行监听器回调函数 + virtual void _callOn() override; + +protected: + bool m_bPressed; + MOUSE_CLICK_LISTENER_CALLBACK m_Callback; +}; + + +// 鼠标点击消息监听器 +class EMouseDoubleClickListener : + public EMouseListener +{ +public: + EMouseDoubleClickListener(); + + EMouseDoubleClickListener( + const EString &name + ); + + EMouseDoubleClickListener( + const MOUSE_DBLCLK_LISTENER_CALLBACK &callback + ); + + EMouseDoubleClickListener( + const EString &name, + const MOUSE_DBLCLK_LISTENER_CALLBACK &callback + ); + + // 设置监听器回调函数 + void setCallback( + const MOUSE_DBLCLK_LISTENER_CALLBACK &callback + ); + +protected: + // 执行监听器回调函数 + virtual void _callOn() override; + +protected: + bool m_bPressed; + MOUSE_DBLCLK_LISTENER_CALLBACK m_Callback; +}; + + +// 鼠标拖动消息监听器 +class EMouseDragListener : + public EMouseListener +{ +public: + EMouseDragListener(); + + EMouseDragListener( + const EString &name + ); + + EMouseDragListener( + const MOUSE_DRAG_LISTENER_CALLBACK &callback + ); + + EMouseDragListener( + const EString &name, + const MOUSE_DRAG_LISTENER_CALLBACK &callback + ); + + // 设置监听器回调函数 + void setCallback( + const MOUSE_DRAG_LISTENER_CALLBACK &callback + ); + +protected: + // 执行监听器回调函数 + virtual void _callOn() override; + +protected: + EPoint m_Begin; + MOUSE_DRAG_LISTENER_CALLBACK m_Callback; +}; + + +// 按键消息监听器 +class EKeyboardListener : + public EListener +{ + friend EMsgManager; + +public: + EKeyboardListener(); + + EKeyboardListener( + const EString &name + ); + + EKeyboardListener( + const KEY_LISTENER_CALLBACK &callback + ); + + EKeyboardListener( + const EString &name, + const KEY_LISTENER_CALLBACK &callback + ); + + // 设置监听器回调函数 + void setCallback( + const KEY_LISTENER_CALLBACK &callback + ); + + // 绑定监听器到场景 + virtual void bindWith( + EScene * pParentScene + ) override; + + // 绑定监听器到节点 + virtual void bindWith( + ENode * pParentNode + ) override; + +protected: + // 执行监听器回调函数 + virtual void _callOn() override; + +protected: + KEY_LISTENER_CALLBACK m_Callback; +}; + + +// 按键按下消息监听 +class EKeyboardPressListener : + public EKeyboardListener +{ + friend EMsgManager; + +public: + EKeyboardPressListener(); + + EKeyboardPressListener( + const EString &name + ); + + EKeyboardPressListener( + const KEY_LISTENER_CALLBACK &callback + ); + + EKeyboardPressListener( + const EString &name, + const KEY_LISTENER_CALLBACK &callback + ); + +protected: + // 执行监听器回调函数 + virtual void _callOn() override; +}; + +} \ No newline at end of file diff --git a/Easy2D/emanagers.h b/Easy2D/emanagers.h new file mode 100644 index 00000000..b5016550 --- /dev/null +++ b/Easy2D/emanagers.h @@ -0,0 +1,331 @@ +#pragma once +#include "emacros.h" +#include "ecommon.h" + +namespace e2d +{ + +class EApp; +class EObject; +class EScene; +class ENode; +class ETimer; +class EAction; +class EMouseListener; +class EKeyboardListener; + +// 对象管理器 +class EObjectManager +{ + friend EApp; + +public: + // 将一个节点放入内存池 + static void add( + e2d::EObject * nptr + ); + + // 通知内存池刷新 + static void notifyFlush(); + +private: + // 刷新内存池 + static void __flush(); +}; + + +// 消息管理器 +class EMsgManager +{ + friend EApp; + friend EScene; + friend ENode; + +public: + // 绑定鼠标消息监听器到场景 + static void bindListener( + EMouseListener * listener, + EScene * pParentScene, + bool always = false /* 是否在游戏暂停时仍然监听 */ + ); + + // 绑定鼠标消息监听器到节点 + static void bindListener( + EMouseListener * listener, + ENode * pParentNode, + bool always = false /* 是否在游戏暂停时仍然监听 */ + ); + + // 启动具有相同名称的鼠标消息监听器 + static void startMouseListeners( + const EString &name + ); + + // 停止具有相同名称的鼠标消息监听器 + static void stopMouseListeners( + const EString &name + ); + + // 删除具有相同名称的鼠标消息监听器 + static void delMouseListeners( + const EString &name + ); + + // 启动绑定在场景及其子节点上的所有鼠标消息监听器 + static void startAllMouseListenersBindedWith( + EScene * pParentScene + ); + + // 停止绑定在场景及其子节点上的所有鼠标消息监听器 + static void stopAllMouseListenersBindedWith( + EScene * pParentScene + ); + + // 启动绑定在节点上的所有鼠标消息监听器 + static void startAllMouseListenersBindedWith( + ENode * pParentNode + ); + + // 停止绑定在节点上的所有鼠标消息监听器 + static void stopAllMouseListenersBindedWith( + ENode * pParentNode + ); + + // 启动所有鼠标消息监听器 + static void startAllMouseListeners(); + + // 停止所有鼠标消息监听器 + static void stopAllMouseListeners(); + + // 绑定按键消息监听器到场景 + static void bindListener( + EKeyboardListener * listener, + EScene * pParentScene, + bool always = false /* 是否在游戏暂停时仍然监听 */ + ); + + // 绑定按键消息监听器到节点 + static void bindListener( + EKeyboardListener * listener, + ENode * pParentNode, + bool always = false /* 是否在游戏暂停时仍然监听 */ + ); + + // 启动名称相同的按键消息监听器 + static void startKeyboardListeners( + const EString &name + ); + + // 停止名称相同的按键消息监听器 + static void stopKeyboardListeners( + const EString &name + ); + + // 删除名称相同的按键消息监听器 + static void delKeyboardListeners( + const EString &name + ); + + // 启动绑定在场景及其子节点上的所有按键消息监听器 + static void startAllKeyboardListenersBindedWith( + EScene * pParentScene + ); + + // 停止绑定在场景及其子节点上的所有按键消息监听器 + static void stopAllKeyboardListenersBindedWith( + EScene * pParentScene + ); + + // 启动绑定在节点上的所有按键消息监听器 + static void startAllKeyboardListenersBindedWith( + ENode * pParentNode + ); + + // 停止绑定在节点上的所有按键消息监听器 + static void stopAllKeyboardListenersBindedWith( + ENode * pParentNode + ); + + // 启动所有按键消息监听器 + static void startAllKeyboardListeners(); + + // 停止所有按键消息监听器 + static void stopAllKeyboardListeners(); + +private: + // 清除所有监听器 + static void _clearManager(); + + // 清除绑定在节点上的所有鼠标消息监听器 + static void _clearAllMouseListenersBindedWith( + ENode * pParentNode + ); + + // 清除绑定在节点上的所有按键消息监听器 + static void _clearAllKeyboardListenersBindedWith( + ENode * pParentNode + ); + + // 鼠标消息程序 + static void MouseProc( + UINT message, + WPARAM wParam, + LPARAM lParam + ); + + // 按键消息程序 + static void KeyboardProc( + UINT message, + WPARAM wParam, + LPARAM lParam + ); +}; + + +// 定时器管理器 +class ETimerManager +{ + friend EApp; + friend EScene; + friend ENode; + +public: + // 绑定定时器到场景 + static void bindTimer( + ETimer * timer, + EScene * pParentScene + ); + + // 绑定定时器到节点 + static void bindTimer( + ETimer * timer, + ENode * pParentNode + ); + + // 启动具有相同名称的定时器 + static void startTimers( + const EString &name + ); + + // 停止具有相同名称的定时器 + static void stopTimers( + const EString &name + ); + + // 删除具有相同名称的定时器 + static void delTimers( + const EString &name + ); + + // 启动绑定在场景及其子节点上的所有定时器 + static void startAllTimersBindedWith( + EScene * pParentScene + ); + + // 停止绑定在场景及其子节点上的所有定时器 + static void stopAllTimersBindedWith( + EScene * pParentScene + ); + + // 启动绑定在节点上的所有定时器 + static void startAllTimersBindedWith( + ENode * pParentNode + ); + + // 停止绑定在节点上的所有定时器 + static void stopAllTimersBindedWith( + ENode * pParentNode + ); + + // 启动所有定时器 + static void startAllTimers(); + + // 停止所有定时器 + static void stopAllTimers(); + +private: + // 清空定时器管理器 + static void _clearManager(); + + // 清空绑定在节点上的所有定时器 + static void _clearAllTimersBindedWith( + ENode * pParentNode + ); + + // 重置定时器状态 + static void _resetAllTimers(); + + // 定时器执行程序 + static void TimerProc(); +}; + + +// 动作管理器 +class EActionManager +{ + friend EApp; + friend EScene; + friend ENode; + +public: + // 添加动作 + static void addAction( + EAction * action + ); + + // 继续绑定在节点上的所有动作 + static void startAllActionsBindedWith( + ENode * pTargetNode + ); + + // 暂停绑定在节点上的所有动作 + static void pauseAllActionsBindedWith( + ENode * pTargetNode + ); + + // 停止绑定在节点上的所有动作 + static void stopAllActionsBindedWith( + ENode * pTargetNode + ); + + // 继续所有动作 + static void startAllActions(); + + // 暂停所有动作 + static void pauseAllActions(); + + // 停止所有动作 + static void stopAllActions(); + +private: + // 清空动画管理器 + static void _clearManager(); + + // 清空绑定在节点上的所有动作 + static void _clearAllActionsBindedWith( + ENode * pTargetNode + ); + + // 重置所有动作状态 + static void _resetAllActions(); + + // 动作执行程序 + static void ActionProc(); +}; + + +class EPhysicsManager +{ +public: + // 绑定形状到节点 + static void bindWith( + EGeometry * geometry, + ENode * node + ); + +protected: + // 物理引擎执行程序 + static void PhysicsProc(); +}; + +} \ No newline at end of file diff --git a/Easy2D/emsg.h b/Easy2D/emsg.h deleted file mode 100644 index 96d7a6f3..00000000 --- a/Easy2D/emsg.h +++ /dev/null @@ -1,615 +0,0 @@ -#pragma once -#include "ebase.h" - -namespace e2d -{ - -class ENode; -class EMsgManager; - -// 鼠标消息 -class EMouseMsg -{ - friend EMsgManager; - -public: - // 鼠标消息集合 - enum MOUSE_MSG - { - MOVE = 0x0200, // 鼠标移动 - LBUTTON_DOWN, // 鼠标左键按下 - LBUTTON_UP, // 鼠标左键抬起 - LBUTTON_DBLCLK, // 鼠标左键双击 - RBUTTON_DOWN, // 鼠标右键按下 - RBUTTON_UP, // 鼠标右键抬起 - RBUTTON_DBLCLK, // 鼠标右键双击 - MBUTTON_DOWN, // 鼠标中键按下 - MBUTTON_UP, // 鼠标中键抬起 - MBUTTON_DBLCLK, // 鼠标中键双击 - WHEEL // 滑动滚轮 - }; - - // 获取鼠标横坐标 - static DWORD getPosX(); - - // 获取鼠标纵坐标 - static DWORD getPosY(); - - // 获取鼠标坐标 - static EPoint getPos(); - - // 获取鼠标左键按下状态 - static bool isLButtonDown(); - - // 获取鼠标中键按下状态 - static bool isMButtonDown(); - - // 获取鼠标右键按下状态 - static bool isRButtonDown(); - - // 获取 Shift 按键状态 - static bool isShiftDown(); - - // 获取 Ctrl 按键状态 - static bool isCtrlDown(); - - // 获取鼠标滚轮值 - static DWORD getWheelDelta(); - - // 获取当前鼠标消息 - static MOUSE_MSG getMsg(); - -protected: - UINT m_nMsg = 0; - WPARAM m_wParam = 0; - LPARAM m_lParam = 0; -}; - - -// 按键消息 -class EKeyboardMsg -{ - friend EMsgManager; - -public: - // 按键消息类型集合 - enum KEYBOARD_MSG - { - KEY_DOWN = 0x0100, // 按下 - KEY_UP // 抬起 - }; - - // 按键键值集合 - enum class KEY - { - A = 'A', B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, // 字母键值 - NUM0 = '0', NUM1, NUM2, NUM3, NUM4, NUM5, NUM6, NUM7, NUM8, NUM9, // 数字键值 - NUMPAD0 = 0x60, NUMPAD1, NUMPAD2, NUMPAD3, NUMPAD4, NUMPAD5, NUMPAD6, NUMPAD7, NUMPAD8, NUMPAD9, // 数字小键盘键值 - F1 = 0x70, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, // F键键值 - MULTIPLY, // 乘号键键值 - ADD, // 加号键键值 - SEPARATOR, // 分割键键值 - SUBTRACT, // 减号键键值 - DECIMAL, // 小数点键键值 - DIVIDE, // 除号键键值 - TAB = 0x09, // TAB 键键值 - ENTER = 0x0D, // 回车键键值 - SHIFT, CTRL, // SHIFT 键键值 - ESC = 0x1B, // ESCAPE 键键值 - SPACE = 0x20, // 空格键键值 - PAGE_UP, // PageUp 键键值 - PAGE_DOWN, // PageDown 键键值 - END, // End 键键值 - HOME, // Home 键键值 - LEFT, // 左键键值 - UP, // 上键键值 - RIGHT, // 右键键值 - DOWN // 下键键值 - }; - - // 获取按键消息类型 - static KEYBOARD_MSG getMsg(); - - // 获取键值 - static KEY getVal(); - - // 获取按键消息的计数 - static DWORD getCount(); - - // 获取特定按键的状态 - static bool isKeyDown( - KEY key - ); - - // 获取大小写锁定状态 - static bool isCapitalLockOn(); - - // 获取数字小键盘锁定状态 - static bool isNumpadLockOn(); - - // 获取滑动锁定状态 - static bool isScrollLockOn(); - -protected: - UINT m_nMsg = 0; - WPARAM m_wParam = 0; - LPARAM m_lParam = 0; -}; - - -// 监听器 -class EListener : - public EObject -{ - friend EMsgManager; - -public: - EListener(); - - EListener( - const EString &name - ); - - // 获取监听器状态 - bool isRunning() const; - - // 启动监听 - void start(); - - // 停止监听 - void stop(); - - // 获取监听器名称 - EString getName() const; - - // 获取监听器所在场景 - EScene * getParentScene() const; - - // 获取监听器所在节点 - ENode * getParentNode() const; - - // 设置监听器名称 - void setName( - const EString &name - ); - - // 绑定监听器到场景 - virtual void bindWith( - EScene * pParentScene - ) = 0; - - // 绑定监听器到节点 - virtual void bindWith( - ENode * pParentNode - ) = 0; - -protected: - // 执行监听器回调函数 - virtual void _callOn() = 0; - -protected: - EString m_sName; - bool m_bRunning; - bool m_bAlways; - EScene * m_pParentScene; - ENode * m_pParentNode; -}; - - -// 鼠标消息监听器 -class EMouseListener : - public EListener -{ - friend EMsgManager; - -public: - EMouseListener(); - - EMouseListener( - const EString &name - ); - - EMouseListener( - const MOUSE_LISTENER_CALLBACK &callback - ); - - EMouseListener( - const EString &name, - const MOUSE_LISTENER_CALLBACK &callback - ); - - // 设置监听器回调函数 - void setCallback( - const MOUSE_LISTENER_CALLBACK &callback - ); - - // 绑定监听器到场景 - virtual void bindWith( - EScene * pParentScene - ) override; - - // 绑定监听器到节点 - virtual void bindWith( - ENode * pParentNode - ) override; - -protected: - // 执行监听器回调函数 - virtual void _callOn() override; - -protected: - MOUSE_LISTENER_CALLBACK m_Callback; -}; - - -// 鼠标按下消息监听器 -class EMousePressListener : - public EMouseListener -{ -public: - EMousePressListener(); - - EMousePressListener( - const EString &name - ); - - EMousePressListener( - const MOUSE_PRESS_LISTENER_CALLBACK &callback - ); - - EMousePressListener( - const EString &name, - const MOUSE_PRESS_LISTENER_CALLBACK &callback - ); - - // 设置监听器回调函数 - void setCallback( - const MOUSE_PRESS_LISTENER_CALLBACK &callback - ); - -protected: - // 执行监听器回调函数 - virtual void _callOn() override; - -protected: - MOUSE_PRESS_LISTENER_CALLBACK m_Callback; -}; - - -// 鼠标点击消息监听器 -class EMouseClickListener : - public EMouseListener -{ -public: - EMouseClickListener(); - - EMouseClickListener( - const EString &name - ); - - EMouseClickListener( - const MOUSE_CLICK_LISTENER_CALLBACK &callback - ); - - EMouseClickListener( - const EString &name, - const MOUSE_CLICK_LISTENER_CALLBACK &callback - ); - - // 设置监听器回调函数 - void setCallback( - const MOUSE_CLICK_LISTENER_CALLBACK &callback - ); - -protected: - // 执行监听器回调函数 - virtual void _callOn() override; - -protected: - bool m_bPressed; - MOUSE_CLICK_LISTENER_CALLBACK m_Callback; -}; - - -// 鼠标点击消息监听器 -class EMouseDoubleClickListener : - public EMouseListener -{ -public: - EMouseDoubleClickListener(); - - EMouseDoubleClickListener( - const EString &name - ); - - EMouseDoubleClickListener( - const MOUSE_DBLCLK_LISTENER_CALLBACK &callback - ); - - EMouseDoubleClickListener( - const EString &name, - const MOUSE_DBLCLK_LISTENER_CALLBACK &callback - ); - - // 设置监听器回调函数 - void setCallback( - const MOUSE_DBLCLK_LISTENER_CALLBACK &callback - ); - -protected: - // 执行监听器回调函数 - virtual void _callOn() override; - -protected: - bool m_bPressed; - MOUSE_DBLCLK_LISTENER_CALLBACK m_Callback; -}; - - -// 鼠标拖动消息监听器 -class EMouseDragListener : - public EMouseListener -{ -public: - EMouseDragListener(); - - EMouseDragListener( - const EString &name - ); - - EMouseDragListener( - const MOUSE_DRAG_LISTENER_CALLBACK &callback - ); - - EMouseDragListener( - const EString &name, - const MOUSE_DRAG_LISTENER_CALLBACK &callback - ); - - // 设置监听器回调函数 - void setCallback( - const MOUSE_DRAG_LISTENER_CALLBACK &callback - ); - -protected: - // 执行监听器回调函数 - virtual void _callOn() override; - -protected: - EPoint m_Begin; - MOUSE_DRAG_LISTENER_CALLBACK m_Callback; -}; - - -// 按键消息监听器 -class EKeyboardListener : - public EListener -{ - friend EMsgManager; - -public: - EKeyboardListener(); - - EKeyboardListener( - const EString &name - ); - - EKeyboardListener( - const KEY_LISTENER_CALLBACK &callback - ); - - EKeyboardListener( - const EString &name, - const KEY_LISTENER_CALLBACK &callback - ); - - // 设置监听器回调函数 - void setCallback( - const KEY_LISTENER_CALLBACK &callback - ); - - // 绑定监听器到场景 - virtual void bindWith( - EScene * pParentScene - ) override; - - // 绑定监听器到节点 - virtual void bindWith( - ENode * pParentNode - ) override; - -protected: - // 执行监听器回调函数 - virtual void _callOn() override; - -protected: - KEY_LISTENER_CALLBACK m_Callback; -}; - - -// 按键按下消息监听 -class EKeyboardPressListener : - public EKeyboardListener -{ - friend EMsgManager; - -public: - EKeyboardPressListener(); - - EKeyboardPressListener( - const EString &name - ); - - EKeyboardPressListener( - const KEY_LISTENER_CALLBACK &callback - ); - - EKeyboardPressListener( - const EString &name, - const KEY_LISTENER_CALLBACK &callback - ); - -protected: - // 执行监听器回调函数 - virtual void _callOn() override; -}; - - -// 消息管理器 -class EMsgManager -{ - friend EApp; - friend EScene; - friend ENode; - -public: - // 绑定鼠标消息监听器到场景 - static void bindListener( - EMouseListener * listener, - EScene * pParentScene, - bool always = false /* 是否在游戏暂停时仍然监听 */ - ); - - // 绑定鼠标消息监听器到节点 - static void bindListener( - EMouseListener * listener, - ENode * pParentNode, - bool always = false /* 是否在游戏暂停时仍然监听 */ - ); - - // 启动具有相同名称的鼠标消息监听器 - static void startMouseListeners( - const EString &name - ); - - // 停止具有相同名称的鼠标消息监听器 - static void stopMouseListeners( - const EString &name - ); - - // 删除具有相同名称的鼠标消息监听器 - static void delMouseListeners( - const EString &name - ); - - // 启动绑定在场景及其子节点上的所有鼠标消息监听器 - static void startAllMouseListenersBindedWith( - EScene * pParentScene - ); - - // 停止绑定在场景及其子节点上的所有鼠标消息监听器 - static void stopAllMouseListenersBindedWith( - EScene * pParentScene - ); - - // 启动绑定在节点上的所有鼠标消息监听器 - static void startAllMouseListenersBindedWith( - ENode * pParentNode - ); - - // 停止绑定在节点上的所有鼠标消息监听器 - static void stopAllMouseListenersBindedWith( - ENode * pParentNode - ); - - // 启动所有鼠标消息监听器 - static void startAllMouseListeners(); - - // 停止所有鼠标消息监听器 - static void stopAllMouseListeners(); - - // 绑定按键消息监听器到场景 - static void bindListener( - EKeyboardListener * listener, - EScene * pParentScene, - bool always = false /* 是否在游戏暂停时仍然监听 */ - ); - - // 绑定按键消息监听器到节点 - static void bindListener( - EKeyboardListener * listener, - ENode * pParentNode, - bool always = false /* 是否在游戏暂停时仍然监听 */ - ); - - // 启动名称相同的按键消息监听器 - static void startKeyboardListeners( - const EString &name - ); - - // 停止名称相同的按键消息监听器 - static void stopKeyboardListeners( - const EString &name - ); - - // 删除名称相同的按键消息监听器 - static void delKeyboardListeners( - const EString &name - ); - - // 启动绑定在场景及其子节点上的所有按键消息监听器 - static void startAllKeyboardListenersBindedWith( - EScene * pParentScene - ); - - // 停止绑定在场景及其子节点上的所有按键消息监听器 - static void stopAllKeyboardListenersBindedWith( - EScene * pParentScene - ); - - // 启动绑定在节点上的所有按键消息监听器 - static void startAllKeyboardListenersBindedWith( - ENode * pParentNode - ); - - // 停止绑定在节点上的所有按键消息监听器 - static void stopAllKeyboardListenersBindedWith( - ENode * pParentNode - ); - - // 启动所有按键消息监听器 - static void startAllKeyboardListeners(); - - // 停止所有按键消息监听器 - static void stopAllKeyboardListeners(); - -private: - // 清除所有监听器 - static void _clearManager(); - - // 清除绑定在节点上的所有鼠标消息监听器 - static void _clearAllMouseListenersBindedWith( - ENode * pParentNode - ); - - // 清除绑定在场景及其子节点上的所有按键消息监听器 - static void _clearAllKeyboardListenersBindedWith( - EScene * pParentScene - ); - - // 清除绑定在场景及其子节点上的所有鼠标消息监听器 - static void _clearAllMouseListenersBindedWith( - EScene * pParentScene - ); - - // 清除绑定在节点上的所有按键消息监听器 - static void _clearAllKeyboardListenersBindedWith( - ENode * pParentNode - ); - - // 鼠标消息程序 - static void MouseProc( - UINT message, - WPARAM wParam, - LPARAM lParam - ); - - // 按键消息程序 - static void KeyboardProc( - UINT message, - WPARAM wParam, - LPARAM lParam - ); -}; - -} \ No newline at end of file diff --git a/Easy2D/enodes.h b/Easy2D/enodes.h index 4026997e..a0e8588f 100644 --- a/Easy2D/enodes.h +++ b/Easy2D/enodes.h @@ -8,6 +8,7 @@ class EText; class ESprite; class EAction; class EButton; +class EGeometry; class ENode : public EObject @@ -63,6 +64,12 @@ public: // 获取节点大小(不考虑缩放) virtual ESize getRealSize() const; + // 获取节点的锚点 + virtual float getAnchorX() const; + + // 获取节点的锚点 + virtual float getAnchorY() const; + // 获取节点大小 virtual ESize getSize() const; @@ -224,6 +231,11 @@ public: float anchorY ); + // 设置节点形状 + virtual void setGeometry( + EGeometry * geometry + ); + // 添加子节点 virtual void addChild( ENode * child, @@ -362,6 +374,7 @@ protected: bool m_bDisplayedInScene; bool m_bSortChildrenNeeded; bool m_bTransformChildrenNeeded; + EGeometry * m_pGeometry; EScene * m_pParentScene; ENode * m_pParent; D2D1::Matrix3x2F m_Matri; @@ -569,12 +582,23 @@ public: virtual ~ESprite(); - // 设置精灵纹理 + // 加载精灵纹理 void loadFrom( ETexture * texture ); - // 设置精灵纹理并裁剪 + // 从本地文件加载纹理 + void loadFrom( + const EString & imageFileName + ); + + // 从资源加载纹理 + void loadFrom( + const EString & resourceName, + const EString & resourceType + ); + + // 加载纹理并裁剪 void loadFrom( ETexture * texture, float x, @@ -618,7 +642,8 @@ public: EFont( EString fontFamily, float fontSize = 22, - EFontWeight fontWeight = EFontWeight::REGULAR, + UINT32 color = EColor::WHITE, + UINT32 fontWeight = EFontWeight::REGULAR, bool italic = false ); @@ -628,7 +653,10 @@ public: float getFontSize() const; // 获取当前字体粗细值 - EFontWeight getFontWeight() const; + UINT32 getFontWeight() const; + + // 获取文字颜色 + UINT32 getColor() const; // 是否是斜体 bool isItalic() const; @@ -645,7 +673,12 @@ public: // 设置字体粗细值 void setWeight( - EFontWeight fontWeight + UINT32 fontWeight + ); + + // 设置文字颜色 + void setColor( + UINT32 color ); // 设置文字斜体 @@ -663,7 +696,8 @@ protected: protected: EString m_sFontFamily; float m_fFontSize; - EFontWeight m_FontWeight; + UINT32 m_FontWeight; + UINT32 m_Color; bool m_bItalic; bool m_bRecreateNeeded; IDWriteTextFormat * m_pTextFormat; @@ -686,16 +720,15 @@ public: EText( const EString & text, - EColor color, EFont * font ); EText( const EString & text, - EColor color, EString fontFamily, float fontSize = 22, - EFontWeight fontWeight = EFontWeight::REGULAR, + UINT32 color = EColor::WHITE, + UINT32 fontWeight = EFontWeight::REGULAR, bool italic = false ); @@ -710,9 +743,6 @@ public: // 获取文本宽度(不考虑缩放) virtual float getRealWidth() const override; - // 获取文字颜色 - EColor getColor() const; - // 获取字体 EFont * getFont() const; @@ -721,11 +751,6 @@ public: const EString & text ); - // 设置文字颜色 - void setColor( - EColor color - ); - // 设置字体 void setFont( EFont * font @@ -750,7 +775,6 @@ protected: protected: EString m_sText; - EColor m_Color; bool m_bWordWrapping; float m_fWordWrappingWidth; EFont * m_pFont; diff --git a/Easy2D/etools.h b/Easy2D/etools.h index e0ce187f..f7a4fb55 100644 --- a/Easy2D/etools.h +++ b/Easy2D/etools.h @@ -9,25 +9,6 @@ namespace e2d class ETimerManager; class EAction; -// 对象管理器 -class EObjectManager -{ - friend EApp; - -public: - // 将一个节点放入内存池 - static void add( - e2d::EObject * nptr - ); - - // 通知内存池刷新 - static void notifyFlush(); - -private: - // 刷新内存池 - static void __flush(); -}; - // 定时器 class ETimer : @@ -65,9 +46,6 @@ public: // 获取定时器名称 EString getName() const; - // 获取定时器所在场景 - EScene * getParentScene() const; - // 获取定时器所在节点 ENode * getParentNode() const; @@ -114,7 +92,6 @@ protected: bool m_bAtOnce; int m_nRunTimes; int m_nRepeatTimes; - EScene * m_pParentScene; ENode * m_pParentNode; TIMER_CALLBACK m_Callback; LONGLONG m_nInterval; @@ -122,143 +99,6 @@ protected: }; -// 定时器管理器 -class ETimerManager -{ - friend EApp; - friend EScene; - friend ENode; - -public: - // 绑定定时器到场景 - static void bindTimer( - ETimer * timer, - EScene * pParentScene - ); - - // 绑定定时器到节点 - static void bindTimer( - ETimer * timer, - ENode * pParentNode - ); - - // 启动具有相同名称的定时器 - static void startTimers( - const EString &name - ); - - // 停止具有相同名称的定时器 - static void stopTimers( - const EString &name - ); - - // 删除具有相同名称的定时器 - static void delTimers( - const EString &name - ); - - // 启动绑定在场景及其子节点上的所有定时器 - static void startAllTimersBindedWith( - EScene * pParentScene - ); - - // 停止绑定在场景及其子节点上的所有定时器 - static void stopAllTimersBindedWith( - EScene * pParentScene - ); - - // 启动绑定在节点上的所有定时器 - static void startAllTimersBindedWith( - ENode * pParentNode - ); - - // 停止绑定在节点上的所有定时器 - static void stopAllTimersBindedWith( - ENode * pParentNode - ); - - // 启动所有定时器 - static void startAllTimers(); - - // 停止所有定时器 - static void stopAllTimers(); - -private: - // 清空定时器管理器 - static void _clearManager(); - - // 清空绑定在场景及其子节点上的所有定时器 - static void _clearAllTimersBindedWith( - EScene * pParentScene - ); - - // 清空绑定在节点上的所有定时器 - static void _clearAllTimersBindedWith( - ENode * pParentNode - ); - - // 重置定时器状态 - static void _resetAllTimers(); - - // 定时器执行程序 - static void TimerProc(); -}; - - -// 动作管理器 -class EActionManager -{ - friend EApp; - friend EScene; - friend ENode; - -public: - // 添加动作 - static void addAction( - EAction * action - ); - - // 继续绑定在节点上的所有动作 - static void startAllActionsBindedWith( - ENode * pTargetNode - ); - - // 暂停绑定在节点上的所有动作 - static void pauseAllActionsBindedWith( - ENode * pTargetNode - ); - - // 停止绑定在节点上的所有动作 - static void stopAllActionsBindedWith( - ENode * pTargetNode - ); - - // 继续所有动作 - static void startAllActions(); - - // 暂停所有动作 - static void pauseAllActions(); - - // 停止所有动作 - static void stopAllActions(); - -private: - // 清空动画管理器 - static void _clearManager(); - - // 清空绑定在节点上的所有动作 - static void _clearAllActionsBindedWith( - ENode * pTargetNode - ); - - // 重置所有动作状态 - static void _resetAllActions(); - - // 动作执行程序 - static void ActionProc(); -}; - - class EFileUtils { public: