diff --git a/ConsoleDemo/ConsoleDemo.vcxproj b/ConsoleDemo/ConsoleDemo.vcxproj index 5d8465c9..3500968a 100644 --- a/ConsoleDemo/ConsoleDemo.vcxproj +++ b/ConsoleDemo/ConsoleDemo.vcxproj @@ -96,6 +96,9 @@ Console true + + DeclareDPIAware.manifest + @@ -128,6 +131,9 @@ true true + + DeclareDPIAware.manifest + diff --git a/ConsoleDemo/DeclareDPIAware.manifest b/ConsoleDemo/DeclareDPIAware.manifest new file mode 100644 index 00000000..5dea26f9 --- /dev/null +++ b/ConsoleDemo/DeclareDPIAware.manifest @@ -0,0 +1,7 @@ + + + + true + + + \ No newline at end of file diff --git a/ConsoleDemo/elyse.png b/ConsoleDemo/elyse.png new file mode 100644 index 00000000..7efa0f78 Binary files /dev/null and b/ConsoleDemo/elyse.png differ diff --git a/ConsoleDemo/main.cpp b/ConsoleDemo/main.cpp index 9d3e6070..13f1f568 100644 --- a/ConsoleDemo/main.cpp +++ b/ConsoleDemo/main.cpp @@ -4,43 +4,33 @@ int main() { EApp app; - if (app.init(L"Easy2D Demo", 640, 480, true)) + if (app.init(L"Easy2D Demo", 320, 320)) { auto scene = new EScene(); - auto node = new ENode(); - node->setPos(50, 80); - node->_setSize(30, 180); - scene->add(node); - - /*auto listener = new EMouseListener([=] { - if (!EMouseMsg::isLButtonDown()) - { - if (EMouseMsg::getMsg() == EMouseMsg::MOVE) - { - node->setPos(EMouseMsg::getPos()); - } - } - });*/ - - auto listener = new EKeyboardPressListener([=] { - if (EKeyboardMsg::isCapitalLockOn()) - { - if (EKeyboardMsg::getVal() == EKeyboardMsg::KEY::LEFT) - { - node->move(-3, 0); - } - if (EKeyboardMsg::getVal() == EKeyboardMsg::KEY::RIGHT) - { - node->move(3, 0); - } - } + auto sprite = new ESprite(L"elyse.png"); + sprite->setScale(0.3f); + // 获取窗口宽度 + float width = EApp::getWidth(); + // 获取窗口高度 + float height = EApp::getHeight(); + // 移动精灵的位置 + sprite->setPos(width / 2, height / 2); + //sprite->setAnchor(0, 0); + scene->add(sprite); + auto text = new EText(L"balabalabalabalabala", L"宋体", 80, EColor::BLUE); + //text->setWordWrapping(true); + //text->setWordWrappingWidth(50); + text->setAnchor(0, 0); + + auto listener = new EListenerMouseClick([=](EPoint) { + EPoint p = EMouseMsg::getPos(); + sprite->setPos(p); }); - - listener->bindWith(node); - - EMsgManager::bindListener(listener, scene); - + listener->bindWith(scene); + EMsgManager::stopAllMouseListeners(); + EMsgManager::stopAllKeyboardListeners(); + scene->add(text, -1); app.enterScene(scene); app.run(); diff --git a/ConsoleDemo/test.png b/ConsoleDemo/test.png new file mode 100644 index 00000000..23b60462 Binary files /dev/null and b/ConsoleDemo/test.png differ diff --git a/Demo/main.cpp b/Demo/main.cpp index bd2130b1..b564cd24 100644 --- a/Demo/main.cpp +++ b/Demo/main.cpp @@ -16,18 +16,16 @@ int WINAPI WinMain( float h = EApp::getHeight(); auto scene = new EScene(); - auto text = new EText(L"中文测试中文测试中文测试中文测试中文测试中文测试中文测试", EColor::WHITE, L"楷体"); + auto text = new EText(L"中文测试中文测试中文测试中文测试中文测试中文测试中文测试", L"楷体"); text->setPos(EApp::getWidth() / 2, EApp::getHeight() / 2); //text->setWordWrapping(true); //text->setWordWrappingWidth(130); text->setRotation(40); - text->getFont()->setItalic(true); text->setAnchor(0.5f, 0.5f); - text->setColor(EColor::WHITE); //text->runAction(new EActionLoop(new EActionTwo(new EActionFadeOut(1), new EActionFadeIn(1)))); scene->add(text); - auto listener = new EKeyboardPressListener([=]() { + auto listener = new EListenerKeyboardPress([=]() { if (EKeyboardMsg::getVal() == EKeyboardMsg::KEY::SPACE) { EApp::backScene(new ETransitionFade(0.5f, 0.5f)); diff --git a/Easy2D/Action/EAction.cpp b/Easy2D/Action/EAction.cpp index 40899116..321de49d 100644 --- a/Easy2D/Action/EAction.cpp +++ b/Easy2D/Action/EAction.cpp @@ -55,6 +55,12 @@ void e2d::EAction::setInterval(LONGLONG milliSeconds) void e2d::EAction::setTarget(ENode * node) { + if (m_pTarget) + { + // 动作只能有一个目标 + return; + } + if (node) { m_pTarget = node; @@ -79,6 +85,14 @@ void e2d::EAction::_init() m_tLast = GetNow(); } +void e2d::EAction::_callOn() +{ + if (!m_bInit) + { + _init(); + } +} + void e2d::EAction::_reset() { m_bInit = false; diff --git a/Easy2D/Action/EActionCallback.cpp b/Easy2D/Action/EActionCallback.cpp index 05bb4b18..0b7aafbb 100644 --- a/Easy2D/Action/EActionCallback.cpp +++ b/Easy2D/Action/EActionCallback.cpp @@ -12,7 +12,7 @@ e2d::EActionCallback * e2d::EActionCallback::clone() const void e2d::EActionCallback::_init() { - EAction::_init(); + // 执行回调函数的动作不需要初始化 } void e2d::EActionCallback::_callOn() diff --git a/Easy2D/Action/EActionDelay.cpp b/Easy2D/Action/EActionDelay.cpp index 629ac683..7047ede3 100644 --- a/Easy2D/Action/EActionDelay.cpp +++ b/Easy2D/Action/EActionDelay.cpp @@ -18,6 +18,7 @@ void e2d::EActionDelay::_init() void e2d::EActionDelay::_callOn() { + EAction::_callOn(); // 判断时间间隔是否足够 if (GetInterval(m_tLast) > m_nAnimationInterval) { diff --git a/Easy2D/Action/EActionGradual.cpp b/Easy2D/Action/EActionGradual.cpp index 1d449179..5ff45ebf 100644 --- a/Easy2D/Action/EActionGradual.cpp +++ b/Easy2D/Action/EActionGradual.cpp @@ -21,6 +21,12 @@ void e2d::EActionGradual::_init() bool e2d::EActionGradual::_isDelayEnough() { // 判断时间间隔是否足够 + if (m_fTotalDuration == 0) + { + m_fRateOfProgress = 1; + return true; + } + if (GetInterval(m_tLast) > m_nAnimationInterval) { // 重新记录时间 diff --git a/Easy2D/Action/EActionLoop.cpp b/Easy2D/Action/EActionLoop.cpp index eb2bfd11..4808732e 100644 --- a/Easy2D/Action/EActionLoop.cpp +++ b/Easy2D/Action/EActionLoop.cpp @@ -1,42 +1,55 @@ #include "..\eactions.h" -e2d::EActionLoop::EActionLoop(EAction * action) : - m_Action(action) +e2d::EActionLoop::EActionLoop(EAction * action, int times /* = -1 */) + : m_pAction(action) + , m_nTimes(0) + , m_nTotalTimes(times) { - m_Action->retain(); + m_pAction->retain(); } e2d::EActionLoop::~EActionLoop() { - SafeRelease(&m_Action); + SafeRelease(&m_pAction); } e2d::EActionLoop * e2d::EActionLoop::clone() const { - return new EActionLoop(m_Action->clone()); + return new EActionLoop(m_pAction->clone()); } void e2d::EActionLoop::_init() { EAction::_init(); - if (!m_Action->getTarget() && m_pTarget) - { - m_Action->setTarget(m_pTarget); - } - m_Action->_init(); + m_pAction->setTarget(m_pTarget); + m_pAction->_init(); } void e2d::EActionLoop::_callOn() { - m_Action->_callOn(); + EAction::_callOn(); - if (m_Action->_isEnding()) + if (m_nTimes == m_nTotalTimes) { - m_Action->_reset(); + this->stop(); + return; + } + + m_pAction->_callOn(); + + if (m_pAction->_isEnding()) + { + m_nTimes++; + + EAction::_reset(); + m_pAction->_reset(); } } void e2d::EActionLoop::_reset() { EAction::_reset(); + + m_pAction->_reset(); + m_nTimes = 0; } diff --git a/Easy2D/Action/EActionMoveBy.cpp b/Easy2D/Action/EActionMoveBy.cpp index 5f6cd930..da3ca261 100644 --- a/Easy2D/Action/EActionMoveBy.cpp +++ b/Easy2D/Action/EActionMoveBy.cpp @@ -18,11 +18,14 @@ void e2d::EActionMoveBy::_init() void e2d::EActionMoveBy::_callOn() { + EAction::_callOn(); + if (m_pTarget == nullptr) { this->stop(); return; } + while (EActionGradual::_isDelayEnough()) { // 移动节点 diff --git a/Easy2D/Action/EActionOpacityBy.cpp b/Easy2D/Action/EActionOpacityBy.cpp index 6ac9e3de..7833e425 100644 --- a/Easy2D/Action/EActionOpacityBy.cpp +++ b/Easy2D/Action/EActionOpacityBy.cpp @@ -18,11 +18,14 @@ void e2d::EActionOpacityBy::_init() void e2d::EActionOpacityBy::_callOn() { + EAction::_callOn(); + if (m_pTarget == nullptr) { this->stop(); return; } + while (EActionGradual::_isDelayEnough()) { // 设置节点透明度 diff --git a/Easy2D/Action/EActionRotateBy.cpp b/Easy2D/Action/EActionRotateBy.cpp index 52828138..732d5306 100644 --- a/Easy2D/Action/EActionRotateBy.cpp +++ b/Easy2D/Action/EActionRotateBy.cpp @@ -12,17 +12,20 @@ void e2d::EActionRotateBy::_init() EActionGradual::_init(); if (m_pTarget) { - m_nBeginVal = m_pTarget->getOpacity(); + m_nBeginVal = m_pTarget->getRotation(); } } void e2d::EActionRotateBy::_callOn() { + EAction::_callOn(); + if (m_pTarget == nullptr) { this->stop(); return; } + while (EActionGradual::_isDelayEnough()) { // 旋转节点 diff --git a/Easy2D/Action/EActionScaleBy.cpp b/Easy2D/Action/EActionScaleBy.cpp index 0bf1178b..8e3f8d17 100644 --- a/Easy2D/Action/EActionScaleBy.cpp +++ b/Easy2D/Action/EActionScaleBy.cpp @@ -27,11 +27,14 @@ void e2d::EActionScaleBy::_init() void e2d::EActionScaleBy::_callOn() { + EAction::_callOn(); + if (m_pTarget == nullptr) { this->stop(); return; } + while (EActionGradual::_isDelayEnough()) { // 缩放节点 diff --git a/Easy2D/Action/EActionSequence.cpp b/Easy2D/Action/EActionSequence.cpp index 1109efa5..f62c5eea 100644 --- a/Easy2D/Action/EActionSequence.cpp +++ b/Easy2D/Action/EActionSequence.cpp @@ -37,10 +37,7 @@ void e2d::EActionSequence::_init() { for (auto action : m_vActions) { - if (!action->getTarget()) - { - action->setTarget(m_pTarget); - } + action->setTarget(m_pTarget); } } // 初始化第一个动作 @@ -49,6 +46,8 @@ void e2d::EActionSequence::_init() void e2d::EActionSequence::_callOn() { + EAction::_callOn(); + auto &action = m_vActions[m_nActionIndex]; action->_callOn(); diff --git a/Easy2D/Action/EActionTwo.cpp b/Easy2D/Action/EActionTwo.cpp index e2f29af4..014ba43b 100644 --- a/Easy2D/Action/EActionTwo.cpp +++ b/Easy2D/Action/EActionTwo.cpp @@ -34,20 +34,16 @@ e2d::EActionTwo * e2d::EActionTwo::reverse(bool actionReverse) const void e2d::EActionTwo::_init() { EAction::_init(); - if (!m_pFirstAction->getTarget() && m_pTarget) - { - m_pFirstAction->setTarget(m_pTarget); - } - if (!m_pSecondAction->getTarget() && m_pTarget) - { - m_pSecondAction->setTarget(m_pTarget); - } + m_pFirstAction->setTarget(m_pTarget); + m_pSecondAction->setTarget(m_pTarget); m_pFirstAction->_init(); } void e2d::EActionTwo::_callOn() { + EAction::_callOn(); + if (!m_pFirstAction->_isEnding()) { m_pFirstAction->_callOn(); diff --git a/Easy2D/Action/EActionTwoAtSameTime.cpp b/Easy2D/Action/EActionTwoAtSameTime.cpp index c9a5ed08..0ab8af70 100644 --- a/Easy2D/Action/EActionTwoAtSameTime.cpp +++ b/Easy2D/Action/EActionTwoAtSameTime.cpp @@ -34,14 +34,8 @@ e2d::EActionTwoAtSameTime * e2d::EActionTwoAtSameTime::reverse(bool actionRevers void e2d::EActionTwoAtSameTime::_init() { EAction::_init(); - if (!m_pFirstAction->getTarget() && m_pTarget) - { - m_pFirstAction->setTarget(m_pTarget); - } - if (!m_pSecondAction->getTarget() && m_pTarget) - { - m_pSecondAction->setTarget(m_pTarget); - } + m_pFirstAction->setTarget(m_pTarget); + m_pSecondAction->setTarget(m_pTarget); m_pFirstAction->_init(); m_pSecondAction->_init(); @@ -49,6 +43,8 @@ void e2d::EActionTwoAtSameTime::_init() void e2d::EActionTwoAtSameTime::_callOn() { + EAction::_callOn(); + if (!m_pFirstAction->_isEnding()) { m_pFirstAction->_callOn(); diff --git a/Easy2D/Action/EAnimation.cpp b/Easy2D/Action/EAnimation.cpp index 756726c7..c325a21a 100644 --- a/Easy2D/Action/EAnimation.cpp +++ b/Easy2D/Action/EAnimation.cpp @@ -30,11 +30,14 @@ void e2d::EAnimation::_init() void e2d::EAnimation::_callOn() { + EAction::_callOn(); + if (m_pTarget == nullptr) { this->stop(); return; } + // 判断时间间隔是否足够 while (GetInterval(m_tLast) > m_nAnimationInterval) { diff --git a/Easy2D/Base/EApp.cpp b/Easy2D/Base/EApp.cpp index 51b231eb..bc7fb8d1 100644 --- a/Easy2D/Base/EApp.cpp +++ b/Easy2D/Base/EApp.cpp @@ -19,6 +19,7 @@ static std::stack s_SceneStack; // 游戏开始时间 static steady_clock::time_point s_tStart; + e2d::EApp::EApp() : m_bEnd(false) , m_bPaused(false) @@ -26,7 +27,7 @@ e2d::EApp::EApp() , m_bTransitional(false) , m_bTopMost(false) , m_bShowConsole(false) - , nAnimationInterval(17LL) + , m_nAnimationInterval(17LL) , m_ClearColor(EColor::BLACK) , m_pCurrentScene(nullptr) , m_pNextScene(nullptr) @@ -112,7 +113,7 @@ bool e2d::EApp::init(const EString &title, UINT32 width, UINT32 height, EWindowS // 取最小值 width = min(width, screenWidth); height = min(height, screenHeight); - + // 创建窗口样式 DWORD dwStyle = WS_OVERLAPPED | WS_SYSMENU; if (!wStyle.m_bNoMiniSize) @@ -251,9 +252,10 @@ void e2d::EApp::run() { SetWindowPos(GetHWnd(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); } + // 记录开始时间 s_tStart = steady_clock::now(); - + // 窗口消息 MSG msg; while (!m_bEnd) @@ -275,7 +277,7 @@ void e2d::EApp::run() void e2d::EApp::setFPS(UINT32 fps) { fps = min(max(fps, 30), 120); - s_pInstance->nAnimationInterval = 1000 / fps; + s_pInstance->m_nAnimationInterval = 1000 / fps; } bool e2d::EApp::onActivate() @@ -295,10 +297,10 @@ bool e2d::EApp::onCloseWindow() void e2d::EApp::_mainLoop() { - // 时间间隔 - static LONGLONG nInterval = 0LL; // 挂起时长 static LONGLONG nWaitMS = 0L; + // 时间间隔 + static LONGLONG nInterval; // 上一帧画面绘制时间 static steady_clock::time_point tLast = steady_clock::now(); @@ -307,10 +309,10 @@ void e2d::EApp::_mainLoop() // 计算时间间隔 nInterval = GetInterval(tLast); // 判断间隔时间是否足够 - if (nInterval >= nAnimationInterval) + if (nInterval >= m_nAnimationInterval) { // 记录当前时间 - tLast += microseconds(nAnimationInterval); + tLast += microseconds(m_nAnimationInterval); // 游戏控制流程 _onControl(); // 刷新游戏画面 @@ -319,7 +321,7 @@ void e2d::EApp::_mainLoop() else { // 计算挂起时长 - nWaitMS = nAnimationInterval - nInterval - 1; + nWaitMS = m_nAnimationInterval - nInterval - 1; // 挂起线程,释放 CPU 占用 if (nWaitMS > 1LL) { @@ -436,6 +438,11 @@ float e2d::EApp::getHeight() return GetRenderTarget()->GetSize().height; } +e2d::ESize e2d::EApp::getSize() +{ + return ESize(GetRenderTarget()->GetSize().width, GetRenderTarget()->GetSize().height); +} + void e2d::EApp::enterScene(EScene * scene, bool saveCurrentScene /* = true */) { enterScene(scene, nullptr, saveCurrentScene); diff --git a/Easy2D/Easy2D.vcxproj b/Easy2D/Easy2D.vcxproj index 20b91013..352074d5 100644 --- a/Easy2D/Easy2D.vcxproj +++ b/Easy2D/Easy2D.vcxproj @@ -217,16 +217,16 @@ - - - + + + - - - - - - + + + + + + diff --git a/Easy2D/Easy2D.vcxproj.filters b/Easy2D/Easy2D.vcxproj.filters index df69779c..ed54ad4e 100644 --- a/Easy2D/Easy2D.vcxproj.filters +++ b/Easy2D/Easy2D.vcxproj.filters @@ -135,30 +135,9 @@ Manager - - Listener - - - Listener - Listener - - Listener - - - Listener - - - Listener - - - Listener - - - Listener - Node @@ -201,13 +180,34 @@ Manager - - Listener - Geometry - + + Listener + + + Listener + + + Listener + + + Listener + + + Listener + + + Listener + + + Listener + + + Listener + + Listener diff --git a/Easy2D/Listener/EContactListener.cpp b/Easy2D/Listener/EContactListener.cpp deleted file mode 100644 index 7afec872..00000000 --- a/Easy2D/Listener/EContactListener.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "..\elisteners.h" -#include "..\egeometry.h" - -e2d::EContactListener::EContactListener() - : EPhysicsListener() -{ -} - -e2d::EContactListener::EContactListener(const EString & name) - : EPhysicsListener(name) -{ -} - -e2d::EContactListener::EContactListener(const COLLISION_LISTENER_CALLBACK & callback) - : EPhysicsListener() -{ - this->m_Callback = callback; -} - -e2d::EContactListener::EContactListener(const EString & name, const COLLISION_LISTENER_CALLBACK & callback) - : EPhysicsListener(name) -{ - this->m_Callback = callback; -} - -void e2d::EContactListener::_callOn() -{ - if (EPhysicsMsg::getMsg() == EPhysicsMsg::OVERLAP || - EPhysicsMsg::getMsg() == EPhysicsMsg::CONTAINS || - EPhysicsMsg::getMsg() == EPhysicsMsg::IS_CONTAINED) - { - m_Callback( - EPhysicsMsg::getActiveGeometry()->getParentNode(), - EPhysicsMsg::getPassiveGeometry()->getParentNode() - ); - } -} diff --git a/Easy2D/Listener/EKeyboardPressListener.cpp b/Easy2D/Listener/EKeyboardPressListener.cpp deleted file mode 100644 index b6990598..00000000 --- a/Easy2D/Listener/EKeyboardPressListener.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "..\elisteners.h" - -e2d::EKeyboardPressListener::EKeyboardPressListener() - : EKeyboardListener() -{ -} - -e2d::EKeyboardPressListener::EKeyboardPressListener(const EString & name) - : EKeyboardListener(name) -{ -} - -e2d::EKeyboardPressListener::EKeyboardPressListener(const KEY_LISTENER_CALLBACK & callback) - : EKeyboardListener(callback) -{ -} - -e2d::EKeyboardPressListener::EKeyboardPressListener(const EString & name, const KEY_LISTENER_CALLBACK & callback) - : EKeyboardListener(name, callback) -{ -} - -void e2d::EKeyboardPressListener::_callOn() -{ - if (EKeyboardMsg::getMsg() == EKeyboardMsg::KEYBOARD_MSG::KEY_DOWN) - { - m_Callback(); - } -} diff --git a/Easy2D/Listener/EKeyboardListener.cpp b/Easy2D/Listener/EListenerKeyboard.cpp similarity index 57% rename from Easy2D/Listener/EKeyboardListener.cpp rename to Easy2D/Listener/EListenerKeyboard.cpp index 571dcf00..cecd0989 100644 --- a/Easy2D/Listener/EKeyboardListener.cpp +++ b/Easy2D/Listener/EListenerKeyboard.cpp @@ -1,39 +1,39 @@ #include "..\elisteners.h" #include "..\emanagers.h" -e2d::EKeyboardListener::EKeyboardListener() +e2d::EListenerKeyboard::EListenerKeyboard() : EListener() { } -e2d::EKeyboardListener::EKeyboardListener(const EString & name) +e2d::EListenerKeyboard::EListenerKeyboard(const EString & name) : EListener(name) { } -e2d::EKeyboardListener::EKeyboardListener(const KEY_LISTENER_CALLBACK & callback) +e2d::EListenerKeyboard::EListenerKeyboard(const KEY_LISTENER_CALLBACK & callback) : EListener() { m_Callback = callback; } -e2d::EKeyboardListener::EKeyboardListener(const EString & name, const KEY_LISTENER_CALLBACK & callback) +e2d::EListenerKeyboard::EListenerKeyboard(const EString & name, const KEY_LISTENER_CALLBACK & callback) : EListener(name) { m_Callback = callback; } -void e2d::EKeyboardListener::_callOn() +void e2d::EListenerKeyboard::_callOn() { m_Callback(); } -void e2d::EKeyboardListener::setCallback(const KEY_LISTENER_CALLBACK & callback) +void e2d::EListenerKeyboard::setCallback(const KEY_LISTENER_CALLBACK & callback) { m_Callback = callback; } -void e2d::EKeyboardListener::bindWith(EScene * pParentScene) +void e2d::EListenerKeyboard::bindWith(EScene * pParentScene) { WARN_IF(m_pParentNode != nullptr, "A listener cannot bind with two object."); @@ -43,7 +43,7 @@ void e2d::EKeyboardListener::bindWith(EScene * pParentScene) } } -void e2d::EKeyboardListener::bindWith(ENode * pParentNode) +void e2d::EListenerKeyboard::bindWith(ENode * pParentNode) { WARN_IF(m_pParentNode != nullptr, "A listener cannot bind with two object."); diff --git a/Easy2D/Listener/EListenerKeyboardPress.cpp b/Easy2D/Listener/EListenerKeyboardPress.cpp new file mode 100644 index 00000000..51c2cadf --- /dev/null +++ b/Easy2D/Listener/EListenerKeyboardPress.cpp @@ -0,0 +1,29 @@ +#include "..\elisteners.h" + +e2d::EListenerKeyboardPress::EListenerKeyboardPress() + : EListenerKeyboard() +{ +} + +e2d::EListenerKeyboardPress::EListenerKeyboardPress(const EString & name) + : EListenerKeyboard(name) +{ +} + +e2d::EListenerKeyboardPress::EListenerKeyboardPress(const KEY_LISTENER_CALLBACK & callback) + : EListenerKeyboard(callback) +{ +} + +e2d::EListenerKeyboardPress::EListenerKeyboardPress(const EString & name, const KEY_LISTENER_CALLBACK & callback) + : EListenerKeyboard(name, callback) +{ +} + +void e2d::EListenerKeyboardPress::_callOn() +{ + if (EKeyboardMsg::getMsg() == EKeyboardMsg::KEYBOARD_MSG::KEY_DOWN) + { + m_Callback(); + } +} diff --git a/Easy2D/Listener/EMouseListener.cpp b/Easy2D/Listener/EListenerMouse.cpp similarity index 59% rename from Easy2D/Listener/EMouseListener.cpp rename to Easy2D/Listener/EListenerMouse.cpp index 31c675eb..3be322b6 100644 --- a/Easy2D/Listener/EMouseListener.cpp +++ b/Easy2D/Listener/EListenerMouse.cpp @@ -1,39 +1,39 @@ #include "..\elisteners.h" #include "..\emanagers.h" -e2d::EMouseListener::EMouseListener() +e2d::EListenerMouse::EListenerMouse() : EListener() { } -e2d::EMouseListener::EMouseListener(const EString & name) +e2d::EListenerMouse::EListenerMouse(const EString & name) : EListener(name) { } -e2d::EMouseListener::EMouseListener(const MOUSE_LISTENER_CALLBACK & callback) +e2d::EListenerMouse::EListenerMouse(const MOUSE_LISTENER_CALLBACK & callback) : EListener() { m_Callback = callback; } -e2d::EMouseListener::EMouseListener(const EString & name, const MOUSE_LISTENER_CALLBACK & callback) +e2d::EListenerMouse::EListenerMouse(const EString & name, const MOUSE_LISTENER_CALLBACK & callback) : EListener(name) { m_Callback = callback; } -void e2d::EMouseListener::_callOn() +void e2d::EListenerMouse::_callOn() { m_Callback(); } -void e2d::EMouseListener::setCallback(const MOUSE_LISTENER_CALLBACK & callback) +void e2d::EListenerMouse::setCallback(const MOUSE_LISTENER_CALLBACK & callback) { m_Callback = callback; } -void e2d::EMouseListener::bindWith(EScene * pParentScene) +void e2d::EListenerMouse::bindWith(EScene * pParentScene) { WARN_IF(m_pParentNode != nullptr, "A listener cannot bind with two object."); @@ -43,7 +43,7 @@ void e2d::EMouseListener::bindWith(EScene * pParentScene) } } -void e2d::EMouseListener::bindWith(ENode * pParentNode) +void e2d::EListenerMouse::bindWith(ENode * pParentNode) { WARN_IF(m_pParentNode != nullptr, "A listener cannot bind with two object."); diff --git a/Easy2D/Listener/EMouseClickListener.cpp b/Easy2D/Listener/EListenerMouseClick.cpp similarity index 57% rename from Easy2D/Listener/EMouseClickListener.cpp rename to Easy2D/Listener/EListenerMouseClick.cpp index e1717c1b..cc131f42 100644 --- a/Easy2D/Listener/EMouseClickListener.cpp +++ b/Easy2D/Listener/EListenerMouseClick.cpp @@ -1,32 +1,32 @@ #include "..\elisteners.h" -e2d::EMouseClickListener::EMouseClickListener() - : EMouseListener() +e2d::EListenerMouseClick::EListenerMouseClick() + : EListenerMouse() , m_bPressed(false) { } -e2d::EMouseClickListener::EMouseClickListener(const EString & name) - : EMouseListener(name) +e2d::EListenerMouseClick::EListenerMouseClick(const EString & name) + : EListenerMouse(name) , m_bPressed(false) { } -e2d::EMouseClickListener::EMouseClickListener(const MOUSE_CLICK_LISTENER_CALLBACK & callback) - : EMouseListener() +e2d::EListenerMouseClick::EListenerMouseClick(const MOUSE_CLICK_LISTENER_CALLBACK & callback) + : EListenerMouse() , m_Callback(callback) , m_bPressed(false) { } -e2d::EMouseClickListener::EMouseClickListener(const EString & name, const MOUSE_CLICK_LISTENER_CALLBACK & callback) - : EMouseListener(name) +e2d::EListenerMouseClick::EListenerMouseClick(const EString & name, const MOUSE_CLICK_LISTENER_CALLBACK & callback) + : EListenerMouse(name) , m_Callback(callback) , m_bPressed(false) { } -void e2d::EMouseClickListener::_callOn() +void e2d::EListenerMouseClick::_callOn() { if (EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DOWN || EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DBLCLK) @@ -40,7 +40,7 @@ void e2d::EMouseClickListener::_callOn() } } -void e2d::EMouseClickListener::setCallback(const MOUSE_CLICK_LISTENER_CALLBACK & callback) +void e2d::EListenerMouseClick::setCallback(const MOUSE_CLICK_LISTENER_CALLBACK & callback) { m_Callback = callback; } diff --git a/Easy2D/Listener/EMouseDoubleClickListener.cpp b/Easy2D/Listener/EListenerMouseDoubleClick.cpp similarity index 59% rename from Easy2D/Listener/EMouseDoubleClickListener.cpp rename to Easy2D/Listener/EListenerMouseDoubleClick.cpp index e353d731..f4274b40 100644 --- a/Easy2D/Listener/EMouseDoubleClickListener.cpp +++ b/Easy2D/Listener/EListenerMouseDoubleClick.cpp @@ -1,32 +1,32 @@ #include "..\elisteners.h" -e2d::EMouseDoubleClickListener::EMouseDoubleClickListener() - : EMouseListener() +e2d::EListenerMouseDoubleClick::EListenerMouseDoubleClick() + : EListenerMouse() , m_bPressed(false) { } -e2d::EMouseDoubleClickListener::EMouseDoubleClickListener(const EString & name) - : EMouseListener(name) +e2d::EListenerMouseDoubleClick::EListenerMouseDoubleClick(const EString & name) + : EListenerMouse(name) , m_bPressed(false) { } -e2d::EMouseDoubleClickListener::EMouseDoubleClickListener(const MOUSE_DBLCLK_LISTENER_CALLBACK & callback) - : EMouseListener() +e2d::EListenerMouseDoubleClick::EListenerMouseDoubleClick(const MOUSE_DBLCLK_LISTENER_CALLBACK & callback) + : EListenerMouse() , m_Callback(callback) , m_bPressed(false) { } -e2d::EMouseDoubleClickListener::EMouseDoubleClickListener(const EString & name, const MOUSE_DBLCLK_LISTENER_CALLBACK & callback) - : EMouseListener(name) +e2d::EListenerMouseDoubleClick::EListenerMouseDoubleClick(const EString & name, const MOUSE_DBLCLK_LISTENER_CALLBACK & callback) + : EListenerMouse(name) , m_Callback(callback) , m_bPressed(false) { } -void e2d::EMouseDoubleClickListener::_callOn() +void e2d::EListenerMouseDoubleClick::_callOn() { if (EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DOWN) { @@ -43,7 +43,7 @@ void e2d::EMouseDoubleClickListener::_callOn() } } -void e2d::EMouseDoubleClickListener::setCallback(const MOUSE_DBLCLK_LISTENER_CALLBACK & callback) +void e2d::EListenerMouseDoubleClick::setCallback(const MOUSE_DBLCLK_LISTENER_CALLBACK & callback) { m_Callback = callback; } diff --git a/Easy2D/Listener/EMouseDragListener.cpp b/Easy2D/Listener/EListenerMouseDrag.cpp similarity index 54% rename from Easy2D/Listener/EMouseDragListener.cpp rename to Easy2D/Listener/EListenerMouseDrag.cpp index a56c54a2..38c1ac6d 100644 --- a/Easy2D/Listener/EMouseDragListener.cpp +++ b/Easy2D/Listener/EListenerMouseDrag.cpp @@ -1,28 +1,28 @@ #include "..\elisteners.h" -e2d::EMouseDragListener::EMouseDragListener() - : EMouseListener() +e2d::EListenerMouseDrag::EListenerMouseDrag() + : EListenerMouse() { } -e2d::EMouseDragListener::EMouseDragListener(const EString & name) - : EMouseListener(name) +e2d::EListenerMouseDrag::EListenerMouseDrag(const EString & name) + : EListenerMouse(name) { } -e2d::EMouseDragListener::EMouseDragListener(const MOUSE_DRAG_LISTENER_CALLBACK & callback) - : EMouseListener() +e2d::EListenerMouseDrag::EListenerMouseDrag(const MOUSE_DRAG_LISTENER_CALLBACK & callback) + : EListenerMouse() , m_Callback(callback) { } -e2d::EMouseDragListener::EMouseDragListener(const EString & name, const MOUSE_DRAG_LISTENER_CALLBACK & callback) - : EMouseListener(name) +e2d::EListenerMouseDrag::EListenerMouseDrag(const EString & name, const MOUSE_DRAG_LISTENER_CALLBACK & callback) + : EListenerMouse(name) , m_Callback(callback) { } -void e2d::EMouseDragListener::_callOn() +void e2d::EListenerMouseDrag::_callOn() { if (EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DOWN || EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DBLCLK) @@ -35,7 +35,7 @@ void e2d::EMouseDragListener::_callOn() } } -void e2d::EMouseDragListener::setCallback(const MOUSE_DRAG_LISTENER_CALLBACK & callback) +void e2d::EListenerMouseDrag::setCallback(const MOUSE_DRAG_LISTENER_CALLBACK & callback) { m_Callback = callback; } diff --git a/Easy2D/Listener/EListenerMousePress.cpp b/Easy2D/Listener/EListenerMousePress.cpp new file mode 100644 index 00000000..0761262e --- /dev/null +++ b/Easy2D/Listener/EListenerMousePress.cpp @@ -0,0 +1,37 @@ +#include "..\elisteners.h" + +e2d::EListenerMousePress::EListenerMousePress() + : EListenerMouse() +{ +} + +e2d::EListenerMousePress::EListenerMousePress(const EString & name) + : EListenerMouse(name) +{ +} + +e2d::EListenerMousePress::EListenerMousePress(const MOUSE_PRESS_LISTENER_CALLBACK & callback) + : EListenerMouse() + , m_Callback(callback) +{ +} + +e2d::EListenerMousePress::EListenerMousePress(const EString & name, const MOUSE_PRESS_LISTENER_CALLBACK & callback) + : EListenerMouse(name) + , m_Callback(callback) +{ +} + +void e2d::EListenerMousePress::_callOn() +{ + if (EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DOWN || + EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DBLCLK) + { + m_Callback(EMouseMsg::getPos()); + } +} + +void e2d::EListenerMousePress::setCallback(const MOUSE_PRESS_LISTENER_CALLBACK & callback) +{ + m_Callback = callback; +} diff --git a/Easy2D/Listener/EPhysicsListener.cpp b/Easy2D/Listener/EListenerPhysics.cpp similarity index 64% rename from Easy2D/Listener/EPhysicsListener.cpp rename to Easy2D/Listener/EListenerPhysics.cpp index 60300c2c..7929b8e3 100644 --- a/Easy2D/Listener/EPhysicsListener.cpp +++ b/Easy2D/Listener/EListenerPhysics.cpp @@ -2,29 +2,29 @@ #include "..\egeometry.h" #include "..\emanagers.h" -e2d::EPhysicsListener::EPhysicsListener() +e2d::EListenerPhysics::EListenerPhysics() : EListener() { } -e2d::EPhysicsListener::EPhysicsListener(const EString & name) +e2d::EListenerPhysics::EListenerPhysics(const EString & name) : EListener(name) { } -e2d::EPhysicsListener::EPhysicsListener(const PHYSICS_LISTENER_CALLBACK & callback) +e2d::EListenerPhysics::EListenerPhysics(const PHYSICS_LISTENER_CALLBACK & callback) : EListener() { m_Callback = callback; } -e2d::EPhysicsListener::EPhysicsListener(const EString & name, const PHYSICS_LISTENER_CALLBACK & callback) +e2d::EListenerPhysics::EListenerPhysics(const EString & name, const PHYSICS_LISTENER_CALLBACK & callback) : EListener(name) { m_Callback = callback; } -void e2d::EPhysicsListener::_callOn() +void e2d::EListenerPhysics::_callOn() { m_Callback( EPhysicsMsg::getActiveGeometry()->getParentNode(), @@ -33,12 +33,12 @@ void e2d::EPhysicsListener::_callOn() ); } -void e2d::EPhysicsListener::setCallback(const PHYSICS_LISTENER_CALLBACK & callback) +void e2d::EListenerPhysics::setCallback(const PHYSICS_LISTENER_CALLBACK & callback) { m_Callback = callback; } -void e2d::EPhysicsListener::bindWith(EScene * pParentScene) +void e2d::EListenerPhysics::bindWith(EScene * pParentScene) { WARN_IF(m_pParentNode != nullptr, "A listener cannot bind with two object."); @@ -48,7 +48,7 @@ void e2d::EPhysicsListener::bindWith(EScene * pParentScene) } } -void e2d::EPhysicsListener::bindWith(ENode * pParentNode) +void e2d::EListenerPhysics::bindWith(ENode * pParentNode) { WARN_IF(m_pParentNode != nullptr, "A listener cannot bind with two object."); diff --git a/Easy2D/Listener/EListenerPhysicsContact.cpp b/Easy2D/Listener/EListenerPhysicsContact.cpp new file mode 100644 index 00000000..3d78c900 --- /dev/null +++ b/Easy2D/Listener/EListenerPhysicsContact.cpp @@ -0,0 +1,37 @@ +#include "..\elisteners.h" +#include "..\egeometry.h" + +e2d::EListenerPhysicsContact::EListenerPhysicsContact() + : EListenerPhysics() +{ +} + +e2d::EListenerPhysicsContact::EListenerPhysicsContact(const EString & name) + : EListenerPhysics(name) +{ +} + +e2d::EListenerPhysicsContact::EListenerPhysicsContact(const COLLISION_LISTENER_CALLBACK & callback) + : EListenerPhysics() +{ + this->m_Callback = callback; +} + +e2d::EListenerPhysicsContact::EListenerPhysicsContact(const EString & name, const COLLISION_LISTENER_CALLBACK & callback) + : EListenerPhysics(name) +{ + this->m_Callback = callback; +} + +void e2d::EListenerPhysicsContact::_callOn() +{ + if (EPhysicsMsg::getMsg() == EPhysicsMsg::OVERLAP || + EPhysicsMsg::getMsg() == EPhysicsMsg::CONTAINS || + EPhysicsMsg::getMsg() == EPhysicsMsg::IS_CONTAINED) + { + m_Callback( + EPhysicsMsg::getActiveGeometry()->getParentNode(), + EPhysicsMsg::getPassiveGeometry()->getParentNode() + ); + } +} diff --git a/Easy2D/Listener/EMousePressListener.cpp b/Easy2D/Listener/EMousePressListener.cpp deleted file mode 100644 index c2c369ab..00000000 --- a/Easy2D/Listener/EMousePressListener.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "..\elisteners.h" - -e2d::EMousePressListener::EMousePressListener() - : EMouseListener() -{ -} - -e2d::EMousePressListener::EMousePressListener(const EString & name) - : EMouseListener(name) -{ -} - -e2d::EMousePressListener::EMousePressListener(const MOUSE_PRESS_LISTENER_CALLBACK & callback) - : EMouseListener() - , m_Callback(callback) -{ -} - -e2d::EMousePressListener::EMousePressListener(const EString & name, const MOUSE_PRESS_LISTENER_CALLBACK & callback) - : EMouseListener(name) - , m_Callback(callback) -{ -} - -void e2d::EMousePressListener::_callOn() -{ - if (EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DOWN || - EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DBLCLK) - { - m_Callback(EMouseMsg::getPos()); - } -} - -void e2d::EMousePressListener::setCallback(const MOUSE_PRESS_LISTENER_CALLBACK & callback) -{ - m_Callback = callback; -} diff --git a/Easy2D/Manager/EActionManager.cpp b/Easy2D/Manager/EActionManager.cpp index 8e2e7cd7..731c50b4 100644 --- a/Easy2D/Manager/EActionManager.cpp +++ b/Easy2D/Manager/EActionManager.cpp @@ -149,11 +149,6 @@ void e2d::EActionManager::ActionProc() } else { - // 初始化动作 - if (!action->m_bInit) - { - action->_init(); - } // 执行动作 action->_callOn(); } diff --git a/Easy2D/Manager/EMsgManager.cpp b/Easy2D/Manager/EMsgManager.cpp index c9597ec1..d5d1cf20 100644 --- a/Easy2D/Manager/EMsgManager.cpp +++ b/Easy2D/Manager/EMsgManager.cpp @@ -5,9 +5,9 @@ // 鼠标消息监听器 -e2d::EVector s_vMouseListeners; +e2d::EVector s_vMouseListeners; // 按键消息监听器 -e2d::EVector s_vKeyboardListeners; +e2d::EVector s_vKeyboardListeners; void e2d::EMsgManager::MouseProc(UINT message, WPARAM wParam, LPARAM lParam) @@ -60,20 +60,20 @@ void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam) } } -void e2d::EMsgManager::bindListener(e2d::EMouseListener * listener, EScene * pParentScene, bool always /* = false */) +void e2d::EMsgManager::bindListener(e2d::EListenerMouse * listener, EScene * pParentScene, bool always /* = false */) { EMsgManager::bindListener(listener, pParentScene->getRoot(), always); } -void e2d::EMsgManager::bindListener(EKeyboardListener * listener, EScene * pParentScene, bool always /* = false */) +void e2d::EMsgManager::bindListener(EListenerKeyboard * listener, EScene * pParentScene, bool always /* = false */) { EMsgManager::bindListener(listener, pParentScene->getRoot(), always); } -void e2d::EMsgManager::bindListener(EMouseListener * listener, ENode * pParentNode, bool always /* = false */) +void e2d::EMsgManager::bindListener(EListenerMouse * listener, ENode * pParentNode, bool always /* = false */) { - WARN_IF(listener == nullptr, "EMouseListener NULL pointer exception!"); - WARN_IF(pParentNode == nullptr, "Bind EMouseListener with a NULL ENode pointer!"); + WARN_IF(listener == nullptr, "EListenerMouse NULL pointer exception!"); + WARN_IF(pParentNode == nullptr, "Bind EListenerMouse with a NULL ENode pointer!"); if (listener && pParentNode) { @@ -90,10 +90,10 @@ void e2d::EMsgManager::bindListener(EMouseListener * listener, ENode * pParentNo } } -void e2d::EMsgManager::bindListener(EKeyboardListener * listener, ENode * pParentNode, bool always /* = false */) +void e2d::EMsgManager::bindListener(EListenerKeyboard * listener, ENode * pParentNode, bool always /* = false */) { - WARN_IF(listener == nullptr, "EKeyboardListener NULL pointer exception!"); - WARN_IF(pParentNode == nullptr, "Bind EKeyboardListener with a NULL ENode pointer!"); + WARN_IF(listener == nullptr, "EListenerKeyboard NULL pointer exception!"); + WARN_IF(pParentNode == nullptr, "Bind EListenerKeyboard with a NULL ENode pointer!"); if (listener && pParentNode) { @@ -135,7 +135,7 @@ void e2d::EMsgManager::stopMouseListeners(const EString & name) void e2d::EMsgManager::delMouseListeners(const EString & name) { // 删除鼠标消息监听器 - EVector::iterator mIter; + EVector::iterator mIter; for (mIter = s_vMouseListeners.begin(); mIter != s_vMouseListeners.end();) { if ((*mIter)->getName() == name) @@ -177,7 +177,7 @@ void e2d::EMsgManager::stopKeyboardListeners(const EString & name) void e2d::EMsgManager::delKeyboardListeners(const EString & name) { // 删除按键消息监听器 - EVector::iterator kIter; + EVector::iterator kIter; for (kIter = s_vKeyboardListeners.begin(); kIter != s_vKeyboardListeners.end();) { if ((*kIter)->getName() == name) diff --git a/Easy2D/Manager/EPhysicsManager.cpp b/Easy2D/Manager/EPhysicsManager.cpp index ab4449ae..bf6cb5a9 100644 --- a/Easy2D/Manager/EPhysicsManager.cpp +++ b/Easy2D/Manager/EPhysicsManager.cpp @@ -4,7 +4,7 @@ #include "..\egeometry.h" // 监听器集合 -e2d::EVector s_vListeners; +e2d::EVector s_vListeners; // 形状集合 e2d::EVector s_vGeometries; @@ -62,15 +62,15 @@ void e2d::EPhysicsManager::PhysicsListenerProc() } } -void e2d::EPhysicsManager::bindListener(EPhysicsListener * listener, EScene * pParentScene) +void e2d::EPhysicsManager::bindListener(EListenerPhysics * listener, EScene * pParentScene) { EPhysicsManager::bindListener(listener, pParentScene->getRoot()); } -void e2d::EPhysicsManager::bindListener(EPhysicsListener * listener, ENode * pParentNode) +void e2d::EPhysicsManager::bindListener(EListenerPhysics * listener, ENode * pParentNode) { - WARN_IF(listener == nullptr, "EPhysicsListener NULL pointer exception!"); - WARN_IF(pParentNode == nullptr, "EPhysicsListener add to a NULL ENode pointer!"); + WARN_IF(listener == nullptr, "EListenerPhysics NULL pointer exception!"); + WARN_IF(pParentNode == nullptr, "EListenerPhysics add to a NULL ENode pointer!"); if (listener && pParentNode) { @@ -135,7 +135,7 @@ void e2d::EPhysicsManager::stopListeners(const EString & name) void e2d::EPhysicsManager::delListeners(const EString & name) { - EVector::iterator iter; + EVector::iterator iter; for (iter = s_vListeners.begin(); iter != s_vListeners.end();) { if ((*iter)->getName() == name) diff --git a/Easy2D/Node/EButton.cpp b/Easy2D/Node/EButton.cpp index f7402d4e..b48c4f28 100644 --- a/Easy2D/Node/EButton.cpp +++ b/Easy2D/Node/EButton.cpp @@ -109,7 +109,7 @@ void e2d::EButton::setDisable(bool disable) void e2d::EButton::setCallback(const BUTTON_CLICK_CALLBACK & callback) { - auto listener = new EMouseListener(std::bind(&EButton::_listenerCallback, this)); + auto listener = new EListenerMouse(std::bind(&EButton::_listenerCallback, this)); EMsgManager::bindListener(listener, this, true); m_Callback = callback; } diff --git a/Easy2D/Node/ENode.cpp b/Easy2D/Node/ENode.cpp index cf64bfb3..6e5b2b3f 100644 --- a/Easy2D/Node/ENode.cpp +++ b/Easy2D/Node/ENode.cpp @@ -379,14 +379,24 @@ void e2d::ENode::setPos(float x, float y) m_bTransformChildrenNeeded = true; } -void e2d::ENode::move(float x, float y) +void e2d::ENode::movePosX(float x) +{ + this->movePos(x, 0); +} + +void e2d::ENode::movePosY(float y) +{ + this->movePos(0, y); +} + +void e2d::ENode::movePos(float x, float y) { this->setPos(m_Pos.x + x, m_Pos.y + y); } -void e2d::ENode::move(const EVec & v) +void e2d::ENode::movePos(const EVec & v) { - this->move(v.x, v.y); + this->movePos(v.x, v.y); } void e2d::ENode::_setWidth(float width) diff --git a/Easy2D/Node/ESprite.cpp b/Easy2D/Node/ESprite.cpp index 09c31d21..ee2be277 100644 --- a/Easy2D/Node/ESprite.cpp +++ b/Easy2D/Node/ESprite.cpp @@ -33,13 +33,13 @@ e2d::ESprite::ESprite(const EString & imageFileName, float x, float y, float wid clip(x, y, width, height); } -e2d::ESprite::ESprite(const EString & resourceName, const EString & resourceType) +e2d::ESprite::ESprite(LPCTSTR resourceName, LPCTSTR resourceType) : ESprite() { loadFrom(resourceName, resourceType); } -e2d::ESprite::ESprite(const EString & resourceName, const EString & resourceType, float x, float y, float width, float height) +e2d::ESprite::ESprite(LPCTSTR resourceName, LPCTSTR resourceType, float x, float y, float width, float height) { loadFrom(resourceName, resourceType); clip(x, y, width, height); @@ -69,7 +69,7 @@ void e2d::ESprite::loadFrom(const EString & imageFileName) loadFrom(new ETexture(imageFileName)); } -void e2d::ESprite::loadFrom(const EString & resourceName, const EString & resourceType) +void e2d::ESprite::loadFrom(LPCTSTR resourceName, LPCTSTR resourceType) { loadFrom(new ETexture(resourceName, resourceType)); } diff --git a/Easy2D/Node/ESpriteFrame.cpp b/Easy2D/Node/ESpriteFrame.cpp index 522f7882..a8fb8dfb 100644 --- a/Easy2D/Node/ESpriteFrame.cpp +++ b/Easy2D/Node/ESpriteFrame.cpp @@ -21,7 +21,7 @@ e2d::ESpriteFrame::ESpriteFrame(const EString & imageFileName) _setTexture(new ETexture(imageFileName)); } -e2d::ESpriteFrame::ESpriteFrame(const EString & resourceName, const EString & resourceType) +e2d::ESpriteFrame::ESpriteFrame(LPCTSTR resourceName, LPCTSTR resourceType) : ESpriteFrame() { _setTexture(new ETexture(resourceName, resourceType)); @@ -41,7 +41,7 @@ e2d::ESpriteFrame::ESpriteFrame(const EString & imageFileName, float x, float y, _clipTexture(x, y, width, height); } -e2d::ESpriteFrame::ESpriteFrame(const EString & resourceName, const EString & resourceType, float x, float y, float width, float height) +e2d::ESpriteFrame::ESpriteFrame(LPCTSTR resourceName, LPCTSTR resourceType, float x, float y, float width, float height) : ESpriteFrame() { _setTexture(new ETexture(resourceName, resourceType)); diff --git a/Easy2D/Node/ETexture.cpp b/Easy2D/Node/ETexture.cpp index b4836bfb..89bf9a6c 100644 --- a/Easy2D/Node/ETexture.cpp +++ b/Easy2D/Node/ETexture.cpp @@ -35,7 +35,7 @@ e2d::ETexture::ETexture(const EString & fileName) this->loadFromFile(fileName); } -e2d::ETexture::ETexture(const EString & resourceName, const EString & resourceType) +e2d::ETexture::ETexture(LPCTSTR resourceName, LPCTSTR resourceType) { this->loadFromResource(resourceName, resourceType); } @@ -63,11 +63,11 @@ void e2d::ETexture::loadFromFile(const EString & fileName) m_pBitmap = s_mBitmapsFromFile.at(hash); } -void e2d::ETexture::loadFromResource(const EString & resourceName, const EString & resourceType) +void e2d::ETexture::loadFromResource(LPCTSTR resourceName, LPCTSTR resourceType) { - WARN_IF(resourceName.empty() || resourceType.empty(), "ETexture cannot load bitmap from NULL resource."); + WARN_IF(!resourceName || !resourceType, "ETexture cannot load bitmap from NULL resource."); - if (resourceName.empty() || resourceType.empty()) + if (!resourceName || !resourceType) return; if (!e2d::ETexture::preload(resourceName, resourceType)) @@ -77,7 +77,7 @@ void e2d::ETexture::loadFromResource(const EString & resourceName, const EString } ResKey key; - std::hash h; + std::hash h; key.resNameHash = h(resourceName); key.resTypeHash = h(resourceType); @@ -202,9 +202,9 @@ bool e2d::ETexture::preload(const EString & fileName) return SUCCEEDED(hr); } -bool e2d::ETexture::preload(const EString & resourceName, const EString & resourceType) +bool e2d::ETexture::preload(LPCTSTR resourceName, LPCTSTR resourceType) { - std::hash h; + std::hash h; ResKey key; key.resNameHash = h(resourceName); @@ -230,7 +230,7 @@ bool e2d::ETexture::preload(const EString & resourceName, const EString & resour DWORD imageFileSize = 0; // 定位资源 - imageResHandle = ::FindResourceW(HINST_THISCOMPONENT, resourceName.c_str(), resourceType.c_str()); + imageResHandle = ::FindResourceW(HINST_THISCOMPONENT, resourceName, resourceType); hr = imageResHandle ? S_OK : E_FAIL; if (SUCCEEDED(hr)) @@ -321,7 +321,7 @@ bool e2d::ETexture::preload(const EString & resourceName, const EString & resour if (SUCCEEDED(hr)) { - std::hash h; + std::hash h; ResKey key; key.resNameHash = h(resourceName); diff --git a/Easy2D/Tool/ETimer.cpp b/Easy2D/Tool/ETimer.cpp index a3a0353b..187b2509 100644 --- a/Easy2D/Tool/ETimer.cpp +++ b/Easy2D/Tool/ETimer.cpp @@ -40,7 +40,7 @@ bool e2d::ETimer::isRunning() const void e2d::ETimer::start() { m_bRunning = true; - m_tLast = GetNow(); + m_tLast = steady_clock::now(); } void e2d::ETimer::stop() diff --git a/Easy2D/Transition/ETransitionMove.cpp b/Easy2D/Transition/ETransitionMove.cpp index d2d88a4b..602b71b9 100644 --- a/Easy2D/Transition/ETransitionMove.cpp +++ b/Easy2D/Transition/ETransitionMove.cpp @@ -35,7 +35,7 @@ void e2d::ETransitionMove::_setTarget(EScene * prev, EScene * next, bool & trans } // 初始化场景属性 - next->getRoot()->move(-distPosX, -distPosY); + next->getRoot()->movePos(-distPosX, -distPosY); // 第一个场景移出 auto action1 = new EActionMoveBy(m_fMoveDuration, EVec(distPosX, distPosY)); diff --git a/Easy2D/eactions.h b/Easy2D/eactions.h index ed888cf7..6e300581 100644 --- a/Easy2D/eactions.h +++ b/Easy2D/eactions.h @@ -65,7 +65,7 @@ protected: virtual void _init(); // 执行动作 - virtual void _callOn() = 0; + virtual void _callOn(); // 获取动作结束状态 virtual bool _isEnding(); @@ -527,7 +527,8 @@ class EActionLoop : public: // 创建循环动作 EActionLoop( - EAction * action /* 执行循环的动作 */ + EAction * action, /* 执行循环的动作 */ + int times = -1 /* 循环次数 */ ); virtual ~EActionLoop(); @@ -546,7 +547,9 @@ protected: virtual void _reset() override; protected: - EAction * m_Action; + EAction * m_pAction; + int m_nTimes; + int m_nTotalTimes; }; diff --git a/Easy2D/ebase.h b/Easy2D/ebase.h index 8a8d1a13..1e6506b5 100644 --- a/Easy2D/ebase.h +++ b/Easy2D/ebase.h @@ -11,8 +11,8 @@ namespace e2d class EScene; class ENode; class EObjectManager; -class EMouseListener; -class EKeyboardListener; +class EListenerMouse; +class EListenerKeyboard; class EAction; class ETransition; @@ -109,6 +109,9 @@ public: // 获取窗口高度 static float getHeight(); + // 获取窗口大小 + static ESize getSize(); + // 获取当前场景 static EScene * getCurrentScene(); @@ -183,7 +186,7 @@ protected: EString m_sTitle; EString m_sAppName; UINT32 m_ClearColor; - LONGLONG nAnimationInterval; + LONGLONG m_nAnimationInterval; EScene * m_pCurrentScene; EScene * m_pNextScene; }; diff --git a/Easy2D/elisteners.h b/Easy2D/elisteners.h index b55fc70b..8cb7d5d1 100644 --- a/Easy2D/elisteners.h +++ b/Easy2D/elisteners.h @@ -65,23 +65,23 @@ protected: // 鼠标消息监听器 -class EMouseListener : +class EListenerMouse : public EListener { friend EMsgManager; public: - EMouseListener(); + EListenerMouse(); - EMouseListener( + EListenerMouse( const EString &name ); - EMouseListener( + EListenerMouse( const MOUSE_LISTENER_CALLBACK &callback ); - EMouseListener( + EListenerMouse( const EString &name, const MOUSE_LISTENER_CALLBACK &callback ); @@ -111,21 +111,21 @@ protected: // 鼠标按下消息监听器 -class EMousePressListener : - public EMouseListener +class EListenerMousePress : + public EListenerMouse { public: - EMousePressListener(); + EListenerMousePress(); - EMousePressListener( + EListenerMousePress( const EString &name ); - EMousePressListener( + EListenerMousePress( const MOUSE_PRESS_LISTENER_CALLBACK &callback ); - EMousePressListener( + EListenerMousePress( const EString &name, const MOUSE_PRESS_LISTENER_CALLBACK &callback ); @@ -145,21 +145,21 @@ protected: // 鼠标点击消息监听器 -class EMouseClickListener : - public EMouseListener +class EListenerMouseClick : + public EListenerMouse { public: - EMouseClickListener(); + EListenerMouseClick(); - EMouseClickListener( + EListenerMouseClick( const EString &name ); - EMouseClickListener( + EListenerMouseClick( const MOUSE_CLICK_LISTENER_CALLBACK &callback ); - EMouseClickListener( + EListenerMouseClick( const EString &name, const MOUSE_CLICK_LISTENER_CALLBACK &callback ); @@ -180,21 +180,21 @@ protected: // 鼠标点击消息监听器 -class EMouseDoubleClickListener : - public EMouseListener +class EListenerMouseDoubleClick : + public EListenerMouse { public: - EMouseDoubleClickListener(); + EListenerMouseDoubleClick(); - EMouseDoubleClickListener( + EListenerMouseDoubleClick( const EString &name ); - EMouseDoubleClickListener( + EListenerMouseDoubleClick( const MOUSE_DBLCLK_LISTENER_CALLBACK &callback ); - EMouseDoubleClickListener( + EListenerMouseDoubleClick( const EString &name, const MOUSE_DBLCLK_LISTENER_CALLBACK &callback ); @@ -215,21 +215,21 @@ protected: // 鼠标拖动消息监听器 -class EMouseDragListener : - public EMouseListener +class EListenerMouseDrag : + public EListenerMouse { public: - EMouseDragListener(); + EListenerMouseDrag(); - EMouseDragListener( + EListenerMouseDrag( const EString &name ); - EMouseDragListener( + EListenerMouseDrag( const MOUSE_DRAG_LISTENER_CALLBACK &callback ); - EMouseDragListener( + EListenerMouseDrag( const EString &name, const MOUSE_DRAG_LISTENER_CALLBACK &callback ); @@ -250,23 +250,23 @@ protected: // 按键消息监听器 -class EKeyboardListener : +class EListenerKeyboard : public EListener { friend EMsgManager; public: - EKeyboardListener(); + EListenerKeyboard(); - EKeyboardListener( + EListenerKeyboard( const EString &name ); - EKeyboardListener( + EListenerKeyboard( const KEY_LISTENER_CALLBACK &callback ); - EKeyboardListener( + EListenerKeyboard( const EString &name, const KEY_LISTENER_CALLBACK &callback ); @@ -296,23 +296,23 @@ protected: // 按键按下消息监听 -class EKeyboardPressListener : - public EKeyboardListener +class EListenerKeyboardPress : + public EListenerKeyboard { friend EMsgManager; public: - EKeyboardPressListener(); + EListenerKeyboardPress(); - EKeyboardPressListener( + EListenerKeyboardPress( const EString &name ); - EKeyboardPressListener( + EListenerKeyboardPress( const KEY_LISTENER_CALLBACK &callback ); - EKeyboardPressListener( + EListenerKeyboardPress( const EString &name, const KEY_LISTENER_CALLBACK &callback ); @@ -330,23 +330,23 @@ typedef std::function PHYSICS typedef std::function COLLISION_LISTENER_CALLBACK; // 物理世界消息监听器 -class EPhysicsListener : +class EListenerPhysics : public EListener { friend EPhysicsManager; public: - EPhysicsListener(); + EListenerPhysics(); - EPhysicsListener( + EListenerPhysics( const EString &name ); - EPhysicsListener( + EListenerPhysics( const PHYSICS_LISTENER_CALLBACK &callback ); - EPhysicsListener( + EListenerPhysics( const EString &name, const PHYSICS_LISTENER_CALLBACK &callback ); @@ -375,23 +375,23 @@ protected: }; -class EContactListener : - public EPhysicsListener +class EListenerPhysicsContact : + public EListenerPhysics { friend EMsgManager; public: - EContactListener(); + EListenerPhysicsContact(); - EContactListener( + EListenerPhysicsContact( const EString &name ); - EContactListener( + EListenerPhysicsContact( const COLLISION_LISTENER_CALLBACK &callback ); - EContactListener( + EListenerPhysicsContact( const EString &name, const COLLISION_LISTENER_CALLBACK &callback ); diff --git a/Easy2D/emanagers.h b/Easy2D/emanagers.h index 5d2462cf..bcab4adf 100644 --- a/Easy2D/emanagers.h +++ b/Easy2D/emanagers.h @@ -11,10 +11,10 @@ class EScene; class ENode; class ETimer; class EAction; -class EMouseListener; -class EKeyboardListener; +class EListenerMouse; +class EListenerKeyboard; class EGeometry; -class EPhysicsListener; +class EListenerPhysics; // 对象管理器 class EObjectManager @@ -46,14 +46,14 @@ class EMsgManager public: // 绑定鼠标消息监听器到场景 static void bindListener( - EMouseListener * listener, + EListenerMouse * listener, EScene * pParentScene, bool always = false /* 是否在游戏暂停时仍然监听 */ ); // 绑定鼠标消息监听器到节点 static void bindListener( - EMouseListener * listener, + EListenerMouse * listener, ENode * pParentNode, bool always = false /* 是否在游戏暂停时仍然监听 */ ); @@ -101,14 +101,14 @@ public: // 绑定按键消息监听器到场景 static void bindListener( - EKeyboardListener * listener, + EListenerKeyboard * listener, EScene * pParentScene, bool always = false /* 是否在游戏暂停时仍然监听 */ ); // 绑定按键消息监听器到节点 static void bindListener( - EKeyboardListener * listener, + EListenerKeyboard * listener, ENode * pParentNode, bool always = false /* 是否在游戏暂停时仍然监听 */ ); @@ -326,13 +326,13 @@ class EPhysicsManager public: // 将监听器与场景绑定 static void bindListener( - EPhysicsListener * listener, + EListenerPhysics * listener, EScene * pParentScene ); // 将监听器与节点绑定 static void bindListener( - EPhysicsListener * listener, + EListenerPhysics * listener, ENode * pParentNode ); diff --git a/Easy2D/enodes.h b/Easy2D/enodes.h index b6f993c0..2c3855b4 100644 --- a/Easy2D/enodes.h +++ b/Easy2D/enodes.h @@ -141,13 +141,23 @@ public: ); // 移动节点 - virtual void move( + virtual void movePosX( + float x + ); + + // 移动节点 + virtual void movePosY( + float y + ); + + // 移动节点 + virtual void movePos( float x, float y ); // 移动节点 - virtual void move( + virtual void movePos( const EVec & v ); @@ -396,8 +406,8 @@ public: // 读取程序资源 ETexture( - const EString & resourceName, - const EString & resourceType + LPCTSTR resourceName, + LPCTSTR resourceType ); virtual ~ETexture(); @@ -409,8 +419,8 @@ public: // 读取程序资源 void loadFromResource( - const EString & resourceName, - const EString & resourceType + LPCTSTR resourceName, + LPCTSTR resourceType ); // 获取源图片宽度 @@ -429,8 +439,8 @@ public: // 预加载资源 static bool preload( - const EString & resourceName, - const EString & resourceType + LPCTSTR resourceName, + LPCTSTR resourceType ); // 清空缓存 @@ -465,8 +475,8 @@ public: // 创建空的精灵帧 ESpriteFrame( - const EString & resourceName, - const EString & resourceType + LPCTSTR resourceName, + LPCTSTR resourceType ); // 创建空的精灵帧 @@ -489,8 +499,8 @@ public: // 创建空的精灵帧 ESpriteFrame( - const EString & resourceName, - const EString & resourceType, + LPCTSTR resourceName, + LPCTSTR resourceType, float x, float y, float width, @@ -564,14 +574,14 @@ public: // 从资源图片创建精灵 ESprite( - const EString & resourceName, - const EString & resourceType + LPCTSTR resourceName, + LPCTSTR resourceType ); // 从资源图片创建精灵并裁剪 ESprite( - const EString & resourceName, - const EString & resourceType, + LPCTSTR resourceName, + LPCTSTR resourceType, float x, float y, float width, @@ -592,8 +602,8 @@ public: // 从资源加载纹理 void loadFrom( - const EString & resourceName, - const EString & resourceType + LPCTSTR resourceName, + LPCTSTR resourceType ); // 加载纹理并裁剪