diff --git a/ConsoleDemo/ConsoleDemo.vcxproj b/ConsoleDemo/ConsoleDemo.vcxproj
index 3500968a..a32b2be5 100644
--- a/ConsoleDemo/ConsoleDemo.vcxproj
+++ b/ConsoleDemo/ConsoleDemo.vcxproj
@@ -97,7 +97,8 @@
true
- DeclareDPIAware.manifest
+
+
@@ -132,7 +133,8 @@
true
- DeclareDPIAware.manifest
+
+
diff --git a/ConsoleDemo/main.cpp b/ConsoleDemo/main.cpp
index 13f1f568..10f68c43 100644
--- a/ConsoleDemo/main.cpp
+++ b/ConsoleDemo/main.cpp
@@ -1,4 +1,4 @@
-#include "..\Easy2D\easy2d.h"
+#include
int main()
{
@@ -6,6 +6,7 @@ int main()
if (app.init(L"Easy2D Demo", 320, 320))
{
+ app.showConsole();
auto scene = new EScene();
auto sprite = new ESprite(L"elyse.png");
@@ -17,20 +18,15 @@ int main()
// 移动精灵的位置
sprite->setPos(width / 2, height / 2);
//sprite->setAnchor(0, 0);
- scene->add(sprite);
+ //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(scene);
- EMsgManager::stopAllMouseListeners();
- EMsgManager::stopAllKeyboardListeners();
scene->add(text, -1);
+ sprite->setName(L"test");
+ auto button = new EButton(sprite, [=] {
+ EApp::enterScene(new EScene);
+ });
+ scene->add(button);
+
app.enterScene(scene);
app.run();
diff --git a/Easy2D/Action/EActionSequence.cpp b/Easy2D/Action/EActionSequence.cpp
index f62c5eea..c4ed1ffe 100644
--- a/Easy2D/Action/EActionSequence.cpp
+++ b/Easy2D/Action/EActionSequence.cpp
@@ -9,16 +9,14 @@ e2d::EActionSequence::EActionSequence() :
e2d::EActionSequence::EActionSequence(int number, EAction * action1, ...) :
m_nActionIndex(0)
{
- va_list params;
- va_start(params, number);
+ EAction ** ppAction = &action1;
while (number > 0)
{
- this->addAction(va_arg(params, EAction*));
+ this->addAction(*ppAction);
+ ppAction++;
number--;
}
-
- va_end(params);
}
e2d::EActionSequence::~EActionSequence()
@@ -77,8 +75,11 @@ void e2d::EActionSequence::_reset()
void e2d::EActionSequence::addAction(EAction * action)
{
- m_vActions.push_back(action);
- action->retain();
+ if (action)
+ {
+ m_vActions.push_back(action);
+ action->retain();
+ }
}
e2d::EActionSequence * e2d::EActionSequence::clone() const
diff --git a/Easy2D/Base/EApp.cpp b/Easy2D/Base/EApp.cpp
index bc7fb8d1..0b68ea14 100644
--- a/Easy2D/Base/EApp.cpp
+++ b/Easy2D/Base/EApp.cpp
@@ -625,173 +625,136 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
{
// 处理窗口消息
LRESULT result = 0;
+ e2d::EApp *pEApp = EApp::get();
- if (message == WM_CREATE)
+ if (pEApp)
{
- // 获取发送 WM_CREATE 消息的 EApp 实例对象指针
- LPCREATESTRUCT pcs = (LPCREATESTRUCT)lParam;
- e2d::EApp *pEApp = (e2d::EApp *)pcs->lpCreateParams;
- // 保存 EApp 指针到 GWLP_USERDATA 字段
- ::SetWindowLongPtrW(
- hWnd,
- GWLP_USERDATA,
- PtrToUlong(pEApp)
- );
-
- result = 1;
- }
- else
- {
- // 从 GWLP_USERDATA 字段取出 EApp 指针
- e2d::EApp *pEApp = reinterpret_cast(static_cast(
- ::GetWindowLongPtrW(
- hWnd,
- GWLP_USERDATA
- )));
-
- bool wasHandled = false;
-
- if (pEApp)
+ switch (message)
{
- switch (message)
+ // 处理鼠标消息
+ case WM_LBUTTONUP:
+ case WM_LBUTTONDOWN:
+ case WM_LBUTTONDBLCLK:
+ case WM_MBUTTONUP:
+ case WM_MBUTTONDOWN:
+ case WM_MBUTTONDBLCLK:
+ case WM_RBUTTONUP:
+ case WM_RBUTTONDOWN:
+ case WM_RBUTTONDBLCLK:
+ case WM_MOUSEMOVE:
+ case WM_MOUSEWHEEL:
+ {
+ // 执行场景切换时屏蔽按键和鼠标消息
+ if (!pEApp->m_bTransitional && !pEApp->m_pNextScene)
{
- // 处理鼠标消息
- case WM_LBUTTONUP:
- case WM_LBUTTONDOWN:
- case WM_LBUTTONDBLCLK:
- case WM_MBUTTONUP:
- case WM_MBUTTONDOWN:
- case WM_MBUTTONDBLCLK:
- case WM_RBUTTONUP:
- case WM_RBUTTONDOWN:
- case WM_RBUTTONDBLCLK:
- case WM_MOUSEMOVE:
- case WM_MOUSEWHEEL:
- {
- // 执行场景切换时屏蔽按键和鼠标消息
- if (!pEApp->m_bTransitional && !pEApp->m_pNextScene)
- {
- EMsgManager::MouseProc(message, wParam, lParam);
- }
- }
- result = 0;
- wasHandled = true;
- break;
-
- // 处理按键消息
- case WM_KEYDOWN:
- case WM_KEYUP:
- {
- // 执行场景切换时屏蔽按键和鼠标消息
- if (!pEApp->m_bTransitional && !pEApp->m_pNextScene)
- {
- EMsgManager::KeyboardProc(message, wParam, lParam);
- }
- }
- result = 0;
- wasHandled = true;
- break;
-
- // 处理窗口大小变化消息
- case WM_SIZE:
- {
- UINT width = LOWORD(lParam);
- UINT height = HIWORD(lParam);
- // 如果程序接收到一个 WM_SIZE 消息,这个方法将调整渲染
- // 目标适当。它可能会调用失败,但是这里可以忽略有可能的
- // 错误,因为这个错误将在下一次调用 EndDraw 时产生
- GetRenderTarget()->Resize(D2D1::SizeU(width, height));
- }
- result = 0;
- wasHandled = true;
- break;
-
- // 处理分辨率变化消息
- case WM_DISPLAYCHANGE:
- {
- // 重绘客户区
- InvalidateRect(hWnd, NULL, FALSE);
- }
- result = 0;
- wasHandled = true;
- break;
-
- // 重绘窗口
- case WM_PAINT:
- {
- pEApp->_onRender();
- ValidateRect(hWnd, NULL);
- }
- result = 0;
- wasHandled = true;
- break;
-
- // 窗口激活消息
- case WM_ACTIVATE:
- {
- if (LOWORD(wParam) == WA_INACTIVE)
- {
- if (pEApp->getCurrentScene() &&
- pEApp->getCurrentScene()->onInactive() &&
- pEApp->onInactive())
- {
- pEApp->m_bPaused = true;
- }
- }
- else
- {
- if (pEApp->getCurrentScene() &&
- pEApp->getCurrentScene()->onActivate() &&
- pEApp->onActivate())
- {
- pEApp->m_bPaused = false;
- }
- }
- }
- result = 1;
- wasHandled = true;
- break;
-
- // 窗口关闭消息
- case WM_CLOSE:
- {
- if (!pEApp->getCurrentScene())
- {
- if (pEApp->onCloseWindow())
- {
- DestroyWindow(hWnd);
- }
- }
- else
- {
- if (pEApp->getCurrentScene()->onCloseWindow() &&
- pEApp->onCloseWindow())
- {
- DestroyWindow(hWnd);
- }
- }
- }
- result = 1;
- wasHandled = true;
- break;
-
- // 窗口被销毁
- case WM_DESTROY:
- {
- // 退出程序
- pEApp->quit();
- // 发送退出消息
- PostQuitMessage(0);
- }
- result = 1;
- wasHandled = true;
- break;
+ EMsgManager::MouseProc(message, wParam, lParam);
}
}
+ result = 0;
+ break;
- // 对当前消息没有特定的处理程序时,执行默认的窗口函数
- if (!wasHandled)
+ // 处理按键消息
+ case WM_KEYDOWN:
+ case WM_KEYUP:
{
+ // 执行场景切换时屏蔽按键和鼠标消息
+ if (!pEApp->m_bTransitional && !pEApp->m_pNextScene)
+ {
+ EMsgManager::KeyboardProc(message, wParam, lParam);
+ }
+ }
+ result = 0;
+ break;
+
+ // 处理窗口大小变化消息
+ case WM_SIZE:
+ {
+ UINT width = LOWORD(lParam);
+ UINT height = HIWORD(lParam);
+ // 如果程序接收到一个 WM_SIZE 消息,这个方法将调整渲染
+ // 目标适当。它可能会调用失败,但是这里可以忽略有可能的
+ // 错误,因为这个错误将在下一次调用 EndDraw 时产生
+ GetRenderTarget()->Resize(D2D1::SizeU(width, height));
+ }
+ break;
+
+ // 处理分辨率变化消息
+ case WM_DISPLAYCHANGE:
+ {
+ // 重绘客户区
+ InvalidateRect(hWnd, NULL, FALSE);
+ }
+ result = 0;
+ break;
+
+ // 重绘窗口
+ case WM_PAINT:
+ {
+ pEApp->_onRender();
+ ValidateRect(hWnd, NULL);
+ }
+ result = 0;
+ break;
+
+ // 窗口激活消息
+ case WM_ACTIVATE:
+ {
+ if (LOWORD(wParam) == WA_INACTIVE)
+ {
+ if (pEApp->getCurrentScene() &&
+ pEApp->getCurrentScene()->onInactive() &&
+ pEApp->onInactive())
+ {
+ pEApp->m_bPaused = true;
+ }
+ }
+ else
+ {
+ if (pEApp->getCurrentScene() &&
+ pEApp->getCurrentScene()->onActivate() &&
+ pEApp->onActivate())
+ {
+ pEApp->m_bPaused = false;
+ }
+ }
+ }
+ result = 1;
+ break;
+
+ // 窗口关闭消息
+ case WM_CLOSE:
+ {
+ if (!pEApp->getCurrentScene())
+ {
+ if (pEApp->onCloseWindow())
+ {
+ DestroyWindow(hWnd);
+ }
+ }
+ else
+ {
+ if (pEApp->getCurrentScene()->onCloseWindow() &&
+ pEApp->onCloseWindow())
+ {
+ DestroyWindow(hWnd);
+ }
+ }
+ }
+ result = 1;
+ break;
+
+ // 窗口被销毁
+ case WM_DESTROY:
+ {
+ // 退出程序
+ pEApp->quit();
+ // 发送退出消息
+ PostQuitMessage(0);
+ }
+ result = 1;
+ break;
+
+ default:
result = DefWindowProc(hWnd, message, wParam, lParam);
}
}
diff --git a/Easy2D/Node/EButton.cpp b/Easy2D/Node/EButton.cpp
index b48c4f28..c5357b07 100644
--- a/Easy2D/Node/EButton.cpp
+++ b/Easy2D/Node/EButton.cpp
@@ -109,6 +109,8 @@ void e2d::EButton::setDisable(bool disable)
void e2d::EButton::setCallback(const BUTTON_CLICK_CALLBACK & callback)
{
+ EMsgManager::stopAllMouseListenersBindedWith(this);
+
auto listener = new EListenerMouse(std::bind(&EButton::_listenerCallback, this));
EMsgManager::bindListener(listener, this, true);
m_Callback = callback;
@@ -153,6 +155,11 @@ void e2d::EButton::_listenerCallback()
{
if (!m_bIsDisable)
{
+ if (!m_pDisplayed)
+ {
+ m_pDisplayed = m_pNormal;
+ }
+
if (EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DOWN &&
m_pDisplayed &&
m_pDisplayed->isPointIn(EMouseMsg::getPos()))
diff --git a/Easy2D/Tool/EMusicUtils.cpp b/Easy2D/Tool/EMusicUtils.cpp
index 947f63b2..c831de24 100644
--- a/Easy2D/Tool/EMusicUtils.cpp
+++ b/Easy2D/Tool/EMusicUtils.cpp
@@ -20,8 +20,8 @@ public:
~MciPlayer();
void close();
- bool open(const e2d::EString & pFileName, UINT uId);
- bool open(const e2d::EString & pResouceName, const e2d::EString & pResouceType, const e2d::EString & musicExtension, UINT uId);
+ bool open(const e2d::EString & pFileName, size_t uId);
+ bool open(const e2d::EString & pResouceName, const e2d::EString & pResouceType, const e2d::EString & musicExtension, size_t uId);
void play(bool bLoop = false);
void pause();
void resume();
@@ -29,13 +29,13 @@ public:
void rewind();
void setVolume(float volume);
bool isPlaying();
- UINT getSoundID();
+ size_t getSoundID();
private:
void _sendCommand(int nCommand, DWORD_PTR param1 = 0, DWORD_PTR parma2 = 0);
MCIDEVICEID m_dev;
- UINT m_nSoundID;
+ size_t m_nSoundID;
bool m_bPlaying;
bool m_bLoop;
e2d::EString m_sTempFileName;
@@ -55,7 +55,7 @@ MciPlayer::~MciPlayer()
close(); // 关闭播放器
}
-bool MciPlayer::open(const e2d::EString & pFileName, UINT uId)
+bool MciPlayer::open(const e2d::EString & pFileName, size_t uId)
{
// 忽略不存在的文件
if (pFileName.empty())
@@ -91,7 +91,7 @@ bool MciPlayer::open(const e2d::EString & pFileName, UINT uId)
}
}
-bool MciPlayer::open(const e2d::EString & pResouceName, const e2d::EString & pResouceType, const e2d::EString & musicExtension, UINT uId)
+bool MciPlayer::open(const e2d::EString & pResouceName, const e2d::EString & pResouceType, const e2d::EString & musicExtension, size_t uId)
{
// 忽略不存在的文件
if (pResouceName.empty() || pResouceType.empty() || musicExtension.empty()) return false;
@@ -233,7 +233,7 @@ bool MciPlayer::isPlaying()
return m_bPlaying;
}
-UINT MciPlayer::getSoundID()
+size_t MciPlayer::getSoundID()
{
return m_nSoundID;
}
@@ -257,8 +257,8 @@ void MciPlayer::_sendCommand(int nCommand, DWORD_PTR param1, DWORD_PTR parma2)
////////////////////////////////////////////////////////////////////
-typedef std::map MusicList;
-typedef std::pair Music;
+typedef std::map MusicList;
+typedef std::pair Music;
static MusicList& getMciPlayerList()
@@ -300,7 +300,7 @@ void e2d::EMusicUtils::setVolume(float volume)
void e2d::EMusicUtils::setVolume(const EString & musicFilePath, float volume)
{
- unsigned int nRet = ::Hash(musicFilePath);
+ size_t nRet = ::Hash(musicFilePath);
MusicList::iterator p = getMciPlayerList().find(nRet);
if (p != getMciPlayerList().end())
@@ -370,7 +370,7 @@ void e2d::EMusicUtils::setBackgroundMusicVolume(float volume)
void e2d::EMusicUtils::playMusic(const EString & musicFilePath, bool bLoop)
{
- unsigned int nRet = ::Hash(musicFilePath);
+ size_t nRet = ::Hash(musicFilePath);
preloadMusic(musicFilePath);
@@ -383,7 +383,7 @@ void e2d::EMusicUtils::playMusic(const EString & musicFilePath, bool bLoop)
void e2d::EMusicUtils::playMusic(const EString & musicResourceName, const EString & musicResourceType, const EString & musicExtension, bool loop)
{
- unsigned int nRet = ::Hash(musicResourceName);
+ size_t nRet = ::Hash(musicResourceName);
preloadMusic(musicResourceName, musicResourceType, musicExtension);
@@ -407,7 +407,7 @@ void e2d::EMusicUtils::preloadMusic(const EString & musicFilePath)
{
if (musicFilePath.empty()) return;
- int nRet = ::Hash(musicFilePath);
+ size_t nRet = ::Hash(musicFilePath);
if (getMciPlayerList().end() != getMciPlayerList().find(nRet)) return;
@@ -426,7 +426,7 @@ void e2d::EMusicUtils::preloadMusic(const EString & musicResourceName, const ESt
{
if (musicResourceName.empty() || musicResourceType.empty()) return;
- int nRet = ::Hash(musicResourceName);
+ size_t nRet = ::Hash(musicResourceName);
if (getMciPlayerList().end() != getMciPlayerList().find(nRet)) return;
@@ -485,7 +485,7 @@ void e2d::EMusicUtils::stopAllMusics()
void e2d::EMusicUtils::unloadMusic(const EString & musicFilePath)
{
- unsigned int nID = ::Hash(musicFilePath);
+ size_t nID = ::Hash(musicFilePath);
MusicList::iterator p = getMciPlayerList().find(nID);
if (p != getMciPlayerList().end())