修复了部分bug

This commit is contained in:
Nomango 2017-11-03 22:14:07 +08:00
parent 1d5f3c7e55
commit 5c8d6fb8b0
6 changed files with 165 additions and 196 deletions

View File

@ -97,7 +97,8 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Manifest>
<AdditionalManifestFiles>DeclareDPIAware.manifest</AdditionalManifestFiles>
<AdditionalManifestFiles>
</AdditionalManifestFiles>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -132,7 +133,8 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Manifest>
<AdditionalManifestFiles>DeclareDPIAware.manifest</AdditionalManifestFiles>
<AdditionalManifestFiles>
</AdditionalManifestFiles>
</Manifest>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">

View File

@ -1,4 +1,4 @@
#include "..\Easy2D\easy2d.h"
#include <easy2d.h>
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();

View File

@ -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)
{
if (action)
{
m_vActions.push_back(action);
action->retain();
}
}
e2d::EActionSequence * e2d::EActionSequence::clone() const

View File

@ -625,31 +625,7 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
{
// 处理窗口消息
LRESULT result = 0;
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;
e2d::EApp *pEApp = EApp::get();
if (pEApp)
{
@ -675,7 +651,6 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
}
}
result = 0;
wasHandled = true;
break;
// 处理按键消息
@ -689,7 +664,6 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
}
}
result = 0;
wasHandled = true;
break;
// 处理窗口大小变化消息
@ -702,8 +676,6 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
// 错误,因为这个错误将在下一次调用 EndDraw 时产生
GetRenderTarget()->Resize(D2D1::SizeU(width, height));
}
result = 0;
wasHandled = true;
break;
// 处理分辨率变化消息
@ -713,7 +685,6 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
InvalidateRect(hWnd, NULL, FALSE);
}
result = 0;
wasHandled = true;
break;
// 重绘窗口
@ -723,7 +694,6 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
ValidateRect(hWnd, NULL);
}
result = 0;
wasHandled = true;
break;
// 窗口激活消息
@ -749,7 +719,6 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
}
}
result = 1;
wasHandled = true;
break;
// 窗口关闭消息
@ -772,7 +741,6 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
}
}
result = 1;
wasHandled = true;
break;
// 窗口被销毁
@ -784,14 +752,9 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
PostQuitMessage(0);
}
result = 1;
wasHandled = true;
break;
}
}
// 对当前消息没有特定的处理程序时,执行默认的窗口函数
if (!wasHandled)
{
default:
result = DefWindowProc(hWnd, message, wParam, lParam);
}
}

View File

@ -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()))

View File

@ -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<unsigned int, MciPlayer *> MusicList;
typedef std::pair<unsigned int, MciPlayer *> Music;
typedef std::map<size_t, MciPlayer *> MusicList;
typedef std::pair<size_t, MciPlayer *> 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())