修复了部分bug
This commit is contained in:
parent
1d5f3c7e55
commit
5c8d6fb8b0
|
|
@ -97,7 +97,8 @@
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
</Link>
|
</Link>
|
||||||
<Manifest>
|
<Manifest>
|
||||||
<AdditionalManifestFiles>DeclareDPIAware.manifest</AdditionalManifestFiles>
|
<AdditionalManifestFiles>
|
||||||
|
</AdditionalManifestFiles>
|
||||||
</Manifest>
|
</Manifest>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
|
@ -132,7 +133,8 @@
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
</Link>
|
</Link>
|
||||||
<Manifest>
|
<Manifest>
|
||||||
<AdditionalManifestFiles>DeclareDPIAware.manifest</AdditionalManifestFiles>
|
<AdditionalManifestFiles>
|
||||||
|
</AdditionalManifestFiles>
|
||||||
</Manifest>
|
</Manifest>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include "..\Easy2D\easy2d.h"
|
#include <easy2d.h>
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
@ -6,6 +6,7 @@ int main()
|
||||||
|
|
||||||
if (app.init(L"Easy2D Demo", 320, 320))
|
if (app.init(L"Easy2D Demo", 320, 320))
|
||||||
{
|
{
|
||||||
|
app.showConsole();
|
||||||
auto scene = new EScene();
|
auto scene = new EScene();
|
||||||
|
|
||||||
auto sprite = new ESprite(L"elyse.png");
|
auto sprite = new ESprite(L"elyse.png");
|
||||||
|
|
@ -17,20 +18,15 @@ int main()
|
||||||
// 移动精灵的位置
|
// 移动精灵的位置
|
||||||
sprite->setPos(width / 2, height / 2);
|
sprite->setPos(width / 2, height / 2);
|
||||||
//sprite->setAnchor(0, 0);
|
//sprite->setAnchor(0, 0);
|
||||||
scene->add(sprite);
|
//scene->add(sprite);
|
||||||
auto text = new EText(L"balabalabalabalabala", L"宋体", 80, EColor::BLUE);
|
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);
|
scene->add(text, -1);
|
||||||
|
sprite->setName(L"test");
|
||||||
|
auto button = new EButton(sprite, [=] {
|
||||||
|
EApp::enterScene(new EScene);
|
||||||
|
});
|
||||||
|
scene->add(button);
|
||||||
|
|
||||||
app.enterScene(scene);
|
app.enterScene(scene);
|
||||||
|
|
||||||
app.run();
|
app.run();
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,14 @@ e2d::EActionSequence::EActionSequence() :
|
||||||
e2d::EActionSequence::EActionSequence(int number, EAction * action1, ...) :
|
e2d::EActionSequence::EActionSequence(int number, EAction * action1, ...) :
|
||||||
m_nActionIndex(0)
|
m_nActionIndex(0)
|
||||||
{
|
{
|
||||||
va_list params;
|
EAction ** ppAction = &action1;
|
||||||
va_start(params, number);
|
|
||||||
|
|
||||||
while (number > 0)
|
while (number > 0)
|
||||||
{
|
{
|
||||||
this->addAction(va_arg(params, EAction*));
|
this->addAction(*ppAction);
|
||||||
|
ppAction++;
|
||||||
number--;
|
number--;
|
||||||
}
|
}
|
||||||
|
|
||||||
va_end(params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
e2d::EActionSequence::~EActionSequence()
|
e2d::EActionSequence::~EActionSequence()
|
||||||
|
|
@ -76,10 +74,13 @@ void e2d::EActionSequence::_reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
void e2d::EActionSequence::addAction(EAction * action)
|
void e2d::EActionSequence::addAction(EAction * action)
|
||||||
|
{
|
||||||
|
if (action)
|
||||||
{
|
{
|
||||||
m_vActions.push_back(action);
|
m_vActions.push_back(action);
|
||||||
action->retain();
|
action->retain();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
e2d::EActionSequence * e2d::EActionSequence::clone() const
|
e2d::EActionSequence * e2d::EActionSequence::clone() const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -625,31 +625,7 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
|
||||||
{
|
{
|
||||||
// 处理窗口消息
|
// 处理窗口消息
|
||||||
LRESULT result = 0;
|
LRESULT result = 0;
|
||||||
|
e2d::EApp *pEApp = EApp::get();
|
||||||
if (message == WM_CREATE)
|
|
||||||
{
|
|
||||||
// 获取发送 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<e2d::EApp *>(static_cast<LONG_PTR>(
|
|
||||||
::GetWindowLongPtrW(
|
|
||||||
hWnd,
|
|
||||||
GWLP_USERDATA
|
|
||||||
)));
|
|
||||||
|
|
||||||
bool wasHandled = false;
|
|
||||||
|
|
||||||
if (pEApp)
|
if (pEApp)
|
||||||
{
|
{
|
||||||
|
|
@ -675,7 +651,6 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = 0;
|
result = 0;
|
||||||
wasHandled = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 处理按键消息
|
// 处理按键消息
|
||||||
|
|
@ -689,7 +664,6 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = 0;
|
result = 0;
|
||||||
wasHandled = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 处理窗口大小变化消息
|
// 处理窗口大小变化消息
|
||||||
|
|
@ -702,8 +676,6 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
|
||||||
// 错误,因为这个错误将在下一次调用 EndDraw 时产生
|
// 错误,因为这个错误将在下一次调用 EndDraw 时产生
|
||||||
GetRenderTarget()->Resize(D2D1::SizeU(width, height));
|
GetRenderTarget()->Resize(D2D1::SizeU(width, height));
|
||||||
}
|
}
|
||||||
result = 0;
|
|
||||||
wasHandled = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 处理分辨率变化消息
|
// 处理分辨率变化消息
|
||||||
|
|
@ -713,7 +685,6 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
|
||||||
InvalidateRect(hWnd, NULL, FALSE);
|
InvalidateRect(hWnd, NULL, FALSE);
|
||||||
}
|
}
|
||||||
result = 0;
|
result = 0;
|
||||||
wasHandled = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 重绘窗口
|
// 重绘窗口
|
||||||
|
|
@ -723,7 +694,6 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
|
||||||
ValidateRect(hWnd, NULL);
|
ValidateRect(hWnd, NULL);
|
||||||
}
|
}
|
||||||
result = 0;
|
result = 0;
|
||||||
wasHandled = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 窗口激活消息
|
// 窗口激活消息
|
||||||
|
|
@ -749,7 +719,6 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = 1;
|
result = 1;
|
||||||
wasHandled = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 窗口关闭消息
|
// 窗口关闭消息
|
||||||
|
|
@ -772,7 +741,6 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = 1;
|
result = 1;
|
||||||
wasHandled = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// 窗口被销毁
|
// 窗口被销毁
|
||||||
|
|
@ -784,14 +752,9 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
|
||||||
PostQuitMessage(0);
|
PostQuitMessage(0);
|
||||||
}
|
}
|
||||||
result = 1;
|
result = 1;
|
||||||
wasHandled = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 对当前消息没有特定的处理程序时,执行默认的窗口函数
|
default:
|
||||||
if (!wasHandled)
|
|
||||||
{
|
|
||||||
result = DefWindowProc(hWnd, message, wParam, lParam);
|
result = DefWindowProc(hWnd, message, wParam, lParam);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,8 @@ void e2d::EButton::setDisable(bool disable)
|
||||||
|
|
||||||
void e2d::EButton::setCallback(const BUTTON_CLICK_CALLBACK & callback)
|
void e2d::EButton::setCallback(const BUTTON_CLICK_CALLBACK & callback)
|
||||||
{
|
{
|
||||||
|
EMsgManager::stopAllMouseListenersBindedWith(this);
|
||||||
|
|
||||||
auto listener = new EListenerMouse(std::bind(&EButton::_listenerCallback, this));
|
auto listener = new EListenerMouse(std::bind(&EButton::_listenerCallback, this));
|
||||||
EMsgManager::bindListener(listener, this, true);
|
EMsgManager::bindListener(listener, this, true);
|
||||||
m_Callback = callback;
|
m_Callback = callback;
|
||||||
|
|
@ -153,6 +155,11 @@ void e2d::EButton::_listenerCallback()
|
||||||
{
|
{
|
||||||
if (!m_bIsDisable)
|
if (!m_bIsDisable)
|
||||||
{
|
{
|
||||||
|
if (!m_pDisplayed)
|
||||||
|
{
|
||||||
|
m_pDisplayed = m_pNormal;
|
||||||
|
}
|
||||||
|
|
||||||
if (EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DOWN &&
|
if (EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DOWN &&
|
||||||
m_pDisplayed &&
|
m_pDisplayed &&
|
||||||
m_pDisplayed->isPointIn(EMouseMsg::getPos()))
|
m_pDisplayed->isPointIn(EMouseMsg::getPos()))
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@ public:
|
||||||
~MciPlayer();
|
~MciPlayer();
|
||||||
|
|
||||||
void close();
|
void close();
|
||||||
bool open(const e2d::EString & pFileName, 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, UINT uId);
|
bool open(const e2d::EString & pResouceName, const e2d::EString & pResouceType, const e2d::EString & musicExtension, size_t uId);
|
||||||
void play(bool bLoop = false);
|
void play(bool bLoop = false);
|
||||||
void pause();
|
void pause();
|
||||||
void resume();
|
void resume();
|
||||||
|
|
@ -29,13 +29,13 @@ public:
|
||||||
void rewind();
|
void rewind();
|
||||||
void setVolume(float volume);
|
void setVolume(float volume);
|
||||||
bool isPlaying();
|
bool isPlaying();
|
||||||
UINT getSoundID();
|
size_t getSoundID();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _sendCommand(int nCommand, DWORD_PTR param1 = 0, DWORD_PTR parma2 = 0);
|
void _sendCommand(int nCommand, DWORD_PTR param1 = 0, DWORD_PTR parma2 = 0);
|
||||||
|
|
||||||
MCIDEVICEID m_dev;
|
MCIDEVICEID m_dev;
|
||||||
UINT m_nSoundID;
|
size_t m_nSoundID;
|
||||||
bool m_bPlaying;
|
bool m_bPlaying;
|
||||||
bool m_bLoop;
|
bool m_bLoop;
|
||||||
e2d::EString m_sTempFileName;
|
e2d::EString m_sTempFileName;
|
||||||
|
|
@ -55,7 +55,7 @@ MciPlayer::~MciPlayer()
|
||||||
close(); // 关闭播放器
|
close(); // 关闭播放器
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MciPlayer::open(const e2d::EString & pFileName, UINT uId)
|
bool MciPlayer::open(const e2d::EString & pFileName, size_t uId)
|
||||||
{
|
{
|
||||||
// 忽略不存在的文件
|
// 忽略不存在的文件
|
||||||
if (pFileName.empty())
|
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;
|
if (pResouceName.empty() || pResouceType.empty() || musicExtension.empty()) return false;
|
||||||
|
|
@ -233,7 +233,7 @@ bool MciPlayer::isPlaying()
|
||||||
return m_bPlaying;
|
return m_bPlaying;
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT MciPlayer::getSoundID()
|
size_t MciPlayer::getSoundID()
|
||||||
{
|
{
|
||||||
return m_nSoundID;
|
return m_nSoundID;
|
||||||
}
|
}
|
||||||
|
|
@ -257,8 +257,8 @@ void MciPlayer::_sendCommand(int nCommand, DWORD_PTR param1, DWORD_PTR parma2)
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
typedef std::map<unsigned int, MciPlayer *> MusicList;
|
typedef std::map<size_t, MciPlayer *> MusicList;
|
||||||
typedef std::pair<unsigned int, MciPlayer *> Music;
|
typedef std::pair<size_t, MciPlayer *> Music;
|
||||||
|
|
||||||
|
|
||||||
static MusicList& getMciPlayerList()
|
static MusicList& getMciPlayerList()
|
||||||
|
|
@ -300,7 +300,7 @@ void e2d::EMusicUtils::setVolume(float volume)
|
||||||
|
|
||||||
void e2d::EMusicUtils::setVolume(const EString & musicFilePath, 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);
|
MusicList::iterator p = getMciPlayerList().find(nRet);
|
||||||
if (p != getMciPlayerList().end())
|
if (p != getMciPlayerList().end())
|
||||||
|
|
@ -370,7 +370,7 @@ void e2d::EMusicUtils::setBackgroundMusicVolume(float volume)
|
||||||
|
|
||||||
void e2d::EMusicUtils::playMusic(const EString & musicFilePath, bool bLoop)
|
void e2d::EMusicUtils::playMusic(const EString & musicFilePath, bool bLoop)
|
||||||
{
|
{
|
||||||
unsigned int nRet = ::Hash(musicFilePath);
|
size_t nRet = ::Hash(musicFilePath);
|
||||||
|
|
||||||
preloadMusic(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)
|
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);
|
preloadMusic(musicResourceName, musicResourceType, musicExtension);
|
||||||
|
|
||||||
|
|
@ -407,7 +407,7 @@ void e2d::EMusicUtils::preloadMusic(const EString & musicFilePath)
|
||||||
{
|
{
|
||||||
if (musicFilePath.empty()) return;
|
if (musicFilePath.empty()) return;
|
||||||
|
|
||||||
int nRet = ::Hash(musicFilePath);
|
size_t nRet = ::Hash(musicFilePath);
|
||||||
|
|
||||||
if (getMciPlayerList().end() != getMciPlayerList().find(nRet)) return;
|
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;
|
if (musicResourceName.empty() || musicResourceType.empty()) return;
|
||||||
|
|
||||||
int nRet = ::Hash(musicResourceName);
|
size_t nRet = ::Hash(musicResourceName);
|
||||||
|
|
||||||
if (getMciPlayerList().end() != getMciPlayerList().find(nRet)) return;
|
if (getMciPlayerList().end() != getMciPlayerList().find(nRet)) return;
|
||||||
|
|
||||||
|
|
@ -485,7 +485,7 @@ void e2d::EMusicUtils::stopAllMusics()
|
||||||
|
|
||||||
void e2d::EMusicUtils::unloadMusic(const EString & musicFilePath)
|
void e2d::EMusicUtils::unloadMusic(const EString & musicFilePath)
|
||||||
{
|
{
|
||||||
unsigned int nID = ::Hash(musicFilePath);
|
size_t nID = ::Hash(musicFilePath);
|
||||||
|
|
||||||
MusicList::iterator p = getMciPlayerList().find(nID);
|
MusicList::iterator p = getMciPlayerList().find(nID);
|
||||||
if (p != getMciPlayerList().end())
|
if (p != getMciPlayerList().end())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue