| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | #include "..\e2dbase.h"
 | 
					
						
							| 
									
										
										
										
											2018-04-21 21:24:46 +08:00
										 |  |  |  | #include "..\e2dtransition.h"
 | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | #include "..\e2dnode.h"
 | 
					
						
							| 
									
										
										
										
											2017-12-09 15:27:11 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | e2d::Transition::Transition(double duration) | 
					
						
							|  |  |  |  | 	: _end(false) | 
					
						
							|  |  |  |  | 	, _last(0) | 
					
						
							|  |  |  |  | 	, _delta(0) | 
					
						
							|  |  |  |  | 	, _outScene(nullptr) | 
					
						
							|  |  |  |  | 	, _inScene(nullptr) | 
					
						
							|  |  |  |  | 	, _outLayer(nullptr) | 
					
						
							|  |  |  |  | 	, _inLayer(nullptr) | 
					
						
							|  |  |  |  | 	, _outLayerParam() | 
					
						
							|  |  |  |  | 	, _inLayerParam() | 
					
						
							| 
									
										
										
										
											2017-12-09 15:27:11 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-04 12:49:05 +08:00
										 |  |  |  | 	_duration = std::max(duration, 0.0); | 
					
						
							| 
									
										
										
										
											2017-12-09 15:27:11 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | e2d::Transition::~Transition() | 
					
						
							| 
									
										
										
										
											2018-04-17 01:11:56 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-22 12:24:43 +08:00
										 |  |  |  | 	SafeRelease(_outLayer); | 
					
						
							|  |  |  |  | 	SafeRelease(_inLayer); | 
					
						
							| 
									
										
										
										
											2018-07-07 01:43:41 +08:00
										 |  |  |  | 	GC::safeRelease(_outScene); | 
					
						
							|  |  |  |  | 	GC::safeRelease(_inScene); | 
					
						
							| 
									
										
										
										
											2018-04-17 01:11:56 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | bool e2d::Transition::isDone() | 
					
						
							| 
									
										
										
										
											2017-12-09 15:27:11 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	return _end; | 
					
						
							| 
									
										
										
										
											2017-12-09 15:27:11 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | void e2d::Transition::_init(Scene * prev, Scene * next) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	auto renderer = Renderer::getInstance(); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	// <20><><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	HRESULT hr = renderer->getRenderTarget()->CreateLayer(&_inLayer); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (SUCCEEDED(hr)) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 		hr = renderer->getRenderTarget()->CreateLayer(&_outLayer); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (FAILED(hr)) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-24 12:24:39 +08:00
										 |  |  |  | 		throw SystemException(L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɶ<EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD>㴴<EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>"); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	_last = Time::getTotalTime(); | 
					
						
							|  |  |  |  | 	_outScene = prev; | 
					
						
							|  |  |  |  | 	_inScene = next; | 
					
						
							| 
									
										
										
										
											2018-07-07 01:43:41 +08:00
										 |  |  |  | 	GC::retain(_outScene); | 
					
						
							|  |  |  |  | 	GC::retain(_inScene); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	_windowSize = Window::getInstance()->getSize(); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	_outLayerParam = _inLayerParam = D2D1::LayerParameters(); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void e2d::Transition::_update() | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  |  | 	// <20><><EFBFBD>㶯<EFBFBD><E3B6AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	if (_duration == 0) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		_delta = 1; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 	else | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-07-04 12:49:05 +08:00
										 |  |  |  | 		_delta = std::min((Time::getTotalTime() - _last) / _duration, 1.0); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	this->_updateCustom(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	// <20><><EFBFBD>³<EFBFBD><C2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 	if (_outScene) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-07-07 19:05:39 +08:00
										 |  |  |  | 		_outScene->update(); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | 	if (_inScene) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-07-07 19:05:39 +08:00
										 |  |  |  | 		_inScene->update(); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void e2d::Transition::_render() | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-07-03 18:16:26 +08:00
										 |  |  |  | 	auto pRT = Renderer::getInstance()->getRenderTarget(); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (_outScene) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		Point rootPos = _outScene->getRoot()->getPos(); | 
					
						
							|  |  |  |  | 		auto clipRect = D2D1::RectF( | 
					
						
							| 
									
										
										
										
											2018-07-04 12:49:05 +08:00
										 |  |  |  | 			float(std::max(rootPos.x, 0.0)), | 
					
						
							|  |  |  |  | 			float(std::max(rootPos.y, 0.0)), | 
					
						
							|  |  |  |  | 			float(std::min(rootPos.x + _windowSize.width, _windowSize.width)), | 
					
						
							|  |  |  |  | 			float(std::min(rootPos.y + _windowSize.height, _windowSize.height)) | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 		); | 
					
						
							|  |  |  |  | 		pRT->SetTransform(D2D1::Matrix3x2F::Identity()); | 
					
						
							|  |  |  |  | 		pRT->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE); | 
					
						
							|  |  |  |  | 		pRT->PushLayer(_outLayerParam, _outLayer); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-07 19:05:39 +08:00
										 |  |  |  | 		_outScene->render(); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 		pRT->PopLayer(); | 
					
						
							|  |  |  |  | 		pRT->PopAxisAlignedClip(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 	if (_inScene) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		Point rootPos = _inScene->getRoot()->getPos(); | 
					
						
							|  |  |  |  | 		auto clipRect = D2D1::RectF( | 
					
						
							| 
									
										
										
										
											2018-07-04 12:49:05 +08:00
										 |  |  |  | 			float(std::max(rootPos.x, 0.0)), | 
					
						
							|  |  |  |  | 			float(std::max(rootPos.y, 0.0)), | 
					
						
							|  |  |  |  | 			float(std::min(rootPos.x + _windowSize.width, _windowSize.width)), | 
					
						
							|  |  |  |  | 			float(std::min(rootPos.y + _windowSize.height, _windowSize.height)) | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 		); | 
					
						
							|  |  |  |  | 		pRT->SetTransform(D2D1::Matrix3x2F::Identity()); | 
					
						
							|  |  |  |  | 		pRT->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE); | 
					
						
							|  |  |  |  | 		pRT->PushLayer(_inLayerParam, _inLayer); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-07 19:05:39 +08:00
										 |  |  |  | 		_inScene->render(); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 		pRT->PopLayer(); | 
					
						
							|  |  |  |  | 		pRT->PopAxisAlignedClip(); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | void e2d::Transition::_stop() | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	_end = true; | 
					
						
							|  |  |  |  | 	_reset(); | 
					
						
							| 
									
										
										
										
											2017-12-09 15:27:11 +08:00
										 |  |  |  | } |