重做了EString类

This commit is contained in:
Nomango 2017-12-11 18:17:24 +08:00
parent 7c035c63ed
commit ef85e2b88d
29 changed files with 814 additions and 342 deletions

View File

@ -1,5 +1,5 @@
#include "..\Easy2D\easy2d.h"
#include <iostream>
int WINAPI WinMain(
HINSTANCE hInstance,
@ -8,69 +8,109 @@ int WINAPI WinMain(
int nCmdShow
)
{
if (!EApp::init(L"Easy2D Demo", 640, 480))
if (!EApp::init(L"Demo", 250, 150))
return -1;
EString str;
str += L"123";
str += L"4";
UINT h1 = str.hash();
EString s = L"abcdea";
EString ss = s.sub(0);
EString sss = s.sub(0, 5);
EString ssss = s.sub(0, 9);
EString ssssss = s.sub(1, 4);
EString sssss = s.sub(-1, 3);
int i = s.findFirstOf(L'a');
int j = s.findLastOf(L'a');
EString string = L"Hello";
string = string + 2017 + L"!";
EString str2;
str2 += 1;
str2 += 2L;
str2 += 2.3;
str2 += 4.6f;
UINT h2 = str2.hash();
str2 += std::wstring(L"sdf");
EString str3;
str3 += str2 + str;
UINT h3 = str3.hash();
auto scene = new EScene();
scene->retain();
EApp::enterScene(scene);
auto text = new EText(L"中文测试中文测试中文测试中文测试中文测试中文测试中文测试", L"楷体");
text->setPos(EApp::getWidth() / 2, EApp::getHeight() / 2);
//text->setWordWrapping(true);
//text->setWordWrappingWidth(130);
text->setRotation(40);
text->runAction(new EActionLoop(new EActionTwo(new EActionFadeOut(1), new EActionFadeIn(1))));
scene->add(text);
for (int i = 0; i < 25; i++)
{
auto sprite = new ESprite(L"test.png");
sprite->setScale(0.5f);
sprite->setPos(ERandom::between(0, EApp::getWidth()), ERandom::between(0, EApp::getHeight()));
scene->add(sprite);
}
auto listener = new EListenerKeyboardPress([=]() {
if (EKeyboardMsg::getKeyValue() == EKeyboardMsg::KEY::SPACE)
{
EApp::backScene(new ETransitionMove(0.5f, ETransitionMove::DOWN));
}
});
listener->bindWith(scene);
//auto scene = new EScene();
//scene->retain();
auto scene2 = new EScene();
//auto text = new EText(L"中文测试中文测试中文测试中文测试中文测试中文测试中文测试", L"楷体");
//text->setPos(EApp::getWidth() / 2, EApp::getHeight() / 2);
////text->setWordWrapping(true);
////text->setWordWrappingWidth(130);
//text->setRotation(40);
//text->runAction(new EActionLoop(new EActionTwo(new EActionFadeOut(1), new EActionFadeIn(1))));
//scene->add(text);
auto bird = new ESprite(L"atlas.png", 5, 982, 34, 24);
auto animation = new EAnimation();
animation->addFrame(new ESpriteFrame(L"atlas.png", 5, 982, 34, 24));
animation->addFrame(new ESpriteFrame(L"atlas.png", 61, 982, 34, 24));
animation->addFrame(new ESpriteFrame(L"atlas.png", 117, 982, 34, 24));
animation->addFrame(new ESpriteFrame(L"atlas.png", 61, 982, 34, 24));
bird->runAction(new EActionLoop(animation));
bird->setPivot(0.5f, 0.5f);
bird->setPos(EApp::getWidth() / 2, EApp::getHeight() / 2);
scene2->add(bird);
//auto listener = new EListenerKeyboardPress([=]() {
// if (EKeyboardMsg::getKeyValue() == EKeyboardMsg::KEY::SPACE)
// {
// EApp::backScene(new ETransitionMove(0.5f, ETransitionMove::DOWN));
// }
//});
//listener->bindWith(scene);
auto btnStart = new ESprite(L"atlas.png", 702, 234, 116, 70);
auto btnStartSelected = new ESprite(L"atlas.png", 702, 234, 116, 70);
btnStartSelected->setPosY(5);
auto button = new EButton(btnStart, btnStartSelected, [=] {
/*if (EApp::isPaused())
{
EApp::resume();
}
else
{
EApp::pause();
}*/
EApp::enterScene(scene, new ETransitionMove(1, ETransitionMove::RIGHT));
});
button->setPivot(0.5f, 0.5f);
button->setPos(EApp::getWidth() / 2, EApp::getHeight() / 2 + 100);
scene2->add(button);
//auto scene2 = new EScene();
EMusicUtils::playMusic(L"music.wav", -1);
//auto bird = new ESprite(L"atlas.png", 5, 982, 34, 24);
//auto animation = new EAnimation();
//animation->addFrame(new ESpriteFrame(L"atlas.png", 5, 982, 34, 24));
//animation->addFrame(new ESpriteFrame(L"atlas.png", 61, 982, 34, 24));
//animation->addFrame(new ESpriteFrame(L"atlas.png", 117, 982, 34, 24));
//animation->addFrame(new ESpriteFrame(L"atlas.png", 61, 982, 34, 24));
//bird->runAction(new EActionLoop(animation));
//bird->setPivot(0.5f, 0.5f);
//bird->setPos(EApp::getWidth() / 2, EApp::getHeight() / 2);
//scene2->add(bird);
/*scene2->runAction(new EActionSequence(5,
new EActionCallback([]() { EMusicUtils::playMusic(L"music.wav", -1); }),
new EActionDelay(3),
new EActionCallback([]() { EMusicUtils::pauseMusic(L"music.wav"); }),
new EActionDelay(10),
new EActionCallback([]() { EMusicUtils::resumeMusic(L"music.wav"); })));*/
//auto btnStart = new ESprite(L"atlas.png", 702, 234, 116, 70);
//auto btnStartSelected = new ESprite(L"atlas.png", 702, 234, 116, 70);
//btnStartSelected->setPosY(5);
//auto button = new EButton(btnStart, btnStartSelected, [=] {
// /*if (EApp::isPaused())
// {
// EApp::resume();
// }
// else
// {
// EApp::pause();
// }*/
// EApp::enterScene(scene, new ETransitionMove(1, ETransitionMove::RIGHT));
//});
//button->setPivot(0.5f, 0.5f);
//button->setPos(EApp::getWidth() / 2, EApp::getHeight() / 2 + 100);
//scene2->add(button);
EApp::enterScene(scene2, new ETransitionMove(1, ETransitionMove::UP));
//EMusicUtils::playMusic(L"music.wav", -1);
///*scene2->runAction(new EActionSequence(5,
// new EActionCallback([]() { EMusicUtils::playMusic(L"music.wav", -1); }),
// new EActionDelay(3),
// new EActionCallback([]() { EMusicUtils::pauseMusic(L"music.wav"); }),
// new EActionDelay(10),
// new EActionCallback([]() { EMusicUtils::resumeMusic(L"music.wav"); })));*/
//EApp::enterScene(scene2, new ETransitionMove(1, ETransitionMove::UP));
return EApp::run();
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 18 KiB

BIN
Demo/test2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -4,7 +4,7 @@
e2d::EActionMoveBy::EActionMoveBy(float duration, EVec vector) :
EActionGradual(duration)
{
m_MoveVector = vector;
m_MoveVec = vector;
}
void e2d::EActionMoveBy::_init()
@ -30,8 +30,8 @@ void e2d::EActionMoveBy::_update()
{
// 移动节点
m_pTarget->setPos(
m_BeginPos.x + m_MoveVector.x * m_fRateOfProgress,
m_BeginPos.y + m_MoveVector.y * m_fRateOfProgress
m_BeginPos.x + m_MoveVec.x * m_fRateOfProgress,
m_BeginPos.y + m_MoveVec.y * m_fRateOfProgress
);
// 判断动作是否结束
if (_isEnd())
@ -49,10 +49,10 @@ void e2d::EActionMoveBy::_reset()
e2d::EActionMoveBy * e2d::EActionMoveBy::clone() const
{
return new EActionMoveBy(m_fTotalDuration / 1000, m_MoveVector);
return new EActionMoveBy(m_fTotalDuration / 1000, m_MoveVec);
}
e2d::EActionMoveBy * e2d::EActionMoveBy::reverse() const
{
return new EActionMoveBy(m_fTotalDuration / 1000, EVec(-m_MoveVector.x, -m_MoveVector.y));
return new EActionMoveBy(m_fTotalDuration / 1000, EVec(-m_MoveVec.x, -m_MoveVec.y));
}

View File

@ -14,7 +14,7 @@ e2d::EActionMoveTo * e2d::EActionMoveTo::clone() const
void e2d::EActionMoveTo::_init()
{
EActionMoveBy::_init();
m_MoveVector = m_EndPos - m_BeginPos;
m_MoveVec = m_EndPos - m_BeginPos;
}
void e2d::EActionMoveTo::_reset()

View File

@ -121,7 +121,7 @@ bool e2d::EApp::init(const EString &title, UINT32 width, UINT32 height, const EW
// 创建窗口
GetHWnd() = CreateWindow(
L"Easy2DApp",
title.c_str(),
title,
dwStyle,
0, 0, width, height,
NULL,
@ -420,7 +420,7 @@ void e2d::EApp::setWindowSize(UINT32 width, UINT32 height)
void e2d::EApp::setWindowTitle(const EString &title)
{
// 设置窗口标题
SetWindowText(GetHWnd(), title.c_str());
SetWindowText(GetHWnd(), title);
// 保存当前标题,用于修改窗口大小时恢复标题
getInstance()->m_sTitle = title;
}
@ -525,7 +525,7 @@ void e2d::EApp::setAppName(const EString &appname)
e2d::EString e2d::EApp::getAppName()
{
if (getInstance()->m_sAppName.empty())
if (getInstance()->m_sAppName.isEmpty())
getInstance()->m_sAppName = getInstance()->m_sTitle;
return getInstance()->m_sAppName;
}

View File

@ -77,7 +77,7 @@ void e2d::EScene::remove(const EString &childName)
return m_pRoot->removeChild(childName);
}
e2d::EVector<e2d::ENode*>& e2d::EScene::getChildren()
std::vector<e2d::ENode*>& e2d::EScene::getChildren()
{
return m_pRoot->m_vChildren;
}

View File

@ -80,13 +80,13 @@ void e2d::EFont::_initTextFormat()
SafeReleaseInterface(&m_pTextFormat);
HRESULT hr = GetDirectWriteFactory()->CreateTextFormat(
m_sFontFamily.c_str(),
NULL, // Font collection(NULL sets it to the system font collection)
m_sFontFamily,
NULL,
DWRITE_FONT_WEIGHT(m_FontWeight),
m_bItalic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL,
m_fFontSize,
L"en-us", // Local
L"en-us",
&m_pTextFormat
);

350
Easy2D/Common/EString.cpp Normal file
View File

@ -0,0 +1,350 @@
#include "..\ecommon.h"
#include <iomanip>
using namespace e2d;
EString::EString()
{
_size = 0;
_string = nullptr;
}
EString::EString(const wchar_t *str)
{
if (str)
{
_size = wcslen(str);
_string = new wchar_t[_size + 1];
wcscpy_s(_string, _size + 1, str);
}
else
{
_string = nullptr;
_size = 0;
}
}
EString::EString(EString && str)
{
_size = str._size;
_string = str._string;
str._string = nullptr;
}
EString::EString(const EString &str)
{
if (str._size)
{
_size = str._size;
_string = new wchar_t[_size + 1];
wcscpy_s(_string, _size + 1, str._string);
}
else
{
_string = nullptr;
_size = 0;
}
}
e2d::EString::EString(const std::wstring &str)
{
if (!str.empty())
{
_size = static_cast<int>(str.length());
_string = new wchar_t[_size + 1];
wcscpy_s(_string, _size + 1, str.c_str());
}
else
{
_string = nullptr;
_size = 0;
}
}
EString::~EString()
{
delete[] _string;
}
EString &EString::operator=(const wchar_t *str)
{
if (_string == str)
return *this;
if (str)
{
delete[] _string;
_size = wcslen(str);
_string = new wchar_t[_size + 1];
wcscpy_s(_string, _size + 1, str);
}
else
{
_string = nullptr;
_size = 0;
}
return *this;
}
EString &EString::operator=(const EString &str)
{
if (_string == str._string)
return *this;
if (str._size)
{
delete[] _string;
_size = str._size;
_string = new wchar_t[_size + 1];
wcscpy_s(_string, _size + 1, str._string);
}
else
{
_string = nullptr;
_size = 0;
}
return *this;
}
EString & e2d::EString::operator=(const std::wstring &str)
{
if (!str.empty())
{
delete[] _string;
_size = static_cast<int>(str.length());
_string = new wchar_t[_size + 1];
wcscpy_s(_string, _size + 1, str.c_str());
}
else
{
_string = nullptr;
_size = 0;
}
return *this;
}
bool EString::operator==(const wchar_t *str)
{
return (wcscmp(str, _string) == 0);
}
bool EString::operator ==(const EString &str)
{
return (wcscmp(str._string, _string) == 0);
}
bool e2d::EString::operator==(const std::wstring &str)
{
return (str.compare(_string) == 0);
}
bool e2d::EString::operator!=(const wchar_t *str)
{
return (wcscmp(str, _string) != 0);
}
bool e2d::EString::operator!=(const EString &str)
{
return (wcscmp(str._string, _string) != 0);
}
bool e2d::EString::operator!=(const std::wstring &str)
{
return (str.compare(_string) != 0);
}
wchar_t &EString::operator[](int index)
{
ASSERT(index >= 0 && index < _size, "EString subscript out of range");
return _string[index];
}
EString EString::operator+(const wchar_t *str)
{
EString str_temp(*this);
str_temp += str;
return std::move(str_temp);
}
EString EString::operator+(const wchar_t x)
{
EString str_temp(*this);
str_temp += x;
return std::move(str_temp);
}
EString EString::operator+(const EString &str)
{
EString str_temp(*this);
str_temp += str;
return std::move(str_temp);
}
EString e2d::EString::operator+(const std::wstring &str)
{
EString str_temp(*this);
str_temp += str;
return std::move(str_temp);
}
EString &EString::operator+=(const wchar_t x)
{
wchar_t *str_temp = new wchar_t[_size + 2];
if (_string) wcscpy_s(str_temp, _size + 2, _string);
str_temp[_size] = x;
str_temp[_size + 1] = 0;
delete[] _string;
_string = str_temp;
_size++;
return *this;
}
EString &EString::operator+=(const wchar_t *str)
{
if (!str) return *this;
int d_size = wcslen(str);
if (d_size == 0) return *this;
wchar_t *str_temp = new wchar_t[_size + d_size + 1];
if (_string) wcscpy_s(str_temp, _size + d_size + 1, _string);
wcscpy_s(str_temp + _size, d_size + 1, str);
delete[] _string;
_string = str_temp;
_size += d_size;
return *this;
}
EString &EString::operator+=(const EString &str)
{
if (str._size == 0) return *this;
wchar_t *str_temp = new wchar_t[_size + str._size + 1];
if (_string) wcscpy_s(str_temp, _size + str._size + 1, _string);
wcscpy_s(str_temp + _size, str._size + 1, str._string);
delete[] _string;
_string = str_temp;
_size += str._size;
return *this;
}
EString & e2d::EString::operator+=(const std::wstring &str)
{
if (str.length() == 0) return *this;
wchar_t *str_temp = new wchar_t[_size + str.length() + 1];
if (_string) wcscpy_s(str_temp, _size + str.length() + 1, _string);
wcscpy_s(str_temp + _size, str.length() + 1, str.c_str());
delete[] _string;
_string = str_temp;
_size += static_cast<int>(str.length());
return *this;
}
unsigned int e2d::EString::hash() const
{
unsigned int hash = 0;
for (int i = 0; i < _size; i++)
{
hash *= 16777619;
hash ^= (unsigned int)towupper(_string[i]);
}
return (hash);
}
std::wistream & e2d::operator>>(std::wistream &cin, EString &str)
{
const int limit_string_size = 4096;
str._string = new wchar_t[limit_string_size];
cin >> std::setw(limit_string_size) >> str._string;
str._size = wcslen(str._string);
return cin;
}
EString e2d::EString::upper() const
{
EString str(*this);
for (int i = 0; i < str._size; i++)
if (str._string[i] >= L'a' && str._string[i] <= L'z')
str._string[i] -= (L'a' - L'A');
return std::move(str);
}
EString e2d::EString::lower() const
{
EString str(*this);
for (int i = 0; i < str._size; i++)
str._string[i] = towlower(str._string[i]);
return std::move(str);
}
EString e2d::EString::sub(int offset, int count) const
{
if (_size == 0 || offset >= _size)
return std::move(EString());
offset = offset >= 0 ? offset : 0;
if (count < 0 || (offset + count) > _size)
count = _size - offset;
EString str_temp;
str_temp._string = new wchar_t[count + 1];
for (int i = 0; i < count; i++)
str_temp._string[i] = (_string + offset)[i];
str_temp._string[count] = 0;
return std::move(str_temp);
}
int e2d::EString::findFirstOf(wchar_t ch) const
{
for (int i = 0; i < _size; i++)
if (_string[i] == ch)
return i;
return -1;
}
int e2d::EString::findLastOf(wchar_t ch) const
{
int index = -1;
for (int i = 0; i < _size; i++)
if (_string[i] == ch)
index = i;
return index;
}
EString & e2d::EString::append(wchar_t ch)
{
return (*this) += ch;
}
EString & e2d::EString::append(wchar_t * str)
{
return (*this) += str;
}
EString & e2d::EString::append(EString & str)
{
return (*this) += str;
}

View File

@ -46,9 +46,9 @@ e2d::ETexture::~ETexture()
void e2d::ETexture::loadFromFile(const EString & fileName)
{
WARN_IF(fileName.empty(), "ETexture cannot load bitmap from NULL file name.");
WARN_IF(fileName.isEmpty(), "ETexture cannot load bitmap from NULL file name.");
if (fileName.empty())
if (fileName.isEmpty())
return;
if (!e2d::ETexture::preload(fileName))
@ -57,10 +57,7 @@ void e2d::ETexture::loadFromFile(const EString & fileName)
return;
}
std::hash<e2d::EString> h;
size_t hash = h(fileName);
m_pBitmap = s_mBitmapsFromFile.at(hash);
m_pBitmap = s_mBitmapsFromFile.at(fileName.hash());
}
void e2d::ETexture::loadFromResource(LPCTSTR resourceName, LPCTSTR resourceType)
@ -122,10 +119,7 @@ e2d::ESize e2d::ETexture::getSourceSize() const
bool e2d::ETexture::preload(const EString & fileName)
{
std::hash<e2d::EString> h;
size_t hash = h(fileName);
if (s_mBitmapsFromFile.find(hash) != s_mBitmapsFromFile.end())
if (s_mBitmapsFromFile.find(fileName.hash()) != s_mBitmapsFromFile.end())
{
return true;
}
@ -140,7 +134,7 @@ bool e2d::ETexture::preload(const EString & fileName)
// 创建解码器
hr = GetImagingFactory()->CreateDecoderFromFilename(
fileName.c_str(),
fileName,
NULL,
GENERIC_READ,
WICDecodeMetadataCacheOnLoad,
@ -183,12 +177,9 @@ bool e2d::ETexture::preload(const EString & fileName)
if (SUCCEEDED(hr))
{
// 保存图片指针和图片的 Hash 名
std::hash<e2d::EString> h;
size_t hash = h(fileName);
s_mBitmapsFromFile.insert(
std::map<size_t, ID2D1Bitmap*>::value_type(
hash,
fileName.hash(),
pBitmap)
);
}

View File

@ -212,6 +212,7 @@
<ClCompile Include="Common\EFont.cpp" />
<ClCompile Include="Common\EObject.cpp" />
<ClCompile Include="Common\ESpriteFrame.cpp" />
<ClCompile Include="Common\EString.cpp" />
<ClCompile Include="Common\ETexture.cpp" />
<ClCompile Include="Geometry\ECircle.cpp" />
<ClCompile Include="Geometry\EEllipse.cpp" />
@ -264,7 +265,6 @@
<ClInclude Include="enodes.h" />
<ClInclude Include="etools.h" />
<ClInclude Include="etransitions.h" />
<ClInclude Include="etypedef.h" />
<ClInclude Include="Win\MciPlayer.h" />
<ClInclude Include="Win\winbase.h" />
</ItemGroup>

View File

@ -219,6 +219,9 @@
<ClCompile Include="Msg\EPhysicsMsg.cpp">
<Filter>Msg</Filter>
</ClCompile>
<ClCompile Include="Common\EString.cpp">
<Filter>Common</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Win\winbase.h">
@ -235,7 +238,6 @@
<ClInclude Include="egeometry.h" />
<ClInclude Include="elisteners.h" />
<ClInclude Include="emanagers.h" />
<ClInclude Include="etypedef.h" />
<ClInclude Include="Win\MciPlayer.h">
<Filter>Win</Filter>
</ClInclude>

View File

@ -2,7 +2,7 @@
#include "..\eactions.h"
#include "..\Win\winbase.h"
static e2d::EVector<e2d::EAction*> s_vActions;
static std::vector<e2d::EAction*> s_vActions;
void e2d::EActionManager::addAction(EAction * action)

View File

@ -5,9 +5,9 @@
// 鼠标消息监听器
e2d::EVector<e2d::EListenerMouse*> s_vMouseListeners;
std::vector<e2d::EListenerMouse*> s_vMouseListeners;
// 按键消息监听器
e2d::EVector<e2d::EListenerKeyboard*> s_vKeyboardListeners;
std::vector<e2d::EListenerKeyboard*> s_vKeyboardListeners;
void e2d::EMsgManager::MouseProc(UINT message, WPARAM wParam, LPARAM lParam)
@ -20,7 +20,7 @@ void e2d::EMsgManager::MouseProc(UINT message, WPARAM wParam, LPARAM lParam)
if (s_vMouseListeners.empty()) return;
// 执行鼠标消息监听函数
EVector<EListenerMouse*>::size_type i = s_vMouseListeners.size();
std::vector<EListenerMouse*>::size_type i = s_vMouseListeners.size();
do
{
@ -45,7 +45,7 @@ void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam)
if (s_vKeyboardListeners.empty()) return;
// 执行按键消息监听函数
EVector<EListenerMouse*>::size_type i = s_vKeyboardListeners.size();
std::vector<EListenerMouse*>::size_type i = s_vKeyboardListeners.size();
do
{
@ -133,7 +133,7 @@ void e2d::EMsgManager::stopMouseListeners(const EString & name)
void e2d::EMsgManager::delMouseListeners(const EString & name)
{
// 删除鼠标消息监听器
EVector<EListenerMouse*>::iterator mIter;
std::vector<EListenerMouse*>::iterator mIter;
for (mIter = s_vMouseListeners.begin(); mIter != s_vMouseListeners.end();)
{
if ((*mIter)->getName() == name)
@ -175,7 +175,7 @@ void e2d::EMsgManager::stopKeyboardListeners(const EString & name)
void e2d::EMsgManager::delKeyboardListeners(const EString & name)
{
// 删除按键消息监听器
EVector<EListenerKeyboard*>::iterator kIter;
std::vector<EListenerKeyboard*>::iterator kIter;
for (kIter = s_vKeyboardListeners.begin(); kIter != s_vKeyboardListeners.end();)
{
if ((*kIter)->getName() == name)

View File

@ -9,7 +9,7 @@
// 让其自动释放
// 释放池容器
static e2d::EVector<e2d::EObject*> s_vPool;
static std::vector<e2d::EObject*> s_vPool;
// 标志释放池执行状态
static bool s_bNotifyed = false;
@ -19,7 +19,7 @@ void e2d::EObjectManager::__flush()
s_bNotifyed = false;
// 创建迭代器
static EVector<e2d::EObject*>::iterator iter;
static std::vector<e2d::EObject*>::iterator iter;
// 循环遍历容器中的所有对象
for (iter = s_vPool.begin(); iter != s_vPool.end();)
{

View File

@ -4,9 +4,9 @@
#include "..\egeometry.h"
// 监听器集合
e2d::EVector<e2d::EListenerPhysics*> s_vListeners;
std::vector<e2d::EListenerPhysics*> s_vListeners;
// 形状集合
e2d::EVector<e2d::EGeometry*> s_vGeometries;
std::vector<e2d::EGeometry*> s_vGeometries;
void e2d::EPhysicsManager::PhysicsGeometryProc(EGeometry * pActiveGeometry)
@ -48,7 +48,7 @@ void e2d::EPhysicsManager::PhysicsGeometryProc(EGeometry * pActiveGeometry)
void e2d::EPhysicsManager::PhysicsListenerProc()
{
// 执行鼠标消息监听函数
EVector<EListenerPhysics*>::size_type i = s_vListeners.size();
std::vector<EListenerPhysics*>::size_type i = s_vListeners.size();
do
{
@ -136,7 +136,7 @@ void e2d::EPhysicsManager::stopListeners(const EString & name)
void e2d::EPhysicsManager::delListeners(const EString & name)
{
EVector<EListenerPhysics*>::iterator iter;
std::vector<EListenerPhysics*>::iterator iter;
for (iter = s_vListeners.begin(); iter != s_vListeners.end();)
{
if ((*iter)->getName() == name)

View File

@ -3,7 +3,7 @@
#include "..\enodes.h"
#include "..\Win\winbase.h"
static e2d::EVector<e2d::ETimer*> s_vTimers;
static std::vector<e2d::ETimer*> s_vTimers;
void e2d::ETimerManager::TimerProc()
@ -69,7 +69,7 @@ void e2d::ETimerManager::stopTimers(const EString & name)
void e2d::ETimerManager::delTimers(const EString & name)
{
EVector<ETimer*>::iterator mIter;
std::vector<ETimer*>::iterator mIter;
for (mIter = s_vTimers.begin(); mIter != s_vTimers.end();)
{
if ((*mIter)->getName() == name)

View File

@ -573,7 +573,7 @@ e2d::EScene * e2d::ENode::getParentScene() const
return m_pParentScene;
}
e2d::EVector<e2d::ENode*>& e2d::ENode::getChildren()
std::vector<e2d::ENode*>& e2d::ENode::getChildren()
{
return m_vChildren;
}
@ -585,10 +585,9 @@ size_t e2d::ENode::getChildrenCount() const
e2d::ENode * e2d::ENode::getChild(const EString & name)
{
WARN_IF(name.empty(), "Invalid ENode name.");
WARN_IF(name.isEmpty(), "Invalid ENode name.");
std::hash<EString> h;
size_t hash = h(name);
unsigned int hash = name.hash();
for (const auto& child : m_vChildren)
{
@ -640,7 +639,7 @@ bool e2d::ENode::removeChild(ENode * child)
void e2d::ENode::removeChild(const EString & childName)
{
WARN_IF(childName.empty(), "Invalid ENode name.");
WARN_IF(childName.isEmpty(), "Invalid ENode name.");
if (m_vChildren.empty())
{
@ -648,8 +647,7 @@ void e2d::ENode::removeChild(const EString & childName)
}
// 计算名称 Hash 值
std::hash<EString> h;
size_t hash = h(childName);
unsigned int hash = childName.hash();
size_t size = m_vChildren.size();
for (size_t i = 0; i < size; i++)
@ -782,15 +780,14 @@ void e2d::ENode::setVisiable(bool value)
void e2d::ENode::setName(const EString & name)
{
WARN_IF(name.empty(), "Invalid ENode name.");
WARN_IF(name.isEmpty(), "Invalid ENode name.");
if (!name.empty())
if (!name.isEmpty())
{
// 保存节点名
m_sName = name;
// 保存节点 Hash 名
std::hash<EString> h;
m_nHashName = h(name);
m_nHashName = name.hash();
}
}

View File

@ -94,7 +94,7 @@ void e2d::EText::_render()
{
GetSolidColorBrush()->SetColor(D2D1::ColorF(m_pFont->m_Color, m_fDisplayOpacity));
GetRenderTarget()->DrawTextW(
m_sText.c_str(),
m_sText,
UINT32(m_sText.length()),
m_pFont->_getTextFormat(),
D2D1::RectF(
@ -110,7 +110,7 @@ void e2d::EText::_render()
void e2d::EText::_initTextLayout()
{
// 未设置字体或空字符串时,文本宽高为 0
if (!m_pFont || m_sText.empty())
if (!m_pFont || m_sText.isEmpty())
{
this->_setHeight(0);
m_fWordWrappingWidth = 0;
@ -131,8 +131,8 @@ void e2d::EText::_initTextLayout()
IDWriteTextLayout * pDWriteTextLayout = nullptr;
HRESULT hr = GetDirectWriteFactory()->CreateTextLayout(
m_sText.c_str(),
UINT32(m_sText.size()),
m_sText,
UINT32(m_sText.length()),
m_pFont->_getTextFormat(),
m_bWordWrapping ? m_fWordWrappingWidth : 0,
0,

View File

@ -35,14 +35,14 @@ e2d::EString e2d::EFileUtils::getLocalAppDataPath()
e2d::EString e2d::EFileUtils::getTempPath()
{
// 获取临时文件目录
TCHAR path[_MAX_PATH];
wchar_t path[_MAX_PATH];
::GetTempPath(_MAX_PATH, path);
// 创建临时文件目录
e2d::EString tempFilePath = path + e2d::EApp::getAppName();
if (_waccess(tempFilePath.c_str(), 0) == -1)
if (_waccess(tempFilePath, 0) == -1)
{
_wmkdir(tempFilePath.c_str());
_wmkdir(tempFilePath);
}
return tempFilePath;
}
@ -50,67 +50,66 @@ e2d::EString e2d::EFileUtils::getTempPath()
e2d::EString e2d::EFileUtils::getDefaultSavePath()
{
EString path = EFileUtils::getLocalAppDataPath();
WARN_IF(path.empty(), "Cannot get local AppData path!");
WARN_IF(path.isEmpty(), "Cannot get local AppData path!");
path.append(L"\\");
path.append(EApp::getAppName());
path += L"\\" + EApp::getAppName();
if (_waccess(path.c_str(), 0) == -1)
if (_waccess(path, 0) == -1)
{
_wmkdir(path.c_str());
_wmkdir(path);
}
path.append(L"\\DefaultData.ini");
path += L"\\DefaultData.ini";
return path;
}
void e2d::EFileUtils::saveInt(const EString & key, int value)
{
::WritePrivateProfileString(L"Default", key.c_str(), std::to_wstring(value).c_str(), getDefaultSavePath().c_str());
::WritePrivateProfileString(L"Default", key, EString::parse(value), getDefaultSavePath());
}
void e2d::EFileUtils::saveFloat(const EString & key, float value)
{
::WritePrivateProfileString(L"Default", key.c_str(), std::to_wstring(value).c_str(), getDefaultSavePath().c_str());
::WritePrivateProfileString(L"Default", key, EString::parse(value), getDefaultSavePath());
}
void e2d::EFileUtils::saveString(const EString & key, const EString & value)
{
::WritePrivateProfileString(L"Default", key.c_str(), value.c_str(), getDefaultSavePath().c_str());
::WritePrivateProfileString(L"Default", key, value, getDefaultSavePath());
}
int e2d::EFileUtils::getInt(const EString & key, int default)
{
return ::GetPrivateProfileInt(L"Default", key.c_str(), default, getDefaultSavePath().c_str());
return ::GetPrivateProfileInt(L"Default", key, default, getDefaultSavePath());
}
float e2d::EFileUtils::getFloat(const EString & key, float default)
{
TCHAR temp[32] = { 0 };
::GetPrivateProfileString(L"Default", key.c_str(), std::to_wstring(default).c_str(), temp, 31, getDefaultSavePath().c_str());
wchar_t temp[32] = { 0 };
::GetPrivateProfileString(L"Default", key, EString::parse(default), temp, 31, getDefaultSavePath());
return std::stof(temp);
}
e2d::EString e2d::EFileUtils::getString(const EString & key, const EString & default)
{
TCHAR temp[256] = { 0 };
::GetPrivateProfileString(L"Default", key.c_str(), default.c_str(), temp, 255, getDefaultSavePath().c_str());
return EString(temp);
wchar_t temp[256] = { 0 };
::GetPrivateProfileString(L"Default", key, default, temp, 255, getDefaultSavePath());
return temp;
}
e2d::EString e2d::EFileUtils::getFileExtension(const EString & filePath)
{
EString fileExtension;
// 找到文件名中的最后一个 '.' 的位置
size_t pos = filePath.find_last_of('.');
size_t pos = filePath.findLastOf(L'.');
// 判断 pos 是否是个有效位置
if (pos != EString::npos)
if (pos != -1)
{
// 截取扩展名
fileExtension = filePath.substr(pos, filePath.length());
fileExtension = filePath.sub(pos, filePath.length());
// 转换为小写字母
std::transform(fileExtension.begin(), fileExtension.end(), fileExtension.begin(), ::tolower);
fileExtension = fileExtension.lower();
}
return fileExtension;
@ -122,15 +121,15 @@ e2d::EString e2d::EFileUtils::getSaveFilePath(const EString & title, const EStri
OPENFILENAME ofn = { 0 };
TCHAR strFilename[MAX_PATH] = { 0 }; // 用于接收文件名
ofn.lStructSize = sizeof(OPENFILENAME); // 结构体大小
ofn.hwndOwner = GetHWnd(); // 拥有着窗口句柄NULL 表示对话框是非模态的
ofn.lpstrFilter = L"所有文件\0*.*\0\0"; // 设置过滤
ofn.hwndOwner = GetHWnd(); // 窗口句柄
ofn.lpstrFilter = L"所有文件\0*.*\0\0"; // 设置过滤
ofn.nFilterIndex = 1; // 过滤器索引
ofn.lpstrFile = strFilename; // 接收返回的文件路径和文件名
ofn.nMaxFile = sizeof(strFilename); // 缓冲区长度
ofn.lpstrInitialDir = NULL; // 初始目录为默认
ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;// 目录必须存在,覆盖文件前发出警告
ofn.lpstrTitle = title.c_str(); // 使用系统默认标题留空即可
ofn.lpstrDefExt = defExt.c_str(); // 默认追加的扩展名
ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
ofn.lpstrTitle = title; // 标题
ofn.lpstrDefExt = defExt; // 默认追加的扩展名
if (GetSaveFileName(&ofn))
{

View File

@ -6,12 +6,6 @@
typedef std::pair<UINT, MciPlayer *> Music;
typedef std::map<UINT, MciPlayer *> MusicList;
static UINT Hash(const e2d::EString & key)
{
static std::hash<e2d::EString> h;
return h(key);
}
static MusicList& getMciPlayerList()
{
static MusicList s_List;
@ -43,10 +37,10 @@ UINT e2d::EMusicUtils::playMusic(const EString & musicResourceName, const EStrin
UINT e2d::EMusicUtils::preloadMusic(const EString & musicFilePath)
{
if (musicFilePath.empty())
if (musicFilePath.isEmpty())
return 0;
UINT nRet = ::Hash(musicFilePath);
UINT nRet = musicFilePath.hash();
if (getMciPlayerList().end() != getMciPlayerList().find(nRet))
return nRet;
@ -64,10 +58,10 @@ UINT e2d::EMusicUtils::preloadMusic(const EString & musicFilePath)
UINT e2d::EMusicUtils::preloadMusic(const EString & musicResourceName, const EString & musicResourceType, const EString & musicExtension)
{
if (musicResourceName.empty() || musicResourceType.empty())
if (musicResourceName.isEmpty() || musicResourceType.isEmpty())
return 0;
UINT nRet = ::Hash(musicResourceName);
UINT nRet = musicResourceName.hash();
if (getMciPlayerList().end() != getMciPlayerList().find(nRet))
return nRet;
@ -96,7 +90,7 @@ bool e2d::EMusicUtils::resumeMusic(UINT musicId)
bool e2d::EMusicUtils::resumeMusic(const EString & musicName)
{
return resumeMusic(Hash(musicName));;
return resumeMusic(musicName.hash());;
}
bool e2d::EMusicUtils::pauseMusic(UINT musicId)
@ -112,7 +106,7 @@ bool e2d::EMusicUtils::pauseMusic(UINT musicId)
bool e2d::EMusicUtils::pauseMusic(const EString & musicName)
{
return pauseMusic(Hash(musicName));
return pauseMusic(musicName.hash());
}
bool e2d::EMusicUtils::stopMusic(UINT musicId)
@ -128,7 +122,7 @@ bool e2d::EMusicUtils::stopMusic(UINT musicId)
bool e2d::EMusicUtils::stopMusic(const EString & musicName)
{
return stopMusic(Hash(musicName));;
return stopMusic(musicName.hash());;
}
void e2d::EMusicUtils::pauseAllMusics()

View File

@ -66,14 +66,14 @@ MciPlayer::~MciPlayer()
bool MciPlayer::open(const e2d::EString & pFileName, UINT uId)
{
if (pFileName.empty())
if (pFileName.isEmpty())
return false;
close();
MCI_OPEN_PARMS mciOpen = { 0 };
mciOpen.lpstrDeviceType = (LPCTSTR)MCI_ALL_DEVICE_ID;
mciOpen.lpstrElementName = pFileName.c_str();
mciOpen.lpstrElementName = pFileName;
MCIERROR mciError;
mciError = mciSendCommand(
@ -96,18 +96,16 @@ 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)
{
// 忽略不存在的文件
if (pResouceName.empty() || pResouceType.empty() || musicExtension.empty()) return false;
if (pResouceName.isEmpty() || pResouceType.isEmpty() || musicExtension.isEmpty()) return false;
// 获取临时文件目录
e2d::EString tempFileName = e2d::EFileUtils::getTempPath();
// 产生临时文件的文件名
tempFileName.append(L"\\");
tempFileName.append(std::to_wstring(uId));
tempFileName.append(L"." + musicExtension);
tempFileName = tempFileName + L"\\" + uId + L"." + musicExtension;
// 导出资源为临时文件
if (ExtractResource(tempFileName.c_str(), pResouceType.c_str(), pResouceName.c_str()))
if (ExtractResource(tempFileName, pResouceType, pResouceName))
{
return open(tempFileName, uId);
}

View File

@ -144,7 +144,7 @@ protected:
protected:
EPoint m_BeginPos;
EVec m_MoveVector;
EVec m_MoveVec;
};
@ -605,7 +605,7 @@ protected:
protected:
UINT m_nFrameIndex;
EVector<ESpriteFrame*> m_vFrames;
std::vector<ESpriteFrame*> m_vFrames;
};

View File

@ -1,10 +1,11 @@
/******************************************************
* Easy2D Game Engine
* Easy2D Game Framework
*
* Website: http://www.easy2d.cn
* Source Code: https://gitee.com/werelone/Easy2D
* Source Code: https://github.com/Nomango/Easy2D
******************************************************/
#pragma once
#ifndef __cplusplus
@ -17,7 +18,6 @@
#include "emacros.h"
#include "etypedef.h"
#include "ecommon.h"
#include "ebase.h"
#include "emanagers.h"

View File

@ -225,7 +225,7 @@ public:
);
// 获取所有子节点
EVector<e2d::ENode*> &getChildren();
std::vector<e2d::ENode*> &getChildren();
// 获取子节点数量
size_t getChildrenCount() const;

View File

@ -1,11 +1,251 @@
#pragma once
#include "emacros.h"
#include "etypedef.h"
#include <vector>
#include <functional>
#include <sstream>
namespace e2d
{
// 表示坐标的结构体
struct EPoint
{
float x;
float y;
EPoint()
{
x = 0;
y = 0;
}
EPoint(float x, float y)
{
this->x = x;
this->y = y;
}
EPoint operator + (EPoint const & p)
{
return EPoint(x + p.x, y + p.y);
}
EPoint operator - (EPoint const & p)
{
return EPoint(x - p.x, y - p.y);
}
EPoint operator * (float const & value)
{
return EPoint(x * value, y * value);
}
EPoint operator / (float const & value)
{
return EPoint(x / value, y / value);
}
};
// 表示二维向量的结构体
typedef EPoint EVec;
// 表示大小的结构体
struct ESize
{
float width;
float height;
ESize()
{
width = 0;
height = 0;
}
ESize(float width, float height)
{
this->width = width;
this->height = height;
}
ESize operator + (ESize const & size)
{
return ESize(width + size.width, height + size.height);
}
ESize operator - (ESize const & size)
{
return ESize(width - size.width, height - size.height);
}
ESize operator * (float const & value)
{
return ESize(width * value, height * value);
}
ESize operator / (float const & value)
{
return ESize(width / value, height / value);
}
};
// 表示窗口样式的结构体
struct EWindowStyle
{
LPCTSTR m_pIconID; /* 程序图标 ID */
bool m_bNoClose; /* 禁用关闭按钮 */
bool m_bNoMiniSize; /* 禁用最小化按钮 */
bool m_bTopMost; /* 窗口置顶 */
EWindowStyle()
{
m_pIconID = 0;
m_bNoClose = false;
m_bNoMiniSize = false;
m_bTopMost = false;
}
EWindowStyle(
LPCTSTR pIconID
)
{
m_pIconID = pIconID;
m_bNoClose = false;
m_bNoMiniSize = false;
m_bTopMost = false;
}
EWindowStyle(
LPCTSTR pIconID,
bool bNoClose,
bool bNoMiniSize,
bool bTopMost
)
{
m_pIconID = pIconID;
m_bNoClose = bNoClose;
m_bNoMiniSize = bNoMiniSize;
m_bTopMost = bTopMost;
}
};
// 字符串
class EString
{
public:
EString();
EString(const wchar_t *);
EString(const EString &);
EString(const std::wstring &);
EString(EString &&);
~EString();
EString& operator=(const wchar_t *);
EString& operator=(const EString &);
EString& operator=(const std::wstring &);
bool operator==(const wchar_t *);
bool operator==(const EString &);
bool operator==(const std::wstring &);
bool operator!=(const wchar_t *);
bool operator!=(const EString &);
bool operator!=(const std::wstring &);
wchar_t &operator[](int);
EString operator+(const wchar_t);
EString operator+(const wchar_t *);
EString operator+(const EString &);
EString operator+(const std::wstring &);
template<typename T>
EString &operator+(const T value)
{
EString str_temp(*this);
str_temp += value;
return std::move(str_temp);
}
EString &operator +=(const wchar_t);
EString &operator +=(const wchar_t *);
EString &operator +=(const EString &);
EString &operator +=(const std::wstring &);
template<typename T>
EString &operator +=(const T value)
{
std::wostringstream ss;
ss << value;
return (*this) += ss.str();
}
friend std::wistream &operator>>(std::wistream &, EString &);
operator const wchar_t*() const { return _string; }
operator bool() const { return _size != 0; }
// 判断字符串是否为空
bool isEmpty() const { return _size == 0; }
// 获取字符串长度
int length() const { return _size; }
// 获取大写字符串
EString upper() const;
// 获取小写字符串
EString lower() const;
// 获取裁剪字符串
EString sub(int offset, int count = -1) const;
// 获取字符串中第一个特定字符的下标
int findFirstOf(wchar_t ch) const;
// 获取字符串中最后一个特定字符的下标
int findLastOf(wchar_t ch) const;
// 后接字符
EString &append(wchar_t ch);
// 后接字符串
EString &append(wchar_t *str);
// 后接字符串
EString &append(EString &str);
// 后接字符串
template<typename T>
EString &append(T &value)
{
return (*this) += value;
}
// 获取该字符串的散列值
unsigned int hash() const;
// 将模板类型转化为字符串
template<typename T>
static EString parse(const T value)
{
EString str;
std::wostringstream ss;
ss << value;
str += ss.str();
return std::move(str);
}
private:
wchar_t *_string;
int _size;
};
// 颜色
class EColor
{
public:
@ -154,7 +394,7 @@ public:
};
};
// 字体粗细值
class EFontWeight
{
public:
@ -588,4 +828,36 @@ protected:
ETexture * m_pTexture;
};
class ENode;
// 定时器回调函数(参数为该定时器被调用的次数,从 0 开始)
typedef std::function<void(int)> TIMER_CALLBACK;
// 按钮点击回调函数
typedef std::function<void()> BUTTON_CLICK_CALLBACK;
// 按键消息监听回调函数
typedef std::function<void()> KEY_LISTENER_CALLBACK;
// 鼠标消息监听回调函数
typedef std::function<void()> MOUSE_LISTENER_CALLBACK;
// 鼠标点击消息监听回调函数(参数为点击位置)
typedef std::function<void(EPoint mousePos)> MOUSE_CLICK_LISTENER_CALLBACK;
// 鼠标按下消息监听回调函数(参数为按下位置)
typedef MOUSE_CLICK_LISTENER_CALLBACK MOUSE_PRESS_LISTENER_CALLBACK;
// 鼠标双击消息监听回调函数(参数为双击位置)
typedef MOUSE_CLICK_LISTENER_CALLBACK MOUSE_DBLCLK_LISTENER_CALLBACK;
// 鼠标拖动消息监听回调函数(参数为拖动前位置和拖动后位置)
typedef std::function<void(EPoint begin, EPoint end)> MOUSE_DRAG_LISTENER_CALLBACK;
// 物理世界消息监听器回调函数
typedef std::function<void()> PHYSICS_LISTENER_CALLBACK;
// 碰撞消息监听器回调函数
typedef PHYSICS_LISTENER_CALLBACK COLLISION_LISTENER_CALLBACK;
}

View File

@ -30,8 +30,6 @@
// C RunTime Header Files
#include <wchar.h>
#include <stdio.h>
#include <stdlib.h>
#include <d2d1.h>
#include <d2d1helper.h>
#include <dwrite.h>

View File

@ -104,7 +104,7 @@ public:
virtual EScene * getParentScene() const;
// 获取所有子节点
virtual EVector<ENode*> &getChildren();
virtual std::vector<ENode*> &getChildren();
// 获取子节点数量
virtual size_t getChildrenCount() const;
@ -398,7 +398,7 @@ protected:
ENode * m_pParent;
D2D1::Matrix3x2F m_MatriInitial;
D2D1::Matrix3x2F m_MatriFinal;
EVector<ENode*> m_vChildren;
std::vector<ENode*> m_vChildren;
};
@ -855,7 +855,7 @@ public:
protected:
bool m_bEnable;
EVector<EButton*> m_vButtons;
std::vector<EButton*> m_vButtons;
};
}

View File

@ -1,169 +0,0 @@
#pragma once
#include <Windows.h>
#include <string>
#include <vector>
#include <functional>
namespace e2d
{
struct EPoint
{
float x;
float y;
EPoint()
{
x = 0;
y = 0;
}
EPoint(float x, float y)
{
this->x = x;
this->y = y;
}
EPoint operator + (EPoint const & p)
{
return EPoint(x + p.x, y + p.y);
}
EPoint operator - (EPoint const & p)
{
return EPoint(x - p.x, y - p.y);
}
EPoint operator * (float const & value)
{
return EPoint(x * value, y * value);
}
EPoint operator / (float const & value)
{
return EPoint(x / value, y / value);
}
};
struct ESize
{
float width;
float height;
ESize()
{
width = 0;
height = 0;
}
ESize(float width, float height)
{
this->width = width;
this->height = height;
}
ESize operator + (ESize const & size)
{
return ESize(width + size.width, height + size.height);
}
ESize operator - (ESize const & size)
{
return ESize(width - size.width, height - size.height);
}
ESize operator * (float const & value)
{
return ESize(width * value, height * value);
}
ESize operator / (float const & value)
{
return ESize(width / value, height / value);
}
};
struct EWindowStyle
{
LPCTSTR m_pIconID; /* 程序图标 ID */
bool m_bNoClose; /* 禁用关闭按钮 */
bool m_bNoMiniSize; /* 禁用最小化按钮 */
bool m_bTopMost; /* 窗口置顶 */
EWindowStyle()
{
m_pIconID = 0;
m_bNoClose = false;
m_bNoMiniSize = false;
m_bTopMost = false;
}
EWindowStyle(
LPCTSTR pIconID
)
{
m_pIconID = pIconID;
m_bNoClose = false;
m_bNoMiniSize = false;
m_bTopMost = false;
}
EWindowStyle(
LPCTSTR pIconID,
bool bNoClose,
bool bNoMiniSize,
bool bTopMost
)
{
m_pIconID = pIconID;
m_bNoClose = bNoClose;
m_bNoMiniSize = bNoMiniSize;
m_bTopMost = bTopMost;
}
};
// 二维向量
typedef EPoint EVec;
// 字符串
typedef std::wstring EString;
// Vector 容器
template<typename T>
using EVector = std::vector<T>;
class ENode;
// 定时器回调函数(参数为该定时器被调用的次数,从 0 开始)
typedef std::function<void(int)> TIMER_CALLBACK;
// 按钮点击回调函数
typedef std::function<void()> BUTTON_CLICK_CALLBACK;
// 按键消息监听回调函数
typedef std::function<void()> KEY_LISTENER_CALLBACK;
// 鼠标消息监听回调函数
typedef std::function<void()> MOUSE_LISTENER_CALLBACK;
// 鼠标点击消息监听回调函数(参数为点击位置)
typedef std::function<void(EPoint mousePos)> MOUSE_CLICK_LISTENER_CALLBACK;
// 鼠标按下消息监听回调函数(参数为按下位置)
typedef MOUSE_CLICK_LISTENER_CALLBACK MOUSE_PRESS_LISTENER_CALLBACK;
// 鼠标双击消息监听回调函数(参数为双击位置)
typedef MOUSE_CLICK_LISTENER_CALLBACK MOUSE_DBLCLK_LISTENER_CALLBACK;
// 鼠标拖动消息监听回调函数(参数为拖动前位置和拖动后位置)
typedef std::function<void(EPoint begin, EPoint end)> MOUSE_DRAG_LISTENER_CALLBACK;
// 物理世界消息监听器回调函数
typedef std::function<void()> PHYSICS_LISTENER_CALLBACK;
// 碰撞消息监听器回调函数
typedef PHYSICS_LISTENER_CALLBACK COLLISION_LISTENER_CALLBACK;
}