| 
									
										
										
										
											2018-09-05 13:17:07 +08:00
										 |  |  | #include "..\e2dmodule.h"
 | 
					
						
							| 
									
										
										
										
											2018-04-21 21:24:46 +08:00
										 |  |  | #include "..\e2dtransition.h"
 | 
					
						
							| 
									
										
										
										
											2018-09-05 13:33:39 +08:00
										 |  |  | #include "..\e2dnode.h"
 | 
					
						
							| 
									
										
										
										
											2017-12-09 15:27:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 00:26:20 +08:00
										 |  |  | e2d::Transition::Transition(Scene* scene, float duration) | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	: done_(false) | 
					
						
							|  |  |  | 	, started_() | 
					
						
							|  |  |  | 	, delta_(0) | 
					
						
							|  |  |  | 	, out_scene_(nullptr) | 
					
						
							|  |  |  | 	, in_scene_(scene) | 
					
						
							|  |  |  | 	, out_layer_(nullptr) | 
					
						
							|  |  |  | 	, in_layer_(nullptr) | 
					
						
							|  |  |  | 	, out_layer_param_() | 
					
						
							|  |  |  | 	, in_layer_param_() | 
					
						
							| 
									
										
										
										
											2017-12-09 15:27:11 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	duration_ = std::max(duration, 0.f); | 
					
						
							|  |  |  | 	if (in_scene_) | 
					
						
							|  |  |  | 		in_scene_->Retain(); | 
					
						
							| 
									
										
										
										
											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-09-04 22:42:34 +08:00
										 |  |  | 	SafeRelease(out_layer_); | 
					
						
							|  |  |  | 	SafeRelease(in_layer_); | 
					
						
							|  |  |  | 	GC::GetInstance()->SafeRelease(out_scene_); | 
					
						
							|  |  |  | 	GC::GetInstance()->SafeRelease(in_scene_); | 
					
						
							| 
									
										
										
										
											2018-04-17 01:11:56 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | bool e2d::Transition::IsDone() | 
					
						
							| 
									
										
										
										
											2017-12-09 15:27:11 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	return done_; | 
					
						
							| 
									
										
										
										
											2017-12-09 15:27:11 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | bool e2d::Transition::Init(Game * game, Scene * prev) | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	started_ = Time::Now(); | 
					
						
							|  |  |  | 	out_scene_ = prev; | 
					
						
							| 
									
										
										
										
											2018-08-14 00:26:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	if (out_scene_) | 
					
						
							|  |  |  | 		out_scene_->Retain(); | 
					
						
							| 
									
										
										
										
											2018-08-14 00:26:20 +08:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	HRESULT hr = S_OK; | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	auto renderer = Renderer::GetInstance(); | 
					
						
							|  |  |  | 	if (in_scene_) | 
					
						
							| 
									
										
										
										
											2018-08-14 00:26:20 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 		hr = renderer->GetRenderTarget()->CreateLayer(&in_layer_); | 
					
						
							| 
									
										
										
										
											2018-08-14 00:26:20 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	if (SUCCEEDED(hr) && out_scene_) | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 		hr = renderer->GetRenderTarget()->CreateLayer(&out_layer_); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (FAILED(hr)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	out_layer_param_ = in_layer_param_ = D2D1::LayerParameters( | 
					
						
							| 
									
										
										
										
											2018-07-24 00:24:29 +08:00
										 |  |  | 		D2D1::InfiniteRect(), | 
					
						
							|  |  |  | 		nullptr, | 
					
						
							|  |  |  | 		D2D1_ANTIALIAS_MODE_PER_PRIMITIVE, | 
					
						
							|  |  |  | 		D2D1::Matrix3x2F::Identity(), | 
					
						
							| 
									
										
										
										
											2018-07-28 20:06:27 +08:00
										 |  |  | 		1.f, | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 		renderer->GetSolidBrush(), | 
					
						
							| 
									
										
										
										
											2018-07-24 00:24:29 +08:00
										 |  |  | 		D2D1_LAYER_OPTIONS_NONE | 
					
						
							|  |  |  | 	); | 
					
						
							| 
									
										
										
										
											2018-08-02 00:27:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return true; | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | void e2d::Transition::Update() | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	if (duration_ == 0) | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 		delta_ = 1; | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 		delta_ = (Time::Now() - started_).Seconds() / duration_; | 
					
						
							|  |  |  | 		delta_ = std::min(delta_, 1.f); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | void e2d::Transition::Draw() | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-05 00:09:23 +08:00
										 |  |  | 	auto render_target = Renderer::GetInstance()->GetRenderTarget(); | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	auto size = Window::GetInstance()->GetSize(); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	if (out_scene_) | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 		auto rootPos = out_scene_->GetPos(); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | 		auto clipRect = D2D1::RectF( | 
					
						
							| 
									
										
										
										
											2018-07-28 20:06:27 +08:00
										 |  |  | 			std::max(rootPos.x, 0.f), | 
					
						
							|  |  |  | 			std::max(rootPos.y, 0.f), | 
					
						
							| 
									
										
										
										
											2018-08-28 00:06:10 +08:00
										 |  |  | 			std::min(rootPos.x + size.width, size.width), | 
					
						
							|  |  |  | 			std::min(rootPos.y + size.height, size.height) | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-09-05 00:09:23 +08:00
										 |  |  | 		render_target->SetTransform(D2D1::Matrix3x2F::Identity()); | 
					
						
							|  |  |  | 		render_target->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE); | 
					
						
							|  |  |  | 		render_target->PushLayer(out_layer_param_, out_layer_); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 		out_scene_->Visit(); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 00:09:23 +08:00
										 |  |  | 		render_target->PopLayer(); | 
					
						
							|  |  |  | 		render_target->PopAxisAlignedClip(); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	if (in_scene_) | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 		Point rootPos = in_scene_->GetPos(); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | 		auto clipRect = D2D1::RectF( | 
					
						
							| 
									
										
										
										
											2018-07-28 20:06:27 +08:00
										 |  |  | 			std::max(rootPos.x, 0.f), | 
					
						
							|  |  |  | 			std::max(rootPos.y, 0.f), | 
					
						
							| 
									
										
										
										
											2018-08-28 00:06:10 +08:00
										 |  |  | 			std::min(rootPos.x + size.width, size.width), | 
					
						
							|  |  |  | 			std::min(rootPos.y + size.height, size.height) | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-09-05 00:09:23 +08:00
										 |  |  | 		render_target->SetTransform(D2D1::Matrix3x2F::Identity()); | 
					
						
							|  |  |  | 		render_target->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE); | 
					
						
							|  |  |  | 		render_target->PushLayer(in_layer_param_, in_layer_); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 		in_scene_->Visit(); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 00:09:23 +08:00
										 |  |  | 		render_target->PopLayer(); | 
					
						
							|  |  |  | 		render_target->PopAxisAlignedClip(); | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | void e2d::Transition::Stop() | 
					
						
							| 
									
										
										
										
											2018-05-09 00:34:15 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-09-04 22:42:34 +08:00
										 |  |  | 	done_ = true; | 
					
						
							|  |  |  | 	Reset(); | 
					
						
							| 
									
										
										
										
											2017-12-09 15:27:11 +08:00
										 |  |  | } |