添加了Geometry类;重整了监听器和定时器的绑定。
This commit is contained in:
		
							parent
							
								
									3f892d23a8
								
							
						
					
					
						commit
						508a3e0fab
					
				|  | @ -1,7 +1,6 @@ | |||
| #include "..\ebase.h" | ||||
| #include "..\Win\winbase.h" | ||||
| #include "..\emsg.h" | ||||
| #include "..\etools.h" | ||||
| #include "..\emanagers.h" | ||||
| #include "..\enodes.h" | ||||
| #include "..\etransitions.h" | ||||
| #include <stack> | ||||
|  | @ -75,7 +74,7 @@ bool e2d::EApp::init(const EString &title, UINT32 width, UINT32 height, EWindowS | |||
| 		// 注册窗口类
 | ||||
| 		WNDCLASSEX wcex = { sizeof(WNDCLASSEX) }; | ||||
| 		UINT style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; | ||||
| 		if (wStyle.NO_CLOSE) | ||||
| 		if (wStyle.m_bNoClose) | ||||
| 		{ | ||||
| 			style |= CS_NOCLOSE; | ||||
| 		} | ||||
|  | @ -88,9 +87,9 @@ bool e2d::EApp::init(const EString &title, UINT32 width, UINT32 height, EWindowS | |||
| 		wcex.lpszMenuName = NULL; | ||||
| 		wcex.hCursor = LoadCursor(NULL, IDI_APPLICATION); | ||||
| 		wcex.lpszClassName = L"Easy2DApp"; | ||||
| 		if (wStyle.ICON_ID) | ||||
| 		if (wStyle.m_pIconID) | ||||
| 		{ | ||||
| 			wcex.hIcon = (HICON)::LoadImage(GetModuleHandle(NULL), wStyle.ICON_ID, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE); | ||||
| 			wcex.hIcon = (HICON)::LoadImage(GetModuleHandle(NULL), wStyle.m_pIconID, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_DEFAULTSIZE); | ||||
| 		} | ||||
| 
 | ||||
| 		RegisterClassEx(&wcex); | ||||
|  | @ -117,12 +116,12 @@ bool e2d::EApp::init(const EString &title, UINT32 width, UINT32 height, EWindowS | |||
| 		 | ||||
| 		// 创建窗口样式
 | ||||
| 		DWORD dwStyle = WS_OVERLAPPED | WS_SYSMENU; | ||||
| 		if (!wStyle.NO_MINI_SIZE) | ||||
| 		if (!wStyle.m_bNoMiniSize) | ||||
| 		{ | ||||
| 			dwStyle |= WS_MINIMIZEBOX; | ||||
| 		} | ||||
| 		// 保存窗口是否置顶显示
 | ||||
| 		m_bTopMost = wStyle.TOP_MOST; | ||||
| 		m_bTopMost = wStyle.m_bTopMost; | ||||
| 		// 保存窗口名称
 | ||||
| 		m_sTitle = title; | ||||
| 		// 创建窗口
 | ||||
|  | @ -366,7 +365,7 @@ void e2d::EApp::_onRender() | |||
| 		// 开始绘图
 | ||||
| 		GetRenderTarget()->BeginDraw(); | ||||
| 		// 使用背景色清空屏幕
 | ||||
| 		GetRenderTarget()->Clear(D2D1::ColorF(m_ClearColor.value)); | ||||
| 		GetRenderTarget()->Clear(D2D1::ColorF(m_ClearColor)); | ||||
| 		// 绘制当前场景
 | ||||
| 		if (m_pCurrentScene) | ||||
| 		{ | ||||
|  | @ -528,7 +527,7 @@ e2d::EString e2d::EApp::getAppName() | |||
| 	return s_pInstance->m_sAppName; | ||||
| } | ||||
| 
 | ||||
| void e2d::EApp::setBkColor(EColor color) | ||||
| void e2d::EApp::setBkColor(UINT32 color) | ||||
| { | ||||
| 	get()->m_ClearColor = color; | ||||
| } | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| #include "..\ebase.h" | ||||
| #include "..\etools.h" | ||||
| #include "..\emanagers.h" | ||||
| 
 | ||||
| e2d::EObject::EObject() | ||||
| 	: m_nRefCount(0) | ||||
|  |  | |||
|  | @ -1,7 +1,8 @@ | |||
| #include "..\ebase.h" | ||||
| #include "..\enodes.h" | ||||
| #include "..\emsg.h" | ||||
| #include "..\emanagers.h" | ||||
| #include "..\etools.h" | ||||
| #include "..\eactions.h" | ||||
| #include <algorithm> | ||||
| 
 | ||||
| e2d::EScene::EScene() | ||||
|  | @ -17,9 +18,6 @@ e2d::EScene::EScene() | |||
| 
 | ||||
| e2d::EScene::~EScene() | ||||
| { | ||||
| 	ETimerManager::_clearAllTimersBindedWith(this); | ||||
| 	EMsgManager::_clearAllMouseListenersBindedWith(this); | ||||
| 	EMsgManager::_clearAllKeyboardListenersBindedWith(this); | ||||
| 	SafeReleaseAndClear(&m_pRoot); | ||||
| } | ||||
| 
 | ||||
|  | @ -91,6 +89,11 @@ void e2d::EScene::clearAllChildren() | |||
| 	m_pRoot->clearAllChildren(); | ||||
| } | ||||
| 
 | ||||
| void e2d::EScene::runAction(EAction * action) | ||||
| { | ||||
| 	this->m_pRoot->runAction(action); | ||||
| } | ||||
| 
 | ||||
| void e2d::EScene::bindListener(EMouseListener * listener) | ||||
| { | ||||
| 	EMsgManager::bindListener(listener, this); | ||||
|  |  | |||
|  | @ -0,0 +1,59 @@ | |||
| #include "..\ecommon.h" | ||||
| 
 | ||||
| static e2d::EKeyboardMsg s_KeyboardMsg; | ||||
| 
 | ||||
| e2d::EKeyboardMsg::KEYBOARD_MSG e2d::EKeyboardMsg::getMsg() | ||||
| { | ||||
| 	return KEYBOARD_MSG(s_KeyboardMsg.m_nMsg); | ||||
| } | ||||
| 
 | ||||
| e2d::EKeyboardMsg::KEY e2d::EKeyboardMsg::getVal() | ||||
| { | ||||
| 	return KEY(s_KeyboardMsg.m_wParam); | ||||
| } | ||||
| 
 | ||||
| DWORD e2d::EKeyboardMsg::getCount() | ||||
| { | ||||
| 	return (((DWORD)s_KeyboardMsg.m_lParam) & 0x0000FFFF); | ||||
| } | ||||
| 
 | ||||
| bool e2d::EKeyboardMsg::isKeyDown(KEY key) | ||||
| { | ||||
| 	if (::GetAsyncKeyState((int)key) & 0x8000) | ||||
| 	{ | ||||
| 		return true; | ||||
| 	} | ||||
| 	return false; | ||||
| } | ||||
| 
 | ||||
| bool e2d::EKeyboardMsg::isCapitalLockOn() | ||||
| { | ||||
| 	if (::GetKeyState(VK_CAPITAL) & 0x0001) | ||||
| 	{ | ||||
| 		return true; | ||||
| 	} | ||||
| 	return false; | ||||
| } | ||||
| 
 | ||||
| bool e2d::EKeyboardMsg::isNumpadLockOn() | ||||
| { | ||||
| 	if (::GetKeyState(VK_NUMLOCK) & 0x0001) | ||||
| 	{ | ||||
| 		return true; | ||||
| 	} | ||||
| 	return false; | ||||
| } | ||||
| 
 | ||||
| bool e2d::EKeyboardMsg::isScrollLockOn() | ||||
| { | ||||
| 	if (::GetKeyState(VK_SCROLL) & 0x0001) | ||||
| 	{ | ||||
| 		return true; | ||||
| 	} | ||||
| 	return false; | ||||
| } | ||||
| 
 | ||||
| e2d::EKeyboardMsg & e2d::EKeyboardMsg::getKeyboardMsg() | ||||
| { | ||||
| 	return s_KeyboardMsg; | ||||
| } | ||||
|  | @ -0,0 +1,58 @@ | |||
| #include "..\ecommon.h" | ||||
| 
 | ||||
| static e2d::EMouseMsg s_MouseMsg; | ||||
| 
 | ||||
| DWORD e2d::EMouseMsg::getPosX() | ||||
| { | ||||
| 	return LOWORD(s_MouseMsg.m_lParam); | ||||
| } | ||||
| 
 | ||||
| DWORD e2d::EMouseMsg::getPosY() | ||||
| { | ||||
| 	return HIWORD(s_MouseMsg.m_lParam); | ||||
| } | ||||
| 
 | ||||
| e2d::EPoint e2d::EMouseMsg::getPos() | ||||
| { | ||||
| 	return EPoint(LOWORD(s_MouseMsg.m_lParam), HIWORD(s_MouseMsg.m_lParam)); | ||||
| } | ||||
| 
 | ||||
| bool e2d::EMouseMsg::isLButtonDown() | ||||
| { | ||||
| 	return GET_KEYSTATE_WPARAM(s_MouseMsg.m_wParam) == MK_LBUTTON; | ||||
| } | ||||
| 
 | ||||
| bool e2d::EMouseMsg::isMButtonDown() | ||||
| { | ||||
| 	return GET_KEYSTATE_WPARAM(s_MouseMsg.m_wParam) == MK_MBUTTON; | ||||
| } | ||||
| 
 | ||||
| bool e2d::EMouseMsg::isRButtonDown() | ||||
| { | ||||
| 	return GET_KEYSTATE_WPARAM(s_MouseMsg.m_wParam) == MK_RBUTTON; | ||||
| } | ||||
| 
 | ||||
| bool e2d::EMouseMsg::isShiftDown() | ||||
| { | ||||
| 	return GET_KEYSTATE_WPARAM(s_MouseMsg.m_wParam) == MK_SHIFT; | ||||
| } | ||||
| 
 | ||||
| bool e2d::EMouseMsg::isCtrlDown() | ||||
| { | ||||
| 	return GET_KEYSTATE_WPARAM(s_MouseMsg.m_wParam) == MK_CONTROL; | ||||
| } | ||||
| 
 | ||||
| DWORD e2d::EMouseMsg::getWheelDelta() | ||||
| { | ||||
| 	return GET_WHEEL_DELTA_WPARAM(s_MouseMsg.m_wParam); | ||||
| } | ||||
| 
 | ||||
| e2d::EMouseMsg::MOUSE_MSG e2d::EMouseMsg::getMsg() | ||||
| { | ||||
| 	return MOUSE_MSG(s_MouseMsg.m_nMsg); | ||||
| } | ||||
| 
 | ||||
| e2d::EMouseMsg & e2d::EMouseMsg::getMouseMsg() | ||||
| { | ||||
| 	return s_MouseMsg; | ||||
| } | ||||
|  | @ -210,6 +210,13 @@ | |||
|     <ClCompile Include="Base\EApp.cpp" /> | ||||
|     <ClCompile Include="Base\EObject.cpp" /> | ||||
|     <ClCompile Include="Base\EScene.cpp" /> | ||||
|     <ClCompile Include="Common\EKeyboardMsg.cpp" /> | ||||
|     <ClCompile Include="Common\EMouseMsg.cpp" /> | ||||
|     <ClCompile Include="Geometry\ECircle.cpp" /> | ||||
|     <ClCompile Include="Geometry\EEllipse.cpp" /> | ||||
|     <ClCompile Include="Geometry\EGeometry.cpp" /> | ||||
|     <ClCompile Include="Geometry\ERectangle.cpp" /> | ||||
|     <ClCompile Include="Listener\ECollisionListener.cpp" /> | ||||
|     <ClCompile Include="Listener\EKeyboardListener.cpp" /> | ||||
|     <ClCompile Include="Listener\EKeyboardPressListener.cpp" /> | ||||
|     <ClCompile Include="Listener\EListener.cpp" /> | ||||
|  | @ -221,6 +228,7 @@ | |||
|     <ClCompile Include="Manager\EActionManager.cpp" /> | ||||
|     <ClCompile Include="Manager\EMsgManager.cpp" /> | ||||
|     <ClCompile Include="Manager\EObjectManager.cpp" /> | ||||
|     <ClCompile Include="Manager\EPhysicsManager.cpp" /> | ||||
|     <ClCompile Include="Manager\ETimerManager.cpp" /> | ||||
|     <ClCompile Include="Node\EButton.cpp" /> | ||||
|     <ClCompile Include="Node\ENode.cpp" /> | ||||
|  | @ -245,8 +253,10 @@ | |||
|     <ClInclude Include="easy2d.h" /> | ||||
|     <ClInclude Include="ebase.h" /> | ||||
|     <ClInclude Include="ecommon.h" /> | ||||
|     <ClInclude Include="egeometry.h" /> | ||||
|     <ClInclude Include="elisteners.h" /> | ||||
|     <ClInclude Include="emacros.h" /> | ||||
|     <ClInclude Include="emsg.h" /> | ||||
|     <ClInclude Include="emanagers.h" /> | ||||
|     <ClInclude Include="enodes.h" /> | ||||
|     <ClInclude Include="etools.h" /> | ||||
|     <ClInclude Include="etransitions.h" /> | ||||
|  |  | |||
|  | @ -25,6 +25,12 @@ | |||
|     <Filter Include="Listener"> | ||||
|       <UniqueIdentifier>{b9bb1728-5106-4574-998e-8564b49cb4a1}</UniqueIdentifier> | ||||
|     </Filter> | ||||
|     <Filter Include="Geometry"> | ||||
|       <UniqueIdentifier>{d5f86335-f3a0-450d-92a3-7edd9348d995}</UniqueIdentifier> | ||||
|     </Filter> | ||||
|     <Filter Include="Common"> | ||||
|       <UniqueIdentifier>{be5d9314-b00a-4f11-bd2a-1f720dc32407}</UniqueIdentifier> | ||||
|     </Filter> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClCompile Include="Win\winbase.cpp"> | ||||
|  | @ -174,6 +180,30 @@ | |||
|     <ClCompile Include="Tool\EMusicUtils.cpp"> | ||||
|       <Filter>Tool</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="Geometry\ERectangle.cpp"> | ||||
|       <Filter>Geometry</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="Geometry\EGeometry.cpp"> | ||||
|       <Filter>Geometry</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="Geometry\ECircle.cpp"> | ||||
|       <Filter>Geometry</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="Geometry\EEllipse.cpp"> | ||||
|       <Filter>Geometry</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="Listener\ECollisionListener.cpp"> | ||||
|       <Filter>Listener</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="Common\EMouseMsg.cpp"> | ||||
|       <Filter>Common</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="Common\EKeyboardMsg.cpp"> | ||||
|       <Filter>Common</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="Manager\EPhysicsManager.cpp"> | ||||
|       <Filter>Manager</Filter> | ||||
|     </ClCompile> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClInclude Include="Win\winbase.h"> | ||||
|  | @ -185,8 +215,10 @@ | |||
|     <ClInclude Include="ecommon.h" /> | ||||
|     <ClInclude Include="ebase.h" /> | ||||
|     <ClInclude Include="easy2d.h" /> | ||||
|     <ClInclude Include="emsg.h" /> | ||||
|     <ClInclude Include="eactions.h" /> | ||||
|     <ClInclude Include="etransitions.h" /> | ||||
|     <ClInclude Include="egeometry.h" /> | ||||
|     <ClInclude Include="elisteners.h" /> | ||||
|     <ClInclude Include="emanagers.h" /> | ||||
|   </ItemGroup> | ||||
| </Project> | ||||
|  | @ -0,0 +1,32 @@ | |||
| #include "..\egeometry.h" | ||||
| #include "..\Win\winbase.h" | ||||
| 
 | ||||
| e2d::ECircle::ECircle() | ||||
| { | ||||
| 	this->_setCircle(EPoint(), 0); | ||||
| } | ||||
| 
 | ||||
| e2d::ECircle::ECircle(EPoint center, float radius) | ||||
| { | ||||
| 	this->_setCircle(center, radius); | ||||
| } | ||||
| 
 | ||||
| void e2d::ECircle::_setCircle(EPoint center, float radius) | ||||
| { | ||||
| 	SafeReleaseInterface(&m_pD2dCircle); | ||||
| 
 | ||||
| 	GetFactory()->CreateEllipseGeometry( | ||||
| 		D2D1::Ellipse( | ||||
| 			D2D1::Point2F( | ||||
| 				center.x,  | ||||
| 				center.y), | ||||
| 			radius, | ||||
| 			radius), | ||||
| 			&m_pD2dCircle | ||||
| 		); | ||||
| } | ||||
| 
 | ||||
| ID2D1EllipseGeometry * e2d::ECircle::_getD2dGeometry() const | ||||
| { | ||||
| 	return m_pD2dCircle; | ||||
| } | ||||
|  | @ -0,0 +1,32 @@ | |||
| #include "..\egeometry.h" | ||||
| #include "..\Win\winbase.h" | ||||
| 
 | ||||
| e2d::EEllipse::EEllipse() | ||||
| { | ||||
| 	this->_setEllipse(EPoint(), 0, 0); | ||||
| } | ||||
| 
 | ||||
| e2d::EEllipse::EEllipse(EPoint center, float radiusX, float radiusY) | ||||
| { | ||||
| 	this->_setEllipse(center, radiusX, radiusY); | ||||
| } | ||||
| 
 | ||||
| void e2d::EEllipse::_setEllipse(EPoint center, float radiusX, float radiusY) | ||||
| { | ||||
| 	SafeReleaseInterface(&m_pD2dEllipse); | ||||
| 
 | ||||
| 	GetFactory()->CreateEllipseGeometry( | ||||
| 		D2D1::Ellipse( | ||||
| 			D2D1::Point2F( | ||||
| 				center.x, | ||||
| 				center.y), | ||||
| 			radiusX, | ||||
| 			radiusY), | ||||
| 		&m_pD2dEllipse | ||||
| 	); | ||||
| } | ||||
| 
 | ||||
| ID2D1EllipseGeometry * e2d::EEllipse::_getD2dGeometry() const | ||||
| { | ||||
| 	return m_pD2dEllipse; | ||||
| } | ||||
|  | @ -0,0 +1,28 @@ | |||
| #include "..\egeometry.h" | ||||
| #include "..\Win\winbase.h" | ||||
| 
 | ||||
| e2d::EGeometry::EGeometry() | ||||
| 	: m_bTransformed(true) | ||||
| 	, m_pParentNode(nullptr) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| bool e2d::EGeometry::_isCollisionWith(EGeometry * pGeometry) | ||||
| { | ||||
| 	D2D1_GEOMETRY_RELATION relation; | ||||
| 
 | ||||
| 	HRESULT	hr = this->_getD2dGeometry()->CompareWithGeometry( | ||||
| 		pGeometry->_getD2dGeometry(), | ||||
| 		D2D1::Matrix3x2F::Identity(), | ||||
| 		&relation | ||||
| 	); | ||||
| 
 | ||||
| 	if (SUCCEEDED(hr)) | ||||
| 	{ | ||||
| 		return (relation == D2D1_GEOMETRY_RELATION::D2D1_GEOMETRY_RELATION_OVERLAP) ||  | ||||
| 			(relation == D2D1_GEOMETRY_RELATION::D2D1_GEOMETRY_RELATION_CONTAINS) || | ||||
| 			(relation == D2D1_GEOMETRY_RELATION::D2D1_GEOMETRY_RELATION_IS_CONTAINED); | ||||
| 	} | ||||
| 
 | ||||
| 	return false; | ||||
| } | ||||
|  | @ -0,0 +1,43 @@ | |||
| #include "..\egeometry.h" | ||||
| #include "..\enodes.h" | ||||
| #include "..\Win\winbase.h" | ||||
| 
 | ||||
| e2d::ERectangle::ERectangle() | ||||
| { | ||||
| 	this->_setRect(0, 0, 0, 0); | ||||
| } | ||||
| 
 | ||||
| e2d::ERectangle::ERectangle(float x, float y, float width, float height) | ||||
| { | ||||
| 	this->_setRect(x, y, x + width, y + height); | ||||
| } | ||||
| 
 | ||||
| e2d::ERectangle::ERectangle(ENode * node) | ||||
| { | ||||
| 	// ¼ÆËã×óÉϽÇ×ø±ê
 | ||||
| 	D2D1_POINT_2F upperLeftCorner = D2D1::Point2F( | ||||
| 		node->getPosX() - node->getRealWidth() * node->getAnchorX(), | ||||
| 		node->getPosY() - node->getRealHeight() * node->getAnchorY() | ||||
| 	); | ||||
| 	this->_setRect( | ||||
| 		upperLeftCorner.x, | ||||
| 		upperLeftCorner.y, | ||||
| 		upperLeftCorner.x + node->getRealWidth(), | ||||
| 		upperLeftCorner.y + node->getRealHeight() | ||||
| 	); | ||||
| } | ||||
| 
 | ||||
| void e2d::ERectangle::_setRect(float left, float top, float right, float bottom) | ||||
| { | ||||
| 	SafeReleaseInterface(&m_pD2dRectangle); | ||||
| 
 | ||||
| 	GetFactory()->CreateRectangleGeometry( | ||||
| 		D2D1::RectF(left, top, right, bottom), | ||||
| 		&m_pD2dRectangle | ||||
| 	); | ||||
| } | ||||
| 
 | ||||
| ID2D1RectangleGeometry * e2d::ERectangle::_getD2dGeometry() const | ||||
| { | ||||
| 	return m_pD2dRectangle; | ||||
| } | ||||
|  | @ -1,4 +1,5 @@ | |||
| #include "..\emsg.h" | ||||
| #include "..\elisteners.h" | ||||
| #include "..\emanagers.h" | ||||
| 
 | ||||
| e2d::EKeyboardListener::EKeyboardListener() | ||||
| 	: EListener() | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\emsg.h" | ||||
| #include "..\elisteners.h" | ||||
| 
 | ||||
| e2d::EKeyboardPressListener::EKeyboardPressListener() | ||||
| 	: EKeyboardListener() | ||||
|  |  | |||
|  | @ -1,9 +1,8 @@ | |||
| #include "..\emsg.h" | ||||
| #include "..\elisteners.h" | ||||
| 
 | ||||
| e2d::EListener::EListener() | ||||
| 	: m_bRunning(false) | ||||
| 	, m_bAlways(false) | ||||
| 	, m_pParentScene(nullptr) | ||||
| 	, m_pParentNode(nullptr) | ||||
| { | ||||
| } | ||||
|  | @ -34,11 +33,6 @@ e2d::EString e2d::EListener::getName() const | |||
| 	return m_sName; | ||||
| } | ||||
| 
 | ||||
| e2d::EScene * e2d::EListener::getParentScene() const | ||||
| { | ||||
| 	return m_pParentScene; | ||||
| } | ||||
| 
 | ||||
| e2d::ENode * e2d::EListener::getParentNode() const | ||||
| { | ||||
| 	return m_pParentNode; | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\emsg.h" | ||||
| #include "..\elisteners.h" | ||||
| 
 | ||||
| e2d::EMouseClickListener::EMouseClickListener() | ||||
| 	: EMouseListener() | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\emsg.h" | ||||
| #include "..\elisteners.h" | ||||
| 
 | ||||
| e2d::EMouseDoubleClickListener::EMouseDoubleClickListener() | ||||
| 	: EMouseListener() | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\emsg.h" | ||||
| #include "..\elisteners.h" | ||||
| 
 | ||||
| e2d::EMouseDragListener::EMouseDragListener() | ||||
| 	: EMouseListener() | ||||
|  |  | |||
|  | @ -1,4 +1,5 @@ | |||
| #include "..\emsg.h" | ||||
| #include "..\elisteners.h" | ||||
| #include "..\emanagers.h" | ||||
| 
 | ||||
| e2d::EMouseListener::EMouseListener() | ||||
| 	: EListener() | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\emsg.h" | ||||
| #include "..\elisteners.h" | ||||
| 
 | ||||
| e2d::EMousePressListener::EMousePressListener() | ||||
| 	: EMouseListener() | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "..\etools.h" | ||||
| #include "..\emanagers.h" | ||||
| #include "..\eactions.h" | ||||
| #include "..\Win\winbase.h" | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,12 +1,9 @@ | |||
| #include "..\emsg.h" | ||||
| #include "..\emanagers.h" | ||||
| #include "..\elisteners.h" | ||||
| #include "..\enodes.h" | ||||
| #include "..\Win\winbase.h" | ||||
| 
 | ||||
| 
 | ||||
| // Êó±êÏûÏ¢
 | ||||
| e2d::EMouseMsg s_MouseMsg; | ||||
| // °´¼üÏûÏ¢
 | ||||
| e2d::EKeyboardMsg s_KeyboardMsg; | ||||
| // 鼠标消息监听器
 | ||||
| e2d::EVector<e2d::EMouseListener*> s_vMouseListeners; | ||||
| // 按键消息监听器
 | ||||
|  | @ -16,9 +13,9 @@ e2d::EVector<e2d::EKeyboardListener*> s_vKeyboardListeners; | |||
| void e2d::EMsgManager::MouseProc(UINT message, WPARAM wParam, LPARAM lParam) | ||||
| { | ||||
| 	// 保存鼠标消息
 | ||||
| 	s_MouseMsg.m_nMsg = message; | ||||
| 	s_MouseMsg.m_wParam = wParam; | ||||
| 	s_MouseMsg.m_lParam = lParam; | ||||
| 	EMouseMsg::getMouseMsg().m_nMsg = message; | ||||
| 	EMouseMsg::getMouseMsg().m_wParam = wParam; | ||||
| 	EMouseMsg::getMouseMsg().m_lParam = lParam; | ||||
| 	// 执行鼠标消息监听函数
 | ||||
| 	for (size_t i = 0; i < s_vMouseListeners.size(); i++) | ||||
| 	{ | ||||
|  | @ -29,8 +26,8 @@ void e2d::EMsgManager::MouseProc(UINT message, WPARAM wParam, LPARAM lParam) | |||
| 
 | ||||
| 		if (mlistener->isRunning()) | ||||
| 		{ | ||||
| 			if (mlistener->getParentScene() == EApp::getCurrentScene() || | ||||
| 				(mlistener->getParentNode() && mlistener->getParentNode()->getParentScene() == EApp::getCurrentScene())) | ||||
| 			if (mlistener->getParentNode() &&  | ||||
| 				mlistener->getParentNode()->getParentScene() == EApp::getCurrentScene()) | ||||
| 			{ | ||||
| 				mlistener->_callOn(); | ||||
| 			} | ||||
|  | @ -41,9 +38,9 @@ void e2d::EMsgManager::MouseProc(UINT message, WPARAM wParam, LPARAM lParam) | |||
| void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam) | ||||
| { | ||||
| 	// 保存按键消息
 | ||||
| 	s_KeyboardMsg.m_nMsg = message; | ||||
| 	s_KeyboardMsg.m_wParam = wParam; | ||||
| 	s_KeyboardMsg.m_lParam = lParam; | ||||
| 	EKeyboardMsg::getKeyboardMsg().m_nMsg = message; | ||||
| 	EKeyboardMsg::getKeyboardMsg().m_wParam = wParam; | ||||
| 	EKeyboardMsg::getKeyboardMsg().m_lParam = lParam; | ||||
| 	// 执行按键消息监听函数
 | ||||
| 	for (size_t i = 0; i < s_vKeyboardListeners.size(); i++) | ||||
| 	{ | ||||
|  | @ -54,8 +51,8 @@ void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam) | |||
| 
 | ||||
| 		if (klistener->isRunning()) | ||||
| 		{ | ||||
| 			if (klistener->getParentScene() == EApp::getCurrentScene() || | ||||
| 				(klistener->getParentNode() && klistener->getParentNode()->getParentScene() == EApp::getCurrentScene())) | ||||
| 			if (klistener->getParentNode() &&  | ||||
| 				klistener->getParentNode()->getParentScene() == EApp::getCurrentScene()) | ||||
| 			{ | ||||
| 				klistener->_callOn(); | ||||
| 			} | ||||
|  | @ -63,159 +60,28 @@ void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam) | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| DWORD e2d::EMouseMsg::getPosX() | ||||
| { | ||||
| 	return LOWORD(s_MouseMsg.m_lParam); | ||||
| } | ||||
| 
 | ||||
| DWORD e2d::EMouseMsg::getPosY() | ||||
| { | ||||
| 	return HIWORD(s_MouseMsg.m_lParam); | ||||
| } | ||||
| 
 | ||||
| e2d::EPoint e2d::EMouseMsg::getPos() | ||||
| { | ||||
| 	return EPoint(LOWORD(s_MouseMsg.m_lParam), HIWORD(s_MouseMsg.m_lParam)); | ||||
| } | ||||
| 
 | ||||
| bool e2d::EMouseMsg::isLButtonDown() | ||||
| { | ||||
| 	return GET_KEYSTATE_WPARAM(s_MouseMsg.m_wParam) == MK_LBUTTON; | ||||
| } | ||||
| 
 | ||||
| bool e2d::EMouseMsg::isMButtonDown() | ||||
| { | ||||
| 	return GET_KEYSTATE_WPARAM(s_MouseMsg.m_wParam) == MK_MBUTTON; | ||||
| } | ||||
| 
 | ||||
| bool e2d::EMouseMsg::isRButtonDown() | ||||
| { | ||||
| 	return GET_KEYSTATE_WPARAM(s_MouseMsg.m_wParam) == MK_RBUTTON; | ||||
| } | ||||
| 
 | ||||
| bool e2d::EMouseMsg::isShiftDown() | ||||
| { | ||||
| 	return GET_KEYSTATE_WPARAM(s_MouseMsg.m_wParam) == MK_SHIFT; | ||||
| } | ||||
| 
 | ||||
| bool e2d::EMouseMsg::isCtrlDown() | ||||
| { | ||||
| 	return GET_KEYSTATE_WPARAM(s_MouseMsg.m_wParam) == MK_CONTROL; | ||||
| } | ||||
| 
 | ||||
| DWORD e2d::EMouseMsg::getWheelDelta() | ||||
| { | ||||
| 	return GET_WHEEL_DELTA_WPARAM(s_MouseMsg.m_wParam); | ||||
| } | ||||
| 
 | ||||
| e2d::EMouseMsg::MOUSE_MSG e2d::EMouseMsg::getMsg() | ||||
| { | ||||
| 	return MOUSE_MSG(s_MouseMsg.m_nMsg); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| e2d::EKeyboardMsg::KEYBOARD_MSG e2d::EKeyboardMsg::getMsg() | ||||
| { | ||||
| 	return KEYBOARD_MSG(s_KeyboardMsg.m_nMsg); | ||||
| } | ||||
| 
 | ||||
| e2d::EKeyboardMsg::KEY e2d::EKeyboardMsg::getVal() | ||||
| { | ||||
| 	return KEY(s_KeyboardMsg.m_wParam); | ||||
| } | ||||
| 
 | ||||
| DWORD e2d::EKeyboardMsg::getCount() | ||||
| { | ||||
| 	return (((DWORD)s_KeyboardMsg.m_lParam) & 0x0000FFFF); | ||||
| } | ||||
| 
 | ||||
| bool e2d::EKeyboardMsg::isKeyDown(KEY key) | ||||
| { | ||||
| 	if (::GetAsyncKeyState((int)key) & 0x8000) | ||||
| 	{ | ||||
| 		return true; | ||||
| 	} | ||||
| 	return false; | ||||
| } | ||||
| 
 | ||||
| bool e2d::EKeyboardMsg::isCapitalLockOn() | ||||
| { | ||||
| 	if (::GetKeyState(VK_CAPITAL) & 0x0001) | ||||
| 	{ | ||||
| 		return true; | ||||
| 	} | ||||
| 	return false; | ||||
| } | ||||
| 
 | ||||
| bool e2d::EKeyboardMsg::isNumpadLockOn() | ||||
| { | ||||
| 	if (::GetKeyState(VK_NUMLOCK) & 0x0001) | ||||
| 	{ | ||||
| 		return true; | ||||
| 	} | ||||
| 	return false; | ||||
| } | ||||
| 
 | ||||
| bool e2d::EKeyboardMsg::isScrollLockOn() | ||||
| { | ||||
| 	if (::GetKeyState(VK_SCROLL) & 0x0001) | ||||
| 	{ | ||||
| 		return true; | ||||
| 	} | ||||
| 	return false; | ||||
| } | ||||
| 
 | ||||
| void e2d::EMsgManager::bindListener(e2d::EMouseListener * listener, EScene * pParentScene, bool always /* = false */) | ||||
| { | ||||
| 	ASSERT( | ||||
| 		(!listener->m_pParentNode) && (!listener->m_pParentScene), | ||||
| 		"The listener is already binded, it cannot bind again!" | ||||
| 	); | ||||
| 	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->m_pParentScene = pParentScene; | ||||
| 		listener->m_bAlways = always; | ||||
| 		s_vMouseListeners.push_back(listener); | ||||
| 	} | ||||
| 	EMsgManager::bindListener(listener, pParentScene->getRoot(), always); | ||||
| } | ||||
| 
 | ||||
| void e2d::EMsgManager::bindListener(EKeyboardListener * listener, EScene * pParentScene, bool always /* = false */) | ||||
| { | ||||
| 	ASSERT( | ||||
| 		(!listener->m_pParentNode) && (!listener->m_pParentScene), | ||||
| 		"The listener is already binded, it cannot bind again!" | ||||
| 	); | ||||
| 	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->m_pParentScene = pParentScene; | ||||
| 		listener->m_bAlways = always; | ||||
| 		s_vKeyboardListeners.push_back(listener); | ||||
| 	} | ||||
| 	EMsgManager::bindListener(listener, pParentScene->getRoot(), always); | ||||
| } | ||||
| 
 | ||||
| void e2d::EMsgManager::bindListener(EMouseListener * listener, ENode * pParentNode, bool always /* = false */) | ||||
| { | ||||
| 	ASSERT( | ||||
| 		(!listener->m_pParentNode) && (!listener->m_pParentScene), | ||||
| 		"The listener is already binded, it cannot bind again!" | ||||
| 	); | ||||
| 	WARN_IF(listener == nullptr, "EMouseListener NULL pointer exception!"); | ||||
| 	WARN_IF(pParentNode == nullptr, "Bind EMouseListener with a NULL ENode pointer!"); | ||||
| 
 | ||||
| 	if (listener && pParentNode) | ||||
| 	{ | ||||
| 		ASSERT( | ||||
| 			!listener->m_pParentNode, | ||||
| 			"The listener is already binded, it cannot bind again!" | ||||
| 		); | ||||
| 
 | ||||
| 		listener->start(); | ||||
| 		listener->retain(); | ||||
| 		listener->m_bAlways = always; | ||||
|  | @ -226,15 +92,16 @@ void e2d::EMsgManager::bindListener(EMouseListener * listener, ENode * pParentNo | |||
| 
 | ||||
| void e2d::EMsgManager::bindListener(EKeyboardListener * listener, ENode * pParentNode, bool always /* = false */) | ||||
| { | ||||
| 	ASSERT( | ||||
| 		(!listener->m_pParentNode) && (!listener->m_pParentScene), | ||||
| 		"The listener is already binded, it cannot bind again!" | ||||
| 	); | ||||
| 	WARN_IF(listener == nullptr, "EKeyboardListener NULL pointer exception!"); | ||||
| 	WARN_IF(pParentNode == nullptr, "Bind EKeyboardListener with a NULL ENode pointer!"); | ||||
| 
 | ||||
| 	if (listener && pParentNode) | ||||
| 	{ | ||||
| 		ASSERT( | ||||
| 			!listener->m_pParentNode, | ||||
| 			"The listener is already binded, it cannot bind again!" | ||||
| 		); | ||||
| 
 | ||||
| 		listener->start(); | ||||
| 		listener->retain(); | ||||
| 		listener->m_pParentNode = pParentNode; | ||||
|  | @ -327,32 +194,12 @@ void e2d::EMsgManager::delKeyboardListeners(const EString & name) | |||
| 
 | ||||
| void e2d::EMsgManager::startAllMouseListenersBindedWith(EScene * pParentScene) | ||||
| { | ||||
| 	for (auto l : s_vMouseListeners) | ||||
| 	{ | ||||
| 		if (l->getParentScene() == pParentScene) | ||||
| 		{ | ||||
| 			l->start(); | ||||
| 		} | ||||
| 	} | ||||
| 	for (auto child : pParentScene->getChildren()) | ||||
| 	{ | ||||
| 		EMsgManager::startAllMouseListenersBindedWith(child); | ||||
| 	} | ||||
| 	EMsgManager::startAllMouseListenersBindedWith(pParentScene->getRoot()); | ||||
| } | ||||
| 
 | ||||
| void e2d::EMsgManager::stopAllMouseListenersBindedWith(EScene * pParentScene) | ||||
| { | ||||
| 	for (auto l : s_vMouseListeners) | ||||
| 	{ | ||||
| 		if (l->getParentScene() == pParentScene) | ||||
| 		{ | ||||
| 			l->stop(); | ||||
| 		} | ||||
| 	} | ||||
| 	for (auto child : pParentScene->getChildren()) | ||||
| 	{ | ||||
| 		EMsgManager::stopAllMouseListenersBindedWith(child); | ||||
| 	} | ||||
| 	EMsgManager::stopAllMouseListenersBindedWith(pParentScene->getRoot()); | ||||
| } | ||||
| 
 | ||||
| void e2d::EMsgManager::startAllMouseListenersBindedWith(ENode * pParentNode) | ||||
|  | @ -387,32 +234,12 @@ void e2d::EMsgManager::stopAllMouseListenersBindedWith(ENode * pParentNode) | |||
| 
 | ||||
| void e2d::EMsgManager::startAllKeyboardListenersBindedWith(EScene * pParentScene) | ||||
| { | ||||
| 	for (auto l : s_vKeyboardListeners) | ||||
| 	{ | ||||
| 		if (l->getParentScene() == pParentScene) | ||||
| 		{ | ||||
| 			l->start(); | ||||
| 		} | ||||
| 	} | ||||
| 	for (auto child : pParentScene->getChildren()) | ||||
| 	{ | ||||
| 		EMsgManager::startAllKeyboardListenersBindedWith(child); | ||||
| 	} | ||||
| 	EMsgManager::startAllKeyboardListenersBindedWith(pParentScene->getRoot()); | ||||
| } | ||||
| 
 | ||||
| void e2d::EMsgManager::stopAllKeyboardListenersBindedWith(EScene * pParentScene) | ||||
| { | ||||
| 	for (auto l : s_vKeyboardListeners) | ||||
| 	{ | ||||
| 		if (l->getParentScene() == pParentScene) | ||||
| 		{ | ||||
| 			l->stop(); | ||||
| 		} | ||||
| 	} | ||||
| 	for (auto child : pParentScene->getChildren()) | ||||
| 	{ | ||||
| 		EMsgManager::stopAllKeyboardListenersBindedWith(child); | ||||
| 	} | ||||
| 	EMsgManager::stopAllKeyboardListenersBindedWith(pParentScene->getRoot()); | ||||
| } | ||||
| 
 | ||||
| void e2d::EMsgManager::startAllKeyboardListenersBindedWith(ENode * pParentNode) | ||||
|  | @ -445,40 +272,6 @@ void e2d::EMsgManager::stopAllKeyboardListenersBindedWith(ENode * pParentNode) | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| void e2d::EMsgManager::_clearAllMouseListenersBindedWith(EScene * pParentScene) | ||||
| { | ||||
| 	for (size_t i = 0; i < s_vMouseListeners.size();) | ||||
| 	{ | ||||
| 		auto t = s_vMouseListeners[i]; | ||||
| 		if (t->getParentScene() == pParentScene) | ||||
| 		{ | ||||
| 			SafeReleaseAndClear(&t); | ||||
| 			s_vMouseListeners.erase(s_vMouseListeners.begin() + i); | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			i++; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void e2d::EMsgManager::_clearAllKeyboardListenersBindedWith(EScene * pParentScene) | ||||
| { | ||||
| 	for (size_t i = 0; i < s_vKeyboardListeners.size();) | ||||
| 	{ | ||||
| 		auto t = s_vKeyboardListeners[i]; | ||||
| 		if (t->getParentScene() == pParentScene) | ||||
| 		{ | ||||
| 			SafeReleaseAndClear(&t); | ||||
| 			s_vKeyboardListeners.erase(s_vKeyboardListeners.begin() + i); | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			i++; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void e2d::EMsgManager::_clearAllMouseListenersBindedWith(ENode * pParentNode) | ||||
| { | ||||
| 	for (size_t i = 0; i < s_vMouseListeners.size();) | ||||
|  |  | |||
|  | @ -1,4 +1,5 @@ | |||
| #include "..\etools.h" | ||||
| #include "..\emanagers.h" | ||||
| #include "..\ebase.h" | ||||
| 
 | ||||
| // EObjectManager 释放池的实现机制:
 | ||||
| // EObject 类中的引用计数(m_nRefCount)保证了指针的使用安全
 | ||||
|  |  | |||
|  | @ -0,0 +1,26 @@ | |||
| #include "..\emanagers.h" | ||||
| #include "..\egeometry.h" | ||||
| 
 | ||||
| e2d::EVector<e2d::EGeometry*> s_vGeometries; | ||||
| 
 | ||||
| void e2d::EPhysicsManager::bindWith(EGeometry * geometry, ENode * node) | ||||
| { | ||||
| 	WARN_IF(geometry == nullptr, "EGeometry NULL pointer exception!"); | ||||
| 	WARN_IF(node == nullptr, "EGeometry add to a NULL ENode pointer!"); | ||||
| 
 | ||||
| 	if (geometry && node) | ||||
| 	{ | ||||
| 		ASSERT( | ||||
| 			!geometry->m_pParentNode, | ||||
| 			"The geometry is already added, it cannot bind again!" | ||||
| 		); | ||||
| 
 | ||||
| 		geometry->retain(); | ||||
| 		geometry->m_pParentNode = node; | ||||
| 		s_vGeometries.push_back(geometry); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void e2d::EPhysicsManager::PhysicsProc() | ||||
| { | ||||
| } | ||||
|  | @ -1,3 +1,4 @@ | |||
| #include "..\emanagers.h" | ||||
| #include "..\etools.h" | ||||
| #include "..\enodes.h" | ||||
| #include "..\Win\winbase.h" | ||||
|  | @ -15,8 +16,8 @@ void e2d::ETimerManager::TimerProc() | |||
| 		auto &t = s_vTimers[i]; | ||||
| 		if (t->isRunning()) | ||||
| 		{ | ||||
| 			if (t->getParentScene() == EApp::getCurrentScene() || | ||||
| 				(t->getParentNode() && (t->getParentNode()->getParentScene() == EApp::getCurrentScene()))) | ||||
| 			if (t->getParentNode() &&  | ||||
| 				t->getParentNode()->getParentScene() == EApp::getCurrentScene()) | ||||
| 			{ | ||||
| 				if (t->_isReady()) | ||||
| 				{ | ||||
|  | @ -29,33 +30,21 @@ void e2d::ETimerManager::TimerProc() | |||
| 
 | ||||
| void e2d::ETimerManager::bindTimer(ETimer * timer, EScene * pParentScene) | ||||
| { | ||||
| 	ASSERT( | ||||
| 		(!timer->m_pParentScene) && (!timer->m_pParentNode), | ||||
| 		"The timer is already binded, it cannot bind again!" | ||||
| 	); | ||||
| 	WARN_IF(timer == nullptr, "ETimer NULL pointer exception!"); | ||||
| 	WARN_IF(pParentScene == nullptr, "Bind ETimer with a NULL EScene pointer!"); | ||||
| 
 | ||||
| 	if (timer && pParentScene) | ||||
| 	{ | ||||
| 		timer->start(); | ||||
| 		timer->retain(); | ||||
| 		timer->m_pParentScene = pParentScene; | ||||
| 		s_vTimers.push_back(timer); | ||||
| 	} | ||||
| 	ETimerManager::bindTimer(timer, pParentScene->getRoot()); | ||||
| } | ||||
| 
 | ||||
| void e2d::ETimerManager::bindTimer(ETimer * timer, ENode * pParentNode) | ||||
| { | ||||
| 	ASSERT( | ||||
| 		(!timer->m_pParentScene) && (!timer->m_pParentNode), | ||||
| 		"The timer is already binded, it cannot bind again!" | ||||
| 	); | ||||
| 	WARN_IF(timer == nullptr, "ETimer NULL pointer exception!"); | ||||
| 	WARN_IF(pParentNode == nullptr, "Bind ETimer with a NULL ENode pointer!"); | ||||
| 
 | ||||
| 	if (timer && pParentNode) | ||||
| 	{ | ||||
| 		ASSERT( | ||||
| 			!timer->m_pParentNode, | ||||
| 			"The timer is already binded, it cannot bind again!" | ||||
| 		); | ||||
| 
 | ||||
| 		timer->start(); | ||||
| 		timer->retain(); | ||||
| 		timer->m_pParentNode = pParentNode; | ||||
|  | @ -104,49 +93,12 @@ void e2d::ETimerManager::delTimers(const EString & name) | |||
| 
 | ||||
| void e2d::ETimerManager::startAllTimersBindedWith(EScene * pParentScene) | ||||
| { | ||||
| 	for (auto t : s_vTimers) | ||||
| 	{ | ||||
| 		if (t->getParentScene() == pParentScene) | ||||
| 		{ | ||||
| 			t->start(); | ||||
| 		} | ||||
| 	} | ||||
| 	for (auto child : pParentScene->getChildren()) | ||||
| 	{ | ||||
| 		ETimerManager::startAllTimersBindedWith(child); | ||||
| 	} | ||||
| 	ETimerManager::startAllTimersBindedWith(pParentScene->getRoot()); | ||||
| } | ||||
| 
 | ||||
| void e2d::ETimerManager::stopAllTimersBindedWith(EScene * pParentScene) | ||||
| { | ||||
| 	for (auto t : s_vTimers) | ||||
| 	{ | ||||
| 		if (t->getParentScene() == pParentScene) | ||||
| 		{ | ||||
| 			t->stop(); | ||||
| 		} | ||||
| 	} | ||||
| 	for (auto child : pParentScene->getChildren()) | ||||
| 	{ | ||||
| 		ETimerManager::stopAllTimersBindedWith(child); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void e2d::ETimerManager::_clearAllTimersBindedWith(EScene * pParentScene) | ||||
| { | ||||
| 	for (size_t i = 0; i < s_vTimers.size();) | ||||
| 	{ | ||||
| 		auto t = s_vTimers[i]; | ||||
| 		if (t->getParentScene() == pParentScene) | ||||
| 		{ | ||||
| 			SafeReleaseAndClear(&t); | ||||
| 			s_vTimers.erase(s_vTimers.begin() + i); | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			i++; | ||||
| 		} | ||||
| 	} | ||||
| 	ETimerManager::stopAllTimersBindedWith(pParentScene->getRoot()); | ||||
| } | ||||
| 
 | ||||
| void e2d::ETimerManager::startAllTimersBindedWith(ENode * pParentNode) | ||||
|  |  | |||
|  | @ -1,5 +1,6 @@ | |||
| #include "..\enodes.h" | ||||
| #include "..\emsg.h" | ||||
| #include "..\elisteners.h" | ||||
| #include "..\emanagers.h" | ||||
| #include "..\Win\winbase.h" | ||||
| 
 | ||||
| e2d::EButton::EButton() | ||||
|  |  | |||
|  | @ -3,6 +3,7 @@ | |||
| 
 | ||||
| e2d::EFont::EFont() | ||||
| 	: m_pTextFormat(nullptr) | ||||
| 	, m_Color(EColor::WHITE) | ||||
| 	, m_fFontSize(22) | ||||
| 	, m_FontWeight(EFontWeight::REGULAR) | ||||
| 	, m_bItalic(false) | ||||
|  | @ -10,10 +11,11 @@ e2d::EFont::EFont() | |||
| { | ||||
| } | ||||
| 
 | ||||
| e2d::EFont::EFont(EString fontFamily, float fontSize, EFontWeight fontWeight, bool italic) | ||||
| e2d::EFont::EFont(EString fontFamily, float fontSize /* = 22 */, UINT32 color /* = EColor::WHITE */, UINT32 fontWeight, bool italic /* = false */) | ||||
| { | ||||
| 	this->setFamily(fontFamily); | ||||
| 	this->setSize(fontSize); | ||||
| 	this->setColor(color); | ||||
| 	this->setWeight(fontWeight); | ||||
| 	this->setItalic(italic); | ||||
| } | ||||
|  | @ -28,11 +30,16 @@ float e2d::EFont::getFontSize() const | |||
| 	return m_fFontSize; | ||||
| } | ||||
| 
 | ||||
| e2d::EFontWeight e2d::EFont::getFontWeight() const | ||||
| UINT32 e2d::EFont::getFontWeight() const | ||||
| { | ||||
| 	return m_FontWeight; | ||||
| } | ||||
| 
 | ||||
| UINT32 e2d::EFont::getColor() const | ||||
| { | ||||
| 	return m_Color; | ||||
| } | ||||
| 
 | ||||
| bool e2d::EFont::isItalic() const | ||||
| { | ||||
| 	return m_bItalic; | ||||
|  | @ -50,12 +57,17 @@ void e2d::EFont::setSize(float fontSize) | |||
| 	m_bRecreateNeeded = true; | ||||
| } | ||||
| 
 | ||||
| void e2d::EFont::setWeight(EFontWeight fontWeight) | ||||
| void e2d::EFont::setWeight(UINT32 fontWeight) | ||||
| { | ||||
| 	m_FontWeight = fontWeight; | ||||
| 	m_bRecreateNeeded = true; | ||||
| } | ||||
| 
 | ||||
| void e2d::EFont::setColor(UINT32 color) | ||||
| { | ||||
| 	m_Color = color; | ||||
| } | ||||
| 
 | ||||
| void e2d::EFont::setItalic(bool value) | ||||
| { | ||||
| 	m_bItalic = value; | ||||
|  | @ -69,7 +81,7 @@ void e2d::EFont::_initTextFormat() | |||
| 	HRESULT hr = GetDirectWriteFactory()->CreateTextFormat( | ||||
| 		m_sFontFamily.c_str(), | ||||
| 		NULL,                          // Font collection(NULL sets it to the system font collection)
 | ||||
| 		DWRITE_FONT_WEIGHT(m_FontWeight.value), | ||||
| 		DWRITE_FONT_WEIGHT(m_FontWeight), | ||||
| 		m_bItalic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL, | ||||
| 		DWRITE_FONT_STRETCH_NORMAL, | ||||
| 		m_fFontSize, | ||||
|  |  | |||
|  | @ -1,7 +1,8 @@ | |||
| #include "..\enodes.h" | ||||
| #include "..\emsg.h" | ||||
| #include "..\emanagers.h" | ||||
| #include "..\etools.h" | ||||
| #include "..\eactions.h" | ||||
| #include "..\egeometry.h" | ||||
| #include "..\Win\winbase.h" | ||||
| #include <algorithm> | ||||
| 
 | ||||
|  | @ -19,6 +20,7 @@ e2d::ENode::ENode() | |||
| 	, m_Matri(D2D1::Matrix3x2F::Identity()) | ||||
| 	, m_bVisiable(true) | ||||
| 	, m_bDisplayedInScene(false) | ||||
| 	, m_pGeometry(nullptr) | ||||
| 	, m_pParent(nullptr) | ||||
| 	, m_pParentScene(nullptr) | ||||
| 	, m_nHashName(0) | ||||
|  | @ -43,6 +45,7 @@ e2d::ENode::~ENode() | |||
| 	{ | ||||
| 		SafeReleaseAndClear(&child); | ||||
| 	} | ||||
| 	SafeReleaseAndClear(&m_pGeometry); | ||||
| } | ||||
| 
 | ||||
| void e2d::ENode::onEnter() | ||||
|  | @ -190,11 +193,14 @@ void e2d::ENode::_updateChildrenTransform() | |||
| 
 | ||||
| void e2d::ENode::_updateTransform(ENode * node) | ||||
| { | ||||
| 	// 计算自身的转换矩阵
 | ||||
| 	node->_updateTransformToReal(); | ||||
| 	// 和父节点矩阵相乘
 | ||||
| 	if (node->m_pParent) | ||||
| 	{ | ||||
| 		node->m_Matri = node->m_Matri * node->m_pParent->m_Matri; | ||||
| 	} | ||||
| 	// 转换矩阵后判断
 | ||||
| 	// 遍历子节点下的所有节点
 | ||||
| 	node->_updateChildrenTransform(); | ||||
| 	node->m_bTransformChildrenNeeded = false; | ||||
|  | @ -267,6 +273,16 @@ e2d::ESize e2d::ENode::getRealSize() const | |||
| 	return m_Size; | ||||
| } | ||||
| 
 | ||||
| float e2d::ENode::getAnchorX() const | ||||
| { | ||||
| 	return m_fAnchorX; | ||||
| } | ||||
| 
 | ||||
| float e2d::ENode::getAnchorY() const | ||||
| { | ||||
| 	return m_fAnchorY; | ||||
| } | ||||
| 
 | ||||
| e2d::ESize e2d::ENode::getSize() const | ||||
| { | ||||
| 	return ESize(getWidth(), getHeight()); | ||||
|  | @ -456,6 +472,11 @@ void e2d::ENode::setAnchor(float anchorX, float anchorY) | |||
| 	m_bTransformChildrenNeeded = true; | ||||
| } | ||||
| 
 | ||||
| void e2d::ENode::setGeometry(EGeometry * geometry) | ||||
| { | ||||
| 	EPhysicsManager::bindWith(geometry, this); | ||||
| } | ||||
| 
 | ||||
| void e2d::ENode::addChild(ENode * child, int order  /* = 0 */) | ||||
| { | ||||
| 	WARN_IF(child == nullptr, "ENode::addChild NULL pointer exception."); | ||||
|  |  | |||
|  | @ -24,24 +24,24 @@ e2d::ESprite::ESprite(ESpriteFrame * spriteFrame) | |||
| e2d::ESprite::ESprite(const EString & imageFileName) | ||||
| 	: ESprite() | ||||
| { | ||||
| 	loadFrom(new ETexture(imageFileName)); | ||||
| 	loadFrom(imageFileName); | ||||
| } | ||||
| 
 | ||||
| e2d::ESprite::ESprite(const EString & imageFileName, float x, float y, float width, float height) | ||||
| { | ||||
| 	loadFrom(new ETexture(imageFileName)); | ||||
| 	loadFrom(imageFileName); | ||||
| 	clip(x, y, width, height); | ||||
| } | ||||
| 
 | ||||
| e2d::ESprite::ESprite(const EString & resourceName, const EString & resourceType) | ||||
| 	: ESprite() | ||||
| { | ||||
| 	loadFrom(new ETexture(resourceName, resourceType)); | ||||
| 	loadFrom(resourceName, resourceType); | ||||
| } | ||||
| 
 | ||||
| e2d::ESprite::ESprite(const EString & resourceName, const EString & resourceType, float x, float y, float width, float height) | ||||
| { | ||||
| 	loadFrom(new ETexture(resourceName, resourceType)); | ||||
| 	loadFrom(resourceName, resourceType); | ||||
| 	clip(x, y, width, height); | ||||
| } | ||||
| 
 | ||||
|  | @ -64,6 +64,16 @@ void e2d::ESprite::loadFrom(ETexture * texture) | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| void e2d::ESprite::loadFrom(const EString & imageFileName) | ||||
| { | ||||
| 	loadFrom(new ETexture(imageFileName)); | ||||
| } | ||||
| 
 | ||||
| void e2d::ESprite::loadFrom(const EString & resourceName, const EString & resourceType) | ||||
| { | ||||
| 	loadFrom(new ETexture(resourceName, resourceType)); | ||||
| } | ||||
| 
 | ||||
| void e2d::ESprite::loadFrom(ETexture * texture, float x, float y, float width, float height) | ||||
| { | ||||
| 	loadFrom(texture); | ||||
|  |  | |||
|  | @ -2,8 +2,7 @@ | |||
| #include "..\Win\winbase.h" | ||||
| 
 | ||||
| e2d::EText::EText() | ||||
| 	: m_Color(EColor::WHITE) | ||||
| 	, m_bWordWrapping(false) | ||||
| 	: m_bWordWrapping(false) | ||||
| 	, m_pFont(nullptr) | ||||
| 	, m_fWordWrappingWidth(0) | ||||
| { | ||||
|  | @ -23,19 +22,17 @@ e2d::EText::EText(EFont * font) | |||
| 	this->setFont(font); | ||||
| } | ||||
| 
 | ||||
| e2d::EText::EText(const EString & text, EColor color, EFont * font) | ||||
| e2d::EText::EText(const EString & text, EFont * font) | ||||
| 	: EText() | ||||
| { | ||||
| 	this->setText(text); | ||||
| 	this->setColor(color); | ||||
| 	this->setFont(font); | ||||
| } | ||||
| 
 | ||||
| e2d::EText::EText(const EString & text, EColor color, EString fontFamily, float fontSize, EFontWeight fontWeight, bool italic) | ||||
| e2d::EText::EText(const EString & text, EString fontFamily, float fontSize, UINT32 color, UINT32 fontWeight, bool italic) | ||||
| { | ||||
| 	this->setText(text); | ||||
| 	this->setColor(color); | ||||
| 	this->setFont(new EFont(fontFamily, fontSize, fontWeight, italic)); | ||||
| 	this->setFont(new EFont(fontFamily, fontSize, color, fontWeight, italic)); | ||||
| } | ||||
| 
 | ||||
| e2d::EText::~EText() | ||||
|  | @ -58,11 +55,6 @@ float e2d::EText::getRealWidth() const | |||
| 	return m_fWordWrappingWidth; | ||||
| } | ||||
| 
 | ||||
| e2d::EColor e2d::EText::getColor() const | ||||
| { | ||||
| 	return m_Color; | ||||
| } | ||||
| 
 | ||||
| e2d::EFont * e2d::EText::getFont() const | ||||
| { | ||||
| 	return m_pFont; | ||||
|  | @ -74,11 +66,6 @@ void e2d::EText::setText(const EString & text) | |||
| 	_initTextLayout(); | ||||
| } | ||||
| 
 | ||||
| void e2d::EText::setColor(EColor color) | ||||
| { | ||||
| 	m_Color = color; | ||||
| } | ||||
| 
 | ||||
| void e2d::EText::setFont(EFont * font) | ||||
| { | ||||
| 	if (font) | ||||
|  | @ -105,7 +92,7 @@ void e2d::EText::setWordWrappingWidth(float wordWrapWidth) | |||
| 
 | ||||
| void e2d::EText::_onRender() | ||||
| { | ||||
| 	GetSolidColorBrush()->SetColor(D2D1::ColorF(m_Color.value, m_fDisplayOpacity)); | ||||
| 	GetSolidColorBrush()->SetColor(D2D1::ColorF(m_pFont->m_Color, m_fDisplayOpacity)); | ||||
| 	GetRenderTarget()->DrawTextW( | ||||
| 		m_sText.c_str(), | ||||
| 		UINT32(m_sText.length()), | ||||
|  |  | |||
|  | @ -1,10 +1,10 @@ | |||
| #include "..\etools.h" | ||||
| #include "..\emanagers.h" | ||||
| #include "..\Win\winbase.h" | ||||
| 
 | ||||
| e2d::ETimer::ETimer() | ||||
| 	: m_bRunning(false) | ||||
| 	, m_nRunTimes(0) | ||||
| 	, m_pParentScene(nullptr) | ||||
| 	, m_pParentNode(nullptr) | ||||
| 	, m_Callback([](int) {}) | ||||
| 	, m_nInterval(0) | ||||
|  | @ -53,11 +53,6 @@ e2d::EString e2d::ETimer::getName() const | |||
| 	return m_sName; | ||||
| } | ||||
| 
 | ||||
| e2d::EScene * e2d::ETimer::getParentScene() const | ||||
| { | ||||
| 	return m_pParentScene; | ||||
| } | ||||
| 
 | ||||
| e2d::ENode * e2d::ETimer::getParentNode() const | ||||
| { | ||||
| 	return m_pParentNode; | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #include "..\etransitions.h" | ||||
| #include "..\eactions.h" | ||||
| #include "..\etools.h" | ||||
| #include "..\emanagers.h" | ||||
| 
 | ||||
| e2d::ETransitionEmerge::ETransitionEmerge(float emergeDuration) | ||||
| 	: m_fEmergeDuration(emergeDuration) | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #include "..\etransitions.h" | ||||
| #include "..\eactions.h" | ||||
| #include "..\etools.h" | ||||
| #include "..\emanagers.h" | ||||
| 
 | ||||
| e2d::ETransitionFade::ETransitionFade(float fadeOutDuration, float fadeInDuration) | ||||
| 	: m_fFadeOutDuration(fadeOutDuration) | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #include "..\etransitions.h" | ||||
| #include "..\eactions.h" | ||||
| #include "..\etools.h" | ||||
| #include "..\emanagers.h" | ||||
| 
 | ||||
| e2d::ETransitionMove::ETransitionMove(float moveDuration, MOVE_DIRECT direct) | ||||
| 	: m_fMoveDuration(moveDuration) | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #include "..\etransitions.h" | ||||
| #include "..\eactions.h" | ||||
| #include "..\etools.h" | ||||
| #include "..\emanagers.h" | ||||
| 
 | ||||
| e2d::ETransitionScale::ETransitionScale(float scaleOutDuration, float scaleInDuration) | ||||
| 	: m_fScaleOutDuration(scaleOutDuration) | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #include "..\etransitions.h" | ||||
| #include "..\eactions.h" | ||||
| #include "..\etools.h" | ||||
| #include "..\emanagers.h" | ||||
| 
 | ||||
| e2d::ETransitionScaleEmerge::ETransitionScaleEmerge(float duration, SCALE_EMERGE_MODE mode) | ||||
| 	: m_fDuration(duration) | ||||
|  |  | |||
|  | @ -19,11 +19,13 @@ | |||
| #include "emacros.h" | ||||
| #include "ecommon.h" | ||||
| #include "ebase.h" | ||||
| #include "emanagers.h" | ||||
| #include "enodes.h" | ||||
| #include "emsg.h" | ||||
| #include "elisteners.h" | ||||
| #include "etools.h" | ||||
| #include "eactions.h" | ||||
| #include "etransitions.h" | ||||
| #include "egeometry.h" | ||||
| 
 | ||||
| 
 | ||||
| #if defined(DEBUG) || defined(_DEBUG) | ||||
|  |  | |||
|  | @ -13,6 +13,7 @@ class ENode; | |||
| class EObjectManager; | ||||
| class EMouseListener; | ||||
| class EKeyboardListener; | ||||
| class EAction; | ||||
| class ETransition; | ||||
| 
 | ||||
| class EApp | ||||
|  | @ -143,7 +144,7 @@ public: | |||
| 
 | ||||
| 	// 修改窗口背景色
 | ||||
| 	static void setBkColor( | ||||
| 		EColor color | ||||
| 		UINT32 color | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置程序是否响应输入法
 | ||||
|  | @ -200,7 +201,7 @@ protected: | |||
| 	bool	m_bTopMost; | ||||
| 	EString	m_sTitle; | ||||
| 	EString	m_sAppName; | ||||
| 	EColor	m_ClearColor; | ||||
| 	UINT32	m_ClearColor; | ||||
| 	LONGLONG nAnimationInterval; | ||||
| 	EScene * m_pCurrentScene; | ||||
| 	EScene * m_pNextScene; | ||||
|  | @ -292,6 +293,11 @@ public: | |||
| 	// 清空所有子成员
 | ||||
| 	void clearAllChildren(); | ||||
| 
 | ||||
| 	// 执行动画
 | ||||
| 	void runAction( | ||||
| 		EAction * action | ||||
| 	); | ||||
| 
 | ||||
| 	// 绑定鼠标消息监听器
 | ||||
| 	void bindListener(EMouseListener * listener); | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										235
									
								
								Easy2D/ecommon.h
								
								
								
								
							
							
						
						
									
										235
									
								
								Easy2D/ecommon.h
								
								
								
								
							|  | @ -7,52 +7,51 @@ | |||
| namespace e2d | ||||
| { | ||||
| 
 | ||||
| typedef std::wstring EString; | ||||
| 
 | ||||
| template<typename T> | ||||
| using EVector = std::vector<T>; | ||||
| 
 | ||||
| struct EWindowStyle | ||||
| { | ||||
| 	LPCTSTR m_pIconID;	/* 程序图标 ID */ | ||||
| 	bool m_bNoClose;	/* 禁用关闭按钮 */ | ||||
| 	bool m_bNoMiniSize;	/* 禁用最小化按钮 */ | ||||
| 	bool m_bTopMost;	/* 窗口置顶 */ | ||||
| 
 | ||||
| 	EWindowStyle() | ||||
| 	{ | ||||
| 		ICON_ID = 0; | ||||
| 		NO_CLOSE = false; | ||||
| 		NO_MINI_SIZE = false; | ||||
| 		TOP_MOST = false; | ||||
| 		m_pIconID = 0; | ||||
| 		m_bNoClose = false; | ||||
| 		m_bNoMiniSize = false; | ||||
| 		m_bTopMost = false; | ||||
| 	} | ||||
| 
 | ||||
| 	EWindowStyle( | ||||
| 		LPCTSTR ICON_ID | ||||
| 		LPCTSTR pIconID | ||||
| 	) | ||||
| 	{ | ||||
| 		this->ICON_ID = ICON_ID; | ||||
| 		NO_CLOSE = false; | ||||
| 		NO_MINI_SIZE = false; | ||||
| 		TOP_MOST = false; | ||||
| 		m_pIconID = pIconID; | ||||
| 		m_bNoClose = false; | ||||
| 		m_bNoMiniSize = false; | ||||
| 		m_bTopMost = false; | ||||
| 	} | ||||
| 
 | ||||
| 	EWindowStyle( | ||||
| 		LPCTSTR ICON_ID, | ||||
| 		bool NO_CLOSE, | ||||
| 		bool NO_MINI_SIZE, | ||||
| 		bool TOP_MOST | ||||
| 		LPCTSTR pIconID, | ||||
| 		bool bNoClose, | ||||
| 		bool bNoMiniSize, | ||||
| 		bool bTopMost | ||||
| 	) | ||||
| 	{ | ||||
| 		this->ICON_ID = ICON_ID; | ||||
| 		this->NO_CLOSE = NO_CLOSE; | ||||
| 		this->NO_MINI_SIZE = NO_MINI_SIZE; | ||||
| 		this->TOP_MOST = TOP_MOST; | ||||
| 		m_pIconID = pIconID; | ||||
| 		m_bNoClose = bNoClose; | ||||
| 		m_bNoMiniSize = bNoMiniSize; | ||||
| 		m_bTopMost = bTopMost; | ||||
| 	} | ||||
| 
 | ||||
| 	LPCTSTR ICON_ID;	/* 程序图标 ID */ | ||||
| 	bool NO_CLOSE;		/* 禁用关闭按钮 */ | ||||
| 	bool NO_MINI_SIZE;	/* 禁用最小化按钮 */ | ||||
| 	bool TOP_MOST;		/* 窗口置顶 */ | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| struct EPoint | ||||
| { | ||||
| 	float x; | ||||
| 	float y; | ||||
| 
 | ||||
| 	EPoint() | ||||
| 	{ | ||||
| 		x = 0; | ||||
|  | @ -74,15 +73,15 @@ struct EPoint | |||
| 	{ | ||||
| 		return EPoint(x - p.x, y - p.y); | ||||
| 	} | ||||
| 
 | ||||
| 	float x; | ||||
| 	float y; | ||||
| }; | ||||
| 
 | ||||
| typedef EPoint EVec; | ||||
| 
 | ||||
| struct ESize | ||||
| { | ||||
| 	float width; | ||||
| 	float height; | ||||
| 
 | ||||
| 	ESize() | ||||
| 	{ | ||||
| 		width = 0; | ||||
|  | @ -104,46 +103,43 @@ struct ESize | |||
| 	{ | ||||
| 		return ESize(width - size.width, height - size.height); | ||||
| 	} | ||||
| 
 | ||||
| 	float width; | ||||
| 	float height; | ||||
| }; | ||||
| 
 | ||||
| typedef std::wstring EString; | ||||
| 
 | ||||
| template<typename T> | ||||
| using EVector = std::vector<T>; | ||||
| 
 | ||||
| 
 | ||||
| // 定时器回调函数(参数为该定时器被调用的次数,从 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; | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| class EColor | ||||
| { | ||||
| public: | ||||
| 
 | ||||
| 	EColor() | ||||
| 	{ | ||||
| 		value = VALUE::WHITE; | ||||
| 	} | ||||
| 
 | ||||
| 	EColor(int color) | ||||
| 	{ | ||||
| 		value = VALUE(color); | ||||
| 	} | ||||
| 	 | ||||
| 	enum VALUE | ||||
| 	enum COMMON_VALUE | ||||
| 	{ | ||||
| 		ALICE_BLUE = 0xF0F8FF, | ||||
| 		ANTIQUE_WHITE = 0xFAEBD7, | ||||
|  | @ -286,26 +282,13 @@ public: | |||
| 		YELLOW = 0xFFFF00, | ||||
| 		YELLOW_GREEN = 0x9ACD32 | ||||
| 	}; | ||||
| 
 | ||||
| 	VALUE value; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| class EFontWeight | ||||
| { | ||||
| public: | ||||
| 
 | ||||
| 	EFontWeight() | ||||
| 	{ | ||||
| 		value = VALUE::REGULAR; | ||||
| 	} | ||||
| 
 | ||||
| 	EFontWeight(int fontWeight) | ||||
| 	{ | ||||
| 		value = VALUE(fontWeight); | ||||
| 	} | ||||
| 
 | ||||
| 	enum VALUE | ||||
| 	enum COMMON_VALUE | ||||
| 	{ | ||||
| 		THIN = 100, | ||||
| 		EXTRA_LIGHT = 200, | ||||
|  | @ -325,8 +308,138 @@ public: | |||
| 		EXTRA_BLACK = 950, | ||||
| 		ULTRA_BLACK = 950 | ||||
| 	}; | ||||
| }; | ||||
| 
 | ||||
| 	VALUE value; | ||||
| 
 | ||||
| // 鼠标消息
 | ||||
| class EMouseMsg | ||||
| { | ||||
| public: | ||||
| 	// 鼠标消息集合
 | ||||
| 	enum 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 getPosX(); | ||||
| 
 | ||||
| 	// 获取鼠标纵坐标
 | ||||
| 	static DWORD getPosY(); | ||||
| 
 | ||||
| 	// 获取鼠标坐标
 | ||||
| 	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(); | ||||
| 
 | ||||
| 	// 获取当前鼠标消息
 | ||||
| 	static EMouseMsg & getMouseMsg(); | ||||
| 
 | ||||
| public: | ||||
| 	UINT m_nMsg = 0; | ||||
| 	WPARAM m_wParam = 0; | ||||
| 	LPARAM m_lParam = 0; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 按键消息
 | ||||
| class EKeyboardMsg | ||||
| { | ||||
| public: | ||||
| 	// 按键消息类型集合
 | ||||
| 	enum 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(); | ||||
| 
 | ||||
| 	// 获取当前按键消息
 | ||||
| 	static EKeyboardMsg & getKeyboardMsg(); | ||||
| 
 | ||||
| public: | ||||
| 	UINT m_nMsg = 0; | ||||
| 	WPARAM m_wParam = 0; | ||||
| 	LPARAM m_lParam = 0; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  | @ -0,0 +1,114 @@ | |||
| #pragma once | ||||
| #include "ebase.h" | ||||
| 
 | ||||
| 
 | ||||
| namespace e2d | ||||
| { | ||||
| 
 | ||||
| class EPhysicsManager; | ||||
| 
 | ||||
| class EGeometry : | ||||
| 	public EObject | ||||
| { | ||||
| 	friend EPhysicsManager; | ||||
| public: | ||||
| 	EGeometry(); | ||||
| 
 | ||||
| protected: | ||||
| 	virtual bool _isCollisionWith( | ||||
| 		EGeometry * pGeometry | ||||
| 	); | ||||
| 
 | ||||
| 	virtual ID2D1Geometry * _getD2dGeometry() const = 0; | ||||
| 
 | ||||
| protected: | ||||
| 	bool	m_bTransformed; | ||||
| 	ENode * m_pParentNode; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| class ERectangle : | ||||
| 	public EGeometry | ||||
| { | ||||
| public: | ||||
| 	// 创建一个空矩形
 | ||||
| 	ERectangle(); | ||||
| 
 | ||||
| 	// 根据左上角坐标和宽高创建矩形
 | ||||
| 	ERectangle( | ||||
| 		float x, | ||||
| 		float y, | ||||
| 		float width, | ||||
| 		float height | ||||
| 	); | ||||
| 
 | ||||
| 	// 创建一个和节点位置大小相同的矩形
 | ||||
| 	ERectangle( | ||||
| 		ENode * node | ||||
| 	); | ||||
| 
 | ||||
| protected: | ||||
| 	void _setRect( | ||||
| 		float left, | ||||
| 		float top, | ||||
| 		float right, | ||||
| 		float bottom | ||||
| 	); | ||||
| 
 | ||||
| 	virtual ID2D1RectangleGeometry * _getD2dGeometry() const override; | ||||
| 
 | ||||
| protected: | ||||
| 	ID2D1RectangleGeometry * m_pD2dRectangle; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| class ECircle : | ||||
| 	public EGeometry | ||||
| { | ||||
| public: | ||||
| 	ECircle(); | ||||
| 
 | ||||
| 	ECircle( | ||||
| 		EPoint center, | ||||
| 		float radius | ||||
| 	); | ||||
| 
 | ||||
| protected: | ||||
| 	void _setCircle( | ||||
| 		EPoint center, | ||||
| 		float radius | ||||
| 	); | ||||
| 
 | ||||
| 	virtual ID2D1EllipseGeometry * _getD2dGeometry() const override; | ||||
| 
 | ||||
| protected: | ||||
| 	ID2D1EllipseGeometry * m_pD2dCircle; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| class EEllipse : | ||||
| 	public EGeometry | ||||
| { | ||||
| public: | ||||
| 	EEllipse(); | ||||
| 
 | ||||
| 	EEllipse( | ||||
| 		EPoint center, | ||||
| 		float radiusX, | ||||
| 		float radiusY | ||||
| 	); | ||||
| 
 | ||||
| protected: | ||||
| 	void _setEllipse( | ||||
| 		EPoint center, | ||||
| 		float radiusX, | ||||
| 		float radiusY | ||||
| 	); | ||||
| 
 | ||||
| 	virtual ID2D1EllipseGeometry * _getD2dGeometry() const override; | ||||
| 
 | ||||
| protected: | ||||
| 	ID2D1EllipseGeometry * m_pD2dEllipse; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  | @ -0,0 +1,324 @@ | |||
| #pragma once | ||||
| #include "ebase.h" | ||||
| 
 | ||||
| namespace e2d | ||||
| { | ||||
| 
 | ||||
| class ENode; | ||||
| class EMsgManager; | ||||
| 
 | ||||
| 
 | ||||
| // 监听器
 | ||||
| class EListener : | ||||
| 	public EObject | ||||
| { | ||||
| 	friend EMsgManager; | ||||
| 
 | ||||
| public: | ||||
| 	EListener(); | ||||
| 
 | ||||
| 	EListener( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	// 获取监听器状态
 | ||||
| 	bool isRunning() const; | ||||
| 
 | ||||
| 	// 启动监听
 | ||||
| 	void start(); | ||||
| 
 | ||||
| 	// 停止监听
 | ||||
| 	void stop(); | ||||
| 
 | ||||
| 	// 获取监听器名称
 | ||||
| 	EString getName() const; | ||||
| 
 | ||||
| 	// 获取监听器所在节点
 | ||||
| 	ENode * getParentNode() const; | ||||
| 
 | ||||
| 	// 设置监听器名称
 | ||||
| 	void setName( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	// 绑定监听器到场景
 | ||||
| 	virtual void bindWith( | ||||
| 		EScene * pParentScene | ||||
| 	) = 0; | ||||
| 
 | ||||
| 	// 绑定监听器到节点
 | ||||
| 	virtual void bindWith( | ||||
| 		ENode * pParentNode | ||||
| 	) = 0; | ||||
| 
 | ||||
| protected: | ||||
| 	// 执行监听器回调函数
 | ||||
| 	virtual void _callOn() = 0; | ||||
| 
 | ||||
| protected: | ||||
| 	EString		m_sName; | ||||
| 	bool		m_bRunning; | ||||
| 	bool		m_bAlways; | ||||
| 	ENode *		m_pParentNode; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 鼠标消息监听器
 | ||||
| class EMouseListener : | ||||
| 	public EListener | ||||
| { | ||||
| 	friend EMsgManager; | ||||
| 
 | ||||
| public: | ||||
| 	EMouseListener(); | ||||
| 
 | ||||
| 	EMouseListener( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	EMouseListener( | ||||
| 		const MOUSE_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	EMouseListener( | ||||
| 		const EString &name, | ||||
| 		const MOUSE_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置监听器回调函数
 | ||||
| 	void setCallback( | ||||
| 		const MOUSE_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	// 绑定监听器到场景
 | ||||
| 	virtual void bindWith( | ||||
| 		EScene * pParentScene | ||||
| 	) override; | ||||
| 
 | ||||
| 	// 绑定监听器到节点
 | ||||
| 	virtual void bindWith( | ||||
| 		ENode * pParentNode | ||||
| 	) override; | ||||
| 
 | ||||
| protected: | ||||
| 	// 执行监听器回调函数
 | ||||
| 	virtual void _callOn() override; | ||||
| 
 | ||||
| protected: | ||||
| 	MOUSE_LISTENER_CALLBACK m_Callback; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 鼠标按下消息监听器
 | ||||
| class EMousePressListener : | ||||
| 	public EMouseListener | ||||
| { | ||||
| public: | ||||
| 	EMousePressListener(); | ||||
| 
 | ||||
| 	EMousePressListener( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	EMousePressListener( | ||||
| 		const MOUSE_PRESS_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	EMousePressListener( | ||||
| 		const EString &name, | ||||
| 		const MOUSE_PRESS_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置监听器回调函数
 | ||||
| 	void setCallback( | ||||
| 		const MOUSE_PRESS_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| protected: | ||||
| 	// 执行监听器回调函数
 | ||||
| 	virtual void _callOn() override; | ||||
| 
 | ||||
| protected: | ||||
| 	MOUSE_PRESS_LISTENER_CALLBACK m_Callback; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 鼠标点击消息监听器
 | ||||
| class EMouseClickListener : | ||||
| 	public EMouseListener | ||||
| { | ||||
| public: | ||||
| 	EMouseClickListener(); | ||||
| 
 | ||||
| 	EMouseClickListener( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	EMouseClickListener( | ||||
| 		const MOUSE_CLICK_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	EMouseClickListener( | ||||
| 		const EString &name, | ||||
| 		const MOUSE_CLICK_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置监听器回调函数
 | ||||
| 	void setCallback( | ||||
| 		const MOUSE_CLICK_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| protected: | ||||
| 	// 执行监听器回调函数
 | ||||
| 	virtual void _callOn() override; | ||||
| 
 | ||||
| protected: | ||||
| 	bool m_bPressed; | ||||
| 	MOUSE_CLICK_LISTENER_CALLBACK m_Callback; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 鼠标点击消息监听器
 | ||||
| class EMouseDoubleClickListener : | ||||
| 	public EMouseListener | ||||
| { | ||||
| public: | ||||
| 	EMouseDoubleClickListener(); | ||||
| 
 | ||||
| 	EMouseDoubleClickListener( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	EMouseDoubleClickListener( | ||||
| 		const MOUSE_DBLCLK_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	EMouseDoubleClickListener( | ||||
| 		const EString &name, | ||||
| 		const MOUSE_DBLCLK_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置监听器回调函数
 | ||||
| 	void setCallback( | ||||
| 		const MOUSE_DBLCLK_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| protected: | ||||
| 	// 执行监听器回调函数
 | ||||
| 	virtual void _callOn() override; | ||||
| 
 | ||||
| protected: | ||||
| 	bool m_bPressed; | ||||
| 	MOUSE_DBLCLK_LISTENER_CALLBACK m_Callback; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 鼠标拖动消息监听器
 | ||||
| class EMouseDragListener : | ||||
| 	public EMouseListener | ||||
| { | ||||
| public: | ||||
| 	EMouseDragListener(); | ||||
| 
 | ||||
| 	EMouseDragListener( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	EMouseDragListener( | ||||
| 		const MOUSE_DRAG_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	EMouseDragListener( | ||||
| 		const EString &name, | ||||
| 		const MOUSE_DRAG_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置监听器回调函数
 | ||||
| 	void setCallback( | ||||
| 		const MOUSE_DRAG_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| protected: | ||||
| 	// 执行监听器回调函数
 | ||||
| 	virtual void _callOn() override; | ||||
| 
 | ||||
| protected: | ||||
| 	EPoint	m_Begin; | ||||
| 	MOUSE_DRAG_LISTENER_CALLBACK m_Callback; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 按键消息监听器
 | ||||
| class EKeyboardListener : | ||||
| 	public EListener | ||||
| { | ||||
| 	friend EMsgManager; | ||||
| 
 | ||||
| public: | ||||
| 	EKeyboardListener(); | ||||
| 
 | ||||
| 	EKeyboardListener( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	EKeyboardListener( | ||||
| 		const KEY_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	EKeyboardListener( | ||||
| 		const EString &name, | ||||
| 		const KEY_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置监听器回调函数
 | ||||
| 	void setCallback( | ||||
| 		const KEY_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	// 绑定监听器到场景
 | ||||
| 	virtual void bindWith( | ||||
| 		EScene * pParentScene | ||||
| 	) override; | ||||
| 
 | ||||
| 	// 绑定监听器到节点
 | ||||
| 	virtual void bindWith( | ||||
| 		ENode * pParentNode | ||||
| 	) override; | ||||
| 
 | ||||
| protected: | ||||
| 	// 执行监听器回调函数
 | ||||
| 	virtual void _callOn() override; | ||||
| 
 | ||||
| protected: | ||||
| 	KEY_LISTENER_CALLBACK m_Callback; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 按键按下消息监听
 | ||||
| class EKeyboardPressListener : | ||||
| 	public EKeyboardListener | ||||
| { | ||||
| 	friend EMsgManager; | ||||
| 
 | ||||
| public: | ||||
| 	EKeyboardPressListener(); | ||||
| 
 | ||||
| 	EKeyboardPressListener( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	EKeyboardPressListener( | ||||
| 		const KEY_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	EKeyboardPressListener( | ||||
| 		const EString &name, | ||||
| 		const KEY_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| protected: | ||||
| 	// 执行监听器回调函数
 | ||||
| 	virtual void _callOn() override; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  | @ -0,0 +1,331 @@ | |||
| #pragma once | ||||
| #include "emacros.h" | ||||
| #include "ecommon.h" | ||||
| 
 | ||||
| namespace e2d | ||||
| { | ||||
| 
 | ||||
| class EApp; | ||||
| class EObject; | ||||
| class EScene; | ||||
| class ENode; | ||||
| class ETimer; | ||||
| class EAction; | ||||
| class EMouseListener; | ||||
| class EKeyboardListener; | ||||
| 
 | ||||
| // 对象管理器
 | ||||
| class EObjectManager | ||||
| { | ||||
| 	friend EApp; | ||||
| 
 | ||||
| public: | ||||
| 	// 将一个节点放入内存池
 | ||||
| 	static void add( | ||||
| 		e2d::EObject * nptr | ||||
| 	); | ||||
| 
 | ||||
| 	// 通知内存池刷新
 | ||||
| 	static void notifyFlush(); | ||||
| 
 | ||||
| private: | ||||
| 	// 刷新内存池
 | ||||
| 	static void __flush(); | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 消息管理器
 | ||||
| class EMsgManager | ||||
| { | ||||
| 	friend EApp; | ||||
| 	friend EScene; | ||||
| 	friend ENode; | ||||
| 
 | ||||
| public: | ||||
| 	// 绑定鼠标消息监听器到场景
 | ||||
| 	static void bindListener( | ||||
| 		EMouseListener * listener, | ||||
| 		EScene * pParentScene, | ||||
| 		bool always = false /* 是否在游戏暂停时仍然监听 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 绑定鼠标消息监听器到节点
 | ||||
| 	static void bindListener( | ||||
| 		EMouseListener * listener, | ||||
| 		ENode * pParentNode, | ||||
| 		bool always = false /* 是否在游戏暂停时仍然监听 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动具有相同名称的鼠标消息监听器
 | ||||
| 	static void startMouseListeners( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止具有相同名称的鼠标消息监听器
 | ||||
| 	static void stopMouseListeners( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	// 删除具有相同名称的鼠标消息监听器
 | ||||
| 	static void delMouseListeners( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动绑定在场景及其子节点上的所有鼠标消息监听器
 | ||||
| 	static void startAllMouseListenersBindedWith( | ||||
| 		EScene * pParentScene | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止绑定在场景及其子节点上的所有鼠标消息监听器
 | ||||
| 	static void stopAllMouseListenersBindedWith( | ||||
| 		EScene * pParentScene | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动绑定在节点上的所有鼠标消息监听器
 | ||||
| 	static void startAllMouseListenersBindedWith( | ||||
| 		ENode * pParentNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止绑定在节点上的所有鼠标消息监听器
 | ||||
| 	static void stopAllMouseListenersBindedWith( | ||||
| 		ENode * pParentNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动所有鼠标消息监听器
 | ||||
| 	static void startAllMouseListeners(); | ||||
| 
 | ||||
| 	// 停止所有鼠标消息监听器
 | ||||
| 	static void stopAllMouseListeners(); | ||||
| 
 | ||||
| 	// 绑定按键消息监听器到场景
 | ||||
| 	static void bindListener( | ||||
| 		EKeyboardListener * listener, | ||||
| 		EScene * pParentScene, | ||||
| 		bool always = false /* 是否在游戏暂停时仍然监听 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 绑定按键消息监听器到节点
 | ||||
| 	static void bindListener( | ||||
| 		EKeyboardListener * listener, | ||||
| 		ENode * pParentNode, | ||||
| 		bool always = false /* 是否在游戏暂停时仍然监听 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动名称相同的按键消息监听器
 | ||||
| 	static void startKeyboardListeners( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止名称相同的按键消息监听器
 | ||||
| 	static void stopKeyboardListeners( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	// 删除名称相同的按键消息监听器
 | ||||
| 	static void delKeyboardListeners( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动绑定在场景及其子节点上的所有按键消息监听器
 | ||||
| 	static void startAllKeyboardListenersBindedWith( | ||||
| 		EScene * pParentScene | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止绑定在场景及其子节点上的所有按键消息监听器
 | ||||
| 	static void stopAllKeyboardListenersBindedWith( | ||||
| 		EScene * pParentScene | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动绑定在节点上的所有按键消息监听器
 | ||||
| 	static void startAllKeyboardListenersBindedWith( | ||||
| 		ENode * pParentNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止绑定在节点上的所有按键消息监听器
 | ||||
| 	static void stopAllKeyboardListenersBindedWith( | ||||
| 		ENode * pParentNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动所有按键消息监听器
 | ||||
| 	static void startAllKeyboardListeners(); | ||||
| 
 | ||||
| 	// 停止所有按键消息监听器
 | ||||
| 	static void stopAllKeyboardListeners(); | ||||
| 
 | ||||
| private: | ||||
| 	// 清除所有监听器
 | ||||
| 	static void _clearManager(); | ||||
| 
 | ||||
| 	// 清除绑定在节点上的所有鼠标消息监听器
 | ||||
| 	static void _clearAllMouseListenersBindedWith( | ||||
| 		ENode * pParentNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 清除绑定在节点上的所有按键消息监听器
 | ||||
| 	static void _clearAllKeyboardListenersBindedWith( | ||||
| 		ENode * pParentNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 鼠标消息程序
 | ||||
| 	static void MouseProc( | ||||
| 		UINT message, | ||||
| 		WPARAM wParam, | ||||
| 		LPARAM lParam | ||||
| 	); | ||||
| 
 | ||||
| 	// 按键消息程序
 | ||||
| 	static void KeyboardProc( | ||||
| 		UINT message, | ||||
| 		WPARAM wParam, | ||||
| 		LPARAM lParam | ||||
| 	); | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 定时器管理器
 | ||||
| class ETimerManager | ||||
| { | ||||
| 	friend EApp; | ||||
| 	friend EScene; | ||||
| 	friend ENode; | ||||
| 
 | ||||
| public: | ||||
| 	// 绑定定时器到场景
 | ||||
| 	static void bindTimer( | ||||
| 		ETimer * timer, | ||||
| 		EScene * pParentScene | ||||
| 	); | ||||
| 
 | ||||
| 	// 绑定定时器到节点
 | ||||
| 	static void bindTimer( | ||||
| 		ETimer * timer, | ||||
| 		ENode * pParentNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动具有相同名称的定时器
 | ||||
| 	static void startTimers( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止具有相同名称的定时器
 | ||||
| 	static void stopTimers( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	// 删除具有相同名称的定时器
 | ||||
| 	static void delTimers( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动绑定在场景及其子节点上的所有定时器
 | ||||
| 	static void startAllTimersBindedWith( | ||||
| 		EScene * pParentScene | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止绑定在场景及其子节点上的所有定时器
 | ||||
| 	static void stopAllTimersBindedWith( | ||||
| 		EScene * pParentScene | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动绑定在节点上的所有定时器
 | ||||
| 	static void startAllTimersBindedWith( | ||||
| 		ENode * pParentNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止绑定在节点上的所有定时器
 | ||||
| 	static void stopAllTimersBindedWith( | ||||
| 		ENode * pParentNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动所有定时器
 | ||||
| 	static void startAllTimers(); | ||||
| 
 | ||||
| 	// 停止所有定时器
 | ||||
| 	static void stopAllTimers(); | ||||
| 
 | ||||
| private: | ||||
| 	// 清空定时器管理器
 | ||||
| 	static void _clearManager(); | ||||
| 
 | ||||
| 	// 清空绑定在节点上的所有定时器
 | ||||
| 	static void _clearAllTimersBindedWith( | ||||
| 		ENode * pParentNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 重置定时器状态
 | ||||
| 	static void _resetAllTimers(); | ||||
| 
 | ||||
| 	// 定时器执行程序
 | ||||
| 	static void TimerProc(); | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 动作管理器
 | ||||
| class EActionManager | ||||
| { | ||||
| 	friend EApp; | ||||
| 	friend EScene; | ||||
| 	friend ENode; | ||||
| 
 | ||||
| public: | ||||
| 	// 添加动作
 | ||||
| 	static void addAction( | ||||
| 		EAction * action | ||||
| 	); | ||||
| 
 | ||||
| 	// 继续绑定在节点上的所有动作
 | ||||
| 	static void startAllActionsBindedWith( | ||||
| 		ENode * pTargetNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 暂停绑定在节点上的所有动作
 | ||||
| 	static void pauseAllActionsBindedWith( | ||||
| 		ENode * pTargetNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止绑定在节点上的所有动作
 | ||||
| 	static void stopAllActionsBindedWith( | ||||
| 		ENode * pTargetNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 继续所有动作
 | ||||
| 	static void startAllActions(); | ||||
| 
 | ||||
| 	// 暂停所有动作
 | ||||
| 	static void pauseAllActions(); | ||||
| 
 | ||||
| 	// 停止所有动作
 | ||||
| 	static void stopAllActions(); | ||||
| 
 | ||||
| private: | ||||
| 	// 清空动画管理器
 | ||||
| 	static void _clearManager(); | ||||
| 
 | ||||
| 	// 清空绑定在节点上的所有动作
 | ||||
| 	static void _clearAllActionsBindedWith( | ||||
| 		ENode * pTargetNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 重置所有动作状态
 | ||||
| 	static void _resetAllActions(); | ||||
| 
 | ||||
| 	// 动作执行程序
 | ||||
| 	static void ActionProc(); | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| class EPhysicsManager | ||||
| { | ||||
| public: | ||||
| 	// 绑定形状到节点
 | ||||
| 	static void bindWith( | ||||
| 		EGeometry * geometry, | ||||
| 		ENode * node | ||||
| 	); | ||||
| 
 | ||||
| protected: | ||||
| 	// 物理引擎执行程序
 | ||||
| 	static void PhysicsProc(); | ||||
| }; | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										615
									
								
								Easy2D/emsg.h
								
								
								
								
							
							
						
						
									
										615
									
								
								Easy2D/emsg.h
								
								
								
								
							|  | @ -1,615 +0,0 @@ | |||
| #pragma once | ||||
| #include "ebase.h" | ||||
| 
 | ||||
| namespace e2d | ||||
| { | ||||
| 
 | ||||
| class ENode; | ||||
| class EMsgManager; | ||||
| 
 | ||||
| // 鼠标消息
 | ||||
| class EMouseMsg | ||||
| { | ||||
| 	friend EMsgManager; | ||||
| 
 | ||||
| public: | ||||
| 	// 鼠标消息集合
 | ||||
| 	enum 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 getPosX(); | ||||
| 
 | ||||
| 	// 获取鼠标纵坐标
 | ||||
| 	static DWORD getPosY(); | ||||
| 
 | ||||
| 	// 获取鼠标坐标
 | ||||
| 	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 EKeyboardMsg | ||||
| { | ||||
| 	friend EMsgManager; | ||||
| 
 | ||||
| public: | ||||
| 	// 按键消息类型集合
 | ||||
| 	enum 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 | ||||
| { | ||||
| 	friend EMsgManager; | ||||
| 
 | ||||
| public: | ||||
| 	EListener(); | ||||
| 
 | ||||
| 	EListener( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	// 获取监听器状态
 | ||||
| 	bool isRunning() const; | ||||
| 
 | ||||
| 	// 启动监听
 | ||||
| 	void start(); | ||||
| 
 | ||||
| 	// 停止监听
 | ||||
| 	void stop(); | ||||
| 
 | ||||
| 	// 获取监听器名称
 | ||||
| 	EString getName() const; | ||||
| 
 | ||||
| 	// 获取监听器所在场景
 | ||||
| 	EScene * getParentScene() const; | ||||
| 
 | ||||
| 	// 获取监听器所在节点
 | ||||
| 	ENode * getParentNode() const; | ||||
| 
 | ||||
| 	// 设置监听器名称
 | ||||
| 	void setName( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	// 绑定监听器到场景
 | ||||
| 	virtual void bindWith( | ||||
| 		EScene * pParentScene | ||||
| 	) = 0; | ||||
| 
 | ||||
| 	// 绑定监听器到节点
 | ||||
| 	virtual void bindWith( | ||||
| 		ENode * pParentNode | ||||
| 	) = 0; | ||||
| 
 | ||||
| protected: | ||||
| 	// 执行监听器回调函数
 | ||||
| 	virtual void _callOn() = 0; | ||||
| 
 | ||||
| protected: | ||||
| 	EString		m_sName; | ||||
| 	bool		m_bRunning; | ||||
| 	bool		m_bAlways; | ||||
| 	EScene *	m_pParentScene; | ||||
| 	ENode *		m_pParentNode; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 鼠标消息监听器
 | ||||
| class EMouseListener : | ||||
| 	public EListener | ||||
| { | ||||
| 	friend EMsgManager; | ||||
| 
 | ||||
| public: | ||||
| 	EMouseListener(); | ||||
| 
 | ||||
| 	EMouseListener( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	EMouseListener( | ||||
| 		const MOUSE_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	EMouseListener( | ||||
| 		const EString &name, | ||||
| 		const MOUSE_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置监听器回调函数
 | ||||
| 	void setCallback( | ||||
| 		const MOUSE_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	// 绑定监听器到场景
 | ||||
| 	virtual void bindWith( | ||||
| 		EScene * pParentScene | ||||
| 	) override; | ||||
| 
 | ||||
| 	// 绑定监听器到节点
 | ||||
| 	virtual void bindWith( | ||||
| 		ENode * pParentNode | ||||
| 	) override; | ||||
| 
 | ||||
| protected: | ||||
| 	// 执行监听器回调函数
 | ||||
| 	virtual void _callOn() override; | ||||
| 
 | ||||
| protected: | ||||
| 	MOUSE_LISTENER_CALLBACK m_Callback; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 鼠标按下消息监听器
 | ||||
| class EMousePressListener : | ||||
| 	public EMouseListener | ||||
| { | ||||
| public: | ||||
| 	EMousePressListener(); | ||||
| 
 | ||||
| 	EMousePressListener( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	EMousePressListener( | ||||
| 		const MOUSE_PRESS_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	EMousePressListener( | ||||
| 		const EString &name, | ||||
| 		const MOUSE_PRESS_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置监听器回调函数
 | ||||
| 	void setCallback( | ||||
| 		const MOUSE_PRESS_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| protected: | ||||
| 	// 执行监听器回调函数
 | ||||
| 	virtual void _callOn() override; | ||||
| 
 | ||||
| protected: | ||||
| 	MOUSE_PRESS_LISTENER_CALLBACK m_Callback; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 鼠标点击消息监听器
 | ||||
| class EMouseClickListener : | ||||
| 	public EMouseListener | ||||
| { | ||||
| public: | ||||
| 	EMouseClickListener(); | ||||
| 
 | ||||
| 	EMouseClickListener( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	EMouseClickListener( | ||||
| 		const MOUSE_CLICK_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	EMouseClickListener( | ||||
| 		const EString &name, | ||||
| 		const MOUSE_CLICK_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置监听器回调函数
 | ||||
| 	void setCallback( | ||||
| 		const MOUSE_CLICK_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| protected: | ||||
| 	// 执行监听器回调函数
 | ||||
| 	virtual void _callOn() override; | ||||
| 
 | ||||
| protected: | ||||
| 	bool m_bPressed; | ||||
| 	MOUSE_CLICK_LISTENER_CALLBACK m_Callback; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 鼠标点击消息监听器
 | ||||
| class EMouseDoubleClickListener : | ||||
| 	public EMouseListener | ||||
| { | ||||
| public: | ||||
| 	EMouseDoubleClickListener(); | ||||
| 
 | ||||
| 	EMouseDoubleClickListener( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	EMouseDoubleClickListener( | ||||
| 		const MOUSE_DBLCLK_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	EMouseDoubleClickListener( | ||||
| 		const EString &name, | ||||
| 		const MOUSE_DBLCLK_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置监听器回调函数
 | ||||
| 	void setCallback( | ||||
| 		const MOUSE_DBLCLK_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| protected: | ||||
| 	// 执行监听器回调函数
 | ||||
| 	virtual void _callOn() override; | ||||
| 
 | ||||
| protected: | ||||
| 	bool m_bPressed; | ||||
| 	MOUSE_DBLCLK_LISTENER_CALLBACK m_Callback; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 鼠标拖动消息监听器
 | ||||
| class EMouseDragListener : | ||||
| 	public EMouseListener | ||||
| { | ||||
| public: | ||||
| 	EMouseDragListener(); | ||||
| 
 | ||||
| 	EMouseDragListener( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	EMouseDragListener( | ||||
| 		const MOUSE_DRAG_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	EMouseDragListener( | ||||
| 		const EString &name, | ||||
| 		const MOUSE_DRAG_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置监听器回调函数
 | ||||
| 	void setCallback( | ||||
| 		const MOUSE_DRAG_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| protected: | ||||
| 	// 执行监听器回调函数
 | ||||
| 	virtual void _callOn() override; | ||||
| 
 | ||||
| protected: | ||||
| 	EPoint	m_Begin; | ||||
| 	MOUSE_DRAG_LISTENER_CALLBACK m_Callback; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 按键消息监听器
 | ||||
| class EKeyboardListener : | ||||
| 	public EListener | ||||
| { | ||||
| 	friend EMsgManager; | ||||
| 
 | ||||
| public: | ||||
| 	EKeyboardListener(); | ||||
| 
 | ||||
| 	EKeyboardListener( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	EKeyboardListener( | ||||
| 		const KEY_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	EKeyboardListener( | ||||
| 		const EString &name, | ||||
| 		const KEY_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置监听器回调函数
 | ||||
| 	void setCallback( | ||||
| 		const KEY_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	// 绑定监听器到场景
 | ||||
| 	virtual void bindWith( | ||||
| 		EScene * pParentScene | ||||
| 	) override; | ||||
| 
 | ||||
| 	// 绑定监听器到节点
 | ||||
| 	virtual void bindWith( | ||||
| 		ENode * pParentNode | ||||
| 	) override; | ||||
| 
 | ||||
| protected: | ||||
| 	// 执行监听器回调函数
 | ||||
| 	virtual void _callOn() override; | ||||
| 
 | ||||
| protected: | ||||
| 	KEY_LISTENER_CALLBACK m_Callback; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 按键按下消息监听
 | ||||
| class EKeyboardPressListener : | ||||
| 	public EKeyboardListener | ||||
| { | ||||
| 	friend EMsgManager; | ||||
| 
 | ||||
| public: | ||||
| 	EKeyboardPressListener(); | ||||
| 
 | ||||
| 	EKeyboardPressListener( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	EKeyboardPressListener( | ||||
| 		const KEY_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| 	EKeyboardPressListener( | ||||
| 		const EString &name, | ||||
| 		const KEY_LISTENER_CALLBACK &callback | ||||
| 	); | ||||
| 
 | ||||
| protected: | ||||
| 	// 执行监听器回调函数
 | ||||
| 	virtual void _callOn() override; | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 消息管理器
 | ||||
| class EMsgManager | ||||
| { | ||||
| 	friend EApp; | ||||
| 	friend EScene; | ||||
| 	friend ENode; | ||||
| 
 | ||||
| public: | ||||
| 	// 绑定鼠标消息监听器到场景
 | ||||
| 	static void bindListener( | ||||
| 		EMouseListener * listener, | ||||
| 		EScene * pParentScene, | ||||
| 		bool always = false /* 是否在游戏暂停时仍然监听 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 绑定鼠标消息监听器到节点
 | ||||
| 	static void bindListener( | ||||
| 		EMouseListener * listener, | ||||
| 		ENode * pParentNode, | ||||
| 		bool always = false /* 是否在游戏暂停时仍然监听 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动具有相同名称的鼠标消息监听器
 | ||||
| 	static void startMouseListeners( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止具有相同名称的鼠标消息监听器
 | ||||
| 	static void stopMouseListeners( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	// 删除具有相同名称的鼠标消息监听器
 | ||||
| 	static void delMouseListeners( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动绑定在场景及其子节点上的所有鼠标消息监听器
 | ||||
| 	static void startAllMouseListenersBindedWith( | ||||
| 		EScene * pParentScene | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止绑定在场景及其子节点上的所有鼠标消息监听器
 | ||||
| 	static void stopAllMouseListenersBindedWith( | ||||
| 		EScene * pParentScene | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动绑定在节点上的所有鼠标消息监听器
 | ||||
| 	static void startAllMouseListenersBindedWith( | ||||
| 		ENode * pParentNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止绑定在节点上的所有鼠标消息监听器
 | ||||
| 	static void stopAllMouseListenersBindedWith( | ||||
| 		ENode * pParentNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动所有鼠标消息监听器
 | ||||
| 	static void startAllMouseListeners(); | ||||
| 
 | ||||
| 	// 停止所有鼠标消息监听器
 | ||||
| 	static void stopAllMouseListeners(); | ||||
| 
 | ||||
| 	// 绑定按键消息监听器到场景
 | ||||
| 	static void bindListener( | ||||
| 		EKeyboardListener * listener, | ||||
| 		EScene * pParentScene, | ||||
| 		bool always = false /* 是否在游戏暂停时仍然监听 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 绑定按键消息监听器到节点
 | ||||
| 	static void bindListener( | ||||
| 		EKeyboardListener * listener, | ||||
| 		ENode * pParentNode, | ||||
| 		bool always = false /* 是否在游戏暂停时仍然监听 */ | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动名称相同的按键消息监听器
 | ||||
| 	static void startKeyboardListeners( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止名称相同的按键消息监听器
 | ||||
| 	static void stopKeyboardListeners( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	// 删除名称相同的按键消息监听器
 | ||||
| 	static void delKeyboardListeners( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动绑定在场景及其子节点上的所有按键消息监听器
 | ||||
| 	static void startAllKeyboardListenersBindedWith( | ||||
| 		EScene * pParentScene | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止绑定在场景及其子节点上的所有按键消息监听器
 | ||||
| 	static void stopAllKeyboardListenersBindedWith( | ||||
| 		EScene * pParentScene | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动绑定在节点上的所有按键消息监听器
 | ||||
| 	static void startAllKeyboardListenersBindedWith( | ||||
| 		ENode * pParentNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止绑定在节点上的所有按键消息监听器
 | ||||
| 	static void stopAllKeyboardListenersBindedWith( | ||||
| 		ENode * pParentNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动所有按键消息监听器
 | ||||
| 	static void startAllKeyboardListeners(); | ||||
| 
 | ||||
| 	// 停止所有按键消息监听器
 | ||||
| 	static void stopAllKeyboardListeners(); | ||||
| 
 | ||||
| private: | ||||
| 	// 清除所有监听器
 | ||||
| 	static void _clearManager(); | ||||
| 
 | ||||
| 	// 清除绑定在节点上的所有鼠标消息监听器
 | ||||
| 	static void _clearAllMouseListenersBindedWith( | ||||
| 		ENode * pParentNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 清除绑定在场景及其子节点上的所有按键消息监听器
 | ||||
| 	static void _clearAllKeyboardListenersBindedWith( | ||||
| 		EScene * pParentScene | ||||
| 	); | ||||
| 
 | ||||
| 	// 清除绑定在场景及其子节点上的所有鼠标消息监听器
 | ||||
| 	static void _clearAllMouseListenersBindedWith( | ||||
| 		EScene * pParentScene | ||||
| 	); | ||||
| 
 | ||||
| 	// 清除绑定在节点上的所有按键消息监听器
 | ||||
| 	static void _clearAllKeyboardListenersBindedWith( | ||||
| 		ENode * pParentNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 鼠标消息程序
 | ||||
| 	static void MouseProc( | ||||
| 		UINT message, | ||||
| 		WPARAM wParam, | ||||
| 		LPARAM lParam | ||||
| 	); | ||||
| 
 | ||||
| 	// 按键消息程序
 | ||||
| 	static void KeyboardProc( | ||||
| 		UINT message, | ||||
| 		WPARAM wParam, | ||||
| 		LPARAM lParam | ||||
| 	); | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  | @ -8,6 +8,7 @@ class EText; | |||
| class ESprite; | ||||
| class EAction; | ||||
| class EButton; | ||||
| class EGeometry; | ||||
| 
 | ||||
| class ENode : | ||||
| 	public EObject | ||||
|  | @ -63,6 +64,12 @@ public: | |||
| 	// 获取节点大小(不考虑缩放)
 | ||||
| 	virtual ESize getRealSize() const; | ||||
| 
 | ||||
| 	// 获取节点的锚点
 | ||||
| 	virtual float getAnchorX() const; | ||||
| 
 | ||||
| 	// 获取节点的锚点
 | ||||
| 	virtual float getAnchorY() const; | ||||
| 
 | ||||
| 	// 获取节点大小
 | ||||
| 	virtual ESize getSize() const; | ||||
| 
 | ||||
|  | @ -224,6 +231,11 @@ public: | |||
| 		float anchorY | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置节点形状
 | ||||
| 	virtual void setGeometry( | ||||
| 		EGeometry * geometry | ||||
| 	); | ||||
| 
 | ||||
| 	// 添加子节点
 | ||||
| 	virtual void addChild( | ||||
| 		ENode * child, | ||||
|  | @ -362,6 +374,7 @@ protected: | |||
| 	bool		m_bDisplayedInScene; | ||||
| 	bool		m_bSortChildrenNeeded; | ||||
| 	bool		m_bTransformChildrenNeeded; | ||||
| 	EGeometry * m_pGeometry; | ||||
| 	EScene *	m_pParentScene; | ||||
| 	ENode *		m_pParent; | ||||
| 	D2D1::Matrix3x2F	m_Matri; | ||||
|  | @ -569,12 +582,23 @@ public: | |||
| 
 | ||||
| 	virtual ~ESprite(); | ||||
| 	 | ||||
| 	// 设置精灵纹理
 | ||||
| 	// 加载精灵纹理
 | ||||
| 	void loadFrom( | ||||
| 		ETexture * texture | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置精灵纹理并裁剪
 | ||||
| 	// 从本地文件加载纹理
 | ||||
| 	void loadFrom( | ||||
| 		const EString & imageFileName | ||||
| 	); | ||||
| 
 | ||||
| 	// 从资源加载纹理
 | ||||
| 	void loadFrom( | ||||
| 		const EString & resourceName, | ||||
| 		const EString & resourceType | ||||
| 	); | ||||
| 
 | ||||
| 	// 加载纹理并裁剪
 | ||||
| 	void loadFrom( | ||||
| 		ETexture * texture, | ||||
| 		float x, | ||||
|  | @ -618,7 +642,8 @@ public: | |||
| 	EFont( | ||||
| 		EString fontFamily, | ||||
| 		float fontSize = 22, | ||||
| 		EFontWeight fontWeight = EFontWeight::REGULAR, | ||||
| 		UINT32 color = EColor::WHITE, | ||||
| 		UINT32 fontWeight = EFontWeight::REGULAR, | ||||
| 		bool italic = false | ||||
| 	); | ||||
| 
 | ||||
|  | @ -628,7 +653,10 @@ public: | |||
| 	float getFontSize() const; | ||||
| 
 | ||||
| 	// 获取当前字体粗细值
 | ||||
| 	EFontWeight getFontWeight() const; | ||||
| 	UINT32 getFontWeight() const; | ||||
| 
 | ||||
| 	// 获取文字颜色
 | ||||
| 	UINT32 getColor() const; | ||||
| 
 | ||||
| 	// 是否是斜体
 | ||||
| 	bool isItalic() const; | ||||
|  | @ -645,7 +673,12 @@ public: | |||
| 
 | ||||
| 	// 设置字体粗细值
 | ||||
| 	void setWeight( | ||||
| 		EFontWeight fontWeight | ||||
| 		UINT32 fontWeight | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置文字颜色
 | ||||
| 	void setColor( | ||||
| 		UINT32 color | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置文字斜体
 | ||||
|  | @ -663,7 +696,8 @@ protected: | |||
| protected: | ||||
| 	EString		m_sFontFamily; | ||||
| 	float		m_fFontSize; | ||||
| 	EFontWeight	m_FontWeight; | ||||
| 	UINT32		m_FontWeight; | ||||
| 	UINT32		m_Color; | ||||
| 	bool		m_bItalic; | ||||
| 	bool		m_bRecreateNeeded; | ||||
| 	IDWriteTextFormat * m_pTextFormat; | ||||
|  | @ -686,16 +720,15 @@ public: | |||
| 
 | ||||
| 	EText( | ||||
| 		const EString & text, | ||||
| 		EColor color, | ||||
| 		EFont * font | ||||
| 	); | ||||
| 
 | ||||
| 	EText( | ||||
| 		const EString & text, | ||||
| 		EColor color, | ||||
| 		EString fontFamily, | ||||
| 		float fontSize = 22, | ||||
| 		EFontWeight fontWeight = EFontWeight::REGULAR, | ||||
| 		UINT32 color = EColor::WHITE, | ||||
| 		UINT32 fontWeight = EFontWeight::REGULAR, | ||||
| 		bool italic = false | ||||
| 	); | ||||
| 
 | ||||
|  | @ -710,9 +743,6 @@ public: | |||
| 	// 获取文本宽度(不考虑缩放)
 | ||||
| 	virtual float getRealWidth() const override; | ||||
| 
 | ||||
| 	// 获取文字颜色
 | ||||
| 	EColor getColor() const; | ||||
| 
 | ||||
| 	// 获取字体
 | ||||
| 	EFont * getFont() const; | ||||
| 
 | ||||
|  | @ -721,11 +751,6 @@ public: | |||
| 		const EString & text | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置文字颜色
 | ||||
| 	void setColor( | ||||
| 		EColor color | ||||
| 	); | ||||
| 
 | ||||
| 	// 设置字体
 | ||||
| 	void setFont( | ||||
| 		EFont * font | ||||
|  | @ -750,7 +775,6 @@ protected: | |||
| 
 | ||||
| protected: | ||||
| 	EString	m_sText; | ||||
| 	EColor	m_Color; | ||||
| 	bool	m_bWordWrapping; | ||||
| 	float	m_fWordWrappingWidth; | ||||
| 	EFont * m_pFont; | ||||
|  |  | |||
							
								
								
									
										160
									
								
								Easy2D/etools.h
								
								
								
								
							
							
						
						
									
										160
									
								
								Easy2D/etools.h
								
								
								
								
							|  | @ -9,25 +9,6 @@ namespace e2d | |||
| class ETimerManager; | ||||
| class EAction; | ||||
| 
 | ||||
| // 对象管理器
 | ||||
| class EObjectManager | ||||
| { | ||||
| 	friend EApp; | ||||
| 
 | ||||
| public: | ||||
| 	// 将一个节点放入内存池
 | ||||
| 	static void add( | ||||
| 		e2d::EObject * nptr | ||||
| 	); | ||||
| 
 | ||||
| 	// 通知内存池刷新
 | ||||
| 	static void notifyFlush(); | ||||
| 
 | ||||
| private: | ||||
| 	// 刷新内存池
 | ||||
| 	static void __flush(); | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 定时器
 | ||||
| class ETimer : | ||||
|  | @ -65,9 +46,6 @@ public: | |||
| 	// 获取定时器名称
 | ||||
| 	EString getName() const; | ||||
| 
 | ||||
| 	// 获取定时器所在场景
 | ||||
| 	EScene * getParentScene() const; | ||||
| 
 | ||||
| 	// 获取定时器所在节点
 | ||||
| 	ENode * getParentNode() const; | ||||
| 
 | ||||
|  | @ -114,7 +92,6 @@ protected: | |||
| 	bool			m_bAtOnce; | ||||
| 	int				m_nRunTimes; | ||||
| 	int				m_nRepeatTimes; | ||||
| 	EScene *		m_pParentScene; | ||||
| 	ENode *			m_pParentNode; | ||||
| 	TIMER_CALLBACK	m_Callback; | ||||
| 	LONGLONG		m_nInterval; | ||||
|  | @ -122,143 +99,6 @@ protected: | |||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 定时器管理器
 | ||||
| class ETimerManager | ||||
| { | ||||
| 	friend EApp; | ||||
| 	friend EScene; | ||||
| 	friend ENode; | ||||
| 
 | ||||
| public: | ||||
| 	// 绑定定时器到场景
 | ||||
| 	static void bindTimer( | ||||
| 		ETimer * timer, | ||||
| 		EScene * pParentScene | ||||
| 	); | ||||
| 
 | ||||
| 	// 绑定定时器到节点
 | ||||
| 	static void bindTimer( | ||||
| 		ETimer * timer, | ||||
| 		ENode * pParentNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动具有相同名称的定时器
 | ||||
| 	static void startTimers( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止具有相同名称的定时器
 | ||||
| 	static void stopTimers( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	// 删除具有相同名称的定时器
 | ||||
| 	static void delTimers( | ||||
| 		const EString &name | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动绑定在场景及其子节点上的所有定时器
 | ||||
| 	static void startAllTimersBindedWith( | ||||
| 		EScene * pParentScene | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止绑定在场景及其子节点上的所有定时器
 | ||||
| 	static void stopAllTimersBindedWith( | ||||
| 		EScene * pParentScene | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动绑定在节点上的所有定时器
 | ||||
| 	static void startAllTimersBindedWith( | ||||
| 		ENode * pParentNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止绑定在节点上的所有定时器
 | ||||
| 	static void stopAllTimersBindedWith( | ||||
| 		ENode * pParentNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 启动所有定时器
 | ||||
| 	static void startAllTimers(); | ||||
| 
 | ||||
| 	// 停止所有定时器
 | ||||
| 	static void stopAllTimers(); | ||||
| 
 | ||||
| private: | ||||
| 	// 清空定时器管理器
 | ||||
| 	static void _clearManager(); | ||||
| 
 | ||||
| 	// 清空绑定在场景及其子节点上的所有定时器
 | ||||
| 	static void _clearAllTimersBindedWith( | ||||
| 		EScene * pParentScene | ||||
| 	); | ||||
| 
 | ||||
| 	// 清空绑定在节点上的所有定时器
 | ||||
| 	static void _clearAllTimersBindedWith( | ||||
| 		ENode * pParentNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 重置定时器状态
 | ||||
| 	static void _resetAllTimers(); | ||||
| 
 | ||||
| 	// 定时器执行程序
 | ||||
| 	static void TimerProc(); | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| // 动作管理器
 | ||||
| class EActionManager | ||||
| { | ||||
| 	friend EApp; | ||||
| 	friend EScene; | ||||
| 	friend ENode; | ||||
| 
 | ||||
| public: | ||||
| 	// 添加动作
 | ||||
| 	static void addAction( | ||||
| 		EAction * action | ||||
| 	); | ||||
| 
 | ||||
| 	// 继续绑定在节点上的所有动作
 | ||||
| 	static void startAllActionsBindedWith( | ||||
| 		ENode * pTargetNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 暂停绑定在节点上的所有动作
 | ||||
| 	static void pauseAllActionsBindedWith( | ||||
| 		ENode * pTargetNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 停止绑定在节点上的所有动作
 | ||||
| 	static void stopAllActionsBindedWith( | ||||
| 		ENode * pTargetNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 继续所有动作
 | ||||
| 	static void startAllActions(); | ||||
| 
 | ||||
| 	// 暂停所有动作
 | ||||
| 	static void pauseAllActions(); | ||||
| 
 | ||||
| 	// 停止所有动作
 | ||||
| 	static void stopAllActions(); | ||||
| 
 | ||||
| private: | ||||
| 	// 清空动画管理器
 | ||||
| 	static void _clearManager(); | ||||
| 
 | ||||
| 	// 清空绑定在节点上的所有动作
 | ||||
| 	static void _clearAllActionsBindedWith( | ||||
| 		ENode * pTargetNode | ||||
| 	); | ||||
| 
 | ||||
| 	// 重置所有动作状态
 | ||||
| 	static void _resetAllActions(); | ||||
| 
 | ||||
| 	// 动作执行程序
 | ||||
| 	static void ActionProc(); | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| class EFileUtils | ||||
| { | ||||
| public: | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue