| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | #include "..\enodes.h"
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | e2d::Sprite::Sprite() | 
					
						
							| 
									
										
										
										
											2018-02-03 22:04:43 +08:00
										 |  |  |  | 	: m_pImage(nullptr) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | e2d::Sprite::Sprite(Image * image) | 
					
						
							| 
									
										
										
										
											2018-02-03 22:04:43 +08:00
										 |  |  |  | 	: m_pImage(nullptr) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	loadFrom(image); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | e2d::Sprite::Sprite(LPCTSTR imageFileName) | 
					
						
							| 
									
										
										
										
											2018-02-03 22:04:43 +08:00
										 |  |  |  | 	: m_pImage(nullptr) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	loadFrom(imageFileName); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-27 21:07:43 +08:00
										 |  |  |  | e2d::Sprite::Sprite(LPCTSTR imageFileName, double x, double y, double width, double height) | 
					
						
							| 
									
										
										
										
											2018-02-03 22:04:43 +08:00
										 |  |  |  | 	: m_pImage(nullptr) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	loadFrom(imageFileName); | 
					
						
							|  |  |  |  | 	clip(x, y, width, height); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | e2d::Sprite::~Sprite() | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	SafeRelease(&m_pImage); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | void e2d::Sprite::loadFrom(Image * image) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							|  |  |  |  | 	if (image) | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		SafeRelease(&m_pImage); | 
					
						
							|  |  |  |  | 		m_pImage = image; | 
					
						
							|  |  |  |  | 		m_pImage->retain(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | 		Node::_setSize(m_pImage->getWidth(), m_pImage->getHeight()); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	} | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | void e2d::Sprite::loadFrom(LPCTSTR imageFileName) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | 	loadFrom(new Image(imageFileName)); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-27 21:07:43 +08:00
										 |  |  |  | void e2d::Sprite::clip(double x, double y, double width, double height) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-03 22:04:43 +08:00
										 |  |  |  | 	m_pImage->clip(x, y, width, height); | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | 	Node::_setSize( | 
					
						
							| 
									
										
										
										
											2018-02-03 22:04:43 +08:00
										 |  |  |  | 		min(max(width, 0), m_pImage->getSourceWidth() - m_pImage->getClipX()), | 
					
						
							|  |  |  |  | 		min(max(height, 0), m_pImage->getSourceHeight() - m_pImage->getClipY()) | 
					
						
							|  |  |  |  | 	); | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | e2d::Image * e2d::Sprite::getImage() const | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-03 22:04:43 +08:00
										 |  |  |  | 	return m_pImage; | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | void e2d::Sprite::onRender() | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-02-03 22:04:43 +08:00
										 |  |  |  | 	if (m_pImage && m_pImage->getBitmap()) | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2018-02-27 21:07:43 +08:00
										 |  |  |  | 		float fClipX = static_cast<float>(m_pImage->getClipX()); | 
					
						
							|  |  |  |  | 		float fClipY = static_cast<float>(m_pImage->getClipY()); | 
					
						
							| 
									
										
										
										
											2018-02-03 22:04:43 +08:00
										 |  |  |  | 		// <20><>ȾͼƬ
 | 
					
						
							| 
									
										
										
										
											2018-02-07 16:37:12 +08:00
										 |  |  |  | 		Renderer::getRenderTarget()->DrawBitmap( | 
					
						
							| 
									
										
										
										
											2018-02-03 22:04:43 +08:00
										 |  |  |  | 			m_pImage->getBitmap(), | 
					
						
							| 
									
										
										
										
											2018-02-27 21:07:43 +08:00
										 |  |  |  | 			D2D1::RectF(0, 0, m_fWidth, m_fHeight), | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 			m_fDisplayOpacity, | 
					
						
							|  |  |  |  | 			D2D1_BITMAP_INTERPOLATION_MODE_LINEAR, | 
					
						
							|  |  |  |  | 			D2D1::RectF( | 
					
						
							| 
									
										
										
										
											2018-02-27 21:07:43 +08:00
										 |  |  |  | 				fClipX, | 
					
						
							|  |  |  |  | 				fClipY, | 
					
						
							|  |  |  |  | 				fClipX + m_fWidth, | 
					
						
							|  |  |  |  | 				fClipY + m_fHeight | 
					
						
							| 
									
										
										
										
											2018-01-30 16:45:38 +08:00
										 |  |  |  | 			) | 
					
						
							|  |  |  |  | 		); | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } |