From 3747c4d0deff1b465dd592f1726e954f5c0906c1 Mon Sep 17 00:00:00 2001
From: Nomango <569629550@qq.com>
Date: Sat, 14 Oct 2017 01:07:34 +0800
Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E4=BD=93=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
ConsoleDemo/ConsoleDemo.vcxproj | 156 ++++
ConsoleDemo/ConsoleDemo.vcxproj.filters | 22 +
ConsoleDemo/main.cpp | 50 ++
Demo/Demo.vcxproj | 4 +-
Demo/main.cpp | 15 +-
Easy2D.sln | 12 +-
Easy2D/Base/EApp.cpp | 152 ++--
Easy2D/Base/EObject.cpp | 2 +
Easy2D/Base/EScene.cpp | 29 +-
Easy2D/Easy2D.vcxproj | 5 +-
Easy2D/Easy2D.vcxproj.filters | 3 +
Easy2D/Msg/EMsgManager.cpp | 292 ++++++-
Easy2D/Msg/Listener/EKeyListener.cpp | 12 +-
Easy2D/Msg/Listener/EKeyPressListener.cpp | 8 +-
Easy2D/Msg/Listener/EListener.cpp | 35 +-
Easy2D/Node/ENode.cpp | 2 +-
Easy2D/Tool/EObjectManager.cpp | 10 +
Easy2D/Tool/ETimerManager.cpp | 1 +
Easy2D/Win/winbase.cpp | 19 -
Easy2D/Win/winbase.h | 3 +-
Easy2D/easy2d.h | 2 +-
Easy2D/ebase.h | 70 +-
Easy2D/emacros.h | 10 +-
Easy2D/emsg.h | 881 ++++++++++++----------
Easy2D/enodes.h | 5 +-
Easy2D/etools.h | 12 +-
26 files changed, 1195 insertions(+), 617 deletions(-)
create mode 100644 ConsoleDemo/ConsoleDemo.vcxproj
create mode 100644 ConsoleDemo/ConsoleDemo.vcxproj.filters
create mode 100644 ConsoleDemo/main.cpp
create mode 100644 Easy2D/Tool/ETimerManager.cpp
diff --git a/ConsoleDemo/ConsoleDemo.vcxproj b/ConsoleDemo/ConsoleDemo.vcxproj
new file mode 100644
index 00000000..5d8465c9
--- /dev/null
+++ b/ConsoleDemo/ConsoleDemo.vcxproj
@@ -0,0 +1,156 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ 15.0
+ {70931955-FE2D-4A50-93C6-6955A730B0FE}
+ Win32Proj
+ ConsoleDemo
+ 10.0.15063.0
+
+
+
+ Application
+ true
+ v141
+ Unicode
+
+
+ Application
+ false
+ v141
+ true
+ Unicode
+
+
+ Application
+ true
+ v141
+ Unicode
+
+
+ Application
+ false
+ v141
+ true
+ Unicode
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ $(MSBuildProjectDirectory)\..\Win32;$(LibraryPath)
+
+
+ true
+
+
+ false
+
+
+ false
+
+
+
+
+
+ Level3
+ Disabled
+ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+
+
+
+
+
+
+ Level3
+ Disabled
+ _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+
+
+
+
+
+
+ Level3
+ MaxSpeed
+ true
+ true
+ WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+
+
+ Level3
+ MaxSpeed
+ true
+ true
+ NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ConsoleDemo/ConsoleDemo.vcxproj.filters b/ConsoleDemo/ConsoleDemo.vcxproj.filters
new file mode 100644
index 00000000..203a71c4
--- /dev/null
+++ b/ConsoleDemo/ConsoleDemo.vcxproj.filters
@@ -0,0 +1,22 @@
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hh;hpp;hxx;hm;inl;inc;xsd
+
+
+ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
+ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
+
+
+
+
+ 源文件
+
+
+
\ No newline at end of file
diff --git a/ConsoleDemo/main.cpp b/ConsoleDemo/main.cpp
new file mode 100644
index 00000000..dc9f6c7c
--- /dev/null
+++ b/ConsoleDemo/main.cpp
@@ -0,0 +1,50 @@
+#include "..\Easy2D\easy2d.h"
+
+int main()
+{
+ EApp app;
+
+ if (app.init(L"Easy2D Demo", 640, 480, true))
+ {
+ auto scene = new EScene();
+
+ auto node = new ENode();
+ node->setPos(50, 80);
+ node->setSize(30, 180);
+ scene->add(node);
+
+ /*auto listener = new EMouseListener([=] {
+ if (!EMouseMsg::isLButtonDown())
+ {
+ if (EMouseMsg::getMsg() == EMouseMsg::MOVE)
+ {
+ node->setPos(EMouseMsg::getPos());
+ }
+ }
+ });*/
+
+ auto listener = new EKeyPressListener([=] {
+ if (EKeyMsg::isCapitalLockOn())
+ {
+ if (EKeyMsg::getVal() == EKeyMsg::KEY::LEFT)
+ {
+ node->move(-3, 0);
+ }
+ if (EKeyMsg::getVal() == EKeyMsg::KEY::RIGHT)
+ {
+ node->move(3, 0);
+ }
+ }
+ });
+
+ listener->bindWithNode(node);
+
+ EMsgManager::bindListenerWithScene(listener, scene);
+
+ app.enterScene(scene);
+
+ app.run();
+ }
+
+ return 0;
+}
diff --git a/Demo/Demo.vcxproj b/Demo/Demo.vcxproj
index 76d54104..2440b382 100644
--- a/Demo/Demo.vcxproj
+++ b/Demo/Demo.vcxproj
@@ -23,13 +23,13 @@
{9D85A92F-BCCE-4EF0-BAD3-601C0086661C}
Win32Proj
Demo
- 8.1
+ 10.0.15063.0
Application
true
- v140
+ v141
Unicode
diff --git a/Demo/main.cpp b/Demo/main.cpp
index 73a4bb5c..bc0016a2 100644
--- a/Demo/main.cpp
+++ b/Demo/main.cpp
@@ -1,12 +1,16 @@
#include "..\Easy2D\easy2d.h"
-#pragma comment(lib, "d2d1.lib")
-int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
+int WINAPI WinMain(
+ HINSTANCE hInstance,
+ HINSTANCE hPrevInstance,
+ LPSTR lpCmdLine,
+ int nCmdShow
+)
{
EApp app;
- if (app.init(L"Easy2D Demo", 640, 480))
+ if (app.init(L"Easy2D Demo", 640, 480, true))
{
auto scene = new EScene();
@@ -37,9 +41,12 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
node->move(3, 0);
}
}
+ EApp::setWindowSize(500, 500);
});
- EMsgManager::addListener(listener);
+ listener->bindWithNode(node);
+
+ EMsgManager::bindListenerWithScene(listener, scene);
app.enterScene(scene);
diff --git a/Easy2D.sln b/Easy2D.sln
index 2c6780c3..22fa8a42 100644
--- a/Easy2D.sln
+++ b/Easy2D.sln
@@ -1,12 +1,14 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
-VisualStudioVersion = 15.0.26730.16
+VisualStudioVersion = 15.0.26730.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Easy2D", "Easy2D\Easy2D.vcxproj", "{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Demo", "Demo\Demo.vcxproj", "{9D85A92F-BCCE-4EF0-BAD3-601C0086661C}"
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ConsoleDemo", "ConsoleDemo\ConsoleDemo.vcxproj", "{70931955-FE2D-4A50-93C6-6955A730B0FE}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@@ -33,6 +35,14 @@ Global
{9D85A92F-BCCE-4EF0-BAD3-601C0086661C}.Release|x64.Build.0 = Release|x64
{9D85A92F-BCCE-4EF0-BAD3-601C0086661C}.Release|x86.ActiveCfg = Release|Win32
{9D85A92F-BCCE-4EF0-BAD3-601C0086661C}.Release|x86.Build.0 = Release|Win32
+ {70931955-FE2D-4A50-93C6-6955A730B0FE}.Debug|x64.ActiveCfg = Debug|x64
+ {70931955-FE2D-4A50-93C6-6955A730B0FE}.Debug|x64.Build.0 = Debug|x64
+ {70931955-FE2D-4A50-93C6-6955A730B0FE}.Debug|x86.ActiveCfg = Debug|Win32
+ {70931955-FE2D-4A50-93C6-6955A730B0FE}.Debug|x86.Build.0 = Debug|Win32
+ {70931955-FE2D-4A50-93C6-6955A730B0FE}.Release|x64.ActiveCfg = Release|x64
+ {70931955-FE2D-4A50-93C6-6955A730B0FE}.Release|x64.Build.0 = Release|x64
+ {70931955-FE2D-4A50-93C6-6955A730B0FE}.Release|x86.ActiveCfg = Release|Win32
+ {70931955-FE2D-4A50-93C6-6955A730B0FE}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Easy2D/Base/EApp.cpp b/Easy2D/Base/EApp.cpp
index 9aa75a0a..3190abd6 100644
--- a/Easy2D/Base/EApp.cpp
+++ b/Easy2D/Base/EApp.cpp
@@ -24,7 +24,6 @@ e2d::EApp::EApp()
, m_bSaveScene(true)
, m_pCurrentScene(nullptr)
, m_pNextScene(nullptr)
- , m_pLoadingScene(nullptr)
{
s_pInstance = this; // ʵ
}
@@ -37,7 +36,7 @@ e2d::EApp::~EApp()
e2d::EApp * e2d::EApp::get()
{
- ASSERT(s_pInstance != nullptr);
+ ASSERT(s_pInstance != nullptr, "Nonexistent EApp instance.");
return s_pInstance; // ȡ EApp Ψһʵ
}
@@ -45,7 +44,7 @@ bool e2d::EApp::init(e2d::EString title, e2d::ESize size, bool bShowConsole /* =
{
return init(title, size.cx, size.cy, bShowConsole);
}
-
+#include
bool e2d::EApp::init(e2d::EString title, UINT32 width, UINT32 height, bool bShowConsole /* = false */)
{
HRESULT hr;
@@ -54,15 +53,29 @@ bool e2d::EApp::init(e2d::EString title, UINT32 width, UINT32 height, bool bShow
if (SUCCEEDED(hr))
{
// رտ̨
- if (!bShowConsole)
+ if (bShowConsole)
{
- HWND consoleHWnd = FindWindow(L"ConsoleWindowClass", NULL);
-
- if (consoleHWnd)
+ // ǷѾڿ̨
+ if (!GetConsoleWindow())
{
- ShowWindow(consoleHWnd, SW_HIDE);
+ // ʾһ¿̨
+ if (AllocConsole())
+ {
+ FILE *stream;
+ freopen_s(&stream, "CONOUT$", "w+t", stdout);
+ freopen_s(&stream, "CONOUT$", "w+t", stderr);
+ freopen_s(&stream, "CONIN$", "r+t", stdin);
+ }
+ else
+ {
+ MessageBox(nullptr, L"Alloc Console Failed!", L"Error", MB_OK);
+ }
}
}
+ else
+ {
+ FreeConsole();
+ }
// ʼ device-indpendent Դ
// Direct2D factory.
@@ -117,6 +130,24 @@ bool e2d::EApp::init(e2d::EString title, UINT32 width, UINT32 height, bool bShow
UnregisterClass(L"E2DApp", HINST_THISCOMPONENT);
MessageBox(nullptr, L"Create Window Failed!", L"Error", MB_OK);
}
+ else
+ {
+ // ȡĻֱ
+ int screenWidth = GetSystemMetrics(SM_CXSCREEN);
+ int screenHeight = GetSystemMetrics(SM_CYSCREEN);
+ // ȡڴС˵
+ tagRECT rcWindow;
+ GetWindowRect(GetHWnd(), &rcWindow);
+ // ĴڴСôĻ
+ MoveWindow(
+ GetHWnd(),
+ (screenWidth - (rcWindow.right - rcWindow.left)) / 2,
+ (screenHeight - (rcWindow.bottom - rcWindow.top)) / 2,
+ (rcWindow.right - rcWindow.left),
+ (rcWindow.bottom - rcWindow.top),
+ FALSE
+ );
+ }
}
if (FAILED(hr))
@@ -130,7 +161,7 @@ bool e2d::EApp::init(e2d::EString title, UINT32 width, UINT32 height, bool bShow
// Ϸ
void e2d::EApp::run()
{
- ASSERT(m_pNextScene != nullptr);
+ ASSERT(m_pNextScene != nullptr, "Next scene NULL pointer exception.");
// һ
_enterNextScene();
// ʾ
@@ -161,9 +192,7 @@ void e2d::EApp::run()
}
}
// Ϸִһѭ
- _mainLoop();
- // رմ
- close();
+ _onControl();
// ͷڴռ
free();
}
@@ -214,10 +243,8 @@ void e2d::EApp::_onControl()
_enterNextScene();
}
// Եǰǿ
- ASSERT(m_pCurrentScene != nullptr);
+ ASSERT(m_pCurrentScene != nullptr, "Current scene NULL pointer exception.");
- //MouseMsg::__exec(); //
- //KeyMsg::__exec(); // ̰
//Timer::__exec(); // ʱִг
//ActionManager::__exec(); // ִг
EObjectManager::__flush(); // ˢڴ
@@ -226,7 +253,7 @@ void e2d::EApp::_onControl()
// This method discards device-specific
// resources if the Direct3D device dissapears during execution and
// recreates the resources the next time it's invoked.
-bool e2d::EApp::_onRender()
+void e2d::EApp::_onRender()
{
HRESULT hr = S_OK;
@@ -251,7 +278,10 @@ bool e2d::EApp::_onRender()
_discardDeviceResources();
}
- return SUCCEEDED(hr);
+ if (FAILED(hr))
+ {
+ exit(EXIT_FAILURE);
+ }
}
void e2d::EApp::setWindowSize(int width, int height)
@@ -268,18 +298,8 @@ void e2d::EApp::setWindowSize(int width, int height)
// ߿С
width += (rcWindow.right - rcWindow.left) - (rcClient.right - rcClient.left);
height += (rcWindow.bottom - rcWindow.top) - (rcClient.bottom - rcClient.top);
- // ٵǰ
- // DestroyWindow(m_);
// ĴڴСôĻ
- SetWindowPos(
- GetHWnd(),
- HWND_TOP,
- (screenWidth - width) / 2,
- (screenHeight - height) / 2,
- width,
- height,
- SWP_SHOWWINDOW
- );
+ MoveWindow(GetHWnd(), (screenWidth - width) / 2, (screenHeight - height) / 2, width, height, TRUE);
}
void e2d::EApp::setWindowSize(e2d::ESize size)
@@ -292,12 +312,12 @@ void e2d::EApp::setWindowTitle(e2d::EString title)
// ôڱ
SetWindowText(GetHWnd(), title.c_str());
// 浱ǰ⣬ĴڴСʱָ
- m_sTitle = title;
+ get()->m_sTitle = title;
}
e2d::EString e2d::EApp::getTitle()
{
- return m_sTitle;
+ return get()->m_sTitle;
}
e2d::ESize e2d::EApp::getSize()
@@ -318,17 +338,17 @@ UINT32 e2d::EApp::getHeight()
void e2d::EApp::enterScene(EScene * scene, bool save /* = true */)
{
// һָ
- m_pNextScene = scene;
+ get()->m_pNextScene = scene;
// лʱǷ浱ǰ
- m_bSaveScene = save;
+ get()->m_bSaveScene = save;
}
void e2d::EApp::backScene()
{
// ջȡָ룬Ϊһ
- m_pNextScene = s_SceneStack.top();
+ get()->m_pNextScene = s_SceneStack.top();
// 浱ǰ
- m_bSaveScene = false;
+ get()->m_bSaveScene = false;
}
void e2d::EApp::clearScene()
@@ -344,17 +364,7 @@ void e2d::EApp::clearScene()
e2d::EScene * e2d::EApp::getCurrentScene()
{
- return m_pCurrentScene;
-}
-
-e2d::EScene * e2d::EApp::getLoadingScene()
-{
- return m_pLoadingScene;
-}
-
-void e2d::EApp::setLoadingScene(EScene * scene)
-{
- m_pLoadingScene = scene;
+ return get()->m_pCurrentScene;
}
void e2d::EApp::setAppName(e2d::EString appname)
@@ -369,7 +379,7 @@ e2d::EString e2d::EApp::getAppName()
void e2d::EApp::setBkColor(EColor::Enum color)
{
- m_ClearColor = color;
+ get()->m_ClearColor = color;
}
void e2d::EApp::close()
@@ -385,8 +395,8 @@ void e2d::EApp::show()
void e2d::EApp::free()
{
// ͷųڴ
- SafeDelete(&m_pCurrentScene);
- SafeDelete(&m_pNextScene);
+ SafeDelete(&get()->m_pCurrentScene);
+ SafeDelete(&get()->m_pNextScene);
// ճջ
while (s_SceneStack.size())
{
@@ -394,33 +404,34 @@ void e2d::EApp::free()
SafeDelete(&temp);
s_SceneStack.pop();
}
- // ɾжʱ
+ // ɾжʱ
//Timer::clearAllTimers();
- //MouseMsg::clearAllListeners();
- //KeyMsg::clearAllListeners();
+ EMsgManager::clearAllKeyboardListeners();
+ EMsgManager::clearAllMouseListeners();
//ActionManager::clearAllActions();
// ɾж
- //EObjectManager::__clearAllObjects();
+ EObjectManager::clearAllObjects();
}
void e2d::EApp::quit()
{
- m_bRunning = false;
+ get()->m_bRunning = false;
}
void e2d::EApp::end()
{
- m_bRunning = false;
+ get()->m_bRunning = false;
}
void e2d::EApp::_enterNextScene()
{
- bool bBackScene = false;
-
// һջ˵ڷһ
if (s_SceneStack.size() && m_pNextScene == s_SceneStack.top())
{
- bBackScene = true;
+ // һʱָϵĶʱ
+ //Timer::notifyAllSceneTimers(m_pNextScene);
+ EMsgManager::notifyAllListenersBindWithScene(m_pNextScene);
+ //ActionManager::notifyAllSceneActions(m_pNextScene);
// ɾջ
s_SceneStack.pop();
}
@@ -435,37 +446,23 @@ void e2d::EApp::_enterNextScene()
s_SceneStack.push(m_pCurrentScene);
// ͣǰежʱ
//Timer::waitAllSceneTimers(m_pCurrentScene);
- //MouseMsg::waitAllSceneListeners(m_pCurrentScene);
- //KeyMsg::waitAllSceneListeners(m_pCurrentScene);
+ EMsgManager::waitAllListenersBindWithScene(m_pCurrentScene);
//ActionManager::waitAllSceneActions(m_pCurrentScene);
}
else
{
// 泡ʱֹͣǰежʱɾǰ
//Timer::clearAllSceneTimers(m_pCurrentScene);
- //MouseMsg::clearAllSceneListeners(m_pCurrentScene);
- //KeyMsg::clearAllSceneListeners(m_pCurrentScene);
+ EMsgManager::clearAllListenersBindWithScene(m_pCurrentScene);
//ActionManager::stopAllSceneActions(m_pCurrentScene);
SafeDelete(&m_pCurrentScene);
}
}
+ m_pNextScene->onEnter(); // ִһ onEnter
+
m_pCurrentScene = m_pNextScene; // л
m_pNextScene = nullptr; // һÿ
-
- if (bBackScene)
- {
- // һʱָϵĶʱ
- //Timer::notifyAllSceneTimers(m_pCurrentScene);
- EMsgManager::notifyAllListenersOnScene(m_pCurrentScene);
- //ActionManager::notifyAllSceneActions(m_pCurrentScene);
- }
- else
- {
- m_pCurrentScene->init(); // һ³ʱִ init
- }
-
- m_pCurrentScene->onEnter(); // ִһ onEnter
}
// Creates resources that are not bound to a particular device.
@@ -602,7 +599,6 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
case WM_KEYDOWN:
case WM_KEYUP:
- case WM_CHAR:
{
EMsgManager::KeyboardProc(message, wParam, lParam);
}
@@ -638,6 +634,10 @@ LRESULT e2d::EApp::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
case WM_DESTROY:
{
+ if (GetConsoleWindow())
+ {
+ FreeConsole();
+ }
PostQuitMessage(0);
}
result = 1;
diff --git a/Easy2D/Base/EObject.cpp b/Easy2D/Base/EObject.cpp
index 82c063be..98e9e087 100644
--- a/Easy2D/Base/EObject.cpp
+++ b/Easy2D/Base/EObject.cpp
@@ -28,4 +28,6 @@ void e2d::EObject::release()
void e2d::EObject::autoRelease()
{
m_bAutoRelease = true;
+ // ֪ͨˢ
+ EObjectManager::notifyFlush();
}
diff --git a/Easy2D/Base/EScene.cpp b/Easy2D/Base/EScene.cpp
index 2de8ed04..9d174c10 100644
--- a/Easy2D/Base/EScene.cpp
+++ b/Easy2D/Base/EScene.cpp
@@ -1,17 +1,14 @@
#include "..\ebase.h"
#include "..\enodes.h"
+#include "..\emsg.h"
-e2d::EScene::EScene()
-{
- EApp::get()->setLoadingScene(this);
-}
e2d::EScene::~EScene()
{
clearAllChildren();
}
-void e2d::EScene::_exec()
+/*void e2d::EScene::_exec()
{
// active ־Ƿȡý
bool active = true;
@@ -23,7 +20,7 @@ void e2d::EScene::_exec()
active = false; // ӽڵȡý㣬־ false
}
}
-}
+}*/
void e2d::EScene::_onRender()
{
@@ -34,10 +31,6 @@ void e2d::EScene::_onRender()
}
}
-void e2d::EScene::init()
-{
-}
-
void e2d::EScene::onEnter()
{
}
@@ -49,11 +42,11 @@ void e2d::EScene::onExit()
void e2d::EScene::add(ENode * child, int zOrder /* = 0 */)
{
// ӵĽڵǿ
- ASSERT(child != nullptr);
+ ASSERT(child != nullptr, "Scene::add NULL pointer exception.");
// Կָ
if (child == nullptr) return;
// ýڵĸ
- child->setParentScene(this);
+ child->bindWithScene(this);
// z ˳
child->setZOrder(zOrder);
// üһ
@@ -118,4 +111,14 @@ void e2d::EScene::clearAllChildren()
}
// մڵ
m_vChildren.clear();
-}
\ No newline at end of file
+}
+
+void e2d::EScene::bindListener(EMouseListener * listener)
+{
+ EMsgManager::bindListenerWithScene(listener, this);
+}
+
+void e2d::EScene::bindListener(EKeyboardListener * listener)
+{
+ EMsgManager::bindListenerWithScene(listener, this);
+}
diff --git a/Easy2D/Easy2D.vcxproj b/Easy2D/Easy2D.vcxproj
index f3d4b807..0f4bdf91 100644
--- a/Easy2D/Easy2D.vcxproj
+++ b/Easy2D/Easy2D.vcxproj
@@ -23,13 +23,13 @@
{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}
Win32Proj
Easy2D
- 8.1
+ 10.0.15063.0
StaticLibrary
true
- v140
+ v141
Unicode
@@ -204,6 +204,7 @@
+
diff --git a/Easy2D/Easy2D.vcxproj.filters b/Easy2D/Easy2D.vcxproj.filters
index c796646e..5c6aded7 100644
--- a/Easy2D/Easy2D.vcxproj.filters
+++ b/Easy2D/Easy2D.vcxproj.filters
@@ -60,6 +60,9 @@
Msg\Listener
+
+ Tool
+
diff --git a/Easy2D/Msg/EMsgManager.cpp b/Easy2D/Msg/EMsgManager.cpp
index 7fa93868..33514906 100644
--- a/Easy2D/Msg/EMsgManager.cpp
+++ b/Easy2D/Msg/EMsgManager.cpp
@@ -8,9 +8,9 @@ e2d::EMouseMsg mouseMsg;
// Ϣ
e2d::EKeyMsg keyMsg;
// Ϣ
-std::vector m_vMouseListeners;
+std::vector s_vMouseListeners;
// Ϣ
-std::vector m_vKeyListeners;
+std::vector s_vKeyListeners;
DWORD e2d::EMouseMsg::getX()
@@ -125,7 +125,7 @@ void e2d::EMsgManager::MouseProc(UINT message, WPARAM wParam, LPARAM lParam)
mouseMsg.m_wParam = wParam;
mouseMsg.m_lParam = lParam;
// ִϢ
- for (auto mlistener : m_vMouseListeners)
+ for (auto mlistener : s_vMouseListeners)
{
if (mlistener->isRunning())
{
@@ -141,7 +141,7 @@ void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam)
keyMsg.m_wParam = wParam;
keyMsg.m_lParam = lParam;
// ִаϢ
- for (auto klistener : m_vKeyListeners)
+ for (auto klistener : s_vKeyListeners)
{
if (klistener->isRunning())
{
@@ -150,38 +150,38 @@ void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam)
}
}
-void e2d::EMsgManager::addListener(e2d::EMouseListener * listener, EScene * pParentScene)
+void e2d::EMsgManager::bindListenerWithScene(e2d::EMouseListener * listener, EScene * pParentScene)
{
- WARN_IF(listener == nullptr, "Add NULL EMouseListener!");
- WARN_IF(pParentScene == nullptr, "Bind EMouseListener on a NULL Scene!");
+ WARN_IF(listener == nullptr, "EMouseListener NULL pointer exception!");
+ WARN_IF(pParentScene == nullptr, "Bind EMouseListener with a NULL EScene pointer!");
if (listener && pParentScene)
{
listener->start();
listener->retain();
- listener->setParentScene(pParentScene);
- m_vMouseListeners.push_back(listener);
+ listener->bindWithScene(pParentScene);
+ s_vMouseListeners.push_back(listener);
}
}
-void e2d::EMsgManager::addListener(e2d::EKeyListener * listener, EScene * pParentScene)
+void e2d::EMsgManager::bindListenerWithScene(e2d::EKeyboardListener * listener, EScene * pParentScene)
{
- WARN_IF(listener == nullptr, "Add NULL EKeyListener!");
- WARN_IF(pParentScene == nullptr, "Bind EKeyListener on a NULL Scene!");
+ WARN_IF(listener == nullptr, "EKeyboardListener NULL pointer exception!");
+ WARN_IF(pParentScene == nullptr, "Bind EKeyboardListener with a NULL EScene pointer!");
if (listener && pParentScene)
{
listener->start();
listener->retain();
- listener->setParentScene(pParentScene);
- m_vKeyListeners.push_back(listener);
+ listener->bindWithScene(pParentScene);
+ s_vKeyListeners.push_back(listener);
}
}
void e2d::EMsgManager::startListener(EString name)
{
// Ϣ
- for (auto l : m_vMouseListeners)
+ for (auto l : s_vMouseListeners)
{
if (l->getName() == name)
{
@@ -189,7 +189,7 @@ void e2d::EMsgManager::startListener(EString name)
}
}
// Ϣ
- for (auto l : m_vKeyListeners)
+ for (auto l : s_vKeyListeners)
{
if (l->getName() == name)
{
@@ -201,7 +201,7 @@ void e2d::EMsgManager::startListener(EString name)
void e2d::EMsgManager::stopListener(EString name)
{
// ֹͣϢ
- for (auto l : m_vMouseListeners)
+ for (auto l : s_vMouseListeners)
{
if (l->getName() == name)
{
@@ -209,7 +209,7 @@ void e2d::EMsgManager::stopListener(EString name)
}
}
// ֹͣϢ
- for (auto l : m_vKeyListeners)
+ for (auto l : s_vKeyListeners)
{
if (l->getName() == name)
{
@@ -221,41 +221,153 @@ void e2d::EMsgManager::stopListener(EString name)
void e2d::EMsgManager::delListener(EString name)
{
// ɾϢ
- for (std::vector::iterator iter = m_vMouseListeners.begin(); iter != m_vMouseListeners.end();)
+ std::vector::iterator mIter;
+ for (mIter = s_vMouseListeners.begin(); mIter != s_vMouseListeners.end();)
{
- if ((*iter)->getName() == name)
+ if ((*mIter)->getName() == name)
{
- (*iter)->autoRelease();
- (*iter)->release();
- delete (*iter);
- iter = m_vMouseListeners.erase(iter);
+ (*mIter)->autoRelease();
+ (*mIter)->release();
+ mIter = s_vMouseListeners.erase(mIter);
}
else
{
- iter++;
+ mIter++;
}
}
// ɾϢ
- for (std::vector::iterator iter = m_vKeyListeners.begin(); iter != m_vKeyListeners.end();)
+ std::vector::iterator kIter;
+ for (kIter = s_vKeyListeners.begin(); kIter != s_vKeyListeners.end();)
{
- if ((*iter)->getName() == name)
+ if ((*kIter)->getName() == name)
{
- (*iter)->autoRelease();
- (*iter)->release();
- delete (*iter);
- iter = m_vKeyListeners.erase(iter);
+ (*kIter)->autoRelease();
+ (*kIter)->release();
+ kIter = s_vKeyListeners.erase(kIter);
}
else
{
- iter++;
+ kIter++;
}
}
}
-void e2d::EMsgManager::waitAllListenersOnScene(EScene * scene)
+void e2d::EMsgManager::startAllMouseListener()
+{
+ for (auto l : s_vMouseListeners)
+ {
+ if (!l->isWaiting())
+ {
+ l->start();
+ }
+ }
+}
+
+void e2d::EMsgManager::stopAllMouseListener()
+{
+ for (auto l : s_vMouseListeners)
+ {
+ if (!l->isWaiting())
+ {
+ l->stop();
+ }
+ }
+}
+
+void e2d::EMsgManager::clearAllMouseListeners()
+{
+ for (auto l : s_vMouseListeners)
+ {
+ l->autoRelease();
+ l->release();
+ }
+ s_vMouseListeners.clear();
+}
+
+void e2d::EMsgManager::startAllKeyboardListener()
+{
+ for (auto l : s_vKeyListeners)
+ {
+ if (!l->isWaiting())
+ {
+ l->start();
+ }
+ }
+}
+
+void e2d::EMsgManager::stopAllKeyboardListener()
+{
+ for (auto l : s_vKeyListeners)
+ {
+ if (!l->isWaiting())
+ {
+ l->stop();
+ }
+ }
+}
+
+void e2d::EMsgManager::clearAllKeyboardListeners()
+{
+ for (auto l : s_vKeyListeners)
+ {
+ l->autoRelease();
+ l->release();
+ }
+ s_vKeyListeners.clear();
+}
+
+void e2d::EMsgManager::startAllMouseListenersBindWithScene(EScene * pParentScene)
+{
+ // Ϣ
+ for (auto l : s_vMouseListeners)
+ {
+ if (l->getParentScene() == pParentScene)
+ {
+ l->start();
+ }
+ }
+}
+
+void e2d::EMsgManager::stopAllMouseListenersBindWithScene(EScene * pParentScene)
+{
+ // ֹͣϢ
+ for (auto l : s_vMouseListeners)
+ {
+ if (l->getParentScene() == pParentScene)
+ {
+ l->stop();
+ }
+ }
+}
+
+void e2d::EMsgManager::startAllKeyboardListenersBindWithScene(EScene * pParentScene)
+{
+ // Ϣ
+ for (auto l : s_vKeyListeners)
+ {
+ if (l->getParentScene() == pParentScene)
+ {
+ l->start();
+ }
+ }
+}
+
+void e2d::EMsgManager::stopAllKeyboardListenersBindWithScene(EScene * pParentScene)
+{
+ // ֹͣϢ
+ for (auto l : s_vKeyListeners)
+ {
+ if (l->getParentScene() == pParentScene)
+ {
+ l->stop();
+ }
+ }
+}
+
+void e2d::EMsgManager::waitAllListenersBindWithScene(EScene * scene)
{
// Ϣ
- for (auto l : m_vMouseListeners)
+ for (auto l : s_vMouseListeners)
{
if (l->getParentScene() == scene)
{
@@ -263,7 +375,7 @@ void e2d::EMsgManager::waitAllListenersOnScene(EScene * scene)
}
}
// 𰴼Ϣ
- for (auto l : m_vKeyListeners)
+ for (auto l : s_vKeyListeners)
{
if (l->getParentScene() == scene)
{
@@ -272,10 +384,10 @@ void e2d::EMsgManager::waitAllListenersOnScene(EScene * scene)
}
}
-void e2d::EMsgManager::notifyAllListenersOnScene(EScene * scene)
+void e2d::EMsgManager::notifyAllListenersBindWithScene(EScene * scene)
{
// Ϣ
- for (auto l : m_vMouseListeners)
+ for (auto l : s_vMouseListeners)
{
if (l->getParentScene() == scene)
{
@@ -283,7 +395,7 @@ void e2d::EMsgManager::notifyAllListenersOnScene(EScene * scene)
}
}
// Ϣ
- for (auto l : m_vKeyListeners)
+ for (auto l : s_vKeyListeners)
{
if (l->getParentScene() == scene)
{
@@ -292,3 +404,107 @@ void e2d::EMsgManager::notifyAllListenersOnScene(EScene * scene)
}
}
+void e2d::EMsgManager::clearAllListenersBindWithScene(EScene * scene)
+{
+ std::vector::iterator mIter;
+ for (mIter = s_vMouseListeners.begin(); mIter != s_vMouseListeners.end();)
+ {
+ if ((*mIter)->getParentScene() == scene)
+ {
+ (*mIter)->autoRelease();
+ (*mIter)->release();
+ mIter = s_vMouseListeners.erase(mIter);
+ }
+ else
+ {
+ mIter++;
+ }
+ }
+ std::vector::iterator kIter;
+ for (kIter = s_vKeyListeners.begin(); kIter != s_vKeyListeners.end();)
+ {
+ if ((*kIter)->getParentScene() == scene)
+ {
+ (*kIter)->autoRelease();
+ (*kIter)->release();
+ kIter = s_vKeyListeners.erase(kIter);
+ }
+ else
+ {
+ kIter++;
+ }
+ }
+}
+
+void e2d::EMsgManager::waitAllListenersBindWithNode(ENode * pParentNode)
+{
+ // Ϣ
+ for (auto l : s_vMouseListeners)
+ {
+ if (l->getParentNode() == pParentNode)
+ {
+ l->wait();
+ }
+ }
+ // 𰴼Ϣ
+ for (auto l : s_vKeyListeners)
+ {
+ if (l->getParentNode() == pParentNode)
+ {
+ l->wait();
+ }
+ }
+}
+
+void e2d::EMsgManager::notifyAllListenersBindWithNode(ENode * pParentNode)
+{
+ // Ϣ
+ for (auto l : s_vMouseListeners)
+ {
+ if (l->getParentNode() == pParentNode)
+ {
+ l->notify();
+ }
+ }
+ // Ϣ
+ for (auto l : s_vKeyListeners)
+ {
+ if (l->getParentNode() == pParentNode)
+ {
+ l->notify();
+ }
+ }
+}
+
+void e2d::EMsgManager::clearAllListenersBindWithNode(ENode * pParentNode)
+{
+ std::vector::iterator mIter;
+ for (mIter = s_vMouseListeners.begin(); mIter != s_vMouseListeners.end();)
+ {
+ if ((*mIter)->getParentNode() == pParentNode)
+ {
+ (*mIter)->autoRelease();
+ (*mIter)->release();
+ mIter = s_vMouseListeners.erase(mIter);
+ }
+ else
+ {
+ mIter++;
+ }
+ }
+ std::vector::iterator kIter;
+ for (kIter = s_vKeyListeners.begin(); kIter != s_vKeyListeners.end();)
+ {
+ if ((*kIter)->getParentNode() == pParentNode)
+ {
+ (*kIter)->autoRelease();
+ (*kIter)->release();
+ kIter = s_vKeyListeners.erase(kIter);
+ }
+ else
+ {
+ kIter++;
+ }
+ }
+}
+
diff --git a/Easy2D/Msg/Listener/EKeyListener.cpp b/Easy2D/Msg/Listener/EKeyListener.cpp
index 214995ed..64092693 100644
--- a/Easy2D/Msg/Listener/EKeyListener.cpp
+++ b/Easy2D/Msg/Listener/EKeyListener.cpp
@@ -1,33 +1,33 @@
#include "..\..\emsg.h"
-e2d::EKeyListener::EKeyListener()
+e2d::EKeyboardListener::EKeyboardListener()
: EListener()
{
}
-e2d::EKeyListener::EKeyListener(EString name)
+e2d::EKeyboardListener::EKeyboardListener(EString name)
: EListener(name)
{
}
-e2d::EKeyListener::EKeyListener(const KEY_LISTENER_CALLBACK & callback)
+e2d::EKeyboardListener::EKeyboardListener(const KEY_LISTENER_CALLBACK & callback)
: EListener()
{
m_callback = callback;
}
-e2d::EKeyListener::EKeyListener(EString name, const KEY_LISTENER_CALLBACK & callback)
+e2d::EKeyboardListener::EKeyboardListener(EString name, const KEY_LISTENER_CALLBACK & callback)
: EListener(name)
{
m_callback = callback;
}
-void e2d::EKeyListener::runCallback()
+void e2d::EKeyboardListener::runCallback()
{
m_callback();
}
-void e2d::EKeyListener::setCallback(const KEY_LISTENER_CALLBACK & callback)
+void e2d::EKeyboardListener::setCallback(const KEY_LISTENER_CALLBACK & callback)
{
m_callback = callback;
}
diff --git a/Easy2D/Msg/Listener/EKeyPressListener.cpp b/Easy2D/Msg/Listener/EKeyPressListener.cpp
index 593b6e29..3b2a22bd 100644
--- a/Easy2D/Msg/Listener/EKeyPressListener.cpp
+++ b/Easy2D/Msg/Listener/EKeyPressListener.cpp
@@ -1,22 +1,22 @@
#include "..\..\emsg.h"
e2d::EKeyPressListener::EKeyPressListener()
- : EKeyListener()
+ : EKeyboardListener()
{
}
e2d::EKeyPressListener::EKeyPressListener(EString name)
- : EKeyListener(name)
+ : EKeyboardListener(name)
{
}
e2d::EKeyPressListener::EKeyPressListener(const KEY_LISTENER_CALLBACK & callback)
- : EKeyListener(callback)
+ : EKeyboardListener(callback)
{
}
e2d::EKeyPressListener::EKeyPressListener(EString name, const KEY_LISTENER_CALLBACK & callback)
- : EKeyListener(name, callback)
+ : EKeyboardListener(name, callback)
{
}
diff --git a/Easy2D/Msg/Listener/EListener.cpp b/Easy2D/Msg/Listener/EListener.cpp
index 1de028d5..43704a15 100644
--- a/Easy2D/Msg/Listener/EListener.cpp
+++ b/Easy2D/Msg/Listener/EListener.cpp
@@ -5,6 +5,7 @@ e2d::EListener::EListener()
, m_bWaiting(false)
, m_sName(L"")
, m_pParentScene(nullptr)
+ , m_pParentNode(nullptr)
{
}
@@ -19,6 +20,11 @@ bool e2d::EListener::isRunning() const
return m_bRunning && !m_bWaiting;
}
+bool e2d::EListener::isWaiting() const
+{
+ return m_bWaiting;
+}
+
void e2d::EListener::start()
{
m_bRunning = true;
@@ -39,6 +45,11 @@ void e2d::EListener::notify()
m_bWaiting = false;
}
+e2d::EListener * e2d::EListener::clone()
+{
+ return nullptr;
+}
+
e2d::EString e2d::EListener::getName() const
{
return m_sName;
@@ -49,12 +60,32 @@ e2d::EScene * e2d::EListener::getParentScene() const
return m_pParentScene;
}
+e2d::ENode * e2d::EListener::getParentNode() const
+{
+ return m_pParentNode;
+}
+
void e2d::EListener::setName(EString name)
{
m_sName = name;
}
-void e2d::EListener::setParentScene(EScene * scene)
+void e2d::EListener::bindWithScene(EScene * scene)
{
- if (scene != nullptr) m_pParentScene = scene;
+ WARN_IF(m_pParentNode != nullptr, "EListener bind with Scene Failed! Please use its clone.");
+
+ if (scene != nullptr && m_pParentNode == nullptr)
+ {
+ m_pParentScene = scene;
+ }
+}
+
+void e2d::EListener::bindWithNode(ENode * pParentNode)
+{
+ WARN_IF(m_pParentScene != nullptr, "EListener bind with Node Failed! Please use its clone.");
+
+ if (pParentNode != nullptr && m_pParentScene == nullptr)
+ {
+ m_pParentNode = pParentNode;
+ }
}
diff --git a/Easy2D/Node/ENode.cpp b/Easy2D/Node/ENode.cpp
index d787542b..a90ba6cc 100644
--- a/Easy2D/Node/ENode.cpp
+++ b/Easy2D/Node/ENode.cpp
@@ -183,7 +183,7 @@ e2d::EScene * &e2d::ENode::getParentScene()
return m_pParentScene;
}
-void e2d::ENode::setParentScene(EScene * scene)
+void e2d::ENode::bindWithScene(EScene * scene)
{
m_pParentScene = scene;
}
diff --git a/Easy2D/Tool/EObjectManager.cpp b/Easy2D/Tool/EObjectManager.cpp
index acf65928..dc5e982c 100644
--- a/Easy2D/Tool/EObjectManager.cpp
+++ b/Easy2D/Tool/EObjectManager.cpp
@@ -10,9 +10,14 @@
// ͷų
static std::vector s_vPool;
+// ־ͷųִ״̬
+static bool s_bNotifyed = false;
void e2d::EObjectManager::__flush()
{
+ if (!s_bNotifyed) return;
+
+ s_bNotifyed = false;
//
static std::vector::iterator iter;
// ѭеж
@@ -49,3 +54,8 @@ void e2d::EObjectManager::clearAllObjects()
}
s_vPool.clear();
}
+
+void e2d::EObjectManager::notifyFlush()
+{
+ s_bNotifyed = true;
+}
diff --git a/Easy2D/Tool/ETimerManager.cpp b/Easy2D/Tool/ETimerManager.cpp
new file mode 100644
index 00000000..08fb0b33
--- /dev/null
+++ b/Easy2D/Tool/ETimerManager.cpp
@@ -0,0 +1 @@
+#include "..\etools.h"
\ No newline at end of file
diff --git a/Easy2D/Win/winbase.cpp b/Easy2D/Win/winbase.cpp
index 48fbea8f..56c472b9 100644
--- a/Easy2D/Win/winbase.cpp
+++ b/Easy2D/Win/winbase.cpp
@@ -21,22 +21,3 @@ ID2D1HwndRenderTarget * &GetRenderTarget()
return pRenderTarget;
}
-void WindowCenter(HWND hWnd)
-{
- // ȡĻֱ
- int screenWidth = GetSystemMetrics(SM_CXSCREEN);
- int screenHeight = GetSystemMetrics(SM_CYSCREEN);
- // ȡڴС
- tagRECT rcWindow;
- GetWindowRect(hWnd, &rcWindow);
- // ôĻ
- SetWindowPos(
- hWnd,
- HWND_TOP,
- (screenWidth - (rcWindow.left - rcWindow.right)) / 2,
- (screenHeight - (rcWindow.top - rcWindow.bottom)) / 2,
- (rcWindow.left - rcWindow.right),
- (rcWindow.top - rcWindow.bottom),
- SWP_SHOWWINDOW | SWP_NOSIZE
- );
-}
diff --git a/Easy2D/Win/winbase.h b/Easy2D/Win/winbase.h
index aae0f32d..83642c4a 100644
--- a/Easy2D/Win/winbase.h
+++ b/Easy2D/Win/winbase.h
@@ -4,6 +4,7 @@
#include
#include
#include
+#pragma comment(lib, "d2d1.lib")
HWND &GetHWnd();
@@ -11,8 +12,6 @@ ID2D1Factory * &GetFactory();
ID2D1HwndRenderTarget * &GetRenderTarget();
-void WindowCenter(HWND hWnd);
-
template
inline void SafeReleaseInterface(
diff --git a/Easy2D/easy2d.h b/Easy2D/easy2d.h
index c3b80997..25f866e4 100644
--- a/Easy2D/easy2d.h
+++ b/Easy2D/easy2d.h
@@ -19,8 +19,8 @@
#include "emacros.h"
#include "ecommon.h"
#include "ebase.h"
-#include "emsg.h"
#include "enodes.h"
+#include "emsg.h"
#include "etools.h"
diff --git a/Easy2D/ebase.h b/Easy2D/ebase.h
index 50837fb8..3b705674 100644
--- a/Easy2D/ebase.h
+++ b/Easy2D/ebase.h
@@ -12,6 +12,8 @@ namespace e2d
class EScene;
class ENode;
class EObjectManager;
+class EMouseListener;
+class EKeyboardListener;
class EApp
{
@@ -42,81 +44,75 @@ public:
void run();
// ĴڴС
- void setWindowSize(
+ static void setWindowSize(
int width,
int height
);
// ĴڴС
- void setWindowSize(
+ static void setWindowSize(
e2d::ESize size
);
// ôڱ
- void setWindowTitle(
+ static void setWindowTitle(
e2d::EString title
);
// ȡڱ
- e2d::EString getTitle();
+ static e2d::EString getTitle();
// ȡڴС
- e2d::ESize getSize();
+ static e2d::ESize getSize();
// ȡڿ
- UINT32 getWidth();
+ static UINT32 getWidth();
// ȡڸ߶
- UINT32 getHeight();
+ static UINT32 getHeight();
// л
- void enterScene(
+ static void enterScene(
EScene * scene,
bool save = true
);
// һ
- void backScene();
+ static void backScene();
// ձг
- void clearScene();
+ static void clearScene();
// ȡǰ
- EScene * getCurrentScene();
-
- // ȡڼеij
- EScene * getLoadingScene();
-
- // ڼеij
- void setLoadingScene(EScene * scene);
+ static EScene * getCurrentScene();
// ȡ AppName
- e2d::EString getAppName();
+ static e2d::EString getAppName();
// AppName
- void setAppName(
+ static void setAppName(
e2d::EString appname
);
// Ĵڱɫ
- void setBkColor(
+ static void setBkColor(
EColor::Enum color
);
// ͷڴԴ
- void free();
+ static void free();
// رմ
- void close();
+ static void close();
// ʾ
- void show();
+ static void show();
// ֹ
- void quit();
+ static void quit();
// ֹ
- void end();
+ static void end();
protected:
// Initialize device-independent resources.
@@ -133,7 +129,7 @@ protected:
void _onControl();
// Draw content.
- bool _onRender();
+ void _onRender();
void _enterNextScene();
@@ -160,7 +156,6 @@ protected:
EScene * m_pCurrentScene;
EScene * m_pNextScene;
- EScene * m_pLoadingScene;
};
@@ -169,13 +164,10 @@ class EScene
friend EApp;
public:
- EScene();
+ EScene() = default;
~EScene();
- // дʼ
- virtual void init();
-
// дڽʱԶִ
virtual void onEnter();
@@ -200,14 +192,18 @@ public:
// ӳԱ
void clearAllChildren();
+ // Ϣ
+ void bindListener(EMouseListener * listener);
+
+ // Ϣ
+ void bindListener(EKeyboardListener * listener);
+
+protected:
+ // Ⱦ
+ void _onRender();
+
protected:
std::vector m_vChildren;
-
-protected:
- //
- void _exec();
-
- void _onRender();
};
diff --git a/Easy2D/emacros.h b/Easy2D/emacros.h
index 2c2b2337..0b75b151 100644
--- a/Easy2D/emacros.h
+++ b/Easy2D/emacros.h
@@ -25,14 +25,18 @@
#ifndef ASSERT_IF
#if defined( DEBUG ) || defined( _DEBUG )
- #define ASSERT(b) do {if (!(b)) { OutputDebugStringA("Assert: " #b "\n"); }} while(0)
+#define ASSERT(b, m) do {if (!(b)) { fprintf(stderr, "Assert: " #m "\n"); abort(); }} while(0)
#else
- #define ASSERT(b)
+ #define ASSERT(b, m) ((void)0)
#endif //DEBUG || _DEBUG
#endif
#ifndef WARN_IF
-#define WARN_IF(b, m) do {if (b) { fprintf(stderr, "Warning: " #m "/n"); }} while(0)
+#if defined( DEBUG ) || defined( _DEBUG )
+#define WARN_IF(b, m) do {if (b) { fprintf(stderr, "Warning: " #m "\n"); }} while(0)
+#else
+#define WARN_IF(b, m) ((void)0)
+#endif //DEBUG || _DEBUG
#endif
diff --git a/Easy2D/emsg.h b/Easy2D/emsg.h
index bc487ef3..0d37b960 100644
--- a/Easy2D/emsg.h
+++ b/Easy2D/emsg.h
@@ -1,406 +1,479 @@
#pragma once
-#include "ebase.h"
-
-namespace e2d
-{
-
-class EMsgManager;
-
-
-// Ϣ
-class EMouseMsg
-{
- friend EMsgManager;
-
-public:
- // Ϣ
- enum class MOUSE_MSG
- {
- MOVE = 0x0200, // ƶ
- LBUTTON_DOWN, //
- LBUTTON_UP, // ̧
- LBUTTON_DBLCLK, // ˫
- RBUTTON_DOWN, // Ҽ
- RBUTTON_UP, // Ҽ̧
- RBUTTON_DBLCLK, // Ҽ˫
- MBUTTON_DOWN, // м
- MBUTTON_UP, // м̧
- MBUTTON_DBLCLK, // м˫
- WHEEL //
- };
-
- // ȡ
- static DWORD getX();
-
- // ȡ
- static DWORD getY();
-
- // ȡ
- static EPoint getPos();
-
- // ȡ״̬
- static bool isLButtonDown();
-
- // ȡм״̬
- static bool isMButtonDown();
-
- // ȡҼ״̬
- static bool isRButtonDown();
-
- // ȡ Shift ״̬
- static bool isShiftDown();
-
- // ȡ Ctrl ״̬
- static bool isCtrlDown();
-
- // ȡֵ
- static DWORD getWheelDelta();
-
- // ȡǰϢ
- static MOUSE_MSG getMsg();
-
-protected:
- UINT m_nMsg = 0;
- WPARAM m_wParam = 0;
- LPARAM m_lParam = 0;
-};
-
-
-//
-class EListener :
- public EObject
-{
-public:
- EListener();
-
- EListener(
- EString name
- );
-
- // ȡ״̬
- bool isRunning() const;
-
- //
- void start();
-
- // ֹͣ
- void stop();
-
- // ȴ״̬
- void wait();
-
- //
- void notify();
-
- // ȡ
- EString getName() const;
-
- // ȡڳ
- EScene * getParentScene() const;
-
- // ü
- void setName(
- EString name
- );
-
- // üڳ
- void setParentScene(
- EScene * scene
- );
-
-protected:
- EString m_sName;
- bool m_bRunning;
- bool m_bWaiting;
- EScene * m_pParentScene;
-};
-
-
-// Ϣ
-class EMouseListener :
- public EListener
-{
-public:
- EMouseListener();
-
- EMouseListener(
- EString name
- );
-
- EMouseListener(
- const MOUSE_LISTENER_CALLBACK &callback
- );
-
- EMouseListener(
- EString name,
- const MOUSE_LISTENER_CALLBACK &callback
- );
-
- // ִмص
- virtual void runCallback();
-
- // üص
- void setCallback(
- const MOUSE_LISTENER_CALLBACK &callback
- );
-
-protected:
- MOUSE_LISTENER_CALLBACK m_callback;
-};
-
-
-// Ϣ
-class EMouseClickListener :
- public EMouseListener
-{
-public:
- EMouseClickListener();
-
- EMouseClickListener(
- EString name
- );
-
- EMouseClickListener(
- const MOUSE_CLICK_LISTENER_CALLBACK &callback
- );
-
- EMouseClickListener(
- EString name,
- const MOUSE_CLICK_LISTENER_CALLBACK &callback
- );
-
- // ִмص
- virtual void runCallback() override;
-
- // üص
- void setCallback(
- const MOUSE_CLICK_LISTENER_CALLBACK &callback
- );
-
-protected:
- MOUSE_CLICK_LISTENER_CALLBACK m_callback;
-};
-
-
-// ϶Ϣ
-class EMouseDraggedListener :
- public EMouseListener
-{
-public:
- EMouseDraggedListener();
-
- EMouseDraggedListener(
- EString name
- );
-
- EMouseDraggedListener(
- const MOUSE_DRAG_LISTENER_CALLBACK &callback
- );
-
- EMouseDraggedListener(
- EString name,
- const MOUSE_DRAG_LISTENER_CALLBACK &callback
- );
-
- // ִмص
- virtual void runCallback() override;
-
- // üص
- void setCallback(
- const MOUSE_DRAG_LISTENER_CALLBACK &callback
- );
-
-protected:
- EPoint m_Begin;
- EPoint m_End;
- MOUSE_DRAG_LISTENER_CALLBACK m_callback;
-};
-
-
-// Ϣ
-class EKeyMsg
-{
- friend EMsgManager;
-
-public:
- // Ϣͼ
- enum class KEYBOARD_MSG
- {
- KEY_DOWN = 0x0100, //
- KEY_UP // ̧
- };
-
- // ֵ
- enum class KEY
- {
- A = 'A', B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, // ĸֵ
- NUM0 = '0', NUM1, NUM2, NUM3, NUM4, NUM5, NUM6, NUM7, NUM8, NUM9, // ֵּ
- NUMPAD0 = 0x60, NUMPAD1, NUMPAD2, NUMPAD3, NUMPAD4, NUMPAD5, NUMPAD6, NUMPAD7, NUMPAD8, NUMPAD9, // Сֵ̼
- F1 = 0x70, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, // Fֵ
- MULTIPLY, // ˺żֵ
- ADD, // Ӻżֵ
- SEPARATOR, // ֵָ
- SUBTRACT, // żֵ
- DECIMAL, // Сֵ
- DIVIDE, // żֵ
- TAB = 0x09, // TAB ֵ
- ENTER = 0x0D, // سֵ
- SHIFT, CTRL, // SHIFT ֵ
- ESC = 0x1B, // ESCAPE ֵ
- SPACE = 0x20, // ոֵ
- PAGE_UP, // PageUp ֵ
- PAGE_DOWN, // PageDown ֵ
- END, // End ֵ
- HOME, // Home ֵ
- LEFT, // ֵ
- UP, // ϼֵ
- RIGHT, // Ҽֵ
- DOWN // ¼ֵ
- };
-
- // ȡϢ
- static KEYBOARD_MSG getMsg();
-
- // ȡֵ
- static KEY getVal();
-
- // ȡϢļ
- static DWORD getCount();
-
- // ȡض״̬
- static bool isKeyDown(
- KEY key
- );
-
- // ȡСд״̬
- static bool isCapitalLockOn();
-
- // ȡС״̬
- static bool isNumpadLockOn();
-
- // ȡ״̬
- static bool isScrollLockOn();
-
-protected:
- UINT m_nMsg = 0;
- WPARAM m_wParam = 0;
- LPARAM m_lParam = 0;
-};
-
-
-// Ϣ
-class EKeyListener :
- public EListener
-{
-public:
- EKeyListener();
-
- EKeyListener(
- EString name
- );
-
- EKeyListener(
- const KEY_LISTENER_CALLBACK &callback
- );
-
- EKeyListener(
- EString name,
- const KEY_LISTENER_CALLBACK &callback
- );
-
- // ִмص
- virtual void runCallback();
-
- // üص
- void setCallback(
- const KEY_LISTENER_CALLBACK &callback
- );
-
-protected:
- KEY_LISTENER_CALLBACK m_callback;
-};
-
-
-// Ϣ
-class EKeyPressListener :
- public EKeyListener
-{
-public:
- EKeyPressListener();
-
- EKeyPressListener(
- EString name
- );
-
- EKeyPressListener(
- const KEY_LISTENER_CALLBACK &callback
- );
-
- EKeyPressListener(
- EString name,
- const KEY_LISTENER_CALLBACK &callback
- );
-
- // ִмص
- virtual void runCallback() override;
-};
-
-
-// Ϣ
-class EMsgManager
-{
- friend EApp;
-
-public:
- // Ϣ
- static void addListener(
- EMouseListener * listener,
- EScene * pParentScene
- );
-
- // ӰϢ
- static void addListener(
- EKeyListener * listener,
- EScene * pParentScene
- );
-
- // ͬƵļ
- static void startListener(
- EString name
- );
-
- // ֹͣͬƵļ
- static void stopListener(
- EString name
- );
-
- // ɾͬƵļ
- static void delListener(
- EString name
- );
-
- // ϵм
- static void waitAllListenersOnScene(
- EScene * scene
- );
-
- // ϵм
- static void notifyAllListenersOnScene(
- EScene * scene
- );
-
-private:
- static void MouseProc(
- UINT message,
- WPARAM wParam,
- LPARAM lParam
- );
-
- static void KeyboardProc(
- UINT message,
- WPARAM wParam,
- LPARAM lParam
- );
-};
-
+#include "ebase.h"
+
+namespace e2d
+{
+
+class ENode;
+class EMsgManager;
+
+// Ϣ
+class EMouseMsg
+{
+ friend EMsgManager;
+
+public:
+ // Ϣ
+ enum class MOUSE_MSG
+ {
+ MOVE = 0x0200, // ƶ
+ LBUTTON_DOWN, //
+ LBUTTON_UP, // ̧
+ LBUTTON_DBLCLK, // ˫
+ RBUTTON_DOWN, // Ҽ
+ RBUTTON_UP, // Ҽ̧
+ RBUTTON_DBLCLK, // Ҽ˫
+ MBUTTON_DOWN, // м
+ MBUTTON_UP, // м̧
+ MBUTTON_DBLCLK, // м˫
+ WHEEL //
+ };
+
+ // ȡ
+ static DWORD getX();
+
+ // ȡ
+ static DWORD getY();
+
+ // ȡ
+ static EPoint getPos();
+
+ // ȡ״̬
+ static bool isLButtonDown();
+
+ // ȡм״̬
+ static bool isMButtonDown();
+
+ // ȡҼ״̬
+ static bool isRButtonDown();
+
+ // ȡ Shift ״̬
+ static bool isShiftDown();
+
+ // ȡ Ctrl ״̬
+ static bool isCtrlDown();
+
+ // ȡֵ
+ static DWORD getWheelDelta();
+
+ // ȡǰϢ
+ static MOUSE_MSG getMsg();
+
+protected:
+ UINT m_nMsg = 0;
+ WPARAM m_wParam = 0;
+ LPARAM m_lParam = 0;
+};
+
+
+// Ϣ
+class EKeyMsg
+{
+ friend EMsgManager;
+
+public:
+ // Ϣͼ
+ enum class KEYBOARD_MSG
+ {
+ KEY_DOWN = 0x0100, //
+ KEY_UP // ̧
+ };
+
+ // ֵ
+ enum class KEY
+ {
+ A = 'A', B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, // ĸֵ
+ NUM0 = '0', NUM1, NUM2, NUM3, NUM4, NUM5, NUM6, NUM7, NUM8, NUM9, // ֵּ
+ NUMPAD0 = 0x60, NUMPAD1, NUMPAD2, NUMPAD3, NUMPAD4, NUMPAD5, NUMPAD6, NUMPAD7, NUMPAD8, NUMPAD9, // Сֵ̼
+ F1 = 0x70, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, // Fֵ
+ MULTIPLY, // ˺żֵ
+ ADD, // Ӻżֵ
+ SEPARATOR, // ֵָ
+ SUBTRACT, // żֵ
+ DECIMAL, // Сֵ
+ DIVIDE, // żֵ
+ TAB = 0x09, // TAB ֵ
+ ENTER = 0x0D, // سֵ
+ SHIFT, CTRL, // SHIFT ֵ
+ ESC = 0x1B, // ESCAPE ֵ
+ SPACE = 0x20, // ոֵ
+ PAGE_UP, // PageUp ֵ
+ PAGE_DOWN, // PageDown ֵ
+ END, // End ֵ
+ HOME, // Home ֵ
+ LEFT, // ֵ
+ UP, // ϼֵ
+ RIGHT, // Ҽֵ
+ DOWN // ¼ֵ
+ };
+
+ // ȡϢ
+ static KEYBOARD_MSG getMsg();
+
+ // ȡֵ
+ static KEY getVal();
+
+ // ȡϢļ
+ static DWORD getCount();
+
+ // ȡض״̬
+ static bool isKeyDown(
+ KEY key
+ );
+
+ // ȡСд״̬
+ static bool isCapitalLockOn();
+
+ // ȡС״̬
+ static bool isNumpadLockOn();
+
+ // ȡ״̬
+ static bool isScrollLockOn();
+
+protected:
+ UINT m_nMsg = 0;
+ WPARAM m_wParam = 0;
+ LPARAM m_lParam = 0;
+};
+
+
+//
+class EListener :
+ public EObject
+{
+public:
+ EListener();
+
+ EListener(
+ EString name
+ );
+
+ // ȡ״̬
+ bool isRunning() const;
+
+ // ȡ״̬
+ bool isWaiting() const;
+
+ //
+ void start();
+
+ // ֹͣ
+ void stop();
+
+ // ȴ״̬
+ void wait();
+
+ //
+ void notify();
+
+ // ¡һͬļ
+ virtual EListener * clone();
+
+ // ȡ
+ EString getName() const;
+
+ // ȡڳ
+ EScene * getParentScene() const;
+
+ // ȡڽڵ
+ ENode * getParentNode() const;
+
+ // ü
+ void setName(
+ EString name
+ );
+
+ //
+ void bindWithScene(
+ EScene * pParentScene
+ );
+
+ // ڵ
+ void bindWithNode(
+ ENode * pParentNode
+ );
+
+protected:
+ EString m_sName;
+ bool m_bRunning;
+ bool m_bWaiting;
+ EScene * m_pParentScene;
+ ENode * m_pParentNode;
+};
+
+
+// Ϣ
+class EMouseListener :
+ public EListener
+{
+public:
+ EMouseListener();
+
+ EMouseListener(
+ EString name
+ );
+
+ EMouseListener(
+ const MOUSE_LISTENER_CALLBACK &callback
+ );
+
+ EMouseListener(
+ EString name,
+ const MOUSE_LISTENER_CALLBACK &callback
+ );
+
+ // ִмص
+ virtual void runCallback();
+
+ // üص
+ void setCallback(
+ const MOUSE_LISTENER_CALLBACK &callback
+ );
+
+protected:
+ MOUSE_LISTENER_CALLBACK m_callback;
+};
+
+
+// Ϣ
+class EMouseClickListener :
+ public EMouseListener
+{
+public:
+ EMouseClickListener();
+
+ EMouseClickListener(
+ EString name
+ );
+
+ EMouseClickListener(
+ const MOUSE_CLICK_LISTENER_CALLBACK &callback
+ );
+
+ EMouseClickListener(
+ EString name,
+ const MOUSE_CLICK_LISTENER_CALLBACK &callback
+ );
+
+ // ִмص
+ virtual void runCallback() override;
+
+ // üص
+ void setCallback(
+ const MOUSE_CLICK_LISTENER_CALLBACK &callback
+ );
+
+protected:
+ MOUSE_CLICK_LISTENER_CALLBACK m_callback;
+};
+
+
+// ϶Ϣ
+class EMouseDraggedListener :
+ public EMouseListener
+{
+public:
+ EMouseDraggedListener();
+
+ EMouseDraggedListener(
+ EString name
+ );
+
+ EMouseDraggedListener(
+ const MOUSE_DRAG_LISTENER_CALLBACK &callback
+ );
+
+ EMouseDraggedListener(
+ EString name,
+ const MOUSE_DRAG_LISTENER_CALLBACK &callback
+ );
+
+ // ִмص
+ virtual void runCallback() override;
+
+ // üص
+ void setCallback(
+ const MOUSE_DRAG_LISTENER_CALLBACK &callback
+ );
+
+protected:
+ EPoint m_Begin;
+ EPoint m_End;
+ MOUSE_DRAG_LISTENER_CALLBACK m_callback;
+};
+
+
+// Ϣ
+class EKeyboardListener :
+ public EListener
+{
+public:
+ EKeyboardListener();
+
+ EKeyboardListener(
+ EString name
+ );
+
+ EKeyboardListener(
+ const KEY_LISTENER_CALLBACK &callback
+ );
+
+ EKeyboardListener(
+ EString name,
+ const KEY_LISTENER_CALLBACK &callback
+ );
+
+ // ִмص
+ virtual void runCallback();
+
+ // üص
+ void setCallback(
+ const KEY_LISTENER_CALLBACK &callback
+ );
+
+protected:
+ KEY_LISTENER_CALLBACK m_callback;
+};
+
+
+// Ϣ
+class EKeyPressListener :
+ public EKeyboardListener
+{
+public:
+ EKeyPressListener();
+
+ EKeyPressListener(
+ EString name
+ );
+
+ EKeyPressListener(
+ const KEY_LISTENER_CALLBACK &callback
+ );
+
+ EKeyPressListener(
+ EString name,
+ const KEY_LISTENER_CALLBACK &callback
+ );
+
+ // ִмص
+ virtual void runCallback() override;
+};
+
+
+// Ϣ
+class EMsgManager
+{
+ friend EApp;
+
+public:
+ // Ϣ
+ static void bindListenerWithScene(
+ EMouseListener * listener,
+ EScene * pParentScene
+ );
+
+ // Ϣ
+ static void bindListenerWithScene(
+ EKeyboardListener * listener,
+ EScene * pParentScene
+ );
+
+ // ͬƵļ
+ static void startListener(
+ EString name
+ );
+
+ // ֹͣͬƵļ
+ static void stopListener(
+ EString name
+ );
+
+ // ɾͬƵļ
+ static void delListener(
+ EString name
+ );
+
+ // Ϣ
+ static void startAllMouseListener();
+
+ // ֹͣϢ
+ static void stopAllMouseListener();
+
+ // Ϣ
+ static void clearAllMouseListeners();
+
+ // аϢ
+ static void startAllKeyboardListener();
+
+ // ֹͣаϢ
+ static void stopAllKeyboardListener();
+
+ // аϢ
+ static void clearAllKeyboardListeners();
+
+ // ڳϵϢ
+ static void startAllMouseListenersBindWithScene(
+ EScene * pParentScene
+ );
+
+ // ڳϵϢ
+ static void stopAllMouseListenersBindWithScene(
+ EScene * pParentScene
+ );
+
+ // ڳϵаϢ
+ static void startAllKeyboardListenersBindWithScene(
+ EScene * pParentScene
+ );
+
+ // ڳϵаϢ
+ static void stopAllKeyboardListenersBindWithScene(
+ EScene * pParentScene
+ );
+
+ // ڳϵм
+ static void waitAllListenersBindWithScene(
+ EScene * pParentScene
+ );
+
+ // ڳϵм
+ static void notifyAllListenersBindWithScene(
+ EScene * pParentScene
+ );
+
+ // հڳϵм
+ static void clearAllListenersBindWithScene(
+ EScene * pParentScene
+ );
+
+ // ڽڵϵм
+ static void waitAllListenersBindWithNode(
+ ENode * pParentNode
+ );
+
+ // ڽڵϵм
+ static void notifyAllListenersBindWithNode(
+ ENode * pParentNode
+ );
+
+ // հڽڵϵм
+ static void clearAllListenersBindWithNode(
+ ENode * pParentNode
+ );
+
+private:
+ static void MouseProc(
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam
+ );
+
+ static void KeyboardProc(
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam
+ );
+};
+
}
\ No newline at end of file
diff --git a/Easy2D/enodes.h b/Easy2D/enodes.h
index a19b6782..ba3a8d86 100644
--- a/Easy2D/enodes.h
+++ b/Easy2D/enodes.h
@@ -4,6 +4,9 @@
namespace e2d
{
+class EScene;
+class EObject;
+
class ENode :
public EObject
{
@@ -144,7 +147,7 @@ public:
);
// ýڵڳ
- void setParentScene(
+ void bindWithScene(
EScene * scene
);
diff --git a/Easy2D/etools.h b/Easy2D/etools.h
index 37f0d50d..c1559737 100644
--- a/Easy2D/etools.h
+++ b/Easy2D/etools.h
@@ -10,7 +10,7 @@ class EObjectManager
friend EApp;
public:
- // һڵͷų
+ // һڵڴ
static void add(
e2d::EObject * nptr
);
@@ -18,9 +18,19 @@ public:
// ɾнڵ
static void clearAllObjects();
+ // ֪ͨڴˢ
+ static void notifyFlush();
+
private:
// ˢڴ
static void __flush();
};
+
+// ʱ
+class ETimerManager
+{
+
+};
+
}
\ No newline at end of file