2017-10-26 17:17:30 +08:00
|
|
|
|
#include "..\emanagers.h"
|
|
|
|
|
|
#include "..\elisteners.h"
|
2017-10-20 00:59:26 +08:00
|
|
|
|
#include "..\enodes.h"
|
|
|
|
|
|
#include "..\Win\winbase.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
e2d::EVector<e2d::EMouseListener*> s_vMouseListeners;
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
e2d::EVector<e2d::EKeyboardListener*> s_vKeyboardListeners;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EMsgManager::MouseProc(UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
2017-10-28 18:48:21 +08:00
|
|
|
|
EMouseMsg::s_nMsg = message;
|
|
|
|
|
|
EMouseMsg::s_wParam = wParam;
|
|
|
|
|
|
EMouseMsg::s_lParam = lParam;
|
2017-10-20 00:59:26 +08:00
|
|
|
|
// ִ<><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2017-10-21 19:09:31 +08:00
|
|
|
|
for (size_t i = 0; i < s_vMouseListeners.size(); i++)
|
2017-10-20 00:59:26 +08:00
|
|
|
|
{
|
2017-10-21 19:09:31 +08:00
|
|
|
|
auto &mlistener = s_vMouseListeners[i];
|
|
|
|
|
|
|
|
|
|
|
|
if (EApp::isPaused() && !mlistener->m_bAlways)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
2017-10-31 17:19:13 +08:00
|
|
|
|
if (mlistener->m_bAlways || mlistener->isRunning())
|
2017-10-20 00:59:26 +08:00
|
|
|
|
{
|
2017-10-26 17:17:30 +08:00
|
|
|
|
if (mlistener->getParentNode() &&
|
|
|
|
|
|
mlistener->getParentNode()->getParentScene() == EApp::getCurrentScene())
|
2017-10-20 00:59:26 +08:00
|
|
|
|
{
|
|
|
|
|
|
mlistener->_callOn();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD>水<EFBFBD><E6B0B4><EFBFBD><EFBFBD>Ϣ
|
2017-10-28 18:48:21 +08:00
|
|
|
|
EKeyboardMsg::s_nMsg = message;
|
|
|
|
|
|
EKeyboardMsg::s_wParam = wParam;
|
|
|
|
|
|
EKeyboardMsg::s_lParam = lParam;
|
2017-10-20 00:59:26 +08:00
|
|
|
|
// ִ<>а<EFBFBD><D0B0><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2017-10-21 19:09:31 +08:00
|
|
|
|
for (size_t i = 0; i < s_vKeyboardListeners.size(); i++)
|
2017-10-20 00:59:26 +08:00
|
|
|
|
{
|
2017-10-21 19:09:31 +08:00
|
|
|
|
auto &klistener = s_vKeyboardListeners[i];
|
|
|
|
|
|
|
|
|
|
|
|
if (EApp::isPaused() && !klistener->m_bAlways)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
2017-10-31 17:19:13 +08:00
|
|
|
|
if (klistener->m_bAlways || klistener->isRunning())
|
2017-10-20 00:59:26 +08:00
|
|
|
|
{
|
2017-10-26 17:17:30 +08:00
|
|
|
|
if (klistener->getParentNode() &&
|
|
|
|
|
|
klistener->getParentNode()->getParentScene() == EApp::getCurrentScene())
|
2017-10-20 00:59:26 +08:00
|
|
|
|
{
|
|
|
|
|
|
klistener->_callOn();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-21 19:09:31 +08:00
|
|
|
|
void e2d::EMsgManager::bindListener(e2d::EMouseListener * listener, EScene * pParentScene, bool always /* = false */)
|
2017-10-20 00:59:26 +08:00
|
|
|
|
{
|
2017-10-26 17:17:30 +08:00
|
|
|
|
EMsgManager::bindListener(listener, pParentScene->getRoot(), always);
|
2017-10-20 00:59:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-21 19:09:31 +08:00
|
|
|
|
void e2d::EMsgManager::bindListener(EKeyboardListener * listener, EScene * pParentScene, bool always /* = false */)
|
2017-10-20 00:59:26 +08:00
|
|
|
|
{
|
2017-10-26 17:17:30 +08:00
|
|
|
|
EMsgManager::bindListener(listener, pParentScene->getRoot(), always);
|
2017-10-20 00:59:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-21 19:09:31 +08:00
|
|
|
|
void e2d::EMsgManager::bindListener(EMouseListener * listener, ENode * pParentNode, bool always /* = false */)
|
2017-10-20 00:59:26 +08:00
|
|
|
|
{
|
|
|
|
|
|
WARN_IF(listener == nullptr, "EMouseListener NULL pointer exception!");
|
|
|
|
|
|
WARN_IF(pParentNode == nullptr, "Bind EMouseListener with a NULL ENode pointer!");
|
|
|
|
|
|
|
|
|
|
|
|
if (listener && pParentNode)
|
|
|
|
|
|
{
|
2017-10-26 17:17:30 +08:00
|
|
|
|
ASSERT(
|
|
|
|
|
|
!listener->m_pParentNode,
|
|
|
|
|
|
"The listener is already binded, it cannot bind again!"
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2017-10-20 00:59:26 +08:00
|
|
|
|
listener->start();
|
|
|
|
|
|
listener->retain();
|
2017-10-21 19:09:31 +08:00
|
|
|
|
listener->m_bAlways = always;
|
2017-10-20 00:59:26 +08:00
|
|
|
|
listener->m_pParentNode = pParentNode;
|
|
|
|
|
|
s_vMouseListeners.push_back(listener);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-21 19:09:31 +08:00
|
|
|
|
void e2d::EMsgManager::bindListener(EKeyboardListener * listener, ENode * pParentNode, bool always /* = false */)
|
2017-10-20 00:59:26 +08:00
|
|
|
|
{
|
|
|
|
|
|
WARN_IF(listener == nullptr, "EKeyboardListener NULL pointer exception!");
|
|
|
|
|
|
WARN_IF(pParentNode == nullptr, "Bind EKeyboardListener with a NULL ENode pointer!");
|
|
|
|
|
|
|
|
|
|
|
|
if (listener && pParentNode)
|
|
|
|
|
|
{
|
2017-10-26 17:17:30 +08:00
|
|
|
|
ASSERT(
|
|
|
|
|
|
!listener->m_pParentNode,
|
|
|
|
|
|
"The listener is already binded, it cannot bind again!"
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2017-10-20 00:59:26 +08:00
|
|
|
|
listener->start();
|
|
|
|
|
|
listener->retain();
|
|
|
|
|
|
listener->m_pParentNode = pParentNode;
|
2017-10-21 19:09:31 +08:00
|
|
|
|
listener->m_bAlways = always;
|
2017-10-20 00:59:26 +08:00
|
|
|
|
s_vKeyboardListeners.push_back(listener);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EMsgManager::startMouseListeners(const EString & name)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (auto l : s_vMouseListeners)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (l->getName() == name)
|
|
|
|
|
|
{
|
|
|
|
|
|
l->start();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EMsgManager::stopMouseListeners(const EString & name)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (auto l : s_vMouseListeners)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (l->getName() == name)
|
|
|
|
|
|
{
|
|
|
|
|
|
l->stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EMsgManager::delMouseListeners(const EString & name)
|
|
|
|
|
|
{
|
|
|
|
|
|
// ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
EVector<EMouseListener*>::iterator mIter;
|
|
|
|
|
|
for (mIter = s_vMouseListeners.begin(); mIter != s_vMouseListeners.end();)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ((*mIter)->getName() == name)
|
|
|
|
|
|
{
|
2017-10-31 17:19:13 +08:00
|
|
|
|
SafeRelease(&(*mIter));
|
2017-10-20 00:59:26 +08:00
|
|
|
|
mIter = s_vMouseListeners.erase(mIter);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
mIter++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EMsgManager::startKeyboardListeners(const EString & name)
|
|
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
for (auto l : s_vKeyboardListeners)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (l->getName() == name)
|
|
|
|
|
|
{
|
|
|
|
|
|
l->start();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EMsgManager::stopKeyboardListeners(const EString & name)
|
|
|
|
|
|
{
|
|
|
|
|
|
// ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
for (auto l : s_vKeyboardListeners)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (l->getName() == name)
|
|
|
|
|
|
{
|
|
|
|
|
|
l->stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EMsgManager::delKeyboardListeners(const EString & name)
|
|
|
|
|
|
{
|
|
|
|
|
|
// ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
EVector<EKeyboardListener*>::iterator kIter;
|
|
|
|
|
|
for (kIter = s_vKeyboardListeners.begin(); kIter != s_vKeyboardListeners.end();)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ((*kIter)->getName() == name)
|
|
|
|
|
|
{
|
2017-10-31 17:19:13 +08:00
|
|
|
|
SafeRelease(&(*kIter));
|
2017-10-20 00:59:26 +08:00
|
|
|
|
kIter = s_vKeyboardListeners.erase(kIter);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
kIter++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EMsgManager::startAllMouseListenersBindedWith(EScene * pParentScene)
|
|
|
|
|
|
{
|
2017-10-26 17:17:30 +08:00
|
|
|
|
EMsgManager::startAllMouseListenersBindedWith(pParentScene->getRoot());
|
2017-10-20 00:59:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EMsgManager::stopAllMouseListenersBindedWith(EScene * pParentScene)
|
|
|
|
|
|
{
|
2017-10-26 17:17:30 +08:00
|
|
|
|
EMsgManager::stopAllMouseListenersBindedWith(pParentScene->getRoot());
|
2017-10-20 00:59:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EMsgManager::startAllMouseListenersBindedWith(ENode * pParentNode)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (auto l : s_vMouseListeners)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (l->getParentNode() == pParentNode)
|
|
|
|
|
|
{
|
|
|
|
|
|
l->start();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for (auto child : pParentNode->getChildren())
|
|
|
|
|
|
{
|
|
|
|
|
|
EMsgManager::startAllMouseListenersBindedWith(child);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EMsgManager::stopAllMouseListenersBindedWith(ENode * pParentNode)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (auto l : s_vMouseListeners)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (l->getParentNode() == pParentNode)
|
|
|
|
|
|
{
|
|
|
|
|
|
l->stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for (auto child : pParentNode->getChildren())
|
|
|
|
|
|
{
|
|
|
|
|
|
EMsgManager::stopAllMouseListenersBindedWith(child);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EMsgManager::startAllKeyboardListenersBindedWith(EScene * pParentScene)
|
|
|
|
|
|
{
|
2017-10-26 17:17:30 +08:00
|
|
|
|
EMsgManager::startAllKeyboardListenersBindedWith(pParentScene->getRoot());
|
2017-10-20 00:59:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EMsgManager::stopAllKeyboardListenersBindedWith(EScene * pParentScene)
|
|
|
|
|
|
{
|
2017-10-26 17:17:30 +08:00
|
|
|
|
EMsgManager::stopAllKeyboardListenersBindedWith(pParentScene->getRoot());
|
2017-10-20 00:59:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EMsgManager::startAllKeyboardListenersBindedWith(ENode * pParentNode)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (auto l : s_vKeyboardListeners)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (l->getParentNode() == pParentNode)
|
|
|
|
|
|
{
|
|
|
|
|
|
l->start();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for (auto child : pParentNode->getChildren())
|
|
|
|
|
|
{
|
|
|
|
|
|
EMsgManager::startAllKeyboardListenersBindedWith(child);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EMsgManager::stopAllKeyboardListenersBindedWith(ENode * pParentNode)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (auto l : s_vKeyboardListeners)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (l->getParentNode() == pParentNode)
|
|
|
|
|
|
{
|
|
|
|
|
|
l->stop();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
for (auto child : pParentNode->getChildren())
|
|
|
|
|
|
{
|
|
|
|
|
|
EMsgManager::stopAllKeyboardListenersBindedWith(child);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-21 19:09:31 +08:00
|
|
|
|
void e2d::EMsgManager::_clearAllMouseListenersBindedWith(ENode * pParentNode)
|
2017-10-20 00:59:26 +08:00
|
|
|
|
{
|
|
|
|
|
|
for (size_t i = 0; i < s_vMouseListeners.size();)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto t = s_vMouseListeners[i];
|
|
|
|
|
|
if (t->getParentNode() == pParentNode)
|
|
|
|
|
|
{
|
2017-10-31 17:19:13 +08:00
|
|
|
|
SafeRelease(&t);
|
2017-10-20 00:59:26 +08:00
|
|
|
|
s_vMouseListeners.erase(s_vMouseListeners.begin() + i);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-21 19:09:31 +08:00
|
|
|
|
void e2d::EMsgManager::_clearAllKeyboardListenersBindedWith(ENode * pParentNode)
|
2017-10-20 00:59:26 +08:00
|
|
|
|
{
|
|
|
|
|
|
for (size_t i = 0; i < s_vKeyboardListeners.size();)
|
|
|
|
|
|
{
|
|
|
|
|
|
auto t = s_vKeyboardListeners[i];
|
|
|
|
|
|
if (t->getParentNode() == pParentNode)
|
|
|
|
|
|
{
|
2017-10-31 17:19:13 +08:00
|
|
|
|
SafeRelease(&t);
|
2017-10-20 00:59:26 +08:00
|
|
|
|
s_vKeyboardListeners.erase(s_vKeyboardListeners.begin() + i);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
i++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EMsgManager::_clearManager()
|
|
|
|
|
|
{
|
|
|
|
|
|
s_vMouseListeners.clear();
|
|
|
|
|
|
s_vKeyboardListeners.clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EMsgManager::startAllMouseListeners()
|
|
|
|
|
|
{
|
|
|
|
|
|
EMsgManager::startAllMouseListenersBindedWith(EApp::getCurrentScene());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EMsgManager::stopAllMouseListeners()
|
|
|
|
|
|
{
|
|
|
|
|
|
EMsgManager::stopAllMouseListenersBindedWith(EApp::getCurrentScene());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EMsgManager::startAllKeyboardListeners()
|
|
|
|
|
|
{
|
|
|
|
|
|
EMsgManager::startAllKeyboardListenersBindedWith(EApp::getCurrentScene());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void e2d::EMsgManager::stopAllKeyboardListeners()
|
|
|
|
|
|
{
|
|
|
|
|
|
EMsgManager::stopAllKeyboardListenersBindedWith(EApp::getCurrentScene());
|
2017-10-17 21:22:25 +08:00
|
|
|
|
}
|