| 
									
										
										
										
											2018-05-19 01:10:37 +08:00
										 |  |  | #include "..\e2daction.h"
 | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | e2d::Animation::Animation() | 
					
						
							|  |  |  | 	: _interval(1) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 12:22:52 +08:00
										 |  |  | e2d::Animation::Animation(const std::vector<Image*>& frames) | 
					
						
							|  |  |  | 	: _interval(1) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	this->add(frames); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  | e2d::Animation::Animation(double interval) | 
					
						
							|  |  |  | 	: _interval(interval) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::Animation::Animation(double interval, const std::vector<Image*>& frames) | 
					
						
							|  |  |  | 	: _interval(interval) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	this->add(frames); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 12:22:52 +08:00
										 |  |  | e2d::Animation * e2d::Animation::create() | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-19 01:10:37 +08:00
										 |  |  | 	return GC::create<Animation>(); | 
					
						
							| 
									
										
										
										
											2018-05-17 12:22:52 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::Animation * e2d::Animation::create(const std::vector<Image*>& frames) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-19 01:10:37 +08:00
										 |  |  | 	return GC::create<Animation>(frames); | 
					
						
							| 
									
										
										
										
											2018-05-17 12:22:52 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::Animation * e2d::Animation::create(double interval) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-19 01:10:37 +08:00
										 |  |  | 	return GC::create<Animation>(interval); | 
					
						
							| 
									
										
										
										
											2018-05-17 12:22:52 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::Animation * e2d::Animation::create(double interval, const std::vector<Image*>& frames) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-19 01:10:37 +08:00
										 |  |  | 	return GC::create<Animation>(interval, frames); | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::Animation::~Animation() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::Animation::setInterval(double interval) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	_interval = max(interval, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::Animation::onDestroy() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	for (auto frame : _frames) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-19 01:10:37 +08:00
										 |  |  | 		GC::release(frame); | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void e2d::Animation::add(Image * frame) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (frame) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		_frames.push_back(frame); | 
					
						
							|  |  |  | 		frame->retain(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-10 17:02:18 +08:00
										 |  |  | void e2d::Animation::add(const std::vector<Image*>& frames) | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  | { | 
					
						
							|  |  |  | 	for (const auto &image : frames) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		this->add(image); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | double e2d::Animation::getInterval() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return _interval; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const std::vector<e2d::Image*>& e2d::Animation::getFrames() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return _frames; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | e2d::Animation * e2d::Animation::clone() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-05-19 01:10:37 +08:00
										 |  |  | 	auto animation = GC::create<Animation>(_interval); | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  | 	for (auto frame : _frames) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-05-14 00:36:01 +08:00
										 |  |  | 		animation->add(frame); | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-05-14 00:36:01 +08:00
										 |  |  | 	return animation; | 
					
						
							| 
									
										
										
										
											2018-05-10 00:58:43 +08:00
										 |  |  | } |